MaCh3  2.2.3
Reference Guide
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Attributes | List of all members
SampleHandlerFD Class Referenceabstract

Class responsible for handling implementation of samples used in analysis, reweighting and returning LLH. More...

#include <Samples/SampleHandlerFD.h>

Inheritance diagram for SampleHandlerFD:
[legend]
Collaboration diagram for SampleHandlerFD:
[legend]

Public Member Functions

 SampleHandlerFD (std::string ConfigFileName, ParameterHandlerGeneric *xsec_cov, const std::shared_ptr< OscillationHandler > &OscillatorObj_=nullptr)
 Constructor. More...
 
virtual ~SampleHandlerFD ()
 destructor More...
 
int GetNDim () const
 DB Function to differentiate 1D or 2D binning. More...
 
std::string GetSampleName (int iSample=0) const override
 
std::string GetTitle () const override
 
std::string GetXBinVarName () const
 
std::string GetYBinVarName () const
 
void PrintIntegral (const TString &OutputName="/dev/null", const int WeightStyle=0, const TString &OutputCSVName="/dev/null")
 
void AddData (TH1D *Data)
 
void AddData (TH2D *Data)
 
void AddData (std::vector< double > &data)
 
void AddData (std::vector< std::vector< double > > &data)
 
double GetLikelihood () override
 DB Multi-threaded GetLikelihood. More...
 
TH1 * GetMCHist (const int Dimension)
 Get MC histogram. More...
 
TH1 * GetW2Hist (const int Dimension)
 Get W2 histogram. More...
 
TH1 * GetDataHist (const int Dimension)
 Get Data histogram. More...
 
void Reweight () override
 
M3::float_t GetEventWeight (const int iEntry) const
 
void InitialiseNuOscillatorObjects ()
 including Dan's magic NuOscillator More...
 
void SetupNuOscillatorPointers ()
 
void ReadSampleConfig ()
 
int GetNOscChannels () override
 
std::string GetFlavourName (const int iChannel)
 
TH1 * Get1DVarHist (const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec=std::vector< KinematicCut >(), int WeightStyle=0, TAxis *Axis=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec=std::vector< KinematicCut >())
 
TH2 * Get2DVarHist (const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec=std::vector< KinematicCut >(), int WeightStyle=0, TAxis *AxisX=nullptr, TAxis *AxisY=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec=std::vector< KinematicCut >())
 
void Fill1DSubEventHist (TH1D *_h1DVar, const std::string &ProjectionVar, const std::vector< KinematicCut > &SubEventSelectionVec=std::vector< KinematicCut >(), int WeightStyle=0)
 
void Fill2DSubEventHist (TH2D *_h2DVar, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &SubEventSelectionVec=std::vector< KinematicCut >(), int WeightStyle=0)
 
TH1 * Get1DVarHistByModeAndChannel (const std::string &ProjectionVar_Str, int kModeToFill=-1, int kChannelToFill=-1, int WeightStyle=0, TAxis *Axis=nullptr)
 
TH2 * Get2DVarHistByModeAndChannel (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)
 
TH1 * GetModeHist1D (int s, int m, int style=0)
 
TH2 * GetModeHist2D (int s, int m, int style=0)
 
std::vector< TH1 * > ReturnHistsBySelection1D (std::string KinematicProjection, int Selection1, int Selection2=-1, int WeightStyle=0, TAxis *Axis=0)
 
std::vector< TH2 * > ReturnHistsBySelection2D (std::string KinematicProjectionX, std::string KinematicProjectionY, int Selection1, int Selection2=-1, int WeightStyle=0, TAxis *XAxis=0, TAxis *YAxis=0)
 
THStack * ReturnStackedHistBySelection1D (std::string KinematicProjection, int Selection1, int Selection2=-1, int WeightStyle=0, TAxis *Axis=0)
 
TLegend * ReturnStackHistLegend ()
 
int ReturnKinematicParameterFromString (const std::string &KinematicStr) const
 ETA function to generically convert a string from xsec cov to a kinematic type. More...
 
std::string ReturnStringFromKinematicParameter (const int KinematicVariable) const
 ETA function to generically convert a kinematic type from xsec cov to a string. More...
 
void SaveAdditionalInfo (TDirectory *Dir) override
 Store additional info in a chan. More...
 
int ReturnKinematicVectorFromString (const std::string &KinematicStr) const
 
std::string ReturnStringFromKinematicVector (const int KinematicVariable) const
 
bool IsSubEventVarString (const std::string &VarStr)
 JM Check if a kinematic parameter string corresponds to a subevent-level variable. More...
 
- Public Member Functions inherited from SampleHandlerBase
 SampleHandlerBase ()
 The main constructor. More...
 
virtual ~SampleHandlerBase ()
 destructor More...
 
virtual M3::int_t GetNsamples ()
 
virtual double GetSampleLikelihood (const int isample)
 
virtual void CleanMemoryBeforeFit ()=0
 Allow to clean not used memory before fit starts. More...
 
MaCh3ModesGetMaCh3Modes () const
 Return pointer to MaCh3 modes. More...
 
unsigned int GetNEvents () const
 
virtual void SetupBinning (const M3::int_t Selection, std::vector< double > &BinningX, std::vector< double > &BinningY)
 
virtual TH1 * GetData (const int Selection)
 
virtual TH2Poly * GetW2 (const int Selection)
 
virtual TH1 * GetPDF (const int Selection)
 
virtual TH1 * GetPDFMode (const int Selection, const int Mode)
 
virtual std::string GetKinVarLabel (const int sample, const int Dimension)
 
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...
 

Protected Member Functions

virtual void SetupWeightPointers ()=0
 DB Function to determine which weights apply to which types of samples pure virtual!! More...
 
void SetupKinematicMap ()
 Ensure Kinematic Map is setup and make sure it is initialised correctly. More...
 
virtual void SetupSplines ()=0
 initialise your splineXX object and then use InitialiseSplineObject to conviently setup everything up More...
 
virtual void Init ()=0
 Initialise any variables that your experiment specific SampleHandler needs. More...
 
virtual int SetupExperimentMC ()=0
 Experiment specific setup, returns the number of events which were loaded. More...
 
virtual void SetupFDMC ()=0
 Function which translates experiment struct into core struct. More...
 
void Initialise ()
 Function which does a lot of the lifting regarding the workflow in creating different MC objects. More...
 
void FillSplineBins ()
 Finds the binned spline that an event should apply to and stored them in a a vector for easy evaluation in the fillArray() function. More...
 
void FindNominalBinAndEdges1D ()
 
void FindNominalBinAndEdges2D ()
 
void Set1DBinning (size_t nbins, double *boundaries)
 sets the binning used for the likelihood calculation, used for both data and MC More...
 
void Set2DBinning (size_t nbins1, double *boundaries1, size_t nbins2, double *boundaries2)
 set the binning for 2D sample used for the likelihood calculation More...
 
void Set1DBinning (std::vector< double > &XVec)
 set the binning for 1D sample used for the likelihood calculation More...
 
void Set2DBinning (std::vector< double > &XVec, std::vector< double > &YVec)
 set the binning for 2D sample used for the likelihood calculation More...
 
void SetupSampleBinning ()
 Function to setup the binning of your sample histograms and the underlying arrays that get handled in fillArray() and fillArray_MP(). The Binning.XBinEdges are filled in the daughter class from the sample config file. This "passing" can be removed. More...
 
void SetupReweightArrays (const size_t numberXBins, const size_t numberYBins)
 Initialise data, MC and W2 histograms. More...
 
virtual void SetupFunctionalParameters ()
 ETA - a function to setup and pass values to functional parameters where you need to pass a value to some custom reweight calc or engine. More...
 
void RegisterIndividualFunctionalParameter (const std::string &fpName, int fpEnum, FuncParFuncType fpFunc)
 HH - a helper function for RegisterFunctionalParameter. More...
 
virtual void RegisterFunctionalParameters ()=0
 HH - a experiment-specific function where the maps to actual functions are set up. More...
 
virtual void PrepFunctionalParameters ()
 Update the functional parameter values to the latest proposed values. Needs to be called before every new reweight so is called in fillArray. More...
 
virtual void ApplyShifts (int iEvent)
 ETA - generic function applying shifts. More...
 
bool IsEventSelected (const int iEvent)
 DB Function which determines if an event is selected, where Selection double looks like {{ND280KinematicTypes Var1, douuble LowBound}. More...
 
bool IsSubEventSelected (const std::vector< KinematicCut > &SubEventCuts, const int iEvent, unsigned const int iSubEvent, size_t nsubevents)
 JM Function which determines if a subevent is selected. More...
 
virtual void resetShifts (int iEvent)
 HH - reset the shifted values to the original values. More...
 
void CalcNormsBins (std::vector< NormParameter > &norm_parameters, std::vector< std::vector< int > > &xsec_norms_bins)
 Check whether a normalisation systematic affects an event or not. More...
 
M3::float_t CalcWeightSpline (const FarDetectorCoreInfo *MCEvent) const
 Calculate the spline weight for a given event. More...
 
M3::float_t CalcWeightNorm (const FarDetectorCoreInfo *MCEvent) const
 Calculate the norm weight for a given event. More...
 
virtual void CalcWeightFunc (int iEvent)
 Calculate weights for function parameters. More...
 
virtual double ReturnKinematicParameter (std::string KinematicParamter, int iEvent)=0
 Return the value of an associated kinematic parameter for an event. More...
 
virtual double ReturnKinematicParameter (int KinematicVariable, int iEvent)=0
 
virtual std::vector< double > ReturnKinematicVector (std::string KinematicParameter, int iEvent)
 
virtual std::vector< double > ReturnKinematicVector (int KinematicVariable, int iEvent)
 
std::vector< double > ReturnKinematicParameterBinning (const std::string &KinematicParameter)
 Return the binning used to draw a kinematic parameter. More...
 
virtual const double * GetPointerToKinematicParameter (std::string KinematicParamter, int iEvent)=0
 
virtual const double * GetPointerToKinematicParameter (double KinematicVariable, int iEvent)=0
 
const double * GetPointerToOscChannel (const int iEvent) const
 Get pointer to oscillation channel associated with given event. Osc channel is const. More...
 
void SetupNormParameters ()
 Setup the norm parameters by assigning each event with bin. More...
 
void FillMCHist (const int Dimension)
 Fill a histogram with the event-level information used in the fit. More...
 
void FillArray ()
 DB Nice new multi-threaded function which calculates the event weights and fills the relevant bins of an array. More...
 
void ResetHistograms ()
 Helper function to reset histograms. More...
 
void InitialiseSingleFDMCObject ()
 function to create the member of the FarDetectorInfo struct so they are the appropriate size. More...
 
void InitialiseSplineObject ()
 
NuPDG GetInitPDGFromFileName (const std::string &FileName) const
 Retrieve the initial neutrino PDG code associated with a given input file name. More...
 
NuPDG GetFinalPDGFromFileName (const std::string &FileName) const
 Retrieve the final neutrino PDG code associated with a given input file name. More...
 
- Protected Member Functions inherited from SampleHandlerBase
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

std::unique_ptr< BinnedSplineHandlerSplineHandler
 Contains all your binned splines and handles the setup and the returning of weights from spline evaluations. More...
 
std::shared_ptr< OscillationHandlerOscillator
 Contains all your binned splines and handles the setup and the returning of weights from spline evaluations. More...
 
std::vector< FunctionalParameterfuncParsVec
 HH - a vector that stores all the FuncPars struct. More...
 
std::unordered_map< std::string, int > funcParsNamesMap
 HH - a map that relates the name of the functional parameter to funcpar enum. More...
 
std::vector< FunctionalParameter * > funcParsMap
 HH - a map that relates the funcpar enum to pointer of FuncPars struct HH - Changed to a vector of pointers since it's faster than unordered_map and we are using ints as keys. More...
 
std::unordered_map< int, FuncParFuncTypefuncParsFuncMap
 HH - a map that relates the funcpar enum to pointer of the actual function. More...
 
std::vector< std::vector< int > > funcParsGrid
 HH - a grid of vectors of enums for each sample and event. More...
 
std::vector< std::string > funcParsNamesVec = {}
 HH - a vector of string names for each functional parameter. More...
 
SampleBinningInfo Binning
 KS: This stores binning information, in future could be come vector to store binning for every used sample. More...
 
double * SampleHandlerFD_array
 DB Array to be filled after reweighting. More...
 
double * SampleHandlerFD_array_w2
 KS Array used for MC stat. More...
 
double * SampleHandlerFD_data
 DB Array to be filled in AddData. More...
 
std::vector< FarDetectorCoreInfoMCSamples
 Stores information about every MC event. More...
 
SampleInfo SampleDetails
 Stores info about currently initialised sample. More...
 
std::vector< OscChannelInfoOscChannels
 Stores info about oscillation channel for a single sample. More...
 
ParameterHandlerGenericParHandler = nullptr
 
std::string SampleName
 A unique ID for each sample based on which we can define what systematic should be applied. More...
 
std::vector< KinematicCutStoredSelection
 What gets pulled from config options, these are constant after loading in this is of length 3: 0th index is the value, 1st is lower bound, 2nd is upper bound. More...
 
std::vector< KinematicCutSelection
 a way to store selection cuts which you may push back in the get1DVar functions most of the time this is just the same as StoredSelection More...
 
const std::unordered_map< std::string, int > * KinematicParameters
 Mapping between string and kinematic enum. More...
 
const std::unordered_map< int, std::string > * ReversedKinematicParameters
 Mapping between kinematic enum and string. More...
 
const std::unordered_map< std::string, int > * KinematicVectors
 
const std::unordered_map< int, std::string > * ReversedKinematicVectors
 
std::unique_ptr< managerSampleManager
 The manager object used to read the sample yaml file. More...
 
std::vector< std::string > mc_files
 names of mc files associated associated with this object More...
 
std::vector< std::string > spline_files
 names of spline files associated associated with this object More...
 
std::unordered_map< std::string, double > _modeNomWeightMap
 
TLegend * THStackLeg = nullptr
 DB Miscellaneous Variables. More...
 
bool FirstTimeW2
 KS:Super hacky to update W2 or not. More...
 
bool UpdateW2
 KS:Super hacky to update W2 or not. More...
 
- Protected Attributes inherited from SampleHandlerBase
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< MaCh3ModesModes
 Holds information about used Generator and MaCh3 modes. More...
 

Private Types

enum  FDPlotType { kModePlot = 0 , kOscChannelPlot = 1 }
 

Private Attributes

std::unordered_map< std::string, NuPDGFileToInitPDGMap
 
std::unordered_map< std::string, NuPDGFileToFinalPDGMap
 

Detailed Description

Class responsible for handling implementation of samples used in analysis, reweighting and returning LLH.

Author
Dan Barrow
Ed Atkin

Definition at line 18 of file SampleHandlerFD.h.

Member Enumeration Documentation

◆ FDPlotType

Enumerator
kModePlot 
kOscChannelPlot 

Definition at line 391 of file SampleHandlerFD.h.

391  {
392  kModePlot = 0,
393  kOscChannelPlot = 1
394  };

Constructor & Destructor Documentation

◆ SampleHandlerFD()

SampleHandlerFD::SampleHandlerFD ( std::string  ConfigFileName,
ParameterHandlerGeneric xsec_cov,
const std::shared_ptr< OscillationHandler > &  OscillatorObj_ = nullptr 
)

Constructor.

Parameters
ConfigFileNameName of config to initialise the sample object

Definition at line 10 of file SampleHandlerFD.cpp.

11  : SampleHandlerBase() {
12 // ************************************************
13  MACH3LOG_INFO("-------------------------------------------------------------------");
14  MACH3LOG_INFO("Creating SampleHandlerFD object");
15 
16  //ETA - safety feature so you can't pass a NULL xsec_cov
17  if(!xsec_cov){
18  MACH3LOG_ERROR("You've passed me a nullptr to a SystematicHandlerGeneric... I need this to setup splines!");
19  throw MaCh3Exception(__FILE__, __LINE__);
20  }
21  ParHandler = xsec_cov;
22 
23  nSamples = 1;
24 
25  if (OscillatorObj_ != nullptr) {
26  MACH3LOG_WARN("You have passed an Oscillator object through the constructor of a SampleHandlerFD object - this will be used for all oscillation channels");
27  Oscillator = OscillatorObj_;
28  }
29 
30  KinematicParameters = nullptr;
32  KinematicVectors = nullptr;
33  ReversedKinematicVectors = nullptr;
34 
35  SampleHandlerFD_array = nullptr;
36  SampleHandlerFD_data = nullptr;
37  SampleHandlerFD_array_w2 = nullptr;
38  SampleName = "";
39  SampleManager = std::make_unique<manager>(ConfigFileName.c_str());
40 
41  // Variables related to MC stat
42  FirstTimeW2 = true;
43  UpdateW2 = false;
44 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:26
Custom exception class for MaCh3 errors.
SampleHandlerBase()
The main constructor.
M3::int_t nSamples
Contains how many samples we've got.
ParameterHandlerGeneric * ParHandler
bool FirstTimeW2
KS:Super hacky to update W2 or not.
double * SampleHandlerFD_data
DB Array to be filled in AddData.
const std::unordered_map< int, std::string > * ReversedKinematicVectors
const std::unordered_map< std::string, int > * KinematicVectors
double * SampleHandlerFD_array
DB Array to be filled after reweighting.
std::unique_ptr< manager > SampleManager
The manager object used to read the sample yaml file.
bool UpdateW2
KS:Super hacky to update W2 or not.
std::shared_ptr< OscillationHandler > Oscillator
Contains all your binned splines and handles the setup and the returning of weights from spline evalu...
const std::unordered_map< std::string, int > * KinematicParameters
Mapping between string and kinematic enum.
const std::unordered_map< int, std::string > * ReversedKinematicParameters
Mapping between kinematic enum and string.
double * SampleHandlerFD_array_w2
KS Array used for MC stat.
std::string SampleName
A unique ID for each sample based on which we can define what systematic should be applied.

◆ ~SampleHandlerFD()

SampleHandlerFD::~SampleHandlerFD ( )
virtual

destructor

Definition at line 46 of file SampleHandlerFD.cpp.

46  {
47  MACH3LOG_DEBUG("I'm deleting SampleHandlerFD");
48 
49  if (SampleHandlerFD_array != nullptr) delete[] SampleHandlerFD_array;
50  if (SampleHandlerFD_array_w2 != nullptr) delete[] SampleHandlerFD_array_w2;
51  //ETA - there is a chance that you haven't added any data...
52  if (SampleHandlerFD_data != nullptr) delete[] SampleHandlerFD_data;
53 
54  if(THStackLeg != nullptr) delete THStackLeg;
55 }
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:24
TLegend * THStackLeg
DB Miscellaneous Variables.

Member Function Documentation

◆ AddData() [1/4]

void SampleHandlerFD::AddData ( std::vector< double > &  data)

Definition at line 1061 of file SampleHandlerFD.cpp.

1061  {
1062  if (SampleDetails.dathist == nullptr) {
1063  MACH3LOG_ERROR("Data hist hasn't been initialised yet");
1064  throw MaCh3Exception(__FILE__, __LINE__);
1065  }
1066 
1067  SampleDetails.dathist2d = nullptr;
1068  SampleDetails.dathist->Reset();
1069 
1070  if (GetNDim()!=1) {
1071  MACH3LOG_ERROR("Trying to set a 1D 'data' histogram when the number of dimensions for this sample is {}", GetNDim());
1072  MACH3LOG_ERROR("This won't work, please specify the correct dimensions in your sample config with the X and Y variables");
1073  throw MaCh3Exception(__FILE__, __LINE__);
1074  }
1075 
1076  for (auto const& data_point : data){
1077  SampleDetails.dathist->Fill(data_point);
1078  }
1079 
1080  if(SampleHandlerFD_data == nullptr) {
1081  MACH3LOG_ERROR("SampleHandlerFD_data haven't been initialised yet");
1082  throw MaCh3Exception(__FILE__, __LINE__);
1083  }
1084  // Assuming nBins == nXBins here, because you have 1D data
1085  for (size_t bin = 0; bin < Binning.nXBins; ++bin) {
1086  // ROOT histograms are 1-based, so bin index + 1
1087  SampleHandlerFD_data[bin] = SampleDetails.dathist->GetBinContent(static_cast<int>(bin + 1));
1088  }
1089 }
SampleBinningInfo Binning
KS: This stores binning information, in future could be come vector to store binning for every used s...
SampleInfo SampleDetails
Stores info about currently initialised sample.
int GetNDim() const
DB Function to differentiate 1D or 2D binning.
size_t nXBins
Number of X axis bins in the histogram used for likelihood calculation.
TH2D * dathist2d
histogram used for plotting storing 2D data distribution
TH1D * dathist
histogram used for plotting storing 1D data distribution

◆ AddData() [2/4]

void SampleHandlerFD::AddData ( std::vector< std::vector< double > > &  data)

Definition at line 1093 of file SampleHandlerFD.cpp.

1093  {
1094  if (SampleDetails.dathist2d == nullptr) {
1095  MACH3LOG_ERROR("Data hist hasn't been initialised yet");
1096  throw MaCh3Exception(__FILE__, __LINE__);
1097  }
1098 
1099  SampleDetails.dathist = nullptr;
1100  SampleDetails.dathist2d->Reset();
1101 
1102  if (GetNDim()!=2) {
1103  MACH3LOG_ERROR("Trying to set a 2D 'data' histogram when the number of dimensions for this sample is {}", GetNDim());
1104  MACH3LOG_ERROR("This won't work, please specify the correct dimensions in your sample config with the X and Y variables");
1105  throw MaCh3Exception(__FILE__, __LINE__);
1106  }
1107 
1108  //TODO: this assumes that std::vector is of length 2 and then both data.at(0) and data
1109  //ETA: I think this might just be wrong? We should probably just make this AddData(std::vector<double> data_x, std::vector<double> data_y)
1110  // or maybe something like AddData(std::vector<std::pair<double, double>> data)?
1111  for (int i = 0; i < int(data.size()); i++) {
1112  SampleDetails.dathist2d->Fill(data.at(0)[i],data.at(1)[i]);
1113  }
1114 
1115  if(SampleHandlerFD_data == nullptr) {
1116  MACH3LOG_ERROR("SampleHandlerFD_data haven't been initialised yet");
1117  throw MaCh3Exception(__FILE__, __LINE__);
1118  }
1119  for (size_t yBin=0;yBin<Binning.nYBins;yBin++) {
1120  for (size_t xBin=0;xBin<Binning.nXBins;xBin++) {
1121  //Need to cast to an int (Int_t) for ROOT
1122  //Need to do +1 for the bin, this is to be consistent with ROOTs binning scheme
1123  const int idx = Binning.GetBinSafe(xBin, yBin);
1124  SampleHandlerFD_data[idx] = SampleDetails.dathist2d->GetBinContent(static_cast<int>(xBin + 1), static_cast<int>(yBin + 1));
1125  }
1126  }
1127 }
size_t nYBins
Number of Y axis bins in the histogram used for likelihood calculation.
int GetBinSafe(const int xBin, const int yBin) const
Get linear bin index from 2D bin indices with additional checks.

◆ AddData() [3/4]

void SampleHandlerFD::AddData ( TH1D *  Data)

Definition at line 1129 of file SampleHandlerFD.cpp.

1129  {
1130  MACH3LOG_INFO("Adding 1D data histogram: {} with {:.2f} events", Data->GetTitle(), Data->Integral());
1131  if (SampleDetails.dathist != nullptr) {
1132  delete SampleDetails.dathist;
1133  }
1134  SampleDetails.dathist2d = nullptr;
1135  SampleDetails.dathist = static_cast<TH1D*>(Data->Clone());
1136 
1137  if (GetNDim() != 1) {
1138  MACH3LOG_ERROR("Trying to set a 1D 'data' histogram in a 2D sample - Quitting");
1139  MACH3LOG_ERROR("The number of dimensions for this sample is {}", GetNDim());
1140  throw MaCh3Exception(__FILE__ , __LINE__ );
1141  }
1142 
1143  if(SampleHandlerFD_data == nullptr) {
1144  MACH3LOG_ERROR("SampleHandlerFD_data haven't been initialised yet");
1145  throw MaCh3Exception(__FILE__, __LINE__);
1146  }
1147 
1148  for (size_t bin = 0; bin < Binning.nXBins; ++bin) {
1149  // ROOT histograms are 1-based, so bin index + 1
1150  SampleHandlerFD_data[bin] = SampleDetails.dathist->GetBinContent(static_cast<int>(bin + 1));
1151  }
1152 }

◆ AddData() [4/4]

void SampleHandlerFD::AddData ( TH2D *  Data)

Definition at line 1154 of file SampleHandlerFD.cpp.

1154  {
1155  MACH3LOG_INFO("Adding 2D data histogram: {} with {:.2f} events", Data->GetTitle(), Data->Integral());
1156  if (SampleDetails.dathist2d != nullptr) {
1157  delete SampleDetails.dathist2d;
1158  }
1159  SampleDetails.dathist2d = static_cast<TH2D*>(Data->Clone());
1160  SampleDetails.dathist = nullptr;
1161 
1162  if (GetNDim() != 2) {
1163  MACH3LOG_ERROR("Trying to set a 2D 'data' histogram in a 1D sample - Quitting");
1164  throw MaCh3Exception(__FILE__ , __LINE__ );}
1165 
1166  if(SampleHandlerFD_data == nullptr) {
1167  MACH3LOG_ERROR("SampleHandlerFD_data haven't been initialised yet");
1168  throw MaCh3Exception(__FILE__, __LINE__);
1169  }
1170  for (size_t yBin=0;yBin<Binning.nYBins;yBin++) {
1171  for (size_t xBin=0;xBin<Binning.nXBins;xBin++) {
1172  //Need to cast to an int (Int_t) for ROOT
1173  //Need to do +1 for the bin, this is to be consistent with ROOTs binning scheme
1174  const int idx = Binning.GetBinSafe(xBin, yBin);
1175  SampleHandlerFD_data[idx] = SampleDetails.dathist2d->GetBinContent(static_cast<int>(xBin + 1), static_cast<int>(yBin + 1));
1176  }
1177  }
1178 }

◆ ApplyShifts()

void SampleHandlerFD::ApplyShifts ( int  iEvent)
protectedvirtual

ETA - generic function applying shifts.

Definition at line 675 of file SampleHandlerFD.cpp.

675  {
676  // Given a sample and event, apply the shifts to the event based on the vector of functional parameter enums
677  // First reset shifted array back to nominal values
678  resetShifts(iEvent);
679 
680  const std::vector<int>& fpEnums = funcParsGrid[iEvent];
681  const std::size_t nShifts = fpEnums.size();
682 
683  for (std::size_t i = 0; i < nShifts; ++i) {
684  const int fpEnum = fpEnums[i];
685  FunctionalParameter *fp = funcParsMap[static_cast<std::size_t>(fpEnum)];
686  // if (fp->funcPtr) {
687  // (*fp->funcPtr)(fp->valuePtr, iEvent);
688  // } else {
689  // MACH3LOG_ERROR("Functional parameter function pointer for {} is null for event {} in sample {}", fp->name, iEvent);
690  // throw MaCh3Exception(__FILE__, __LINE__);
691  // }
692  (*fp->funcPtr)(fp->valuePtr, iEvent);
693  }
694 }
std::vector< std::vector< int > > funcParsGrid
HH - a grid of vectors of enums for each sample and event.
virtual void resetShifts(int iEvent)
HH - reset the shifted values to the original values.
std::vector< FunctionalParameter * > funcParsMap
HH - a map that relates the funcpar enum to pointer of FuncPars struct HH - Changed to a vector of po...
HH - Functional parameters Carrier for whether you want to apply a systematic to an event or not.
const double * valuePtr
Parameter value pointer.
FuncParFuncType * funcPtr
Function pointer.

◆ CalcNormsBins()

void SampleHandlerFD::CalcNormsBins ( std::vector< NormParameter > &  norm_parameters,
std::vector< std::vector< int > > &  xsec_norms_bins 
)
protected

Check whether a normalisation systematic affects an event or not.

Definition at line 767 of file SampleHandlerFD.cpp.

767  {
768 // ************************************************
769  #ifdef DEBUG
770  std::vector<int> VerboseCounter(norm_parameters.size(), 0);
771  #endif
772  for(unsigned int iEvent = 0; iEvent < GetNEvents(); ++iEvent){
773  std::vector< int > NormBins = {};
774  if (ParHandler) {
775  // Skip oscillated NC events
776  // Not strictly needed, but these events don't get included in oscillated predictions, so
777  // no need to waste our time calculating and storing information about xsec parameters
778  // that will never be used.
779  if (MCSamples[iEvent].isNC && (*MCSamples[iEvent].nupdg != *MCSamples[iEvent].nupdgUnosc) ) {
780  MACH3LOG_TRACE("Event {}, missed NC/signal check", iEvent);
781  continue;
782  } //DB Abstract check on MaCh3Modes to determine which apply to neutral current
783  for (std::vector<NormParameter>::iterator it = norm_parameters.begin(); it != norm_parameters.end(); ++it) {
784  //Now check that the target of an interaction matches with the normalisation parameters
785  bool TargetMatch = MatchCondition((*it).targets, *(MCSamples[iEvent].Target));
786  if (!TargetMatch) {
787  MACH3LOG_TRACE("Event {}, missed target check ({}) for dial {}", iEvent, *(MCSamples[iEvent].Target), (*it).name);
788  continue;
789  }
790 
791  //Now check that the neutrino flavour in an interaction matches with the normalisation parameters
792  bool FlavourMatch = MatchCondition((*it).pdgs, *(MCSamples[iEvent].nupdg));
793  if (!FlavourMatch) {
794  MACH3LOG_TRACE("Event {}, missed PDG check ({}) for dial {}", iEvent,(*MCSamples[iEvent].nupdg), (*it).name);
795  continue;
796  }
797 
798  //Now check that the unoscillated neutrino flavour in an interaction matches with the normalisation parameters
799  bool FlavourUnoscMatch = MatchCondition((*it).preoscpdgs, *(MCSamples[iEvent].nupdgUnosc));
800  if (!FlavourUnoscMatch){
801  MACH3LOG_TRACE("Event {}, missed FlavourUnosc check ({}) for dial {}", iEvent,(*MCSamples[iEvent].nupdgUnosc), (*it).name);
802  continue;
803  }
804 
805  //Now check that the mode of an interaction matches with the normalisation parameters
806  bool ModeMatch = MatchCondition((*it).modes, static_cast<int>(std::round(*(MCSamples[iEvent].mode))));
807  if (!ModeMatch) {
808  MACH3LOG_TRACE("Event {}, missed Mode check ({}) for dial {}", iEvent, *(MCSamples[iEvent].mode), (*it).name);
809  continue;
810  }
811 
812  //Now check whether the norm has kinematic bounds
813  //i.e. does it only apply to events in a particular kinematic region?
814  // Now check whether within kinematic bounds
815  bool IsSelected = true;
816  if ((*it).hasKinBounds) {
817  const auto& kinVars = (*it).KinematicVarStr;
818  const auto& selection = (*it).Selection;
819 
820  for (std::size_t iKinPar = 0; iKinPar < kinVars.size(); ++iKinPar) {
821  const double kinVal = ReturnKinematicParameter(kinVars[iKinPar], static_cast<int>(iEvent));
822 
823  bool passedAnyBound = false;
824  const auto& boundsList = selection[iKinPar];
825 
826  for (const auto& bounds : boundsList) {
827  if (kinVal > bounds[0] && kinVal <= bounds[1]) {
828  passedAnyBound = true;
829  break;
830  }
831  }
832 
833  if (!passedAnyBound) {
834  MACH3LOG_TRACE("Event {}, missed kinematic check ({}) for dial {}",
835  iEvent, kinVars[iKinPar], (*it).name);
836  IsSelected = false;
837  break;
838  }
839  }
840  }
841  // Need to then break the event loop
842  if(!IsSelected){
843  MACH3LOG_TRACE("Event {}, missed Kinematic var check for dial {}", iEvent, (*it).name);
844  continue;
845  }
846  // Now set 'index bin' for each normalisation parameter
847  // All normalisations are just 1 bin for 2015, so bin = index (where index is just the bin for that normalisation)
848  int bin = (*it).index;
849 
850  NormBins.push_back(bin);
851  MACH3LOG_TRACE("Event {}, will be affected by dial {}", iEvent, (*it).name);
852  #ifdef DEBUG
853  VerboseCounter[std::distance(norm_parameters.begin(), it)]++;
854  #endif
855  //}
856  } // end iteration over norm_parameters
857  } // end if (ParHandler)
858  xsec_norms_bins[iEvent] = NormBins;
859  }//end loop over events
860  #ifdef DEBUG
861  MACH3LOG_DEBUG("┌──────────────────────────────────────────────────────────┐");
862  for (std::size_t i = 0; i < norm_parameters.size(); ++i) {
863  const auto& norm = norm_parameters[i];
864  double eventRatio = static_cast<double>(VerboseCounter[i]) / static_cast<double>(GetNEvents());
865 
866  MACH3LOG_DEBUG("│ Param {:<15}, affects {:<8} events ({:>6.2f}%) │",
867  ParHandler->GetParFancyName(norm.index), VerboseCounter[i], eventRatio);
868  }
869  MACH3LOG_DEBUG("└──────────────────────────────────────────────────────────┘");
870  #endif
871 }
#define MACH3LOG_TRACE
Definition: MaCh3Logger.h:23
bool MatchCondition(const std::vector< T > &allowedValues, const T &value)
check if event is affected by following conditions, for example pdg, or modes etc
virtual double ReturnKinematicParameter(std::string KinematicParamter, int iEvent)=0
Return the value of an associated kinematic parameter for an event.
std::vector< FarDetectorCoreInfo > MCSamples
Stores information about every MC event.
std::string GetParFancyName(const int i) const
Get fancy name of the Parameter.
unsigned int GetNEvents() const

◆ CalcWeightFunc()

virtual void SampleHandlerFD::CalcWeightFunc ( int  iEvent)
inlineprotectedvirtual

Calculate weights for function parameters.

First you need to setup additional pointers in you experiment code in SetupWeightPointers Then in this function you can calculate whatever fancy function you want by filling weight to which you have pointer This way func weight shall be used in GetEventWeight

Definition at line 259 of file SampleHandlerFD.h.

259 {return; (void)iEvent;};

◆ CalcWeightNorm()

M3::float_t SampleHandlerFD::CalcWeightNorm ( const FarDetectorCoreInfo MCEvent) const
protected

Calculate the norm weight for a given event.

Definition at line 715 of file SampleHandlerFD.cpp.

715  {
716 // ***************************************************************************
717  M3::float_t xsecw = 1.0;
718  const int nNorms = static_cast<int>(MCEvent->xsec_norm_pointers.size());
719  //Loop over stored normalisation and function pointers
720  #ifdef MULTITHREAD
721  #pragma omp simd
722  #endif
723  for (int iParam = 0; iParam < nNorms; ++iParam)
724  {
725 #pragma GCC diagnostic push
726 #pragma GCC diagnostic ignored "-Wuseless-cast"
727  xsecw *= static_cast<M3::float_t>(*(MCEvent->xsec_norm_pointers[iParam]));
728 #pragma GCC diagnostic pop
729  #ifdef DEBUG
730  if (std::isnan(xsecw)) MACH3LOG_WARN("iParam= {} xsecweight=nan from norms", iParam);
731  #endif
732  }
733  return xsecw;
734 }
double float_t
Definition: Core.h:30
std::vector< const double * > xsec_norm_pointers
Pointers to normalisation weights which are being taken from Parameter Handler.

◆ CalcWeightSpline()

M3::float_t SampleHandlerFD::CalcWeightSpline ( const FarDetectorCoreInfo MCEvent) const
protected

Calculate the spline weight for a given event.

Definition at line 698 of file SampleHandlerFD.cpp.

698  {
699 // ***************************************************************************
700  M3::float_t spline_weight = 1.0;
701  const int nSplines = static_cast<int>(MCEvent->xsec_spline_pointers.size());
702  //DB Xsec syst
703  //Loop over stored spline pointers
704  #ifdef MULTITHREAD
705  #pragma omp simd
706  #endif
707  for (int iSpline = 0; iSpline < nSplines; ++iSpline) {
708  spline_weight *= *(MCEvent->xsec_spline_pointers[iSpline]);
709  }
710  return spline_weight;
711 }
std::vector< const M3::float_t * > xsec_spline_pointers
Pointers to spline weights which are being calculated by Splines Handler.

◆ Fill2DSubEventHist()

void SampleHandlerFD::Fill2DSubEventHist ( TH2D *  _h2DVar,
const std::string &  ProjectionVarX,
const std::string &  ProjectionVarY,
const std::vector< KinematicCut > &  SubEventSelectionVec = std::vector< KinematicCut >(),
int  WeightStyle = 0 
)

Definition at line 1572 of file SampleHandlerFD.cpp.

1573  {
1574  bool IsSubEventVarX = IsSubEventVarString(ProjectionVar_StrX);
1575  bool IsSubEventVarY = IsSubEventVarString(ProjectionVar_StrY);
1576 
1577  int ProjectionVar_IntX, ProjectionVar_IntY;
1578  if (IsSubEventVarX) ProjectionVar_IntX = ReturnKinematicVectorFromString(ProjectionVar_StrX);
1579  else ProjectionVar_IntX = ReturnKinematicParameterFromString(ProjectionVar_StrX);
1580  if (IsSubEventVarY) ProjectionVar_IntY = ReturnKinematicVectorFromString(ProjectionVar_StrY);
1581  else ProjectionVar_IntY = ReturnKinematicParameterFromString(ProjectionVar_StrY);
1582 
1583  //JM Loop over all events
1584  for (unsigned int iEvent = 0; iEvent < GetNEvents(); iEvent++) {
1585  if (IsEventSelected(iEvent)) {
1586  double Weight = GetEventWeight(iEvent);
1587  if (WeightStyle == 1) {
1588  Weight = 1.;
1589  }
1590  std::vector<double> VecX = {}, VecY = {};
1591  double VarX = M3::_BAD_DOUBLE_, VarY = M3::_BAD_DOUBLE_;
1592  size_t nsubevents = 0;
1593  // JM Three cases: subeventX vs eventY || eventX vs subeventY || subeventX vs subeventY
1594  if (IsSubEventVarX && !IsSubEventVarY) {
1595  VecX = ReturnKinematicVector(ProjectionVar_IntX, iEvent);
1596  VarY = ReturnKinematicParameter(ProjectionVar_IntY, iEvent);
1597  nsubevents = VecX.size();
1598  }
1599  else if (!IsSubEventVarX && IsSubEventVarY) {
1600  VecY = ReturnKinematicVector(ProjectionVar_IntY, iEvent);
1601  VarX = ReturnKinematicParameter(ProjectionVar_IntX, iEvent);
1602  nsubevents = VecY.size();
1603  }
1604  else {
1605  VecX = ReturnKinematicVector(ProjectionVar_IntX, iEvent);
1606  VecY = ReturnKinematicVector(ProjectionVar_IntY, iEvent);
1607  if (VecX.size() != VecY.size()) {
1608  MACH3LOG_ERROR("Cannot plot {} of size {} against {} of size {}", ProjectionVar_StrX, VecX.size(), ProjectionVar_StrY, VecY.size());
1609  throw MaCh3Exception(__FILE__, __LINE__);
1610  }
1611  nsubevents = VecX.size();
1612  }
1613  //JM Loop over all subevents in event
1614  for (unsigned int iSubEvent = 0; iSubEvent < nsubevents; iSubEvent++) {
1615  if (IsSubEventSelected(SubEventSelectionVec, iEvent, iSubEvent, nsubevents)) {
1616  if (IsSubEventVarX) VarX = VecX[iSubEvent];
1617  if (IsSubEventVarY) VarY = VecY[iSubEvent];
1618  _h2DVar->Fill(VarX,VarY,Weight);
1619  }
1620  }
1621  }
1622  }
1623 }
bool IsEventSelected(const int iEvent)
DB Function which determines if an event is selected, where Selection double looks like {{ND280Kinema...
M3::float_t GetEventWeight(const int iEntry) const
bool IsSubEventSelected(const std::vector< KinematicCut > &SubEventCuts, const int iEvent, unsigned const int iSubEvent, size_t nsubevents)
JM Function which determines if a subevent is selected.
bool IsSubEventVarString(const std::string &VarStr)
JM Check if a kinematic parameter string corresponds to a subevent-level variable.
int ReturnKinematicVectorFromString(const std::string &KinematicStr) const
virtual std::vector< double > ReturnKinematicVector(std::string KinematicParameter, int iEvent)
int ReturnKinematicParameterFromString(const std::string &KinematicStr) const
ETA function to generically convert a string from xsec cov to a kinematic type.
constexpr static const double _BAD_DOUBLE_
Default value used for double initialisation.
Definition: Core.h:46

◆ FillArray()

void SampleHandlerFD::FillArray ( )
protected

DB Nice new multi-threaded function which calculates the event weights and fills the relevant bins of an array.

Function which does the core reweighting. This assumes that oscillation weights have already been calculated and stored in SampleHandlerFD.osc_w[iEvent]. This function takes advantage of most of the things called in setupSKMC to reduce reweighting time. It also follows the ND code reweighting pretty closely. This function fills the SampleHandlerFD array array which is binned to match the sample binning, such that bin[1][1] is the equivalent of SampleDetails._hPDF2D->GetBinContent(2,2) {Noticing the offset}

Definition at line 398 of file SampleHandlerFD.cpp.

398  {
399 //************************************************
400  //DB Reset which cuts to apply
402 
404 
405  for (unsigned int iEvent = 0; iEvent < GetNEvents(); iEvent++) {
406  ApplyShifts(iEvent);
407 
408  if (!IsEventSelected(iEvent)) {
409  continue;
410  }
411 
412  FarDetectorCoreInfo* MCEvent = &MCSamples[iEvent];
413  M3::float_t splineweight = CalcWeightSpline(MCEvent);
414  //DB Catch negative spline weights and skip any event with a negative event. Previously we would set weight to zero and continue but that is inefficient. Do this on a spline-by-spline basis
415  if (splineweight <= 0.){
416  MCEvent->xsec_w = 0.;
417  continue;
418  }
419 
420  //Loop over stored normalisation and function pointers
421  M3::float_t normweight = CalcWeightNorm(MCEvent);
422 
423  // Virtual by default does nothing
424  CalcWeightFunc(iEvent);
425 
426  MCEvent->xsec_w = splineweight*normweight;
427 
428  //DB Total weight
429  M3::float_t totalweight = GetEventWeight(iEvent);
430  //DB Catch negative weights and skip any event with a negative event
431  if (totalweight <= 0.){
432  MCEvent->xsec_w = 0.;
433  continue;
434  }
435  //DB Switch on BinningOpt to allow different binning options to be implemented
436  //The alternative would be to have inheritance based on BinningOpt
437  const double XVar = *(MCEvent->x_var);
438 
439  //DB Find the relevant bin in the PDF for each event
440  const int XBinToFill = Binning.FindXBin(XVar, MCEvent->NomXBin);
441  const int YBinToFill = MCEvent->NomYBin;
442 
443  //DB Fill relevant part of thread array
444  if (XBinToFill != -1 && YBinToFill != -1) {
445  const int GlobalBin = Binning.GetBin(XBinToFill, YBinToFill);
446  SampleHandlerFD_array[GlobalBin] += totalweight;
447  if (FirstTimeW2) SampleHandlerFD_array_w2[GlobalBin] += totalweight*totalweight;
448  }
449  }
450 }
virtual void CalcWeightFunc(int iEvent)
Calculate weights for function parameters.
std::vector< KinematicCut > Selection
a way to store selection cuts which you may push back in the get1DVar functions most of the time this...
std::vector< KinematicCut > StoredSelection
What gets pulled from config options, these are constant after loading in this is of length 3: 0th in...
virtual void PrepFunctionalParameters()
Update the functional parameter values to the latest proposed values. Needs to be called before every...
M3::float_t CalcWeightNorm(const FarDetectorCoreInfo *MCEvent) const
Calculate the norm weight for a given event.
M3::float_t CalcWeightSpline(const FarDetectorCoreInfo *MCEvent) const
Calculate the spline weight for a given event.
virtual void ApplyShifts(int iEvent)
ETA - generic function applying shifts.
constructors are same for all three so put in here
M3::float_t xsec_w
Total weight of norm and spline parameters.
int GetBin(const int xBin, const int yBin) const
Get linear bin index from 2D bin indices.
int FindXBin(const double XVar, const int NomXBin) const
DB Find the relevant bin in the PDF for each event.

◆ FillMCHist()

void SampleHandlerFD::FillMCHist ( const int  Dimension)
protected

Fill a histogram with the event-level information used in the fit.

Definition at line 263 of file SampleHandlerFD.cpp.

263  {
264 // ************************************************
265  // DB Commented out by default - Code heading towards GetLikelihood using arrays instead of root objects
266  // Wouldn't actually need this for GetLikelihood as TH objects wouldn't be filled
267  if(Dimension == 1){
268  SampleDetails._hPDF1D->Reset();
269  for (size_t yBin = 0; yBin < Binning.nYBins; ++yBin) {
270  for (size_t xBin = 0; xBin < Binning.nXBins; ++xBin) {
271  const int idx = Binning.GetBinSafe(xBin, yBin);
272  SampleDetails._hPDF1D->SetBinContent(idx + 1, SampleHandlerFD_array[idx]);
273  }
274  }
275  } else if (Dimension == 2) {
276  SampleDetails._hPDF2D->Reset();
277  for (size_t yBin = 0; yBin < Binning.nYBins; ++yBin) {
278  for (size_t xBin = 0; xBin < Binning.nXBins; ++xBin) {
279  const int idx = Binning.GetBinSafe(xBin, yBin);
280  SampleDetails._hPDF2D->SetBinContent(static_cast<int>(xBin + 1), static_cast<int>(yBin + 1), SampleHandlerFD_array[idx]);
281  }
282  }
283  } else {
284  MACH3LOG_ERROR("Asking for {} with N Dimension = {}. This is not implemented", __func__, Dimension);
285  throw MaCh3Exception(__FILE__, __LINE__);
286  }
287 }
TH1D * _hPDF1D
histogram used for plotting storing 1D MC distribution
TH2D * _hPDF2D
histogram used for plotting storing 2D MC distribution

◆ FillSplineBins()

void SampleHandlerFD::FillSplineBins ( )
protected

Finds the binned spline that an event should apply to and stored them in a a vector for easy evaluation in the fillArray() function.

Definition at line 1302 of file SampleHandlerFD.cpp.

1302  {
1303  //Now loop over events and get the spline bin for each event
1304  for (unsigned int j = 0; j < GetNEvents(); ++j) {
1305  const int OscIndex = GetOscChannel(OscChannels, (*MCSamples[j].nupdgUnosc), (*MCSamples[j].nupdg));
1306 
1307  std::vector< std::vector<int> > EventSplines;
1308  switch(GetNDim()){
1309  case 1:
1310  EventSplines = SplineHandler->GetEventSplines(GetTitle(), OscIndex, int(*(MCSamples[j].mode)), *(MCSamples[j].rw_etru), *(MCSamples[j].x_var), 0.);
1311  break;
1312  case 2:
1313  EventSplines = SplineHandler->GetEventSplines(GetTitle(), OscIndex, int(*(MCSamples[j].mode)), *(MCSamples[j].rw_etru), *(MCSamples[j].x_var), *(MCSamples[j].y_var));
1314  break;
1315  default:
1316  MACH3LOG_ERROR("Error in assigning spline bins because nDimensions = {}", GetNDim());
1317  MACH3LOG_ERROR("MaCh3 only supports splines binned in Etrue + the sample binning");
1318  MACH3LOG_ERROR("Please check the sample binning you specified in your sample config ");
1319  throw MaCh3Exception(__FILE__, __LINE__);
1320  break;
1321  }
1322  int NSplines = int(EventSplines.size());
1323  if(NSplines < 0){
1324  throw MaCh3Exception(__FILE__, __LINE__);
1325  }
1326  MCSamples[j].xsec_spline_pointers.resize(NSplines);
1327  for(size_t spline = 0; spline < MCSamples[j].xsec_spline_pointers.size(); spline++) {
1328  //Event Splines indexed as: sample name, oscillation channel, syst, mode, etrue, var1, var2 (var2 is a dummy 0 for 1D splines)
1329  MCSamples[j].xsec_spline_pointers[spline] = SplineHandler->retPointer(EventSplines[spline][0], EventSplines[spline][1],
1330  EventSplines[spline][2], EventSplines[spline][3],
1331  EventSplines[spline][4], EventSplines[spline][5],
1332  EventSplines[spline][6]);
1333  }
1334  }
1335 }
int GetOscChannel(const std::vector< OscChannelInfo > &OscChannel, const int InitFlav, const int FinalFlav)
KS: Get Osc Channel Index based on initial and final PDG codes.
std::unique_ptr< BinnedSplineHandler > SplineHandler
Contains all your binned splines and handles the setup and the returning of weights from spline evalu...
std::vector< OscChannelInfo > OscChannels
Stores info about oscillation channel for a single sample.
std::string GetTitle() const override

◆ FindNominalBinAndEdges1D()

void SampleHandlerFD::FindNominalBinAndEdges1D ( )
protected

Definition at line 917 of file SampleHandlerFD.cpp.

917  {
918  for(unsigned int event_i = 0; event_i < GetNEvents(); event_i++){
919  //Set x_var and y_var values based on XVarStr and YVarStr
920  MCSamples[event_i].x_var = GetPointerToKinematicParameter(GetXBinVarName(), event_i);
921  if (std::isnan(*MCSamples[event_i].x_var) || std::isinf(*MCSamples[event_i].x_var)) {
922  MACH3LOG_ERROR("X var for event {} is ill-defined and equal to {}", event_i, *MCSamples[event_i].x_var);
923  throw MaCh3Exception(__FILE__, __LINE__);
924  }
925 
926  //Give y_var M3::_BAD_DOUBLE_ value for the 1D case since this won't be used
927  MCSamples[event_i].y_var = &(M3::_BAD_DOUBLE_);
928  int bin = SampleDetails._hPDF1D->FindBin(*(MCSamples[event_i].x_var));
929 
930  if ((bin-1) >= 0 && (bin-1) < int(Binning.XBinEdges.size()-1)) {
931  MCSamples[event_i].NomXBin = bin-1;
932  } else {
933  MCSamples[event_i].NomXBin = -1;
934  }
935  MCSamples[event_i].NomYBin = 0;
936  }
937 
939 }
virtual const double * GetPointerToKinematicParameter(std::string KinematicParamter, int iEvent)=0
std::string GetXBinVarName() const
void InitialiseBinMigrationLookUp()
Initialise special lookup arrays allowing to more efficiently perform bin-migration These arrays stor...
std::vector< double > XBinEdges
Vector to hold x-axis bin-edges.

◆ FindNominalBinAndEdges2D()

void SampleHandlerFD::FindNominalBinAndEdges2D ( )
protected

Definition at line 958 of file SampleHandlerFD.cpp.

958  {
959 // ************************************************
960  for(unsigned int event_i = 0 ; event_i < GetNEvents(); event_i++) {
961  //Set x_var and y_var values based on XVarStr and YVarStr
962  MCSamples[event_i].x_var = GetPointerToKinematicParameter(GetXBinVarName(), event_i);
963  MCSamples[event_i].y_var = GetPointerToKinematicParameter(GetYBinVarName(), event_i);
964 
965  if (std::isnan(*MCSamples[event_i].x_var) || std::isinf(*MCSamples[event_i].x_var)) {
966  MACH3LOG_ERROR("X var for event {} is ill-defined and equal to {}", event_i, *MCSamples[event_i].x_var);
967  throw MaCh3Exception(__FILE__, __LINE__);
968  }
969  if (std::isnan(*MCSamples[event_i].y_var) || std::isinf(*MCSamples[event_i].y_var)) {
970  MACH3LOG_ERROR("Y var for event {} is ill-defined and equal to {}", event_i, *MCSamples[event_i].y_var);
971  throw MaCh3Exception(__FILE__, __LINE__);
972  }
973  //Global bin number
974  int bin = SampleDetails._hPDF2D->FindBin(*(MCSamples[event_i].x_var), *(MCSamples[event_i].y_var));
975 
976  int bin_x = M3::_BAD_INT_;
977  int bin_y = M3::_BAD_INT_;
978  int bin_z = M3::_BAD_INT_;
979  SampleDetails._hPDF2D->GetBinXYZ(bin, bin_x, bin_y, bin_z);
980 
981  if ((bin_x-1) >= 0 && (bin_x-1) < int(Binning.XBinEdges.size()-1)) {
982  MCSamples[event_i].NomXBin = bin_x-1;
983  }
984  MCSamples[event_i].NomYBin = bin_y-1;
985  if(MCSamples[event_i].NomYBin < 0){
986  MACH3LOG_WARN("Nominal YBin PROBLEM, y-bin is {}", MCSamples[event_i].NomYBin);
987  }
988  }
990 }
std::string GetYBinVarName() const
constexpr static const int _BAD_INT_
Default value used for int initialisation.
Definition: Core.h:48

◆ Get2DVarHist()

TH2 * SampleHandlerFD::Get2DVarHist ( const std::string &  ProjectionVarX,
const std::string &  ProjectionVarY,
const std::vector< KinematicCut > &  EventSelectionVec = std::vector< KinematicCut >(),
int  WeightStyle = 0,
TAxis *  AxisX = nullptr,
TAxis *  AxisY = nullptr,
const std::vector< KinematicCut > &  SubEventSelectionVec = std::vector< KinematicCut >() 
)

Definition at line 1515 of file SampleHandlerFD.cpp.

1516  {
1517 // ************************************************
1518  //DB Need to overwrite the Selection member variable so that IsEventSelected function operates correctly.
1519  // Consequently, store the selection cuts already saved in the sample, overwrite the Selection variable, then reset
1520  std::vector< KinematicCut > tmp_Selection = Selection;
1521  std::vector< KinematicCut > SelectionVecToApply;
1522 
1523  //DB Add all the predefined selections to the selection vector which will be applied
1524  for (size_t iSelec=0;iSelec<Selection.size();iSelec++) {
1525  SelectionVecToApply.emplace_back(Selection[iSelec]);
1526  }
1527 
1528  //DB Add all requested cuts from the argument to the selection vector which will be applied
1529  for (size_t iSelec=0;iSelec<EventSelectionVec.size();iSelec++) {
1530  SelectionVecToApply.emplace_back(EventSelectionVec[iSelec]);
1531  }
1532 
1533  //DB Set the member variable to be the cuts to apply
1534  Selection = SelectionVecToApply;
1535 
1536  //DB Define the histogram which will be returned
1537  TH2D* _h2DVar;
1538  if (AxisX && AxisY) {
1539  _h2DVar = new TH2D("","",AxisX->GetNbins(),AxisX->GetXbins()->GetArray(),AxisY->GetNbins(),AxisY->GetXbins()->GetArray());
1540  } else {
1541  std::vector<double> xBinEdges = ReturnKinematicParameterBinning(ProjectionVar_StrX);
1542  std::vector<double> yBinEdges = ReturnKinematicParameterBinning(ProjectionVar_StrY);
1543  _h2DVar = new TH2D("", "", int(xBinEdges.size())-1, xBinEdges.data(), int(yBinEdges.size())-1, yBinEdges.data());
1544  }
1545 
1546  bool IsSubEventHist = IsSubEventVarString(ProjectionVar_StrX) || IsSubEventVarString(ProjectionVar_StrY);
1547  if (IsSubEventHist) Fill2DSubEventHist(_h2DVar, ProjectionVar_StrX, ProjectionVar_StrY, SubEventSelectionVec, WeightStyle);
1548  else {
1549  //DB Grab the associated enum with the argument string
1550  int ProjectionVar_IntX = ReturnKinematicParameterFromString(ProjectionVar_StrX);
1551  int ProjectionVar_IntY = ReturnKinematicParameterFromString(ProjectionVar_StrY);
1552 
1553  //DB Loop over all events
1554  for (unsigned int iEvent = 0; iEvent < GetNEvents(); iEvent++) {
1555  if (IsEventSelected(iEvent)) {
1556  double Weight = GetEventWeight(iEvent);
1557  if (WeightStyle == 1) {
1558  Weight = 1.;
1559  }
1560  double VarX = ReturnKinematicParameter(ProjectionVar_IntX, iEvent);
1561  double VarY = ReturnKinematicParameter(ProjectionVar_IntY, iEvent);
1562  _h2DVar->Fill(VarX,VarY,Weight);
1563  }
1564  }
1565  }
1566  //DB Reset the saved selection
1567  Selection = tmp_Selection;
1568 
1569  return _h2DVar;
1570 }
std::vector< double > ReturnKinematicParameterBinning(const std::string &KinematicParameter)
Return the binning used to draw a kinematic parameter.
void Fill2DSubEventHist(TH2D *_h2DVar, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &SubEventSelectionVec=std::vector< KinematicCut >(), int WeightStyle=0)

◆ GetEventWeight()

M3::float_t SampleHandlerFD::GetEventWeight ( const int  iEntry) const

Definition at line 1287 of file SampleHandlerFD.cpp.

1287  {
1288  M3::float_t totalweight = 1.0;
1289  const int nParams = static_cast<int>(MCSamples[iEntry].total_weight_pointers.size());
1290  #ifdef MULTITHREAD
1291  #pragma omp simd
1292  #endif
1293  for (int iParam = 0; iParam < nParams; ++iParam) {
1294  totalweight *= *(MCSamples[iEntry].total_weight_pointers[iParam]);
1295  }
1296 
1297  return totalweight;
1298 }

◆ GetFinalPDGFromFileName()

NuPDG SampleHandlerFD::GetFinalPDGFromFileName ( const std::string &  FileName) const
inlineprotected

Retrieve the final neutrino PDG code associated with a given input file name.

Definition at line 385 of file SampleHandlerFD.h.

385 {return FileToFinalPDGMap.at(FileName);}
std::unordered_map< std::string, NuPDG > FileToFinalPDGMap

◆ GetInitPDGFromFileName()

NuPDG SampleHandlerFD::GetInitPDGFromFileName ( const std::string &  FileName) const
inlineprotected

Retrieve the initial neutrino PDG code associated with a given input file name.

Definition at line 383 of file SampleHandlerFD.h.

383 {return FileToInitPDGMap.at(FileName);}
std::unordered_map< std::string, NuPDG > FileToInitPDGMap

◆ GetLikelihood()

double SampleHandlerFD::GetLikelihood ( )
overridevirtual

DB Multi-threaded GetLikelihood.

Implements SampleHandlerBase.

Definition at line 1338 of file SampleHandlerFD.cpp.

1338  {
1339 // ************************************************
1340  if (SampleHandlerFD_data == nullptr) {
1341  MACH3LOG_ERROR("Data sample is empty! Can't calculate a likelihood!");
1342  throw MaCh3Exception(__FILE__, __LINE__);
1343  }
1344 
1345  double negLogL = 0.;
1346  #ifdef MULTITHREAD
1347  #pragma omp parallel for reduction(+:negLogL)
1348  #endif
1349  for (size_t idx = 0; idx < Binning.nBins; ++idx)
1350  {
1351  const double DataVal = SampleHandlerFD_data[idx];
1352  const double MCPred = SampleHandlerFD_array[idx];
1353  const double w2 = SampleHandlerFD_array_w2[idx];
1354 
1355  //KS: Calculate likelihood using Barlow-Beeston Poisson or even IceCube
1356  negLogL += GetTestStatLLH(DataVal, MCPred, w2);
1357  }
1358  return negLogL;
1359 }
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....
size_t nBins
Number of total bins.

◆ GetPointerToKinematicParameter() [1/2]

virtual const double* SampleHandlerFD::GetPointerToKinematicParameter ( double  KinematicVariable,
int  iEvent 
)
protectedpure virtual

Implemented in PySampleHandlerFD.

◆ GetPointerToKinematicParameter() [2/2]

virtual const double* SampleHandlerFD::GetPointerToKinematicParameter ( std::string  KinematicParamter,
int  iEvent 
)
protectedpure virtual

Implemented in PySampleHandlerFD.

◆ GetPointerToOscChannel()

const double * SampleHandlerFD::GetPointerToOscChannel ( const int  iEvent) const
protected

Get pointer to oscillation channel associated with given event. Osc channel is const.

Definition at line 2047 of file SampleHandlerFD.cpp.

2047  {
2048 // ************************************************
2049  const int Channel = GetOscChannel(OscChannels, (*MCSamples[iEvent].nupdgUnosc), (*MCSamples[iEvent].nupdg));
2050 
2051  return &(OscChannels[Channel].ChannelIndex);
2052 }

◆ Init()

virtual void SampleHandlerFD::Init ( )
protectedpure virtual

Initialise any variables that your experiment specific SampleHandler needs.

Implemented in PySampleHandlerFD.

◆ Initialise()

void SampleHandlerFD::Initialise ( )
protected

Function which does a lot of the lifting regarding the workflow in creating different MC objects.

Definition at line 185 of file SampleHandlerFD.cpp.

185  {
186  //First grab all the information from your sample config via your manager
188 
189  //Now initialise all the variables you will need
190  Init();
191 
193 
195  SetupFDMC();
196 
197  MACH3LOG_INFO("=============================================");
198  MACH3LOG_INFO("Total number of events is: {}", GetNEvents());
199 
201  if (OscParams.size() > 0) {
202  MACH3LOG_INFO("Setting up NuOscillator..");
203  if (Oscillator != nullptr) {
204  MACH3LOG_INFO("You have passed an OscillatorBase object through the constructor of a SampleHandlerFD object - this will be used for all oscillation channels");
205  if(Oscillator->isEqualBinningPerOscChannel() != true) {
206  MACH3LOG_ERROR("Trying to run shared NuOscillator without EqualBinningPerOscChannel, this will not work");
207  throw MaCh3Exception(__FILE__, __LINE__);
208  }
209 
210  if(OscParams.size() != Oscillator->GetOscParamsSize()){
211  MACH3LOG_ERROR("Sample {} with {} has {} osc params, while shared NuOsc has {} osc params", GetTitle(), GetSampleName(),
212  OscParams.size(), Oscillator->GetOscParamsSize());
213  MACH3LOG_ERROR("This indicate misconfiguration in your Osc yaml");
214  throw MaCh3Exception(__FILE__, __LINE__);
215  }
216  } else {
218  }
220  } else{
221  MACH3LOG_WARN("Didn't find any oscillation params, thus will not enable oscillations");
222  }
223 
224  MACH3LOG_INFO("Setting up Sample Binning..");
226  MACH3LOG_INFO("Setting up Splines..");
227  SetupSplines();
228  MACH3LOG_INFO("Setting up Normalisation Pointers..");
230  MACH3LOG_INFO("Setting up Functional Pointers..");
232  MACH3LOG_INFO("Setting up Weight Pointers..");
234  MACH3LOG_INFO("Setting up Kinematic Map..");
236  MACH3LOG_INFO("=======================================================");
237 }
unsigned int nEvents
Number of MC events are there.
virtual void Init()=0
Initialise any variables that your experiment specific SampleHandler needs.
virtual void SetupSplines()=0
initialise your splineXX object and then use InitialiseSplineObject to conviently setup everything up
virtual int SetupExperimentMC()=0
Experiment specific setup, returns the number of events which were loaded.
void SetupNormParameters()
Setup the norm parameters by assigning each event with bin.
void SetupKinematicMap()
Ensure Kinematic Map is setup and make sure it is initialised correctly.
virtual void SetupFDMC()=0
Function which translates experiment struct into core struct.
void InitialiseNuOscillatorObjects()
including Dan's magic NuOscillator
void InitialiseSingleFDMCObject()
function to create the member of the FarDetectorInfo struct so they are the appropriate size.
virtual void SetupWeightPointers()=0
DB Function to determine which weights apply to which types of samples pure virtual!...
void SetupSampleBinning()
Function to setup the binning of your sample histograms and the underlying arrays that get handled in...
void SetupNuOscillatorPointers()
virtual void SetupFunctionalParameters()
ETA - a function to setup and pass values to functional parameters where you need to pass a value to ...
std::vector< const double * > GetOscParsFromSampleName(const std::string &SampleName)
Get pointers to Osc params from Sample name.
std::string GetSampleName(int iSample=0) const override

◆ InitialiseNuOscillatorObjects()

void SampleHandlerFD::InitialiseNuOscillatorObjects ( )

including Dan's magic NuOscillator

Definition at line 1182 of file SampleHandlerFD.cpp.

1182  {
1183 // ************************************************
1184  auto NuOscillatorConfigFile = Get<std::string>(SampleManager->raw()["NuOsc"]["NuOscConfigFile"], __FILE__ , __LINE__);
1185  auto EqualBinningPerOscChannel = Get<bool>(SampleManager->raw()["NuOsc"]["EqualBinningPerOscChannel"], __FILE__ , __LINE__);
1186 
1187  // TN override the sample setting if not using binned oscillation
1188  if (EqualBinningPerOscChannel) {
1189  if (YAML::LoadFile(NuOscillatorConfigFile)["General"]["CalculationType"].as<std::string>() == "Unbinned") {
1190  MACH3LOG_WARN("Tried using EqualBinningPerOscChannel while using Unbinned oscillation calculation, changing EqualBinningPerOscChannel to false");
1191  EqualBinningPerOscChannel = false;
1192  }
1193  }
1194  std::vector<const double*> OscParams = ParHandler->GetOscParsFromSampleName(SampleName);
1195  if (OscParams.empty()) {
1196  MACH3LOG_ERROR("OscParams is empty for sample '{}'.", GetTitle());
1197  MACH3LOG_ERROR("This likely indicates an error in your oscillation YAML configuration.");
1198  throw MaCh3Exception(__FILE__, __LINE__);
1199  }
1200  Oscillator = std::make_shared<OscillationHandler>(NuOscillatorConfigFile, EqualBinningPerOscChannel, OscParams, GetNOscChannels());
1201 
1202  if (!EqualBinningPerOscChannel) {
1203  for(int iChannel = 0; iChannel < GetNOscChannels(); iChannel++) {
1204  std::vector<M3::float_t> EnergyArray;
1205  std::vector<M3::float_t> CosineZArray;
1206 
1207  for (unsigned int iEvent = 0; iEvent < GetNEvents(); iEvent++) {
1208  // KS: This is bit weird but we basically loop over all events and push to vector only these which are part of a given OscChannel
1209  const int Channel = GetOscChannel(OscChannels, (*MCSamples[iEvent].nupdgUnosc), (*MCSamples[iEvent].nupdg));
1210  //DB Remove NC events from the arrays which are handed to the NuOscillator objects
1211  if (!MCSamples[iEvent].isNC && Channel == iChannel) {
1212  EnergyArray.push_back(M3::float_t(*(MCSamples[iEvent].rw_etru)));
1213  }
1214  }
1215  std::sort(EnergyArray.begin(),EnergyArray.end());
1216 
1217  //============================================================================
1218  //DB Atmospheric only part, can only happen if truecz has been initialised within the experiment specific code
1219  if (*(MCSamples[0].rw_truecz) != M3::_BAD_DOUBLE_) {
1220  for (unsigned int iEvent = 0; iEvent < GetNEvents(); iEvent++) {
1221  // KS: This is bit weird but we basically loop over all events and push to vector only these which are part of a given OscChannel
1222  const int Channel = GetOscChannel(OscChannels, (*MCSamples[iEvent].nupdgUnosc), (*MCSamples[iEvent].nupdg));
1223  //DB Remove NC events from the arrays which are handed to the NuOscillator objects
1224  if (!MCSamples[iEvent].isNC && Channel == iChannel) {
1225  CosineZArray.push_back(M3::float_t(*(MCSamples[iEvent].rw_truecz)));
1226  }
1227  }
1228  std::sort(CosineZArray.begin(),CosineZArray.end());
1229  }
1230  Oscillator->SetOscillatorBinning(iChannel, EnergyArray, CosineZArray);
1231  } // end loop over channels
1232  }
1233 }
int GetNOscChannels() override

◆ InitialiseSingleFDMCObject()

void SampleHandlerFD::InitialiseSingleFDMCObject ( )
protected

function to create the member of the FarDetectorInfo struct so they are the appropriate size.

Definition at line 1361 of file SampleHandlerFD.cpp.

1361  {
1362  MCSamples.resize(nEvents);
1363 }

◆ InitialiseSplineObject()

void SampleHandlerFD::InitialiseSplineObject ( )
protected

Definition at line 1400 of file SampleHandlerFD.cpp.

1400  {
1401  std::vector<std::string> spline_filepaths;
1402  for(int iChannel = 0 ; iChannel < GetNOscChannels(); iChannel++){
1403  spline_filepaths.push_back(spline_files[iChannel]);
1404  }
1405 
1406  //Keep a track of the spline variables
1407  std::vector<std::string> SplineVarNames = {"TrueNeutrinoEnergy"};
1408  if(GetXBinVarName().length() > 0){
1409  SplineVarNames.push_back(GetXBinVarName());
1410  }
1411  if(GetYBinVarName().length() > 0){
1412  SplineVarNames.push_back(GetYBinVarName());
1413  }
1414 
1415  bool LoadSplineFile = GetFromManager<bool>(SampleManager->raw()["InputFiles"]["LoadSplineFile"], false, __FILE__, __LINE__);
1416  bool PrepSplineFile = GetFromManager<bool>(SampleManager->raw()["InputFiles"]["PrepSplineFile"], false, __FILE__, __LINE__);
1417  auto SplineFileName = GetFromManager<std::string>(SampleManager->raw()["InputFiles"]["SplineFileName"],
1418  (SampleName + "_SplineFile.root"), __FILE__, __LINE__);
1419  if(!LoadSplineFile) {
1420  SplineHandler->AddSample(SampleName, GetTitle(), spline_filepaths, SplineVarNames);
1421  SplineHandler->CountNumberOfLoadedSplines(false, 1);
1422  SplineHandler->TransferToMonolith();
1423  if(PrepSplineFile) SplineHandler->PrepareSplineFile(SplineFileName);
1424  } else {
1425  // KS: Skip default spline loading and use flattened spline format allowing to read stuff much faster
1426  SplineHandler->LoadSplineFile(SplineFileName);
1427  }
1428  MACH3LOG_INFO("--------------------------------");
1429  MACH3LOG_INFO("Setup Far Detector splines");
1430 
1431  FillSplineBins();
1432 
1433  SplineHandler->cleanUpMemory();
1434 }
std::vector< std::string > spline_files
names of spline files associated associated with this object
void FillSplineBins()
Finds the binned spline that an event should apply to and stored them in a a vector for easy evaluati...

◆ IsEventSelected()

bool SampleHandlerFD::IsEventSelected ( const int  iEvent)
protected

DB Function which determines if an event is selected, where Selection double looks like {{ND280KinematicTypes Var1, douuble LowBound}.

Definition at line 334 of file SampleHandlerFD.cpp.

334  {
335 // ************************************************
336  const int SelectionSize = static_cast<int>(Selection.size());
337  for (int iSelection = 0; iSelection < SelectionSize; ++iSelection) {
338  const auto& Cut = Selection[iSelection];
339  const double Val = ReturnKinematicParameter(Cut.ParamToCutOnIt, iEvent);
340  if ((Val < Cut.LowerBound) || (Val >= Cut.UpperBound)) {
341  return false;
342  }
343  }
344  //DB To avoid unnecessary checks, now return false rather than setting bool to true and continuing to check
345  return true;
346 }

◆ IsSubEventSelected()

bool SampleHandlerFD::IsSubEventSelected ( const std::vector< KinematicCut > &  SubEventCuts,
const int  iEvent,
unsigned const int  iSubEvent,
size_t  nsubevents 
)
protected

JM Function which determines if a subevent is selected.

Definition at line 349 of file SampleHandlerFD.cpp.

349  {
350  for (unsigned int iSelection=0;iSelection < SubEventCuts.size() ;iSelection++) {
351  std::vector<double> Vec = ReturnKinematicVector(SubEventCuts[iSelection].ParamToCutOnIt, iEvent);
352  if (nsubevents != Vec.size()) {
353  MACH3LOG_ERROR("Cannot apply kinematic cut on {} as it is of different size to plotting variable");
354  throw MaCh3Exception(__FILE__, __LINE__);
355  }
356  const double Val = Vec[iSubEvent];
357  if ((Val < SubEventCuts[iSelection].LowerBound) || (Val >= SubEventCuts[iSelection].UpperBound)) {
358  return false;
359  }
360  }
361  //DB To avoid unnecessary checks, now return false rather than setting bool to true and continuing to check
362  return true;
363 }

◆ IsSubEventVarString()

bool SampleHandlerFD::IsSubEventVarString ( const std::string &  VarStr)

JM Check if a kinematic parameter string corresponds to a subevent-level variable.

Definition at line 1714 of file SampleHandlerFD.cpp.

1714  {
1715  if (KinematicVectors == nullptr) return false;
1716 
1717  if (KinematicVectors->count(VarStr)) {
1718  if (!KinematicParameters->count(VarStr)) return true;
1719  else {
1720  MACH3LOG_ERROR("Attempted to plot kinematic variable {}, but it appears in both KinematicVectors and KinematicParameters", VarStr);
1721  throw MaCh3Exception(__FILE__,__LINE__);
1722  }
1723  }
1724  return false;
1725 }

◆ PrepFunctionalParameters()

virtual void SampleHandlerFD::PrepFunctionalParameters ( )
inlineprotectedvirtual

Update the functional parameter values to the latest proposed values. Needs to be called before every new reweight so is called in fillArray.

Definition at line 219 of file SampleHandlerFD.h.

219 {};

◆ PrintIntegral()

void SampleHandlerFD::PrintIntegral ( const TString &  OutputName = "/dev/null",
const int  WeightStyle = 0,
const TString &  OutputCSVName = "/dev/null" 
)

Definition at line 1828 of file SampleHandlerFD.cpp.

1828  {
1829  constexpr int space = 14;
1830 
1831  bool printToFile=false;
1832  if (OutputFileName.CompareTo("/dev/null")) {printToFile = true;}
1833 
1834  bool printToCSV=false;
1835  if(OutputCSVFileName.CompareTo("/dev/null")) printToCSV=true;
1836 
1837  std::ofstream outfile;
1838  if (printToFile) {
1839  outfile.open(OutputFileName.Data(), std::ios_base::app);
1840  outfile.precision(7);
1841  }
1842 
1843  std::ofstream outcsv;
1844  if(printToCSV){
1845  outcsv.open(OutputCSVFileName, std::ios_base::app); // Appened to CSV
1846  outcsv.precision(7);
1847  }
1848 
1849  double PDFIntegral = 0.;
1850 
1851  std::vector< std::vector< TH1* > > IntegralList;
1852  IntegralList.resize(Modes->GetNModes());
1853 
1854  std::vector<double> ChannelIntegral;
1855  ChannelIntegral.resize(GetNOscChannels());
1856  for (unsigned int i=0;i<ChannelIntegral.size();i++) {ChannelIntegral[i] = 0.;}
1857 
1858  for (int i=0;i<Modes->GetNModes();i++) {
1859  if (GetNDim()==1) {
1860  IntegralList[i] = ReturnHistsBySelection1D(GetXBinVarName(),1,i,WeightStyle);
1861  } else {
1862  IntegralList[i] = CastVector<TH2, TH1>(ReturnHistsBySelection2D(GetXBinVarName(),GetYBinVarName(),1,i,WeightStyle));
1863  }
1864  }
1865 
1866  MACH3LOG_INFO("-------------------------------------------------");
1867 
1868  if (printToFile) {
1869  outfile << "\\begin{table}[ht]" << std::endl;
1870  outfile << "\\begin{center}" << std::endl;
1871  outfile << "\\caption{Integral breakdown for sample: " << GetTitle() << "}" << std::endl;
1872  outfile << "\\label{" << GetTitle() << "-EventRate}" << std::endl;
1873 
1874  TString nColumns;
1875  for (int i=0;i<GetNOscChannels();i++) {nColumns+="|c";}
1876  nColumns += "|c|";
1877  outfile << "\\begin{tabular}{|l" << nColumns.Data() << "}" << std::endl;
1878  outfile << "\\hline" << std::endl;
1879  }
1880 
1881  if(printToCSV){
1882  // HW Probably a better way but oh well, here I go making MaCh3 messy again
1883  outcsv<<"Integral Breakdown for sample :"<<GetTitle()<<"\n";
1884  }
1885 
1886  MACH3LOG_INFO("Integral breakdown for sample: {}", GetTitle());
1887  MACH3LOG_INFO("");
1888 
1889  if (printToFile) {outfile << std::setw(space) << "Mode:";}
1890  if(printToCSV) {outcsv<<"Mode,";}
1891 
1892  std::string table_headings = fmt::format("| {:<8} |", "Mode");
1893  std::string table_footline = "------------"; //Scalable table horizontal line
1894  for (int i = 0;i < GetNOscChannels(); i++) {
1895  table_headings += fmt::format(" {:<17} |", GetFlavourName(i));
1896  table_footline += "--------------------";
1897  if (printToFile) {outfile << "&" << std::setw(space) << OscChannels[i].flavourName_Latex << " ";}
1898  if (printToCSV) {outcsv << GetFlavourName(i) << ",";}
1899  }
1900  if (printToFile) {outfile << "&" << std::setw(space) << "Total:" << "\\\\ \\hline" << std::endl;}
1901  if (printToCSV) {outcsv <<"Total\n";}
1902  table_headings += fmt::format(" {:<10} |", "Total");
1903  table_footline += "-------------";
1904 
1905  MACH3LOG_INFO("{}", table_headings);
1906  MACH3LOG_INFO("{}", table_footline);
1907 
1908  for (unsigned int i=0;i<IntegralList.size();i++) {
1909  double ModeIntegral = 0;
1910  if (printToFile) {outfile << std::setw(space) << Modes->GetMaCh3ModeName(i);}
1911  if(printToCSV) {outcsv << Modes->GetMaCh3ModeName(i) << ",";}
1912 
1913  table_headings = fmt::format("| {:<8} |", Modes->GetMaCh3ModeName(i)); //Start string with mode name
1914 
1915  for (unsigned int j=0;j<IntegralList[i].size();j++) {
1916  double Integral = IntegralList[i][j]->Integral();
1917 
1918  if (Integral<1e-100) {Integral=0;}
1919 
1920  ModeIntegral += Integral;
1921  ChannelIntegral[j] += Integral;
1922  PDFIntegral += Integral;
1923 
1924  if (printToFile) {outfile << "&" << std::setw(space) << Form("%4.5f",Integral) << " ";}
1925  if (printToCSV) {outcsv << Form("%4.5f", Integral) << ",";}
1926 
1927  table_headings += fmt::format(" {:<17.4f} |", Integral);
1928  }
1929  if (printToFile) {outfile << "&" << std::setw(space) << Form("%4.5f",ModeIntegral) << " \\\\ \\hline" << std::endl;}
1930  if (printToCSV) {outcsv << Form("%4.5f", ModeIntegral) << "\n";}
1931 
1932  table_headings += fmt::format(" {:<10.4f} |", ModeIntegral);
1933 
1934  MACH3LOG_INFO("{}", table_headings);
1935  }
1936 
1937  if (printToFile) {outfile << std::setw(space) << "Total:";}
1938  if (printToCSV) {outcsv << "Total,";}
1939 
1940  //Clear the table_headings to print last row of totals
1941  table_headings = fmt::format("| {:<8} |", "Total");
1942  for (unsigned int i=0;i<ChannelIntegral.size();i++) {
1943  if (printToFile) {outfile << "&" << std::setw(space) << Form("%4.5f",ChannelIntegral[i]) << " ";}
1944  if (printToCSV) {outcsv << Form("%4.5f", ChannelIntegral[i]) << ",";}
1945  table_headings += fmt::format(" {:<17.4f} |", ChannelIntegral[i]);
1946  }
1947  if (printToFile) {outfile << "&" << std::setw(space) << Form("%4.5f",PDFIntegral) << " \\\\ \\hline" << std::endl;}
1948  if (printToCSV) {outcsv << Form("%4.5f", PDFIntegral) << "\n\n\n\n";} // Let's have a few new lines!
1949 
1950  table_headings += fmt::format(" {:<10.4f} |", PDFIntegral);
1951  MACH3LOG_INFO("{}", table_headings);
1952  MACH3LOG_INFO("{}", table_footline);
1953 
1954  if (printToFile) {
1955  outfile << "\\end{tabular}" << std::endl;
1956  outfile << "\\end{center}" << std::endl;
1957  outfile << "\\end{table}" << std::endl;
1958  }
1959 
1960  MACH3LOG_INFO("");
1961 
1962  if (printToFile) {
1963  outfile << std::endl;
1964  outfile.close();
1965  }
1966  // KS: Clean memory we could use smart pointers in future
1967  CleanContainer(IntegralList);
1968 }
void CleanContainer(std::vector< T * > &container)
Generic cleanup function.
std::unique_ptr< MaCh3Modes > Modes
Holds information about used Generator and MaCh3 modes.
std::vector< TH2 * > ReturnHistsBySelection2D(std::string KinematicProjectionX, std::string KinematicProjectionY, int Selection1, int Selection2=-1, int WeightStyle=0, TAxis *XAxis=0, TAxis *YAxis=0)
std::string GetFlavourName(const int iChannel)
std::vector< TH1 * > ReturnHistsBySelection1D(std::string KinematicProjection, int Selection1, int Selection2=-1, int WeightStyle=0, TAxis *Axis=0)

◆ ReadSampleConfig()

void SampleHandlerFD::ReadSampleConfig ( )

Definition at line 57 of file SampleHandlerFD.cpp.

58 {
59  auto ModeName = Get<std::string>(SampleManager->raw()["MaCh3ModeConfig"], __FILE__ , __LINE__);
60  Modes = std::make_unique<MaCh3Modes>(ModeName);
61  //SampleTitle has to be provided in the sample yaml otherwise this will throw an exception
62  SampleDetails.SampleTitle = Get<std::string>(SampleManager->raw()["SampleTitle"], __FILE__ , __LINE__);
63  //SampleName has to be provided in the sample yaml otherwise this will throw an exception
64  SampleName = Get<std::string>(SampleManager->raw()["SampleName"], __FILE__ , __LINE__);
65 
66  fTestStatistic = static_cast<TestStatistic>(SampleManager->GetMCStatLLH());
67  if (CheckNodeExists(SampleManager->raw(), "LikelihoodOptions")) {
68  UpdateW2 = GetFromManager<bool>(SampleManager->raw()["LikelihoodOptions"]["UpdateW2"], false);
69  }
70  //Binning
72  SampleDetails.XVarStr = GetFromManager(SampleManager->raw()["Binning"]["XVarStr"], std::string(""));
73  Binning.XBinEdges = GetFromManager(SampleManager->raw()["Binning"]["XVarBins"], std::vector<double>());
74  const auto& edgesx = Binning.XBinEdges;
75  if (!std::is_sorted(edgesx.begin(), edgesx.end())) {
76  MACH3LOG_ERROR("XVarBins must be in increasing order in sample config {}\n XVarBins: [{}]",
77  GetTitle(), fmt::join(edgesx, ", "));
78  throw MaCh3Exception(__FILE__, __LINE__);
79  }
80  if(GetXBinVarName().length() > 0){
82  } else{
83  MACH3LOG_ERROR("Please specify an X-variable string in sample config {}", SampleManager->GetFileName());
84  throw MaCh3Exception(__FILE__, __LINE__);
85  }
86 
87  SampleDetails.YVarStr = GetFromManager(SampleManager->raw()["Binning"]["YVarStr"], std::string(""));
88  Binning.YBinEdges = GetFromManager(SampleManager->raw()["Binning"]["YVarBins"], std::vector<double>());
89  const auto& edgesy = Binning.YBinEdges;
90  if (!std::is_sorted(edgesy.begin(), edgesy.end())) {
91  MACH3LOG_ERROR("YBinEdges must be in increasing order in sample config {}\n YBinEdges: [{}]",
92  GetTitle(), fmt::join(edgesy, ", "));
93  throw MaCh3Exception(__FILE__, __LINE__);
94  }
95  if(GetYBinVarName().length() > 0){
96  if(GetXBinVarName().length() == 0){
97  MACH3LOG_ERROR("Please specify an X-variable string in sample config {}. I won't work only with a Y-variable", SampleManager->GetFileName());
98  throw MaCh3Exception(__FILE__, __LINE__);
99  }
101  }
102 
103  if(GetNDim() == 0){
104  MACH3LOG_ERROR("Error setting up the sample binning");
105  MACH3LOG_ERROR("Number of dimensions is {}", GetNDim());
106  MACH3LOG_ERROR("Check that an XVarStr has been given in the sample config");
107  throw MaCh3Exception(__FILE__, __LINE__);
108  } else{
109  MACH3LOG_INFO("Found {} dimensions for sample binning", GetNDim());
110  }
111 
112  //Sanity check that some binning has been specified
113  if(Binning.XBinEdges.size() == 0 && Binning.YBinEdges.size() == 0){
114  MACH3LOG_ERROR("No binning specified for either X or Y of sample binning, please add some binning to the sample config {}", SampleManager->GetFileName());
115  throw MaCh3Exception(__FILE__, __LINE__);
116  }
117 
118  if (!CheckNodeExists(SampleManager->raw(), "BinningFile")){
119  MACH3LOG_ERROR("BinningFile not given in for sample {}, ReturnKinematicParameterBinning will not work", GetTitle());
120  throw MaCh3Exception(__FILE__, __LINE__);
121  }
122 
123  auto mtupleprefix = Get<std::string>(SampleManager->raw()["InputFiles"]["mtupleprefix"], __FILE__, __LINE__);
124  auto mtuplesuffix = Get<std::string>(SampleManager->raw()["InputFiles"]["mtuplesuffix"], __FILE__, __LINE__);
125  auto splineprefix = Get<std::string>(SampleManager->raw()["InputFiles"]["splineprefix"], __FILE__, __LINE__);
126  auto splinesuffix = Get<std::string>(SampleManager->raw()["InputFiles"]["splinesuffix"], __FILE__, __LINE__);
127 
128  int NChannels = static_cast<M3::int_t>(SampleManager->raw()["SubSamples"].size());
129  OscChannels.reserve(NChannels);
130 
131  for (auto const &osc_channel : SampleManager->raw()["SubSamples"]) {
132  std::string MTupleFileName = mtupleprefix+osc_channel["mtuplefile"].as<std::string>()+mtuplesuffix;
133 
134  OscChannelInfo OscInfo;
135  OscInfo.flavourName = osc_channel["Name"].as<std::string>();
136  OscInfo.flavourName_Latex = osc_channel["LatexName"].as<std::string>();
137  OscInfo.InitPDG = static_cast<NuPDG>(osc_channel["nutype"].as<int>());
138  OscInfo.FinalPDG = static_cast<NuPDG>(osc_channel["oscnutype"].as<int>());
139  OscInfo.ChannelIndex = GetNOscChannels();
140 
141  OscChannels.push_back(std::move(OscInfo));
142 
143  FileToInitPDGMap[MTupleFileName] = static_cast<NuPDG>(osc_channel["nutype"].as<int>());
144  FileToFinalPDGMap[MTupleFileName] = static_cast<NuPDG>(osc_channel["oscnutype"].as<int>());
145 
146  mc_files.push_back(MTupleFileName);
147  spline_files.push_back(splineprefix+osc_channel["splinefile"].as<std::string>()+splinesuffix);
148  }
149 
150  //Now grab the selection cuts from the manager
151  for ( auto const &SelectionCuts : SampleManager->raw()["SelectionCuts"]) {
152  auto TempBoundsVec = GetBounds(SelectionCuts["Bounds"]);
153  KinematicCut CutObj;
154  CutObj.LowerBound = TempBoundsVec[0];
155  CutObj.UpperBound = TempBoundsVec[1];
156  CutObj.ParamToCutOnIt = ReturnKinematicParameterFromString(SelectionCuts["KinematicStr"].as<std::string>());
157  MACH3LOG_INFO("Adding cut on {} with bounds {} to {}", SelectionCuts["KinematicStr"].as<std::string>(), TempBoundsVec[0], TempBoundsVec[1]);
158  StoredSelection.push_back(CutObj);
159  }
160 
161  // EM: initialise the mode weight map
162  for( int iMode=0; iMode < Modes->GetNModes(); iMode++ ) {
163  _modeNomWeightMap[Modes->GetMaCh3ModeName(iMode)] = 1.0;
164  }
165 
166  // EM: multiply by the nominal weight specified in the sample config file
167  if ( SampleManager->raw()["NominalWeights"] ) {
168  for( int iMode=0; iMode<Modes->GetNModes(); iMode++ ) {
169  std::string modeStr = Modes->GetMaCh3ModeName(iMode);
170  if( SampleManager->raw()["NominalWeights"][modeStr] ) {
171  double modeWeight = SampleManager->raw()["NominalWeights"][modeStr].as<double>();
172  _modeNomWeightMap[Modes->GetMaCh3ModeName(iMode)] *= modeWeight;
173  }
174  }
175  }
176 
177  // EM: print em out
178  MACH3LOG_INFO(" Nominal mode weights to apply: ");
179  for(int iMode=0; iMode<Modes->GetNModes(); iMode++ ) {
180  std::string modeStr = Modes->GetMaCh3ModeName(iMode);
181  MACH3LOG_INFO(" - {}: {}", modeStr, _modeNomWeightMap.at(modeStr));
182  }
183 }
NuPDG
Enum to track the incoming neutrino species.
TestStatistic
Make an enum of the test statistic that we're using.
Type GetFromManager(const YAML::Node &node, Type defval, const std::string File="", const int Line=1)
Get content of config file if node is not found take default value specified.
Definition: YamlHelper.h:299
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
Definition: YamlHelper.h:55
#define GetBounds(filename)
Definition: YamlHelper.h:562
TestStatistic fTestStatistic
Test statistic tells what kind of likelihood sample is using.
std::vector< std::string > mc_files
names of mc files associated associated with this object
std::unordered_map< std::string, double > _modeNomWeightMap
int int_t
Definition: Core.h:31
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: Store info about used osc channels.
std::string flavourName
Name of osc channel.
std::vector< double > YBinEdges
Vector to hold y-axis bin-edges.
int nDimensions
Keep track of the dimensions of the sample binning.
std::string XVarStr
the strings associated with the variables used for the X binning e.g. "RecoNeutrinoEnergy"
std::string SampleTitle
the name of this sample e.g."muon-like"
std::string YVarStr
the strings associated with the variables used for the Y binning e.g. "RecoNeutrinoEnergy"

◆ RegisterFunctionalParameters()

virtual void SampleHandlerFD::RegisterFunctionalParameters ( )
protectedpure virtual

HH - a experiment-specific function where the maps to actual functions are set up.

Implemented in PySampleHandlerFD.

◆ RegisterIndividualFunctionalParameter()

void SampleHandlerFD::RegisterIndividualFunctionalParameter ( const std::string &  fpName,
int  fpEnum,
FuncParFuncType  fpFunc 
)
protected

HH - a helper function for RegisterFunctionalParameter.

Definition at line 581 of file SampleHandlerFD.cpp.

581  {
582  // Add protections to not add the same functional parameter twice
583  if (funcParsNamesMap.find(fpName) != funcParsNamesMap.end()) {
584  MACH3LOG_ERROR("Functional parameter {} already registered in funcParsNamesMap with enum {}", fpName, funcParsNamesMap[fpName]);
585  throw MaCh3Exception(__FILE__, __LINE__);
586  }
587  if (std::find(funcParsNamesVec.begin(), funcParsNamesVec.end(), fpName) != funcParsNamesVec.end()) {
588  MACH3LOG_ERROR("Functional parameter {} already in funcParsNamesVec", fpName);
589  throw MaCh3Exception(__FILE__, __LINE__);
590  }
591  if (funcParsFuncMap.find(fpEnum) != funcParsFuncMap.end()) {
592  MACH3LOG_ERROR("Functional parameter enum {} already registered in funcParsFuncMap", fpEnum);
593  throw MaCh3Exception(__FILE__, __LINE__);
594  }
595  funcParsNamesMap[fpName] = fpEnum;
596  funcParsNamesVec.push_back(fpName);
597  funcParsFuncMap[fpEnum] = fpFunc;
598 }
std::unordered_map< int, FuncParFuncType > funcParsFuncMap
HH - a map that relates the funcpar enum to pointer of the actual function.
std::vector< std::string > funcParsNamesVec
HH - a vector of string names for each functional parameter.
std::unordered_map< std::string, int > funcParsNamesMap
HH - a map that relates the name of the functional parameter to funcpar enum.

◆ ResetHistograms()

void SampleHandlerFD::ResetHistograms ( )
inlineprotected

Helper function to reset histograms.

Definition at line 568 of file SampleHandlerFD.cpp.

568  {
569 // **************************************************
570  //DB Reset values stored in PDF array to 0.
571  // Don't openMP this; no significant gain
572  #ifdef MULTITHREAD
573  #pragma omp simd
574  #endif
575  for (size_t i = 0; i < Binning.nBins; ++i) {
576  SampleHandlerFD_array[i] = 0.;
578  }
579 } // end function

◆ resetShifts()

virtual void SampleHandlerFD::resetShifts ( int  iEvent)
inlineprotectedvirtual

HH - reset the shifted values to the original values.

Definition at line 228 of file SampleHandlerFD.h.

228 {(void)iEvent;};

◆ ReturnKinematicParameter() [1/2]

virtual double SampleHandlerFD::ReturnKinematicParameter ( int  KinematicVariable,
int  iEvent 
)
protectedpure virtual

Implemented in PySampleHandlerFD.

◆ ReturnKinematicParameter() [2/2]

virtual double SampleHandlerFD::ReturnKinematicParameter ( std::string  KinematicParamter,
int  iEvent 
)
protectedpure virtual

Return the value of an associated kinematic parameter for an event.

Implemented in PySampleHandlerFD.

◆ ReturnKinematicParameterBinning()

std::vector< double > SampleHandlerFD::ReturnKinematicParameterBinning ( const std::string &  KinematicParameter)
protected

Return the binning used to draw a kinematic parameter.

Definition at line 1680 of file SampleHandlerFD.cpp.

1680  {
1681 // ************************************************
1682  // If x or y variable return used binning
1683  if(KinematicParameter == GetXBinVarName()) {
1684  return Binning.XBinEdges;
1685  } else if (KinematicParameter == GetYBinVarName()) {
1686  return Binning.YBinEdges;
1687  }
1688 
1689  auto MakeBins = [](int nBins) {
1690  std::vector<double> bins(nBins + 1);
1691  for (int i = 0; i <= nBins; ++i)
1692  bins[i] = static_cast<double>(i) - 0.5;
1693  return bins;
1694  };
1695 
1696  if (KinematicParameter == "OscillationChannel") {
1697  return MakeBins(GetNOscChannels());
1698  } else if (KinematicParameter == "Mode") {
1699  return MakeBins(Modes->GetNModes());
1700  }
1701 
1702  // We first check if binning for a sample has been specified
1703  auto BinningConfig = M3OpenConfig(SampleManager->raw()["BinningFile"].as<std::string>());
1704  if(BinningConfig[GetTitle()] && BinningConfig[GetTitle()][KinematicParameter]){
1705  auto BinningVect = Get<std::vector<double>>(BinningConfig[GetTitle()][KinematicParameter], __FILE__, __LINE__);
1706  return BinningVect;
1707  } else {
1708  auto BinningVect = Get<std::vector<double>>(BinningConfig[KinematicParameter], __FILE__, __LINE__);
1709  return BinningVect;
1710  }
1711 }
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:561

◆ ReturnKinematicVector() [1/2]

virtual std::vector<double> SampleHandlerFD::ReturnKinematicVector ( int  KinematicVariable,
int  iEvent 
)
inlineprotectedvirtual

Definition at line 267 of file SampleHandlerFD.h.

267 {return {}; (void)KinematicVariable; (void)iEvent;};

◆ ReturnKinematicVector() [2/2]

virtual std::vector<double> SampleHandlerFD::ReturnKinematicVector ( std::string  KinematicParameter,
int  iEvent 
)
inlineprotectedvirtual

Definition at line 266 of file SampleHandlerFD.h.

266 {return {}; (void)KinematicParameter; (void)iEvent;};

◆ ReturnKinematicVectorFromString()

int SampleHandlerFD::ReturnKinematicVectorFromString ( const std::string &  KinematicStr) const

Definition at line 1654 of file SampleHandlerFD.cpp.

1654  {
1655 // ************************************************
1656  auto it = KinematicVectors->find(KinematicVectorStr);
1657  if (it != KinematicVectors->end()) return it->second;
1658 
1659  MACH3LOG_ERROR("Did not recognise Kinematic Vector: {}", KinematicVectorStr);
1660  throw MaCh3Exception(__FILE__, __LINE__);
1661 
1662  return M3::_BAD_INT_;
1663 }

◆ ReturnStringFromKinematicVector()

std::string SampleHandlerFD::ReturnStringFromKinematicVector ( const int  KinematicVariable) const

Definition at line 1666 of file SampleHandlerFD.cpp.

1666  {
1667 // ************************************************
1668  auto it = ReversedKinematicVectors->find(KinematicVector);
1669  if (it != ReversedKinematicVectors->end()) {
1670  return it->second;
1671  }
1672 
1673  MACH3LOG_ERROR("Did not recognise Kinematic Vector: {}", KinematicVector);
1674  throw MaCh3Exception(__FILE__, __LINE__);
1675 
1676  return "";
1677 }

◆ Reweight()

void SampleHandlerFD::Reweight ( )
overridevirtual

Implements SampleHandlerBase.

Definition at line 368 of file SampleHandlerFD.cpp.

368  {
369 //************************************************
370  //KS: Reset the histograms before reweight
371  ResetHistograms();
372 
373  //You only need to do these things if Oscillator has been initialised
374  //if not then you're not considering oscillations
375  if (Oscillator) Oscillator->Evaluate();
376 
377  // Calculate weight coming from all splines if we initialised handler
378  if(SplineHandler) SplineHandler->Evaluate();
379 
380  #ifdef MULTITHREAD
381  // Call entirely different routine if we're running with openMP
382  FillArray_MP();
383  #else
384  FillArray();
385  #endif
386 
387  //KS: If you want to not update W2 wights then uncomment this line
388  if(!UpdateW2) FirstTimeW2 = false;
389 }
void ResetHistograms()
Helper function to reset histograms.
void FillArray()
DB Nice new multi-threaded function which calculates the event weights and fills the relevant bins of...

◆ SaveAdditionalInfo()

void SampleHandlerFD::SaveAdditionalInfo ( TDirectory *  Dir)
overridevirtual

Store additional info in a chan.

Reimplemented from SampleHandlerBase.

Definition at line 1367 of file SampleHandlerFD.cpp.

1367  {
1368 // ************************************************
1369  Dir->cd();
1370 
1371  YAML::Node Config = SampleManager->raw();
1372  TMacro ConfigSave = YAMLtoTMacro(Config, (std::string("Config_") + GetTitle()));
1373  ConfigSave.Write();
1374 
1375  std::unique_ptr<TH1> data_hist;
1376 
1377  if (GetNDim() == 1) {
1378  data_hist = M3::Clone<TH1D>(dynamic_cast<TH1D*>(GetDataHist(1)), "data_" + GetTitle());
1379  data_hist->GetXaxis()->SetTitle(GetXBinVarName().c_str());
1380  data_hist->GetYaxis()->SetTitle("Number of Events");
1381  } else if (GetNDim() == 2) {
1382  data_hist = M3::Clone<TH2D>(dynamic_cast<TH2D*>(GetDataHist(2)), "data_" + GetTitle());
1383  data_hist->GetXaxis()->SetTitle(GetXBinVarName().c_str());
1384  data_hist->GetYaxis()->SetTitle(GetYBinVarName().c_str());
1385  data_hist->GetZaxis()->SetTitle("Number of Events");
1386  } else {
1387  MACH3LOG_ERROR("Not implemented");
1388  throw MaCh3Exception(__FILE__, __LINE__);
1389  }
1390 
1391  if (!data_hist) {
1392  MACH3LOG_ERROR("nullptr data hist :(");
1393  throw MaCh3Exception(__FILE__, __LINE__);
1394  }
1395 
1396  data_hist->SetTitle(("data_" + GetTitle()).c_str());
1397  data_hist->Write();
1398 }
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
Definition: YamlHelper.h:162
TH1 * GetDataHist(const int Dimension)
Get Data histogram.

◆ Set1DBinning() [1/2]

void SampleHandlerFD::Set1DBinning ( size_t  nbins,
double *  boundaries 
)
protected

sets the binning used for the likelihood calculation, used for both data and MC

Parameters
nbinsnumber of total bins
boundariesthe bin edges e.g. 0, 0.1, 0.2, 0.3

Definition at line 899 of file SampleHandlerFD.cpp.

900 {
901  SampleDetails._hPDF1D->Reset();
902  SampleDetails._hPDF1D->SetBins(static_cast<int>(nbins),boundaries);
903  SampleDetails.dathist->SetBins(static_cast<int>(nbins),boundaries);
904 
905  Binning.YBinEdges = {-1e8, 1e8};
906 
907  SampleDetails._hPDF2D->Reset();
908  SampleDetails._hPDF2D->SetBins(static_cast<int>(nbins),boundaries,1, Binning.YBinEdges.data());
909  SampleDetails.dathist2d->SetBins(static_cast<int>(nbins),boundaries,1, Binning.YBinEdges.data());
910 
911  //Set the number of X and Y bins now
912  SetupReweightArrays(Binning.XBinEdges.size() - 1, Binning.YBinEdges.size() - 1);
913 
915 }
void FindNominalBinAndEdges1D()
void SetupReweightArrays(const size_t numberXBins, const size_t numberYBins)
Initialise data, MC and W2 histograms.

◆ Set1DBinning() [2/2]

void SampleHandlerFD::Set1DBinning ( std::vector< double > &  XVec)
inlineprotected

set the binning for 1D sample used for the likelihood calculation

Parameters
XVecvector containing the binning in axis 1 (the x-axis)

Definition at line 197 of file SampleHandlerFD.h.

197 {Set1DBinning(XVec.size()-1, XVec.data());};
void Set1DBinning(size_t nbins, double *boundaries)
sets the binning used for the likelihood calculation, used for both data and MC

◆ Set2DBinning() [1/2]

void SampleHandlerFD::Set2DBinning ( size_t  nbins1,
double *  boundaries1,
size_t  nbins2,
double *  boundaries2 
)
protected

set the binning for 2D sample used for the likelihood calculation

Parameters
nbins1number of bins in axis 1 (the x-axis)
nbins2number of bins in axis 2 (the y-axis)
boundaries1the bin boundaries used in axis 1 (the x-axis)
boundaries2the bin boundaries used in axis 2 (the y-axis)

Definition at line 941 of file SampleHandlerFD.cpp.

942 {
943  SampleDetails._hPDF1D->Reset();
944  SampleDetails._hPDF1D->SetBins(static_cast<int>(nbins1),boundaries1);
945  SampleDetails.dathist->SetBins(static_cast<int>(nbins1),boundaries1);
946 
947  SampleDetails._hPDF2D->Reset();
948  SampleDetails._hPDF2D->SetBins(static_cast<int>(nbins1),boundaries1,static_cast<int>(nbins2),boundaries2);
949  SampleDetails.dathist2d->SetBins(static_cast<int>(nbins1),boundaries1,static_cast<int>(nbins2),boundaries2);
950 
951  //Set the number of X and Y bins now
952  SetupReweightArrays(Binning.XBinEdges.size() - 1, Binning.YBinEdges.size() - 1);
953 
955 }
void FindNominalBinAndEdges2D()

◆ Set2DBinning() [2/2]

void SampleHandlerFD::Set2DBinning ( std::vector< double > &  XVec,
std::vector< double > &  YVec 
)
inlineprotected

set the binning for 2D sample used for the likelihood calculation

Parameters
XVecvector containing the binning in axis 1 (the x-axis)
YVecvector containing the binning in axis 2 (the y-axis)

Definition at line 201 of file SampleHandlerFD.h.

201 {Set2DBinning(XVec.size()-1, XVec.data(), YVec.size()-1, YVec.data());};
void Set2DBinning(size_t nbins1, double *boundaries1, size_t nbins2, double *boundaries2)
set the binning for 2D sample used for the likelihood calculation

◆ SetupExperimentMC()

virtual int SampleHandlerFD::SetupExperimentMC ( )
protectedpure virtual

Experiment specific setup, returns the number of events which were loaded.

Implemented in PySampleHandlerFD.

◆ SetupFDMC()

virtual void SampleHandlerFD::SetupFDMC ( )
protectedpure virtual

Function which translates experiment struct into core struct.

Implemented in PySampleHandlerFD.

◆ SetupFunctionalParameters()

void SampleHandlerFD::SetupFunctionalParameters ( )
protectedvirtual

ETA - a function to setup and pass values to functional parameters where you need to pass a value to some custom reweight calc or engine.

Definition at line 600 of file SampleHandlerFD.cpp.

600  {
602  // RegisterFunctionalParameters is implemented in experiment-specific code,
603  // which calls RegisterIndividualFuncPar to populate funcParsNamesMap, funcParsNamesVec, and funcParsFuncMap
605  funcParsMap.resize(funcParsNamesMap.size());
606  funcParsGrid.resize(GetNEvents());
607 
608  // For every functional parameter in XsecCov that matches the name in funcParsNames, add it to the map
609  for (FunctionalParameter & fp : funcParsVec) {
610  for (std::string name : funcParsNamesVec) {
611  if (fp.name == name) {
612  MACH3LOG_INFO("Adding functional parameter: {} to funcParsMap with key: {}", fp.name, funcParsNamesMap[fp.name]);
613  fp.funcPtr = &funcParsFuncMap[funcParsNamesMap[fp.name]];
614  funcParsMap[static_cast<std::size_t>(funcParsNamesMap[fp.name])] = &fp;
615  continue;
616  }
617  }
618  // If we don't find a match, we need to throw an error
619  if (funcParsMap[static_cast<std::size_t>(funcParsNamesMap[fp.name])] == nullptr) {
620  MACH3LOG_ERROR("Functional parameter {} not found, did you define it in RegisterFunctionalParameters()?", fp.name);
621  throw MaCh3Exception(__FILE__, __LINE__);
622  }
623  }
624 
625  // Mostly the same as CalcXsecNormsBins
626  // For each event, make a vector of pointers to the functional parameters
627  for (std::size_t iEvent = 0; iEvent < static_cast<std::size_t>(GetNEvents()); ++iEvent) {
628  // Now loop over the functional parameters and get a vector of enums corresponding to the functional parameters
629  for (std::vector<FunctionalParameter>::iterator it = funcParsVec.begin(); it != funcParsVec.end(); ++it) {
630  // Check whether the interaction modes match
631  bool ModeMatch = MatchCondition((*it).modes, static_cast<int>(std::round(*(MCSamples[iEvent].mode))));
632  if (!ModeMatch) {
633  MACH3LOG_TRACE("Event {}, missed Mode check ({}) for dial {}", iEvent, *(MCSamples[iEvent].mode), (*it).name);
634  continue;
635  }
636  // Now check whether within kinematic bounds
637  bool IsSelected = true;
638  if ((*it).hasKinBounds) {
639  const auto& kinVars = (*it).KinematicVarStr;
640  const auto& selection = (*it).Selection;
641 
642  for (std::size_t iKinPar = 0; iKinPar < kinVars.size(); ++iKinPar) {
643  const double kinVal = ReturnKinematicParameter(kinVars[iKinPar], static_cast<int>(iEvent));
644 
645  bool passedAnyBound = false;
646  const auto& boundsList = selection[iKinPar];
647 
648  for (const auto& bounds : boundsList) {
649  if (kinVal > bounds[0] && kinVal <= bounds[1]) {
650  passedAnyBound = true;
651  break;
652  }
653  }
654 
655  if (!passedAnyBound) {
656  MACH3LOG_TRACE("Event {}, missed kinematic check ({}) for dial {}",
657  iEvent, kinVars[iKinPar], (*it).name);
658  IsSelected = false;
659  break;
660  }
661  }
662  }
663  // Need to then break the event loop
664  if(!IsSelected){
665  MACH3LOG_TRACE("Event {}, missed Kinematic var check for dial {}", iEvent, (*it).name);
666  continue;
667  }
668  auto funcparenum = funcParsNamesMap[(*it).name];
669  funcParsGrid.at(iEvent).push_back(funcparenum);
670  }
671  }
672  MACH3LOG_INFO("Finished setting up functional parameters");
673 }
std::vector< FunctionalParameter > funcParsVec
HH - a vector that stores all the FuncPars struct.
virtual void RegisterFunctionalParameters()=0
HH - a experiment-specific function where the maps to actual functions are set up.
const std::vector< FunctionalParameter > GetFunctionalParametersFromSampleName(const std::string &SampleName) const
HH Get functional parameters for the relevant SampleName.

◆ SetupKinematicMap()

void SampleHandlerFD::SetupKinematicMap ( )
protected

Ensure Kinematic Map is setup and make sure it is initialised correctly.

Definition at line 240 of file SampleHandlerFD.cpp.

240  {
241 // ************************************************
242  if(KinematicParameters == nullptr || ReversedKinematicParameters == nullptr) {
243  MACH3LOG_INFO("Map KinematicParameters or ReversedKinematicParameters hasn't been initialised");
244  throw MaCh3Exception(__FILE__, __LINE__);
245  }
246  // KS: Ensure maps exist correctly
247  for (const auto& pair : *KinematicParameters) {
248  const auto& key = pair.first;
249  const auto& value = pair.second;
250 
251  auto it = ReversedKinematicParameters->find(value);
252  if (it == ReversedKinematicParameters->end() || it->second != key) {
253  MACH3LOG_ERROR("Mismatch found: {} -> {} but {} -> {}",
254  key, value, value, (it != ReversedKinematicParameters->end() ? it->second : "NOT FOUND"));
255  throw MaCh3Exception(__FILE__, __LINE__);
256  }
257  }
258 }

◆ SetupNormParameters()

void SampleHandlerFD::SetupNormParameters ( )
protected

Setup the norm parameters by assigning each event with bin.

Definition at line 738 of file SampleHandlerFD.cpp.

738  {
739 // ***************************************************************************
740  std::vector< std::vector< int > > xsec_norms_bins(GetNEvents());
741 
742  std::vector<NormParameter> norm_parameters = ParHandler->GetNormParsFromSampleName(GetSampleName());
743 
744  if(!ParHandler){
745  MACH3LOG_ERROR("ParHandler is not setup!");
746  throw MaCh3Exception(__FILE__ , __LINE__ );
747  }
748 
749  // Assign xsec norm bins in MCSamples tree
750  CalcNormsBins(norm_parameters, xsec_norms_bins);
751 
752  //DB Attempt at reducing impact of SystematicHandlerGeneric::calcReweight()
753  int counter;
754  for (unsigned int iEvent = 0; iEvent < GetNEvents(); ++iEvent) {
755  counter = 0;
756 
757  MCSamples[iEvent].xsec_norm_pointers.resize(xsec_norms_bins[iEvent].size());
758  for(auto const & norm_bin: xsec_norms_bins[iEvent]) {
759  MCSamples[iEvent].xsec_norm_pointers[counter] = ParHandler->RetPointer(norm_bin);
760  counter += 1;
761  }
762  }
763 }
int size
const double * RetPointer(const int iParam)
DB Pointer return to param position.
void CalcNormsBins(std::vector< NormParameter > &norm_parameters, std::vector< std::vector< int > > &xsec_norms_bins)
Check whether a normalisation systematic affects an event or not.
const std::vector< NormParameter > GetNormParsFromSampleName(const std::string &SampleName) const
DB Get norm/func parameters depending on given SampleName.

◆ SetupNuOscillatorPointers()

void SampleHandlerFD::SetupNuOscillatorPointers ( )

Definition at line 1235 of file SampleHandlerFD.cpp.

1235  {
1236  for (unsigned int iEvent=0;iEvent<GetNEvents();iEvent++) {
1237  MCSamples[iEvent].osc_w_pointer = &M3::Unity;
1238  if (MCSamples[iEvent].isNC) {
1239  if (*MCSamples[iEvent].nupdg != *MCSamples[iEvent].nupdgUnosc) {
1240  MCSamples[iEvent].osc_w_pointer = &M3::Zero;
1241  } else {
1242  MCSamples[iEvent].osc_w_pointer = &M3::Unity;
1243  }
1244  } else {
1245  int InitFlav = M3::_BAD_INT_;
1246  int FinalFlav = M3::_BAD_INT_;
1247 
1248  InitFlav = MaCh3Utils::PDGToNuOscillatorFlavour((*MCSamples[iEvent].nupdgUnosc));
1249  FinalFlav = MaCh3Utils::PDGToNuOscillatorFlavour((*MCSamples[iEvent].nupdg));
1250 
1251  if (InitFlav == M3::_BAD_INT_ || FinalFlav == M3::_BAD_INT_) {
1252  MACH3LOG_ERROR("Something has gone wrong in the mapping between MCSamples.nutype and the enum used within NuOscillator");
1253  MACH3LOG_ERROR("MCSamples.nupdgUnosc: {}", (*MCSamples[iEvent].nupdgUnosc));
1254  MACH3LOG_ERROR("InitFlav: {}", InitFlav);
1255  MACH3LOG_ERROR("MCSamples.nupdg: {}", (*MCSamples[iEvent].nupdg));
1256  MACH3LOG_ERROR("FinalFlav: {}", FinalFlav);
1257  throw MaCh3Exception(__FILE__, __LINE__);
1258  }
1259 
1260  const int OscIndex = GetOscChannel(OscChannels, (*MCSamples[iEvent].nupdgUnosc), (*MCSamples[iEvent].nupdg));
1261  //Can only happen if truecz has been initialised within the experiment specific code
1262  if (*(MCSamples[iEvent].rw_truecz) != M3::_BAD_DOUBLE_) {
1263  //Atmospherics
1264  MCSamples[iEvent].osc_w_pointer = Oscillator->GetNuOscillatorPointers(OscIndex, InitFlav, FinalFlav, FLOAT_T(*(MCSamples[iEvent].rw_etru)), FLOAT_T(*(MCSamples[iEvent].rw_truecz)));
1265  } else {
1266  //Beam
1267  MCSamples[iEvent].osc_w_pointer = Oscillator->GetNuOscillatorPointers(OscIndex, InitFlav, FinalFlav, FLOAT_T(*(MCSamples[iEvent].rw_etru)));
1268  }
1269  } // end if NC
1270  } // end loop over events
1271 }
constexpr static const float_t Unity
Definition: Core.h:57
constexpr static const float_t Zero
Definition: Core.h:64
int PDGToNuOscillatorFlavour(const int NuPdg)
Convert from PDG flavour to NuOscillator type beware that in the case of anti-neutrinos the NuOscilla...

◆ SetupReweightArrays()

void SampleHandlerFD::SetupReweightArrays ( const size_t  numberXBins,
const size_t  numberYBins 
)
protected

Initialise data, MC and W2 histograms.

Definition at line 874 of file SampleHandlerFD.cpp.

874  {
875 // ************************************************
876  //Set the number of X and Y bins now
877  Binning.nXBins = numberXBins;
878  Binning.nYBins = numberYBins;
879 
880  // Set total number of bins
882  Binning.GlobalOffset = 0;
883  SampleHandlerFD_array = new double[Binning.nBins];
884  SampleHandlerFD_array_w2 = new double[Binning.nBins];
885  SampleHandlerFD_data = new double[Binning.nBins];
886 
887  for (size_t i = 0; i < Binning.nBins; ++i) {
888  SampleHandlerFD_array[i] = 0.0;
889  SampleHandlerFD_array_w2[i] = 0.0;
890  SampleHandlerFD_data[i] = 0.0;
891  }
892 }
size_t GlobalOffset
If you have binning for multiple samples and trying to define 1D vector let's.

◆ SetupSampleBinning()

void SampleHandlerFD::SetupSampleBinning ( )
protected

Function to setup the binning of your sample histograms and the underlying arrays that get handled in fillArray() and fillArray_MP(). The Binning.XBinEdges are filled in the daughter class from the sample config file. This "passing" can be removed.

Definition at line 294 of file SampleHandlerFD.cpp.

294  {
295 // ************************************************
296  MACH3LOG_INFO("Setting up Sample Binning");
298 
299  //A string to store the binning for a nice print out
300  std::string XBinEdgesStr = "";
301  std::string YBinEdgesStr = "";
302 
303  for(auto XBinEdge : Binning.XBinEdges){
304  XBinEdgesStr += std::to_string(XBinEdge);
305  XBinEdgesStr += ", ";
306  }
307  MACH3LOG_INFO("XBinning:");
308  MACH3LOG_INFO("{}", XBinEdgesStr);
309 
310  //And now the YBin Edges
311  for(auto YBinEdge : Binning.YBinEdges){
312  YBinEdgesStr += std::to_string(YBinEdge);
313  YBinEdgesStr += ", ";
314  }
315  MACH3LOG_INFO("YBinning:");
316  MACH3LOG_INFO("{}", YBinEdgesStr);
317 
318  //Check whether you are setting up 1D or 2D binning
319  if(GetNDim() == 1){
320  MACH3LOG_INFO("Setting up {}D binning with {}", GetNDim(), GetXBinVarName());
322  }
323  else if(GetNDim() == 2){
324  MACH3LOG_INFO("Setting up {}D binning with {} and {}", GetNDim(), GetXBinVarName(), GetYBinVarName());
326  }
327  else{
328  MACH3LOG_ERROR("Number of dimensions is not 1 or 2, this is unsupported at the moment");
329  throw MaCh3Exception(__FILE__, __LINE__);
330  }
331 }
void InitialiseHistograms()
Initialise histograms used for plotting.

◆ SetupSplines()

virtual void SampleHandlerFD::SetupSplines ( )
protectedpure virtual

initialise your splineXX object and then use InitialiseSplineObject to conviently setup everything up

Todo:
abstract the spline initialisation completely to core

Implemented in PySampleHandlerFD.

◆ SetupWeightPointers()

virtual void SampleHandlerFD::SetupWeightPointers ( )
protectedpure virtual

DB Function to determine which weights apply to which types of samples pure virtual!!

Implemented in PySampleHandlerFD.

Member Data Documentation

◆ _modeNomWeightMap

std::unordered_map<std::string, double> SampleHandlerFD::_modeNomWeightMap
protected

Definition at line 370 of file SampleHandlerFD.h.

◆ Binning

SampleBinningInfo SampleHandlerFD::Binning
protected

KS: This stores binning information, in future could be come vector to store binning for every used sample.

Definition at line 305 of file SampleHandlerFD.h.

◆ FileToFinalPDGMap

std::unordered_map<std::string, NuPDG> SampleHandlerFD::FileToFinalPDGMap
private

Definition at line 389 of file SampleHandlerFD.h.

◆ FileToInitPDGMap

std::unordered_map<std::string, NuPDG> SampleHandlerFD::FileToInitPDGMap
private

Definition at line 388 of file SampleHandlerFD.h.

◆ FirstTimeW2

bool SampleHandlerFD::FirstTimeW2
protected

KS:Super hacky to update W2 or not.

Definition at line 378 of file SampleHandlerFD.h.

◆ funcParsFuncMap

std::unordered_map<int, FuncParFuncType> SampleHandlerFD::funcParsFuncMap
protected

HH - a map that relates the funcpar enum to pointer of the actual function.

Definition at line 241 of file SampleHandlerFD.h.

◆ funcParsGrid

std::vector<std::vector<int> > SampleHandlerFD::funcParsGrid
protected

HH - a grid of vectors of enums for each sample and event.

Definition at line 243 of file SampleHandlerFD.h.

◆ funcParsMap

std::vector<FunctionalParameter *> SampleHandlerFD::funcParsMap
protected

HH - a map that relates the funcpar enum to pointer of FuncPars struct HH - Changed to a vector of pointers since it's faster than unordered_map and we are using ints as keys.

Definition at line 238 of file SampleHandlerFD.h.

◆ funcParsNamesMap

std::unordered_map<std::string, int> SampleHandlerFD::funcParsNamesMap
protected

HH - a map that relates the name of the functional parameter to funcpar enum.

Definition at line 233 of file SampleHandlerFD.h.

◆ funcParsNamesVec

std::vector<std::string> SampleHandlerFD::funcParsNamesVec = {}
protected

HH - a vector of string names for each functional parameter.

Definition at line 245 of file SampleHandlerFD.h.

◆ funcParsVec

std::vector<FunctionalParameter> SampleHandlerFD::funcParsVec
protected

HH - a vector that stores all the FuncPars struct.

Definition at line 230 of file SampleHandlerFD.h.

◆ KinematicParameters

const std::unordered_map<std::string, int>* SampleHandlerFD::KinematicParameters
protected

Mapping between string and kinematic enum.

Definition at line 349 of file SampleHandlerFD.h.

◆ KinematicVectors

const std::unordered_map<std::string, int>* SampleHandlerFD::KinematicVectors
protected

Definition at line 354 of file SampleHandlerFD.h.

◆ mc_files

std::vector<std::string> SampleHandlerFD::mc_files
protected

names of mc files associated associated with this object

Definition at line 366 of file SampleHandlerFD.h.

◆ MCSamples

std::vector<FarDetectorCoreInfo> SampleHandlerFD::MCSamples
protected

Stores information about every MC event.

Definition at line 317 of file SampleHandlerFD.h.

◆ OscChannels

std::vector<OscChannelInfo> SampleHandlerFD::OscChannels
protected

Stores info about oscillation channel for a single sample.

Definition at line 321 of file SampleHandlerFD.h.

◆ Oscillator

std::shared_ptr<OscillationHandler> SampleHandlerFD::Oscillator
protected

Contains all your binned splines and handles the setup and the returning of weights from spline evaluations.

Definition at line 173 of file SampleHandlerFD.h.

◆ ParHandler

ParameterHandlerGeneric* SampleHandlerFD::ParHandler = nullptr
protected

Definition at line 328 of file SampleHandlerFD.h.

◆ ReversedKinematicParameters

const std::unordered_map<int, std::string>* SampleHandlerFD::ReversedKinematicParameters
protected

Mapping between kinematic enum and string.

Definition at line 351 of file SampleHandlerFD.h.

◆ ReversedKinematicVectors

const std::unordered_map<int, std::string>* SampleHandlerFD::ReversedKinematicVectors
protected

Definition at line 355 of file SampleHandlerFD.h.

◆ SampleDetails

SampleInfo SampleHandlerFD::SampleDetails
protected

Stores info about currently initialised sample.

Definition at line 319 of file SampleHandlerFD.h.

◆ SampleHandlerFD_array

double* SampleHandlerFD::SampleHandlerFD_array
protected

DB Array to be filled after reweighting.

Definition at line 308 of file SampleHandlerFD.h.

◆ SampleHandlerFD_array_w2

double* SampleHandlerFD::SampleHandlerFD_array_w2
protected

KS Array used for MC stat.

Definition at line 310 of file SampleHandlerFD.h.

◆ SampleHandlerFD_data

double* SampleHandlerFD::SampleHandlerFD_data
protected

DB Array to be filled in AddData.

Definition at line 312 of file SampleHandlerFD.h.

◆ SampleManager

std::unique_ptr<manager> SampleHandlerFD::SampleManager
protected

The manager object used to read the sample yaml file.

Definition at line 359 of file SampleHandlerFD.h.

◆ SampleName

std::string SampleHandlerFD::SampleName
protected

A unique ID for each sample based on which we can define what systematic should be applied.

Definition at line 332 of file SampleHandlerFD.h.

◆ Selection

std::vector< KinematicCut > SampleHandlerFD::Selection
protected

a way to store selection cuts which you may push back in the get1DVar functions most of the time this is just the same as StoredSelection

Definition at line 345 of file SampleHandlerFD.h.

◆ spline_files

std::vector<std::string> SampleHandlerFD::spline_files
protected

names of spline files associated associated with this object

Definition at line 368 of file SampleHandlerFD.h.

◆ SplineHandler

std::unique_ptr<BinnedSplineHandler> SampleHandlerFD::SplineHandler
protected

Contains all your binned splines and handles the setup and the returning of weights from spline evaluations.

Definition at line 170 of file SampleHandlerFD.h.

◆ StoredSelection

std::vector< KinematicCut > SampleHandlerFD::StoredSelection
protected

What gets pulled from config options, these are constant after loading in this is of length 3: 0th index is the value, 1st is lower bound, 2nd is upper bound.

Definition at line 342 of file SampleHandlerFD.h.

◆ THStackLeg

TLegend* SampleHandlerFD::THStackLeg = nullptr
protected

DB Miscellaneous Variables.

Definition at line 374 of file SampleHandlerFD.h.

◆ UpdateW2

bool SampleHandlerFD::UpdateW2
protected

KS:Super hacky to update W2 or not.

Definition at line 380 of file SampleHandlerFD.h.


The documentation for this class was generated from the following files: