1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

Merge branch 'master' into tmp-merge

This commit is contained in:
Andrew Zhen Ning Yong 2019-03-28 11:28:55 +00:00
commit c49da2ec2d
5 changed files with 470 additions and 46 deletions

View File

@ -30,7 +30,7 @@ int main(int argc, char *argv[])
opt.addOption("s", "shift" , OptParser::OptType::value , true,
"time variable shift", "0");
opt.addOption("m", "model" , OptParser::OptType::value , true,
"fit model (exp|exp2|exp3|cosh|cosh2|cosh3|explin|<interpreter code>)", "cosh");
"fit model (exp|exp2|exp3|cosh|cosh2|cosh3|explin|const|<interpreter code>)", "cosh");
opt.addOption("" , "nPar" , OptParser::OptType::value , true,
"number of model parameters for custom models "
"(-1 if irrelevant)", "-1");
@ -117,7 +117,7 @@ int main(int argc, char *argv[])
// make model //////////////////////////////////////////////////////////////
DoubleModel mod;
bool coshModel = false, linearModel = false;
bool coshModel = false, linearModel = false, constModel = false;
if ((model == "exp") or (model == "exp1"))
{
@ -183,6 +183,15 @@ int main(int argc, char *argv[])
return p[1] - p[0]*x[0];
}, 1, nPar);
}
else if (model == "const")
{
constModel = true;
nPar = 1;
mod.setFunction([](const double *x __dumb, const double *p)
{
return p[0];
}, 1, nPar);
}
else
{
if (nPar > 0)
@ -214,16 +223,30 @@ int main(int argc, char *argv[])
data.addXDim(nt, "t/a", true);
data.addYDim("C(t)");
data.setUnidimData(tvec, corr);
for (Index p = 0; p < nPar; p += 2)
// set parameter name /////////////
if(constModel)
{
mod.parName().setName(p, "E_" + strFrom(p/2));
mod.parName().setName(p + 1, "Z_" + strFrom(p/2));
mod.parName().setName(0, "const");
}
else
{
for (Index p = 0; p < nPar; p += 2)
{
mod.parName().setName(p, "E_" + strFrom(p/2));
mod.parName().setName(p + 1, "Z_" + strFrom(p/2));
}
}
//set initial values ////////////////
if (linearModel)
{
init(0) = data.y(nt/4, 0)[central] - data.y(nt/4 + 1, 0)[central];
init(1) = data.y(nt/4, 0)[central] + nt/4*init(0);
}
else if(constModel)
{
init(0) = data.y(nt/4, 0)[central];
}
else
{
init(0) = log(data.y(nt/4, 0)[central]/data.y(nt/4 + 1, 0)[central]);
@ -234,6 +257,7 @@ int main(int argc, char *argv[])
init(p) = 2*init(p - 2);
init(p + 1) = init(p - 1)/2.;
}
// set limits for minimiser //////////////
for (Index p = 0; p < nPar; p += 2)
{
if (linearModel)
@ -241,20 +265,32 @@ int main(int argc, char *argv[])
globMin.setLowLimit(p, -10.*fabs(init(p)));
globMin.setHighLimit(p, 10.*fabs(init(p)));
}
else if(constModel)
{
globMin.setLowLimit(p, -10*fabs(init(0)));
locMin.setLowLimit(p, -10*fabs(init(0)));
// cout << "Suppressing low limits" << endl;
globMin.setHighLimit(p, 10*fabs(init(0)));
}
else
{
globMin.setLowLimit(p, 0.);
locMin.setLowLimit(p, 0.);
globMin.setHighLimit(p, 10.*init(p));
}
globMin.setLowLimit(p + 1, -10.*fabs(init(p + 1)));
globMin.setHighLimit(p + 1, 10.*fabs(init(p + 1)));
if(!constModel)
{
globMin.setLowLimit(p + 1, -10.*fabs(init(p + 1)));
globMin.setHighLimit(p + 1, 10.*fabs(init(p + 1)));
}
}
globMin.setPrecision(0.001);
globMin.setMaxIteration(100000);
globMin.setVerbosity(verbosity);
locMin.setMaxIteration(1000000);
locMin.setVerbosity(verbosity);
// fit /////////////////////////////////
for (Index t = 0; t < nt; ++t)
{
data.fitPoint((t >= ti) and (t <= tf)
@ -278,69 +314,75 @@ int main(int argc, char *argv[])
fit = data.fit(locMin, init, mod);
fit.print();
}
// plots ///////////////////////////////////////////////////////////////////
if (doPlot)
{
Plot p;
DMatSample effMass(nSample);
DVec effMassT, fitErr;
Index maxT = (coshModel) ? (nt - 2) : (nt - 1);
double e0, e0Err;
p << PlotRange(Axis::x, 0, nt - 1);
if (!linearModel)
if (!linearModel and !constModel)
{
p << LogScale(Axis::y);
}
p << Color("rgb 'blue'") << PlotPredBand(fit.getModel(_), 0, nt - 1);
p << Color("rgb 'blue'") << PlotFunction(fit.getModel(), 0, nt - 1);
p << Color("rgb 'red'") << PlotData(data.getData());
p << Color("rgb 'red'") << PlotData(data.getData());
p.display();
effMass.resizeMat(maxT, 1);
effMassT.setLinSpaced(maxT, 1, maxT);
fitErr = fit.variance().cwiseSqrt();
e0 = fit[central](0);
e0Err = fitErr(0);
if (coshModel)
// effective mass plot //////////////////////////////////////////////////////
if (!constModel)
{
FOR_STAT_ARRAY(effMass, s)
DMatSample effMass(nSample);
DVec effMassT, fitErr;
Index maxT = (coshModel) ? (nt - 2) : (nt - 1);
double e0, e0Err;
effMass.resizeMat(maxT, 1);
effMassT.setLinSpaced(maxT, 0, maxT-1);
fitErr = fit.variance().cwiseSqrt();
e0 = fit[central](0);
e0Err = fitErr(0);
if (coshModel)
{
for (Index t = 1; t < nt - 1; ++t)
FOR_STAT_ARRAY(effMass, s)
{
effMass[s](t - 1) = acosh((corr[s](t-1) + corr[s](t+1))
/(2.*corr[s](t)));
for (Index t = 1; t < nt - 1; ++t)
{
effMass[s](t - 1) = acosh((corr[s](t-1) + corr[s](t+1))
/(2.*corr[s](t)));
}
}
}
}
else if (linearModel)
{
FOR_STAT_ARRAY(effMass, s)
else if (linearModel)
{
for (Index t = 0; t < nt - 1; ++t)
FOR_STAT_ARRAY(effMass, s)
{
effMass[s](t) = corr[s](t) - corr[s](t+1);
for (Index t = 0; t < nt - 1; ++t)
{
effMass[s](t) = corr[s](t) - corr[s](t+1);
}
}
}
}
else
{
FOR_STAT_ARRAY(effMass, s)
else
{
for (Index t = 1; t < nt; ++t)
FOR_STAT_ARRAY(effMass, s)
{
effMass[s](t - 1) = log(corr[s](t-1)/corr[s](t));
for (Index t = 1; t < nt; ++t)
{
effMass[s](t - 1) = log(corr[s](t-1)/corr[s](t));
}
}
}
p.reset();
p << PlotRange(Axis::x, 0, maxT);
p << PlotRange(Axis::y, e0 - 20.*e0Err, e0 + 20.*e0Err);
p << Color("rgb 'blue'") << PlotBand(0, maxT, e0 - e0Err, e0 + e0Err);
p << Color("rgb 'blue'") << PlotHLine(e0);
p << Color("rgb 'red'") << PlotData(effMassT, effMass);
p << Caption("Effective Mass");
p.display();
}
p.reset();
p << PlotRange(Axis::x, 1, maxT);
p << PlotRange(Axis::y, e0 - 20.*e0Err, e0 + 20.*e0Err);
p << Color("rgb 'blue'") << PlotBand(0, maxT, e0 - e0Err, e0 + e0Err);
p << Color("rgb 'blue'") << PlotHLine(e0);
p << Color("rgb 'red'") << PlotData(effMassT, effMass);
p.display();
}
}
if (doHeatmap)
{
Plot p;
@ -359,6 +401,7 @@ int main(int argc, char *argv[])
}
}
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{

116
physics/eff-mass.cpp Normal file
View File

@ -0,0 +1,116 @@
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/CompiledModel.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/MatSample.hpp>
#include <LatAnalyze/Math.hpp>
#include <LatAnalyze/MinuitMinimizer.hpp>
#include <LatAnalyze/NloptMinimizer.hpp>
#include <LatAnalyze/Plot.hpp>
#include <LatAnalyze/XYSampleData.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
// parse arguments /////////////////////////////////////////////////////////
OptParser opt;
bool parsed, doPlot;
string corrFileName, corr0FileName, outFileName;
Index shift;
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file", "");
opt.addOption("s", "shift" , OptParser::OptType::value , true,
"time variable shift", "0");
opt.addOption("p", "plot" , OptParser::OptType::trigger, true,
"show the fit plot");
opt.addOption("", "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() < 2) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0] << " <options> < QED correlator file> < QCD correlator file 2>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
corrFileName = opt.getArgs()[0];
corr0FileName = opt.getArgs()[1];
outFileName = opt.optionValue<string>("o");
shift = opt.optionValue<Index>("s");
doPlot = opt.gotOption("p");
// load correlator /////////////////////////////////////////////////////////
DMatSample tmp, c0, dc, effmass;
Index nSample, nt;
float tp,tm;
tmp = Io::load<DMatSample>(corr0FileName);
nSample = tmp.size();
nt = tmp[central].rows();
tmp = tmp.block(0, 0, nt, 1);
c0 = tmp;
dc = tmp;
effmass = tmp; // initialise effmass like this
FOR_STAT_ARRAY(c0, s) // loads the QCD correlator, bootstrap sample by sample
{
for (Index t = 0; t < nt; ++t)
{
c0[s]((t - shift + nt)%nt) = tmp[s](t);
}
}
tmp = Io::load<DMatSample>(corrFileName);
tmp = tmp.block(0, 0, nt, 1);
FOR_STAT_ARRAY(dc, s) // computes the leading order perturbation in corr
{
for (Index t = 0; t < nt; ++t)
{
dc[s](t) = tmp[s](t);
}
}
FOR_STAT_ARRAY(effmass, s) //generate effective mass here
{
for (Index t = 0; t < nt; ++t)
{
tp = (t+1)%nt;
tm = (t-1)%nt;
if( tm == -1)
{
tm = nt-1;
}
effmass[s](t) = ( 1./sqrt( (( c0[s](tp) + c0[s](tm) )/(2*c0[s](t)))*(( c0[s](tp) + c0[s](tm) )/(2*c0[s](t))) - 1 ) )*( (dc[s](tp) + dc[s](tm) )/(2*c0[s](t)) - ( dc[s](t)/c0[s](t) )*( ( c0[s](tp) + c0[s](tm) )/(2*c0[s](t)) ) );
}
}
// cout << "\n***********\n***********\n***********\nCheckpoint.\n***********\n***********\n***********\n" << endl;
// plots ///////////////////////////////////////////////////////////////////
if(doPlot)
{
Plot p;
DVec tAxis;
tAxis.setLinSpaced(nt,1,nt);
p << PlotRange(Axis::x, 1, nt);
p << PlotRange(Axis::y, -0.1,0.1);
p << Color("rgb 'red'") << PlotData(tAxis, effmass);
p.display();
}
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{
Io::save(effmass, outFileName);
cout << "File saved as: " << outFileName << endl;
}
return EXIT_SUCCESS;
}

123
physics/pert-eff-mass.cpp Normal file
View File

@ -0,0 +1,123 @@
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/CompiledModel.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/MatSample.hpp>
#include <LatAnalyze/Math.hpp>
#include <LatAnalyze/MinuitMinimizer.hpp>
#include <LatAnalyze/NloptMinimizer.hpp>
#include <LatAnalyze/Plot.hpp>
#include <LatAnalyze/XYSampleData.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
// parse arguments /////////////////////////////////////////////////////////
OptParser opt;
bool parsed, doPlot, fold;
string corrFileName, corr0FileName, outFileName;
Index shift;
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file", "");
opt.addOption("s", "shift" , OptParser::OptType::value , true,
"time variable shift", "0");
opt.addOption("p", "plot" , OptParser::OptType::trigger, true,
"show the fit plot");
opt.addOption("" , "fold" , OptParser::OptType::trigger, true,
"fold the correlator");
opt.addOption("", "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or (opt.getArgs().size() < 2) or opt.gotOption("help"))
{
cerr << "usage: " << argv[0] << " <options> < QED correlator file> < QCD correlator file>" << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
corrFileName = opt.getArgs()[0];
corr0FileName = opt.getArgs()[1];
outFileName = opt.optionValue<string>("o");
shift = opt.optionValue<Index>("s");
doPlot = opt.gotOption("p");
fold = opt.gotOption("fold");
// load correlator /////////////////////////////////////////////////////////
DMatSample tmp0, tmp, c0, dc, effmass;
Index nSample, nt;
float tp,tm;
tmp0 = Io::load<DMatSample>(corr0FileName);
tmp = Io::load<DMatSample>(corrFileName);
nSample = tmp.size();
nt = tmp[central].rows();
tmp0 = tmp0.block(0, 0, nt, 1);
tmp = tmp.block(0, 0, nt, 1);
c0 = tmp0;
dc = tmp;
effmass = tmp;
FOR_STAT_ARRAY(c0, s)
{
for (Index t = 0; t < nt; ++t)
{
c0[s]((t - shift + nt)%nt) = tmp0[s](t);
dc[s](t) = tmp[s](t);
}
}
if (fold)
{
cout << "Folding correlators..." << endl;
tmp0 = c0;
tmp = dc;
FOR_STAT_ARRAY(c0, s)
{
for (Index t = 0; t < nt; ++t)
{
c0[s](t) = 0.5*(tmp0[s](t) + tmp0[s]((nt - t) % nt));
}
}
FOR_STAT_ARRAY(dc, s)
{
for (Index t = 0; t < nt; ++t)
{
dc[s](t) = 0.5*(tmp[s](t) + tmp[s]((nt - t) % nt));
}
}
}
FOR_STAT_ARRAY(effmass, s)
{
for (Index t = 0; t < nt; ++t)
{
tp = (t+1)%nt;
tm = (t-1)%nt;
if( tm == -1)
{
tm = nt-1;
}
effmass[s](t) = ( 1./sqrt( ( ( c0[s](tp) + c0[s](tm) )/(2*c0[s](t) ) )*(( c0[s](tp) + c0[s](tm) )/(2*c0[s](t))) - 1 ) )*( (dc[s](tp) + dc[s](tm) )/(2*c0[s](t)) - ( dc[s](t)/c0[s](t) )*( ( c0[s](tp) + c0[s](tm) )/(2*c0[s](t)) ) );
}
}
// plots ///////////////////////////////////////////////////////////////////
if(doPlot)
{
Plot p;
DVec tAxis;
tAxis.setLinSpaced(nt, 0, nt-1);
p << PlotRange(Axis::x, 0, nt);
p << PlotRange(Axis::y, -0.1, 0.1);
p << Color("rgb 'red'") << PlotData(tAxis, effmass);
p.display();
}
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{
Io::save(effmass, outFileName);
cout << "File saved as: " << outFileName << endl;
}
return EXIT_SUCCESS;
}

View File

@ -7,6 +7,7 @@ endif
endif
bin_PROGRAMS = \
latan-plot \
latan-sample-combine \
latan-sample-element \
latan-sample-fake \
@ -14,7 +15,11 @@ bin_PROGRAMS = \
latan-sample-plot \
latan-sample-plot-corr\
latan-sample-read \
latan-resample
latan-resample
latan_plot_SOURCES = plot.cpp
latan_plot_CXXFLAGS = $(COM_CXXFLAGS)
latan_plot_LDFLAGS = -L../lib/.libs -lLatAnalyze
latan_sample_combine_SOURCES = sample-combine.cpp
latan_sample_combine_CXXFLAGS = $(COM_CXXFLAGS)

137
utils/plot.cpp Normal file
View File

@ -0,0 +1,137 @@
#include <LatCore/OptParser.hpp>
#include <LatAnalyze/CompiledModel.hpp>
#include <LatAnalyze/Io.hpp>
#include <LatAnalyze/MatSample.hpp>
#include <LatAnalyze/Math.hpp>
#include <LatAnalyze/MinuitMinimizer.hpp>
#include <LatAnalyze/NloptMinimizer.hpp>
#include <LatAnalyze/Plot.hpp>
#include <LatAnalyze/XYSampleData.hpp>
using namespace std;
using namespace Latan;
int main(int argc, char *argv[])
{
// parse arguments /////////////////////////////////////////////////////////
OptParser opt;
bool parsed, imag;
string plotFileName, outFileName, xName, yName, title, save;
vector<string> inFileName;
double xLow, xHigh, spacing;
opt.addOption("i" , "imag" , OptParser::OptType::trigger, true,
"plot imaginary");
opt.addOption("o", "output", OptParser::OptType::value , true,
"output file", "");
opt.addOption("x", "xAxis", OptParser::OptType::value , true,
"x-axis name", "");
opt.addOption("l", "xLow", OptParser::OptType::value , true,
"x-axis lower bound", "0");
opt.addOption("y", "yAxis", OptParser::OptType::value , true,
"y-axis name", "");
opt.addOption("", "spacing", OptParser::OptType::value , true,
"spacing between points", "1");
opt.addOption("s", "save", OptParser::OptType::value, true,
"saves the source and .pdf", "");
opt.addOption("t", "title", OptParser::OptType::value , true,
"plot title", "");
opt.addOption("", "help" , OptParser::OptType::trigger, true,
"show this help message and exit");
parsed = opt.parse(argc, argv);
if (!parsed or opt.gotOption("help") or opt.getArgs().size() != 1)
{
cerr << "usage: " << argv[0] << " <.h5/manifest file> <options> " << endl;
cerr << endl << "Possible options:" << endl << opt << endl;
return EXIT_FAILURE;
}
plotFileName = opt.getArgs().front();
imag = opt.gotOption("i");
xName = opt.optionValue("x");
xLow = opt.optionValue<double>("l");
yName = opt.optionValue("y");
spacing = opt.optionValue<double>("spacing");
save = opt.optionValue("s");
title = opt.optionValue("t");
outFileName = opt.optionValue<string>("o");
if(plotFileName.find(".h5") == string::npos)
{
inFileName = readManifest(plotFileName);
}
// load and plot file(s) /////////////////////////////////////////////////////////
DMatSample tmp;
Index nt;
Plot p;
DVec tAxis;
if(inFileName.size() == 0)
{
tmp = Io::load<DMatSample>(plotFileName);
nt = tmp[central].rows();
if(imag)
{
tmp = tmp.block(0, 1, nt, 1);
}
else
{
tmp = tmp.block(0, 0, nt, 1);
}
xHigh= xLow+spacing*(nt-1);
tAxis.setLinSpaced(nt, xLow, xHigh);
p << PlotData(tAxis, tmp);
}
else
{
tmp = Io::load<DMatSample>(inFileName[0]);
nt = tmp[central].rows();
xHigh= xLow+spacing*(nt-1);
tAxis.setLinSpaced(nt, xLow, xHigh);
for(unsigned long i = 0; i < inFileName.size(); i++)
{
plotFileName = inFileName[i];
tmp = Io::load<DMatSample>(plotFileName);
if(imag)
{
tmp = tmp.block(0, 1, nt, 1);
}
else
{
tmp = tmp.block(0, 0, nt, 1);
}
p << PlotData(tAxis, tmp);
}
}
p << Label(xName, Axis::x);
p << Label(yName, Axis::y);
p << PlotRange(Axis::x, xLow, xHigh);
p << Caption(title);
if(save != "")
{
cout << "Saving plot and source code to " << save << endl;
p.save(save + "/" + title);
}
cout << "Displaying plot..." << endl;
p.display();
// output //////////////////////////////////////////////////////////////////
if (!outFileName.empty())
{
Io::save(tmp, outFileName);
cout << "File saved as: " << outFileName << endl;
}
return EXIT_SUCCESS;
}