MaCh3  2.4.2
Reference Guide
FitterBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 // C++ includes
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 
8 // MaCh3 Includes
11 #include "Manager/Manager.h"
12 #include "Fitters/MCMCProcessor.h"
13 
14 //KS: Joy of forward declaration https://gieseanw.wordpress.com/2018/02/25/the-joys-of-forward-declarations-results-from-the-real-world/
15 class TRandom3;
16 class TStopwatch;
17 class TTree;
18 class TGraphAsymmErrors;
19 class TDirectory;
20 
26 class FitterBase {
27  public:
30  FitterBase(Manager * const fitMan);
32  virtual ~FitterBase();
33 
36  void AddSampleHandler(SampleHandlerBase* sample);
37 
41 
43  virtual void RunMCMC() = 0;
44 
47  void DragRace(const int NLaps = 100);
48 
50  void RunLLHScan();
51 
53  void RunLLHMap();
54 
57 
60  void Run2DLLHScan();
61 
63  void RunSigmaVar();
64 
67  virtual void StartFromPreviousFit(const std::string& FitName);
68 
70  inline std::string GetName() const {return AlgorithmName;};
71  protected:
73  void ProcessMCMC();
74 
76  void PrepareOutput();
77 
79  void SaveOutput();
80 
83  void SanitiseInputs();
84 
86  void SaveSettings();
87 
90  bool GetScanRange(std::map<std::string, std::vector<double>>& scanRanges) const;
92  void GetParameterScanRange(const ParameterHandlerBase* cov, const int i, double& CentralValue,
93  double& lower, double& upper, const int n_points, const std::string& suffix = "") const;
95  bool CheckSkipParameter(const std::vector<std::string>& SkipVector, const std::string& ParamName) const;
96 
105  void CustomRange(const std::string& ParName, const double sigma, double& ParamShiftValue) const;
106 
109 
111  unsigned int step;
113  double logLCurr;
115  double logLProp;
117  double accProb;
119  int accCount;
121  unsigned int stepStart;
122 
124  std::vector<double> sample_llh;
126  std::vector<double> syst_llh;
127 
129  std::vector<SampleHandlerBase*> samples;
131  unsigned int TotalNSamples;
132 
134  std::vector<ParameterHandlerBase*> systematics;
135 
137  std::unique_ptr<TStopwatch> clock;
139  std::unique_ptr<TStopwatch> stepClock;
141  double stepTime;
142 
144  std::unique_ptr<TRandom3> random;
145 
147  TFile *outputFile;
149  TDirectory *CovFolder;
151  TDirectory *SampleFolder;
153  TTree *outTree;
156 
159 
161  bool FileSaved;
166 
168  std::string AlgorithmName;
169 
170  #ifdef DEBUG
172  bool debug;
174  std::ofstream debugFile;
175  #endif
176 };
177 
Base class for implementing fitting algorithms.
Definition: FitterBase.h:26
void RunLLHScan()
Perform a 1D likelihood scan.
Definition: FitterBase.cpp:622
FitterBase(Manager *const fitMan)
Constructor.
Definition: FitterBase.cpp:16
void AddSystObj(ParameterHandlerBase *cov)
This function adds a Covariance object to the analysis framework. The Covariance object will be utili...
Definition: FitterBase.cpp:298
std::string GetName() const
Get name of class.
Definition: FitterBase.h:70
void AddSampleHandler(SampleHandlerBase *sample)
This function adds a sample PDF object to the analysis framework. The sample PDF object will be utili...
Definition: FitterBase.cpp:262
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:144
std::vector< SampleHandlerBase * > samples
Sample holder.
Definition: FitterBase.h:129
double logLProp
proposed likelihood
Definition: FitterBase.h:115
bool CheckSkipParameter(const std::vector< std::string > &SkipVector, const std::string &ParamName) const
KS: Check whether we want to skip parameter using skip vector.
Definition: FitterBase.cpp:543
void ProcessMCMC()
Process MCMC output.
Definition: FitterBase.cpp:414
int accCount
counts accepted steps
Definition: FitterBase.h:119
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:165
void SaveOutput()
Save output and close files.
Definition: FitterBase.cpp:231
TFile * outputFile
Output.
Definition: FitterBase.h:147
void SaveSettings()
Save the settings that the MCMC was run with.
Definition: FitterBase.cpp:79
unsigned int step
current state
Definition: FitterBase.h:111
void PrepareOutput()
Prepare the output file.
Definition: FitterBase.cpp:153
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:163
virtual void RunMCMC()=0
The specific fitting algorithm implemented in this function depends on the derived class....
double accProb
current acceptance prob
Definition: FitterBase.h:117
void GetStepScaleBasedOnLLHScan()
LLH scan is good first estimate of step scale.
Definition: FitterBase.cpp:887
virtual void StartFromPreviousFit(const std::string &FitName)
Allow to start from previous fit/chain.
Definition: FitterBase.cpp:348
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:161
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:168
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:124
void RunSigmaVar()
Perform a 1D/2D sigma var for all samples.
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.
Definition: FitterBase.cpp:559
double stepTime
Time of single step.
Definition: FitterBase.h:141
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:137
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:108
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:121
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....
Definition: FitterBase.cpp:523
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:139
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:149
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 parame...
TDirectory * SampleFolder
Output sample folder.
Definition: FitterBase.h:151
void DragRace(const int NLaps=100)
Calculates the required time for each sample or covariance object in a drag race simulation....
Definition: FitterBase.cpp:461
void Run2DLLHScan()
Perform a 2D likelihood scan.
Definition: FitterBase.cpp:936
unsigned int TotalNSamples
Total number of samples used, single SampleHandler can store more than one analysis sample!
Definition: FitterBase.h:131
double logLCurr
current likelihood
Definition: FitterBase.h:113
void RunLLHMap()
Perform a general multi-dimensional likelihood scan.
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:126
int auto_save
auto save every N steps
Definition: FitterBase.h:155
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:158
virtual ~FitterBase()
Destructor for the FitterBase class.
Definition: FitterBase.cpp:68
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:153
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
Definition: FitterBase.cpp:223
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
Definition: FitterBase.h:134
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
Base class responsible for handling of systematic error parameters. Capable of using PCA or using ada...
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...