diff --git a/CIValidations/BinningValidations.cpp b/CIValidations/BinningValidations.cpp index 4cffd8f..472a7a0 100755 --- a/CIValidations/BinningValidations.cpp +++ b/CIValidations/BinningValidations.cpp @@ -358,6 +358,11 @@ int main(int argc, char *argv[]) MACH3LOG_CRITICAL("You specified arguments, but none are needed. (Program name: {})", argv[0]); throw MaCh3Exception(__FILE__ , __LINE__ ); } + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); // Open a file in write mode diff --git a/CIValidations/CovarianceValidations.cpp b/CIValidations/CovarianceValidations.cpp index a35d78b..697d48a 100755 --- a/CIValidations/CovarianceValidations.cpp +++ b/CIValidations/CovarianceValidations.cpp @@ -26,6 +26,11 @@ void ValidateCholeskyDecomposition(std::ostream& outFile) { /// @brief This simply updates YAML file void TuneValidations(std::ostream& outFile) { + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); YAML::Node Node = M3OpenConfig(TutorialPath + "/TutorialConfigs/CovObjs/SystematicModel.yaml"); std::vector TuneValues = {1.05, 0.90, 1.10, 1.05, 1.05, 1.05, 1.05, 1.05, 0., 10}; diff --git a/CIValidations/FitterValidations.cpp b/CIValidations/FitterValidations.cpp index 35df8ec..27a4387 100755 --- a/CIValidations/FitterValidations.cpp +++ b/CIValidations/FitterValidations.cpp @@ -6,6 +6,11 @@ void FitVal(const std::string& Algo, bool MoreTests) { + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::string ManagerInput = TutorialPath + "/TutorialConfigs/FitterConfig.yaml"; auto FitManager = std::make_unique(ManagerInput); @@ -71,6 +76,11 @@ void FitVal(const std::string& Algo, bool MoreTests) void StartFromPosteriorTest(const std::string& PreviousName) { + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::string ManagerInput = TutorialPath + "/TutorialConfigs/FitterConfig.yaml"; auto FitManager = std::make_unique(ManagerInput); diff --git a/CIValidations/LLHValidation.cpp b/CIValidations/LLHValidation.cpp index 003ffbd..5eecf19 100755 --- a/CIValidations/LLHValidation.cpp +++ b/CIValidations/LLHValidation.cpp @@ -11,6 +11,11 @@ int main(int argc, char *argv[]) throw MaCh3Exception(__FILE__ , __LINE__ ); } MACH3LOG_INFO("Testing LLH scan"); + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::string command = TutorialPath + "/bin/LLHScanTutorial " + diff --git a/CIValidations/MaCh3ModeValidations.cpp b/CIValidations/MaCh3ModeValidations.cpp index e9fdc5a..1dd2cc4 100755 --- a/CIValidations/MaCh3ModeValidations.cpp +++ b/CIValidations/MaCh3ModeValidations.cpp @@ -47,6 +47,11 @@ int main(int argc, char *argv[]) } MACH3LOG_INFO("Testing MaCh3 Mode"); + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::string ModeInput = TutorialPath + "/TutorialConfigs/MaCh3Modes.yaml"; auto Modes = std::make_unique(ModeInput); diff --git a/CIValidations/SamplePDFValidations.cpp b/CIValidations/SamplePDFValidations.cpp index aaca24f..2271404 100755 --- a/CIValidations/SamplePDFValidations.cpp +++ b/CIValidations/SamplePDFValidations.cpp @@ -9,6 +9,11 @@ _MaCh3_Safe_Include_End_ //} void SharedNuOscTest(const std::string& config, ParameterHandlerGeneric* xsec) { MACH3LOG_INFO("Utilising a shared NuOscillator object between all atmospheric samples"); + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string OscillatorConfig = std::string(std::getenv("MaCh3Tutorial_ROOT")) + "/TutorialConfigs/NuOscillator/CUDAProb3.yaml"; auto OscParams = xsec->GetOscParsFromSampleName("Tutorial_ATM"); auto OscillatorObj = std::make_shared(OscillatorConfig, true, OscParams, 6); @@ -19,6 +24,11 @@ void SharedNuOscTest(const std::string& config, ParameterHandlerGeneric* xsec) { void NoSplinesNoOscTest(const std::string& config){ MACH3LOG_INFO("Utilising a shared NuOscillator object between all atmospheric samples"); + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::vector ParameterMatrixFile = {TutorialPath + "/TutorialConfigs/CovObjs/PCATest.yaml"}; auto xsec = std::make_unique(ParameterMatrixFile, "xsec_cov"); diff --git a/CIValidations/SigmaVarValidation.cpp b/CIValidations/SigmaVarValidation.cpp index a61e501..38e5624 100755 --- a/CIValidations/SigmaVarValidation.cpp +++ b/CIValidations/SigmaVarValidation.cpp @@ -12,6 +12,11 @@ int main(int argc, char *argv[]) throw MaCh3Exception(__FILE__ , __LINE__ ); } MACH3LOG_INFO("Testing Sigma Var"); + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::string command = TutorialPath + "/bin/SigmaVarTutorial " + diff --git a/CIValidations/SplineValidations.cpp b/CIValidations/SplineValidations.cpp index bb0de70..f7cdca7 100755 --- a/CIValidations/SplineValidations.cpp +++ b/CIValidations/SplineValidations.cpp @@ -119,6 +119,11 @@ int main(int argc, char *argv[]) MACH3LOG_CRITICAL("You specified arguments, but none are needed. (Program name: ", argv[0]); throw MaCh3Exception(__FILE__ , __LINE__ ); } + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); // Open a file in write mode diff --git a/CIValidations/pValueValidations.cpp b/CIValidations/pValueValidations.cpp index 0c39832..0686d10 100755 --- a/CIValidations/pValueValidations.cpp +++ b/CIValidations/pValueValidations.cpp @@ -98,6 +98,11 @@ int main(int argc, char *argv[]) MACH3LOG_CRITICAL("You specified arguments, but none are needed. (Program name: {})", argv[0]); throw MaCh3Exception(__FILE__ , __LINE__ ); } + if(!std::getenv("MaCh3Tutorial_ROOT")){ + MACH3LOG_CRITICAL("${MaCh3Tutorial_ROOT} is not defined in the environment," + " have you sourced setup.MaCh3Tutorial.sh? "); + throw MaCh3Exception(__FILE__ , __LINE__ ); + } std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT"); std::vector xsecCovMatrixFile = {TutorialPath + "/TutorialConfigs/CovObjs/SystematicModel.yaml", diff --git a/SamplesTutorial/SampleHandlerTutorial.cpp b/SamplesTutorial/SampleHandlerTutorial.cpp index 0684909..00d8c92 100755 --- a/SamplesTutorial/SampleHandlerTutorial.cpp +++ b/SamplesTutorial/SampleHandlerTutorial.cpp @@ -35,48 +35,32 @@ void SampleHandlerTutorial::Init() { MACH3LOG_INFO("-------------------------------------------------------------------"); } -void SampleHandlerTutorial::DebugShift(const M3::float_t* par, std::size_t iEvent) { - // HH: This is a debug function to shift the reco energy to 4 GeV if the reco energy is less than 2 GeV - if (TutorialSamples[iEvent].RecoEnu < 2.0 && *par != 0) { - TutorialSamples[iEvent].RecoEnu_shifted = 4; +void DebugShift(double const &pval, TutorialMCInfo &ev) { + if (ev.RecoEnu < 2.0 && pval != 0) { + ev.RecoEnu_shifted = 4; } -} - -void SampleHandlerTutorial::EResLep(const M3::float_t* par, std::size_t iEvent) { - // HH: Lepton energy resolution contribution to reco energy - TutorialSamples[iEvent].RecoEnu_shifted += (*par) * TutorialSamples[iEvent].ELep; -} - -void SampleHandlerTutorial::EResTot(const M3::float_t* par, std::size_t iEvent) { - // HH: Total energy resolution contribution to reco energy - TutorialSamples[iEvent].RecoEnu_shifted += (*par) * TutorialSamples[iEvent].RecoEnu; -} +}; +// example using a non-capturing lambda void SampleHandlerTutorial::RegisterFunctionalParameters() { MACH3LOG_INFO("Registering functional parameters"); - // This function manually populates the map of functional parameters - // Maps the name of the functional parameter to the pointer of the function - - // This is the part where we manually enter things - // A lambda function has to be used so we can refer to a non-static member function - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" - RegisterIndividualFunctionalParameter("DebugNothing", - kDebugNothing, - [this](const M3::float_t* par, std::size_t iEvent) {}); - - RegisterIndividualFunctionalParameter("DebugShift", - kDebugShift, - [this](const M3::float_t* par, std::size_t iEvent) { this->DebugShift(par, iEvent); }); - - RegisterIndividualFunctionalParameter("EResLep", - kEResLep, - [this](const M3::float_t* par, std::size_t iEvent) { this->EResLep(par, iEvent); }); - - RegisterIndividualFunctionalParameter("EResTot", - kEResTot, - [this](const M3::float_t* par, std::size_t iEvent) { this->EResTot(par, iEvent); }); - #pragma GCC diagnostic pop + RegisterIndividualFunctionalParameter( + TutorialSamples, "DebugNothing", + [](double const &pval, TutorialMCInfo &ev) {}); + + // example using a free function + RegisterIndividualFunctionalParameter(TutorialSamples, "DebugShift", + DebugShift); + + RegisterIndividualFunctionalParameter( + TutorialSamples, "EResLep", [](double const &pval, TutorialMCInfo &ev) { + ev.RecoEnu_shifted += pval * ev.ELep; + }); + + RegisterIndividualFunctionalParameter( + TutorialSamples, "EResTot", [](double const &pval, TutorialMCInfo &ev) { + ev.RecoEnu_shifted += pval * ev.RecoEnu; + }); } void SampleHandlerTutorial::ResetShifts(const int iEvent) { @@ -325,7 +309,7 @@ double SampleHandlerTutorial::ReturnKinematicParameter(const int KinematicVariab return *paramPointer; } -// === JM Define ReturnKinematicVector functions === +// === JM Define ReturnKinematicVector functions === std::vector SampleHandlerTutorial::ReturnKinematicVector(const int KinematicVector, const int iEvent) const { switch (KinematicVector) { case kParticleEnergy: diff --git a/SamplesTutorial/SampleHandlerTutorial.h b/SamplesTutorial/SampleHandlerTutorial.h index 3fc8b22..a1fcdd7 100755 --- a/SamplesTutorial/SampleHandlerTutorial.h +++ b/SamplesTutorial/SampleHandlerTutorial.h @@ -13,7 +13,7 @@ class SampleHandlerTutorial : public SampleHandlerBase virtual ~SampleHandlerTutorial(); enum KinematicTypes {kTrueNeutrinoEnergy, kTrueQ2, kM3Mode, kTarget, kRecoNeutrinoEnergy, kOscChannel, kTargetNucleus}; - + // === JM enum for particle-level parameters === enum KinematicParticleVecs {kParticleEnergy, kParticlePDG, kParticleBeamAngle}; // ============================================= @@ -31,7 +31,7 @@ class SampleHandlerTutorial : public SampleHandlerBase void CleanMemoryBeforeFit() final; double ReturnKinematicParameter(const int KinematicVariable, const int iEvent) const final; - + // === JM ReturnKinematicVector declarations for particle-level parameters === void FillParticles(int eventIndex, int nParticles, int PDGLep, double ELep, std::mt19937& gen); std::vector ReturnKinematicVector(const int KinematicVector, const int iEvent) const final; @@ -64,7 +64,7 @@ class SampleHandlerTutorial : public SampleHandlerBase {kRecoNeutrinoEnergy, "RecoNeutrinoEnergy"}, {kOscChannel, "OscillationChannel"}, }; - + // === JM maps for particle-level parameters === const std::unordered_map KinematicVectorsTutorial = { {"ParticleEnergy", kParticleEnergy}, @@ -86,9 +86,5 @@ class SampleHandlerTutorial : public SampleHandlerBase enum FuncParEnum {kDebugNothing, kDebugShift, kEResLep, kEResTot}; void RegisterFunctionalParameters() final; void ResetShifts(const int iEvent) final; - - void DebugShift(const M3::float_t* par, std::size_t iEvent); - void EResLep(const M3::float_t* par, std::size_t iEvent); - void EResTot(const M3::float_t* par, std::size_t iEvent); // ================================= };