![]() |
MaCh3
2.4.2
Reference Guide
|
Class responsible for handling implementation of samples used in analysis, reweighting and returning LLH. More...
#include <Samples/SampleHandlerBase.h>
Public Member Functions | |
| SampleHandlerBase () | |
| The main constructor. More... | |
| virtual | ~SampleHandlerBase () |
| destructor More... | |
| virtual M3::int_t | GetNsamples () |
| virtual std::string | GetSampleTitle (const int Sample) const =0 |
| virtual std::string | GetName () const =0 |
| virtual double | GetSampleLikelihood (const int isample) const =0 |
| virtual void | CleanMemoryBeforeFit ()=0 |
| Allow to clean not used memory before fit starts. More... | |
| virtual void | SaveAdditionalInfo (TDirectory *Dir) |
| Store additional info in a chan. More... | |
| MaCh3Modes * | GetMaCh3Modes () const |
| Return pointer to MaCh3 modes. More... | |
| virtual void | Reweight ()=0 |
| virtual double | GetLikelihood () const =0 |
| virtual void | PrintRates (const bool DataOnly=false)=0 |
| Helper function to print rates for the samples with LLH. More... | |
| unsigned int | GetNEvents () const |
| virtual int | GetNOscChannels (const int iSample) const =0 |
| virtual std::string | GetKinVarName (const int iSample, const int Dimension) const =0 |
| Return Kinematic Variable name for specified sample and dimension for example "Reconstructed_Neutrino_Energy". More... | |
| virtual TH1 * | GetDataHist (const int Sample)=0 |
| Get Data histogram. More... | |
| virtual TH1 * | GetMCHist (const int Sample)=0 |
| Get MC histogram. More... | |
| virtual TH1 * | GetW2Hist (const int Sample)=0 |
| Get W2 histogram. More... | |
| virtual int | GetNDim (const int Sample) const =0 |
| DB Function to differentiate 1D or 2D binning. More... | |
| virtual std::string | GetFlavourName (const int iSample, const int iChannel) const =0 |
| virtual std::vector< double > | ReturnKinematicParameterBinning (const int Sample, const std::string &KinematicParameter) const =0 |
| Return the binning used to draw a kinematic parameter. More... | |
| virtual TH1 * | Get1DVarHistByModeAndChannel (const int iSample, const std::string &ProjectionVar_Str, int kModeToFill=-1, int kChannelToFill=-1, int WeightStyle=0, TAxis *Axis=nullptr)=0 |
| virtual TH2 * | Get2DVarHistByModeAndChannel (const int iSample, const std::string &ProjectionVar_StrX, const std::string &ProjectionVar_StrY, int kModeToFill=-1, int kChannelToFill=-1, int WeightStyle=0, TAxis *AxisX=nullptr, TAxis *AxisY=nullptr)=0 |
| virtual TH1 * | Get1DVarHist (const int iSample, const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, TAxis *Axis=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec={})=0 |
| virtual TH2 * | Get2DVarHist (const int iSample, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, TAxis *AxisX=nullptr, TAxis *AxisY=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec={})=0 |
| double | GetPoissonLLH (const double data, const double mc) const |
| Calculate test statistic for a single bin using Poisson. More... | |
| double | GetTestStatLLH (const double data, const double mc, const double w2) const |
Calculate test statistic for a single bin. Calculation depends on setting of fTestStatistic. Data and mc -> 0 cut-offs are defined in M3::LOW_MC_BOUND. More... | |
| void | SetTestStatistic (TestStatistic testStat) |
| Set the test statistic to be used when calculating the binned likelihoods. More... | |
| TestStatistic | GetTestStatistic () const |
| Get the test statistic used when calculating the binned likelihoods. More... | |
Protected Member Functions | |
| void | QuietPlease () |
| CW: Redirect std::cout to silence some experiment specific libraries. More... | |
| void | NowTalk () |
| CW: Redirect std::cout to silence some experiment specific libraries. More... | |
| template<typename T > | |
| bool | MatchCondition (const std::vector< T > &allowedValues, const T &value) |
| check if event is affected by following conditions, for example pdg, or modes etc More... | |
Protected Attributes | |
| TestStatistic | fTestStatistic |
| Test statistic tells what kind of likelihood sample is using. More... | |
| std::streambuf * | buf |
| Keep the cout buffer. More... | |
| std::streambuf * | errbuf |
| Keep the cerr buffer. More... | |
| M3::int_t | nSamples |
| Contains how many samples we've got. More... | |
| unsigned int | nEvents |
| Number of MC events are there. More... | |
| std::unique_ptr< MaCh3Modes > | Modes |
| Holds information about used Generator and MaCh3 modes. More... | |
Class responsible for handling implementation of samples used in analysis, reweighting and returning LLH.
Definition at line 26 of file SampleHandlerBase.h.
| SampleHandlerBase::SampleHandlerBase | ( | ) |
The main constructor.
Definition at line 4 of file SampleHandlerBase.cpp.
|
virtual |
destructor
Definition at line 11 of file SampleHandlerBase.cpp.
|
pure virtual |
Allow to clean not used memory before fit starts.
Implemented in PySampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Get Data histogram.
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Return Kinematic Variable name for specified sample and dimension for example "Reconstructed_Neutrino_Energy".
| iSample | Sample index |
| Dimension | Dimension index |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inline |
Return pointer to MaCh3 modes.
Definition at line 43 of file SampleHandlerBase.h.
|
pure virtual |
Get MC histogram.
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
DB Function to differentiate 1D or 2D binning.
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inline |
Definition at line 52 of file SampleHandlerBase.h.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inlinevirtual |
Definition at line 34 of file SampleHandlerBase.h.
| double SampleHandlerBase::GetPoissonLLH | ( | const double | data, |
| const double | mc | ||
| ) | const |
Calculate test statistic for a single bin using Poisson.
| data | is data |
| mc | is mc |
Definition at line 17 of file SampleHandlerBase.cpp.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inline |
Get the test statistic used when calculating the binned likelihoods.
Definition at line 184 of file SampleHandlerBase.h.
| double SampleHandlerBase::GetTestStatLLH | ( | const double | data, |
| const double | mc, | ||
| const double | w2 | ||
| ) | const |
Calculate test statistic for a single bin. Calculation depends on setting of fTestStatistic. Data and mc -> 0 cut-offs are defined in M3::LOW_MC_BOUND.
Standard Poisson log-likelihood (Stirling approximation) [2]
\[ - \log \mathcal{L}_\mathrm{Poisson} = \sum_i N_i^\mathrm{MC} - N_i^\mathrm{data} + N_i^\mathrm{data} \ln \frac{N_i^\mathrm{data}}{N_i^\mathrm{MC}}, \]
Standard Pearson likelihood [25] (assumes Gaussian approximation of bin counts):
\[ - \log \mathcal{L}_\mathrm{Pearson} = \sum_i \frac{(N_i^\mathrm{data} - N_i^\mathrm{MC})^2}{2 \, N_i^\mathrm{MC}} \]
Based on [3] and following Conway approximation ([5]) The generation of MC is a stochastic process, so even identical settings can lead to different outputs (assuming that the seeds of the random number generator are different). This introduces uncertainty in MC distributions, especially in bins with low statistics.
\[ - \log \mathcal{L}_\mathrm{BB} = - \log \mathcal{L}_\mathrm{Poisson} - \log \mathcal{L}_\mathrm{MC_{stat}} = \sum_i \Biggl[ N_i^\mathrm{MC}(\vec{\theta}) - N_i^\mathrm{data} + N_i^\mathrm{data} \ln \frac{N_i^\mathrm{data}}{N_i^\mathrm{MC}(\vec{\theta})} + \frac{(\beta_i - 1)^2}{2 \sigma_{\beta_i}^2} \Biggr], \]
where \(\beta_i\) is a scaling parameter between ideal ("true") and generated MC in a bin ( \(N^\mathrm{true}_{\mathrm{MC},i} = \beta_i N_i^\mathrm{MC}\)), and \(\sigma^2_{\beta_i} = \frac{\sum_i w_i^2}{N_i^\mathrm{MC}}\), with \(\sum_i w_i^2\) being the sum of the squares of weights in bin \(i\). Assuming \(\beta_i\) follows a Gaussian, its mean can be found by solving the quadratic equation derived by Conway:
\[ \beta_i^2 + (N_i^\mathrm{MC} \sigma_{\beta_i}^2 - 1)\beta_i - N_i^\mathrm{data} \sigma_{\beta_i}^2 = 0 \]
Alternative treatment of MC statistical uncertainty following Hans Dembinski and Ahmed Abdelmotteleb [6]
This approach extends the Barlow-Beeston method. For each bin:
\[ - \log \mathcal{L}_\mathrm{DA} = (N_i^{\mathrm{MC},\prime} - N_i^\mathrm{data} + N_i^\mathrm{data} \ln \frac{N_i^\mathrm{data}}{N_i^{\mathrm{MC},\prime}}) + k \beta - k + k \ln \frac{k}{k \beta} \]
where
\[ k = \frac{(N_i^\mathrm{MC})^2}{\sum_i w_i^2} \]
and
\[ \beta = \frac{N_i^\mathrm{data} + k}{N_i^\mathrm{MC} + k}, \quad N_i^{\mathrm{MC},\prime} = N_i^\mathrm{MC} \cdot \beta \]
Alternative likelihood definition described by the IceCube collaboration [1]
\[ - \log \mathcal{L} = - \sum_i \Biggl( a_i \log(b_i) + \log[\Gamma(N_i^{\mathrm{data}}+a_i)] - (N_i^{\mathrm{data}}+a_i)\log(b_i+1) - \log[\Gamma(a_i)] \Biggr), \]
where the auxiliary variables are
\[ a_i = N^{\mathrm{gen}}_{\mathrm{MC},i} \, b_i + 1, \quad b_i = \frac{N^{\mathrm{gen}}_{\mathrm{MC},i}}{\sum_i w_i^2}. \]
Implemented fTestStatistic are kPoisson (with Stirling's approx.), kBarlowBeeston (arXiv:1103.0354), kDembinskiAbdelmotteleb (arXiv:2206.12346), kIceCube (arxiv:1901.04645), and kPearson. Test statistics require mc > 0, therefore low mc and data values are treated with cut-offs based on M3::LOW_MC_BOUND = .00001 by default. For kPoisson, kBarlowBeeston, kDembinskiAbdelmotteleb, kPearson: data > LOW_MC_BOUND & mc <= LOW_MC_BOUND: returns GetTestStatLLH(data, LOW_MC_BOUND, w2), with Poisson(data,LOW_MC_BOUND) limit for mc->0, w2->0. mc < data <= LOW_MC_BOUND: returns 0 (as if any data <= LOW_MC_BOUND were effectively consistent with 0 data count), with a limit of 0 for mc->0. data = 0: returns mc (or mc/2. for kPearson), with a limit of 0 for mc->0. For kIceCube: mc < data returns the lower of IceCube(data,mc,w2) and Poisson(data,mc) penalties, with a Poisson(data,LOW_MC_BOUND) limit for mc->0, w2->0.
| data | is data |
| mc | is mc |
| w2 | is \(\sum_{i} w_{i}^2\) (sum of weights squared), which is \(\sigma^2_{\text{MC stats}}\) |
Definition at line 35 of file SampleHandlerBase.cpp.
|
pure virtual |
Get W2 histogram.
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inlineprotected |
check if event is affected by following conditions, for example pdg, or modes etc
Definition at line 194 of file SampleHandlerBase.h.
|
protected |
CW: Redirect std::cout to silence some experiment specific libraries.
Definition at line 210 of file SampleHandlerBase.cpp.
|
pure virtual |
Helper function to print rates for the samples with LLH.
| DataOnly | whether to print data only rates |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
protected |
CW: Redirect std::cout to silence some experiment specific libraries.
Definition at line 196 of file SampleHandlerBase.cpp.
|
pure virtual |
Return the binning used to draw a kinematic parameter.
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
pure virtual |
Implemented in SampleHandlerFD, and PySampleHandlerBase.
|
inlinevirtual |
Store additional info in a chan.
Reimplemented in SampleHandlerFD.
Definition at line 41 of file SampleHandlerBase.h.
|
inline |
Set the test statistic to be used when calculating the binned likelihoods.
| testStat | The test statistic to use. |
Definition at line 182 of file SampleHandlerBase.h.
|
protected |
Keep the cout buffer.
Definition at line 205 of file SampleHandlerBase.h.
|
protected |
Keep the cerr buffer.
Definition at line 207 of file SampleHandlerBase.h.
|
protected |
Test statistic tells what kind of likelihood sample is using.
Definition at line 202 of file SampleHandlerBase.h.
|
protected |
Holds information about used Generator and MaCh3 modes.
Definition at line 216 of file SampleHandlerBase.h.
|
protected |
Number of MC events are there.
Definition at line 213 of file SampleHandlerBase.h.
|
protected |
Contains how many samples we've got.
Definition at line 210 of file SampleHandlerBase.h.