MaCh3  2.4.2
Reference Guide
PredictiveThrower.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Fitters/FitterBase.h"
4 
6 class BinningHandler;
7 class SampleHandlerFD;
8 
9 // ***************************
12 // ***************************
13  // Name of sample
14  std::string Name;
20  int LocalId;
23 };
24 
35 
42 class PredictiveThrower : public FitterBase {
43  public:
48  virtual ~PredictiveThrower();
49 
51  void ProduceToys();
52 
54  void RunPredictiveAnalysis();
55 
57  void RunMCMC() override {
58  MACH3LOG_ERROR("{} is not supported in {}", __func__, GetName());
59  throw MaCh3Exception(__FILE__ , __LINE__ );
60  };
61 
62  private:
64  void SetParamters();
65 
67  void SetupToyGeneration();
68 
70  bool LoadToys();
71 
74 
76  std::vector<std::string> GetStoredFancyName(ParameterHandlerBase* Systematics) const;
77 
79  std::vector<std::unique_ptr<TH1>> MakePredictive(const std::vector<std::vector<std::unique_ptr<TH1>>>& Toys,
80  const std::vector<TDirectory*>& Director,
81  const std::string& suffix,
82  const bool DebugHistograms);
83 
85  std::vector<std::vector<std::unique_ptr<TH2D>>> ProduceSpectra(
86  const std::vector<std::vector<std::unique_ptr<TH1>>>& Toys,
87  const std::vector<TDirectory*>& Director,
88  const std::string suffix);
89 
91  void PosteriorPredictivepValue(const std::vector<std::unique_ptr<TH1>>& PostPred_mc,
92  const std::vector<TDirectory*>& SampleDir);
93 
94 
99  double GetLLH(const std::unique_ptr<TH1>& DatHist,
100  const std::unique_ptr<TH1>& MCHist,
101  const std::unique_ptr<TH1>& W2Hist,
102  const SampleHandlerBase* SampleHandler);
103 
105  void MakeChi2Plots(const std::vector<std::vector<double>>& Chi2_x,
106  const std::string& Chi2_x_title,
107  const std::vector<std::vector<double>>& Chi2_y,
108  const std::string& Chi2_y_title,
109  const std::vector<TDirectory*>& SampleDir,
110  const std::string Title);
111 
112 
114  void StudyBetaParameters(TDirectory* PredictiveDir);
115 
117  bool FullLLH;
122 
125 
127  std::vector<PredictiveSample> SampleInfo;
128 
130  int Ntoys;
132  std::vector<std::string> ParameterGroupsNotVaried;
134  std::unordered_set<int> ParameterOnlyToVary;
135 
138 
140  std::vector<std::unique_ptr<TH1>> Data_Hist;
142  std::vector<std::unique_ptr<TH1>> MC_Nom_Hist;
144  std::vector<std::unique_ptr<TH1>> W2_Nom_Hist;
145 
148  std::vector<std::vector<std::unique_ptr<TH1>>> MC_Hist_Toy;
151  std::vector<std::vector<std::unique_ptr<TH1>>> W2_Hist_Toy;
152 
154  std::vector<double> ReweightWeight;
156  std::vector<double> PenaltyTerm;
157 };
158 
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
KS: Class handling binning for multiple samples.
Base class for implementing fitting algorithms.
Definition: FitterBase.h:26
std::string GetName() const
Get name of class.
Definition: FitterBase.h:70
Manager * fitMan
The manager for configuration handling.
Definition: FitterBase.h:108
Custom exception class used throughout MaCh3.
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
Base class responsible for handling of systematic error parameters. Capable of using PCA or using ada...
Class responsible for handling of systematic error parameters with different types defined in the con...
Implementation of Prior/Posterior Predictive and Bayesian p-Value calculations following the approach...
void SetParamters()
This set some params to prior value this way you can evaluate errors from subset of errors.
std::vector< double > PenaltyTerm
Penalty term values for each toy by default 0.
virtual ~PredictiveThrower()
Destructor.
std::vector< std::vector< std::unique_ptr< TH2D > > > ProduceSpectra(const std::vector< std::vector< std::unique_ptr< TH1 >>> &Toys, const std::vector< TDirectory * > &Director, const std::string suffix)
Produce Violin style spectra.
bool FullLLH
KS: Use Full LLH or only sample contribution based on discussion with Asher we almost always only wan...
void RunPredictiveAnalysis()
Main routine responsible for producing posterior predictive distributions and $p$-value.
bool LoadToys()
Load existing toys.
void PosteriorPredictivepValue(const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< TDirectory * > &SampleDir)
Calculate Posterior Predictive $p$-value.
std::vector< std::unique_ptr< TH1 > > MakePredictive(const std::vector< std::vector< std::unique_ptr< TH1 >>> &Toys, const std::vector< TDirectory * > &Director, const std::string &suffix, const bool DebugHistograms)
Produce posterior predictive distribution.
std::vector< std::string > GetStoredFancyName(ParameterHandlerBase *Systematics) const
Get Fancy parameters stored in mcmc chains for passed ParameterHandler.
std::vector< std::unique_ptr< TH1 > > W2_Nom_Hist
Vector of W2 histograms.
std::unordered_set< int > ParameterOnlyToVary
KS: Index of parameters that will be varied.
std::vector< std::vector< std::unique_ptr< TH1 > > > W2_Hist_Toy
double GetLLH(const std::unique_ptr< TH1 > &DatHist, const std::unique_ptr< TH1 > &MCHist, const std::unique_ptr< TH1 > &W2Hist, const SampleHandlerBase *SampleHandler)
Helper functions to calculate likelihoods using TH1.
bool Is_PriorPredictive
Whether it is Prior or Posterior predictive.
std::vector< std::string > ParameterGroupsNotVaried
KS: Names of parameter groups that will not be varied.
int NModelParams
KS: Count total number of model parameters which can be used for stuff like BIC.
void RunMCMC() override
This is not used in this class.
int Ntoys
Number of toys we are generating analysing.
void SetupToyGeneration()
Setup useful variables etc before stating toy generation.
void MakeChi2Plots(const std::vector< std::vector< double >> &Chi2_x, const std::string &Chi2_x_title, const std::vector< std::vector< double >> &Chi2_y, const std::string &Chi2_y_title, const std::vector< TDirectory * > &SampleDir, const std::string Title)
Produce Chi2 plot for a single sample based on which $p$-value is calculated.
void SetupSampleInformation()
Setup sample information.
std::vector< std::unique_ptr< TH1 > > MC_Nom_Hist
Vector of MC histograms.
int TotalNumberOfSamples
Number of toys we are generating analysing.
void ProduceToys()
Produce toys by throwing from MCMC.
void StudyBetaParameters(TDirectory *PredictiveDir)
Evaluate prior/post predictive distribution for beta parameters (used for evaluating impact MC statis...
std::vector< std::unique_ptr< TH1 > > Data_Hist
Vector of Data histograms.
ParameterHandlerGeneric * ModelSystematic
Pointer to El Generico.
std::vector< double > ReweightWeight
Reweighting factors applied for each toy, by default 1.
PredictiveThrower(Manager *const fitMan)
Constructor.
std::vector< std::vector< std::unique_ptr< TH1 > > > MC_Hist_Toy
std::vector< PredictiveSample > SampleInfo
Handy struct for all sample info.
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...
Class responsible for handling implementation of samples used in analysis, reweighting and returning ...
KS: Summary of sample info to be used by.
int LocalId
Local SampleId in SampleHandler.
int Dimenstion
Sample Dimension.
const SampleHandlerFD * SamHandler
Pointer to SampleHandler.
const BinningHandler * Binning
Pointer to binning handler.