MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
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"
13
14//KS: Joy of forward declaration https://gieseanw.wordpress.com/2018/02/25/the-joys-of-forward-declarations-results-from-the-real-world/
15class TRandom3;
16class TStopwatch;
17class TTree;
18class TGraphAsymmErrors;
19class TDirectory;
20
24 public:
27 FitterBase(manager * const fitMan);
29 virtual ~FitterBase();
30
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
63 virtual void StartFromPreviousFit(const std::string& FitName);
64
66 virtual inline std::string GetName()const {return "FitterBase";};
67 protected:
69 void ProcessMCMC();
70
72 void PrepareOutput();
73
75 void SaveOutput();
76
79 void SanitiseInputs();
80
82 void SaveSettings();
83
85 bool GetScaneRange(std::map<std::string, std::vector<double>>& scanRanges);
86
88 bool CheckSkipParameter(const std::vector<std::string>& SkipVector, const std::string& ParamName) const;
89
90
93
95 unsigned int step;
97 double logLCurr;
99 double logLProp;
101 double accProb;
106
108 std::vector<double> sample_llh;
110 std::vector<double> syst_llh;
111
113 std::vector<SampleHandlerBase*> samples;
115 unsigned int TotalNSamples;
116
118 std::vector<ParameterHandlerBase*> systematics;
119
121 std::unique_ptr<TStopwatch> clock;
123 std::unique_ptr<TStopwatch> stepClock;
125 double stepTime;
126
128 std::unique_ptr<TRandom3> random;
129
133 TDirectory *CovFolder;
135 TDirectory *SampleFolder;
137 TTree *outTree;
140
143
150
151 #ifdef DEBUG
153 bool debug;
155 std::ofstream debugFile;
156 #endif
157};
158
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:267
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:246
std::unique_ptr< TRandom3 > random
Random number.
Definition: FitterBase.h:128
std::vector< SampleHandlerBase * > samples
Sample holder.
Definition: FitterBase.h:113
int stepStart
step start if restarting
Definition: FitterBase.h:105
double logLProp
proposed likelihood
Definition: FitterBase.h:99
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:103
virtual std::string GetName() const
Get name of class.
Definition: FitterBase.h:66
bool OutputPrepared
Checks if output prepared not repeat some operations.
Definition: FitterBase.h:149
void SaveOutput()
Save output and close files.
Definition: FitterBase.cpp:221
TFile * outputFile
Output.
Definition: FitterBase.h:131
void SaveSettings()
Save the settings that the MCMC was run with.
Definition: FitterBase.cpp:82
manager * fitMan
The manager.
Definition: FitterBase.h:92
unsigned int step
current state
Definition: FitterBase.h:95
void PrepareOutput()
Prepare the output file.
Definition: FitterBase.cpp:148
bool SettingsSaved
Checks if setting saved not repeat some operations.
Definition: FitterBase.h:147
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:101
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:295
bool FileSaved
Checks if file saved not repeat some operations.
Definition: FitterBase.h:145
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:108
void RunSigmaVar()
Perform a 2D and 1D sigma var for all samples.
double stepTime
Time of single step.
Definition: FitterBase.h:125
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
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:115
double logLCurr
current likelihood
Definition: FitterBase.h:97
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:110
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
virtual ~FitterBase()
Destructor for the FitterBase class.
Definition: FitterBase.cpp:71
TTree * outTree
Output tree with posteriors.
Definition: FitterBase.h:137
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
Definition: FitterBase.cpp:213
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
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
Definition: FitterBase.h:118
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