MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
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.
 
std::string GetName () const override
 Get name of class.
 
 FitterBase (manager *const fitMan)
 Constructor.
 
- Public Member Functions inherited from FitterBase
 FitterBase (manager *const fitMan)
 Constructor.
 
virtual ~FitterBase ()
 Destructor for the FitterBase class.
 
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.
 
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.
 
virtual void RunMCMC ()=0
 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.
 
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.
 
void RunLLHScan ()
 Perform a 1D likelihood scan.
 
void GetStepScaleBasedOnLLHScan ()
 LLH scan is good first estimate of step scale.
 
void Run2DLLHScan ()
 Perform a 2D likelihood scan.
 
void RunSigmaVar ()
 Perform a 2D and 1D sigma var for all samples.
 
virtual void StartFromPreviousFit (const std::string &FitName)
 Allow to start from previous fit/chain.
 
virtual std::string GetName () const
 Get name of class.
 

Additional Inherited Members

- Protected Member Functions inherited from FitterBase
void ProcessMCMC ()
 Process MCMC output.
 
void PrepareOutput ()
 Prepare the output file.
 
void SaveOutput ()
 Save output and close files.
 
void SanitiseInputs ()
 Remove obsolete memory and make other checks before fit starts.
 
void SaveSettings ()
 Save the settings that the MCMC was run with.
 
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.
 
bool CheckSkipParameter (const std::vector< std::string > &SkipVector, const std::string &ParamName) const
 KS: Check whether we want to skip parameter using skip vector.
 
- Protected Attributes inherited from FitterBase
managerfitMan
 The manager.
 
unsigned int step
 current state
 
double logLCurr
 current likelihood
 
double logLProp
 proposed likelihood
 
double accProb
 current acceptance prob
 
int accCount
 counts accepted steps
 
int stepStart
 step start if restarting
 
std::vector< double > sample_llh
 store the llh breakdowns
 
std::vector< double > syst_llh
 systematic llh breakdowns
 
std::vector< SampleHandlerBase * > samples
 Sample holder.
 
unsigned int TotalNSamples
 Total number of samples used.
 
std::vector< ParameterHandlerBase * > systematics
 Systematic holder.
 
std::unique_ptr< TStopwatch > clock
 tells global time how long fit took
 
std::unique_ptr< TStopwatch > stepClock
 tells how long single step/fit iteration took
 
double stepTime
 Time of single step.
 
std::unique_ptr< TRandom3 > random
 Random number.
 
TFile * outputFile
 Output.
 
TDirectory * CovFolder
 Output cov folder.
 
TDirectory * SampleFolder
 Output sample folder.
 
TTree * outTree
 Output tree with posteriors.
 
int auto_save
 auto save every N steps
 
bool fTestLikelihood
 Necessary for some fitting algorithms like PSO.
 
bool FileSaved
 Checks if file saved not repeat some operations.
 
bool SettingsSaved
 Checks if setting saved not repeat some operations.
 
bool OutputPrepared
 Checks if output prepared not repeat some operations.
 

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 13 of file fitters.cpp.

Member Function Documentation

◆ FitterBase()

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ FitterBase::FitterBase ( manager *const  fitMan)

Constructor.

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

Definition at line 27 of file FitterBase.cpp.

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

◆ GetName()

std::string PyFitterBase::GetName ( ) const
inlineoverridevirtual

Get name of class.

Reimplemented from FitterBase.

Definition at line 28 of file fitters.cpp.

28 {
29 PYBIND11_OVERRIDE_PURE_NAME(
30 std::string, /* Return type */
31 FitterBase, /* Parent class */
32 "get_name", /* Python name*/
33 GetName /* Name of function in C++ (must match Python name) */
34 );
35 }
Base class for implementing fitting algorithms.
Definition: FitterBase.h:23
std::string GetName() const override
Get name of class.
Definition: fitters.cpp:28

◆ 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 19 of file fitters.cpp.

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

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