MaCh3  2.4.2
Reference Guide
Public Member Functions | Private Attributes | List of all members
OscillationHandler Class Reference

Interface between NuOscillator and MaCh3, meant to compute oscillation weights for events/bin. More...

#include <Samples/OscillationHandler.h>

Collaboration diagram for OscillationHandler:
[legend]

Public Member Functions

 OscillationHandler (const std::string &ConfigFile, bool EqualBinningPerChannel, std::vector< const double * > OscParams_, const int SubChannels)
 Constructor. More...
 
virtual ~OscillationHandler ()
 Destructor. More...
 
void AddSample (const std::string &NuOscillatorConfigFile, const int SubChannels)
 Add different oscillator for sample. More...
 
bool isEqualBinningPerOscChannel ()
 check if same binning is used for multiple oscillation channels More...
 
void Evaluate ()
 DB Evaluate oscillation weights for each defined event/bin. More...
 
const M3::float_tGetNuOscillatorPointers (const int Sample, const int Channel, const int InitFlav, const int FinalFlav, const FLOAT_T TrueEnu, const FLOAT_T TrueCosZenith=-999)
 Get pointer to oscillation weight. More...
 
void SetOscillatorBinning (const int Sample, 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. More...
 
unsigned int GetOscParamsSize () const
 return size of oscillation parameter pointer vector More...
 

Private Attributes

bool EqualBinningPerOscChannel
 flag used to define whether all oscillation channels have a probability calculated using the same binning More...
 
std::vector< std::vector< std::unique_ptr< OscillatorBase > > > NuOscProbCalcers
 DB Variables required for oscillation. More...
 
std::vector< const double * > OscParams
 pointer to osc params, since not all params affect every sample, we perform some operations before hand for speed More...
 

Detailed Description

Interface between NuOscillator and MaCh3, meant to compute oscillation weights for events/bin.

Author
Dan Barrow

Definition at line 11 of file OscillationHandler.h.

Constructor & Destructor Documentation

◆ OscillationHandler()

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ OscillationHandler::OscillationHandler ( const std::string &  ConfigFile,
bool  EqualBinningPerChannel,
std::vector< const double * >  OscParams_,
const int  SubChannels 
)

Constructor.

Parameters
ConfigFilename/path to NuOscillator Config
EqualBinningPerChannelwhether to use same binning per each oscillation channel
OscParams_Pointers to values of oscillation parameters
SubChannelsNumber of oscillation channels
Warning
If EqualBinningPerChannel is true then argument SubChannels makes no difference

Definition at line 9 of file OscillationHandler.cpp.

10  {
11 // ************************************************
12  EqualBinningPerOscChannel = BinningPerOscChannel_;
13  OscParams = OscParams_;
14  // Add first sample
15  NuOscProbCalcers.resize(1);
16 
17  auto OscillFactory = std::make_unique<OscillatorFactory>();
18  //DB's explanation of EqualBinningPerOscChannel:
19  //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
20  //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
21  //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
22 
24  NuOscProbCalcers[0].resize(1);
25  LoggerPrint("NuOscillator",
26  [](const std::string& message) { MACH3LOG_INFO("{}", message); },
27  [this, &OscillFactory, &NuOscillatorConfigFile]() {
28  this->NuOscProbCalcers[0][0] = std::unique_ptr<OscillatorBase>(OscillFactory->CreateOscillator(NuOscillatorConfigFile));
29  });
30 
31  if (!NuOscProbCalcers[0][0]->EvalPointsSetInConstructor()) {
32  MACH3LOG_ERROR("Attempted to use equal binning per oscillation channel, but not binning has been set in the NuOscillator::Oscillator object");
33  throw MaCh3Exception(__FILE__, __LINE__);
34  }
35  NuOscProbCalcers[0][0]->Setup();
36  } else {
37  NuOscProbCalcers[0].resize(SubChannels);
38  for (int iChannel = 0; iChannel < SubChannels; iChannel++) {
39  MACH3LOG_INFO("Setting up NuOscillator::Oscillator object in OscillationChannel: {}/{}", iChannel, SubChannels);
40 
41  LoggerPrint("NuOscillator",
42  [](const std::string& message) { MACH3LOG_INFO("{}", message); },
43  [this, iChannel, &OscillFactory, &NuOscillatorConfigFile]() {
44  this->NuOscProbCalcers[0][iChannel] = std::unique_ptr<OscillatorBase>(
45  OscillFactory->CreateOscillator(NuOscillatorConfigFile));
46  });
47  }
48  }
49 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
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:100
Custom exception class used throughout MaCh3.
std::vector< std::vector< std::unique_ptr< OscillatorBase > > > NuOscProbCalcers
DB Variables required for oscillation.
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...

◆ ~OscillationHandler()

OscillationHandler::~OscillationHandler ( )
virtual

Destructor.

Definition at line 52 of file OscillationHandler.cpp.

52  {
53 // ************************************************
54 }

Member Function Documentation

◆ AddSample()

void OscillationHandler::AddSample ( const std::string &  NuOscillatorConfigFile,
const int  SubChannels 
)

Add different oscillator for sample.

Definition at line 57 of file OscillationHandler.cpp.

57  {
58 // ************************************************
60  MACH3LOG_ERROR("Trying to add sample while EqualBinningPerOscChannel is enabled. This will not work...");
61  throw MaCh3Exception(__FILE__, __LINE__);
62  }
63  auto OscillFactory = std::make_unique<OscillatorFactory>();
64 
65  std::vector<std::unique_ptr<OscillatorBase>> OscProbCalcersTemp(SubChannels);
66 
67  for (int iChannel = 0; iChannel < SubChannels; iChannel++) {
68  MACH3LOG_INFO("Setting up NuOscillator::Oscillator object in OscillationChannel: {}/{}", iChannel, SubChannels);
69 
70  LoggerPrint("NuOscillator",
71  [](const std::string& message) { MACH3LOG_INFO("{}", message); },
72  [&OscProbCalcersTemp, iChannel, &OscillFactory, &NuOscillatorConfigFile]() {
73  OscProbCalcersTemp[iChannel] = std::unique_ptr<OscillatorBase>(
74  OscillFactory->CreateOscillator(NuOscillatorConfigFile));
75  });
76  }
77  NuOscProbCalcers.push_back(std::move(OscProbCalcersTemp));
78 }

◆ Evaluate()

void OscillationHandler::Evaluate ( )

DB Evaluate oscillation weights for each defined event/bin.

Definition at line 81 of file OscillationHandler.cpp.

81  {
82 // ************************************************
83  std::vector<M3::float_t> OscVec(OscParams.size());
84  for (size_t iPar = 0; iPar < OscParams.size(); ++iPar) {
85  #pragma GCC diagnostic push
86  #pragma GCC diagnostic ignored "-Wuseless-cast"
87  OscVec[iPar] = static_cast<M3::float_t>(*OscParams[iPar]);
88  #pragma GCC diagnostic pop
89  }
90 
92  NuOscProbCalcers[0][0]->CalculateProbabilities(OscVec);
93  } else {
94  for (size_t iSample = 0; iSample < NuOscProbCalcers.size(); iSample++) {
95  for (size_t iChannel = 0; iChannel < NuOscProbCalcers[iSample].size(); iChannel++) {
96  NuOscProbCalcers[iSample][iChannel]->CalculateProbabilities(OscVec);
97  }
98  }
99  }
100 }
double float_t
Definition: Core.h:37

◆ GetNuOscillatorPointers()

const M3::float_t * OscillationHandler::GetNuOscillatorPointers ( const int  Sample,
const int  Channel,
const int  InitFlav,
const int  FinalFlav,
const FLOAT_T  TrueEnu,
const FLOAT_T  TrueCosZenith = -999 
)

Get pointer to oscillation weight.

Definition at line 104 of file OscillationHandler.cpp.

105  {
106 // ************************************************
107  int IndexSample = 0;
108  int IndexChannel = 0;
110  IndexSample = Sample;
111  IndexChannel = Channel;
112  }
113 
114  if(TrueCosZenith != -999) {
115  return NuOscProbCalcers[IndexSample][IndexChannel]->ReturnWeightPointer(InitFlav ,FinalFlav, TrueEnu, TrueCosZenith);
116  } else {
117  return NuOscProbCalcers[IndexSample][IndexChannel]->ReturnWeightPointer(InitFlav ,FinalFlav, TrueEnu);
118  }
119 }

◆ GetOscParamsSize()

unsigned int OscillationHandler::GetOscParamsSize ( ) const
inline

return size of oscillation parameter pointer vector

Definition at line 41 of file OscillationHandler.h.

41 {return static_cast<unsigned int>(OscParams.size());};

◆ isEqualBinningPerOscChannel()

bool OscillationHandler::isEqualBinningPerOscChannel ( )
inline

check if same binning is used for multiple oscillation channels

Definition at line 29 of file OscillationHandler.h.

◆ SetOscillatorBinning()

void OscillationHandler::SetOscillatorBinning ( const int  Sample,
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.

Definition at line 123 of file OscillationHandler.cpp.

124  {
125 // ************************************************
126  if (!NuOscProbCalcers[Sample][Channel]->EvalPointsSetInConstructor()) {
127  NuOscProbCalcers[Sample][Channel]->SetEnergyArrayInCalcer(EnergyArray);
128  if(CosineZArray.size() != 0) NuOscProbCalcers[Sample][Channel]->SetCosineZArrayInCalcer(CosineZArray);
129  }
130  NuOscProbCalcers[Sample][Channel]->Setup();
131 }

Member Data Documentation

◆ EqualBinningPerOscChannel

bool OscillationHandler::EqualBinningPerOscChannel
private

flag used to define whether all oscillation channels have a probability calculated using the same binning

Definition at line 44 of file OscillationHandler.h.

◆ NuOscProbCalcers

std::vector<std::vector<std::unique_ptr<OscillatorBase> > > OscillationHandler::NuOscProbCalcers
private

DB Variables required for oscillation.

Definition at line 47 of file OscillationHandler.h.

◆ OscParams

std::vector<const double*> OscillationHandler::OscParams
private

pointer to osc params, since not all params affect every sample, we perform some operations before hand for speed

Definition at line 50 of file OscillationHandler.h.


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