diff --git a/CMakeLists.txt b/CMakeLists.txt index 284f985..068cf84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,190 +1,196 @@ # 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 . ################################################################################ cmake_minimum_required (VERSION 2.6 FATAL_ERROR) project(NUISANCE) include(ExternalProject) enable_language(Fortran) set (NUISANCE_VERSION_MAJOR 1) set (NUISANCE_VERSION_MINOR 0) set (NUISANCE_VERSION_REVISION 0) set (NUISANCE_VERSION_STRING "v${NUISANCE_VERSION_MAJOR}r${NUISANCE_VERSION_MINOR}") if(${NUISANCE_VERSION_REVISION} STRGREATER "0") set (NUISANCE_VERSION_STRING "${NUISANCE_VERSION_STRING}p${NUISANCE_VERSION_REVISION}") endif() #Set this to TRUE to enable build debugging messages set(BUILD_DEBUG_MSGS TRUE) include(${CMAKE_SOURCE_DIR}/cmake/cmessage.cmake) include(${CMAKE_SOURCE_DIR}/cmake/cacheVariables.cmake) cmessage(STATUS "CMAKE_INSTALL_PREFIX: \"${CMAKE_INSTALL_PREFIX}\"") cmessage(STATUS "CMAKE_BUILD_TYPE: \"${CMAKE_BUILD_TYPE}\"") ################################################################################ # Check Dependencies ################################################################################ ################################## ROOT ###################################### include(${CMAKE_SOURCE_DIR}/cmake/ROOTSetup.cmake) ################################# HEPMC ###################################### include(${CMAKE_SOURCE_DIR}/cmake/HepMC.cmake) ############################ Reweight Engines ################################ include(${CMAKE_SOURCE_DIR}/cmake/ReweightEnginesSetup.cmake) ############################ Other Generators ################################ include(${CMAKE_SOURCE_DIR}/cmake/GiBUUSetup.cmake) if(USE_NUANCE) LIST(APPEND EXTRA_CXX_FLAGS -D__NUANCE_ENABLED__) endif() ################################# Pythia6/8 #################################### include(${CMAKE_SOURCE_DIR}/cmake/pythia6Setup.cmake) include(${CMAKE_SOURCE_DIR}/cmake/pythia8Setup.cmake) ################################# gperftools ################################### include(${CMAKE_SOURCE_DIR}/cmake/gperfSetup.cmake) if(NOT NOTEST) enable_testing() endif() SET(GENERATOR_SUPPORT) foreach(gen NEUT;NuWro;GENIE;GiBUU;NUANCE) if(USE_${gen}) SET(GENERATOR_SUPPORT "${GENERATOR_SUPPORT}${gen} ") endif() endforeach(gen) cmessage(STATUS "Generator Input Support: ${GENERATOR_SUPPORT}") set(MINCODE Routines FCN) set(CORE MCStudies Genie FitBase + Config + Logger + Statistical InputHandler Splines - Reweight + Reweight Utils #Devel Smearceptance ) LIST(APPEND ALLEXPERIMENTS ANL ArgoNeuT BEBC BNL Electron FNAL GGM K2K MINERvA MiniBooNE SciBooNE T2K) foreach(exp ${ALLEXPERIMENTS}) if(NOT NO_${exp}) LIST(APPEND EXPERIMENTS_TO_BUILD ${exp}) else() LIST(REVERSE EXTRA_CXX_FLAGS) LIST(APPEND EXTRA_CXX_FLAGS -D__NO_${exp}__) LIST(REVERSE EXTRA_CXX_FLAGS) endif() endforeach() ################################## COMPILER #################################### include(${CMAKE_SOURCE_DIR}/cmake/c++CompilerSetup.cmake) ################################### doxygen ################################### include(${CMAKE_SOURCE_DIR}/cmake/docsSetup.cmake) ################################################################################ set(MINIMUM_INCLUDE_DIRECTORIES) LIST(APPEND MINIMUM_INCLUDE_DIRECTORIES ${RWENGINE_INCLUDE_DIRECTORIES} ${CMAKE_SOURCE_DIR}/src/FitBase ${CMAKE_SOURCE_DIR}/src/Reweight ${CMAKE_SOURCE_DIR}/src/InputHandler + ${CMAKE_SOURCE_DIR}/src/Config + ${CMAKE_SOURCE_DIR}/src/Logger + ${CMAKE_SOURCE_DIR}/src/Statistical ${CMAKE_SOURCE_DIR}/src/Splines ${CMAKE_SOURCE_DIR}/src/Utils ${CMAKE_SOURCE_DIR}/src/Genie) cmessage(DEBUG "Base include directories: ${MINIMUM_INCLUDE_DIRECTORIES}") set(EXP_INCLUDE_DIRECTORIES) foreach(edir ${EXPERIMENTS_TO_BUILD}) LIST(APPEND EXP_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src/${edir}) endforeach() cmessage(DEBUG "Included experiments: ${EXP_INCLUDE_DIRECTORIES}") foreach(mdir ${MINCODE}) cmessage (DEBUG "Configuring directory: src/${mdir}") add_subdirectory(src/${mdir}) endforeach() foreach(edir ${EXPERIMENTS_TO_BUILD}) cmessage (DEBUG "Configuring directory: src/${edir}") add_subdirectory(src/${edir}) endforeach() foreach(cdir ${CORE}) cmessage (DEBUG "Configuring directory: src/${cdir}") add_subdirectory(src/${cdir}) endforeach() cmessage(DEBUG "Module targets: ${MODULETargets}") add_subdirectory(app) add_subdirectory(src/Tests) configure_file(cmake/setup.sh.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.sh" @ONLY) install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.sh" DESTINATION ${CMAKE_INSTALL_PREFIX}) install(PROGRAMS "${PROJECT_SOURCE_DIR}/scripts/nuiscardgen" DESTINATION bin) install(PROGRAMS "${PROJECT_SOURCE_DIR}/scripts/nuissamples" DESTINATION bin) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 878957e..e4e2350 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,201 +1,217 @@ # 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 . ################################################################################ set(TARGETS_TO_BUILD) if(USE_MINIMIZER) add_executable(nuismin nuismin.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuismin) target_link_libraries(nuismin ${MODULETargets}) target_link_libraries(nuismin ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuismin ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuismin PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(nuissplines nuissplines.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissplines) target_link_libraries(nuissplines ${MODULETargets}) target_link_libraries(nuissplines ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuissplines ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuissplines PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() include_directories(${RWENGINE_INCLUDE_DIRECTORIES}) include_directories(${CMAKE_SOURCE_DIR}/src/Routines) include_directories(${CMAKE_SOURCE_DIR}/src/InputHandler) include_directories(${CMAKE_SOURCE_DIR}/src/Genie) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) include_directories(${CMAKE_SOURCE_DIR}/src/Utils) +include_directories(${CMAKE_SOURCE_DIR}/src/Config) +include_directories(${CMAKE_SOURCE_DIR}/src/Logger) +include_directories(${CMAKE_SOURCE_DIR}/src/Statistical) include_directories(${CMAKE_SOURCE_DIR}/src/Splines) include_directories(${CMAKE_SOURCE_DIR}/src/Reweight) include_directories(${CMAKE_SOURCE_DIR}/src/FCN) include_directories(${CMAKE_SOURCE_DIR}/src/MCStudies) include_directories(${CMAKE_SOURCE_DIR}/src/Smearceptance) include_directories(${EXP_INCLUDE_DIRECTORIES}) if (USE_NuWro AND NOT NUWRO_BUILT_FROM_FILE) add_executable(nuwro_nuisance nuwro_NUISANCE.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuwro_nuisance) target_link_libraries(nuwro_nuisance ${MODULETargets}) target_link_libraries(nuwro_nuisance ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuwro_nuisance ${ROOT_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuwro_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() if (USE_NEUT) add_executable(neut_nuisance neut_NUISANCE.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};neut_nuisance) target_link_libraries(neut_nuisance ${MODULETargets}) target_link_libraries(neut_nuisance ${CMAKE_DEPENDLIB_FLAGS}) target_link_libraries(neut_nuisance ${ROOT_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(neut_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() if (BUILD_GEVGEN) add_executable(gevgen_nuisance gEvGen_NUISANCE.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};gevgen_nuisance) target_link_libraries(gevgen_nuisance ${MODULETargets}) target_link_libraries(gevgen_nuisance ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(gevgen_nuisance ${ROOT_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) include_directories(${GENIE_INCLUDES}/Apps) include_directories(${GENIE_INCLUDES}/FluxDrivers) include_directories(${GENIE_INCLUDES}/EVGDrivers) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(gevgen_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(gevgen_nuisance_mixed gEvGen_NUISANCE_MIXED.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};gevgen_nuisance_mixed) target_link_libraries(gevgen_nuisance_mixed ${MODULETargets}) target_link_libraries(gevgen_nuisance_mixed ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(gevgen_nuisance_mixed ${ROOT_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) include_directories(${GENIE_INCLUDES}/Apps) include_directories(${GENIE_INCLUDES}/FluxDrivers) include_directories(${GENIE_INCLUDES}/EVGDrivers) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(gevgen_nuisance_mixed PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() if (USE_GiBUU) add_executable(DumpGiBUUEvents DumpGiBUUEvents.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};DumpGiBUUEvents) target_link_libraries(DumpGiBUUEvents ${MODULETargets}) target_link_libraries(DumpGiBUUEvents ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(DumpGiBUUEvents ${ROOT_LIBS}) include_directories(${CMAKE_SOURCE_DIR}/src/FitBase) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(DumpGiBUUEvents PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() add_executable(nuiscomp nuiscomp.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuiscomp) target_link_libraries(nuiscomp ${MODULETargets}) target_link_libraries(nuiscomp ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuiscomp ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuiscomp PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(nuisflat nuisflat.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuisflat) target_link_libraries(nuisflat ${MODULETargets}) target_link_libraries(nuisflat ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuisflat ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuisflat PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(nuissmear nuissmear.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissmear) target_link_libraries(nuissmear ${MODULETargets}) target_link_libraries(nuissmear ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuissmear ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuissmear PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(nuissyst nuissyst.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissyst) target_link_libraries(nuissyst ${MODULETargets}) target_link_libraries(nuissyst ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuissyst ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuissyst PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() add_executable(nuisbayes nuisbayes.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuisbayes) target_link_libraries(nuisbayes ${MODULETargets}) target_link_libraries(nuisbayes ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(nuisbayes ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuisbayes PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() if(USE_GENIE) add_executable(PrepareGENIE PrepareGENIE.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareGENIE) target_link_libraries(PrepareGENIE ${MODULETargets}) target_link_libraries(PrepareGENIE ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(PrepareGENIE ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(PrepareGENIE PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() if(USE_NEUT) add_executable(PrepareNEUT PrepareNEUT.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareNEUT) target_link_libraries(PrepareNEUT ${MODULETargets}) target_link_libraries(PrepareNEUT ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(PrepareNEUT ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(PrepareNEUT PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() # PREPARE NUWRO # Commented out for the time being until it is finished.. if(USE_NuWro) add_executable(PrepareNuwro PrepareNuwroEvents.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareNuwro) target_link_libraries(PrepareNuwro ${MODULETargets}) target_link_libraries(PrepareNuwro ${CMAKE_DEPENDLIB_FLAGS}) # target_link_libraries(PrepareNuwro ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(PrepareNuwro PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() install(TARGETS ${TARGETS_TO_BUILD} DESTINATION bin) + +#add_executable(DumpROOTClassesFromVector DumpROOTClassesFromVector.cxx) +# #Strip out -lNuWro_event1 +# string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${CMAKE_DEPENDLIB_FLAGS}) +# cmessage(DEBUG "Attempted to strip out nuwro library: \"${CMAKE_DEPENDLIB_FLAGS}\" -> \"${NWEVSTRIPPED_CDF}\"") +# add_executable(PrepareNEUT PrepareNEUT.cxx) +# target_link_libraries(DumpROOTClassesFromVector ${MODULETargets}) +# target_link_libraries(DumpROOTClassesFromVector ${NWEVSTRIPPED_CDF}) +# if(NOT CMAKE_LINK_FLAGS STREQUAL "") +# set_target_properties(DumpROOTClassesFromVector PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) +# endif() +#install(TARGETS DumpROOTClassesFromVector DESTINATION bin) + diff --git a/src/Utils/DumpROOTClassesFromVector.cxx b/app/DumpROOTClassesFromVector.cxx similarity index 100% rename from src/Utils/DumpROOTClassesFromVector.cxx rename to app/DumpROOTClassesFromVector.cxx diff --git a/src/FitBase/CMakeLists.txt b/src/Config/CMakeLists.txt similarity index 73% copy from src/FitBase/CMakeLists.txt copy to src/Config/CMakeLists.txt index 543bcb2..7577b9d 100644 --- a/src/FitBase/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -1,72 +1,52 @@ # 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 . ################################################################################ -set(IMPLFILES -ParamPull.cxx -EventManager.cxx -Measurement1D.cxx -Measurement2D.cxx -JointMeas1D.cxx -MeasurementBase.cxx -TemplateMeas1D.cxx -SampleSettings.cxx -MeasurementVariableBox.cxx -MeasurementVariableBox2D.cxx -MeasurementVariableBox1D.cxx -CustomVariableBoxes.h +set(HEADERFILES +NuisConfig.h +NuisKey.h ) -set(HEADERFILES -ParamPull.h -JointMeas1D.h -Measurement2D.h -EventManager.h -MeasurementBase.h -Measurement1D.h -TemplateMeas1D.h -SampleSettings.h -MeasurementVariableBox.h -MeasurementVariableBox2D.h -MeasurementVariableBox1D.h -CustomVariableBoxes.h +set(IMPLFILES +NuisConfig.cxx +NuisKey.cxx ) -set(LIBNAME FitBase) +set(LIBNAME Config) if(CMAKE_BUILD_TYPE MATCHES DEBUG) add_library(${LIBNAME} STATIC ${IMPLFILES}) else(CMAKE_BUILD_TYPE MATCHES RELEASE) add_library(${LIBNAME} SHARED ${IMPLFILES}) endif() include_directories(${MINIMUM_INCLUDE_DIRECTORIES}) -cmessage(DEBUG "FitBase includes: ${MINIMUM_INCLUDE_DIRECTORIES}") set_target_properties(${LIBNAME} PROPERTIES VERSION "${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}") + #set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS}) if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES) add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES}) endif() install(TARGETS ${LIBNAME} DESTINATION lib) #Can uncomment this to install the headers... but is it really neccessary? -install(FILES ${HEADERFILES} DESTINATION include) +#install(FILES ${HEADERFILES} DESTINATION include) set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE) diff --git a/src/Utils/NuisConfig.cxx b/src/Config/NuisConfig.cxx similarity index 99% rename from src/Utils/NuisConfig.cxx rename to src/Config/NuisConfig.cxx index a9f4e80..f015dc6 100644 --- a/src/Utils/NuisConfig.cxx +++ b/src/Config/NuisConfig.cxx @@ -1,788 +1,783 @@ // 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 . *******************************************************************************/ #include "NuisConfig.h" #include "TXMLEngine.h" #include "GeneralUtils.h" #include "FitLogger.h" -#include "GeneralUtils.h" namespace Config { -nuisconfig& Get() { return nuisconfig::GetConfig(); }; +nuisconfig& Get() { + return nuisconfig::GetConfig(); +}; std::string GetPar(std::string name) { return Get().GetConfig(name); } int GetParI(std::string name) { return Get().GetConfigI(name); } bool GetParB(std::string name) { return Get().GetConfigB(name); } +float GetParF(std::string name) { + return Get().GetConfigF(name); +} double GetParD(std::string name) { return Get().GetConfigD(name); } void SetPar(std::string name, std::string val) { Get().SetConfig(name, val); } void SetPar(std::string name, bool val) { Get().SetConfig(name, val); } void SetPar(std::string name, int val) { Get().SetConfig(name, val); } void SetPar(std::string name, float val) { Get().SetConfig(name, val); } void SetPar(std::string name, double val) { Get().SetConfig(name, val); } + } +namespace FitPar { + std::string GetDataBase() { return GeneralUtils::GetTopLevelDir() + "/data/"; }; + nuisconfig& Config() { return Config::Get(); }; +} nuisconfig* nuisconfig::m_nuisconfigInstance = NULL; nuisconfig& nuisconfig::GetConfig(void) { if (!m_nuisconfigInstance) m_nuisconfigInstance = new nuisconfig; return *m_nuisconfigInstance; }; // Main Class Definition nuisconfig::nuisconfig() { // Load default Parameters std::string filename = (GeneralUtils::GetTopLevelDir() + "/parameters/config.xml"); std::cout << "[ NUISANCE ]: Loading DEFAULT settings from : " << filename; // Create XML Engine fXML = new TXMLEngine; fXML->SetSkipComments(true); // Load in documents fXMLDocs.push_back(fXML->ParseFile(filename.c_str(), 1000000)); if (!fXMLDocs[0]) { THROW("Cannot Read Parameters File!"); } // Setup Main XML Node to be the first file read fMainNode = fXML->DocGetRootElement(fXMLDocs[0]); // Print result std::cout << " -> DONE." << std::endl; } nuisconfig::~nuisconfig() { // Should really delete XML objects here but we don't } void nuisconfig::LoadSettings(std::string filename, std::string state) { // Open file and see if its XML std::cout << "[ NUISANCE ]: Trying to parse file : " << filename; StopTalking(); XMLDocPointer_t readdoc = fXML->ParseFile(filename.c_str(), 1000000); StartTalking(); // If it is parse it as a nice XML config file if (readdoc) { std::cout << " -> Found XML file." << std::endl; LoadXMLSettings(filename, state); // Otherwise its an old simple card file } else { std::cout << " -> Assuming its a simple card file." << std::endl; LoadCardSettings(filename, state); } } void nuisconfig::LoadXMLSettings(std::string filename, std::string state = "") { std::cout << "[ NUISANCE ]: Loading XML settings from : " << filename; // Add new file to xml docs list fXMLDocs.push_back(fXML->ParseFile(filename.c_str(), 1000000)); // Get New Doc ROOT int nxml = fXMLDocs.size(); XMLNodePointer_t newdocroot = fXML->DocGetRootElement(fXMLDocs[nxml - 1]); // Loop over children and add XMLNodePointer_t child = fXML->GetChild(newdocroot); // // Here we manually load all the children from the card file into our root node if (!child){ THROW("CANNOT Find child inside settings file!"); } while (child != 0) { // SPECIAL CONFIG CASE // If its a config node, then remove previous attributes, overriding old value if (!std::string(fXML->GetNodeName(child)).compare("config")) { // Loop over attribues XMLAttrPointer_t attr1 = fXML->GetFirstAttr(child); while (attr1 != 0) { // If a valid attribute name is given then compare if (!GetConfigS(fXML->GetAttrName(attr1)).empty()) { // Get full list of present configs std::vector confignodes = GetNodes("config"); // Loop over present configs and compare for (size_t i = 0; i < confignodes.size(); i++) { // If we already have this config, free the old attribute if (fXML->HasAttr(confignodes[i], fXML->GetAttrName(attr1))) { fXML->FreeAttr(confignodes[i], fXML->GetAttrName(attr1)); break; } } } // Move onto next config attribute attr1 = fXML->GetNextAttr(attr1); } } // Add this child to the main config list fXML->AddChild(fMainNode, child); // Get Next Child child = fXML->GetNext(child); } std::cout << " -> DONE." << std::endl; } void nuisconfig::LoadCardSettings(std::string filename, std::string state) { std::cout << "[ NUISANCE ]: Loading simple config from : " << filename; // Build XML Config from the card file by parsing each line std::vector cardlines = GeneralUtils::ParseFileToStr(filename, "\n"); int linecount = 0; // Loop over all input lines for (std::vector::iterator iter = cardlines.begin(); iter != cardlines.end(); iter++) { std::string line = (*iter); linecount++; // Skip Comments if (line.empty()) continue; if (line.c_str()[0] == '#') continue; // Parse whitespace std::vector strvct = GeneralUtils::ParseToStr(line, " "); if (strvct.empty()) continue; // Get Identifier std::string id = strvct[0]; // Build backwards compatible xml configs // Sample structure if (!id.compare("sample")) { CreateSampleNodeFromLine(line); } // Any parameter structure if (id.find("_parameter") != std::string::npos) { CreateParameterNodeFromLine(line); } // Any covar structure if (!id.compare("covar") || !id.compare("pull") || !id.compare("throw")) { CreatePullNodeFromLine(line); } // Any config structure if (!id.compare("config")) { CreateOldConfigNodeFromLine(line); } } std::cout << " -> DONE." << std::endl; } XMLNodePointer_t nuisconfig::CreateSampleNodeFromLine(const std::string line) { // Create new node entry XMLNodePointer_t samplenode = CreateNode("sample"); // Parse line std::vector strvct = GeneralUtils::ParseToStr(line, " "); // Add line elements to the node // name input type norm if (strvct.size() > 1) Set(samplenode, "name", strvct[1]); if (strvct.size() > 2) Set(samplenode, "input", strvct[2]); if (strvct.size() > 3) Set(samplenode, "type", strvct[3]); if (strvct.size() > 4) Set(samplenode, "norm", strvct[4]); return samplenode; } XMLNodePointer_t nuisconfig::CreateParameterNodeFromLine(const std::string line) { // Create new node entry XMLNodePointer_t parnode = CreateNode("parameter"); // Parse line std::vector strvct = GeneralUtils::ParseToStr(line, " "); // Add line elements to the node // type name nominal [low] [high] [step] state if (strvct.size() > 0) Set(parnode, "type", strvct[0]); if (strvct.size() > 1) Set(parnode, "name", strvct[1]); if (strvct.size() > 2) Set(parnode, "nominal", strvct[2]); // If free structure if (strvct.size() == 7) { Set(parnode, "low", strvct[3]); Set(parnode, "high", strvct[4]); Set(parnode, "step", strvct[5]); Set(parnode, "state", strvct[6]); // Fixed param structure } else if (strvct.size() == 3) { Set(parnode, "state", "FIX"); } else if (strvct.size() == 4) { Set(parnode, "state", strvct[3]); } return parnode; } XMLNodePointer_t nuisconfig::CreatePullNodeFromLine(const std::string line) { // Create new node entry XMLNodePointer_t parnode = CreateNode("covar"); // Parse line std::vector strvct = GeneralUtils::ParseToStr(line, " "); // Add line elements to the node // name input type if (strvct.size() > 1) Set(parnode, "name", strvct[1]); if (strvct.size() > 2) Set(parnode, "input", strvct[2]); if (strvct.size() > 3) Set(parnode, "type", strvct[3]); return parnode; } XMLNodePointer_t nuisconfig::CreateOldConfigNodeFromLine(const std::string line) { // Create new node entry XMLNodePointer_t confignode = CreateNode("config"); // Parse line std::vector strvct = GeneralUtils::ParseToStr(line, " "); // Add line elements to the node // name value if (strvct.size() > 2) Set(confignode, strvct[1], strvct[2]); return confignode; } void nuisconfig::FinaliseSettings(std::string name) { std::cout << "[ NUISANCE ]: Finalising run settings"; WriteSettings(name); // Save full config to file RemoveEmptyNodes(); RemoveIdenticalNodes(); std::cout << " -> DONE." << std::endl; } void nuisconfig::WriteSettings(std::string outputname) { // Create a New XML Doc XMLDocPointer_t newxmldoc = fXML->NewDoc(); fXML->DocSetRootElement(newxmldoc, fMainNode); // Save document to file if (GetConfigB("SaveParsedXMLFile")) { fXML->SaveDoc(newxmldoc, outputname.c_str()); } } - - - - - XMLNodePointer_t nuisconfig::CreateNode(std::string name) { return fXML->NewChild(fMainNode, 0, name.c_str()); } XMLNodePointer_t nuisconfig::CreateNode(XMLNodePointer_t node, std::string name) { return fXML->NewChild(node, 0, name.c_str()); } XMLNodePointer_t nuisconfig::GetNode(XMLNodePointer_t node, std::string type) { /// Loop over all children XMLNodePointer_t child = fXML->GetChild(node); while (child != 0) { /// Get nodes for given type (if type empty return all) if (std::string(fXML->GetNodeName(child)) == type.c_str() or type.empty()) { return child; } // Next child child = fXML->GetNext(child); } // Child not found return 0; } void nuisconfig::RemoveEmptyNodes() { std::vector nodelist = Config::Get().GetNodes(); for (size_t i = 0; i < nodelist.size(); i++) { if (fXML->IsEmptyNode(nodelist[i])) { RemoveNode(nodelist[i]); } } } void nuisconfig::RemoveIdenticalNodes() { std::vector removed; // Loop over all nodes and check for identical nodes std::vector nodelist = Config::Get().GetNodes(); for (size_t i = 0; i < nodelist.size(); i++) { for (size_t j = 0; j < nodelist.size(); j++) { XMLNodePointer_t node1 = nodelist[i]; XMLNodePointer_t node2 = nodelist[j]; // Check node already removed. if (std::find(removed.begin(), removed.end(), node1) != removed.end()) continue; if (std::find(removed.begin(), removed.end(), node2) != removed.end()) continue; if (i == j) continue; // Check matching if (!MatchingNodes(node1, node2)) continue; if (std::string(fXML->GetNodeName(node1)).compare("config") and fXML->IsEmptyNode(node1)) { // Matching so print out warning std::cout << "Matching nodes given! Removing node1!" << std::endl << "Node 1" << std::endl; PrintNode(node1); std::cout << "Node 2" << std::endl; PrintNode(node2); } // Remove node removed.push_back(node1); } } // Now go through and remove this node. for (size_t i = 0; i < removed.size(); i++) { RemoveNode(removed.at(i)); } return; } void nuisconfig::RemoveNode(XMLNodePointer_t node) { fXML->FreeAllAttr(node); fXML->CleanNode(node); fXML->FreeNode(node); fXML->UnlinkNode(node); } void nuisconfig::PrintNode(XMLNodePointer_t node) { // Print Node Name std::cout << fXML->GetNodeName(node) << std::endl; // Loop and print all attributes XMLAttrPointer_t attr = fXML->GetFirstAttr(node); while (attr != 0) { std::cout << " -> " << fXML->GetAttrName(attr) << " : " << fXML->GetAttrValue(attr) << std::endl; attr = fXML->GetNextAttr(attr); } } bool nuisconfig::MatchingNodes(XMLNodePointer_t node1, XMLNodePointer_t node2) { bool matching = true; XMLAttrPointer_t attr = fXML->GetFirstAttr(node1); while (attr != 0) { if (GetS(node2, fXML->GetAttrName(attr)) != fXML->GetAttrValue(attr)) matching = false; attr = fXML->GetNextAttr(attr); } return matching; } XMLNodePointer_t nuisconfig::GetNode(std::string type) { return GetNode(fMainNode, type); } std::vector nuisconfig::GetNodes(XMLNodePointer_t node, std::string type) { // Create new vector for nodes std::vector nodelist; /// Loop over all children XMLNodePointer_t child = fXML->GetChild(node); while (child != 0) { /// Get nodes for given type (if type empty return all) if (std::string(fXML->GetNodeName(child)) == type.c_str() or type.empty()) { nodelist.push_back(child); } // Next child child = fXML->GetNext(child); } // return list return nodelist; } std::vector nuisconfig::GetNodes(std::string type) { return GetNodes(fMainNode, type); } void nuisconfig::Set(XMLNodePointer_t node, std::string name, std::string val) { // Remove and re-add attribute if (fXML->HasAttr(node, name.c_str())) { fXML->FreeAttr(node, name.c_str()); } fXML->NewAttr(node, 0, name.c_str(), val.c_str()); } void nuisconfig::Set(XMLNodePointer_t node, std::string name, bool val) { Set(node, name, GeneralUtils::BoolToStr(val)); } void nuisconfig::Set(XMLNodePointer_t node, std::string name, int val) { Set(node, name, GeneralUtils::IntToStr(val)); } void nuisconfig::Set(XMLNodePointer_t node, std::string name, float val) { Set(node, name, GeneralUtils::DblToStr(val)); } void nuisconfig::Set(XMLNodePointer_t node, std::string name, double val) { Set(node, name, GeneralUtils::DblToStr(val)); } void nuisconfig::SetS(XMLNodePointer_t node, std::string name, std::string val) { Set(node, name, val); } void nuisconfig::SetB(XMLNodePointer_t node, std::string name, bool val) { Set(node, name, GeneralUtils::BoolToStr(val)); } void nuisconfig::SetI(XMLNodePointer_t node, std::string name, int val) { Set(node, name, GeneralUtils::IntToStr(val)); } void nuisconfig::SetF(XMLNodePointer_t node, std::string name, float val) { Set(node, name, GeneralUtils::DblToStr(val)); } void nuisconfig::SetD(XMLNodePointer_t node, std::string name, double val) { Set(node, name, GeneralUtils::DblToStr(val)); } bool nuisconfig::Has(XMLNodePointer_t node, std::string name) { // If node empty return empty if (node == 0) return false; // Search attributes XMLAttrPointer_t attr = fXML->GetFirstAttr(node); bool found = false; // Loop over all attributes while (attr != 0) { // Find value of correct name if (std::string(fXML->GetAttrName(attr)) == name.c_str()) { found = true; break; } // Next Attribute attr = fXML->GetNextAttr(attr); } return found; } std::string nuisconfig::Get(XMLNodePointer_t node, std::string name) { // If node empty return empty if (node == 0) return ""; // Get Attribute from child with name XMLAttrPointer_t attr = fXML->GetFirstAttr(node); std::string temp = ""; // Loop over all attributes while (attr != 0) { // If valid match then save if (std::string(fXML->GetAttrName(attr)) == name.c_str()) { temp = fXML->GetAttrValue(attr); } // Next Attribute attr = fXML->GetNextAttr(attr); } return temp; } std::string nuisconfig::GetS(XMLNodePointer_t node, std::string name) { return Get(node, name); } bool nuisconfig::GetB(XMLNodePointer_t node, std::string name) { std::string tempattr = Get(node, name); return GeneralUtils::StrToBool(tempattr); } int nuisconfig::GetI(XMLNodePointer_t node, std::string name) { std::string tempattr = Get(node, name); return GeneralUtils::StrToInt(tempattr); } float nuisconfig::GetF(XMLNodePointer_t node, std::string name) { std::string tempattr = Get(node, name); return GeneralUtils::StrToDbl(tempattr); } double nuisconfig::GetD(XMLNodePointer_t node, std::string name) { std::string tempattr = Get(node, name); return GeneralUtils::StrToDbl(tempattr); } std::vector nuisconfig::GetVS(XMLNodePointer_t node, std::string name, const char* del) { std::string tempattr = Get(node, name); return GeneralUtils::ParseToStr(tempattr, del); } // std::vector nuisconfig::GetVB(XMLNodePointer_t node, // std::string name, // const char* del) { // std::string tempattr = Get(node, name); // return GeneralUtils::ParseToBool(tempattr, del); // } std::vector nuisconfig::GetVI(XMLNodePointer_t node, std::string name, const char* del) { std::string tempattr = Get(node, name); return GeneralUtils::ParseToInt(tempattr, del); } // std::vector nuisconfig::GetVF(XMLNodePointer_t node, // std::string name, // const char* del) { // std::string tempattr = Get(node, name); // return GeneralUtils::ParseToDouble(tempattr, del); // } std::vector nuisconfig::GetVD(XMLNodePointer_t node, std::string name, const char* del) { std::string tempattr = Get(node, name); return GeneralUtils::ParseToDbl(tempattr, del); } std::vector nuisconfig::GetAllKeysForNode(XMLNodePointer_t node) { bool matching = true; XMLAttrPointer_t attr = fXML->GetFirstAttr(node); std::vector keys; while (attr != 0) { if (!std::string(fXML->GetAttrName(attr)).empty()) { keys.push_back(std::string(fXML->GetAttrName(attr))); } attr = fXML->GetNextAttr(attr); } return keys; } XMLNodePointer_t nuisconfig::GetConfigNode(std::string name) { // Loop over children and look for name XMLNodePointer_t child = fXML->GetChild(fMainNode); while (child != 0) { // Select only config parameters if (!std::string(fXML->GetNodeName(child)).compare("config")) { // Loop over config attributes and search for name XMLAttrPointer_t attr = fXML->GetFirstAttr(child); while (attr != 0) { // Save name value if (std::string(fXML->GetAttrName(attr)) == name.c_str()) { return child; } // Get Next Attribute attr = fXML->GetNextAttr(attr); } } // Next Child child = fXML->GetNext(child); } return 0; } void nuisconfig::SetConfig(std::string name, std::string val) { XMLNodePointer_t node = GetConfigNode(name); if (!node) node = CreateNode("config"); Set(node, name, val); } void nuisconfig::SetConfig(std::string name, bool val) { XMLNodePointer_t node = GetConfigNode(name); if (!node) node = CreateNode("config"); Set(node, name, val); } void nuisconfig::SetConfig(std::string name, int val) { XMLNodePointer_t node = GetConfigNode(name); if (!node) node = CreateNode("config"); Set(node, name, val); } void nuisconfig::SetConfig(std::string name, float val) { XMLNodePointer_t node = GetConfigNode(name); if (!node) node = CreateNode("config"); Set(node, name, val); } void nuisconfig::SetConfig(std::string name, double val) { XMLNodePointer_t node = GetConfigNode(name); if (!node) node = CreateNode("config"); Set(node, name, val); } void nuisconfig::OverrideConfig(std::string conf) { std::vector opts = GeneralUtils::ParseToStr(conf, "="); SetConfig(opts[0], opts[1]); } std::string nuisconfig::GetConfig(std::string name) { XMLNodePointer_t node = GetConfigNode(name); if (!node) return ""; XMLAttrPointer_t attr = fXML->GetFirstAttr(node); std::string temp = ""; // Loop config attributes while (attr != 0) { // Find match if (std::string(fXML->GetAttrName(attr)) == name.c_str()) { temp = fXML->GetAttrValue(attr); } // Get Next Attribute attr = fXML->GetNextAttr(attr); } return temp; } std::string nuisconfig::GetConfigS(const std::string name) { return GetConfig(name); } bool nuisconfig::GetConfigB(const std::string name) { std::string pars = GetConfig(name); return GeneralUtils::StrToBool(pars); } int nuisconfig::GetConfigI(const std::string name) { std::string pars = GetConfig(name); return GeneralUtils::StrToInt(pars); } float nuisconfig::GetConfigF(const std::string name) { std::string pars = GetConfig(name); return GeneralUtils::StrToDbl(pars); } double nuisconfig::GetConfigD(const std::string name) { std::string pars = GetConfig(name); return GeneralUtils::StrToDbl(pars); } std::string nuisconfig::GetParDIR(std::string parName) { std::string outstr = this->GetParS(parName); // Make replacements in the string const int nfiletypes = 2; const std::string filetypes[nfiletypes] = {"@data", "@nuisance"}; std::string filerepl[nfiletypes] = { FitPar::GetDataBase(), FitPar::GetDataBase() + "/../" }; for (int i = 0; i < nfiletypes; i++) { std::string findstring = filetypes[i]; std::string replstring = filerepl[i]; if (outstr.find(findstring) != std::string::npos) { outstr.replace(outstr.find(findstring), findstring.size(), filerepl[i]); break; } } return outstr; }; - - - -namespace FitPar { - std::string GetDataBase() { return GeneralUtils::GetTopLevelDir() + "/data/"; }; - nuisconfig& Config() { return Config::Get(); }; -} - - diff --git a/src/Utils/NuisConfig.h b/src/Config/NuisConfig.h similarity index 71% rename from src/Utils/NuisConfig.h rename to src/Config/NuisConfig.h index bd2cf9b..1d93029 100644 --- a/src/Utils/NuisConfig.h +++ b/src/Config/NuisConfig.h @@ -1,202 +1,184 @@ // 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 NUISCONFIG_H_SEEN #define NUISCONFIG_H_SEEN #include #include #include "TXMLEngine.h" -#include "GeneralUtils.h" #include "TFile.h" - -// NUISANCE Global Settings Class +/// NUISANCE Global Settings Class class nuisconfig { - public: +public: /// Singleton Get Function static nuisconfig& GetConfig(void); /// Constructor \n /// Loads defaults from $NUISANCE/parameters/config.xml nuisconfig(); /// Desctructor \n Frees XML Docs virtual ~nuisconfig(); /// Adds a new configuration list void LoadSettings(std::string filename, std::string state); /// Adds a new config from new xml file format void LoadXMLSettings(std::string filename, std::string state); /// Adds a new config from old card file format void LoadCardSettings(std::string filename, std::string state); /// Save the config to file void WriteSettings(std::string filename); + XMLNodePointer_t CreateNode(std::string name); + XMLNodePointer_t CreateNode(XMLNodePointer_t node, std::string name); void RemoveEmptyNodes(); void RemoveIdenticalNodes(); + bool MatchingNodes(XMLNodePointer_t node1, XMLNodePointer_t node2); + void PrintNode(XMLNodePointer_t node); + void RemoveNode(XMLNodePointer_t node); + void FinaliseSettings(std::string name); - void OverrideConfig(std::string conf); - - XMLNodePointer_t GetConfigNode(std::string name); - XMLNodePointer_t CreateNode(XMLNodePointer_t node, std::string name); - - /// Request a string config key - void SetConfig(std::string name, std::string val); - void SetConfig(std::string name, bool val); - void SetConfig(std::string name, int val); - void SetConfig(std::string name, float val); - void SetConfig(std::string name, double val); - - void SetParS(std::string name, std::string val); - void SetParB(std::string name, bool val); - void SetParI(std::string name, int val); - void SetParD(std::string name, double val); - - // Set config - std::string GetConfig(const std::string name); - std::string GetConfigS(const std::string name); - bool GetConfigB(const std::string name); - int GetConfigI(const std::string name); - float GetConfigF(const std::string name); - double GetConfigD(const std::string name); - - std::string GetPar(const std::string name) { return GetConfig(name); }; - std::string GetParS(const std::string name){ return GetConfigS(name); }; - bool GetParB(const std::string name){ return GetConfigB(name); }; - int GetParI(const std::string name){ return GetConfigI(name); }; - double GetParD(const std::string name){return GetConfigD(name); }; - -XMLNodePointer_t CreateSampleNodeFromLine(const std::string line); -XMLNodePointer_t CreateParameterNodeFromLine(const std::string line); -XMLNodePointer_t CreatePullNodeFromLine(const std::string line); -XMLNodePointer_t CreateOldConfigNodeFromLine(const std::string line); - - /// Node Functions - void CheckCallCount(std::string name); - - /// Get list of child nodes of given element - std::vector GetChildNodes(XMLNodePointer_t node, - const std::string type); + XMLNodePointer_t CreateSampleNodeFromLine(const std::string line); + XMLNodePointer_t CreateParameterNodeFromLine(const std::string line); + XMLNodePointer_t CreatePullNodeFromLine(const std::string line); + XMLNodePointer_t CreateOldConfigNodeFromLine(const std::string line); // Get List of child nodes of nuisance element std::vector GetNodes(std::string type = ""); std::vector GetNodes(XMLNodePointer_t node, std::string type = ""); - XMLNodePointer_t GetNode(std::string type = ""); XMLNodePointer_t GetNode(XMLNodePointer_t node, std::string type = ""); - /// Get String from a given node - std::string Get(XMLNodePointer_t node, std::string name); - std::string GetS(XMLNodePointer_t node, std::string name); - bool GetB(XMLNodePointer_t node, std::string name); - int GetI(XMLNodePointer_t node, std::string name); - float GetF(XMLNodePointer_t node, std::string name); - double GetD(XMLNodePointer_t node, std::string name); + std::vector GetAllKeysForNode(XMLNodePointer_t node); - // Add Children to root node - XMLNodePointer_t CreateNode(std::string name); + std::string GetElementName(XMLNodePointer_t node) { return fXML->GetNodeName(node); } - void FinaliseSettings(std::string name); + /// Check node has key name + bool Has(XMLNodePointer_t node, std::string name); - // Add attribute to node + /// Add attribute to node void Set(XMLNodePointer_t node, std::string name, std::string val); void Set(XMLNodePointer_t node, std::string name, bool val); void Set(XMLNodePointer_t node, std::string name, int val); void Set(XMLNodePointer_t node, std::string name, float val); void Set(XMLNodePointer_t node, std::string name, double val); void SetS(XMLNodePointer_t node, std::string name, std::string val); void SetB(XMLNodePointer_t node, std::string name, bool val); void SetI(XMLNodePointer_t node, std::string name, int val); void SetF(XMLNodePointer_t node, std::string name, float val); void SetD(XMLNodePointer_t node, std::string name, double val); - // Check has element - bool Has(XMLNodePointer_t node, std::string name); + /// Get String from a given node + std::string Get(XMLNodePointer_t node, std::string name); + std::string GetS(XMLNodePointer_t node, std::string name); + bool GetB(XMLNodePointer_t node, std::string name); + int GetI(XMLNodePointer_t node, std::string name); + float GetF(XMLNodePointer_t node, std::string name); + double GetD(XMLNodePointer_t node, std::string name); - // Get Vectors + // Get values paresed into a vector std::vector GetVS(XMLNodePointer_t node, std::string name, const char* del); std::vector GetVI(XMLNodePointer_t node, std::string name, const char* del); std::vector GetVD(XMLNodePointer_t node, std::string name, const char* del); - std::vector GetAllKeysForNode(XMLNodePointer_t node); + /// Set an already set config value to something else + void OverrideConfig(std::string conf); - bool MatchingNodes(XMLNodePointer_t node1, XMLNodePointer_t node2); - void PrintNode(XMLNodePointer_t node); - void RemoveNode(XMLNodePointer_t node); + /// Return the node of a given config parameter + XMLNodePointer_t GetConfigNode(std::string name); + + void SetConfig(std::string name, std::string val); + void SetConfig(std::string name, bool val); + void SetConfig(std::string name, int val); + void SetConfig(std::string name, float val); + void SetConfig(std::string name, double val); + + void SetParS(std::string name, std::string val); + void SetParB(std::string name, bool val); + void SetParI(std::string name, int val); + void SetParD(std::string name, double val); - std::string GetElementName(XMLNodePointer_t node){ return fXML->GetNodeName(node); } + std::string GetConfig(const std::string name); + std::string GetConfigS(const std::string name); + bool GetConfigB(const std::string name); + int GetConfigI(const std::string name); + float GetConfigF(const std::string name); + double GetConfigD(const std::string name); + + std::string GetPar (const std::string name) { return GetConfig(name); }; + std::string GetParS(const std::string name) { return GetConfigS(name); }; + bool GetParB(const std::string name) { return GetConfigB(name); }; + int GetParI(const std::string name) { return GetConfigI(name); }; + float GetParF(const std::string name) { return GetConfigF(name); }; + double GetParD(const std::string name) { return GetConfigD(name); }; std::string GetParDIR(std::string parName); - TFile* out; - private: +private: + XMLNodePointer_t fMainNode; ///< Main XML Parent Node TXMLEngine* fXML; ///< ROOT XML Engine std::vector fXMLDocs; ///< List of all XML document inputs - int fCurrentTime; ///< Unix time for inefficiency checking - std::map fConfigCallCount; ///< To check for inefficiency. - std::map fConfigCallWarning; ///< Only print warning once. +protected: - - protected: static nuisconfig* m_nuisconfigInstance; }; -// Get Function for Singleton namespace Config { nuisconfig& Get(); std::string GetPar(std::string name); std::string GetParS(std::string name); -int GetParI(std::string name); -bool GetParB(std::string name); -double GetParD(std::string name); +bool GetParB(std::string name); +int GetParI(std::string name); +float GetParF(std::string name); +double GetParD(std::string name); void SetPar(std::string name, std::string val); void SetPar(std::string name, bool val); void SetPar(std::string name, int val); void SetPar(std::string name, float val); void SetPar(std::string name, double val); } namespace FitPar { - nuisconfig& Config(); - std::string GetDataBase(); - +nuisconfig& Config(); +std::string GetDataBase(); } /*! @} */ #endif diff --git a/src/Utils/NuisKey.cxx b/src/Config/NuisKey.cxx similarity index 98% rename from src/Utils/NuisKey.cxx rename to src/Config/NuisKey.cxx index 2aff40c..b89a5b3 100644 --- a/src/Utils/NuisKey.cxx +++ b/src/Config/NuisKey.cxx @@ -1,132 +1,134 @@ #include "NuisKey.h" +#include "NuisConfig.h" +#include "GeneralUtils.h" nuiskey::nuiskey(std::string name){ fNode = Config::Get().CreateNode(name); } std::string nuiskey::GetS(std::string name) { return Config::Get().GetS(fNode, name); }; int nuiskey::GetI(std::string name) { return Config::Get().GetI(fNode, name); }; double nuiskey::GetD(std::string name) { return Config::Get().GetD(fNode, name); }; bool nuiskey::GetB(std::string name) { return Config::Get().GetB(fNode, name); }; void nuiskey::Set(std::string name, std::string newval) { Config::Get().SetS(fNode, name, newval); } void nuiskey::Set(std::string name, int newval) { Config::Get().SetI(fNode, name, newval); } void nuiskey::Set(std::string name, double newval) { Config::Get().SetD(fNode, name, newval); } void nuiskey::Set(std::string name, bool newval) { Config::Get().SetB(fNode, name, newval); } void nuiskey::SetS(std::string name, std::string newval) { Config::Get().SetS(fNode, name, newval); } void nuiskey::SetI(std::string name, int newval) { Config::Get().SetI(fNode, name, newval); } void nuiskey::SetD(std::string name, double newval) { Config::Get().SetD(fNode, name, newval); } void nuiskey::SetB(std::string name, bool newval) { Config::Get().SetB(fNode, name, newval); } std::vector nuiskey::GetAllKeys() { return Config::Get().GetAllKeysForNode(fNode); } std::vector nuiskey::GetListOfChildNodes(std::string const& filter) { std::vector nodelist = Config::Get().GetNodes(fNode, filter); std::vector keylist; for (size_t n_it = 0; n_it < nodelist.size(); ++n_it) { keylist.push_back(nuiskey(nodelist[n_it])); } return keylist; } std::vector nuiskey::GetVS(std::string name, const char* del) { return Config::Get().GetVS(fNode, name, del); }; std::vector nuiskey::GetVI(std::string name, const char* del) { return Config::Get().GetVI(fNode, name, del); }; std::vector nuiskey::GetVD(std::string name, const char* del) { return Config::Get().GetVD(fNode, name, del); }; std::vector Config::QueryKeys(const std::string type, const std::string test1) { // Get Vector of nodes std::vector nodelist = Config::Get().GetNodes(type); - std::cout << "Got " << nodelist.size() << " " << type << std::endl; + // Convert List into a key list for easier access std::vector keylist; for (std::vector::const_iterator iter = nodelist.begin(); iter != nodelist.end(); iter++) { // Create new key nuiskey newkey = nuiskey(*iter); // Add test1 if (!test1.empty()) { std::vector testvect = GeneralUtils::ParseToStr(test1, "="); if (testvect.size() < 2) continue; if (newkey.GetS(testvect[0]) != testvect[1]) continue; } // Save node as nuiskey keylist.push_back(newkey); } // Return list of keys return keylist; } nuiskey Config::QueryLastKey(const std::string type, const std::string test1) { // Loop over all for now because I'm lazy... std::vector allkeys = Config::QueryKeys(type, test1); if (allkeys.size() < 1) return nuiskey(); else return allkeys[allkeys.size() - 1]; } nuiskey Config::QueryFirstKey(const std::string type, const std::string test1) { // Loop over all for now because I'm lazy... std::vector allkeys = Config::QueryKeys(type, test1); if (allkeys.size() < 1) return nuiskey(); else return allkeys[allkeys.size() - 1]; } bool nuiskey::Has(const std::string name) { return Config::Get().Has(fNode, name); } std::string nuiskey::GetElementName() { return Config::Get().GetElementName(fNode); } nuiskey Config::CreateKey(const std::string name) { return nuiskey(Config::Get().CreateNode(name)); } diff --git a/src/Utils/NuisKey.h b/src/Config/NuisKey.h similarity index 86% rename from src/Utils/NuisKey.h rename to src/Config/NuisKey.h index 9ff766f..cdf192a 100644 --- a/src/Utils/NuisKey.h +++ b/src/Config/NuisKey.h @@ -1,62 +1,61 @@ #ifndef NUISKEY_H #define NUISKEY_H -#include +#include +#include -#include "NuisConfig.h" +#include "TXMLEngine.h" +#include "TFile.h" class nuiskey { - public: - nuiskey(){}; +public: + nuiskey() {}; nuiskey(XMLNodePointer_t node) { fNode = node; }; nuiskey(std::string name); - ~nuiskey(){}; + ~nuiskey() {}; std::string GetS(std::string name); int GetI(std::string name); double GetD(std::string name); bool GetB(std::string name); std::vector GetVS(std::string name, const char* del); std::vector GetVI(std::string name, const char* del); std::vector GetVD(std::string name, const char* del); void SetS(std::string name, std::string newval); void SetI(std::string name, int newval); void SetD(std::string name, double newval); void SetB(std::string name, bool newval); void Set(std::string name, std::string newval); void Set(std::string name, int newval); void Set(std::string name, double newval); void Set(std::string name, bool newval); bool Has(std::string name); std::string GetElementName(); std::vector GetAllKeys(); std::vector GetListOfChildNodes(std::string const& filter = ""); XMLNodePointer_t fNode; ///< XML Node in Config::Get().fXML for this key }; namespace Config { // Return a vector of keys for use std::vector QueryKeys(const std::string name, const std::string test1 = ""); nuiskey QueryFirstKey(const std::string name, const std::string test1 = ""); nuiskey QueryLastKey(const std::string name, const std::string test1 = ""); -// Create a new global config entry nuiskey CreateKey(const std::string name); -// void ConvertAndLoadCardToXMLFormat(const std::string cardfile); -// Backwards compatible sample key options } #endif diff --git a/src/FCN/#JointFCN.cxx# b/src/FCN/#JointFCN.cxx# new file mode 100755 index 0000000..cc31fe4 --- /dev/null +++ b/src/FCN/#JointFCN.cxx# @@ -0,0 +1,1016 @@ +#include "JointFCN.h" +#include +#include "FitUtils.h" + + +//*************************************************** +JointFCN::JointFCN(TFile* outfile) { +//*************************************************** + + fOutputDir = gDirectory; + if (outfile) FitPar::Config().out = outfile; + + std::vector samplekeys = Config::QueryKeys("sample"); + LoadSamples(samplekeys); + + std::vector covarkeys = Config::QueryKeys("covar"); + LoadPulls(covarkeys); + + fCurIter = 0; + fMCFilled = false; + + fIterationTree = false; + fDialVals = NULL; + fNDials = 0; + + fUsingEventManager = FitPar::Config().GetParB("EventManager"); + fOutputDir->cd(); +} + +//*************************************************** +JointFCN::JointFCN(std::vector samplekeys, TFile* outfile) { +//*************************************************** + + fOutputDir = gDirectory; + if (outfile) FitPar::Config().out = outfile; + + LoadSamples(samplekeys); + + fCurIter = 0; + fMCFilled = false; + + fOutputDir->cd(); + + fIterationTree = false; + fDialVals = NULL; + fNDials = 0; + + fUsingEventManager = FitPar::Config().GetParB("EventManager"); + fOutputDir->cd(); +} + +//*************************************************** +JointFCN::~JointFCN() { + //*************************************************** + + // Delete Samples + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + delete exp; + } + + for (PullListConstIter iter = fPulls.begin(); iter != fPulls.end(); iter++) { + ParamPull* pull = *iter; + delete pull; + } + + // Sort Tree + if (fIterationTree) DestroyIterationTree(); + if (fDialVals) delete fDialVals; + if (fSampleLikes) delete fSampleLikes; +}; + +//*************************************************** +void JointFCN::CreateIterationTree(std::string name, FitWeight* rw) { +//*************************************************** + + LOG(FIT) << " Creating new iteration container! " << std::endl; + DestroyIterationTree(); + fIterationTreeName = name; + + // Add sample likelihoods and ndof + for (MeasListConstIter iter = fSamples.begin(); + iter != fSamples.end(); + iter++) { + + MeasurementBase* exp = *iter; + std::string name = exp->GetName(); + + std::string liketag = name + "_likelihood"; + fNameValues.push_back(liketag); + fCurrentValues.push_back(0.0); + + std::string ndoftag = name + "_ndof"; + fNameValues.push_back(ndoftag); + fCurrentValues.push_back(0.0); + } + + // Add Pull terms + for (PullListConstIter iter = fPulls.begin(); + iter != fPulls.end(); iter++) { + + ParamPull* pull = *iter; + std::string name = pull->GetName(); + + std::string liketag = name + "_likelihood"; + fNameValues.push_back(liketag); + fCurrentValues.push_back(0.0); + + std::string ndoftag = name + "_ndof"; + fNameValues.push_back(ndoftag); + fCurrentValues.push_back(0.0); + } + + // Add Likelihoods + fNameValues.push_back("total_likelihood"); + fCurrentValues.push_back(0.0); + + fNameValues.push_back("total_ndof"); + fCurrentValues.push_back(0.0); + + // Setup Containers + fSampleN = fSamples.size() + fPulls.size(); + fSampleLikes = new double[fSampleN]; + fSampleNDOF = new int[fSampleN]; + + // Add Dials + std::vector dials = rw->GetDialNames(); + for (size_t i = 0; i < dials.size(); i++){ + fNameValues.push_back( dials[i] ); + fCurrentValues.push_back( 0.0 ); + } + fNDials = dials.size(); + fDialVals = new double[fNDials]; + + // Set IterationTree Flag + fIterationTree = true; + +} + +//*************************************************** +void JointFCN::DestroyIterationTree() { +//*************************************************** + + fIterationCount.clear(); + fCurrentValues.clear(); + fNameValues.clear(); + fIterationValues.clear(); + +} + +//*************************************************** +void JointFCN::WriteIterationTree() { +//*************************************************** + LOG(FIT) << "Writing iteration tree" << std::endl; + + // Make a new TTree + TTree* itree = new TTree(fIterationTreeName.c_str(), + fIterationTreeName.c_str()); + + double* vals = new double[fNameValues.size()]; + int count = 0; + + itree->Branch("iteration",&count,"Iteration/I"); + for (int i = 0; i < fNameValues.size(); i++) { + itree->Branch( fNameValues[i].c_str(), + &vals[i], + (fNameValues[i] + "/D").c_str() ); + } + + // Fill Iterations + for (size_t i = 0; i < fIterationValues.size(); i++){ + std::vector itervals = fIterationValues[i]; + + // Fill iteration state + count = fIterationCount[i]; + for (size_t j = 0; j < itervals.size(); j++){ + vals[j] = itervals[j]; + } + + // Save to TTree + itree->Fill(); + } + + // Write to file + std::cout << "Writing iteration tree" << std::endl; + itree->Write(); + std::cout << "Written iteration tree" << std::endl; +} + +//*************************************************** +void JointFCN::FillIterationTree(FitWeight* rw) { +//*************************************************** + + // Loop over samples count + int count = 0; + for (int i = 0; i < fSampleN; i++){ + fCurrentValues[count++] = fSampleLikes[i]; + fCurrentValues[count++] = double(fSampleNDOF[i]); + } + + // Fill Totals + fCurrentValues[count++] = fLikelihood; + fCurrentValues[count++] = double(fNDOF); + + // Loop Over Parameter Counts + rw->GetAllDials(fDialVals, fNDials); + for (int i = 0; i < fNDials; i++){ + fCurrentValues[count++] = double(fDialVals[i]); + } + + // Push Back Into Container + fIterationCount.push_back( fCurIter ); + fIterationValues.push_back(fCurrentValues); +} + +//*************************************************** +double JointFCN::DoEval(const double* x) { + //*************************************************** + + // WEIGHT ENGINE + fDialChanged = FitBase::GetRW()->HasRWDialChanged(x); + FitBase::GetRW()->UpdateWeightEngine(x); + if (fDialChanged) { + FitBase::GetRW()->Reconfigure(); + FitBase::EvtManager().ResetWeightFlags(); + } + if (LOG_LEVEL(REC)) { + FitBase::GetRW()->Print(); + } + + // SORT SAMPLES + ReconfigureSamples(); + + // GET TEST STAT + fLikelihood = GetLikelihood(); + fNDOF = GetNDOF(); + + // PRINT PROGRESS + LOG(FIT) << "Current Stat (iter. " << this->fCurIter << ") = " << fLikelihood + << std::endl; + + // UPDATE TREE + if (fIterationTree) FillIterationTree(FitBase::GetRW()); + + return fLikelihood; +} + +//*************************************************** +int JointFCN::GetNDOF() { + //*************************************************** + + int totaldof = 0; + int count = 0; + + // Total number of Free bins in each MC prediction + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + int dof = exp->GetNDOF(); + + // Save Seperate DOF + if (fIterationTree) { + fSampleNDOF[count] = dof; + } + + // Add to total + totaldof += dof; + count++; + } + + // Loop over pulls + for (PullListConstIter iter = fPulls.begin(); iter != fPulls.end(); iter++) { + ParamPull* pull = *iter; + double dof = pull->GetLikelihood(); + + // Save seperate DOF + if (fIterationTree) { + fSampleNDOF[count] = dof; + } + + // Add to total + totaldof += dof; + count++; + } + + // Set Data Variable + if (fIterationTree){ + fSampleNDOF[count] = totaldof; + } + return totaldof; +} + +//*************************************************** +double JointFCN::GetLikelihood() { + //*************************************************** + + LOG(MIN) << std::left << std::setw(43) << "Getting likelihoods..." + << " : " + << "-2logL" << std::endl; + + // Loop and add up likelihoods in an uncorrelated way + double like = 0.0; + int count = 0; + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + double newlike = exp->GetLikelihood(); + int ndof = exp->GetNDOF(); + // Save seperate likelihoods + if (fIterationTree) { + fSampleLikes[count] = newlike; + } + + LOG(MIN) << "-> " << std::left << std::setw(40) << exp->GetName() << " : " + << newlike << "/" << ndof << std::endl; + + // Add Weight Scaling + // like *= FitBase::GetRW()->GetSampleLikelihoodWeight(exp->GetName()); + + // Add to total + like += newlike; + count++; + } + + // Loop over pulls + for (PullListConstIter iter = fPulls.begin(); iter != fPulls.end(); iter++) { + ParamPull* pull = *iter; + double newlike = pull->GetLikelihood(); + + // Save seperate likelihoods + if (fIterationTree) { + fSampleLikes[count] = newlike; + } + + // Add to total + like += newlike; + count++; + } + + // Set Data Variable + fLikelihood = like; + if (fIterationTree){ + fSampleLikes[count] = fLikelihood; + } + + return like; +}; + +void JointFCN::LoadSamples(std::vector samplekeys) { + LOG(MIN) << "Loading Samples : " << samplekeys.size() << std::endl; + for (size_t i = 0; i < samplekeys.size(); i++) { + nuiskey key = samplekeys[i]; + + // Get Sample Options + std::string samplename = key.GetS("name"); + std::string samplefile = key.GetS("input"); + std::string sampletype = key.GetS("type"); + std::string fakeData = ""; + + LOG(MIN) << "Loading Sample : " << samplename << std::endl; + + fOutputDir->cd(); + MeasurementBase* NewLoadedSample = SampleUtils::CreateSample(key); + + if (!NewLoadedSample) { + ERR(FTL) << "Could not load sample provided: " << samplename << std::endl; + ERR(FTL) << "Check spelling with that in src/FCN/SampleList.cxx" + << std::endl; + throw; + } else { + fSamples.push_back(NewLoadedSample); + } + } +} + +//*************************************************** +void JointFCN::LoadPulls(std::vector pullkeys) { +//*************************************************** + for (size_t i = 0; i < pullkeys.size(); i++) { + nuiskey key = pullkeys[i]; + + std::string pullname = key.GetS("name"); + std::string pullfile = key.GetS("input"); + std::string pulltype = key.GetS("type"); + + fOutputDir->cd(); + fPulls.push_back(new ParamPull(pullname, pullfile, pulltype)); + } +} + +//*************************************************** +void JointFCN::ReconfigureSamples(bool fullconfig) { +//*************************************************** + + int starttime = time(NULL); + LOG(REC) << "Starting Reconfigure iter. " << this->fCurIter << std::endl; + // std::cout << fUsingEventManager << " " << fullconfig << " " << fMCFilled << + // std::endl; + // Event Manager Reconf + if (fUsingEventManager) { + if (!fullconfig and fMCFilled) + ReconfigureFastUsingManager(); + else + ReconfigureUsingManager(); + + } else { + // Loop over all Measurement Classes + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + + // If RW Either do signal or full reconfigure. + if (fDialChanged or !fMCFilled or fullconfig) { + if (!fullconfig and fMCFilled) + exp->ReconfigureFast(); + else + exp->Reconfigure(); + + // If RW Not needed just do normalisation + } else { + exp->Renormalise(); + } + } + } + + // Loop over pulls and update + for (PullListConstIter iter = fPulls.begin(); iter != fPulls.end(); iter++) { + ParamPull* pull = *iter; + pull->Reconfigure(); + } + + fMCFilled = true; + LOG(MIN) << "Finished Reconfigure iter. " << fCurIter << " in " + << time(NULL) - starttime << "s" << std::endl; + + fCurIter++; +} + +//*************************************************** +void JointFCN::ReconfigureSignal() { +//*************************************************** + ReconfigureSamples(false); +} + +//*************************************************** +void JointFCN::ReconfigureAllEvents() { + //*************************************************** + FitBase::GetRW()->Reconfigure(); + FitBase::EvtManager().ResetWeightFlags(); + ReconfigureSamples(true); +} + +std::vector JointFCN::GetInputList() { + std::vector InputList; + fIsAllSplines = true; + + MeasListConstIter iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + + std::vector subsamples = exp->GetSubSamples(); + for (size_t i = 0; i < subsamples.size(); i++) { + InputHandlerBase* inp = subsamples[i]->GetInput(); + if (std::find(InputList.begin(), InputList.end(), inp) == + InputList.end()) { + if (subsamples[i]->GetInput()->GetType() != kSPLINEPARAMETER) + fIsAllSplines = false; + + InputList.push_back(subsamples[i]->GetInput()); + } + } + } + + return InputList; +} + +std::vector JointFCN::GetSubSampleList() { + std::vector SampleList; + + MeasListConstIter iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + + std::vector subsamples = exp->GetSubSamples(); + for (size_t i = 0; i < subsamples.size(); i++) { + SampleList.push_back(subsamples[i]); + } + } + + return SampleList; +} + +//*************************************************** +void JointFCN::ReconfigureUsingManager() { +//*************************************************** + + // 'Slow' Event Manager Reconfigure + LOG(REC) << "Event Manager Reconfigure" << std::endl; + int timestart = time(NULL); + + // Reset all samples + MeasListConstIter iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + exp->ResetAll(); + } + + // If we are siving signal, reset all containers. + bool savesignal = (FitPar::Config().GetParB("SignalReconfigures")); + + if (savesignal) { + // Reset all of our event signal vectors + fSignalEventBoxes.clear(); + fSignalEventFlags.clear(); + fSampleSignalFlags.clear(); + fSignalEventSplines.clear(); + } + + // Make sure we have a list of inputs + if (fInputList.empty()) { + fInputList = GetInputList(); + fSubSampleList = GetSubSampleList(); + } + + // If all inputs are splines make sure the readers are told + // they need to be reconfigured. + std::vector::iterator inp_iter = fInputList.begin(); + + if (fIsAllSplines) { + for (; inp_iter != fInputList.end(); inp_iter++) { + InputHandlerBase* curinput = (*inp_iter); + + // Tell reader in each BaseEvent it needs a Reconfigure next weight calc. + BaseFitEvt* curevent = curinput->FirstBaseEvent(); + if (curevent->fSplineRead) { + curevent->fSplineRead->SetNeedsReconfigure(true); + } + } + } + + // MAIN INPUT LOOP ==================== + + int fillcount = 0; + int inputcount = 0; + inp_iter = fInputList.begin(); + + // Loop over each input in manager + for (; inp_iter != fInputList.end(); inp_iter++) { + InputHandlerBase* curinput = (*inp_iter); + + // Get event information + FitEvent* curevent = curinput->FirstNuisanceEvent(); + curinput->CreateCache(); + + int i = 0; + int nevents = curinput->GetNEvents(); + int countwidth = nevents / 5; + + // Start event loop iterating until we get a NULL pointer. + while (curevent) { + // Get Event Weight + curevent->RWWeight = FitBase::GetRW()->CalcWeight(curevent); + curevent->Weight = curevent->RWWeight * curevent->InputWeight; + double rwweight = curevent->Weight; + // std::cout << "RWWeight = " << curevent->RWWeight << " " << + // curevent->InputWeight << std::endl; + + // Logging + // std::cout << CHECKLOG(1) << std::endl; + if (LOGGING(REC)) { + if (i % countwidth == 0) { + QLOG(REC, curinput->GetName() + << " : Processed " << i << " events. [M, W] = [" + << curevent->Mode << ", " << rwweight << "]"); + } + } + + // Setup flag for if signal found in at least one sample + bool foundsignal = false; + + // Create a new signal bitset for this event + std::vector signalbitset(fSubSampleList.size()); + + // Create a new signal box vector for this event + std::vector signalboxes; + + // Start measurement iterator + size_t measitercount = 0; + std::vector::iterator meas_iter = + fSubSampleList.begin(); + + // Loop over all subsamples (sub in JointMeas) + for (; meas_iter != fSubSampleList.end(); meas_iter++) { + MeasurementBase* curmeas = (*meas_iter); + + // Compare input pointers, to current input, skip if not. + // Pointer tells us if it matches without doing ID checks. + if (curinput != curmeas->GetInput()) { + if (savesignal) { + // Set bit to 0 as definitely not signal + signalbitset[measitercount] = 0; + } + + // Count up what measurement we are on. + measitercount++; + + // Skip sample as input not signal. + continue; + } + + // Fill events for matching inputs. + MeasurementVariableBox* box = curmeas->FillVariableBox(curevent); + + bool signal = curmeas->isSignal(curevent); + curmeas->SetSignal(signal); + curmeas->FillHistograms(curevent->Weight); + + // If its Signal tally up fills + if (signal) { + fillcount++; + } + + // If we are saving signal/splines fill the bitset + if (savesignal) { + signalbitset[measitercount] = signal; + } + + // If signal save a clone of the event box for use later. + if (savesignal and signal) { + foundsignal = true; + signalboxes.push_back(box->CloneSignalBox()); + } + + // Keep track of Measurement we are on. + measitercount++; + } + + // Once we've filled the measurements, if saving signal + // push back if any sample flagged this event as signal + if (savesignal) { + fSignalEventFlags.push_back(foundsignal); + } + + // Save the vector of signal boxes for this event + if (savesignal and foundsignal) { + fSignalEventBoxes.push_back(signalboxes); + fSampleSignalFlags.push_back(signalbitset); + } + + // If all inputs are splines we can save the spline coefficients + // for fast in memory reconfigures later. + if (fIsAllSplines and savesignal and foundsignal) { + // Make temp vector to push back with + std::vector coeff; + for (size_t l = 0; l < (UInt_t)curevent->fSplineRead->GetNPar(); l++) { + coeff.push_back(curevent->fSplineCoeff[l]); + } + + // Push back to signal event splines. Kept in sync with + // fSignalEventBoxes size. + // int splinecount = fSignalEventSplines.size(); + fSignalEventSplines.push_back(coeff); + + // if (splinecount % 1000 == 0) { + // std::cout << "Pushed Back Coeff " << splinecount << " : "; + // for (size_t l = 0; l < fSignalEventSplines[splinecount].size(); l++) + // { + // std::cout << " " << fSignalEventSplines[splinecount][l]; + // } + // std::cout << std::endl; + // } + } + + // Clean up vectors once done with this event + signalboxes.clear(); + signalbitset.clear(); + + // Iterate to the next event. + curevent = curinput->NextNuisanceEvent(); + i++; + } + + // curinput->RemoveCache(); + + // Keep track of what input we are on. + inputcount++; + } + + // End of Event Loop =============================== + + // Now event loop is finished loop over all Measurements + // Converting Binned events to XSec Distributions + iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + exp->ConvertEventRates(); + } + + // Print out statements on approximate memory usage for profiling. + LOG(REC) << "Filled " << fillcount << " signal events." << std::endl; + if (savesignal) { + int mem = + ( // sizeof(fSignalEventBoxes) + + // fSignalEventBoxes.size() * sizeof(fSignalEventBoxes.at(0)) + + sizeof(MeasurementVariableBox1D) * fillcount) * + 1E-6; + LOG(REC) << " -> Saved " << fillcount + << " signal boxes for faster access. (~" << mem << " MB)" + << std::endl; + if (fIsAllSplines and !fSignalEventSplines.empty()) { + int splmem = sizeof(float) * fSignalEventSplines.size() * + fSignalEventSplines[0].size() * 1E-6; + LOG(REC) << " -> Saved " << fillcount << " " << fSignalEventSplines.size() + << " spline sets into memory. (~" << splmem << " MB)" + << std::endl; + } + } + + LOG(REC) << "Time taken ReconfigureUsingManager() : " + << time(NULL) - timestart << std::endl; + + // Check SignalReconfigures works for all samples + if (savesignal) { + double likefull = GetLikelihood(); + ReconfigureFastUsingManager(); + double likefast = GetLikelihood(); + + if (fabs(likefull - likefast) > 0.0001) + { + ERROR(FTL, "Fast and Full Likelihoods DIFFER! : " << likefull << " : " << likefast); + ERROR(FTL, "This means some samples you are using are not setup to use SignalReconfigures=1"); + ERROR(FTL, "Please turn OFF signal reconfigures."); + throw; + } else { + LOG(FIT) << "Likelihoods for FULL and FAST match. Will use FAST next time." << std::endl; + } + } + + // End of reconfigure + return; +}; + +//*************************************************** +void JointFCN::ReconfigureFastUsingManager() { +//*************************************************** + + LOG(FIT) << " -> Doing FAST using manager" << std::endl; + // Get Start time for profilling + int timestart = time(NULL); + + // Reset all samples + MeasListConstIter iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + exp->ResetAll(); + } + + // Check for saved variables if not do a full reconfigure. + if (fSignalEventFlags.empty()) { + ERR(WRN) << "Signal Flags Empty! Using normal manager." << std::endl; + ReconfigureUsingManager(); + return; + } + + bool fFillNuisanceEvent = + FitPar::Config().GetParB("FullEventOnSignalReconfigure"); + + // Setup fast vector iterators. + std::vector::iterator inpsig_iter = fSignalEventFlags.begin(); + std::vector >::iterator box_iter = + fSignalEventBoxes.begin(); + std::vector >::iterator spline_iter = + fSignalEventSplines.begin(); + std::vector >::iterator samsig_iter = + fSampleSignalFlags.begin(); + int splinecount = 0; + + // Setup stuff for logging + int fillcount = 0; + int nevents = fSignalEventFlags.size(); + int countwidth = nevents / 20; + + // If All Splines tell splines they need a reconfigure. + std::vector::iterator inp_iter = fInputList.begin(); + if (fIsAllSplines) { + LOG(REC) << "All Spline Inputs so using fast spline loop." << std::endl; + for (; inp_iter != fInputList.end(); inp_iter++) { + InputHandlerBase* curinput = (*inp_iter); + + // Tell each fSplineRead in BaseFitEvent to reconf next weight calc + BaseFitEvt* curevent = curinput->FirstBaseEvent(); + if (curevent->fSplineRead) + curevent->fSplineRead->SetNeedsReconfigure(true); + } + } + + // Loop over all possible spline inputs + double* coreeventweights = new double[fSignalEventBoxes.size()]; + splinecount = 0; + + inp_iter = fInputList.begin(); + inpsig_iter = fSignalEventFlags.begin(); + spline_iter = fSignalEventSplines.begin(); + + // Loop over all signal flags + // For each valid signal flag add one to splinecount + // Get Splines from that count and add to weight + // Add splinecount + int sigcount = 0; + splinecount = 0; + + // #pragma omp parallel for shared(splinecount,sigcount) + for (uint iinput = 0; iinput < fInputList.size(); iinput++) { + InputHandlerBase* curinput = fInputList[iinput]; + BaseFitEvt* curevent = curinput->FirstBaseEvent(); + + for (int i = 0; i < curinput->GetNEvents(); i++) { + double rwweight = 0.0; + if (fSignalEventFlags[sigcount]) { + // Get Event Info + if (!fIsAllSplines) { + if (fFillNuisanceEvent) + curinput->GetNuisanceEvent(i); + else + curevent = curinput->GetBaseEvent(i); + } else { + curevent->fSplineCoeff = &fSignalEventSplines[splinecount][0]; + } + + curevent->RWWeight = FitBase::GetRW()->CalcWeight(curevent); + curevent->Weight = curevent->RWWeight * curevent->InputWeight; + rwweight = curevent->Weight; + + coreeventweights[splinecount] = rwweight; + if (splinecount % countwidth == 0) { + LOG(REC) << "Processed " << splinecount + << " event weights. W = " << rwweight << std::endl; + } + + // #pragma omp atomic + splinecount++; + } + + // #pragma omp atomic + sigcount++; + } + } + LOG(SAM) << "Processed event weights." << std::endl; + + // #pragma omp barrier + + // Reset Iterators + inpsig_iter = fSignalEventFlags.begin(); + spline_iter = fSignalEventSplines.begin(); + box_iter = fSignalEventBoxes.begin(); + samsig_iter = fSampleSignalFlags.begin(); + int nsplineweights = splinecount; + splinecount = 0; + + // Start of Fast Event Loop ============================ + + // Start input iterators + // Loop over number of inputs + for (int ispline = 0; ispline < nsplineweights; ispline++) { + double rwweight = coreeventweights[ispline]; + + // Get iterators for this event + std::vector::iterator subsamsig_iter = (*samsig_iter).begin(); + std::vector::iterator subbox_iter = + (*box_iter).begin(); + + // Loop over all sub measurements. + std::vector::iterator meas_iter = fSubSampleList.begin(); + for (; meas_iter != fSubSampleList.end(); meas_iter++, subsamsig_iter++) { + MeasurementBase* curmeas = (*meas_iter); + + // If event flagged as signal for this sample fill from the box. + if (*subsamsig_iter) { + curmeas->SetSignal(true); + curmeas->FillHistogramsFromBox((*subbox_iter), rwweight); + + // Move onto next box if there is one. + subbox_iter++; + fillcount++; + } + } + + if (ispline % countwidth == 0) { + LOG(REC) << "Filled " << ispline << " sample weights." << std::endl; + } + + // Iterate over the main signal event containers. + samsig_iter++; + box_iter++; + spline_iter++; + splinecount++; + } + // End of Fast Event Loop =================== + + LOG(SAM) << "Filled sample distributions." << std::endl; + + // Now loop over all Measurements + // Convert Binned events + iterSam = fSamples.begin(); + for (; iterSam != fSamples.end(); iterSam++) { + MeasurementBase* exp = (*iterSam); + exp->ConvertEventRates(); + } + + // Cleanup coreeventweights + if (fIsAllSplines) { + delete coreeventweights; + } + + // Print some reconfigure profiling. + LOG(REC) << "Filled " << fillcount << " signal events." << std::endl; + LOG(REC) << "Time taken ReconfigureFastUsingManager() : " + << time(NULL) - timestart << std::endl; +} + +//*************************************************** +void JointFCN::Write() { +//*************************************************** + + // Save a likelihood/ndof plot + LOG(MIN) << "Writing likelihood plot.." << std::endl; + std::vector likes; + std::vector ndofs; + std::vector names; + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + double like = exp->GetLikelihood(); + double ndof = exp->GetNDOF(); + std::string name = exp->GetName(); + likes.push_back(like); + ndofs.push_back(ndof); + names.push_back(name); + } + TH1D likehist = TH1D("likelihood_hist", "likelihood_hist", + likes.size(), 0.0, double(likes.size())); + TH1D ndofhist = TH1D("ndof_hist", "ndof_hist", + ndofs.size(), 0.0, double(ndofs.size())); + TH1D divhist = TH1D("likedivndof_hist", "likedivndof_hist", + likes.size(), 0.0, double(likes.size())); + for (size_t i = 0; i < likehist.GetNbinsX(); i++) { + likehist.SetBinContent(i + 1, likes[i]); + ndofhist.SetBinContent(i + 1, ndofs[i]); + if (ndofs[i] != 0.0) { + divhist.SetBinContent(i + 1, likes[i] / ndofs[i]); + } + likehist.GetXaxis()->SetBinLabel(i + 1, names[i].c_str()); + ndofhist.GetXaxis()->SetBinLabel(i + 1, names[i].c_str()); + divhist.GetXaxis()->SetBinLabel(i + 1, names[i].c_str()); + } + likehist.Write(); + ndofhist.Write(); + divhist.Write(); + + // Loop over individual experiments and call Write + LOG(MIN) << "Writing each of the data classes..." << std::endl; + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + exp->Write(); + } + + // Save Pull Terms + for (PullListConstIter iter = fPulls.begin(); iter != fPulls.end(); iter++) { + ParamPull* pull = *iter; + pull->Write(); + } + + if (FitPar::Config().GetParB("EventManager")) { + // Get list of inputs + std::map fInputs = + FitBase::EvtManager().GetInputs(); + std::map::const_iterator iterInp; + + for (iterInp = fInputs.begin(); iterInp != fInputs.end(); iterInp++) { + InputHandlerBase* input = (iterInp->second); + + input->GetFluxHistogram()->Write(); + input->GetXSecHistogram()->Write(); + input->GetEventHistogram()->Write(); + } + } +}; + +//*************************************************** +void JointFCN::SetFakeData(std::string fakeinput) { +//*************************************************** + + LOG(MIN) << "Setting fake data from " << fakeinput << std::endl; + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + exp->SetFakeDataValues(fakeinput); + } + + return; +} + +//*************************************************** +void JointFCN::ThrowDataToy() { +//*************************************************** + + for (MeasListConstIter iter = fSamples.begin(); iter != fSamples.end(); + iter++) { + MeasurementBase* exp = *iter; + exp->ThrowDataToy(); + } + + return; +} diff --git a/src/FitBase/CMakeLists.txt b/src/FitBase/CMakeLists.txt index 543bcb2..91bfe86 100644 --- a/src/FitBase/CMakeLists.txt +++ b/src/FitBase/CMakeLists.txt @@ -1,72 +1,76 @@ # 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 . ################################################################################ set(IMPLFILES ParamPull.cxx EventManager.cxx Measurement1D.cxx Measurement2D.cxx JointMeas1D.cxx MeasurementBase.cxx TemplateMeas1D.cxx SampleSettings.cxx MeasurementVariableBox.cxx MeasurementVariableBox2D.cxx MeasurementVariableBox1D.cxx CustomVariableBoxes.h +StandardStacks.cxx +StackBase.cxx ) set(HEADERFILES ParamPull.h JointMeas1D.h Measurement2D.h EventManager.h MeasurementBase.h Measurement1D.h TemplateMeas1D.h SampleSettings.h MeasurementVariableBox.h MeasurementVariableBox2D.h MeasurementVariableBox1D.h CustomVariableBoxes.h +StandardStacks.h +StackBase.h ) set(LIBNAME FitBase) if(CMAKE_BUILD_TYPE MATCHES DEBUG) add_library(${LIBNAME} STATIC ${IMPLFILES}) else(CMAKE_BUILD_TYPE MATCHES RELEASE) add_library(${LIBNAME} SHARED ${IMPLFILES}) endif() include_directories(${MINIMUM_INCLUDE_DIRECTORIES}) cmessage(DEBUG "FitBase includes: ${MINIMUM_INCLUDE_DIRECTORIES}") set_target_properties(${LIBNAME} PROPERTIES VERSION "${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}") #set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS}) if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES) add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES}) endif() install(TARGETS ${LIBNAME} DESTINATION lib) #Can uncomment this to install the headers... but is it really neccessary? install(FILES ${HEADERFILES} DESTINATION include) set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE) diff --git a/src/Utils/StackBase.cxx b/src/FitBase/StackBase.cxx similarity index 100% rename from src/Utils/StackBase.cxx rename to src/FitBase/StackBase.cxx diff --git a/src/Utils/StackBase.h b/src/FitBase/StackBase.h similarity index 100% rename from src/Utils/StackBase.h rename to src/FitBase/StackBase.h diff --git a/src/Utils/StandardStacks.cxx b/src/FitBase/StandardStacks.cxx similarity index 100% rename from src/Utils/StandardStacks.cxx rename to src/FitBase/StandardStacks.cxx diff --git a/src/Utils/StandardStacks.h b/src/FitBase/StandardStacks.h similarity index 100% rename from src/Utils/StandardStacks.h rename to src/FitBase/StandardStacks.h diff --git a/src/FitBase/CMakeLists.txt b/src/Logger/CMakeLists.txt similarity index 73% copy from src/FitBase/CMakeLists.txt copy to src/Logger/CMakeLists.txt index 543bcb2..dee1fc1 100644 --- a/src/FitBase/CMakeLists.txt +++ b/src/Logger/CMakeLists.txt @@ -1,72 +1,54 @@ # 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 . ################################################################################ -set(IMPLFILES -ParamPull.cxx -EventManager.cxx -Measurement1D.cxx -Measurement2D.cxx -JointMeas1D.cxx -MeasurementBase.cxx -TemplateMeas1D.cxx -SampleSettings.cxx -MeasurementVariableBox.cxx -MeasurementVariableBox2D.cxx -MeasurementVariableBox1D.cxx -CustomVariableBoxes.h +set(HEADERFILES +FitLogger.h +Initialiser.h ) -set(HEADERFILES -ParamPull.h -JointMeas1D.h -Measurement2D.h -EventManager.h -MeasurementBase.h -Measurement1D.h -TemplateMeas1D.h -SampleSettings.h -MeasurementVariableBox.h -MeasurementVariableBox2D.h -MeasurementVariableBox1D.h -CustomVariableBoxes.h +set(IMPLFILES +PythiaQuiet.f +FitLogger.cxx +Initialiser.cxx ) -set(LIBNAME FitBase) +set(LIBNAME Logger) if(CMAKE_BUILD_TYPE MATCHES DEBUG) add_library(${LIBNAME} STATIC ${IMPLFILES}) else(CMAKE_BUILD_TYPE MATCHES RELEASE) add_library(${LIBNAME} SHARED ${IMPLFILES}) endif() include_directories(${MINIMUM_INCLUDE_DIRECTORIES}) -cmessage(DEBUG "FitBase includes: ${MINIMUM_INCLUDE_DIRECTORIES}") set_target_properties(${LIBNAME} PROPERTIES VERSION "${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}") + #set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS}) if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES) add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES}) endif() install(TARGETS ${LIBNAME} DESTINATION lib) #Can uncomment this to install the headers... but is it really neccessary? -install(FILES ${HEADERFILES} DESTINATION include) +#install(FILES ${HEADERFILES} DESTINATION include) set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE) + diff --git a/src/Utils/FitLogger.cxx b/src/Logger/FitLogger.cxx similarity index 100% rename from src/Utils/FitLogger.cxx rename to src/Logger/FitLogger.cxx diff --git a/src/Utils/FitLogger.h b/src/Logger/FitLogger.h similarity index 100% rename from src/Utils/FitLogger.h rename to src/Logger/FitLogger.h diff --git a/src/Utils/Initialiser.cxx b/src/Logger/Initialiser.cxx similarity index 100% rename from src/Utils/Initialiser.cxx rename to src/Logger/Initialiser.cxx diff --git a/src/Utils/Initialiser.h b/src/Logger/Initialiser.h similarity index 100% rename from src/Utils/Initialiser.h rename to src/Logger/Initialiser.h diff --git a/src/Utils/PythiaQuiet.f b/src/Logger/PythiaQuiet.f similarity index 100% rename from src/Utils/PythiaQuiet.f rename to src/Logger/PythiaQuiet.f diff --git a/src/FitBase/CMakeLists.txt b/src/Statistical/CMakeLists.txt similarity index 73% copy from src/FitBase/CMakeLists.txt copy to src/Statistical/CMakeLists.txt index 543bcb2..7512473 100644 --- a/src/FitBase/CMakeLists.txt +++ b/src/Statistical/CMakeLists.txt @@ -1,72 +1,50 @@ # 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 . ################################################################################ -set(IMPLFILES -ParamPull.cxx -EventManager.cxx -Measurement1D.cxx -Measurement2D.cxx -JointMeas1D.cxx -MeasurementBase.cxx -TemplateMeas1D.cxx -SampleSettings.cxx -MeasurementVariableBox.cxx -MeasurementVariableBox2D.cxx -MeasurementVariableBox1D.cxx -CustomVariableBoxes.h +set(HEADERFILES +StatUtils.h ) -set(HEADERFILES -ParamPull.h -JointMeas1D.h -Measurement2D.h -EventManager.h -MeasurementBase.h -Measurement1D.h -TemplateMeas1D.h -SampleSettings.h -MeasurementVariableBox.h -MeasurementVariableBox2D.h -MeasurementVariableBox1D.h -CustomVariableBoxes.h +set(IMPLFILES +StatUtils.cxx ) -set(LIBNAME FitBase) +set(LIBNAME Statistical) if(CMAKE_BUILD_TYPE MATCHES DEBUG) add_library(${LIBNAME} STATIC ${IMPLFILES}) else(CMAKE_BUILD_TYPE MATCHES RELEASE) add_library(${LIBNAME} SHARED ${IMPLFILES}) endif() include_directories(${MINIMUM_INCLUDE_DIRECTORIES}) -cmessage(DEBUG "FitBase includes: ${MINIMUM_INCLUDE_DIRECTORIES}") set_target_properties(${LIBNAME} PROPERTIES VERSION "${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}") + #set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS}) if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES) add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES}) endif() install(TARGETS ${LIBNAME} DESTINATION lib) #Can uncomment this to install the headers... but is it really neccessary? -install(FILES ${HEADERFILES} DESTINATION include) +#install(FILES ${HEADERFILES} DESTINATION include) set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE) diff --git a/src/Utils/StatUtils.cxx b/src/Statistical/StatUtils.cxx similarity index 100% rename from src/Utils/StatUtils.cxx rename to src/Statistical/StatUtils.cxx diff --git a/src/Utils/StatUtils.h b/src/Statistical/StatUtils.h similarity index 100% rename from src/Utils/StatUtils.h rename to src/Statistical/StatUtils.h diff --git a/src/Utils/CMakeLists.txt b/src/Utils/CMakeLists.txt index 2ac8c01..2f557fc 100644 --- a/src/Utils/CMakeLists.txt +++ b/src/Utils/CMakeLists.txt @@ -1,91 +1,76 @@ # 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 . ################################################################################ set(HEADERFILES -FitLogger.h FitUtils.h GeneralUtils.h ParserUtils.h PlotUtils.h -StatUtils.h SignalDef.h -NuisConfig.h -NuisKey.h BeamUtils.h TargetUtils.h -StackBase.h -StandardStacks.h OpenMPWrapper.h PhysConst.h -Initialiser.h ) set(IMPLFILES -PythiaQuiet.f -FitLogger.cxx FitUtils.cxx GeneralUtils.cxx PlotUtils.cxx -StatUtils.cxx SignalDef.cxx -NuisConfig.cxx -NuisKey.cxx BeamUtils.cxx TargetUtils.cxx -StackBase.cxx ParserUtils.cxx -StandardStacks.cxx -Initialiser.cxx ) set(LIBNAME Utils) if(CMAKE_BUILD_TYPE MATCHES DEBUG) add_library(${LIBNAME} STATIC ${IMPLFILES}) else(CMAKE_BUILD_TYPE MATCHES RELEASE) add_library(${LIBNAME} SHARED ${IMPLFILES}) endif() include_directories(${MINIMUM_INCLUDE_DIRECTORIES}) +include_directories(${CMAKE_SOURCE_DIR}/src/Logger) set_target_properties(${LIBNAME} PROPERTIES VERSION "${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}") #set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS}) if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES) add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES}) endif() install(TARGETS ${LIBNAME} DESTINATION lib) #Can uncomment this to install the headers... but is it really neccessary? #install(FILES ${HEADERFILES} DESTINATION include) set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE) -add_executable(DumpROOTClassesFromVector DumpROOTClassesFromVector.cxx GeneralUtils.cxx FitLogger.cxx PythiaQuiet.f) - - #Strip out -lNuWro_event1 - string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${CMAKE_DEPENDLIB_FLAGS}) - cmessage(DEBUG "Attempted to strip out nuwro library: \"${CMAKE_DEPENDLIB_FLAGS}\" -> \"${NWEVSTRIPPED_CDF}\"") - target_link_libraries(DumpROOTClassesFromVector ${NWEVSTRIPPED_CDF}) - if(NOT CMAKE_LINK_FLAGS STREQUAL "") - set_target_properties(DumpROOTClassesFromVector PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) - endif() - -install(TARGETS DumpROOTClassesFromVector DESTINATION bin) +#add_executable(DumpROOTClassesFromVector DumpROOTClassesFromVector.cxx GeneralUtils.cxx FitLogger.cxx PythiaQuiet.f) +# +# #Strip out -lNuWro_event1 +# string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${CMAKE_DEPENDLIB_FLAGS}) +# cmessage(DEBUG "Attempted to strip out nuwro library: \"${CMAKE_DEPENDLIB_FLAGS}\" -> \"${NWEVSTRIPPED_CDF}\"") +# target_link_libraries(DumpROOTClassesFromVector ${NWEVSTRIPPED_CDF}) +# if(NOT CMAKE_LINK_FLAGS STREQUAL "") +# set_target_properties(DumpROOTClassesFromVector PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) +# endif() +#install(TARGETS DumpROOTClassesFromVector DESTINATION bin)