MaCh3  2.6.0
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 
29 class FitterBase {
30  public:
33  FitterBase(Manager * const fitMan);
35  virtual ~FitterBase();
36 
40 
44 
46  virtual void RunMCMC() = 0;
47 
50  void DragRace(const int NLaps = 100);
51 
53  void RunLLHScan();
54 
57  void RunLLHMap();
58 
61  void GetStepScaleBasedOnLLHScan(const std::string& filename = "");
62 
65  void Run2DLLHScan();
66 
68  void RunSigmaVar();
69 
72  virtual void StartFromPreviousFit(const std::string& FitName);
73 
75  std::string GetName() const {return AlgorithmName;};
76  protected:
78  void ProcessMCMC();
79 
81  void PrepareOutput();
82 
84  void SaveOutput();
85 
88  void SanitiseInputs();
89 
91  void SaveSettings();
92 
95  bool GetScanRange(std::map<std::string, std::vector<double>>& scanRanges) const;
97  void GetParameterScanRange(const ParameterHandlerBase* cov, const int i, double& CentralValue,
98  double& lower, double& upper, const int n_points, const std::string& suffix = "") const;
100  bool CheckSkipParameter(const std::vector<std::string>& SkipVector, const std::string& ParamName) const;
101 
110  void CustomRange(const std::string& ParName, const double sigma, double& ParamShiftValue) const;
111 
114 
116  unsigned int step;
118  double logLCurr;
120  double logLProp;
122  double accProb;
124  int accCount;
126  unsigned int stepStart;
127 
129  std::vector<double> sample_llh;
131  std::vector<double> syst_llh;
132 
134  std::vector<SampleHandlerInterface*> samples;
136  unsigned int TotalNSamples;
137 
139  std::vector<ParameterHandlerBase*> systematics;
140 
142  std::unique_ptr<TStopwatch> clock;
144  std::unique_ptr<TStopwatch> stepClock;
146  double stepTime;
147 
149  std::unique_ptr<TRandom3> random;
150 
152  TFile *outputFile;
154  TDirectory *CovFolder;
156  TDirectory *SampleFolder;
158  TTree *outTree;
161 
164 
166  bool FileSaved;
171 
173  std::string AlgorithmName;
174 
175  #ifdef MACH3_DEBUG
177  bool debug;
179  std::ofstream debugFile;
180  #endif
181 };
182 
Base class for implementing fitting algorithms.
Definition: FitterBase.h:29
void RunLLHScan()
Perform a 1D likelihood scan.
Definition: FitterBase.cpp:603
FitterBase(Manager *const fitMan)
Constructor.
Definition: FitterBase.cpp:15
void AddSystObj(ParameterHandlerBase *cov)
This function adds a Covariance object to the analysis framework. The Covariance object will be utili...
Definition: FitterBase.cpp:296
std::string GetName() const
Get name of class.
Definition: FitterBase.h:75
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:149
double logLProp
proposed likelihood
Definition: FitterBase.h:120
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:533
void ProcessMCMC()
Process MCMC output.
Definition: FitterBase.cpp:404
int accCount
counts accepted steps
Definition: FitterBase.h:124
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:170
void SaveOutput()
Save output and close files.
Definition: FitterBase.cpp:229
TFile * outputFile
Output.
Definition: FitterBase.h:152
void SaveSettings()
Save the settings that the MCMC was run with.
Definition: FitterBase.cpp:77
unsigned int step
current state
Definition: FitterBase.h:116
void PrepareOutput()
Prepare the output file.
Definition: FitterBase.cpp:151
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:168
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:122
virtual void StartFromPreviousFit(const std::string &FitName)
Allow to start from previous fit/chain.
Definition: FitterBase.cpp:346
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:166
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:173
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:129
void RunSigmaVar()
Perform a 1D/2D sigma var for all samples.
std::vector< SampleHandlerInterface * > samples
Sample holder.
Definition: FitterBase.h:134
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:540
double stepTime
Time of single step.
Definition: FitterBase.h:146
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:142
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:113
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:126
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:513
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:144
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:154
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:156
void DragRace(const int NLaps=100)
Calculates the required time for each sample or covariance object in a drag race simulation....
Definition: FitterBase.cpp:451
void Run2DLLHScan()
Perform a 2D likelihood scan.
Definition: FitterBase.cpp:930
unsigned int TotalNSamples
Total number of samples used, single SampleHandler can store more than one analysis sample!
Definition: FitterBase.h:136
double logLCurr
current likelihood
Definition: FitterBase.h:118
void RunLLHMap()
Perform a general multi-dimensional likelihood scan.
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:131
int auto_save
auto save every N steps
Definition: FitterBase.h:160
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:163
void GetStepScaleBasedOnLLHScan(const std::string &filename="")
LLH scan is good first estimate of step scale.
Definition: FitterBase.cpp:868
virtual ~FitterBase()
Destructor for the FitterBase class.
Definition: FitterBase.cpp:67
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:158
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
Definition: FitterBase.cpp:221
void AddSampleHandler(SampleHandlerInterface *sample)
This function adds a sample PDF object to the analysis framework. The sample PDF object will be utili...
Definition: FitterBase.cpp:260
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
Definition: FitterBase.h:139
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
Base class for handling systematic uncertainty parameters.
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...