MaCh3  2.6.1
Reference Guide
MCMCProcessor.h
Go to the documentation of this file.
1 #pragma once
2 
3 // C++ includes
4 #include <complex>
5 #include <cstdio>
6 
7 // MaCh3 includes
11 
13 // ROOT includes
14 #include "TFile.h"
15 #include "TBranch.h"
16 #include "TCanvas.h"
17 #include "TLine.h"
18 #include "TLegend.h"
19 #include "TString.h"
20 #include "TGraphErrors.h"
21 #include "TVectorD.h"
22 #include "TColor.h"
23 #include "TStyle.h"
24 #include "TStopwatch.h"
25 #include "TText.h"
26 #include "TGaxis.h"
27 #include "TTree.h"
28 #include "TROOT.h"
29 #include "TKey.h"
30 #include "TRandom3.h"
31 #include "TGraphPolar.h"
32 #include "TCandle.h"
33 #include "TMath.h"
34 #include "TMatrixDSymEigen.h"
36 
37 
38 //KS: Joy of forward declaration https://gieseanw.wordpress.com/2018/02/25/the-joys-of-forward-declarations-results-from-the-real-world/
39 class TChain;
40 class TF1;
41 class MCMCProcessorGPU;
42 
46  kXSecPar = 0,
47  kNDPar = 1,
48  kFDDetPar = 2,
49 
50  kNParameterEnum = 3 //KS: keep it at the end to keep track of all parameters
51 };
52 
62  public:
65  MCMCProcessor(const std::string &InputFile);
67  virtual ~MCMCProcessor();
68 
70  void Initialise();
72  void MakePostfit(const std::map<std::string, std::pair<double, double>>& Edges = {});
75  void MakeCovariance();
77  void CacheSteps();
80  void MakeCovariance_MP(const bool Mute = false);
84  void MakeSubOptimality(const int NIntervals = 10);
85 
87  void Reset2DPosteriors();
88 
90  void DrawPostfit();
92  void MakeViolin();
97  void MakeCredibleIntervals(const std::vector<double>& CredibleIntervals = {0.99, 0.90, 0.68 },
98  const std::vector<Color_t>& CredibleIntervalsColours = {kCyan+4, kCyan-2, kCyan-10},
99  const bool CredibleInSigmas = false
100  );
102  void DrawCovariance();
104  void MakeCovarianceYAML(const std::string& OutputYAMLFile, const std::string& MeansMethod) const;
112  void MakeCredibleRegions(const std::vector<double>& CredibleRegions = {0.99, 0.90, 0.68},
113  const std::vector<Style_t>& CredibleRegionStyle = {kDashed, kSolid, kDotted},
114  const std::vector<Color_t>& CredibleRegionColor = {kGreen-3, kGreen-10, kGreen},
115  const bool CredibleInSigmas = false,
116  const bool Draw2DPosterior = true,
117  const bool DrawBestFit = true
118  );
127  void MakeTrianglePlot(const std::vector<std::string>& ParNames,
128  // 1D
129  const std::vector<double>& CredibleIntervals = {0.99, 0.90, 0.68 },
130  const std::vector<Color_t>& CredibleIntervalsColours = {kCyan+4, kCyan-2, kCyan-10},
131  //2D
132  const std::vector<double>& CredibleRegions = {0.99, 0.90, 0.68},
133  const std::vector<Style_t>& CredibleRegionStyle = {kDashed, kSolid, kDotted},
134  const std::vector<Color_t>& CredibleRegionColor = {kGreen-3, kGreen-10, kGreen},
135  // Other
136  const bool CredibleInSigmas = false
137  );
138 
143  void CheckCredibleIntervalsOrder(const std::vector<double>& CredibleIntervals, const std::vector<Color_t>& CredibleIntervalsColours) const;
144 
150  void CheckCredibleRegionsOrder(const std::vector<double>& CredibleRegions,
151  const std::vector<Style_t>& CredibleRegionStyle,
152  const std::vector<Color_t>& CredibleRegionColor);
153 
156  void GetPolarPlot(const std::vector<std::string>& ParNames);
157 
163  void GetBayesFactor(const std::vector<std::string>& ParName,
164  const std::vector<std::vector<double>>& Model1Bounds,
165  const std::vector<std::vector<double>>& Model2Bounds,
166  const std::vector<std::vector<std::string>>& ModelNames);
168  void GetSavageDickey(const std::vector<std::string>& ParName,
169  const std::vector<double>& EvaluationPoint,
170  const std::vector<std::vector<double>>& Bounds);
171 
177  void SavageDickeyPlot(std::unique_ptr<TH1D>& PriorHist,
178  std::unique_ptr<TH1D>& PosteriorHist,
179  const std::string& Title,
180  const double EvaluationPoint) const ;
181 
183  void ProduceChi2(const std::string& GroupName) const;
184 
191  void SmearChain(const std::vector<std::string>& Names,
192  const std::vector<double>& Error,
193  const bool& SaveBranch) const;
194 
198  void ParameterEvolution(const std::vector<std::string>& Names,
199  const std::vector<int>& NIntervals);
200 
203  void ThinMCMC(const int ThinningCut) const { ThinningMCMC(MCMCFile+".root", ThinningCut); };
204 
206  void DiagMCMC();
207 
208  // Get the number of parameters
210  int GetNParams() const { return nDraw; };
211  int GetNXSec() const { return nParam[kXSecPar]; };
212  int GetNND() const { return nParam[kNDPar]; };
213  int GetNFD() const { return nParam[kFDDetPar]; };
214 
216  YAML::Node GetCovConfig(const int i) const {return CovConfig.at(i); }
217 
219  int GetGroup(const std::string& name) const;
220 
223  TH1D* GetHpost(const int i) const { return hpost[i]; };
227  TH2D* GetHpost2D(const int i, const int j) const { return hpost2D[i][j]; };
229  TH2D* GetViolin() const { return hviolin.get(); };
231  TH2D* GetViolinPrior() const { return hviolin_prior.get(); };
232 
233  //Covariance getters
234  std::vector<std::string> GetXSecCov() const { return CovPos[kXSecPar]; };
235  std::string GetNDCov() const { return CovPos[kNDPar].back(); };
236  std::string GetFDCov() const { return CovPos[kFDDetPar].back(); };
237 
239  void GetPostfit(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Central_Gauss, TVectorD *&Errors_Gauss, TVectorD *&Peaks);
243  void GetCovariance(TMatrixDSym *&Cov, TMatrixDSym *&Corr);
245  void GetPostfit_Ind(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Peaks, ParameterEnum kParam);
246 
248  const std::vector<TString>& GetBranchNames() const { return BranchNames;};
250  const std::vector<TString>& GetSampleBranchNames() const { return SampleName_v;};
252  const std::vector<TString>& GetSystBranchNames() const { return SystName_v;};
253 
255  void GetNthParameter(const int param, double &Prior, double &PriorError, TString &Title) const;
257  int GetParamIndexFromName(const std::string& Name) const;
259  bool GetParamFlat(const int iParam) const;
261  Long64_t GetnEntries(){return nEntries;};
263  Long64_t GetnSteps(){return nSteps;};
265  void SetNBins(const int NewBins) {nBins = NewBins;};
266 
269  void SetEntries(const int NewEntries) {
270  if (NewEntries > nEntries) {
271  MACH3LOG_ERROR("Cannot increase entries from {} to {}. Only decreasing is allowed.", nEntries, NewEntries);
272  throw MaCh3Exception(__FILE__, __LINE__);
273  }
274  if (NewEntries <= 0) {
275  MACH3LOG_ERROR("Entries cannot be below 0, but {} was passed.", NewEntries);
276  throw MaCh3Exception(__FILE__, __LINE__);
277  }
278 
279  if (static_cast<int>(BurnInCut) > NewEntries) {
280  MACH3LOG_ERROR("BurnInCut ({}) is larger than NewEntries ({})", BurnInCut, NewEntries);
281  throw MaCh3Exception(__FILE__, __LINE__);
282  }
283 
284  MACH3LOG_INFO("Setting entries to {} from {}.", NewEntries, nEntries);
285  MACH3LOG_WARN("This may behave not as expected when using merged multiple chains");
286  nEntries = NewEntries;
287  }
289  void SetReweightNames(std::vector<std::string> NewName) { ReweightNames = NewName; }
292  void SetStepCut(const std::string& Cuts);
295  void SetStepCut(const int Cuts);
297  void CheckStepCut() const;
298 
301  void SetPlotRelativeToPrior(const bool PlotOrNot){plotRelativeToPrior = PlotOrNot; };
303  void SetPrintToPDF(const bool PlotOrNot){printToPDF = PlotOrNot; };
305  void SetPlotErrorForFlatPrior(const bool PlotOrNot){PlotFlatPrior = PlotOrNot; };
306  void SetPlotBinValue(const bool PlotOrNot){plotBinValue = PlotOrNot; };
307  void SetFancyNames(const bool PlotOrNot){FancyPlotNames = PlotOrNot; };
309  void SetSmoothing(const bool PlotOrNot){ApplySmoothing = PlotOrNot; };
312  void SetPost2DPlotThreshold(const double Threshold){Post2DPlotThreshold = Threshold; };
314  void SetUseFFTAutoCorrelation(const bool useFFT){useFFTAutoCorrelation = useFFT; };
315 
317  void SetExcludedTypes(std::vector<std::string> Name){ExcludedTypes = Name; };
318  void SetExcludedNames(std::vector<std::string> Name){ExcludedNames = Name; };
319  void SetExcludedGroups(std::vector<std::string> Name){ExcludedGroups = Name; };
320 
323  void SetnBatches(const int Batches){nBatches = Batches; };
324  void SetnLags(const int nLags){AutoCorrLag = nLags; };
325 
327  void SetOutputSuffix(const std::string Suffix){OutputSuffix = Suffix; };
329  void SetPosterior1DCut(const std::string Cut){Posterior1DCut = Cut; };
330 
331  protected:
333  std::unique_ptr<TH1D> MakePrefit();
335  void DrawPosterior(const int i, TDirectory* PostDir, TDirectory* PostHistDir);
337  void MakeOutputFile();
339  void DrawCorrelations1D();
343  void DrawCorrelationsGroup(const std::unique_ptr<TH2D>& CorrMatrix) const;
345  void ReadInputCov();
347  void ReadInputCovLegacy();
349  void FindInputFiles();
351  void FindInputFilesLegacy();
353  void ReadModelFile();
355  virtual void LoadAdditionalInfo() {};
358  void ReadNDFile();
361  void ReadFDFile();
363  void PrintInfo() const;
364 
366  void ScanInput();
368  void ScanParameterOrder();
370  void SetupOutput();
371 
372  // MCMC Diagnostic
374  void PrepareDiagMCMC();
376  std::vector <double> GetParameterSums();
378  void ParamTraces();
380  void AutoCorrelation();
383  void AutoCorrelation_FFT();
394  void CalculateESS(const int nLags, const std::vector<std::vector<double>>& LagL);
398  void BatchedAnalysis();
400  void BatchedMeans();
404  void GewekeDiagnostic();
410  void PowerSpectrumAnalysis();
411 
413  std::vector<double> GetMargins(const std::unique_ptr<TCanvas>& Canv) const;
415  void SetMargins(std::unique_ptr<TCanvas>& Canv, const std::vector<double>& margins);
421  void SetTLineStyle(TLine* Line, const Color_t Colour, const Width_t Width, const ELineStyle Style) const;
425  void SetLegendStyle(TLegend* Legend, const double size) const;
427  std::pair<double, double> GetHistRange(const int iParam) const;
428 
430  std::string MCMCFile;
432  std::string OutputSuffix;
434  std::vector<std::vector<std::string>> CovPos;
436  std::vector<std::string> CovNamePos;
438  std::vector<YAML::Node> CovConfig;
439 
441  TChain *Chain;
443  std::string StepCut;
445  std::string Posterior1DCut;
447  unsigned int UpperCut;
449  unsigned int BurnInCut;
453  int nEntries;
455  int nSteps;
461  int nDraw;
462 
463  //Name of all branches as well as branches we don't want to include in the analysis
464  std::vector<TString> BranchNames;
465  std::vector<std::string> ExcludedTypes;
466  std::vector<std::string> ExcludedNames;
467  std::vector<std::string> ExcludedGroups;
468 
470  std::vector<bool> ParamVaried;
472  std::vector<std::vector<TString>> ParamNames;
474  std::vector<std::vector<double>> ParamCentral;
476  std::vector<std::vector<double>> ParamErrors;
478  std::vector<std::vector<bool>> ParamFlat;
480  std::vector<int> nParam;
482  std::vector<ParameterEnum> ParamType;
485  std::vector<int> ParamTypeStartPos;
486  // KS: For example flux or detector within matrix
487  std::vector<std::string> ParameterGroup;
488 
490  std::vector<TString> SampleName_v;
492  std::vector<TString> SystName_v;
493 
495  std::string OutputName;
497  TString CanvasName;
498 
501 
502  //Even more flags
519 
520  std::vector<int> NDSamplesBins;
521  std::vector<std::string> NDSamplesNames;
522 
524  std::unique_ptr<TF1> Gauss;
525 
527  TFile *OutputFile;
528 
530  std::unique_ptr<TCanvas> Posterior;
531 
532  //Vector of best fit points and errors obtained with different methods
534  TVectorD *Central_Value;
536  TVectorD *Means;
538  TVectorD *Errors;
540  TVectorD *Means_Gauss;
542  TVectorD *Errors_Gauss;
544  TVectorD *Means_HPD;
546  TVectorD *Errors_HPD;
551 
553  TMatrixDSym *Covariance;
555  TMatrixDSym *Correlation;
556 
558  std::vector<TH1D*> hpost;
560  std::vector<std::vector<TH2D*>> hpost2D;
562  std::unique_ptr<TH2D> hviolin;
564  std::unique_ptr<TH2D> hviolin_prior;
565 
569  unsigned int* StepNumber;
570 
572  int nBins;
574  double DrawRange;
575 
577  bool CacheMCMC;
580 
581  //Number of batches and LagL used in MCMC diagnostic
583  int nBatches;
586 
588  double **BatchedAverages;
589 
591  double **SampleValues;
593  double **SystValues;
594 
596  double *AccProbValues;
599 
603  std::vector<std::string> ReweightNames;
605  double* WeightValue;
606 
607  //Only if GPU is enabled
608  #ifdef MaCh3_CUDA
610  void PrepareGPU_AutoCorr(const int nLags, const std::vector<double>& ParamSums, float*& ParStep_cpu,
611  float*& NumeratorSum_cpu, float*& ParamSums_cpu, float*& DenomSum_cpu);
612  std::unique_ptr<MCMCProcessorGPU> GPUProcessor;
613  #endif
614 };
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:126
#define _MaCh3_Safe_Include_End_
ParameterEnum
Definition: MCMCProcessor.h:45
@ kNDPar
Definition: MCMCProcessor.h:47
@ kXSecPar
Definition: MCMCProcessor.h:46
@ kNParameterEnum
Definition: MCMCProcessor.h:50
@ kFDDetPar
Definition: MCMCProcessor.h:48
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:36
constexpr ELineStyle Style[NVars]
void ThinningMCMC(const std::string &FilePath, const int ThinningCut)
Thin MCMC Chain, to save space and maintain low autocorrelations.
Utility functions for statistical interpretations in MaCh3.
Class responsible for performing MCMC Processing with GPU.
Class responsible for processing MCMC chains, performing diagnostics, generating plots,...
Definition: MCMCProcessor.h:61
void ScanParameterOrder()
Scan order of params from a different groups.
int nBatches
Number of batches for Batched Mean.
void CheckStepCut() const
Check if step cut isn't larger than highest values of step in a chain.
void GewekeDiagnostic()
Geweke Diagnostic based on the methods described by Fang (2014) and Karlsbakk (2011)....
TMatrixDSym * Correlation
Posterior Correlation Matrix.
void MakeViolin()
Make and Draw Violin.
void GetNthParameter(const int param, double &Prior, double &PriorError, TString &Title) const
Get properties of parameter by passing it number.
void SetExcludedGroups(std::vector< std::string > Name)
void Reset2DPosteriors()
Reset 2D posteriors, in case we would like to calculate in again with different BurnInCut.
void SetExcludedNames(std::vector< std::string > Name)
void ThinMCMC(const int ThinningCut) const
Thin MCMC Chain, to save space and maintain low autocorrelations.
const std::vector< TString > & GetBranchNames() const
Get the vector of branch names from root file.
void PrintInfo() const
Print info like how many params have been loaded etc.
void SetnLags(const int nLags)
void MakeCredibleIntervals(const std::vector< double > &CredibleIntervals={0.99, 0.90, 0.68 }, const std::vector< Color_t > &CredibleIntervalsColours={kCyan+4, kCyan-2, kCyan-10}, const bool CredibleInSigmas=false)
Make and Draw Credible intervals.
void ReadModelFile()
Read the xsec file and get the input central values and errors.
std::vector< double > GetMargins(const std::unique_ptr< TCanvas > &Canv) const
Get TCanvas margins, to be able to reset them if particular function need different margins.
M3::float_t ** ParStep
Array holding values for all parameters.
std::unique_ptr< TF1 > Gauss
Gaussian fitter.
void Initialise()
Scan chain, what parameters we have and load information from covariance matrices.
MCMCProcessor(const std::string &InputFile)
Constructs an MCMCProcessor object with the specified input file and options.
double Post2DPlotThreshold
KS: Set Threshold when to plot 2D posterior as by default we get a LOT of plots.
void AcceptanceProbabilities()
Acceptance Probability.
std::vector< std::string > ReweightNames
Name of branch used for chain reweighting.
double ** SampleValues
Holds the sample values.
void BatchedAnalysis()
Get the batched means variance estimation and variable indicating if number of batches is sensible .
void SetOutputSuffix(const std::string Suffix)
Sett output suffix, this way jobs using the same file will have different names.
void AutoCorrelation()
KS: Calculate autocorrelations supports both OpenMP and CUDA :)
TVectorD * Means_HPD
Vector with mean values using Highest Posterior Density.
const std::vector< TString > & GetSampleBranchNames() const
Get the vector of each sample branch names from root file.
std::vector< TString > SampleName_v
Vector of each sample PDF object.
void GetBayesFactor(const std::vector< std::string > &ParName, const std::vector< std::vector< double >> &Model1Bounds, const std::vector< std::vector< double >> &Model2Bounds, const std::vector< std::vector< std::string >> &ModelNames)
Calculate Bayes factor for vector of params, and model boundaries.
double * WeightValue
Stores value of weight for each step.
std::vector< std::vector< double > > ParamCentral
Parameters central values which we are going to analyse.
std::vector< std::vector< double > > ParamErrors
Uncertainty on a single parameter.
void MakeTrianglePlot(const std::vector< std::string > &ParNames, const std::vector< double > &CredibleIntervals={0.99, 0.90, 0.68 }, const std::vector< Color_t > &CredibleIntervalsColours={kCyan+4, kCyan-2, kCyan-10}, const std::vector< double > &CredibleRegions={0.99, 0.90, 0.68}, const std::vector< Style_t > &CredibleRegionStyle={kDashed, kSolid, kDotted}, const std::vector< Color_t > &CredibleRegionColor={kGreen-3, kGreen-10, kGreen}, const bool CredibleInSigmas=false)
Make fancy triangle plot for selected parameters.
std::string OutputName
Name of output files.
std::unique_ptr< TH2D > hviolin_prior
Holds prior violin plot for all dials,.
bool GetParamFlat(const int iParam) const
Get whether param has flat prior or not.
std::vector< int > nParam
Number of parameters per type.
void SetExcludedTypes(std::vector< std::string > Name)
Setter related what parameters we want to exclude from analysis, for example if cross-section paramet...
int GetGroup(const std::string &name) const
Number of params from a given group, for example flux.
void DrawPosterior(const int i, TDirectory *PostDir, TDirectory *PostHistDir)
Perform plot of 1d marginalised posterior with HPD etc.
std::vector< std::string > CovNamePos
Covariance matrix name position.
double DrawRange
Drawrange for SetMaximum.
std::vector< std::vector< bool > > ParamFlat
Whether Param has flat prior or not.
void SetSmoothing(const bool PlotOrNot)
Set whether want to use smoothing for histograms using ROOT algorithm.
std::vector< YAML::Node > CovConfig
Covariance matrix config.
double ** SystValues
Holds the systs values.
virtual ~MCMCProcessor()
Destroys the MCMCProcessor object.
TVectorD * Errors
Vector with errors values using RMS.
double * AccProbBatchedAverages
Holds all accProb in batches.
void MakePostfit(const std::map< std::string, std::pair< double, double >> &Edges={})
Make 1D projection for each parameter and prepare structure.
bool useFFTAutoCorrelation
MJR: Use FFT-based autocorrelation algorithm (save time & resources)?
int GetParamIndexFromName(const std::string &Name) const
Get parameter number based on name.
void MakeCredibleRegions(const std::vector< double > &CredibleRegions={0.99, 0.90, 0.68}, const std::vector< Style_t > &CredibleRegionStyle={kDashed, kSolid, kDotted}, const std::vector< Color_t > &CredibleRegionColor={kGreen-3, kGreen-10, kGreen}, const bool CredibleInSigmas=false, const bool Draw2DPosterior=true, const bool DrawBestFit=true)
Make and Draw Credible Regions.
std::string StepCut
BurnIn Cuts.
void GetPostfit_Ind(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Peaks, ParameterEnum kParam)
Or the individual post-fits.
void DrawCorrelations1D()
Draw 1D correlations which might be more helpful than looking at huge 2D Corr matrix.
void SetnBatches(const int Batches)
Set value of Nbatches used for batched mean, this need to be done earlier as batches are made when re...
int GetNFD() const
void SetEntries(const int NewEntries)
Set number of entries to make potentially MCMC Processing faster.
void GetPostfit(TVectorD *&Central, TVectorD *&Errors, TVectorD *&Central_Gauss, TVectorD *&Errors_Gauss, TVectorD *&Peaks)
Get the post-fit results (arithmetic and Gaussian)
TVectorD * Means_Gauss
Vector with mean values using Gaussian fit.
unsigned int * StepNumber
Step number for step, important if chains were merged.
int AutoCorrLag
LagL used in AutoCorrelation.
std::unique_ptr< TCanvas > Posterior
Fancy canvas used for our beautiful plots.
TFile * OutputFile
The output file.
void SetPosterior1DCut(const std::string Cut)
Allow to set addtional cuts based on ROOT TBrowser cut, for to only affect one mass ordering.
void ReadNDFile()
Read the ND cov file and get the input central values and errors.
TH1D * GetHpost(const int i) const
Get 1D posterior for a given parameter.
void ProduceChi2(const std::string &GroupName) const
Convert posterior likelihood to Delta Chi2 used for comparison with frequentists fitter.
bool ApplySmoothing
Apply smoothing for 2D histos using root algorithm.
unsigned int UpperCut
KS: Used only for SubOptimality.
int nBins
Number of bins.
TChain * Chain
Main chain storing all steps etc.
std::string MCMCFile
Name of MCMC file.
void SetPlotRelativeToPrior(const bool PlotOrNot)
You can set relative to prior or relative to generated. It is advised to use relate to prior.
bool ReweightPosterior
Whether to apply reweighting weight or not.
TH2D * GetViolin() const
Get Violin plot for all parameters with posterior values.
void SetLegendStyle(TLegend *Legend, const double size) const
Configures the style of a TLegend object.
int GetNParams() const
Get total number of used parameters.
std::vector< std::string > ExcludedNames
std::unique_ptr< TH1D > MakePrefit()
Prepare prefit histogram for parameter overlay plot.
std::vector< TH1D * > hpost
Holds 1D Posterior Distributions.
YAML::Node GetCovConfig(const int i) const
Get Yaml config obtained from a Chain.
TVectorD * Errors_HPD_Negative
Vector with negative error (left hand side) values using Highest Posterior Density.
std::vector< std::vector< std::string > > CovPos
Covariance matrix file name position.
void DrawCorrelationsGroup(const std::unique_ptr< TH2D > &CorrMatrix) const
Produces correlation matrix but instead of giving name for each param it only give name for param gro...
Long64_t GetnEntries()
Get Number of entries that Chain has, for merged chains will not be the same Nsteps.
void SetFancyNames(const bool PlotOrNot)
void DiagMCMC()
KS: Perform MCMC diagnostic including Autocorrelation, Trace etc.
std::vector< std::string > ExcludedGroups
std::string Posterior1DCut
Cut used when making 1D Posterior distribution.
int nSampleHandlers
Number of sample PDF objects.
double * AccProbValues
Holds all accProb.
void FindInputFilesLegacy()
std::vector< double > GetParameterSums()
Computes the average of each parameter across all MCMC entries. Useful for autocorrelation.
void DrawCovariance()
Draw the post-fit covariances.
void SetMargins(std::unique_ptr< TCanvas > &Canv, const std::vector< double > &margins)
Set TCanvas margins to specified values.
void ParamTraces()
CW: Draw trace plots of the parameters i.e. parameter vs step.
void PrepareDiagMCMC()
CW: Prepare branches etc. for DiagMCMC.
TH2D * GetHpost2D(const int i, const int j) const
Get 2D posterior for a given parameter combination.
std::unique_ptr< TH2D > hviolin
Holds violin plot for all dials.
void SetPrintToPDF(const bool PlotOrNot)
Whether to dump all plots into PDF.
int nParameterHandlers
Number of covariance objects.
Long64_t GetnSteps()
Get Number of Steps that Chain has, for merged chains will not be the same nEntries.
int nDraw
Number of all parameters used in the analysis.
std::string OutputSuffix
Output file suffix useful when running over same file with different settings.
int GetNXSec() const
void SetNBins(const int NewBins)
Modify number of bins used for 1D and 2D Histograms.
void SetupOutput()
Prepare all objects used for output.
void MakeOutputFile()
prepare output root file and canvas to which we will save EVERYTHING
bool plotBinValue
If true it will print value on each bin of covariance matrix.
TVectorD * Errors_Gauss
Vector with error values using Gaussian fit.
void CheckCredibleIntervalsOrder(const std::vector< double > &CredibleIntervals, const std::vector< Color_t > &CredibleIntervalsColours) const
Checks the order and size consistency of the CredibleIntervals and CredibleIntervalsColours vectors.
void CalculateESS(const int nLags, const std::vector< std::vector< double >> &LagL)
KS: calc Effective Sample Size.
std::vector< ParameterEnum > ParamType
Make an enum for which class this parameter belongs to so we don't have to keep string comparing.
std::vector< std::string > NDSamplesNames
virtual void LoadAdditionalInfo()
allow loading additional info for example used for oscillation parameters
TVectorD * Central_Value
Vector with central value for each parameter.
std::vector< std::string > ExcludedTypes
int nSteps
KS: For merged chains number of entries will be different from nSteps.
TH2D * GetViolinPrior() const
Get Violin plot for all parameters with prior values.
void CheckCredibleRegionsOrder(const std::vector< double > &CredibleRegions, const std::vector< Style_t > &CredibleRegionStyle, const std::vector< Color_t > &CredibleRegionColor)
Checks the order and size consistency of the CredibleRegions, CredibleRegionStyle,...
std::vector< int > NDSamplesBins
void MakeCovariance_MP(const bool Mute=false)
Calculate covariance by making 2D projection of each combination of parameters using multithreading.
double ** BatchedAverages
Values of batched average for every param and batch.
void DrawPostfit()
Draw the post-fit comparisons.
TString CanvasName
Name of canvas which help to save to the sample pdf.
void SetPost2DPlotThreshold(const double Threshold)
Code will only plot 2D posteriors if Correlation are larger than defined threshold.
std::vector< std::string > ParameterGroup
std::string GetFDCov() const
void SetUseFFTAutoCorrelation(const bool useFFT)
Toggle using the FFT-based autocorrelation calculator.
TVectorD * Errors_HPD
Vector with error values using Highest Posterior Density.
void AutoCorrelation_FFT()
MJR: Autocorrelation function using FFT algorithm for extra speed.
void SetTLineStyle(TLine *Line, const Color_t Colour, const Width_t Width, const ELineStyle Style) const
Configures a TLine object with the specified style parameters.
void ReadInputCovLegacy()
void GetPolarPlot(const std::vector< std::string > &ParNames)
Make funny polar plot.
const std::vector< TString > & GetSystBranchNames() const
Get the vector of each systematic branch names from root file.
std::vector< std::vector< TH2D * > > hpost2D
Holds 2D Posterior Distributions.
void ParameterEvolution(const std::vector< std::string > &Names, const std::vector< int > &NIntervals)
Make .gif of parameter evolution.
void GetCovariance(TMatrixDSym *&Cov, TMatrixDSym *&Corr)
Get the post-fit covariances and correlations.
TVectorD * Means
Vector with mean values using Arithmetic Mean.
std::vector< TString > SystName_v
Vector of each systematic.
void CacheSteps()
KS:By caching each step we use multithreading.
void SetReweightNames(std::vector< std::string > NewName)
Set reweight branch names.
std::vector< TString > BranchNames
std::vector< bool > ParamVaried
Is the ith parameter varied.
bool PlotFlatPrior
Whether we plot flat prior or not, we usually provide error even for flat prior params.
bool FancyPlotNames
Whether we want fancy plot names or not.
std::string GetNDCov() const
void SetStepCut(const std::string &Cuts)
Set the step cutting by string.
bool printToPDF
Will plot all plot to PDF not only to root file.
int GetNND() const
void GetSavageDickey(const std::vector< std::string > &ParName, const std::vector< double > &EvaluationPoint, const std::vector< std::vector< double >> &Bounds)
Calculate Bayes factor for point like hypothesis using SavageDickey.
void SetPlotErrorForFlatPrior(const bool PlotOrNot)
Set whether you want to plot error for parameters which have flat prior.
std::pair< double, double > GetHistRange(const int iParam) const
Get Min/Max ranges for single parameter.
std::vector< std::vector< TString > > ParamNames
Name of parameters which we are going to analyse.
bool doDiagMCMC
Doing MCMC Diagnostic.
void ReadFDFile()
Read the FD cov file and get the input central values and errors.
std::vector< std::string > GetXSecCov() const
void FindInputFiles()
Read the output MCMC file and find what inputs were used.
bool CacheMCMC
MCMC Chain has been cached.
std::vector< int > ParamTypeStartPos
bool MadePostfit
Sanity check if Postfit is already done to not make several times.
void SetPlotBinValue(const bool PlotOrNot)
void PowerSpectrumAnalysis()
RC: Perform spectral analysis of MCMC .
void ScanInput()
Scan Input etc.
void BatchedMeans()
CW: Batched means, literally read from an array and chuck into TH1D.
int nEntries
KS: For merged chains number of entries will be different from nSteps.
void SavageDickeyPlot(std::unique_ptr< TH1D > &PriorHist, std::unique_ptr< TH1D > &PosteriorHist, const std::string &Title, const double EvaluationPoint) const
Produce Savage Dickey plot.
int nBranches
Number of branches in a TTree.
TVectorD * Errors_HPD_Positive
Vector with positive error (right hand side) values using Highest Posterior Density.
TMatrixDSym * Covariance
Posterior Covariance Matrix.
void MakeSubOptimality(const int NIntervals=10)
Make and Draw SubOptimality .
void MakeCovarianceYAML(const std::string &OutputYAMLFile, const std::string &MeansMethod) const
Make YAML file from post-fit covariance.
bool plotRelativeToPrior
Whether we plot relative to prior or nominal, in most cases is prior.
void MakeCovariance()
Calculate covariance by making 2D projection of each combination of parameters.
unsigned int BurnInCut
Value of burn in cut.
void SmearChain(const std::vector< std::string > &Names, const std::vector< double > &Error, const bool &SaveBranch) const
Smear chain contours.
void ReadInputCov()
CW: Read the input Covariance matrix entries. Get stuff like parameter input errors,...
Custom exception class used throughout MaCh3.
double float_t
Definition: Core.h:37