diff --git a/cmake/c++CompilerSetup.cmake b/cmake/c++CompilerSetup.cmake index 89a51eb..266b708 100644 --- a/cmake/c++CompilerSetup.cmake +++ b/cmake/c++CompilerSetup.cmake @@ -1,108 +1,109 @@ # Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ if(USE_OMP) LIST(APPEND EXTRA_CXX_FLAGS -fopenmp) endif() if(USE_DYNSAMPLES) LIST(APPEND EXTRA_LIBS dl) LIST(APPEND EXTRA_CXX_FLAGS -D__USE_DYNSAMPLES__) endif() set(CXX_WARNINGS -Wall ) cmessage(DEBUG "EXTRA_CXX_FLAGS: ${EXTRA_CXX_FLAGS}") string(REPLACE ";" " " STR_EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STR_EXTRA_CXX_FLAGS} ${CXX_WARNINGS}") - + set(CMAKE_Fortran_FLAGS_RELEASE "-fPIC") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") if(USE_DYNSAMPLES) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC") + set(CMAKE_Fortran_FLAGS_DEBUG "-fPIC") endif() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC -O3") if(CMAKE_BUILD_TYPE MATCHES DEBUG) set(CURRENT_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}) elseif(CMAKE_BUILD_TYPE MATCHES RELEASE) set(CURRENT_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE}) else() cmessage(FATAL_ERROR "[ERROR]: Unknown CMAKE_BUILD_TYPE (\"${CMAKE_BUILD_TYPE}\"): Should be \"DEBUG\" or \"RELEASE\".") endif() SET(STR_EXTRA_LINK_DIRS) if(NOT EXTRA_LINK_DIRS STREQUAL "") string(REPLACE ";" " -L" STR_EXTRA_LINK_DIRS "-L${EXTRA_LINK_DIRS}") endif() SET(STR_EXTRA_LIBS) if(NOT EXTRA_LIBS STREQUAL "") string(REPLACE ";" " -l" STR_EXTRA_LIBS "-l${EXTRA_LIBS}") endif() SET(STR_EXTRA_SHAREDOBJS) if(NOT EXTRA_SHAREDOBJS STREQUAL "") string(REPLACE ";" " " STR_EXTRA_SHAREDOBJS "${EXTRA_SHAREDOBJS}") endif() SET(STR_EXTRA_LINK_FLAGS) if(NOT EXTRA_LINK_FLAGS STREQUAL "") string(REPLACE ";" " " STR_EXTRA_LINK_FLAGS "${EXTRA_LINK_FLAGS}") endif() cmessage(DEBUG "EXTRA_LINK_DIRS: ${STR_EXTRA_LINK_DIRS}") cmessage(DEBUG "EXTRA_LIBS: ${STR_EXTRA_LIBS}") cmessage(DEBUG "EXTRA_SHAREDOBJS: ${STR_EXTRA_SHAREDOBJS}") cmessage(DEBUG "EXTRA_LINK_FLAGS: ${STR_EXTRA_LINK_FLAGS}") if(NOT STR_EXTRA_LINK_DIRS STREQUAL "" AND NOT STR_EXTRA_LIBS STREQUAL "") SET(CMAKE_DEPENDLIB_FLAGS "${STR_EXTRA_LINK_DIRS} ${STR_EXTRA_LIBS}") endif() if(NOT EXTRA_SHAREDOBJS STREQUAL "") if(NOT STR_EXTRA_LINK_FLAGS STREQUAL "") SET(STR_EXTRA_LINK_FLAGS "${STR_EXTRA_SHAREDOBJS} ${STR_EXTRA_LINK_FLAGS}") else() SET(STR_EXTRA_LINK_FLAGS "${STR_EXTRA_SHAREDOBJS}") endif() endif() if(NOT EXTRA_LINK_FLAGS STREQUAL "") if(NOT CMAKE_LINK_FLAGS STREQUAL "") SET(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${STR_EXTRA_LINK_FLAGS}") else() SET(CMAKE_LINK_FLAGS "${STR_EXTRA_LINK_FLAGS}") endif() endif() if(USE_OMP) cmessage(FATAL_ERROR "No OMP features currently enabled so this is a FATAL_ERROR to let you know that you don't gain anything with this declaration.") endif() if (VERBOSE) cmessage (STATUS "C++ Compiler : ${CXX_COMPILER_NAME}") cmessage (STATUS " flags : ${CMAKE_CXX_FLAGS}") cmessage (STATUS " Release flags : ${CMAKE_CXX_FLAGS_RELEASE}") cmessage (STATUS " Debug flags : ${CMAKE_CXX_FLAGS_DEBUG}") cmessage (STATUS " Link Flags : ${CMAKE_LINK_FLAGS}") cmessage (STATUS " Lib Flags : ${CMAKE_DEPENDLIB_FLAGS}") endif() diff --git a/src/InputHandler/InputTypes.h b/src/InputHandler/InputTypes.h index 89215cd..7a78145 100644 --- a/src/InputHandler/InputTypes.h +++ b/src/InputHandler/InputTypes.h @@ -1,164 +1,160 @@ // Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret /******************************************************************************* * This file is part of NUISANCE. * * NUISANCE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NUISANCE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NUISANCE. If not, see . *******************************************************************************/ #ifndef INPUTTYPES_SEEN_H #define INPUTTYPES_SEEN_H /// Global Enum to define generator type being read with FitEvent /// Have to define kNORM as if its a generator for the time being. enum generator_event_type { kUNKNOWN = 999, kNEUT = 0, kNIWG = 1, kNUWRO = 2, kT2K = 3, kCUSTOM = 4, kGENIE = 5, kEVTSPLINE = 6, kNUANCE = 7, kGiBUU = 8, kNORM = 9, - kMODENORM = 10, - kEMPTY = 11, - kINPUTFITEVENT = 12, - kNEWSPLINE = 13, - kLIKEWEIGHT = 14, - kSPLINEPARAMETER = 15, - kHEPMC = 16, - kHISTO = 17, - kSIGMAQ0HIST = 18, + kEMPTY = 10, + kINPUTFITEVENT = 11, + kNEWSPLINE = 12, + kLIKEWEIGHT = 13, + kSPLINEPARAMETER = 14, + kHEPMC = 15, + kHISTO = 16, + kSIGMAQ0HIST = 17, kLast_generator_event_type }; namespace InputUtils { enum InputType { kNEUT_Input = 0, kNUWRO_Input = 1, kGENIE_Input = 2, kGiBUU_Input, kNUANCE_Input, kEVSPLN_Input, kEMPTY_Input, kFEVENT_Input, kJOINT_Input, kSIGMAQ0HIST_Input, kHISTO_Input, kInvalid_Input, kBNSPLN_Input, // Not sure if this are currently used. }; } inline std::ostream& operator<<(std::ostream& os, generator_event_type const& gs) { switch (gs) { case kUNKNOWN: { return os << "kUNKNOWN"; } case kNEUT: { return os << "kNEUT"; } case kNIWG: { return os << "kNIWG"; } case kNUWRO: { return os << "kNUWRO"; } case kT2K: { return os << "kT2K"; } case kCUSTOM: { return os << "kCUSTOM"; } case kGENIE: { return os << "kGENIE"; } case kEVTSPLINE: { return os << "kEVTSPLINE"; } case kNUANCE: { return os << "kNUANCE"; } case kGiBUU: { return os << "kGiBUU"; } case kNORM: { return os << "kNORM"; } - case kMODENORM: { - return os << "kMODENORM"; - } case kHEPMC: { return os << "kHEPMC"; } case kSIGMAQ0HIST: { return os << "kSIGMAQ0HIST"; } case kHISTO: { return os << "kHISTO"; } default: { return os << "kUNKNOWN"; } } } inline std::ostream &operator<<(std::ostream &os, InputUtils::InputType it) { switch (it) { case InputUtils::kNEUT_Input: { return os << "kNEUT_Input"; } case InputUtils::kNUWRO_Input: { return os << "kNUWRO_Input"; } case InputUtils::kGENIE_Input: { return os << "kGENIE_Input"; } case InputUtils::kGiBUU_Input: { return os << "kGiBUU_Input"; } case InputUtils::kNUANCE_Input: { return os << "kNUANCE_Input"; } case InputUtils::kEVSPLN_Input: { return os << "kEVSPLN_Input"; } case InputUtils::kEMPTY_Input: { return os << "kEMPTY_Input"; } case InputUtils::kFEVENT_Input: { return os << "kFEVENT_Input"; } case InputUtils::kJOINT_Input: { return os << "kJOINT_Input"; } case InputUtils::kSIGMAQ0HIST_Input: { return os << "kSIGMAQ0HIST_Input"; } case InputUtils::kHISTO_Input: { return os << "kHISTO_Input"; } case InputUtils::kInvalid_Input: case InputUtils::kBNSPLN_Input: default: { return os << "kInvalid_Input"; } } } #endif diff --git a/src/Reweight/FitWeight.cxx b/src/Reweight/FitWeight.cxx index 84fab8e..56939c4 100644 --- a/src/Reweight/FitWeight.cxx +++ b/src/Reweight/FitWeight.cxx @@ -1,303 +1,273 @@ #include "FitWeight.h" +#include "GENIEWeightEngine.h" +#include "LikelihoodWeightEngine.h" +#include "ModeNormEngine.h" +#include "NEUTWeightEngine.h" +#include "NIWGWeightEngine.h" +#include "NUISANCEWeightEngine.h" +#include "NuWroWeightEngine.h" #include "OscWeightEngine.h" +#include "SampleNormEngine.h" +#include "SplineWeightEngine.h" +#include "T2KWeightEngine.h" void FitWeight::AddRWEngine(int type) { switch (type) { case kNEUT: fAllRW[type] = new NEUTWeightEngine("neutrw"); break; case kNUWRO: fAllRW[type] = new NuWroWeightEngine("nuwrorw"); break; case kGENIE: fAllRW[type] = new GENIEWeightEngine("genierw"); break; case kNORM: fAllRW[type] = new SampleNormEngine("normrw"); break; case kLIKEWEIGHT: fAllRW[type] = new LikelihoodWeightEngine("likerw"); break; case kT2K: fAllRW[type] = new T2KWeightEngine("t2krw"); break; case kCUSTOM: fAllRW[type] = new NUISANCEWeightEngine("nuisrw"); break; case kSPLINEPARAMETER: fAllRW[type] = new SplineWeightEngine("splinerw"); break; case kNIWG: fAllRW[type] = new NIWGWeightEngine("niwgrw"); break; case kOSCILLATION: fAllRW[type] = new OscWeightEngine(); break; + case kMODENORM: + fAllRW[type] = new ModeNormEngine(); default: THROW("CANNOT ADD RW Engine for unknown dial type: " << type); break; } } WeightEngineBase* FitWeight::GetRWEngine(int type) { - switch (type) { - case kNEUT: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kNUWRO: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kGENIE: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kNORM: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kLIKEWEIGHT: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kT2K: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kCUSTOM: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kSPLINEPARAMETER: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kNIWG: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - case kOSCILLATION: - if (fAllRW.count(type)) { - return fAllRW[type]; - } - default: { THROW("CANNOT get RW Engine for dial type: " << type); } + if (HasRWEngine(type)) { + return fAllRW[type]; } + THROW("CANNOT get RW Engine for dial type: " << type); } -bool FitWeight::HasRWEngine(int type){ -switch (type) { +bool FitWeight::HasRWEngine(int type) { + switch (type) { case kNEUT: case kNUWRO: case kGENIE: case kNORM: case kLIKEWEIGHT: case kT2K: case kCUSTOM: case kSPLINEPARAMETER: case kNIWG: - case kOSCILLATION:{ + case kOSCILLATION: { return fAllRW.count(type); } default: { THROW("CANNOT get RW Engine for dial type: " << type); } } } void FitWeight::IncludeDial(std::string name, std::string type, double val) { // Should register the dial here. int typeenum = Reweight::ConvDialType(type); IncludeDial(name, typeenum, val); } void FitWeight::IncludeDial(std::string name, int dialtype, double val) { // Get the dial enum int nuisenum = Reweight::ConvDial(name, dialtype); if (nuisenum == -1) { THROW("NUISENUM == " << nuisenum << " for " << name); } // Setup RW Engine Pointer if (fAllRW.find(dialtype) == fAllRW.end()) { AddRWEngine(dialtype); } WeightEngineBase* rw = fAllRW[dialtype]; // Include the dial rw->IncludeDial(name, val); // Set Dial Value if (val != -9999.9) { rw->SetDialValue(name, val); } // Sort Maps fAllEnums[name] = nuisenum; fAllValues[nuisenum] = val; // Sort Lists fNameList.push_back(name); fEnumList.push_back(nuisenum); fValueList.push_back(val); } void FitWeight::Reconfigure(bool silent) { // Reconfigure all added RW engines for (std::map::iterator iter = fAllRW.begin(); iter != fAllRW.end(); iter++) { (*iter).second->Reconfigure(silent); } } void FitWeight::SetDialValue(std::string name, double val) { // Add extra check, if name not found look for one with name in it. int nuisenum = fAllEnums[name]; SetDialValue(nuisenum, val); } // Allow for name aswell using GlobalList to determine sample name. void FitWeight::SetDialValue(int nuisenum, double val) { // Conv dial type - int dialtype = int(nuisenum - (nuisenum % 1000)) / 1000; + int dialtype = Reweight::GetDialType(nuisenum); if (fAllRW.find(dialtype) == fAllRW.end()) { THROW("Cannot find RW Engine for dialtype = " - << dialtype << " " << nuisenum << " " - << (nuisenum - (nuisenum % 1000)) / 1000); + << dialtype << ", " << Reweight::RemoveDialType(nuisenum)); } // Get RW Engine for this dial fAllRW[dialtype]->SetDialValue(nuisenum, val); fAllValues[nuisenum] = val; // Update ValueList for (size_t i = 0; i < fEnumList.size(); i++) { if (fEnumList[i] == nuisenum) { fValueList[i] = val; } } } void FitWeight::SetAllDials(const double* x, int n) { for (size_t i = 0; i < (UInt_t)n; i++) { int rwenum = fEnumList[i]; SetDialValue(rwenum, x[i]); } Reconfigure(); } double FitWeight::GetDialValue(std::string name) { // Add extra check, if name not found look for one with name in it. int nuisenum = fAllEnums[name]; return GetDialValue(nuisenum); } double FitWeight::GetDialValue(int nuisenum) { return fAllValues[nuisenum]; } int FitWeight::GetDialPos(std::string name) { int rwenum = fAllEnums[name]; return GetDialPos(rwenum); } int FitWeight::GetDialPos(int nuisenum) { for (size_t i = 0; i < fEnumList.size(); i++) { if (fEnumList[i] == nuisenum) { return i; } } ERR(FTL) << "No Dial Found! " << std::endl; throw; return -1; } bool FitWeight::DialIncluded(std::string name) { return (fAllEnums.find(name) != fAllEnums.end()); } bool FitWeight::DialIncluded(int rwenum) { return (fAllValues.find(rwenum) != fAllValues.end()); } double FitWeight::CalcWeight(BaseFitEvt* evt) { double rwweight = 1.0; for (std::map::iterator iter = fAllRW.begin(); iter != fAllRW.end(); iter++) { double w = (*iter).second->CalcWeight(evt); - // LOG(FIT) << "Iter " << (*iter).second->fCalcName << " = " << w << - // std::endl; rwweight *= w; } return rwweight; } void FitWeight::UpdateWeightEngine(const double* x) { size_t count = 0; for (std::vector::iterator iter = fEnumList.begin(); iter != fEnumList.end(); iter++) { SetDialValue((*iter), x[count]); count++; } } void FitWeight::GetAllDials(double* x, int n) { for (int i = 0; i < n; i++) { x[i] = GetDialValue(fEnumList[i]); } } -bool FitWeight::NeedsEventReWeight(const double* x) { - bool haschange = false; - size_t count = 0; - - // Compare old to new and decide if RW needed. - for (std::vector::iterator iter = fEnumList.begin(); - iter != fEnumList.end(); iter++) { - int nuisenum = (*iter); - int type = (nuisenum / 1000) - (nuisenum % 1000); - - // Compare old to new - double oldval = GetDialValue(nuisenum); - double newval = x[count]; - if (oldval != newval) { - if (fAllRW[type]->NeedsEventReWeight()) { - haschange = true; - } - } - - count++; - } - - return haschange; -} +// bool FitWeight::NeedsEventReWeight(const double* x) { +// bool haschange = false; +// size_t count = 0; + +// // Compare old to new and decide if RW needed. +// for (std::vector::iterator iter = fEnumList.begin(); +// iter != fEnumList.end(); iter++) { +// int nuisenum = (*iter); +// int type = (nuisenum / 1000) - (nuisenum % 1000); + +// // Compare old to new +// double oldval = GetDialValue(nuisenum); +// double newval = x[count]; +// if (oldval != newval) { +// if (fAllRW[type]->NeedsEventReWeight()) { +// haschange = true; +// } +// } + +// count++; +// } + +// return haschange; +// } double FitWeight::GetSampleNorm(std::string name) { if (name.empty()) return 1.0; // Find norm dial if (fAllEnums.find(name + "_norm") != fAllEnums.end()) { if (fAllValues.find(fAllEnums[name + "_norm"]) != fAllValues.end()) { return fAllValues[fAllEnums[name + "_norm"]]; } else { return 1.0; } } else { return 1.0; } } void FitWeight::Print() { LOG(REC) << "Fit Weight State: " << std::endl; for (size_t i = 0; i < fNameList.size(); i++) { LOG(REC) << " -> Par " << i << ". " << fNameList[i] << " " << fValueList[i] << std::endl; } } diff --git a/src/Reweight/FitWeight.h b/src/Reweight/FitWeight.h index 8393e16..0829ce8 100644 --- a/src/Reweight/FitWeight.h +++ b/src/Reweight/FitWeight.h @@ -1,74 +1,65 @@ #ifndef FITWEIGHT2_H #define FITWEIGHT2_H #include "WeightUtils.h" #include "WeightEngineBase.h" -#include "NEUTWeightEngine.h" -#include "GENIEWeightEngine.h" -#include "NuWroWeightEngine.h" -#include "SampleNormEngine.h" -#include "LikelihoodWeightEngine.h" -#include "SplineWeightEngine.h" -#include "NUISANCEWeightEngine.h" -#include "T2KWeightEngine.h" -#include "NIWGWeightEngine.h" #include #include class FitWeight { public: FitWeight(std::string name = "") {}; // Add a new RW engine given type void AddRWEngine(int rwtype); WeightEngineBase* GetRWEngine(int type); bool HasRWEngine(int type); // Includes void IncludeDial(std::string name, std::string type, double val = -9999.9); void IncludeDial(std::string name, int type, double val = -9999.9); // Update RW Engines void Reconfigure(bool silent = false); void SetDialValue(std::string name, double val); void SetDialValue(int rwenum, double val); double GetDialValue(std::string name); double GetDialValue(int rwenum); int GetDialPos(std::string name); int GetDialPos(int rwenum); bool DialIncluded(std::string name); bool DialIncluded(int rwenum); double CalcWeight(BaseFitEvt* evt); bool HasRWDialChanged(const double* x) { return true; }; - bool NeedsEventReWeight(const double* x); + // bool NeedsEventReWeight(const double* x); void SetAllDials(const double* x, int n); double GetSampleNorm(std::string name); void UpdateWeightEngine(const double* x); inline std::vector GetDialEnums() { return fEnumList; }; inline std::vector GetDialNames() { return fNameList; }; inline std::vector GetDialValues() { return fValueList; }; void GetAllDials(double* x, int n); void Print(); std::vector fEnumList; std::vector fNameList; std::vector fValueList; std::map fAllEnums; std::map fAllValues; std::map fAllRW; }; #endif diff --git a/src/Reweight/GlobalDialList.cxx b/src/Reweight/GlobalDialList.cxx index a3ef8f6..0db67e1 100644 --- a/src/Reweight/GlobalDialList.cxx +++ b/src/Reweight/GlobalDialList.cxx @@ -1,56 +1,48 @@ #include "GlobalDialList.h" -int GlobalDialList::EnumFromNameAndType(std::string name, int type){ - +int GlobalDialList::EnumFromNameAndType(std::string name, int type) { // Setup Type Container - if (fTypeEnumCont.find(type) == fTypeEnumCont.end()){ + if (fTypeEnumCont.find(type) == fTypeEnumCont.end()) { std::map temp; temp[name] = 0; fTypeEnumCont[type] = temp; } // Get Type Container std::map enumcont = fTypeEnumCont[type]; - // LOG(FIT) << "Getting Enum From name and type " << name << " " << type << std::endl; // Check name is in container, if its not add it - if (enumcont.find(name) == enumcont.end()){ - // LOG(FIT) << " Name not found in Enum type " << type << std::endl; + if (enumcont.find(name) == enumcont.end()) { int index = enumcont.size(); enumcont[name] = index; - // LOG(FIT) << "Returning new index of " << index << std::endl; fTypeEnumCont[type][name] = index; return index; } return enumcont[name]; } -void GlobalDialList::RegisterDialEnum(std::string name, int type, int nuisenum){ - - if (std::find(fAllDialNames.begin(), fAllDialNames.end(), name) != fAllDialNames.end()){ +void GlobalDialList::RegisterDialEnum(std::string name, int type, + int nuisenum) { + if (std::find(fAllDialNames.begin(), fAllDialNames.end(), name) != + fAllDialNames.end()) { return; } - LOG(FIT) << "Registed Dial Enum : " << name << " " << type << " " << nuisenum << std::endl; + LOG(FIT) << "Registed Dial Enum : " << name << " " << type << " " << nuisenum + << std::endl; fAllDialNames.push_back(name); fAllDialTypes.push_back(type); fAllDialEnums.push_back(nuisenum); } - - - /// Singleton functions -GlobalDialList& Reweight::DialList(){ - return GlobalDialList::Get(); -} +GlobalDialList& Reweight::DialList() { return GlobalDialList::Get(); } GlobalDialList* GlobalDialList::m_diallistInstance = NULL; -GlobalDialList& GlobalDialList::Get(void){ +GlobalDialList& GlobalDialList::Get(void) { if (!m_diallistInstance) m_diallistInstance = new GlobalDialList; return *m_diallistInstance; } - diff --git a/src/Reweight/ModeNormEngine.h b/src/Reweight/ModeNormEngine.h new file mode 100644 index 0000000..c53d51d --- /dev/null +++ b/src/Reweight/ModeNormEngine.h @@ -0,0 +1,79 @@ +#ifndef ModeNormEngine_H +#define ModeNormEngine_H + +#include "FitLogger.h" +#include "GeneratorUtils.h" +#include "WeightEngineBase.h" + +class ModeNormEngine : public WeightEngineBase { + public: + ModeNormEngine(std::string name="ModeNormEngine") : fName(name){}; + ~ModeNormEngine(){}; + + void IncludeDial(std::string name, double startval) { + int rwenum = Reweight::ConvDial(name, kMODENORM); + int mode = Reweight::RemoveDialType(rwenum); + if (fDialEnumIndex.count(mode)) { + THROW("Mode dial: " << mode + << " already included. Cannot include twice."); + } + fDialEnumIndex[mode] = fDialValues.size(); + fDialValues.push_back(startval); + QLOG(FIT, "Added mode dial for mode: " << mode); + } + void SetDialValue(int rwenum, double val) { + int mode = Reweight::RemoveDialType(rwenum); + if (!fDialEnumIndex.count(mode)) { + THROW("Mode dial: " << mode + << " has not been included. Cannot set value."); + } + fDialValues[fDialEnumIndex[mode]] = val; + } + void SetDialValue(std::string name, double val) { + SetDialValue(Reweight::ConvDial(name, kMODENORM), val); + } + + void Reconfigure(bool silent = false) { (void)silent; } + double CalcWeight(BaseFitEvt* evt) { + int mode = abs(evt->Mode); + if (!fDialEnumIndex.count(mode)) { + return 1; + } + return fDialValues[fDialEnumIndex[mode]]; + }; + bool NeedsEventReWeight() { return false; }; + + double GetDialValue(std::string name) { + int rwenum = Reweight::ConvDial(name, kMODENORM); + int mode = Reweight::RemoveDialType(rwenum); + if (fDialEnumIndex.count(mode)) { + return fDialValues[fDialEnumIndex[mode]]; + } else { + return 0xdeadbeef; + } + } + + static int SystEnumFromString(std::string const& name) { + std::vector splits = GeneralUtils::ParseToStr(name, "_"); + if (splits.size() != 2) { + ERR(FTL) << "Attempting to parse dial name: \"" << name + << "\" as a mode norm dial but failed. Expect e.g. \"mode_2\"." + << std::endl; + } + + int mode_num = GeneralUtils::StrToInt(splits[1]); + if (!mode_num) { + ERR(FTL) << "Attempting to parse dial name: \"" << name + << "\" as a mode norm dial but failed." << std::endl; + throw; + } + return 60 + mode_num; + } + + std::map fDialEnumIndex; + std::vector fDialValues; + + std::string fName; +}; + +#endif diff --git a/src/Reweight/NUISANCEWeightCalcs.cxx b/src/Reweight/NUISANCEWeightCalcs.cxx index bd76c00..4a70d6b 100644 --- a/src/Reweight/NUISANCEWeightCalcs.cxx +++ b/src/Reweight/NUISANCEWeightCalcs.cxx @@ -1,346 +1,346 @@ #include "NUISANCEWeightCalcs.h" +#include "GeneralUtils.h" +#include "FitEvent.h" +#include "WeightUtils.h" +#include "NUISANCESyst.h" + +using namespace Reweight; + ModeNormCalc::ModeNormCalc(){ fNormRES = 1.0; } double ModeNormCalc::CalcWeight(BaseFitEvt* evt) { - FitEvent* fevt = static_cast(evt); - int mode = abs(fevt->Mode); + int mode = abs(evt->Mode); double w = 1.0; - + if (mode == 11 or mode == 12 or mode == 13){ w *= fNormRES; - } + } return w; } void ModeNormCalc::SetDialValue(std::string name, double val) { SetDialValue(Reweight::ConvDial(name, kCUSTOM), val); } void ModeNormCalc::SetDialValue(int rwenum, double val) { int curenum = rwenum % 1000; - // Check Handled + // Check Handled if (!IsHandled(curenum)) return; if (curenum == kModeNorm_NormRES) fNormRES = val; } bool ModeNormCalc::IsHandled(int rwenum) { int curenum = rwenum % 1000; switch (curenum) { case kModeNorm_NormRES: return true; default: return false; } } - - - - - - GaussianModeCorr::GaussianModeCorr() { // Init fApply_CCQE = false; fGausVal_CCQE[kPosNorm] = 0.0; fGausVal_CCQE[kPosTilt] = 0.0; fGausVal_CCQE[kPosPq0] = 1.0; fGausVal_CCQE[kPosWq0] = 1.0; fGausVal_CCQE[kPosPq3] = 1.0; fGausVal_CCQE[kPosWq3] = 1.0; fApply_2p2h = false; fGausVal_2p2h[kPosNorm] = 0.0; fGausVal_2p2h[kPosTilt] = 0.0; fGausVal_2p2h[kPosPq0] = 1.0; fGausVal_2p2h[kPosWq0] = 1.0; fGausVal_2p2h[kPosPq3] = 1.0; fGausVal_2p2h[kPosWq3] = 1.0; fApply_2p2h_PPandNN = false; fGausVal_2p2h_PPandNN[kPosNorm] = 0.0; fGausVal_2p2h_PPandNN[kPosTilt] = 0.0; fGausVal_2p2h_PPandNN[kPosPq0] = 1.0; fGausVal_2p2h_PPandNN[kPosWq0] = 1.0; fGausVal_2p2h_PPandNN[kPosPq3] = 1.0; fGausVal_2p2h_PPandNN[kPosWq3] = 1.0; fApply_2p2h_NP = false; fGausVal_2p2h_NP[kPosNorm] = 0.0; fGausVal_2p2h_NP[kPosTilt] = 0.0; fGausVal_2p2h_NP[kPosPq0] = 1.0; fGausVal_2p2h_NP[kPosWq0] = 1.0; fGausVal_2p2h_NP[kPosPq3] = 1.0; fGausVal_2p2h_NP[kPosWq3] = 1.0; fApply_CC1pi = false; fGausVal_CC1pi[kPosNorm] = 0.0; fGausVal_CC1pi[kPosTilt] = 0.0; fGausVal_CC1pi[kPosPq0] = 1.0; fGausVal_CC1pi[kPosWq0] = 1.0; fGausVal_CC1pi[kPosPq3] = 1.0; fGausVal_CC1pi[kPosWq3] = 1.0; fAllowSuppression = false; fDebugStatements = FitPar::Config().GetParB("GaussianModeCorr_DEBUG"); } double GaussianModeCorr::CalcWeight(BaseFitEvt* evt) { FitEvent* fevt = static_cast(evt); double rw_weight = 1.0; // Get Neutrino if (!fevt->Npart()){ THROW("NO particles found in stack!"); } FitParticle* pnu = fevt->PartInfo(0); if (!pnu){ THROW("NO Starting particle found in stack!"); } int pdgnu = pnu->fPID; FitParticle* plep = fevt->GetHMFSParticle(abs(pdgnu) - 1); if (!plep) return 1.0; TLorentzVector q = pnu->fP - plep->fP; // Extra q0,q3 double q0 = fabs(q.E()) / 1.E3; double q3 = fabs(q.Vect().Mag()) / 1.E3; int initialstate = -1; // Undef if (abs(fevt->Mode) == 2) { int npr = 0; int nne = 0; for (UInt_t j = 0; j < fevt->Npart(); j++) { if ((fevt->PartInfo(j))->fIsAlive) continue; if (fevt->PartInfo(j)->fPID == 2212) npr++; else if (fevt->PartInfo(j)->fPID == 2112) nne++; } // std::cout << "PN State = " << npr << " " << nne << std::endl; if (fevt->Mode == 2 and npr == 1 and nne == 1) { initialstate = 2; } else if (fevt->Mode == 2 and ((npr == 0 and nne == 2) or (npr == 2 and nne == 0))) { initialstate = 1; } } // std::cout << "Got q0 q3 = " << q0 << " " << q3 << std::endl; // Apply weighting if (fApply_CCQE and abs(fevt->Mode) == 1) { if (fDebugStatements) std::cout << "Getting CCQE Weight" << std::endl; double g = GetGausWeight(q0, q3, fGausVal_CCQE); if (g < 1.0) g = 1.0; rw_weight *= g; } if (fApply_2p2h and abs(fevt->Mode) == 2) { if (fDebugStatements) std::cout << "Getting 2p2h Weight" << std::endl; rw_weight *= GetGausWeight(q0, q3, fGausVal_2p2h); } if (fApply_2p2h_PPandNN and abs(fevt->Mode) == 2 and initialstate == 1) { if (fDebugStatements) std::cout << "Getting 2p2h PPandNN Weight" << std::endl; rw_weight *= GetGausWeight(q0, q3, fGausVal_2p2h_PPandNN); } if (fApply_2p2h_NP and abs(fevt->Mode) == 2 and initialstate == 2) { if (fDebugStatements) std::cout << "Getting 2p2h NP Weight" << std::endl; rw_weight *= GetGausWeight(q0, q3, fGausVal_2p2h_NP); } if (fApply_CC1pi and abs(fevt->Mode) >= 11 and abs(fevt->Mode) <= 13) { if (fDebugStatements) std::cout << "Getting CC1pi Weight" << std::endl; rw_weight *= GetGausWeight(q0, q3, fGausVal_CC1pi); } // if (fDebugStatements) std::cout << "Returning Weight " << rw_weight << std::endl; return rw_weight; } double GaussianModeCorr::GetGausWeight(double q0, double q3, double vals[]) { // // CCQE Without Suppression // double Norm = 4.82788679036; // double Tilt = 2.3501416116; // double Pq0 = 0.363964889702; // double Wq0 = 0.133976806938; // double Pq3 = 0.431769740224; // double Wq3 = 0.207666663434; // // Also add for CCQE at the end // return (w > 1.0) ? w : 1.0; // // 2p2h with suppression // double Norm = 15.967; // double Tilt = -0.455655; // double Pq0 = 0.214598; // double Wq0 = 0.0291061; // double Pq3 = 0.480194; // double Wq3 = 0.134588; double Norm = vals[kPosNorm]; double Tilt = vals[kPosTilt]; double Pq0 = vals[kPosPq0]; double Wq0 = vals[kPosWq0]; double Pq3 = vals[kPosPq3]; double Wq3 = vals[kPosWq3]; double a = cos(Tilt) * cos(Tilt) / (2 * Wq0 * Wq0); a += sin(Tilt) * sin(Tilt) / (2 * Wq3 * Wq3); double b = - sin(2 * Tilt) / (4 * Wq0 * Wq0); b += sin(2 * Tilt) / (4 * Wq3 * Wq3); double c = sin(Tilt) * sin(Tilt) / (2 * Wq0 * Wq0); c += cos(Tilt) * cos(Tilt) / (2 * Wq3 * Wq3); double w = Norm; w *= exp(-a * (q0 - Pq0) * (q0 - Pq0)); w *= exp(+2.0 * b * (q0 - Pq0) * (q3 - Pq3)); w *= exp(-c * (q3 - Pq3) * (q3 - Pq3)); if (fDebugStatements) { std::cout << "Applied Tilt " << Tilt << " " << cos(Tilt) << " " << sin(Tilt) << std::endl; std::cout << "abc = " << a << " " << b << " " << c << std::endl; std::cout << "Returning " << Norm << " " << Pq0 << " " << Wq0 << " " << Pq3 << " " << Wq3 << " " << w << std::endl; } if (w != w || isnan(w) || w < 0.0){ w = 0.0; } if (w < 1.0 and !fAllowSuppression){ w = 1.0; - } + } return w; } void GaussianModeCorr::SetDialValue(std::string name, double val) { SetDialValue(Reweight::ConvDial(name, kCUSTOM), val); } void GaussianModeCorr::SetDialValue(int rwenum, double val) { int curenum = rwenum % 1000; // Check Handled if (!IsHandled(curenum)) return; // CCQE Setting for (int i = kGaussianCorr_CCQE_norm; i <= kGaussianCorr_CCQE_Wq3; i++) { if (i == curenum) { int index = i - kGaussianCorr_CCQE_norm; fGausVal_CCQE[index] = val; fApply_CCQE = true; } } // 2p2h Setting for (int i = kGaussianCorr_2p2h_norm; i <= kGaussianCorr_2p2h_Wq3; i++) { if (i == curenum) { int index = i - kGaussianCorr_2p2h_norm; fGausVal_2p2h[index] = val; fApply_2p2h = true; } } // 2p2h_PPandNN Setting for (int i = kGaussianCorr_2p2h_PPandNN_norm; i <= kGaussianCorr_2p2h_PPandNN_Wq3; i++) { if (i == curenum) { int index = i - kGaussianCorr_2p2h_PPandNN_norm; fGausVal_2p2h_PPandNN[index] = val; fApply_2p2h_PPandNN = true; } } // 2p2h_NP Setting for (int i = kGaussianCorr_2p2h_NP_norm; i <= kGaussianCorr_2p2h_NP_Wq3; i++) { if (i == curenum) { int index = i - kGaussianCorr_2p2h_NP_norm; fGausVal_2p2h_NP[index] = val; fApply_2p2h_NP = true; } } // CC1pi Setting for (int i = kGaussianCorr_CC1pi_norm; i <= kGaussianCorr_CC1pi_Wq3; i++) { if (i == curenum) { int index = i - kGaussianCorr_CC1pi_norm; fGausVal_CC1pi[index] = val; fApply_CC1pi = true; } } if (curenum == kGaussianCorr_AllowSuppression){ fAllowSuppression = (val > 0.5); } } bool GaussianModeCorr::IsHandled(int rwenum) { int curenum = rwenum % 1000; switch (curenum) { case kGaussianCorr_CCQE_norm: case kGaussianCorr_CCQE_tilt: case kGaussianCorr_CCQE_Pq0: case kGaussianCorr_CCQE_Wq0: case kGaussianCorr_CCQE_Pq3: case kGaussianCorr_CCQE_Wq3: case kGaussianCorr_2p2h_norm: case kGaussianCorr_2p2h_tilt: case kGaussianCorr_2p2h_Pq0: case kGaussianCorr_2p2h_Wq0: case kGaussianCorr_2p2h_Pq3: case kGaussianCorr_2p2h_Wq3: case kGaussianCorr_2p2h_PPandNN_norm: case kGaussianCorr_2p2h_PPandNN_tilt: case kGaussianCorr_2p2h_PPandNN_Pq0: case kGaussianCorr_2p2h_PPandNN_Wq0: case kGaussianCorr_2p2h_PPandNN_Pq3: case kGaussianCorr_2p2h_PPandNN_Wq3: case kGaussianCorr_2p2h_NP_norm: case kGaussianCorr_2p2h_NP_tilt: case kGaussianCorr_2p2h_NP_Pq0: case kGaussianCorr_2p2h_NP_Wq0: case kGaussianCorr_2p2h_NP_Pq3: case kGaussianCorr_2p2h_NP_Wq3: case kGaussianCorr_CC1pi_norm: case kGaussianCorr_CC1pi_tilt: case kGaussianCorr_CC1pi_Pq0: case kGaussianCorr_CC1pi_Wq0: case kGaussianCorr_CC1pi_Pq3: case kGaussianCorr_CC1pi_Wq3: case kGaussianCorr_AllowSuppression: return true; default: return false; } } diff --git a/src/Reweight/NUISANCEWeightCalcs.h b/src/Reweight/NUISANCEWeightCalcs.h index 3814d67..15e2c6b 100644 --- a/src/Reweight/NUISANCEWeightCalcs.h +++ b/src/Reweight/NUISANCEWeightCalcs.h @@ -1,100 +1,90 @@ #ifndef NUISANCE_WEIGHT_CALCS #define NUISANCE_WEIGHT_CALCS -#include "FitEvent.h" -#include "GeneralUtils.h" #include "BaseFitEvt.h" -#include "WeightUtils.h" -#include "NUISANCESyst.h" - - -using namespace Reweight; - class NUISANCEWeightCalc { public: NUISANCEWeightCalc() {}; virtual ~NUISANCEWeightCalc() {}; virtual double CalcWeight(BaseFitEvt* evt){return 1.0;}; virtual void SetDialValue(std::string name, double val){}; virtual void SetDialValue(int rwenum, double val){}; virtual bool IsHandled(int rwenum){return false;}; virtual void Print(){}; std::map fDialNameIndex; std::map fDialEnumIndex; std::vector fDialValues; std::string fName; }; class ModeNormCalc : public NUISANCEWeightCalc { public: ModeNormCalc(); ~ModeNormCalc(){}; double CalcWeight(BaseFitEvt* evt); void SetDialValue(std::string name, double val); void SetDialValue(int rwenum, double val); bool IsHandled(int rwenum); double fNormRES; }; - - class GaussianModeCorr : public NUISANCEWeightCalc { public: GaussianModeCorr(); ~GaussianModeCorr(){}; double CalcWeight(BaseFitEvt* evt); void SetDialValue(std::string name, double val); void SetDialValue(int rwenum, double val); bool IsHandled(int rwenum); double GetGausWeight(double q0, double q3, double vals[]); // 5 pars describe the Gaussain // 0 norm. // 1 q0 pos // 2 q0 width // 3 q3 pos // 4 q3 width static const int kPosNorm = 0; static const int kPosTilt = 1; static const int kPosPq0 = 2; static const int kPosWq0 = 3; static const int kPosPq3 = 4; static const int kPosWq3 = 5; bool fApply_CCQE; double fGausVal_CCQE[6]; bool fApply_2p2h; double fGausVal_2p2h[6]; bool fApply_2p2h_PPandNN; double fGausVal_2p2h_PPandNN[6]; bool fApply_2p2h_NP; double fGausVal_2p2h_NP[6]; bool fApply_CC1pi; double fGausVal_CC1pi[6]; bool fAllowSuppression; bool fDebugStatements; }; #endif diff --git a/src/Reweight/WeightUtils.cxx b/src/Reweight/WeightUtils.cxx index 6bb4c57..b6787f3 100644 --- a/src/Reweight/WeightUtils.cxx +++ b/src/Reweight/WeightUtils.cxx @@ -1,568 +1,614 @@ #include "WeightUtils.h" +#include "FitLogger.h" +#ifdef __T2KREW_ENABLED__ +#include "T2KGenieReWeight.h" +#include "T2KNIWGReWeight.h" +#include "T2KNIWGUtils.h" +#include "T2KNeutReWeight.h" +#include "T2KNeutUtils.h" +#include "T2KReWeight.h" +using namespace t2krew; +#endif + +#ifdef __NIWG_ENABLED__ +#include "NIWGReWeight.h" +#include "NIWGReWeight1piAngle.h" +#include "NIWGReWeight2010a.h" +#include "NIWGReWeight2012a.h" +#include "NIWGReWeight2014a.h" +#include "NIWGReWeightDeltaMass.h" +#include "NIWGReWeightEffectiveRPA.h" +#include "NIWGReWeightHadronMultSwitch.h" +#include "NIWGReWeightMEC.h" +#include "NIWGReWeightPiMult.h" +#include "NIWGReWeightProtonFSIbug.h" +#include "NIWGReWeightRPA.h" +#include "NIWGReWeightSpectralFunc.h" +#include "NIWGReWeightSplineEnu.h" +#include "NIWGSyst.h" +#include "NIWGSystUncertainty.h" +#endif + +#ifdef __NEUT_ENABLED__ +#include "NReWeight.h" +#include "NReWeightCasc.h" +#include "NReWeightNuXSecCCQE.h" +#include "NReWeightNuXSecCCRES.h" +#include "NReWeightNuXSecCOH.h" +#include "NReWeightNuXSecDIS.h" +#include "NReWeightNuXSecNC.h" +#include "NReWeightNuXSecNCEL.h" +#include "NReWeightNuXSecNCRES.h" +#include "NReWeightNuXSecRES.h" +#include "NReWeightNuclPiless.h" +#include "NSyst.h" +#include "NSystUncertainty.h" +#include "neutpart.h" +#include "neutvect.h" +#endif + +#ifdef __NUWRO_ENABLED__ +#include "event1.h" +#endif + +#ifdef __NUWRO_REWEIGHT_ENABLED__ +#include "NuwroReWeight.h" +#include "NuwroReWeight_FlagNorm.h" +#include "NuwroReWeight_QEL.h" +#include "NuwroReWeight_SPP.h" +#include "NuwroSyst.h" +#include "NuwroSystUncertainty.h" +#endif + +#ifdef __GENIE_ENABLED__ +#include "EVGCore/EventRecord.h" +#include "EVGCore/EventRecord.h" +#include "GHEP/GHepRecord.h" +#include "GSyst.h" +#include "GSystUncertainty.h" +#include "Ntuple/NtpMCEventRecord.h" +#include "ReWeight/GReWeight.h" +#include "ReWeight/GReWeightAGKY.h" +#include "ReWeight/GReWeightDISNuclMod.h" +#include "ReWeight/GReWeightFGM.h" +#include "ReWeight/GReWeightFZone.h" +#include "ReWeight/GReWeightINuke.h" +#include "ReWeight/GReWeightNonResonanceBkg.h" +#include "ReWeight/GReWeightNuXSecCCQE.h" +#include "ReWeight/GReWeightNuXSecCCQEvec.h" +#include "ReWeight/GReWeightNuXSecCCRES.h" +#include "ReWeight/GReWeightNuXSecCOH.h" +#include "ReWeight/GReWeightNuXSecDIS.h" +#include "ReWeight/GReWeightNuXSecNC.h" +#include "ReWeight/GReWeightNuXSecNCEL.h" +#include "ReWeight/GReWeightNuXSecNCRES.h" +#include "ReWeight/GReWeightResonanceDecay.h" +using namespace genie; +using namespace genie::rew; +#endif + +#include "GlobalDialList.h" +#include "ModeNormEngine.h" +#include "NUISANCESyst.h" #include "OscWeightEngine.h" //******************************************************************** -TF1 FitBase::GetRWConvFunction(std::string type, std::string name) { +TF1 FitBase::GetRWConvFunction(std::string const &type, + std::string const &name) { //******************************************************************** std::string dialfunc = "x"; std::string parType = type; double low = -10000.0; double high = 10000.0; if (parType.find("parameter") == std::string::npos) parType += "_parameter"; std::string line; ifstream card( (GeneralUtils::GetTopLevelDir() + "/parameters/dial_conversion.card") .c_str(), ifstream::in); while (std::getline(card >> std::ws, line, '\n')) { std::vector inputlist = GeneralUtils::ParseToStr(line, " "); // Check the line length if (inputlist.size() < 4) continue; // Check whether this is a comment if (inputlist[0].c_str()[0] == '#') continue; // Check whether this is the correct parameter type if (inputlist[0].compare(parType) != 0) continue; // Check the parameter name if (inputlist[1].compare(name) != 0) continue; // inputlist[2] should be the units... ignore for now dialfunc = inputlist[3]; // High and low are optional, check whether they exist if (inputlist.size() > 4) low = GeneralUtils::StrToDbl(inputlist[4]); if (inputlist.size() > 5) high = GeneralUtils::StrToDbl(inputlist[5]); } TF1 convfunc = TF1((name + "_convfunc").c_str(), dialfunc.c_str(), low, high); return convfunc; } //******************************************************************** -std::string FitBase::GetRWUnits(std::string type, std::string name) { +std::string FitBase::GetRWUnits(std::string const &type, + std::string const &name) { //******************************************************************** std::string unit = "sig."; std::string parType = type; if (parType.find("parameter") == std::string::npos) { parType += "_parameter"; } std::string line; std::ifstream card( (GeneralUtils::GetTopLevelDir() + "/parameters/dial_conversion.card") .c_str(), ifstream::in); while (std::getline(card >> std::ws, line, '\n')) { std::vector inputlist = GeneralUtils::ParseToStr(line, " "); // Check the line length if (inputlist.size() < 3) continue; // Check whether this is a comment if (inputlist[0].c_str()[0] == '#') continue; // Check whether this is the correct parameter type if (inputlist[0].compare(parType) != 0) continue; // Check the parameter name if (inputlist[1].compare(name) != 0) continue; unit = inputlist[2]; break; } return unit; } //******************************************************************** -double FitBase::RWAbsToSigma(std::string type, std::string name, double val) { +double FitBase::RWAbsToSigma(std::string const &type, std::string const &name, + double val) { //******************************************************************** TF1 f1 = GetRWConvFunction(type, name); double conv_val = f1.GetX(val); if (fabs(conv_val) < 1E-10) conv_val = 0.0; return conv_val; } //******************************************************************** -double FitBase::RWSigmaToAbs(std::string type, std::string name, double val) { +double FitBase::RWSigmaToAbs(std::string const &type, std::string const &name, + double val) { //******************************************************************** TF1 f1 = GetRWConvFunction(type, name); double conv_val = f1.Eval(val); return conv_val; } //******************************************************************** -double FitBase::RWFracToSigma(std::string type, std::string name, double val) { +double FitBase::RWFracToSigma(std::string const &type, std::string const &name, + double val) { //******************************************************************** TF1 f1 = GetRWConvFunction(type, name); double conv_val = f1.GetX((val * f1.Eval(0.0))); if (fabs(conv_val) < 1E-10) conv_val = 0.0; return conv_val; } //******************************************************************** -double FitBase::RWSigmaToFrac(std::string type, std::string name, double val) { +double FitBase::RWSigmaToFrac(std::string const &type, std::string const &name, + double val) { //******************************************************************** TF1 f1 = GetRWConvFunction(type, name); double conv_val = f1.Eval(val) / f1.Eval(0.0); return conv_val; } -int FitBase::ConvDialType(std::string type) { +int FitBase::ConvDialType(std::string const &type) { if (!type.compare("neut_parameter")) return kNEUT; else if (!type.compare("niwg_parameter")) return kNIWG; else if (!type.compare("nuwro_parameter")) return kNUWRO; else if (!type.compare("t2k_parameter")) return kT2K; else if (!type.compare("genie_parameter")) return kGENIE; else if (!type.compare("custom_parameter")) return kCUSTOM; else if (!type.compare("norm_parameter")) return kNORM; - else if (!type.compare("modenorm_parameter")) - return kMODENORM; else if (!type.compare("likeweight_parameter")) return kLIKEWEIGHT; else if (!type.compare("spline_parameter")) return kSPLINEPARAMETER; else if (!type.compare("osc_parameter")) return kOSCILLATION; + else if (!type.compare("modenorm_parameter")) + return kMODENORM; else return kUNKNOWN; } std::string FitBase::ConvDialType(int type) { switch (type) { case kNEUT: { return "neut_parameter"; } case kNIWG: { return "niwg_parameter"; } case kNUWRO: { return "nuwro_parameter"; } case kT2K: { return "t2k_parameter"; } case kGENIE: { return "genie_parameter"; } case kNORM: { return "norm_parameter"; } case kCUSTOM: { return "custom_parameter"; } - case kMODENORM: { - return "modenorm_parameter"; - } case kLIKEWEIGHT: { return "likeweight_parameter"; } case kSPLINEPARAMETER: { return "spline_parameter"; } case kOSCILLATION: { return "osc_parameter"; } + case kMODENORM: { + return "modenorm_parameter"; + } default: return "unknown_parameter"; } } -int FitBase::GetDialEnum(std::string type, std::string name) { +int FitBase::GetDialEnum(std::string const &type, std::string const &name) { return FitBase::GetDialEnum(FitBase::ConvDialType(type), name); } -int FitBase::GetDialEnum(int type, std::string name) { +int FitBase::GetDialEnum(int type, std::string const &name) { int offset = type * 1000; - int this_enum = -1; // Not Found + int this_enum = Reweight::kNoDialFound; // Not Found std::cout << "Getting dial enum " << type << " " << name << std::endl; // Select Types switch (type) { // NEUT DIAL TYPE case kNEUT: { #ifdef __NEUT_ENABLED__ int neut_enum = (int)neut::rew::NSyst::FromString(name); if (neut_enum != 0) { this_enum = neut_enum + offset; } #else - this_enum = -2; // Not enabled + this_enum = Reweight::kNoTypeFound; // Not enabled #endif break; } // NIWG DIAL TYPE case kNIWG: { #ifdef __NIWG_ENABLED__ int niwg_enum = (int)niwg::rew::NIWGSyst::FromString(name); if (niwg_enum != 0) { this_enum = niwg_enum + offset; } #else - this_enum = -2; + this_enum = Reweight::kNoTypeFound; #endif break; } // NUWRO DIAL TYPE case kNUWRO: { #ifdef __NUWRO_REWEIGHT_ENABLED__ int nuwro_enum = (int)nuwro::rew::NuwroSyst::FromString(name); if (nuwro_enum > 0) { this_enum = nuwro_enum + offset; } #else - this_enum = -2; + this_enum = Reweight::kNoTypeFound; #endif } // GENIE DIAL TYPE case kGENIE: { #ifdef __GENIE_ENABLED__ int genie_enum = (int)genie::rew::GSyst::FromString(name); if (genie_enum > 0) { this_enum = genie_enum + offset; } #else - this_enum = -2; + this_enum = Reweight::kNoTypeFound; #endif break; } case kCUSTOM: { int custom_enum = 0; // PLACEHOLDER this_enum = custom_enum + offset; break; } // T2K DIAL TYPE case kT2K: { #ifdef __T2KREW_ENABLED__ int t2k_enum = (int)t2krew::T2KSyst::FromString(name); if (t2k_enum > 0) { this_enum = t2k_enum + offset; } #else - this_enum = -2; + this_enum = Reweight::kNoTypeFound; #endif break; } case kNORM: { if (gNormEnums.find(name) == gNormEnums.end()) { gNormEnums[name] = gNormEnums.size() + 1 + offset; } this_enum = gNormEnums[name]; break; } - case kMODENORM: { - size_t us_pos = name.find_first_of('_'); - std::string numstr = name.substr(us_pos + 1); - int mode_num = std::atoi(numstr.c_str()); - LOG(FTL) << "Getting mode num " << mode_num << std::endl; - if (!mode_num) { - ERR(FTL) << "Attempting to parse dial name: \"" << name - << "\" as a mode norm dial but failed." << std::endl; - throw; - } - this_enum = 60 + mode_num + offset; - break; - } - case kLIKEWEIGHT: { if (gLikeWeightEnums.find(name) == gLikeWeightEnums.end()) { gLikeWeightEnums[name] = gLikeWeightEnums.size() + 1 + offset; } this_enum = gLikeWeightEnums[name]; break; } case kSPLINEPARAMETER: { if (gSplineParameterEnums.find(name) == gSplineParameterEnums.end()) { gSplineParameterEnums[name] = gSplineParameterEnums.size() + 1 + offset; } this_enum = gSplineParameterEnums[name]; break; } case kOSCILLATION: { #ifdef __PROB3PP_ENABLED__ int oscEnum = OscWeightEngine::SystEnumFromString(name); if (oscEnum != 0) { this_enum = oscEnum + offset; } #else - this_enum = -2; // Not enabled + this_enum = Reweight::kNoTypeFound; // Not enabled #endif } + case kMODENORM: { + size_t us_pos = name.find_first_of('_'); + std::string numstr = name.substr(us_pos + 1); + int mode_num = std::atoi(numstr.c_str()); + LOG(FTL) << "Getting mode num " << mode_num << std::endl; + if (!mode_num) { + ERR(FTL) << "Attempting to parse dial name: \"" << name + << "\" as a mode norm dial but failed." << std::endl; + throw; + } + this_enum = 60 + mode_num + offset; + break; + } } // If Not Enabled - if (this_enum == -2) { + if (this_enum == Reweight::kNoTypeFound) { ERR(FTL) << "RW Engine not supported for " << FitBase::ConvDialType(type) << std::endl; ERR(FTL) << "Check dial " << name << std::endl; } // If Not Found - if (this_enum == -1) { + if (this_enum == Reweight::kNoDialFound) { ERR(FTL) << "Dial " << name << " not found." << std::endl; } return this_enum; } -int Reweight::ConvDialType(std::string type) { - if (!type.compare("neut_parameter")) - return kNEUT; - else if (!type.compare("niwg_parameter")) - return kNIWG; - else if (!type.compare("nuwro_parameter")) - return kNUWRO; - else if (!type.compare("t2k_parameter")) - return kT2K; - else if (!type.compare("genie_parameter")) - return kGENIE; - else if (!type.compare("norm_parameter")) - return kNORM; - else if (!type.compare("modenorm_parameter")) - return kMODENORM; - else if (!type.compare("custom_parameter")) - return kCUSTOM; - else if (!type.compare("likeweight_parameter")) - return kLIKEWEIGHT; - else if (!type.compare("spline_parameter")) - return kSPLINEPARAMETER; - else if (!type.compare("osc_parameter")) - return kOSCILLATION; - else - return kUNKNOWN; +int Reweight::ConvDialType(std::string const &type) { + return FitBase::ConvDialType(type); } std::string Reweight::ConvDialType(int type) { - switch (type) { - case kNEUT: { - return "neut_parameter"; - } - case kNIWG: { - return "niwg_parameter"; - } - case kNUWRO: { - return "nuwro_parameter"; - } - case kT2K: { - return "t2k_parameter"; - } - case kGENIE: { - return "genie_parameter"; - } - case kNORM: { - return "norm_parameter"; - } - case kCUSTOM: { - return "custom_parameter"; - } - - case kMODENORM: { - return "modenorm_parameter"; - } - case kLIKEWEIGHT: { - return "likeweight_parameter"; - } - case kSPLINEPARAMETER: { - return "spline_parameter"; - } + return FitBase::ConvDialType(type); +} - case kOSCILLATION: { - return "spline_parameter"; - } - default: - return "unknown_parameter"; - } +int Reweight::GetDialType(int type) { + int t = (type / 1000); + return t > kMODENORM ? Reweight::kNoDialFound : t; +} +int Reweight::RemoveDialType(int type){ + return (type%1000); } -int Reweight::NEUTEnumFromName(std::string name) { +int Reweight::NEUTEnumFromName(std::string const &name) { #ifdef __NEUT_ENABLED__ int neutenum = (int)neut::rew::NSyst::FromString(name); - return (neutenum > 0) ? neutenum : kNoDialFound; + return (neutenum > 0) ? neutenum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::NIWGEnumFromName(std::string name) { +int Reweight::NIWGEnumFromName(std::string const &name) { #ifdef __NIWG_ENABLED__ int niwgenum = (int)niwg::rew::NIWGSyst::FromString(name); - return (niwgenum != 0) ? niwgenum : kNoDialFound; + return (niwgenum != 0) ? niwgenum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::NUWROEnumFromName(std::string name) { +int Reweight::NUWROEnumFromName(std::string const &name) { #ifdef __NUWRO_REWEIGHT_ENABLED__ int nuwroenum = (int)nuwro::rew::NuwroSyst::FromString(name); - return (nuwroenum > 0) ? nuwroenum : kNoDialFound; + return (nuwroenum > 0) ? nuwroenum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::GENIEEnumFromName(std::string name) { +int Reweight::GENIEEnumFromName(std::string const &name) { #ifdef __GENIE_ENABLED__ int genieenum = (int)genie::rew::GSyst::FromString(name); - return (genieenum > 0) ? genieenum : kNoDialFound; + return (genieenum > 0) ? genieenum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::T2KEnumFromName(std::string name) { +int Reweight::T2KEnumFromName(std::string const &name) { #ifdef __T2KREW_ENABLED__ int t2kenum = (int)t2krew::T2KSyst::FromString(name); - return (t2kenum > 0) ? t2kenum : kNoDialFound; + return (t2kenum > 0) ? t2kenum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::OscillationEnumFromName(std::string name) { +int Reweight::OscillationEnumFromName(std::string const &name) { #ifdef __PROB3PP_ENABLED__ int oscEnum = OscWeightEngine::SystEnumFromString(name); - return (oscEnum > 0) ? oscEnum : kNoDialFound; + return (oscEnum > 0) ? oscEnum : Reweight::kNoDialFound; #else - return kGeneratorNotBuilt; + return Reweight::kGeneratorNotBuilt; #endif } -int Reweight::NUISANCEEnumFromName(std::string name, int type) { +int Reweight::NUISANCEEnumFromName(std::string const &name, int type) { int nuisenum = Reweight::DialList().EnumFromNameAndType(name, type); return nuisenum; } -int Reweight::CustomEnumFromName(std::string name) { +int Reweight::CustomEnumFromName(std::string const &name) { int custenum = Reweight::ConvertNUISANCEDial(name); return custenum; } -int Reweight::ConvDial(std::string name, std::string type, bool exceptions) { +int Reweight::ConvDial(std::string const &name, std::string const &type, + bool exceptions) { return Reweight::ConvDial(name, Reweight::ConvDialType(type), exceptions); } -int Reweight::ConvDial(std::string fullname, int type, bool exceptions) { +int Reweight::ConvDial(std::string const &fullname, int type, bool exceptions) { std::string name = GeneralUtils::ParseToStr(fullname, ",")[0]; // Only use first dial given // Produce offset seperating each type. int offset = type * 1000; - int genenum = kNoDialFound; + int genenum = Reweight::kNoDialFound; switch (type) { case kNEUT: genenum = NEUTEnumFromName(name); break; case kNIWG: genenum = NIWGEnumFromName(name); break; case kNUWRO: genenum = NUWROEnumFromName(name); break; case kGENIE: genenum = GENIEEnumFromName(name); break; case kT2K: genenum = T2KEnumFromName(name); break; case kCUSTOM: genenum = CustomEnumFromName(name); break; case kNORM: - case kMODENORM: case kLIKEWEIGHT: case kSPLINEPARAMETER: case kNEWSPLINE: genenum = NUISANCEEnumFromName(name, type); break; case kOSCILLATION: genenum = OscillationEnumFromName(name); break; + case kMODENORM: + genenum = ModeNormEngine::SystEnumFromString(name); + break; + default: - genenum = kNoTypeFound; + genenum = Reweight::kNoTypeFound; break; } // Throw if required. if (exceptions) { // If Not Enabled - if (genenum == kGeneratorNotBuilt) { + if (genenum == Reweight::kGeneratorNotBuilt) { ERR(FTL) << "RW Engine not supported for " << FitBase::ConvDialType(type) << std::endl; ERR(FTL) << "Check dial " << name << std::endl; throw; } // If no type enabled - if (genenum == kNoTypeFound) { + if (genenum == Reweight::kNoTypeFound) { ERR(FTL) << "Type mismatch inside ConvDialEnum" << std::endl; throw; } // If Not Found - if (genenum == kNoDialFound) { + if (genenum == Reweight::kNoDialFound) { ERR(FTL) << "Dial " << name << " not found." << std::endl; throw; } } // Add offset if no issue int nuisenum = genenum; - if (genenum != kGeneratorNotBuilt and genenum != kNoTypeFound and - genenum != kNoDialFound) { + if ((genenum != Reweight::kGeneratorNotBuilt) && + (genenum != Reweight::kNoTypeFound) && + (genenum != Reweight::kNoDialFound)) { nuisenum += offset; } // Now register dial - // std::cout << "Returning " << nuisenum << std::endl; Reweight::DialList().RegisterDialEnum(name, type, nuisenum); return nuisenum; } std::string Reweight::ConvDial(int nuisenum) { - // GlobalDialList* temp; for (size_t i = 0; i < Reweight::DialList().fAllDialEnums.size(); i++) { if (Reweight::DialList().fAllDialEnums[i] == nuisenum) { return Reweight::DialList().fAllDialNames[i]; } } LOG(FIT) << "Cannot find dial with enum = " << nuisenum << std::endl; return ""; } diff --git a/src/Reweight/WeightUtils.h b/src/Reweight/WeightUtils.h index 52cf634..c7b044f 100644 --- a/src/Reweight/WeightUtils.h +++ b/src/Reweight/WeightUtils.h @@ -1,144 +1,63 @@ #ifndef WEIGHTUTILS_H #define WEIGHTUTILS_H #include "FitEvent.h" -#include "FitLogger.h" #include "TF1.h" -#ifdef __T2KREW_ENABLED__ -#include "T2KGenieReWeight.h" -#include "T2KNIWGReWeight.h" -#include "T2KNIWGUtils.h" -#include "T2KNeutReWeight.h" -#include "T2KNeutUtils.h" -#include "T2KReWeight.h" -using namespace t2krew; -#endif - -#ifdef __NIWG_ENABLED__ -#include "NIWGReWeight.h" -#include "NIWGReWeight1piAngle.h" -#include "NIWGReWeight2010a.h" -#include "NIWGReWeight2012a.h" -#include "NIWGReWeight2014a.h" -#include "NIWGReWeightDeltaMass.h" -#include "NIWGReWeightEffectiveRPA.h" -#include "NIWGReWeightHadronMultSwitch.h" -#include "NIWGReWeightMEC.h" -#include "NIWGReWeightPiMult.h" -#include "NIWGReWeightProtonFSIbug.h" -#include "NIWGReWeightRPA.h" -#include "NIWGReWeightSpectralFunc.h" -#include "NIWGReWeightSplineEnu.h" -#include "NIWGSyst.h" -#include "NIWGSystUncertainty.h" -#endif - -#ifdef __NEUT_ENABLED__ -#include "NReWeight.h" -#include "NReWeightCasc.h" -#include "NReWeightNuXSecCCQE.h" -#include "NReWeightNuXSecCCRES.h" -#include "NReWeightNuXSecCOH.h" -#include "NReWeightNuXSecDIS.h" -#include "NReWeightNuXSecNC.h" -#include "NReWeightNuXSecNCEL.h" -#include "NReWeightNuXSecNCRES.h" -#include "NReWeightNuXSecRES.h" -#include "NReWeightNuclPiless.h" -#include "NSyst.h" -#include "NSystUncertainty.h" -#include "neutpart.h" -#include "neutvect.h" -#endif - -#ifdef __NUWRO_ENABLED__ -#include "event1.h" -#endif - -#ifdef __NUWRO_REWEIGHT_ENABLED__ -#include "NuwroReWeight.h" -#include "NuwroReWeight_FlagNorm.h" -#include "NuwroReWeight_QEL.h" -#include "NuwroReWeight_SPP.h" -#include "NuwroSyst.h" -#include "NuwroSystUncertainty.h" -#endif - -#ifdef __GENIE_ENABLED__ -#include "EVGCore/EventRecord.h" -#include "EVGCore/EventRecord.h" -#include "GHEP/GHepRecord.h" -#include "GSyst.h" -#include "GSystUncertainty.h" -#include "Ntuple/NtpMCEventRecord.h" -#include "ReWeight/GReWeight.h" -#include "ReWeight/GReWeightAGKY.h" -#include "ReWeight/GReWeightDISNuclMod.h" -#include "ReWeight/GReWeightFGM.h" -#include "ReWeight/GReWeightFZone.h" -#include "ReWeight/GReWeightINuke.h" -#include "ReWeight/GReWeightNonResonanceBkg.h" -#include "ReWeight/GReWeightNuXSecCCQE.h" -#include "ReWeight/GReWeightNuXSecCCQEvec.h" -#include "ReWeight/GReWeightNuXSecCCRES.h" -#include "ReWeight/GReWeightNuXSecCOH.h" -#include "ReWeight/GReWeightNuXSecDIS.h" -#include "ReWeight/GReWeightNuXSecNC.h" -#include "ReWeight/GReWeightNuXSecNCEL.h" -#include "ReWeight/GReWeightNuXSecNCRES.h" -#include "ReWeight/GReWeightResonanceDecay.h" -using namespace genie; -using namespace genie::rew; -#endif - -#include "GlobalDialList.h" -#include "NUISANCESyst.h" - -enum extra_reweight_types { kOSCILLATION = kLast_generator_event_type }; +enum extra_reweight_types { + kOSCILLATION = kLast_generator_event_type, + kMODENORM +}; namespace FitBase { -TF1 GetRWConvFunction(std::string type, std::string name); -std::string GetRWUnits(std::string type, std::string name); +TF1 GetRWConvFunction(std::string const &type, std::string const &name); +std::string GetRWUnits(std::string const &type, std::string const &name); -double RWSigmaToFrac(std::string type, std::string name, double val); -double RWSigmaToAbs(std::string type, std::string name, double val); -double RWAbsToSigma(std::string type, std::string name, double val); -double RWFracToSigma(std::string type, std::string name, double val); +double RWSigmaToFrac(std::string const &type, std::string const &name, + double val); +double RWSigmaToAbs(std::string const &type, std::string const &name, + double val); +double RWAbsToSigma(std::string const &type, std::string const &name, + double val); +double RWFracToSigma(std::string const &type, std::string const &name, + double val); -int ConvDialType(std::string type); +int ConvDialType(std::string const &type); std::string ConvDialType(int type); -int GetDialEnum(std::string type, std::string name); -int GetDialEnum(int type, std::string name); +int GetDialEnum(std::string const &type, std::string const &name); +int GetDialEnum(int type, std::string const &name); static std::map gNormEnums; static std::map gLikeWeightEnums; static std::map gSplineParameterEnums; } namespace Reweight { -int ConvDial(std::string name, std::string type, bool exceptions = false); -int ConvDial(std::string name, int type, bool exceptions = false); +int ConvDial(std::string const &name, std::string const &type, + bool exceptions = false); +int ConvDial(std::string const &name, int type, bool exceptions = false); std::string ConvDial(int nuisenum); -int ConvDialType(std::string type); +int ConvDialType(std::string const &type); std::string ConvDialType(int type); - -int NEUTEnumFromName(std::string name); -int NIWGEnumFromName(std::string name); -int NUWROEnumFromName(std::string name); -int T2KEnumFromName(std::string name); -int GENIEEnumFromName(std::string name); -int CustomEnumFromName(std::string name); - -int NUISANCEEnumFromName(std::string name, int type); -int OscillationEnumFromName(std::string name); +int GetDialType(int type); +int RemoveDialType(int type); + +int NEUTEnumFromName(std::string const &name); +int NIWGEnumFromName(std::string const &name); +int NUWROEnumFromName(std::string const &name); +int T2KEnumFromName(std::string const &name); +int GENIEEnumFromName(std::string const &name); +int CustomEnumFromName(std::string const &name); + +int NUISANCEEnumFromName(std::string const &name, int type); +int OscillationEnumFromName(std::string const &name); static const int kNoDialFound = -1; static const int kNoTypeFound = -2; static const int kGeneratorNotBuilt = -3; } #endif