6 #include <unordered_map>
16 #include "TObjString.h"
22 #include "Constants/OscillatorConstants.h"
36 constexpr
unsigned int str2int(
const char* str,
const int h = 0) {
38 return !str[h] ? 5381 : (
str2int(str, h+1) * 33) ^ str[h];
92 name =
"TargetMat_Undefined";
125 std::string name =
"";
132 name =
"Barlow-Beeston";
141 name =
"Dembinski-Abdelmotteleb";
148 MACH3LOG_ERROR(
"You gave test-statistic {}",
static_cast<int>(TestStat));
205 int GetBin(
const int xBin,
const int yBin)
const {
206 return static_cast<int>(yBin *
nXBins + xBin);
215 if (xBin < 0 || yBin < 0 ||
static_cast<size_t>(xBin) >=
nXBins ||
static_cast<size_t>(yBin) >=
nYBins) {
216 MACH3LOG_ERROR(
"GetBinSafe: Bin indices out of range: xBin={}, yBin={}, max xBin={}, max yBin={}",
220 return GetBin(xBin, yBin);
231 int FindXBin(
const double XVar,
const int NomXBin)
const {
241 else if (XVar < xBin.upper_binedge && XVar >= xBin.lower_binedge) {
246 else if (XVar < xBin.lower_binedge && XVar >= xBin.lower_lower_binedge) {
250 else if (XVar < xBin.upper_upper_binedge && XVar >= xBin.upper_binedge) {
265 BinLookup.resize(TotBins);
267 for(
size_t bin_i = 0; bin_i < TotBins; bin_i++){
269 double low_edge = BinEdges[bin_i];
270 double upper_edge = BinEdges[bin_i+1];
274 low_lower_edge = BinEdges[0];
276 low_lower_edge = BinEdges[bin_i-1];
279 if (bin_i + 2 < TotBins) {
280 upper_upper_edge = BinEdges[bin_i + 2];
281 }
else if (bin_i + 1 < TotBins) {
282 upper_upper_edge = BinEdges[bin_i + 1];
285 BinLookup[bin_i].lower_binedge = low_edge;
286 BinLookup[bin_i].upper_binedge = upper_edge;
287 BinLookup[bin_i].lower_lower_binedge = low_lower_edge;
288 BinLookup[bin_i].upper_upper_binedge = upper_upper_edge;
305 for (
size_t iSample = 0; iSample < BinningInfo.size(); ++iSample) {
308 return static_cast<int>(iSample);
312 MACH3LOG_ERROR(
"Couldn't find sample corresponding to bin {}", GlobalBin);
322 if (BinningInfo.empty()) {
327 size_t GlobalOffsetCounter = 0;
328 for(
size_t iSample = 0; iSample < BinningInfo.size(); iSample++){
329 BinningInfo[iSample].GlobalOffset = GlobalOffsetCounter;
330 GlobalOffsetCounter += BinningInfo[iSample].nBins;
348 case 11:
return 0.00051099895;
349 case 13:
return 0.1056583755;
350 case 15:
return 1.77693;
359 case 211:
return 0.13957039;
360 case 111:
return 0.1349768;
361 case 221:
return 0.547862;
366 case 321:
return 0.493677;
368 case 2112:
return 0.939565;
369 case 2212:
return 0.938272;
370 case 3122:
return 1.115683;
371 case 3222:
return 1.118937;
372 case 3112:
return 1.197449;
373 case 3212:
return 1.192642;
375 case 1000050110:
return 10.255103;
376 case 1000060120:
return 11.177929;
377 case 1000070140:
return 13.043781;
378 case 1000080160:
return 14.899169;
379 case 1000090190:
return 17.696901;
380 case 1000110230:
return 21.414835;
381 case 1000130270:
return 25.133144;
382 case 1000140280:
return 26.060342;
383 case 1000190390:
return 36.294463;
384 case 1000180400:
return 37.224724;
385 case 1000220480:
return 44.663224;
386 case 1000300640:
return 59.549619;
403 switch(std::abs(NuPdg)){
405 NuOscillatorFlavour = NuOscillator::kElectron;
408 NuOscillatorFlavour = NuOscillator::kMuon;
411 NuOscillatorFlavour = NuOscillator::kTau;
414 MACH3LOG_ERROR(
"Unknown Neutrino PDG {}, cannot convert to NuOscillator type", NuPdg);
421 if(NuPdg < 0){NuOscillatorFlavour *= -1;}
423 return NuOscillatorFlavour;
429 inline std::string
FormatDouble(
const double value,
const int precision) {
431 std::ostringstream oss;
432 oss << std::fixed << std::setprecision(precision) << value;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
KS: Based on this https://github.com/gabime/spdlog/blob/a2b4262090fd3f005c2315dcb5be2f0f1774a005/incl...
NuPDG
Enum to track the incoming neutrino species.
std::string TestStatistic_ToString(const TestStatistic TestStat)
Convert a LLH type to a string.
std::string TargetMat_ToString(const TargetMat i)
Converted the Target Mat to a string.
TargetMat
Enum to track the target material.
@ kTarget_Fe
Iron (Atomic number 26)
@ kTarget_C
Carbon 12 (Atomic number 6)
@ kTarget_Al
Aluminum (Atomic number 13)
@ kTarget_H
Hydrogen (Atomic number 1)
@ kTarget_Ti
Titanium (Atomic number 22)
@ kTarget_Ar
Argon (Atomic number 18)
@ kTarget_N
Nitrogen (Atomic number 7)
@ kTarget_Pb
Lead (Atomic number 82)
@ kTarget_O
Oxygen 16 (Atomic number 8)
void SetGlobalBinNumbers(std::vector< SampleBinningInfo > &BinningInfo)
Sets the GlobalOffset for each SampleBinningInfo to enable linearization of multiple 2D binning sampl...
int GetSampleFromGlobalBin(const std::vector< SampleBinningInfo > &BinningInfo, const size_t GlobalBin)
Get the sample index corresponding to a global bin number.
TestStatistic
Make an enum of the test statistic that we're using.
@ kNTestStatistics
Number of test statistics.
@ kPearson
Standard Pearson likelihood .
@ kBarlowBeeston
Barlow-Beeston () following Conway approximation ()
@ kDembinskiAbdelmotteleb
Based on .
@ kPoisson
Standard Poisson likelihood .
constexpr unsigned int str2int(const char *str, const int h=0)
KS: This is mad way of converting string to int. Why? To be able to use string with switch.
Custom exception class for MaCh3 errors.
constexpr static const double _BAD_DOUBLE_
Default value used for double initialisation.
constexpr static const int _BAD_INT_
Default value used for int initialisation.
constexpr static const double _DEFAULT_RETURN_VAL_
double GetMassFromPDG(const int PDG)
Return mass for given PDG.
std::string FormatDouble(const double value, const int precision)
Convert double into string for precision, useful for playing with yaml if you don't want to have in c...
int PDGToNuOscillatorFlavour(const int NuPdg)
Convert from PDG flavour to NuOscillator type beware that in the case of anti-neutrinos the NuOscilla...
KS: Store bin lookups allowing to quickly find bin after migration.
double lower_lower_binedge
lower to check if Eb has moved the erec bin
double upper_upper_binedge
upper to check if Eb has moved the erec bin
double lower_binedge
lower to check if Eb has moved the erec bin
double upper_binedge
upper to check if Eb has moved the erec bin
KS: Small struct used for applying kinematic cuts.
double UpperBound
Upper bound on which we apply cut.
double LowerBound
Lower bound on which we apply cut.
int ParamToCutOnIt
Index or enum value identifying the kinematic variable to cut on.
KS: Small struct storying info about used binning.
int GetBin(const int xBin, const int yBin) const
Get linear bin index from 2D bin indices.
void InitialiseBinMigrationLookUp()
Initialise special lookup arrays allowing to more efficiently perform bin-migration These arrays stor...
std::vector< double > YBinEdges
Vector to hold y-axis bin-edges.
int GetBinGlobal(const int xBin, const int yBin) const
Calculates the global bin number for a given 2D bin, accounting for multiple binning samples.
std::vector< BinShiftLookup > xBinLookup
Bin lookups for X axis only.
size_t nXBins
Number of X axis bins in the histogram used for likelihood calculation.
size_t nYBins
Number of Y axis bins in the histogram used for likelihood calculation.
void InitialiseLookUpSingleDimension(std::vector< BinShiftLookup > &BinLookup, const std::vector< double > &BinEdges, const size_t TotBins)
Initializes lookup arrays for efficient bin migration in a single dimension.
int GetBinSafe(const int xBin, const int yBin) const
Get linear bin index from 2D bin indices with additional checks.
size_t GlobalOffset
If you have binning for multiple samples and trying to define 1D vector let's.
std::vector< double > XBinEdges
Vector to hold x-axis bin-edges.
size_t nBins
Number of total bins.
int FindXBin(const double XVar, const int NomXBin) const
DB Find the relevant bin in the PDF for each event.