MaCh3  2.5.0
Reference Guide
SampleSummary.h
Go to the documentation of this file.
1 #pragma once
2 
3 // MaCh3 includes
7 
8 // *******************
15 // *******************
16  public:
22  SampleSummary(const int n_Samples, const std::string &Filename, SampleHandlerInterface* const sample, const int nSteps);
25 
28  void AddData(std::vector<TH2Poly*> &DataHist);
30  void AddNominal(std::vector<TH2Poly*> &NominalHist, std::vector<TH2Poly*> &W2Nom);
32  void AddThrow(std::vector<TH2Poly*> &MCHist, std::vector<TH2Poly*> &W2Hist, const double LLHPenalty = 0.0, const double Weight = 1.0, const int DrawNumber = 0);
34  void AddThrowByMode(std::vector<std::vector<TH2Poly*>> &SampleVector_ByMode);
35 
37  void Write();
38 
40  inline void SetLikelihood(const TestStatistic TestStat){ likelihood = TestStat;};
42  inline void SetNModelParams(const int nPars){ nModelParams = nPars;};
43 
44  private:
46  inline void MakePredictive();
47 
49  inline void PrepareOutput();
50 
55  inline void CalcLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
60  inline void CalcLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
61 
66  inline double GetLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
71  inline double GetLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
72 
74  inline void PlotBetaParameters();
75 
77  inline void StudyKinematicCorrelations();
78 
80  inline void MakeCutLLH();
81  // Make the 1D cut distribution and give the 1D p-value
82  inline void MakeCutLLH1D(TH1D *Histogram, double llh_ref = -999);
84  inline void MakeCutEventRate(TH1D *Histogram, const double DataRate);
89  inline void MakeChi2Hists();
90 
92  inline bool CheckSamples(const int Length);
93 
95  inline TH1D* ProjectHist(TH2D* Histogram, const bool ProjectX);
97  inline TH1D* ProjectPoly(TH2Poly* Histogram, const bool ProjectX, const int selection, const bool MakeErrorHist = false);
98 
100  inline void MakeFluctuatedHistogram(TH1D *FluctHist, TH1D* PolyHist);
101 
103  inline void MakeFluctuatedHistogram(TH2Poly *FluctHist, TH2Poly* PolyHist);
104 
106  inline void StudyInformationCriterion(M3::kInfCrit Criterion);
107 
110  inline void StudyBIC();
111 
115  inline void StudyDIC();
116 
120  inline void StudyWAIC();
121 
123  std::unique_ptr<TRandom3> rnd;
126 
129 
131  std::vector<std::vector<TH2Poly*>> MCVector;
133  std::vector<std::vector<TH2Poly*>> W2MCVector;
135  std::vector<std::vector<std::vector<TH2Poly*>>> MCVectorByMode;
136 
138  std::vector<double> LLHPenaltyVector;
140  std::vector<double> WeightVector;
141 
143  int nSamples;
144 
146  std::vector<std::string> SampleNames;
147 
149  std::vector<std::vector<std::unique_ptr<TH1D>>> PosteriorHist;
151  std::vector<std::vector<std::unique_ptr<TH1D>>> w2Hist;
152 
154  std::vector<TH2D*> ViolinHists_ProjectX;
156  std::vector<TH2D*> ViolinHists_ProjectY;
157 
159  std::vector<TH2Poly*> DataHist;
161  std::vector<TH1D*> DataHist_ProjectX;
163  std::vector<TH1D*> DataHist_ProjectY;
165  std::vector<TH2Poly*> NominalHist;
167  std::vector<TH2Poly*> W2NomHist;
169  std::vector<TH2Poly*> W2MeanHist;
171  std::vector<TH2Poly*> W2ModeHist;
172 
174  std::unique_ptr<TH1D> lnLHist;
176  std::unique_ptr<TH1D> lnLHist_drawfluc;
178  std::unique_ptr<TH1D> lnLHist_drawflucdraw;
180  std::unique_ptr<TH1D> lnLHist_drawdata;
182  std::unique_ptr<TH2D> lnLDrawHist;
184  std::unique_ptr<TH2D> lnLFlucHist;
185 
187  std::unique_ptr<TH2D> lnLDrawHistRate;
189  std::unique_ptr<TH2D> lnLFlucHist_ProjectX;
190 
192  std::vector<TH1D*> lnLHist_Sample_DrawData;
194  std::vector<TH1D*> lnLHist_Sample_DrawflucDraw;
196  std::vector<TH1D*> lnLHist_Sample_PredflucDraw;
197 
199  std::vector<TH2Poly*> lnLHist_Mean;
201  std::vector<TH2Poly*> lnLHist_Mode;
202 
204  std::vector<TH1D*> lnLHist_Mean_ProjectX;
205 
207  std::vector<TH2Poly*> MeanHist;
209  std::vector<TH2Poly*> MeanHistCorrected;
211  std::vector<TH2Poly*> ModeHist;
212 
214  std::vector<TH1D*> lnLHist_Mean1D;
216  std::vector<TH1D*> lnLHist_Mode1D;
217 
219  std::unique_ptr<TH1D> RandomHist;
220 
222  std::vector<std::vector<std::unique_ptr<TH1D>>> BetaHist;
225 
227  unsigned int nChainSteps;
228 
231 
234 
236  unsigned int nThrows;
237 
239  std::vector<int> maxBins;
240 
242  double llh_total;
243 
245  std::string OutputName;
247  TFile *Outputfile;
249  std::vector<TDirectory*> Dir;
250 
252  TTree *OutputTree;
254  std::vector<double> llh_data_draw;
256  std::vector<double> llh_drawfluc_draw;
258  std::vector<double> llh_predfluc_draw;
259 
261  std::vector<double> llh_rate_data_draw;
263  std::vector<double> llh_rate_predfluc_draw;
264 
266  std::vector<double> llh_data_drawfluc;
268  std::vector<double> llh_data_predfluc;
270  std::vector<double> llh_draw_pred;
272  std::vector<double> llh_drawfluc_pred;
273 
275  std::vector<double> llh_predfluc_pred;
277  std::vector<double> llh_drawfluc_predfluc;
279  std::vector<double> llh_datafluc_draw;
280 
282  std::vector<double> llh_data_draw_ProjectX;
283  std::vector<double> llh_drawfluc_draw_ProjectX;
284 
286  double llh_penalty;
287 
294 
299 
314 
319 
323  std::vector<std::vector<TH2Poly*>> MeanHist_ByMode;
326 
329 
332 
335 
338 
340  int Debug;
341 };
TestStatistic
Make an enum of the test statistic that we're using.
Utility functions for statistical interpretations in MaCh3.
KS: Class describing MaCh3 modes used in the analysis, it is being initialised from config.
Definition: MaCh3Modes.h:135
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...
Class to calculate pvalue produce posterior predictive and many fancy Bayesian stuff .
Definition: SampleSummary.h:14
void StudyInformationCriterion(M3::kInfCrit Criterion)
Information Criterion.
std::vector< TH2Poly * > lnLHist_Mode
The LLH distribution in pmu cosmu for using the mode in each bin.
std::vector< double > LLHPenaltyVector
Vector to hold the penalty term.
std::vector< double > llh_data_draw_ProjectX
Projection X (most likely muon momentum) of LLH.
void MakeCutEventRate(TH1D *Histogram, const double DataRate)
Make the 1D Event Rate Hist.
~SampleSummary()
Destructor.
std::vector< double > llh_predfluc_draw
Fluctuated Predictive vs Draw.
void AddThrow(std::vector< TH2Poly * > &MCHist, std::vector< TH2Poly * > &W2Hist, const double LLHPenalty=0.0, const double Weight=1.0, const int DrawNumber=0)
KS: Add histograms with throws.
std::vector< std::vector< TH2Poly * > > MCVector
Vector of vectors which holds the loaded MC histograms.
std::vector< TH2Poly * > lnLHist_Mean
The LLH distribution in pmu cosmu for using the mean in each bin.
void CalcLLH(TH2Poly *const &Data, TH2Poly *const &MC, TH2Poly *const &W2)
Helper functions to calculate likelihoods using TH2Poly, will modify MC hist title to include LLH.
double total_llh_predfluc_pred
Fluctuated Predictive vs Predictive.
double total_llh_drawfluc_draw_ProjectX
Fluctuated Draw vs Draw for projection X (most likely muon momentum)
std::vector< std::vector< TH2Poly * > > W2MCVector
Vector of vectors which holds the loaded W2 histograms.
std::vector< TH2Poly * > W2MeanHist
Pointer to the w2 histograms (for mean values).
double total_llh_data_draw
Data vs Draw.
std::unique_ptr< TH1D > RandomHist
Holds the history of which entries have been drawn in the MCMC file.
double total_llh_rate_predfluc_draw
Fluctuated Predictive vs Draw using Rate.
void MakeChi2Hists()
Make the fluctuated histograms (2D and 1D) for the chi2s Essentially taking the MCMC draws and calcul...
std::vector< double > llh_data_predfluc
Data vs Fluctuated Predictive.
void StudyBIC()
Study Bayesian Information Criterion (BIC) .
std::unique_ptr< TRandom3 > rnd
Random number generator.
SampleSummary(const int n_Samples, const std::string &Filename, SampleHandlerInterface *const sample, const int nSteps)
Constructor.
std::vector< TH1D * > lnLHist_Mode1D
Holds the bin-by-bin LLH for the mode posterior predictive vs the data.
std::string OutputName
Output filename.
void MakePredictive()
Finalise the distributions from the thrown samples.
std::vector< double > llh_predfluc_pred
Fluctuated Predictive vs Predictive.
std::vector< std::vector< std::unique_ptr< TH1D > > > BetaHist
Distribution of beta parameters in Barlow Beeston formalisms.
int nModelParams
Number of parameters.
std::vector< TH2D * > ViolinHists_ProjectX
Posterior predictive but for X projection but as a violin plot.
bool first_pass
KS: Hacky flag to let us know if this is first toy.
std::vector< TH2Poly * > NominalHist
The nominal histogram for the selection.
std::vector< std::vector< std::unique_ptr< TH1D > > > PosteriorHist
The posterior predictive for the whole selection: this gets built after adding in the toys....
SampleHandlerInterface * SampleHandler
Pointer to SampleHandler object, mostly used to get sample names, binning etc.
double total_llh_draw_pred
Draw vs Predictive.
std::vector< double > llh_drawfluc_draw
Fluctuated Draw vs Draw.
double total_llh_data_draw_ProjectX
Data vs Draw for projection X (most likely muon momentum)
std::vector< TH2Poly * > MeanHistCorrected
The posterior predictive distribution in pmu cosmu using the mean after applying Barlow-Beeston Corre...
std::vector< double > llh_drawfluc_predfluc
Fluctuated Draw vs Fluctuated Predictive.
MaCh3Modes * Modes
MaCh3 Modes.
std::vector< double > llh_data_draw
Data vs Draw.
double total_llh_data_drawfluc
Data vs Fluctuated Draw.
void AddData(std::vector< TH2Poly * > &DataHist)
KS: Add data histograms.
TH1D * ProjectPoly(TH2Poly *Histogram, const bool ProjectX, const int selection, const bool MakeErrorHist=false)
Helper to project TH2Poly onto axis.
std::unique_ptr< TH1D > lnLHist
The histogram containing the lnL for each throw.
std::vector< TH1D * > lnLHist_Mean1D
Holds the bin-by-bin LLH for the mean posterior predictive vs the data.
TTree * OutputTree
TTree which we save useful information to.
bool DoByModePlots
By mode variables.
std::vector< TH1D * > lnLHist_Mean_ProjectX
The LLH distribution in pmu using the mean in each bin.
void PrepareOutput()
KS: Prepare output tree and necessary variables.
double total_llh_drawfluc_draw
Fluctuated Draw vs Draw.
std::vector< TH2Poly * > DataHist
The data histogram for the selection.
std::vector< double > llh_draw_pred
Draw vs Predictive.
double total_llh_predfluc_draw
Fluctuated Predictive vs Draw.
int Debug
Tells Debug level to save additional histograms.
std::vector< double > llh_drawfluc_draw_ProjectX
bool CheckSamples(const int Length)
Check the length of samples agrees.
std::unique_ptr< TH2D > lnLDrawHist
The 2D lnLhist, showing (draw vs data) and (draw vs fluct), anything above y=x axis is the p-value.
void AddNominal(std::vector< TH2Poly * > &NominalHist, std::vector< TH2Poly * > &W2Nom)
KS: Add prior histograms.
void StudyDIC()
KS: Get the Deviance Information Criterion (DIC) .
void AddThrowByMode(std::vector< std::vector< TH2Poly * >> &SampleVector_ByMode)
KS: Add histograms for each mode.
std::vector< TH2D * > ViolinHists_ProjectY
Posterior predictive but for Y projection but as a violin plot.
std::vector< double > llh_data_drawfluc
Data vs Fluctuated Draw.
std::vector< TH2Poly * > ModeHist
The posterior predictive distribution in pmu cosmu using the mode.
std::vector< std::string > SampleNames
name for each sample
std::vector< TH2Poly * > W2NomHist
Pointer to the w2 histograms (for nominal values).
double total_llh_drawfluc_pred
Fluctuated Draw vs Predictive.
void StudyWAIC()
KS: Get the Watanabe-Akaike information criterion (WAIC) .
std::vector< TDirectory * > Dir
Directory for each sample.
std::vector< double > llh_rate_predfluc_draw
Fluctuated Predictive vs Draw using rate only.
unsigned int nThrows
Number of throws.
std::vector< TH1D * > lnLHist_Sample_DrawData
The histogram containing the lnL (draw vs data) for each throw for each sample.
std::vector< std::vector< std::unique_ptr< TH1D > > > w2Hist
The posterior predictive for the whole selection: this gets built after adding in the toys....
TH1D **** PosteriorHist_ByMode
Histogram which corresponds to each bin in the sample's th2poly.
std::unique_ptr< TH1D > lnLHist_drawflucdraw
The lnLhist for the draw vs draw fluctuated.
TFile * Outputfile
Output filename.
double llh_total
Total LLH for the posterior predictive distribution.
void Write()
KS: Write results into root file.
std::unique_ptr< TH2D > lnLDrawHistRate
The 2D lnLhist, showing (draw vs data) and (draw vs fluct), using rate, anything above y=x axis is th...
double total_llh_rate_data_draw
Rate Data vs Draw.
std::unique_ptr< TH1D > lnLHist_drawdata
The lnLhist for the draw vs data.
TestStatistic likelihood
Type of likelihood for example Poisson, Barlow-Beeston or Ice Cube.
int nSamples
Number of samples.
void MakeCutLLH()
Make the cut LLH histogram.
std::vector< std::vector< std::vector< TH2Poly * > > > MCVectorByMode
Vector of vectors which holds the loaded MC histograms for each mode.
void SetNModelParams(const int nPars)
Set number of model params used for BIC.
Definition: SampleSummary.h:42
std::vector< double > llh_drawfluc_pred
Fluctuated Draw vs Predictive.
std::vector< std::vector< TH2Poly * > > MeanHist_ByMode
The posterior predictive distribution in pmu cosmu using the mean.
std::vector< double > llh_datafluc_draw
Fluctuated Data vs Draw.
std::vector< TH1D * > DataHist_ProjectX
The data histogram for the selection X projection.
void MakeCutLLH1D(TH1D *Histogram, double llh_ref=-999)
std::vector< TH1D * > DataHist_ProjectY
The data histogram for the selection Y projection.
void PlotBetaParameters()
KS: In Barlow Beeston we have Beta Parameters which scale generated MC.
double GetLLH(TH2Poly *const &Data, TH2Poly *const &MC, TH2Poly *const &W2)
Helper functions to calculate likelihoods using TH2Poly.
std::vector< double > WeightVector
Vector holding weight.
void MakeFluctuatedHistogram(TH1D *FluctHist, TH1D *PolyHist)
Make Poisson fluctuation of TH1D hist.
std::vector< double > llh_rate_data_draw
Data vs Draw using rate only.
bool isPriorPredictive
bool whether we have Prior or Posterior Predictive
bool DoBetaParam
Are we making Beta Histograms.
std::vector< TH2Poly * > W2ModeHist
Pointer to the w2 histograms (for mode values).
std::unique_ptr< TH2D > lnLFlucHist
The 2D lnLHist, showing (draw vs data) and (draw vs draw fluct), anything above y=x axis is the p-val...
bool StandardFluctuation
KS: We have two methods for Poissonian fluctuation.
std::unique_ptr< TH2D > lnLFlucHist_ProjectX
The 2D lnLHist but for ProjectionX histogram (pmu), showing (draw vs data) and (draw vs draw fluct),...
std::unique_ptr< TH1D > lnLHist_drawfluc
The lnLhist for the draw vs MC fluctuated.
bool doShapeOnly
bool whether to normalise each toy to have shape based p-value and pos pred distribution
void SetLikelihood(const TestStatistic TestStat)
KS: Set likelihood type.
Definition: SampleSummary.h:40
std::vector< TH1D * > lnLHist_Sample_PredflucDraw
The histogram containing the lnL (draw vs pred fluct) for each throw for each sample.
double total_llh_data_predfluc
Data vs Fluctuated Predictive.
double llh_penalty
LLH penalty for each throw.
std::vector< TH2Poly * > MeanHist
The posterior predictive distribution in pmu cosmu using the mean.
unsigned int nChainSteps
Number of throws by user.
std::vector< int > maxBins
Max Number of Bins per each sample.
TH1D * ProjectHist(TH2D *Histogram, const bool ProjectX)
Helper to project TH2D onto axis.
double total_llh_drawfluc_predfluc
Fluctuated Draw vs Fluctuated Predictive.
double total_llh_datafluc_draw
Fluctuated Data vs Draw.
void StudyKinematicCorrelations()
KS: Study how correlated are sample or kinematic bins.
std::vector< TH1D * > lnLHist_Sample_DrawflucDraw
The histogram containing the lnL (draw vs draw fluct) for each throw for each sample.
kInfCrit
KS: Different Information Criterion tests mostly based Gelman paper.