4#define _UNDEF_ 1234567890
24#include "TGraphErrors.h"
28#include "TStopwatch.h"
35#include "TGraphPolar.h"
38#include "TMatrixDSymEigen.h"
39#include "TVirtualFFT.h"
101 const std::vector<Color_t>& CredibleIntervalsColours = {kCyan+4, kCyan-2, kCyan-10},
102 const bool CredibleInSigmas = false
112 const std::vector<Style_t>& CredibleRegionStyle = {kDashed, kSolid, kDotted},
113 const std::vector<Color_t>& CredibleRegionColor = {kGreen-3, kGreen-10, kGreen},
114 const bool CredibleInSigmas =
false,
115 const bool Draw2DPosterior =
true,
116 const bool DrawBestFit = true
127 const std::vector<double>& CredibleIntervals = {0.99, 0.90, 0.68 },
128 const std::vector<Color_t>& CredibleIntervalsColours = {kCyan+4, kCyan-2, kCyan-10},
130 const std::vector<double>& CredibleRegions = {0.99, 0.90, 0.68},
131 const std::vector<Style_t>& CredibleRegionStyle = {kDashed, kSolid, kDotted},
132 const std::vector<Color_t>& CredibleRegionColor = {kGreen-3, kGreen-10, kGreen},
134 const bool CredibleInSigmas = false
141 void CheckCredibleIntervalsOrder(
const std::vector<double>& CredibleIntervals,
const std::vector<Color_t>& CredibleIntervalsColours);
149 const std::vector<Style_t>& CredibleRegionStyle,
150 const std::vector<Color_t>& CredibleRegionColor);
154 void GetPolarPlot(
const std::vector<std::string>& ParNames);
162 const std::vector<std::vector<double>>& Model1Bounds,
163 const std::vector<std::vector<double>>& Model2Bounds,
164 const std::vector<std::vector<std::string>>& ModelNames);
167 const std::vector<double>& EvaluationPoint,
168 const std::vector<std::vector<double>>& Bounds);
174 const std::vector<double>& NewCentral,
175 const std::vector<double>& NewError);
181 const std::vector<int>& NIntervals);
198 int GetGroup(
const std::string& name)
const;
229 void GetNthParameter(
const int param,
double &Prior,
double &PriorError, TString &Title)
const;
328 inline void CalculateESS(
const int nLags,
const std::vector<std::vector<double>>& LagL);
347 std::vector<double>
GetMargins(
const std::unique_ptr<TCanvas>& Canv)
const;
349 void SetMargins(std::unique_ptr<TCanvas>& Canv,
const std::vector<double>& margins);
355 void SetTLineStyle(TLine* Line,
const Color_t Colour,
const Width_t Width,
const ELineStyle Style)
const;
366 std::vector<std::vector<std::string>>
CovPos;
535 inline void PrepareGPU_AutoCorr(
const int nLags);
539 float* NumeratorSum_cpu;
540 float* ParamSums_cpu;
545 float* NumeratorSum_gpu;
546 float* ParamSums_gpu;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
ParameterEnum
KS: Enum for different covariance classes.
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 processing MCMC chains, performing diagnostics, generating plots,...
void ScanParameterOrder()
Scan order of params from a different groups.
int nBatches
Number of batches for Batched Mean.
void GewekeDiagnostic()
Geweke Diagnostic based on the methods described by Fang (2014) and Karlsbakk (2011)....
TMatrixDSym * Correlation
Posterior Correlation Matrix.
TH2D * GetViolinPrior()
Get Violin plot for all parameters with prior values.
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.
int * StepNumber
Step number for step, important if chains were merged.
double ** ParStep
Array holding values for all parameters.
void SetExcludedNames(std::vector< std::string > Name)
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.
void CalculateESS(const int nLags, const std::vector< std::vector< double > > &LagL)
KS: calc Effective Sample Size.
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.
std::unique_ptr< TF1 > Gauss
Gaussian fitter.
void Initialise()
Scan chain, what parameters we have and load information from covariance matrices.
int BurnInCut
Value of burn in cut.
double Post2DPlotThreshold
KS: Set Threshold when to plot 2D posterior as by default we get a LOT of plots.
void AcceptanceProbabilities()
Acceptance Probability.
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.
void ResetHistograms()
Reset 2D posteriors, in case we would like to calculate in again with different BurnInCut.
std::vector< TString > SampleName_v
Vector of each systematic.
const std::vector< TString > & GetBranchNames() const
Get the vector of branch names from root file.
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,.
int nSamples
Number of sample PDF objects.
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.
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.
std::vector< std::vector< double > > ParamNom
double ** SystValues
Holds the systs values.
TH2D * GetViolin()
Get Violin plot for all parameters with posterior values.
virtual ~MCMCProcessor()
Destroys the MCMCProcessor object.
TVectorD * Errors
Vector with errors values using RMS.
double * AccProbBatchedAverages
Holds all accProb in batches.
bool useFFTAutoCorrelation
MJR: Use FFT-based autocorrelation algorithm (save time & resources)?
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.
int GetParamIndexFromName(const std::string &Name)
Get parameter number based on name.
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...
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.
int AutoCorrLag
LagL used in AutoCorrelation.
std::unique_ptr< TCanvas > Posterior
Fancy canvas used for our beautiful plots.
TFile * OutputFile
The output file.
void ThinMCMC(const int ThinningCut)
Thin MCMC Chain, to save space and maintain low autocorrelations.
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.
bool ApplySmoothing
Apply smoothing for 2D histos using root algorithm.
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.
void SetLegendStyle(TLegend *Legend, const double size) const
Configures the style of a TLegend object.
TH1D * GetHpost(const int i)
Get 1D posterior for a given parameter.
std::vector< std::string > ExcludedNames
std::unique_ptr< TH1D > MakePrefit()
Prepare prefit histogram for parameter overlay plot.
TH2D * GetHpost2D(const int i, const int j)
Get 2D posterior for a given parameter combination.
std::vector< TH1D * > hpost
Holds 1D Posterior Distributions.
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 name position.
double * ParamSums
Total parameter sum for each param.
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.
int UpperCut
KS: Used only for SubOptimality.
std::string Posterior1DCut
Cut used when making 1D Posterior distribution.
void MakePostfit()
Make 1D projection for each parameter and prepare structure.
double * AccProbValues
Holds all accProb.
void FindInputFilesLegacy()
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.
std::vector< bool > IamVaried
Is the ith parameter varied.
std::unique_ptr< TH2D > hviolin
Holds violin plot for all dials.
void SetPrintToPDF(const bool PlotOrNot)
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.
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.
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.
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.
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 sample PDF object.
void CacheSteps()
KS:By caching each step we use multithreading.
std::vector< TString > BranchNames
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.
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 ReweightPrior(const std::vector< std::string > &Names, const std::vector< double > &NewCentral, const std::vector< double > &NewError)
Reweight Prior by giving new central value and new error.
std::vector< std::string > GetXSecCov() 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 GetNParams()
Get total number of used parameters.
void SetPlotErrorForFlatPrior(const bool PlotOrNot)
Set whether you want to plot error for parameters which have flat prior.
void CheckCredibleIntervalsOrder(const std::vector< double > &CredibleIntervals, const std::vector< Color_t > &CredibleIntervalsColours)
Checks the order and size consistency of the CredibleIntervals and CredibleIntervalsColours vectors.
std::vector< std::vector< TString > > ParamNames
Name of parameters which we are going to analyse.
bool doDiagMCMC
Doing MCMC Diagnostic.
int nSysts
Number of covariance objects.
void ReadFDFile()
Read the FD cov file and get the input central values and errors.
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.
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 .
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.
void ReadInputCov()
CW: Read the input Covariance matrix entries. Get stuff like parameter input errors,...