MaCh3  2.2.3
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 
23 class FitterBase {
24  public:
27  FitterBase(manager * const fitMan);
29  virtual ~FitterBase();
30 
33  void AddSampleHandler(SampleHandlerBase* sample);
34 
38 
40  virtual void RunMCMC() = 0;
41 
44  void DragRace(const int NLaps = 100);
45 
47  void RunLLHScan();
48 
51 
54  void Run2DLLHScan();
55 
58  void RunSigmaVar();
59 
62  void RunSigmaVarFD();
63 
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 
89  bool GetScaneRange(std::map<std::string, std::vector<double>>& scanRanges);
90 
92  bool CheckSkipParameter(const std::vector<std::string>& SkipVector, const std::string& ParamName) const;
93 
94 
107  void CustomRange(const std::string& ParName, const double sigma, double& ParamShiftValue);
108 
111 
113  unsigned int step;
115  double logLCurr;
117  double logLProp;
119  double accProb;
121  int accCount;
123  unsigned int stepStart;
124 
126  std::vector<double> sample_llh;
128  std::vector<double> syst_llh;
129 
131  std::vector<SampleHandlerBase*> samples;
133  unsigned int TotalNSamples;
134 
136  std::vector<ParameterHandlerBase*> systematics;
137 
139  std::unique_ptr<TStopwatch> clock;
141  std::unique_ptr<TStopwatch> stepClock;
143  double stepTime;
144 
146  std::unique_ptr<TRandom3> random;
147 
149  TFile *outputFile;
151  TDirectory *CovFolder;
153  TDirectory *SampleFolder;
155  TTree *outTree;
158 
161 
163  bool FileSaved;
168 
170  std::string AlgorithmName;
171 
172  #ifdef DEBUG
174  bool debug;
176  std::ofstream debugFile;
177  #endif
178 };
179 
Base class for implementing fitting algorithms.
Definition: FitterBase.h:23
void RunLLHScan()
Perform a 1D likelihood scan.
Definition: FitterBase.cpp:516
void AddSystObj(ParameterHandlerBase *cov)
This function adds a Covariance object to the analysis framework. The Covariance object will be utili...
Definition: FitterBase.cpp:276
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:255
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:146
std::vector< SampleHandlerBase * > samples
Sample holder.
Definition: FitterBase.h:131
double logLProp
proposed likelihood
Definition: FitterBase.h:117
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:500
void ProcessMCMC()
Process MCMC output.
Definition: FitterBase.cpp:371
int accCount
counts accepted steps
Definition: FitterBase.h:121
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:167
void SaveOutput()
Save output and close files.
Definition: FitterBase.cpp:230
TFile * outputFile
Output.
Definition: FitterBase.h:149
void SaveSettings()
Save the settings that the MCMC was run with.
Definition: FitterBase.cpp:84
manager * fitMan
The manager.
Definition: FitterBase.h:110
unsigned int step
current state
Definition: FitterBase.h:113
void PrepareOutput()
Prepare the output file.
Definition: FitterBase.cpp:155
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:165
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:119
void GetStepScaleBasedOnLLHScan()
LLH scan is good first estimate of step scale.
Definition: FitterBase.cpp:826
virtual void StartFromPreviousFit(const std::string &FitName)
Allow to start from previous fit/chain.
Definition: FitterBase.cpp:304
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:163
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:170
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:126
void RunSigmaVar()
Perform a 2D and 1D sigma var for all samples.
double stepTime
Time of single step.
Definition: FitterBase.h:143
std::unique_ptr< TStopwatch > clock
tells global time how long fit took
Definition: FitterBase.h:139
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
Definition: FitterBase.h:123
void CustomRange(const std::string &ParName, const double sigma, double &ParamShiftValue)
For comparison with P-Theta we usually have to apply different parameter values then usual 1,...
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
Definition: FitterBase.h:141
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....
Definition: FitterBase.cpp:480
TDirectory * CovFolder
Output cov folder.
Definition: FitterBase.h:151
TDirectory * SampleFolder
Output sample folder.
Definition: FitterBase.h:153
void DragRace(const int NLaps=100)
Calculates the required time for each sample or covariance object in a drag race simulation....
Definition: FitterBase.cpp:418
void Run2DLLHScan()
Perform a 2D likelihood scan.
Definition: FitterBase.cpp:875
unsigned int TotalNSamples
Total number of samples used.
Definition: FitterBase.h:133
double logLCurr
current likelihood
Definition: FitterBase.h:115
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:128
int auto_save
auto save every N steps
Definition: FitterBase.h:157
FitterBase(manager *const fitMan)
Constructor.
Definition: FitterBase.cpp:16
bool fTestLikelihood
Necessary for some fitting algorithms like PSO.
Definition: FitterBase.h:160
virtual ~FitterBase()
Destructor for the FitterBase class.
Definition: FitterBase.cpp:73
void RunSigmaVarFD()
Perform a 1D sigma var for all samples.
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:155
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
Definition: FitterBase.cpp:222
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
Definition: FitterBase.h:136
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 ...
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16