diff --git a/samplePDF/samplePDFBase.h b/samplePDF/samplePDFBase.h index 1e02a71d8..bc1accd0b 100644 --- a/samplePDF/samplePDFBase.h +++ b/samplePDF/samplePDFBase.h @@ -88,6 +88,15 @@ class samplePDFBase /// @brief CW: Redirect std::cout to silence some experiment specific libraries void NowTalk(); + /// @brief check if event is affected by following conditions, for example pdg, or modes etc + template + bool MatchCondition(const std::vector& allowedValues, const T& value) { + if (allowedValues.empty()) { + return true; // Apply to all if no specific values are specified + } + return std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end(); + } + /// Test statistic tells what kind of likelihood sample is using TestStatistic fTestStatistic; diff --git a/samplePDF/samplePDFFDBase.cpp b/samplePDF/samplePDFFDBase.cpp index e190bcd2b..9b02d38f6 100644 --- a/samplePDF/samplePDFFDBase.cpp +++ b/samplePDF/samplePDFFDBase.cpp @@ -746,13 +746,15 @@ void samplePDFFDBase::SetupNormParameters() { } } +// ************************************************ //A way to check whether a normalisation parameter applies to an event or not -void samplePDFFDBase::CalcXsecNormsBins(int iSample){ +void samplePDFFDBase::CalcXsecNormsBins(int iSample) { +// ************************************************ FarDetectorCoreInfo *fdobj = &MCSamples[iSample]; #ifdef DEBUG std::vector VerboseCounter(xsec_norms.size(), 0); #endif - for(int iEvent=0; iEvent < fdobj->nEvents; ++iEvent){ + for(int iEvent = 0; iEvent < fdobj->nEvents; ++iEvent){ std::vector< int > XsecBins = {}; if (XsecCov) { // Skip oscillated NC events @@ -765,68 +767,28 @@ void samplePDFFDBase::CalcXsecNormsBins(int iSample){ } //DB Abstract check on MaCh3Modes to determine which apply to neutral current for (std::vector::iterator it = xsec_norms.begin(); it != xsec_norms.end(); ++it) { //Now check that the target of an interaction matches with the normalisation parameters - bool TargetMatch = false; - //If no target specified then apply to all modes - if ((*it).targets.size()==0) { - TargetMatch=true; - } else { - for (unsigned iTarget=0;iTarget<(*it).targets.size();iTarget++) { - if ((*it).targets.at(iTarget)== *(fdobj->Target[iEvent])) { - TargetMatch=true; - } - } - } + bool TargetMatch = MatchCondition((*it).targets, *(fdobj->Target[iEvent])); if (!TargetMatch) { MACH3LOG_TRACE("Event {}, missed target check ({}) for dial {}", iEvent, *(fdobj->Target[iEvent]), (*it).name); continue; } //Now check that the neutrino flavour in an interaction matches with the normalisation parameters - bool FlavourMatch=false; - //If no mode specified then apply to all modes - if ((*it).pdgs.size()==0) { - FlavourMatch=true; - } else { - for (unsigned iPDG=0;iPDG<(*it).pdgs.size();iPDG++) { - if ((*it).pdgs.at(iPDG)== (*fdobj->nupdg[iEvent])) { - FlavourMatch=true; - } - } - } + bool FlavourMatch = MatchCondition((*it).pdgs, *(fdobj->nupdg[iEvent])); if (!FlavourMatch) { MACH3LOG_TRACE("Event {}, missed PDG check ({}) for dial {}", iEvent,(*fdobj->nupdg[iEvent]), (*it).name); continue; } //Now check that the unoscillated neutrino flavour in an interaction matches with the normalisation parameters - bool FlavourUnoscMatch=false; - //If no mode specified then apply to all modes - if ((*it).preoscpdgs.size()==0) { - FlavourUnoscMatch=true; - } else { - for (unsigned iPDG=0;iPDG<(*it).preoscpdgs.size();iPDG++) { - if ((*it).preoscpdgs.at(iPDG) == (*fdobj->nupdgUnosc[iEvent])) { - FlavourUnoscMatch=true; - } - } - } + bool FlavourUnoscMatch = MatchCondition((*it).preoscpdgs, *(fdobj->nupdgUnosc[iEvent])); if (!FlavourUnoscMatch){ MACH3LOG_TRACE("Event {}, missed FlavourUnosc check ({}) for dial {}", iEvent,(*fdobj->nupdgUnosc[iEvent]), (*it).name); continue; } //Now check that the mode of an interaction matches with the normalisation parameters - bool ModeMatch=false; - //If no mode specified then apply to all modes - if ((*it).modes.size()==0) { - ModeMatch=true; - } else { - for (unsigned imode=0;imode<(*it).modes.size();imode++) { - if ((*it).modes.at(imode)== *(fdobj->mode[iEvent])) { - ModeMatch=true; - } - } - } + bool ModeMatch = MatchCondition((*it).modes, static_cast(*(fdobj->mode[iEvent]))); if (!ModeMatch) { MACH3LOG_TRACE("Event {}, missed Mode check ({}) for dial {}", iEvent, *(fdobj->mode[iEvent]), (*it).name); continue;