MaCh3  2.8.0
Reference Guide
Public Member Functions | List of all members
PyFitterBase Class Reference

EW: As FitterBase is an abstract base class we have to do some gymnastics to get it to get it into python. More...

#include <python/fitters.h>

Inheritance diagram for PyFitterBase:
[legend]
Collaboration diagram for PyFitterBase:
[legend]

Public Member Functions

void RunMCMC () override
 The specific fitting algorithm implemented in this function depends on the derived class. It could be Markov Chain Monte Carlo (MCMC), MinuitFit, or another algorithm. More...
 
 FitterBase (Manager *const fitMan)
 Constructor. More...
 
- Public Member Functions inherited from FitterBase
 FitterBase (Manager *const fitMan)
 Constructor. More...
 
virtual ~FitterBase ()
 Destructor for the FitterBase class. More...
 
void AddSampleHandler (SampleHandlerInterface *sample)
 This function adds a sample PDF object to the analysis framework. The sample PDF object will be utilized in fitting procedures or likelihood scans. More...
 
void AddSystObj (ParameterHandlerBase *cov)
 This function adds a Covariance object to the analysis framework. The Covariance object will be utilized in fitting procedures or likelihood scans. More...
 
void DragRace (const int NLaps=100)
 Calculates the required time for each sample or covariance object in a drag race simulation. Inspired by Dan's feature. More...
 
void RunLLHScan ()
 Perform a 1D likelihood scan. More...
 
void RunLLHMap ()
 Perform a general multi-dimensional likelihood scan. More...
 
void GetStepScaleBasedOnLLHScan (const std::string &filename="")
 LLH scan is good first estimate of step scale. More...
 
void Run2DLLHScan ()
 Perform a 2D likelihood scan. More...
 
void RunSigmaVar ()
 Perform a 1D/2D sigma var for all samples. More...
 
virtual void StartFromPreviousFit (const std::string &FitName)
 Allow to start from previous fit/chain. More...
 
std::string GetName () const
 Get name of class. More...
 
virtual std::string GetFancyName () const
 This name is to get include some special algorithm extensions. More...
 

Additional Inherited Members

- Protected Member Functions inherited from FitterBase
void ProcessMCMC ()
 Process MCMC output. More...
 
void PrepareOutput ()
 Prepare the output file. More...
 
void SaveOutput ()
 Save output and close files. More...
 
void SanitiseInputs ()
 Remove obsolete memory and make other checks before fit starts. More...
 
void SaveSettings ()
 Save the settings that the MCMC was run with. More...
 
bool GetScanRange (std::map< std::string, std::vector< double >> &scanRanges) const
 YSP: Set up a mapping to store parameters with user-specified ranges, suggested by D. Barrow. More...
 
void GetParameterScanRange (const ParameterHandlerBase *cov, const int i, double &CentralValue, double &lower, double &upper, const int n_points, const std::string &suffix="") const
 Helper function to get parameter scan range, central value. More...
 
bool CheckSkipParameter (const std::vector< std::string > &SkipVector, const std::string &ParamName) const
 KS: Check whether we want to skip parameter using skip vector. More...
 
void CustomRange (const std::string &ParName, const double sigma, double &ParamShiftValue) const
 For comparison with other fitting frameworks (like P-Theta) we usually have to apply different parameter values then usual 1, 3 sigma. More...
 
std::vector< double > CalculateBinEdges (double lowerlimit, double upperlimit, int n_points) const
 
- Protected Attributes inherited from FitterBase
Manager * fitMan
 The manager for configuration handling. More...
 
unsigned int step
 current state More...
 
double logLCurr
 current likelihood More...
 
double logLProp
 proposed likelihood More...
 
double accProb
 current acceptance prob More...
 
int accCount
 counts accepted steps More...
 
unsigned int stepStart
 step start, by default 0 if we start from previous chain then it will be different More...
 
std::vector< double > sample_llh
 store the llh breakdowns More...
 
std::vector< double > syst_llh
 systematic llh breakdowns More...
 
std::vector< SampleHandlerInterface * > samples
 Sample holder. More...
 
unsigned int TotalNSamples
 Total number of samples used, single SampleHandler can store more than one analysis sample! More...
 
std::vector< ParameterHandlerBase * > systematics
 Systematic holder. More...
 
std::unique_ptr< TStopwatch > clock
 tells global time how long fit took More...
 
std::unique_ptr< TStopwatch > stepClock
 tells how long single step/fit iteration took More...
 
double stepTime
 Time of single step. More...
 
TFile * outputFile
 Output. More...
 
TDirectory * CovFolder
 Output cov folder. More...
 
TDirectory * SampleFolder
 Output sample folder. More...
 
TTree * outTree
 Output tree with posteriors. More...
 
int auto_save
 auto save every N steps More...
 
bool fTestLikelihood
 Necessary for some fitting algorithms like PSO. More...
 
bool FileSaved
 Checks if file saved not repeat some operations. More...
 
bool SettingsSaved
 Checks if setting saved not repeat some operations. More...
 
bool OutputPrepared
 Checks if output prepared not repeat some operations. More...
 
std::string AlgorithmName
 Name of fitting algorithm that is being used. More...
 

Detailed Description

EW: As FitterBase is an abstract base class we have to do some gymnastics to get it to get it into python.

Definition at line 19 of file fitters.h.

Member Function Documentation

◆ FitterBase()

Constructor.

Parameters
fitManA pointer to a manager object, which will handle all settings.

Definition at line 33 of file FitterBase.cpp.

17  : fitMan(man) {
18 // *************************
19  AlgorithmName = "";
20  //Get mach3 modes from Manager
21  auto Seed = Get<int>(fitMan->raw()["General"]["Seed"], __FILE__, __LINE__);
22  M3::rand::SetSeed(Seed);
23  // Counter of the accepted # of steps
24  accCount = 0;
25  step = 0;
26  stepStart = 0;
27 
28  clock = std::make_unique<TStopwatch>();
29  stepClock = std::make_unique<TStopwatch>();
30  #ifdef MACH3_DEBUG
31  // Fit summary and debug info
32  debug = GetFromManager<bool>(fitMan->raw()["General"]["Debug"], false, __FILE__ , __LINE__);
33  #endif
34 
35  auto outfile = Get<std::string>(fitMan->raw()["General"]["OutputFile"], __FILE__ , __LINE__);
36  // Save output every auto_save steps
37  //you don't want this too often https://root.cern/root/html606/TTree_8cxx_source.html#l01229
38  auto_save = Get<int>(fitMan->raw()["General"]["MCMC"]["AutoSave"], __FILE__ , __LINE__);
39 
40  // Set the output file
41  outputFile = M3::Open(outfile, "RECREATE", __FILE__, __LINE__);
42  outputFile->cd();
43  // Set output tree
44  outTree = new TTree("posteriors", "Posterior_Distributions");
45  // Auto-save every 200MB, the bigger the better https://root.cern/root/html606/TTree_8cxx_source.html#l01229
46  outTree->SetAutoSave(-200E6);
47 
48  FileSaved = false;
49  SettingsSaved = false;
50  OutputPrepared = false;
51 
52  //Create TDirectory
53  CovFolder = outputFile->mkdir("CovarianceFolder");
54  outputFile->cd();
55  SampleFolder = outputFile->mkdir("SampleFolder");
56  outputFile->cd();
57 
58  #ifdef MACH3_DEBUG
59  // Prepare the output log file
60  if (debug) debugFile.open((outfile+".log").c_str());
61  #endif
62 
63  TotalNSamples = 0;
64  fTestLikelihood = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["FitTestLikelihood"], false, __FILE__ , __LINE__);
65 }
int accCount
counts accepted steps
Definition: FitterBase.h:131
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:174
TFile * outputFile
Output.
Definition: FitterBase.h:156
unsigned int step
current state
Definition: FitterBase.h:123
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:172
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:170
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:177
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:149
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:120
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:133
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:151
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:158
TDirectory * SampleFolder
Output sample folder.
Definition: FitterBase.h:160
unsigned int TotalNSamples
Total number of samples used, single SampleHandler can store more than one analysis sample!
Definition: FitterBase.h:143
int auto_save
auto save every N steps
Definition: FitterBase.h:164
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:167
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:162
YAML::Node const & raw() const
Return config.
Definition: Manager.h:48
void SetSeed(const std::uint64_t seed)
Set the global random seed.
Definition: Random.h:111
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.

◆ RunMCMC()

void PyFitterBase::RunMCMC ( )
inlineoverridevirtual

The specific fitting algorithm implemented in this function depends on the derived class. It could be Markov Chain Monte Carlo (MCMC), MinuitFit, or another algorithm.

Implements FitterBase.

Definition at line 25 of file fitters.h.

25  {
26  PYBIND11_OVERRIDE_PURE_NAME(
27  void, /* Return type */
28  FitterBase, /* Parent class */
29  "run", /* Python name*/
30  RunMCMC /* Name of function in C++ (must match Python name) */
31  );
32  }
Base class for implementing fitting algorithms.
Definition: FitterBase.h:29
void RunMCMC() override
The specific fitting algorithm implemented in this function depends on the derived class....
Definition: fitters.h:25

The documentation for this class was generated from the following file: