![]() |
MaCh3
2.5.1
Reference Guide
|
Class responsible for handling implementation of samples used in analysis, reweighting and returning LLH. More...
#include <Samples/SampleHandlerInterface.h>
Public Member Functions | |
| SampleHandlerInterface () | |
| The main constructor. More... | |
| virtual | ~SampleHandlerInterface () |
| destructor More... | |
| virtual M3::int_t | GetNSamples () |
| returns total number of samples More... | |
| virtual std::string | GetSampleTitle (const int iSample) const =0 |
| Get fancy title for specified samples. More... | |
| virtual std::string | GetName () const =0 |
| Get name for Sample Handler. More... | |
| virtual double | GetSampleLikelihood (const int iSample) const =0 |
| Get likelihood (-logL) for a single sample. More... | |
| virtual void | CleanMemoryBeforeFit ()=0 |
| Allow to clean not used memory before fit starts. More... | |
| virtual void | SaveAdditionalInfo (TDirectory *Dir) |
| Store additional info in a chain. More... | |
| MaCh3Modes * | GetMaCh3Modes () const |
| Return pointer to MaCh3 modes. More... | |
| virtual void | Reweight ()=0 |
| main routine modifying MC prediction based on proposed parameter values More... | |
| virtual double | GetLikelihood () const =0 |
| Return likelihood (-logL) for all samples. More... | |
| virtual void | PrintRates (const bool DataOnly=false)=0 |
| Helper function to print rates for the samples with LLH. More... | |
| unsigned int | GetNEvents () const |
| Return total number of events. More... | |
| virtual int | GetNOscChannels (const int iSample) const =0 |
| Get number of oscillation channels for a single sample. More... | |
| 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 const TH1 * | GetDataHist (const int Sample)=0 |
| Get Data histogram. More... | |
| virtual const TH1 * | GetMCHist (const int Sample)=0 |
| Get MC histogram. More... | |
| virtual const TH1 * | GetW2Hist (const int Sample)=0 |
| Get W2 histogram. More... | |
| virtual int | GetNDim (const int Sample) const =0 |
| DB Get what dimensionality binning for given sample has. More... | |
| virtual std::string | GetFlavourName (const int iSample, const int iChannel) const =0 |
| Get the flavour name for a given sample and oscillation channel. More... | |
| 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 std::unique_ptr< TH1 > | Get1DVarHistByModeAndChannel (const int iSample, const std::string &ProjectionVar_Str, const int kModeToFill=-1, const int kChannelToFill=-1, const int WeightStyle=0)=0 |
| Build a 1D histogram for a given variable, optionally filtered by mode and channel. More... | |
| virtual std::unique_ptr< TH2 > | Get2DVarHistByModeAndChannel (const int iSample, const std::string &ProjectionVar_StrX, const std::string &ProjectionVar_StrY, int kModeToFill=-1, const int kChannelToFill=-1, const int WeightStyle=0)=0 |
| Build a 2D histogram for given variables, optionally filtered by mode and channel. More... | |
| virtual std::unique_ptr< TH1 > | Get1DVarHist (const int iSample, const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={})=0 |
| Return 1D projection of MC into given 1D variable (doesn't have to be variable used in the fit) More... | |
| virtual std::unique_ptr< TH2 > | Get2DVarHist (const int iSample, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec={}, const int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={})=0 |
| Build a 2D projection of MC events into specified variables. More... | |
| 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.
It serves as basic interface for fit running, as well as other fucnitonalsities liek llh scan, sigma var or event posterior predictive disturibon. Concrete implementations of this interface are responsible for defining the specific structure of samples, event selections, and histogram filling.
Definition at line 34 of file SampleHandlerInterface.h.
| SampleHandlerInterface::SampleHandlerInterface | ( | ) |
The main constructor.
Definition at line 4 of file SampleHandlerInterface.cpp.
|
virtual |
destructor
Definition at line 11 of file SampleHandlerInterface.cpp.
|
pure virtual |
Allow to clean not used memory before fit starts.
Implemented in PySampleHandlerBase, PySampleHandlerInterface, and SampleHandlerNuDockBase.
|
pure virtual |
Return 1D projection of MC into given 1D variable (doesn't have to be variable used in the fit)
| iSample | Index of the sample. |
| ProjectionVar | name of variable |
| EventSelectionVec | Vector of additional cuts like cut on interaction mode |
| WeightStyle | Alow to modify weight for example if equal to 1 all weights are set to 1 |
| SubEventSelectionVec | Vector of additional cuts for sub event (particle, ring etc.) |
Implemented in SampleHandlerNuDockBase, SampleHandlerBase, and PySampleHandlerInterface.
|
pure virtual |
Build a 1D histogram for a given variable, optionally filtered by mode and channel.
| iSample | Index of the sample. |
| ProjectionVar_Str | Name of the variable to project onto. |
| kModeToFill | Interaction mode to select (-1 means all modes). |
| kChannelToFill | Oscillation channel to select (-1 means all channels). |
| WeightStyle | Weighting scheme (e.g. 0 = nominal weights, 1 = unit weights). |
Implemented in SampleHandlerNuDockBase, PySampleHandlerInterface, and SampleHandlerBase.
|
pure virtual |
Build a 2D projection of MC events into specified variables.
| iSample | Index of the sample. |
| ProjectionVarX | Name of the variable for the X axis. |
| ProjectionVarY | Name of the variable for the Y axis. |
| EventSelectionVec | Vector of event-level selection cuts. |
| WeightStyle | Weighting scheme (e.g. 0 = nominal weights, 1 = unit weights). |
| SubEventSelectionVec | Vector of sub-event selection cuts. |
Implemented in SampleHandlerNuDockBase, SampleHandlerBase, and PySampleHandlerInterface.
|
pure virtual |
Build a 2D histogram for given variables, optionally filtered by mode and channel.
| iSample | Index of the sample. |
| ProjectionVar_StrX | Name of the variable for the X axis. |
| ProjectionVar_StrY | Name of the variable for the Y axis. |
| kModeToFill | Interaction mode to select (-1 means all modes). |
| kChannelToFill | Oscillation channel to select (-1 means all channels). |
| WeightStyle | Weighting scheme (e.g. 0 = nominal weights, 1 = unit weights). |
Implemented in SampleHandlerNuDockBase, PySampleHandlerInterface, and SampleHandlerBase.
|
pure virtual |
Get Data histogram.
| Sample | Sample enumerator |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
Get the flavour name for a given sample and oscillation channel.
| iSample | Index of the sample. |
| iChannel | Index of the oscillation channel within the sample. |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
Return Kinematic Variable name for specified sample and dimension for example "Reconstructed_Neutrino_Energy".
| iSample | Sample index |
| Dimension | Dimension index |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
Return likelihood (-logL) for all samples.
Implemented in SampleHandlerBase, PySampleHandlerInterface, and SampleHandlerNuDockBase.
|
inline |
Return pointer to MaCh3 modes.
Definition at line 58 of file SampleHandlerInterface.h.
|
pure virtual |
Get MC histogram.
| Sample | Sample enumerator |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
Get name for Sample Handler.
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
DB Get what dimensionality binning for given sample has.
| Sample | Number of sample |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
inline |
|
pure virtual |
Get number of oscillation channels for a single sample.
| iSample | Sample enumerator |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
inlinevirtual |
| double SampleHandlerInterface::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 SampleHandlerInterface.cpp.
|
pure virtual |
Get likelihood (-logL) for a single sample.
| iSample | Sample enumerator |
Implemented in SampleHandlerBase, PySampleHandlerInterface, and SampleHandlerNuDockBase.
|
pure virtual |
Get fancy title for specified samples.
| iSample | Sample enumerator |
Implemented in SampleHandlerNuDockBase, SampleHandlerBase, and PySampleHandlerInterface.
|
inline |
Get the test statistic used when calculating the binned likelihoods.
Definition at line 237 of file SampleHandlerInterface.h.
| double SampleHandlerInterface::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 [27] (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 SampleHandlerInterface.cpp.
|
pure virtual |
Get W2 histogram.
| Sample | Sample enumerator |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
inlineprotected |
check if event is affected by following conditions, for example pdg, or modes etc
Definition at line 247 of file SampleHandlerInterface.h.
|
protected |
CW: Redirect std::cout to silence some experiment specific libraries.
Definition at line 210 of file SampleHandlerInterface.cpp.
|
pure virtual |
Helper function to print rates for the samples with LLH.
| DataOnly | whether to print data only rates |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
protected |
CW: Redirect std::cout to silence some experiment specific libraries.
Definition at line 196 of file SampleHandlerInterface.cpp.
|
pure virtual |
Return the binning used to draw a kinematic parameter.
| iSample | Index of the sample. |
| KinematicParameter | name of variable |
Implemented in PySampleHandlerInterface, SampleHandlerNuDockBase, and SampleHandlerBase.
|
pure virtual |
main routine modifying MC prediction based on proposed parameter values
Implemented in SampleHandlerBase, PySampleHandlerInterface, and SampleHandlerNuDockBase.
|
inlinevirtual |
Store additional info in a chain.
| Dir | directory to which we save additional info |
Reimplemented in SampleHandlerBase.
Definition at line 56 of file SampleHandlerInterface.h.
|
inline |
Set the test statistic to be used when calculating the binned likelihoods.
| testStat | The test statistic to use. |
Definition at line 235 of file SampleHandlerInterface.h.
|
protected |
Keep the cout buffer.
Definition at line 258 of file SampleHandlerInterface.h.
|
protected |
Keep the cerr buffer.
Definition at line 260 of file SampleHandlerInterface.h.
|
protected |
Test statistic tells what kind of likelihood sample is using.
Definition at line 255 of file SampleHandlerInterface.h.
|
protected |
Holds information about used Generator and MaCh3 modes.
Definition at line 269 of file SampleHandlerInterface.h.
|
protected |
Number of MC events are there.
Definition at line 266 of file SampleHandlerInterface.h.
|
protected |
Contains how many samples we've got.
Definition at line 263 of file SampleHandlerInterface.h.