MaCh3  2.5.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 
26 class FitterBase {
27  public:
30  FitterBase(Manager * const fitMan);
32  virtual ~FitterBase();
33 
37 
41 
43  virtual void RunMCMC() = 0;
44 
47  void DragRace(const int NLaps = 100);
48 
50  void RunLLHScan();
51 
54  void RunLLHMap();
55 
57  void GetStepScaleBasedOnLLHScan(const std::string& filename = "");
58 
61  void Run2DLLHScan();
62 
64  void RunSigmaVar();
65 
68  virtual void StartFromPreviousFit(const std::string& FitName);
69 
71  inline std::string GetName() const {return AlgorithmName;};
72  protected:
74  void ProcessMCMC();
75 
77  void PrepareOutput();
78 
80  void SaveOutput();
81 
84  void SanitiseInputs();
85 
87  void SaveSettings();
88 
91  bool GetScanRange(std::map<std::string, std::vector<double>>& scanRanges) const;
93  void GetParameterScanRange(const ParameterHandlerBase* cov, const int i, double& CentralValue,
94  double& lower, double& upper, const int n_points, const std::string& suffix = "") const;
96  bool CheckSkipParameter(const std::vector<std::string>& SkipVector, const std::string& ParamName) const;
97 
106  void CustomRange(const std::string& ParName, const double sigma, double& ParamShiftValue) const;
107 
110 
112  unsigned int step;
114  double logLCurr;
116  double logLProp;
118  double accProb;
120  int accCount;
122  unsigned int stepStart;
123 
125  std::vector<double> sample_llh;
127  std::vector<double> syst_llh;
128 
130  std::vector<SampleHandlerInterface*> samples;
132  unsigned int TotalNSamples;
133 
135  std::vector<ParameterHandlerBase*> systematics;
136 
138  std::unique_ptr<TStopwatch> clock;
140  std::unique_ptr<TStopwatch> stepClock;
142  double stepTime;
143 
145  std::unique_ptr<TRandom3> random;
146 
148  TFile *outputFile;
150  TDirectory *CovFolder;
152  TDirectory *SampleFolder;
154  TTree *outTree;
157 
160 
162  bool FileSaved;
167 
169  std::string AlgorithmName;
170 
171  #ifdef MACH3_DEBUG
173  bool debug;
175  std::ofstream debugFile;
176  #endif
177 };
178 
Base class for implementing fitting algorithms.
Definition: FitterBase.h:26
void RunLLHScan()
Perform a 1D likelihood scan.
Definition: FitterBase.cpp:620
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:71
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:145
double logLProp
proposed likelihood
Definition: FitterBase.h:116
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:541
void ProcessMCMC()
Process MCMC output.
Definition: FitterBase.cpp:412
int accCount
counts accepted steps
Definition: FitterBase.h:120
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:166
void SaveOutput()
Save output and close files.
Definition: FitterBase.cpp:229
TFile * outputFile
Output.
Definition: FitterBase.h:148
void SaveSettings()
Save the settings that the MCMC was run with.
Definition: FitterBase.cpp:77
unsigned int step
current state
Definition: FitterBase.h:112
void PrepareOutput()
Prepare the output file.
Definition: FitterBase.cpp:151
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:164
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:118
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:162
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:169
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:125
void RunSigmaVar()
Perform a 1D/2D sigma var for all samples.
std::vector< SampleHandlerInterface * > samples
Sample holder.
Definition: FitterBase.h:130
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:557
double stepTime
Time of single step.
Definition: FitterBase.h:142
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:138
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:109
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:122
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:521
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:140
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:150
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:152
void DragRace(const int NLaps=100)
Calculates the required time for each sample or covariance object in a drag race simulation....
Definition: FitterBase.cpp:459
void Run2DLLHScan()
Perform a 2D likelihood scan.
Definition: FitterBase.cpp:944
unsigned int TotalNSamples
Total number of samples used, single SampleHandler can store more than one analysis sample!
Definition: FitterBase.h:132
double logLCurr
current likelihood
Definition: FitterBase.h:114
void RunLLHMap()
Perform a general multi-dimensional likelihood scan.
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:127
int auto_save
auto save every N steps
Definition: FitterBase.h:156
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:159
void GetStepScaleBasedOnLLHScan(const std::string &filename="")
LLH scan is good first estimate of step scale.
Definition: FitterBase.cpp:885
virtual ~FitterBase()
Destructor for the FitterBase class.
Definition: FitterBase.cpp:67
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:154
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:135
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 ...