MaCh3  2.2.3
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...

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 (SampleHandlerBase *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 GetStepScaleBasedOnLLHScan ()
 LLH scan is good first estimate of step scale. More...
 
void Run2DLLHScan ()
 Perform a 2D likelihood scan. More...
 
void RunSigmaVar ()
 Perform a 2D and 1D sigma var for all samples. More...
 
void RunSigmaVarFD ()
 Perform a 1D 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...
 

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 GetScaneRange (std::map< std::string, std::vector< double >> &scanRanges)
 YSP: Set up a mapping to store parameters with user-specified ranges, suggested by D. Barrow. 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)
 For comparison with P-Theta we usually have to apply different parameter values then usual 1, 3 sigma. More...
 
- Protected Attributes inherited from FitterBase
managerfitMan
 The manager. 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< SampleHandlerBase * > samples
 Sample holder. More...
 
unsigned int TotalNSamples
 Total number of samples used. 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...
 
std::unique_ptr< TRandom3 > random
 Random number. 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 14 of file fitters.cpp.

Member Function Documentation

◆ FitterBase()

Constructor.

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

Definition at line 27 of file FitterBase.cpp.

16  : fitMan(man) {
17 // *************************
18  AlgorithmName = "";
19  //Get mach3 modes from manager
20  random = std::make_unique<TRandom3>(Get<int>(fitMan->raw()["General"]["Seed"], __FILE__, __LINE__));
21 
22  // Counter of the accepted # of steps
23  accCount = 0;
24  step = 0;
25  stepStart = 0;
26 
27  clock = std::make_unique<TStopwatch>();
28  stepClock = std::make_unique<TStopwatch>();
29  #ifdef DEBUG
30  // Fit summary and debug info
31  debug = GetFromManager<bool>(fitMan->raw()["General"]["Debug"], false, __FILE__ , __LINE__);
32  #endif
33 
34  auto outfile = Get<std::string>(fitMan->raw()["General"]["OutputFile"], __FILE__ , __LINE__);
35  // Save output every auto_save steps
36  //you don't want this too often https://root.cern/root/html606/TTree_8cxx_source.html#l01229
37  auto_save = Get<int>(fitMan->raw()["General"]["MCMC"]["AutoSave"], __FILE__ , __LINE__);
38 
39  #ifdef MULTITHREAD
40  //KS: TODO This should help with performance when saving entries to ROOT file. I didn't have time to validate hence commented out
41  //Based on other tests it is really helpful
42  //ROOT::EnableImplicitMT();
43  #endif
44  // Set the output file
45  outputFile = M3::Open(outfile, "RECREATE", __FILE__, __LINE__);
46  outputFile->cd();
47  // Set output tree
48  outTree = new TTree("posteriors", "Posterior_Distributions");
49  // Auto-save every 200MB, the bigger the better https://root.cern/root/html606/TTree_8cxx_source.html#l01229
50  outTree->SetAutoSave(-200E6);
51 
52  FileSaved = false;
53  SettingsSaved = false;
54  OutputPrepared = false;
55 
56  //Create TDirectory
57  CovFolder = outputFile->mkdir("CovarianceFolder");
58  outputFile->cd();
59  SampleFolder = outputFile->mkdir("SampleFolder");
60  outputFile->cd();
61 
62  #ifdef DEBUG
63  // Prepare the output log file
64  if (debug) debugFile.open((outfile+".log").c_str());
65  #endif
66 
67  TotalNSamples = 0;
68  fTestLikelihood = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["FitTestLikelihood"], false, __FILE__ , __LINE__);
69 }
MaCh3Plotting::PlottingManager * man
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:146
int accCount
counts accepted steps
Definition: FitterBase.h:121
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:167
TFile * outputFile
Output.
Definition: FitterBase.h:149
manager * fitMan
The manager.
Definition: FitterBase.h:110
unsigned int step
current state
Definition: FitterBase.h:113
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:165
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:163
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:170
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:139
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:123
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:141
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:151
TDirectory * SampleFolder
Output sample folder.
Definition: FitterBase.h:153
unsigned int TotalNSamples
Total number of samples used.
Definition: FitterBase.h:133
int auto_save
auto save every N steps
Definition: FitterBase.h:157
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:160
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:155
YAML::Node const & raw()
Return config.
Definition: Manager.h:41
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 20 of file fitters.cpp.

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

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