MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
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.
 
virtual ~OscillationHandler ()
 Destructor.
 
bool isEqualBinningPerOscChannel ()
 check if same binning is used for multiple oscillation channels
 
void Evaluate ()
 DB Evaluate oscillation weights for each defined event/bin.
 
const M3::float_tGetNuOscillatorPointers (int Channel, int InitFlav, int FinalFlav, FLOAT_T TrueEnu, FLOAT_T TrueCosZenith=-999)
 Get pointer to oscillation weight.
 
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.
 
unsigned int GetOscParamsSize () const
 return size of oscillation parameter pointer vector
 

Private Attributes

bool EqualBinningPerOscChannel
 flag used to define whether all oscillation channels have a probability calculated using the same binning
 
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 hand for speed
 

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 make no difference

Definition at line 9 of file OscillationHandler.cpp.

10 {
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 iSample = 0; iSample < SubChannels; iSample++) {
37 MACH3LOG_INFO("Setting up NuOscillator::Oscillator object in OscillationChannel: {}/{}", iSample, SubChannels);
38
39 LoggerPrint("NuOscillator",
40 [](const std::string& message) { MACH3LOG_INFO("{}", message); },
41 [this, iSample, &OscillFactory, &NuOscillatorConfigFile]() {
42 this->NuOscProbCalcers[iSample] = std::unique_ptr<OscillatorBase>(
43 OscillFactory->CreateOscillator(NuOscillatorConfigFile));
44 });
45 }
46 }
47}
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:25
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:23
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:67
Custom exception class for MaCh3 errors.
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 50 of file OscillationHandler.cpp.

50 {
51// ************************************************
52
53}

Member Function Documentation

◆ Evaluate()

void OscillationHandler::Evaluate ( )

DB Evaluate oscillation weights for each defined event/bin.

Definition at line 56 of file OscillationHandler.cpp.

56 {
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}
double float_t
Definition: Core.h:28

◆ GetNuOscillatorPointers()

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

Get pointer to oscillation weight.

Definition at line 77 of file OscillationHandler.cpp.

77 {
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}

◆ GetOscParamsSize()

unsigned int OscillationHandler::GetOscParamsSize ( ) const
inline

return size of oscillation parameter pointer vector

Definition at line 35 of file OscillationHandler.h.

35{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 25 of file OscillationHandler.h.

◆ SetOscillatorBinning()

void OscillationHandler::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.

Definition at line 93 of file OscillationHandler.cpp.

93 {
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}

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 38 of file OscillationHandler.h.

◆ NuOscProbCalcers

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

DB Variables required for oscillation.

Definition at line 41 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 44 of file OscillationHandler.h.


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