MaCh3  2.4.2
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 // *******************
24 // *******************
25  public:
31  SampleSummary(const int n_Samples, const std::string &Filename, SampleHandlerBase* const sample, const int nSteps);
34 
37  void AddData(std::vector<TH2Poly*> &DataHist);
39  void AddNominal(std::vector<TH2Poly*> &NominalHist, std::vector<TH2Poly*> &W2Nom);
41  void AddThrow(std::vector<TH2Poly*> &MCHist, std::vector<TH2Poly*> &W2Hist, const double LLHPenalty = 0.0, const double Weight = 1.0, const int DrawNumber = 0);
43  void AddThrowByMode(std::vector<std::vector<TH2Poly*>> &SampleVector_ByMode);
44 
46  void Write();
47 
49  inline void SetLikelihood(const TestStatistic TestStat){ likelihood = TestStat;};
51  inline void SetNModelParams(const int nPars){ nModelParams = nPars;};
52 
53  private:
55  inline void MakePredictive();
56 
58  inline void PrepareOutput();
59 
64  inline void CalcLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
69  inline void CalcLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
70 
75  inline double GetLLH(TH2Poly * const & Data, TH2Poly * const & MC, TH2Poly * const & W2);
80  inline double GetLLH(TH1D * const & Data, TH1D * const & MC, TH1D * const & W2);
81 
83  inline void PlotBetaParameters();
84 
86  inline void StudyKinematicCorrelations();
87 
89  inline void MakeCutLLH();
90  // Make the 1D cut distribution and give the 1D p-value
91  inline void MakeCutLLH1D(TH1D *Histogram, double llh_ref = -999);
93  inline void MakeCutEventRate(TH1D *Histogram, const double DataRate);
98  inline void MakeChi2Hists();
99 
101  inline bool CheckSamples(const int Length);
102 
104  inline TH1D* ProjectHist(TH2D* Histogram, const bool ProjectX);
106  inline TH1D* ProjectPoly(TH2Poly* Histogram, const bool ProjectX, const int selection, const bool MakeErrorHist = false);
107 
109  inline void MakeFluctuatedHistogram(TH1D *FluctHist, TH1D* PolyHist);
110 
112  inline void MakeFluctuatedHistogram(TH2Poly *FluctHist, TH2Poly* PolyHist);
113 
115  inline void StudyInformationCriterion(M3::kInfCrit Criterion);
116 
119  inline void StudyBIC();
120 
124  inline void StudyDIC();
125 
129  inline void StudyWAIC();
130 
132  std::unique_ptr<TRandom3> rnd;
135 
138 
140  std::vector<std::vector<TH2Poly*>> MCVector;
142  std::vector<std::vector<TH2Poly*>> W2MCVector;
144  std::vector<std::vector<std::vector<TH2Poly*>>> MCVectorByMode;
145 
147  std::vector<double> LLHPenaltyVector;
149  std::vector<double> WeightVector;
150 
152  int nSamples;
153 
155  std::vector<std::string> SampleNames;
156 
158  std::vector<std::vector<std::unique_ptr<TH1D>>> PosteriorHist;
160  std::vector<std::vector<std::unique_ptr<TH1D>>> w2Hist;
161 
163  std::vector<TH2D*> ViolinHists_ProjectX;
165  std::vector<TH2D*> ViolinHists_ProjectY;
166 
168  std::vector<TH2Poly*> DataHist;
170  std::vector<TH1D*> DataHist_ProjectX;
172  std::vector<TH1D*> DataHist_ProjectY;
174  std::vector<TH2Poly*> NominalHist;
176  std::vector<TH2Poly*> W2NomHist;
178  std::vector<TH2Poly*> W2MeanHist;
180  std::vector<TH2Poly*> W2ModeHist;
181 
183  std::unique_ptr<TH1D> lnLHist;
185  std::unique_ptr<TH1D> lnLHist_drawfluc;
187  std::unique_ptr<TH1D> lnLHist_drawflucdraw;
189  std::unique_ptr<TH1D> lnLHist_drawdata;
191  std::unique_ptr<TH2D> lnLDrawHist;
193  std::unique_ptr<TH2D> lnLFlucHist;
194 
196  std::unique_ptr<TH2D> lnLDrawHistRate;
198  std::unique_ptr<TH2D> lnLFlucHist_ProjectX;
199 
201  std::vector<TH1D*> lnLHist_Sample_DrawData;
203  std::vector<TH1D*> lnLHist_Sample_DrawflucDraw;
205  std::vector<TH1D*> lnLHist_Sample_PredflucDraw;
206 
208  std::vector<TH2Poly*> lnLHist_Mean;
210  std::vector<TH2Poly*> lnLHist_Mode;
211 
213  std::vector<TH1D*> lnLHist_Mean_ProjectX;
214 
216  std::vector<TH2Poly*> MeanHist;
218  std::vector<TH2Poly*> MeanHistCorrected;
220  std::vector<TH2Poly*> ModeHist;
221 
223  std::vector<TH1D*> lnLHist_Mean1D;
225  std::vector<TH1D*> lnLHist_Mode1D;
226 
228  std::unique_ptr<TH1D> RandomHist;
229 
231  std::vector<std::vector<std::unique_ptr<TH1D>>> BetaHist;
234 
236  unsigned int nChainSteps;
237 
240 
243 
245  unsigned int nThrows;
246 
248  std::vector<int> maxBins;
249 
251  double llh_total;
252 
254  std::string OutputName;
256  TFile *Outputfile;
258  std::vector<TDirectory*> Dir;
259 
261  TTree *OutputTree;
263  std::vector<double> llh_data_draw;
265  std::vector<double> llh_drawfluc_draw;
267  std::vector<double> llh_predfluc_draw;
268 
270  std::vector<double> llh_rate_data_draw;
272  std::vector<double> llh_rate_predfluc_draw;
273 
275  std::vector<double> llh_data_drawfluc;
277  std::vector<double> llh_data_predfluc;
279  std::vector<double> llh_draw_pred;
281  std::vector<double> llh_drawfluc_pred;
282 
284  std::vector<double> llh_predfluc_pred;
286  std::vector<double> llh_drawfluc_predfluc;
288  std::vector<double> llh_datafluc_draw;
289 
291  std::vector<double> llh_data_draw_ProjectX;
292  std::vector<double> llh_drawfluc_draw_ProjectX;
293 
295  double llh_penalty;
296 
303 
308 
323 
328 
332  std::vector<std::vector<TH2Poly*>> MeanHist_ByMode;
335 
338 
341 
344 
347 
349  int Debug;
350 };
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:23
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:51
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:49
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.
Main namespace for MaCh3 software.
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