MaCh3  2.2.3
Reference Guide
SampleSummary.h
Go to the documentation of this file.
1 #pragma once
2 
3 // MaCh3 includes
7 
8 namespace M3 {
10  enum kInfCrit {
11  kBIC,
12  kDIC,
14  kInfCrits
15  };
16 }
17 // *******************
23 // *******************
24  public:
30  SampleSummary(const int n_Samples, const std::string &Filename, SampleHandlerBase* const sample, const int nSteps);
33 
36  void AddData(std::vector<TH2Poly*> &DataHist);
38  void AddNominal(std::vector<TH2Poly*> &NominalHist, std::vector<TH2Poly*> &W2Nom);
40  void AddThrow(std::vector<TH2Poly*> &MCHist, std::vector<TH2Poly*> &W2Hist, const double LLHPenalty = 0.0, const double Weight = 1.0, const int DrawNumber = 0);
42  void AddThrowByMode(std::vector<std::vector<TH2Poly*>> &SampleVector_ByMode);
43 
45  void Write();
46 
48  inline void SetLikelihood(const TestStatistic TestStat){ likelihood = TestStat;};
50  inline void SetNModelParams(const int nPars){ nModelParams = nPars;};
51 
52  private:
54  inline void MakePredictive();
55 
57  inline void PrepareOutput();
58 
63  inline void CalcLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
68  inline void CalcLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
69 
74  inline double GetLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
79  inline double GetLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
80 
82  inline void PlotBetaParameters();
83 
85  inline void StudyKinematicCorrelations();
86 
88  inline void MakeCutLLH();
89  // Make the 1D cut distribution and give the 1D p-value
90  inline void MakeCutLLH1D(TH1D *Histogram, double llh_ref = -999);
92  inline void MakeCutEventRate(TH1D *Histogram, const double DataRate);
97  inline void MakeChi2Hists();
98 
100  inline bool CheckSamples(const int Length);
101 
103  inline TH1D* ProjectHist(TH2D* Histogram, const bool ProjectX);
105  inline TH1D* ProjectPoly(TH2Poly* Histogram, const bool ProjectX, const int selection, const bool MakeErrorHist = false);
106 
108  inline void MakeFluctuatedHistogram(TH1D *FluctHist, TH1D* PolyHist);
109 
111  inline void MakeFluctuatedHistogram(TH2Poly *FluctHist, TH2Poly* PolyHist);
112 
114  inline void StudyInformationCriterion(M3::kInfCrit Criterion);
115 
118  inline void StudyBIC();
119 
123  inline void StudyDIC();
124 
128  inline void StudyWAIC();
129 
131  std::unique_ptr<TRandom3> rnd;
134 
137 
139  std::vector<std::vector<TH2Poly*>> MCVector;
141  std::vector<std::vector<TH2Poly*>> W2MCVector;
143  std::vector<std::vector<std::vector<TH2Poly*>>> MCVectorByMode;
144 
146  std::vector<double> LLHPenaltyVector;
148  std::vector<double> WeightVector;
149 
151  int nSamples;
152 
154  std::vector<std::string> SampleNames;
155 
157  std::vector<std::vector<std::unique_ptr<TH1D>>> PosteriorHist;
159  std::vector<std::vector<std::unique_ptr<TH1D>>> w2Hist;
160 
162  std::vector<TH2D*> ViolinHists_ProjectX;
164  std::vector<TH2D*> ViolinHists_ProjectY;
165 
167  std::vector<TH2Poly*> DataHist;
169  std::vector<TH1D*> DataHist_ProjectX;
171  std::vector<TH1D*> DataHist_ProjectY;
173  std::vector<TH2Poly*> NominalHist;
175  std::vector<TH2Poly*> W2NomHist;
177  std::vector<TH2Poly*> W2MeanHist;
179  std::vector<TH2Poly*> W2ModeHist;
180 
182  std::unique_ptr<TH1D> lnLHist;
184  std::unique_ptr<TH1D> lnLHist_drawfluc;
186  std::unique_ptr<TH1D> lnLHist_drawflucdraw;
188  std::unique_ptr<TH1D> lnLHist_drawdata;
190  std::unique_ptr<TH2D> lnLDrawHist;
192  std::unique_ptr<TH2D> lnLFlucHist;
193 
195  std::unique_ptr<TH2D> lnLDrawHistRate;
197  std::unique_ptr<TH2D> lnLFlucHist_ProjectX;
198 
200  std::vector<TH1D*> lnLHist_Sample_DrawData;
202  std::vector<TH1D*> lnLHist_Sample_DrawflucDraw;
204  std::vector<TH1D*> lnLHist_Sample_PredflucDraw;
205 
207  std::vector<TH2Poly*> lnLHist_Mean;
209  std::vector<TH2Poly*> lnLHist_Mode;
210 
212  std::vector<TH1D*> lnLHist_Mean_ProjectX;
213 
215  std::vector<TH2Poly*> MeanHist;
217  std::vector<TH2Poly*> MeanHistCorrected;
219  std::vector<TH2Poly*> ModeHist;
220 
222  std::vector<TH1D*> lnLHist_Mean1D;
224  std::vector<TH1D*> lnLHist_Mode1D;
225 
227  std::unique_ptr<TH1D> RandomHist;
228 
230  std::vector<std::vector<std::unique_ptr<TH1D>>> BetaHist;
233 
235  unsigned int nChainSteps;
236 
239 
242 
244  unsigned int nThrows;
245 
247  std::vector<int> maxBins;
248 
250  double llh_total;
251 
253  std::string OutputName;
255  TFile *Outputfile;
257  std::vector<TDirectory*> Dir;
258 
260  TTree *OutputTree;
262  std::vector<double> llh_data_draw;
264  std::vector<double> llh_drawfluc_draw;
266  std::vector<double> llh_predfluc_draw;
267 
269  std::vector<double> llh_rate_data_draw;
271  std::vector<double> llh_rate_predfluc_draw;
272 
274  std::vector<double> llh_data_drawfluc;
276  std::vector<double> llh_data_predfluc;
278  std::vector<double> llh_draw_pred;
280  std::vector<double> llh_drawfluc_pred;
281 
283  std::vector<double> llh_predfluc_pred;
285  std::vector<double> llh_drawfluc_predfluc;
287  std::vector<double> llh_datafluc_draw;
288 
290  std::vector<double> llh_data_draw_ProjectX;
291  std::vector<double> llh_drawfluc_draw_ProjectX;
292 
294  double llh_penalty;
295 
302 
307 
322 
327 
331  std::vector<std::vector<TH2Poly*>> MeanHist_ByMode;
334 
337 
340 
343 
346 
348  int Debug;
349 };
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:41
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:22
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.
SampleHandlerBase * SampleHandler
Pointer to SampleHandler object, mostly used to get sample names, binning etc.
~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.
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....
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.
SampleSummary(const int n_Samples, const std::string &Filename, SampleHandlerBase *const sample, const int nSteps)
Constructor.
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:50
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:48
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.
Definition: Core.h:19
kInfCrit
KS: Different Information Criterion tests mostly based Gelman paper.
Definition: SampleSummary.h:10
@ kWAIC
Watanabe-Akaike information criterion.
Definition: SampleSummary.h:13
@ kInfCrits
This only enumerates.
Definition: SampleSummary.h:14
@ kBIC
Bayesian Information Criterion.
Definition: SampleSummary.h:11
@ kDIC
Deviance Information Criterion.
Definition: SampleSummary.h:12