MaCh3  2.2.3
Reference Guide
OscillationHandler.cpp
Go to the documentation of this file.
1 #include "OscillationHandler.h"
2 
4 #include "Oscillator/OscillatorFactory.h"
5 #include "Constants/OscillatorConstants.h"
7 
8 // ************************************************
9 OscillationHandler::OscillationHandler(const std::string& NuOscillatorConfigFile, bool BinningPerOscChannel_,
10  std::vector<const double*> OscParams_, const int SubChannels) {
11 // ************************************************
12  EqualBinningPerOscChannel = BinningPerOscChannel_;
13  OscParams = OscParams_;
14  auto OscillFactory = std::make_unique<OscillatorFactory>();
15 
16  //DB's explanation of EqualBinningPerOscChannel:
17  //In the situation where we are applying binning oscillation probabilities to a SampleHandler object, it maybe the case that there is identical binning per oscillation channel
18  //In which case, and remembering that each NuOscillator::Oscillator object calculate the oscillation probabilities for all channels, we just have to create one Oscillator object and use the results from that
19  //This means that we can get up to a factor of 12 reduction in the calculation time of the oscillation probabilities, because we don't need to repeat the operation per oscillation channel
20 
22  NuOscProbCalcers.resize(1);
23  LoggerPrint("NuOscillator",
24  [](const std::string& message) { MACH3LOG_INFO("{}", message); },
25  [this, &OscillFactory, &NuOscillatorConfigFile]() {
26  this->NuOscProbCalcers[0] = std::unique_ptr<OscillatorBase>(OscillFactory->CreateOscillator(NuOscillatorConfigFile));
27  });
28 
29  if (!NuOscProbCalcers[0]->EvalPointsSetInConstructor()) {
30  MACH3LOG_ERROR("Attempted to use equal binning per oscillation channel, but not binning has been set in the NuOscillator::Oscillator object");
31  throw MaCh3Exception(__FILE__, __LINE__);
32  }
33  NuOscProbCalcers[0]->Setup();
34  } else {
35  NuOscProbCalcers.resize(SubChannels);
36  for (int iChannel = 0; iChannel < SubChannels; iChannel++) {
37  MACH3LOG_INFO("Setting up NuOscillator::Oscillator object in OscillationChannel: {}/{}", iChannel, SubChannels);
38 
39  LoggerPrint("NuOscillator",
40  [](const std::string& message) { MACH3LOG_INFO("{}", message); },
41  [this, iChannel, &OscillFactory, &NuOscillatorConfigFile]() {
42  this->NuOscProbCalcers[iChannel] = std::unique_ptr<OscillatorBase>(
43  OscillFactory->CreateOscillator(NuOscillatorConfigFile));
44  });
45  }
46  }
47 }
48 
49 // ************************************************
51 // ************************************************
52 
53 }
54 
55 // ************************************************
57 // ************************************************
58  std::vector<M3::float_t> OscVec(OscParams.size());
59  for (size_t iPar = 0; iPar < OscParams.size(); ++iPar) {
60  #pragma GCC diagnostic push
61  #pragma GCC diagnostic ignored "-Wuseless-cast"
62  OscVec[iPar] = static_cast<M3::float_t>(*OscParams[iPar]);
63  #pragma GCC diagnostic pop
64  }
65 
67  NuOscProbCalcers[0]->CalculateProbabilities(OscVec);
68  } else {
69  for (size_t iChannel = 0; iChannel < NuOscProbCalcers.size(); iChannel++) {
70  NuOscProbCalcers[iChannel]->CalculateProbabilities(OscVec);
71  }
72  }
73 }
74 
75 
76 // ************************************************
77 const M3::float_t* OscillationHandler::GetNuOscillatorPointers(int Channel, int InitFlav, int FinalFlav, FLOAT_T TrueEnu, FLOAT_T TrueCosZenith) {
78 // ************************************************
79  int Index = 0;
81  Index = Channel;
82  }
83 
84  if(TrueCosZenith != -999) {
85  return NuOscProbCalcers[Index]->ReturnWeightPointer(InitFlav ,FinalFlav, TrueEnu, TrueCosZenith);
86  } else {
87  return NuOscProbCalcers[Index]->ReturnWeightPointer(InitFlav ,FinalFlav, TrueEnu);
88  }
89 }
90 
91 
92 // ************************************************
93 void OscillationHandler::SetOscillatorBinning(const int Channel, const std::vector<M3::float_t>& EnergyArray, const std::vector<M3::float_t>& CosineZArray) {
94 // ************************************************
95  if (!NuOscProbCalcers[Channel]->EvalPointsSetInConstructor()) {
96  NuOscProbCalcers[Channel]->SetEnergyArrayInCalcer(EnergyArray);
97  if(CosineZArray.size() != 0) NuOscProbCalcers[Channel]->SetCosineZArrayInCalcer(CosineZArray);
98  }
99  NuOscProbCalcers[Channel]->Setup();
100 }
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:109
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
Definition: Core.h:120
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25
void LoggerPrint(const std::string &LibName, LogFunc logFunction, Func &&func, Args &&... args)
KS: This is bit convoluted but this is to allow redirecting cout and errors from external library int...
Definition: MaCh3Logger.h:90
Custom exception class for MaCh3 errors.
void Evaluate()
DB Evaluate oscillation weights for each defined event/bin.
virtual ~OscillationHandler()
Destructor.
OscillationHandler(const std::string &ConfigFile, bool EqualBinningPerChannel, std::vector< const double * > OscParams_, const int SubChannels)
Constructor.
const M3::float_t * GetNuOscillatorPointers(int Channel, int InitFlav, int FinalFlav, FLOAT_T TrueEnu, FLOAT_T TrueCosZenith=-999)
Get pointer to oscillation weight.
std::vector< std::unique_ptr< OscillatorBase > > NuOscProbCalcers
DB Variables required for oscillation.
void SetOscillatorBinning(const int Channel, const std::vector< M3::float_t > &EnergyArray, const std::vector< M3::float_t > &CosineZArray)
Setup binning, arrays correspond to events and their energy bins.
std::vector< const double * > OscParams
pointer to osc params, since not all params affect every sample, we perform some operations before ha...
bool EqualBinningPerOscChannel
flag used to define whether all oscillation channels have a probability calculated using the same bin...
double float_t
Definition: Core.h:30