#include <apfel/timer.h>
#include <algorithm>
#include <fstream>
#include <sys/stat.h>
#include <cstring>
int main(int argc, char* argv[])
{
if (argc < 6 || strcmp(argv[1], "--help") == 0)
{
std::cout << "\nInvalid Parameters:" << std::endl;
std::cout << "Syntax: ./RunFit <output dir> <fit configuration file> <path to data folder> <path to tables folder> <replica ID>\n" << std::endl;
exit(-10);
}
apfel::Timer t;
YAML::Node fitconfig = YAML::LoadFile(argv[2]);
gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxs2);
gsl_rng_set(rng, fitconfig["Seed"].as<int>());
const int ReplicaID = atoi(argv[5]);
const std::string OutputFolder = std::string(argv[1]) + "/replica_" + std::string(argv[5]);
mkdir((OutputFolder).c_str(), ACCESSPERMS);
if (fitconfig["t0prescription"].as<bool>())
NPFunc->
SetParameters(fitconfig[
"t0parameters"].as<std::vector<double>>());
const YAML::Node datasets = YAML::LoadFile(std::string(argv[3]) + "/datasets.yaml");
for (auto const& exp : datasets)
for (auto const& ds : exp.second)
{
std::cout << "Reading table for " << ds["name"].as<std::string>() << "..." << std::endl;
fitconfig["cutParam"].as<std::vector<double>>()};
YAML::LoadFile(std::string(argv[3]) + "/" + exp.first.as<std::string>() + "/" + ds["file"].as<std::string>()),
rng, ReplicaID,
(fitconfig[
"t0prescription"].as<bool>() ? ct->GetPredictions(NPFunc->
Function()) : std::vector<double>{})};
chi2.AddBlock(std::make_pair(dh, ct));
}
t.stop();
t.start();
bool status;
if (fitconfig["Minimiser"].as<std::string>() == "none")
else if (fitconfig["Minimiser"].as<std::string>() == "minuit")
status =
MinuitMinimiser(chi2, fitconfig[
"Parameters"], (fitconfig[
"Paramfluct"].as<bool>() ? rng : NULL));
else if (fitconfig["Minimiser"].as<std::string>() == "ceres")
status =
CeresMinimiser(chi2, fitconfig[
"Parameters"], (fitconfig[
"Paramfluct"].as<bool>() ? rng : NULL));
else if (fitconfig["Minimiser"].as<std::string>() == "scan")
status =
MinuitScan(chi2, fitconfig[
"Parameters"], std::string(argv[1]));
else
throw std::runtime_error("[RunFit]: Unknown minimiser");
std::cout << "Total chi2 = " << chi2() << "\n" << std::endl;
YAML::Emitter out;
out << chi2;
std::ofstream rout(OutputFolder + "/Report.yaml");
rout << "Status: " << status << std::endl;
rout << out.c_str() << std::endl;
rout.close();
if (ReplicaID == 0)
{
const std::vector<double> pars = chi2.GetParameters();
int i = 0;
for (auto p : fitconfig["Parameters"])
p["starting_value"] = pars[i++];
fitconfig["t0parameters"] = pars;
std::ofstream fout(OutputFolder + "/fitconfig.yaml");
fout << fitconfig;
fout.close();
}
gsl_rng_free(rng);
delete NPFunc;
t.stop();
return status;
}
The "ChiSquare" class computes the χ2's given a set of "DataHandler" objects and the corresponding "C...
Definition: chisquare.h:22
Class that implements the methods fot the numerical convolution of the interpolation tables with user...
Definition: convolutiontable.h:25
The "DataHandler" class provides a common interface to all datasets. It provides methods to get kinem...
Definition: datahandler.h:23
Mother class that implements the main feautures of a functional parameterisation of non-perturbative ...
Definition: parameterisation.h:20
virtual void SetParameters(std::vector< double > const &pars)
Function that sets the free parameters of the parameterisation.
Definition: parameterisation.h:41
std::function< double(double const &, double const &, double const &, int const &)> Function() const
Function that returns the parametrisation in the form of a std::function.
bool NoMinimiser(ChiSquare const &chi2, YAML::Node const ¶meters)
The "NoMinimiser" function simply returns predictions.
Parameterisation * GetParametersation(std::string const &name)
Utility function that returns a pointer to a NangaParbat::Parameterisation object pointing to a speci...
bool CeresMinimiser(ChiSquare const &chi2, YAML::Node const ¶meters, gsl_rng *rng=NULL)
The "CeresMinimiser" function using ceres-solver.
bool MinuitMinimiser(ChiSquare const &chi2, YAML::Node const ¶meters, gsl_rng *rng=NULL)
The "MinuitMinimiser" function using Minuit2 as implemented in ROOT.
bool MinuitScan(ChiSquare const &chi2, YAML::Node const ¶meters, std::string const &outfolder)
The "MinuitScan" function performs a scan around the parameters using Minuit2.