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

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
ManagerfitMan
 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...
 
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 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.

18  : fitMan(man) {
19 // *************************
20  AlgorithmName = "";
21  //Get mach3 modes from Manager
22  random = std::make_unique<TRandom3>(Get<int>(fitMan->raw()["General"]["Seed"], __FILE__, __LINE__));
23 
24  // Counter of the accepted # of steps
25  accCount = 0;
26  step = 0;
27  stepStart = 0;
28 
29  clock = std::make_unique<TStopwatch>();
30  stepClock = std::make_unique<TStopwatch>();
31  #ifdef MACH3_DEBUG
32  // Fit summary and debug info
33  debug = GetFromManager<bool>(fitMan->raw()["General"]["Debug"], false, __FILE__ , __LINE__);
34  #endif
35 
36  auto outfile = Get<std::string>(fitMan->raw()["General"]["OutputFile"], __FILE__ , __LINE__);
37  // Save output every auto_save steps
38  //you don't want this too often https://root.cern/root/html606/TTree_8cxx_source.html#l01229
39  auto_save = Get<int>(fitMan->raw()["General"]["MCMC"]["AutoSave"], __FILE__ , __LINE__);
40 
41  // Set the output file
42  outputFile = M3::Open(outfile, "RECREATE", __FILE__, __LINE__);
43  outputFile->cd();
44  // Set output tree
45  outTree = new TTree("posteriors", "Posterior_Distributions");
46  // Auto-save every 200MB, the bigger the better https://root.cern/root/html606/TTree_8cxx_source.html#l01229
47  outTree->SetAutoSave(-200E6);
48 
49  FileSaved = false;
50  SettingsSaved = false;
51  OutputPrepared = false;
52 
53  //Create TDirectory
54  CovFolder = outputFile->mkdir("CovarianceFolder");
55  outputFile->cd();
56  SampleFolder = outputFile->mkdir("SampleFolder");
57  outputFile->cd();
58 
59  #ifdef MACH3_DEBUG
60  // Prepare the output log file
61  if (debug) debugFile.open((outfile+".log").c_str());
62  #endif
63 
64  TotalNSamples = 0;
65  fTestLikelihood = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["FitTestLikelihood"], false, __FILE__ , __LINE__);
66 }
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:153
int accCount
counts accepted steps
Definition: FitterBase.h:128
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:120
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:146
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:117
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:130
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:148
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:140
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:47
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: