diff --git a/src/Reweight/NUISANCEWeightEngine.cxx b/src/Reweight/NUISANCEWeightEngine.cxx index 0ccf97a..033ed0c 100644 --- a/src/Reweight/NUISANCEWeightEngine.cxx +++ b/src/Reweight/NUISANCEWeightEngine.cxx @@ -1,128 +1,137 @@ #include "NUISANCEWeightEngine.h" #include "NUISANCEWeightCalcs.h" #ifdef __MINERVA_RW_ENABLED__ #ifdef __GENIE_ENABLED__ #include "MINERvAWeightCalcs.h" #endif #endif NUISANCEWeightEngine::NUISANCEWeightEngine(std::string name) { // Setup the NUISANCE Reweight engine fCalcName = name; NUIS_LOG(FIT, "Setting up NUISANCE Custom RW : " << fCalcName); // Load in all Weight Calculations GaussianModeCorr *GaussianMode = new GaussianModeCorr(); std::string Gaussian_Method = FitPar::Config().GetParS("Gaussian_Enhancement"); if (Gaussian_Method == "Tilt-Shift") { GaussianMode->SetMethod(true); } else if (Gaussian_Method == "Normal") { GaussianMode->SetMethod(false); } else { NUIS_ABORT("I do not recognise method " << Gaussian_Method << " for the Gaussian enhancement, so will die now..."); } fWeightCalculators.push_back(GaussianMode); fWeightCalculators.push_back(new ModeNormCalc()); fWeightCalculators.push_back(new SBLOscWeightCalc()); fWeightCalculators.push_back(new BeRPACalc()); #ifdef __MINERVA_RW_ENABLED__ #ifdef __GENIE_ENABLED__ fWeightCalculators.push_back(new nuisance::reweight::MINERvAReWeight_QE()); fWeightCalculators.push_back(new nuisance::reweight::MINERvAReWeight_MEC()); fWeightCalculators.push_back(new nuisance::reweight::MINERvAReWeight_RES()); fWeightCalculators.push_back(new nuisance::reweight::MINOSRPA()); fWeightCalculators.push_back(new nuisance::reweight::LagrangeRPA()); fWeightCalculators.push_back(new nuisance::reweight::RikRPA()); fWeightCalculators.push_back(new nuisance::reweight::COHBrandon()); fWeightCalculators.push_back(new nuisance::reweight::WEnhancement()); #endif #endif // Set Abs Twk Config fIsAbsTwk = true; }; void NUISANCEWeightEngine::IncludeDial(std::string name, double startval) { // Get First enum int nuisenum = Reweight::ConvDial(name, kCUSTOM); // Setup Maps fEnumIndex[nuisenum]; // = std::vector(0); fNameIndex[name]; // = std::vector(0); // Split by commas std::vector allnames = GeneralUtils::ParseToStr(name, ","); for (uint i = 0; i < allnames.size(); i++) { std::string singlename = allnames[i]; // Get RW int singleenum = Reweight::ConvDial(singlename, kCUSTOM); // Fill Maps int index = fValues.size(); fValues.push_back(0.0); fNUISANCEEnums.push_back(singleenum); // Initialize dial NUIS_LOG(FIT, "Registering " << singlename << " from " << name); // Setup index fEnumIndex[nuisenum].push_back(index); fNameIndex[name].push_back(index); } // Set Value if given if (startval != _UNDEF_DIAL_VALUE_) { SetDialValue(nuisenum, startval); } }; void NUISANCEWeightEngine::SetDialValue(int nuisenum, double val) { std::vector indices = fEnumIndex[nuisenum]; for (uint i = 0; i < indices.size(); i++) { fValues[indices[i]] = val; } } void NUISANCEWeightEngine::SetDialValue(std::string name, double val) { std::vector indices = fNameIndex[name]; for (uint i = 0; i < indices.size(); i++) { fValues[indices[i]] = val; } } void NUISANCEWeightEngine::Reconfigure(bool silent) { for (size_t i = 0; i < fNUISANCEEnums.size(); i++) { + // Is this parameter handled + bool IsHandledSomewhere = false; for (std::vector::iterator calciter = fWeightCalculators.begin(); calciter != fWeightCalculators.end(); calciter++) { NUISANCEWeightCalc *nuiscalc = static_cast(*calciter); if (nuiscalc->IsHandled(fNUISANCEEnums[i])) { nuiscalc->SetDialValue(fNUISANCEEnums[i], fValues[i]); + IsHandledSomewhere = true; } } - } -} + + // Check if this parameter is actually handled + if (!IsHandledSomewhere) { + std::string name = GetNameFromEnum(i); + NUIS_ABORT("NUISANCE parameter " << name << " (enum " << i << ") not enabled, can not continue!"); + } // End check of it's handled + } // End loop over enums +} // Return double NUISANCEWeightEngine::CalcWeight(BaseFitEvt *evt) { double rw_weight = 1.0; // Cast as usable class for (std::vector::iterator iter = fWeightCalculators.begin(); iter != fWeightCalculators.end(); iter++) { NUISANCEWeightCalc *nuiscalc = static_cast(*iter); rw_weight *= nuiscalc->CalcWeight(evt); } // Return rw_weight return rw_weight; } diff --git a/src/Reweight/WeightEngineBase.cxx b/src/Reweight/WeightEngineBase.cxx index ef04e5a..0b3dded 100644 --- a/src/Reweight/WeightEngineBase.cxx +++ b/src/Reweight/WeightEngineBase.cxx @@ -1,23 +1,48 @@ #include "WeightEngineBase.h" bool WeightEngineBase::IsDialIncluded(std::string name) { return (fNameIndex.find(name) != fNameIndex.end()); } bool WeightEngineBase::IsDialIncluded(int nuisenum) { return (fEnumIndex.find(nuisenum) != fEnumIndex.end()); } double WeightEngineBase::GetDialValue(std::string name) { if (!IsDialIncluded(name)) { NUIS_ABORT("Dial " << name << " not included in " << fCalcName); } return fValues[fNameIndex[name][0]]; } double WeightEngineBase::GetDialValue(int nuisenum) { if (!IsDialIncluded(nuisenum)) { NUIS_ABORT("Dial Enum " << nuisenum << " not included in " << fCalcName); } return fValues[fEnumIndex[nuisenum][0]]; } + +std::string WeightEngineBase::GetNameFromEnum(int nuisenum) { + + // Find the name in the map; need to iterate through the map + for (std::map >::iterator it = fNameIndex.begin(); it!=fNameIndex.end(); ++it) { + std::string name = (*it).first; + std::vector Enums = (*it).second; + bool found = false; + for (std::vector::iterator EnumIt = Enums.begin(); EnumIt != Enums.end(); ++EnumIt) { + size_t Enum = (*EnumIt); + if (Enum == (size_t)nuisenum) { + found = true; + break; + } + } + if (found) { + return name; + } + } // Finish looping over the map + + NUIS_ABORT("Could not find a matching name for parameter enum " << nuisenum); + + return std::string("EMPTY"); + +} diff --git a/src/Reweight/WeightEngineBase.h b/src/Reweight/WeightEngineBase.h index dbec387..5a6e6cf 100644 --- a/src/Reweight/WeightEngineBase.h +++ b/src/Reweight/WeightEngineBase.h @@ -1,54 +1,56 @@ #ifndef WEIGHTENGINE_BASE_H #define WEIGHTENGINE_BASE_H #include "BaseFitEvt.h" #include "FitLogger.h" #include "FitUtils.h" #include #include #include #include #include #include #include #include #include #include #include #define _UNDEF_DIAL_VALUE_ -9999.9 class WeightEngineBase { public: WeightEngineBase(){}; virtual ~WeightEngineBase(){}; // Functions requiring Override virtual void IncludeDial(std::string name, double startval){}; virtual void SetDialValue(int nuisenum, double val){}; virtual void SetDialValue(std::string name, double val){}; virtual bool IsDialIncluded(std::string name); virtual bool IsDialIncluded(int nuisenum); virtual double GetDialValue(std::string name); virtual double GetDialValue(int nuisenum); virtual void Reconfigure(bool silent){}; virtual double CalcWeight(BaseFitEvt* evt) { return 1.0; }; virtual bool NeedsEventReWeight() = 0; + std::string GetNameFromEnum(int nuisenum); + bool fHasChanged; bool fIsAbsTwk; std::vector fValues; std::map > fEnumIndex; std::map > fNameIndex; std::string fCalcName; }; #endif