diff --git a/CMakeLists.txt b/CMakeLists.txt index 78fe008..342761b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,80 +1,82 @@ # Copyright 2018 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.8 FATAL_ERROR) #Use the compilers found in the path find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH) find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH) project(NUISANCE) include(ExternalProject) set (NUISANCE_VERSION_MAJOR 3) 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) +include(${CMAKE_SOURCE_DIR}/cmake/parseConfigApp.cmake) +include(${CMAKE_SOURCE_DIR}/cmake/StringAndListUtils.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) ################################# InputHandler ################################# include(${CMAKE_SOURCE_DIR}/cmake/InputHandlerSetup.cmake) ################################# Pythia6/8 ################################### include(${CMAKE_SOURCE_DIR}/cmake/pythia6Setup.cmake) -#Want this before fhiclcpp which will add the install directory -LIST(APPEND EXTRA_CXX_FLAGS -I${CMAKE_SOURCE_DIR}/src) - ################################## FHICLCPP #################################### include(${CMAKE_SOURCE_DIR}/cmake/fhiclcppSetup.cmake) + +#Want this after fhiclcpp which will add the install directory +include_directories(${CMAKE_SOURCE_DIR}/src) + ################################## COMPILER #################################### include(${CMAKE_SOURCE_DIR}/cmake/c++CompilerSetup.cmake) ################################################################################ add_subdirectory(src) 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}) add_subdirectory(config) add_subdirectory(data) diff --git a/CMakeLists_old.txt b/CMakeLists_old.txt index 13398f8..220742b 100644 --- a/CMakeLists_old.txt +++ b/CMakeLists_old.txt @@ -1,232 +1,232 @@ # 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.8 FATAL_ERROR) #Use the compilers found in the path find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH) find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH) project(NUISANCE) include(ExternalProject) enable_language(Fortran) set (NUISANCE_VERSION_MAJOR 2) set (NUISANCE_VERSION_MINOR 7) 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 InputHandler Splines Reweight Utils Statistical #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}") set(MODULETargets "${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}) configure_file(cmake/MakeBinaryBlob.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/MakeBinaryBlob" @ONLY) install(PROGRAMS "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/MakeBinaryBlob" DESTINATION bin) if(USE_DYNSAMPLES) SET(ALL_INCLUDES ${MINIMUM_INCLUDE_DIRECTORIES}) LIST(APPEND ALL_INCLUDES ${CMAKE_SOURCE_DIR}/src/Smearceptance) LIST(APPEND ALL_INCLUDES ${EXP_INCLUDE_DIRECTORIES}) string(REPLACE ";" " -I" ALL_INCLUDES_STR "${ALL_INCLUDES}") - cmessage(DEBUG ${CMAKE_DEPENDLIB_FLAGS}) - string(REPLACE "-levent " "" CMAKE_DEPENDLIB_FLAGS_NEW ${CMAKE_DEPENDLIB_FLAGS}) - set(CMAKE_DEPENDLIB_FLAGS ${CMAKE_DEPENDLIB_FLAGS_NEW}) - cmessage(DEBUG ${CMAKE_DEPENDLIB_FLAGS}) + cmessage(DEBUG ${NUISANCE_DEPEND_LIBS}) + string(REPLACE "-levent " "" NUISANCE_DEPEND_LIBS_NEW ${NUISANCE_DEPEND_LIBS}) + set(NUISANCE_DEPEND_LIBS ${NUISANCE_DEPEND_LIBS_NEW}) + cmessage(DEBUG ${NUISANCE_DEPEND_LIBS}) configure_file(cmake/BuildDynamicSample.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BuildDynamicSample" @ONLY) install(PROGRAMS "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BuildDynamicSample" DESTINATION bin) configure_file(cmake/BuildDynamicSmearcepter.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BuildDynamicSmearcepter" @ONLY) install(PROGRAMS "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/BuildDynamicSmearcepter" DESTINATION bin) endif() 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 1afec7d..35aaabb 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,225 +1,225 @@ # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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/Statistical) 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/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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # 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 ${NUISANCE_DEPEND_LIBS}) # target_link_libraries(PrepareNuwro ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(PrepareNuwro PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() endif() add_executable(nuisbac nuisbac.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuisbac) target_link_libraries(nuisbac ${MODULETargets}) -target_link_libraries(nuisbac ${CMAKE_DEPENDLIB_FLAGS}) +target_link_libraries(nuisbac ${NUISANCE_DEPEND_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(nuisbac PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) 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}\"") +# string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${NUISANCE_DEPEND_LIBS}) +# cmessage(DEBUG "Attempted to strip out nuwro library: \"${NUISANCE_DEPEND_LIBS}\" -> \"${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/cmake/GENIESetup.cmake b/cmake/GENIESetup.cmake new file mode 100644 index 0000000..aa51857 --- /dev/null +++ b/cmake/GENIESetup.cmake @@ -0,0 +1,192 @@ +# 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 . +################################################################################ + +################################################################################ +# Check Dependencies +################################################################################ + +################################# GENIE ###################################### +if(GENIE STREQUAL "") + cmessage(FATAL_ERROR "Variable GENIE is not defined. " + "The location of a pre-built GENIE install must be defined either as" + " $ cmake -DGENIE=/path/to/GENIE or as an environment variable" + " $ export GENIE=/path/to/GENIE") +endif() + +execute_process(COMMAND genie-config --version +OUTPUT_VARIABLE GENIE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + +if(GENIE_VERSION VERSION_GREATER 2.12.999) + LIST(APPEND GENIE_CXX_FLAGS -DGENIE_V3_INTERFACE -DGENIE_EMP_MECRW_ENABLED) +endif() + +execute_process (COMMAND genie-config + --topsrcdir OUTPUT_VARIABLE GENIE_INCLUDES_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + +#Allows for external override in the case where genie-config lies. +if(NOT DEFINED GENIE_LIB_DIR OR GENIE_LIB_DIR STREQUAL "") + GETLIBDIRS(genie-config --libs GENIE_LIB_DIR) +endif() +GETLIBS(genie-config --libs GENIE_LIBS) + +string(REGEX MATCH "ReinSeghal" WASMATCHED ${GENIE_LIBS}) +if(WASMATCHED AND GENIE_VERSION VERSION_GREATER 2.9.999 AND GENIE_VERSION VERSION_LESS 2.11.0 ) + set(GENIE_SEHGAL ${GENIE_LIBS}) + STRING(REPLACE "ReinSeghal" "ReinSehgal" GENIE_LIBS ${GENIE_SEHGAL}) + cmessage(DEBUG "Fixed inconsistency in library naming: ${GENIE_LIBS}") +endif() + +if(USE_GENERATOR_REWEIGHT) + if(GENIE_VERSION VERSION_GREATER 2.12.999) + LIST(FIND GENIE_LIBS GRwFwk WAS_FOUND) + if(WAS_FOUND STREQUAL "-1") + LIST(APPEND GENIE_LIBS GRwClc GRwFwk GRwIO) + cmessage(DEBUG "Force added ReWeight library: ${GENIE_LIBS}") + endif() + else() + LIST(FIND GENIE_LIBS GReWeight WAS_FOUND) + if(WAS_FOUND STREQUAL "-1") + LIST(APPEND GENIE_LIBS GReWeight) + cmessage(DEBUG "Force added ReWeight library: ${GENIE_LIBS}") + endif() + endif(GENIE_VERSION VERSION_GREATER 2.12.999) +endif(USE_GENERATOR_REWEIGHT) + +LIST(APPEND GENIE_LIBS -Wl,--end-group ) +LIST(REVERSE GENIE_LIBS) +LIST(APPEND GENIE_LIBS -Wl,--start-group -Wl,--no-as-needed ) +LIST(REVERSE GENIE_LIBS) + +################################ LHAPDF ###################################### +if(LHAPDF_LIB STREQUAL "") + cmessage(FATAL_ERROR "Variable LHAPDF_LIB is not defined. The location of a pre-built lhapdf install must be defined either as $ cmake -DLHAPDF_LIB=/path/to/LHAPDF_libraries or as an environment variable $ export LHAPDF_LIB=/path/to/LHAPDF_libraries") +endif() + +if(LHAPDF_INC STREQUAL "") + cmessage(FATAL_ERROR "Variable LHAPDF_INC is not defined. The location of a pre-built lhapdf install must be defined either as $ cmake -DLHAPDF_INC=/path/to/LHAPDF_includes or as an environment variable $ export LHAPDF_INC=/path/to/LHAPDF_includes") +endif() + +if(LHAPATH STREQUAL "") + cmessage(FATAL_ERROR "Variable LHAPATH is not defined. The location of a the LHAPATH directory must be defined either as $ cmake -DLHAPATH=/path/to/LHAPATH or as an environment variable $ export LHAPATH=/path/to/LHAPATH") +endif() + +################################ LIBXML ###################################### +if(LIBXML2_LIB STREQUAL "") + GETLIBDIR(xml2-config --libs LIBXML2_LIB IGNORE_EMPTY_RESPONSE) + if(LIBXML2_LIB STREQUAL "") + message(WARNING "Variable LIBXML2_LIB is not defined, as xml2-config was found and didn't report a library include path, it is likely that libxml2.so can be found in the standard system location, lets hope so.") + endif() +endif() + +if(LIBXML2_INC STREQUAL "") + GETINCDIR(xml2-config --cflags LIBXML2_INC) + if(LIBXML2_INC STREQUAL "") + message(FATAL_ERROR "Variable LIBXML2_INC is not defined and could not be found with xml2-config. The location of a pre-built libxml2 install must be defined either as $ cmake -DLIBXML2_INC=/path/to/LIBXML2_includes or as an environment variable $ export LIBXML2_INC=/path/to/LIBXML2_includes") + endif() +endif() + +############################### log4cpp ###################################### +if(LOG4CPP_LIB STREQUAL "") + GETLIBDIR(log4cpp-config --libs LOG4CPP_LIB) + if(LOG4CPP_LIB STREQUAL "") + message(FATAL_ERROR "Variable LOG4CPP_LIB is not defined and could not be found with log4cpp-config. The location of a pre-built log4cpp install must be defined either as $ cmake -DLOG4CPP_LIB=/path/to/LOG4CPP_libraries or as an environment variable $ export LOG4CPP_LIB=/path/to/LOG4CPP_libraries") + endif() +endif() + +if(LOG4CPP_INC STREQUAL "") + GETINCDIR(log4cpp-config --cflags LOG4CPP_INC) + if(LOG4CPP_INC STREQUAL "") + message(FATAL_ERROR "Variable LOG4CPP_INC is not defined and could not be found with log4cpp-config. The location of a pre-built log4cpp install must be defined either as $ cmake -DLOG4CPP_INC=/path/to/LOG4CPP_includes or as an environment variable $ export LOG4CPP_INC=/path/to/LOG4CPP_includes") + endif() +endif() +################################################################################ + +LIST(APPEND GENIE_CXX_FLAGS -DGENIE_VERSION=${GENIE_VERSION}) + +############################### GSL ###################################### +if(GENIE_VERSION VERSION_GREATER 2.12.999) + if(GSL_LIB STREQUAL "") + GETLIBDIR(gsl-config --libs GSL_LIB) + if(GSL_LIB STREQUAL "") + message(FATAL_ERROR "Variable GSL_LIB is not defined and could not be found with gsl-config. The location of a pre-built gsl install must be defined either as $ cmake -DGSL_LIB=/path/to/GSL_libraries or as an environment variable $ export GSL_LIB=/path/to/GSL_libraries") + endif() + endif() + + if(GSL_INC STREQUAL "") + GETINCDIR(gsl-config --cflags GSL_INC) + if(GSL_INC STREQUAL "") + message(FATAL_ERROR "Variable GSL_INC is not defined and could not be found with gsl-config. The location of a pre-built gsl install must be defined either as $ cmake -DGSL_INC=/path/to/GSL_includes or as an environment variable $ export GSL_INC=/path/to/GSL_includes") + endif() + endif() + + GETLIBS(gsl-config --libs GSL_LIB_LIST) + + if(GENIE_REWEIGHT STREQUAL "") + message(FATAL_ERROR "Variable GENIE_REWEIGHT is not defined. When using GENIE v3+, we require the reweight product to be built and accessible via the environment variable GENIE_REWEIGHT") + endif() +endif(GENIE_VERSION VERSION_GREATER 2.12.999) +################################################################################ + +LIST(APPEND GENIE_LIBS LHAPDF xml2 log4cpp) + +LIST(APPEND GENIE_LINK_DIRS + ${GENIE_LIB_DIR} + ${LHAPDF_LIB} + ${LOG4CPP_LIB}) + +if(GENIE_VERSION VERSION_GREATER 2.12.999) + LIST(APPEND GENIE_INCLUDE_DIRS + ${GENIE_INCLUDES_DIR} + ${GENIE_REWEIGHT}/src + ${GSL_INC} + ${LHAPDF_INC} + ${LIBXML2_INC} + ${LOG4CPP_INC}) + + LIST(APPEND GENIE_LINK_DIRS + ${GENIE_REWEIGHT}/lib + ${GSL_LIB} + ) + + LIST(APPEND GENIE_LIBS ${GSL_LIB_LIST}) +else() + LIST(APPEND GENIE_INCLUDE_DIRS + ${GENIE_INCLUDES_DIR} + ${LHAPDF_INC} + ${LIBXML2_INC} + ${LOG4CPP_INC}) +endif(GENIE_VERSION VERSION_GREATER 2.12.999) + +BuildFlagString(GENIE_CXX_FLAGS " " ${GENIE_CXX_FLAGS}) +BuildFlagString(GENIE_LINK_DIRS "-L" ${GENIE_LINK_DIRS}) + +set(NEED_PYTHIA6 TRUE) +set(NEED_ROOTPYTHIA6 TRUE) + +set(NEED_ROOTEVEGEN TRUE) + +SET(USE_GENIE TRUE CACHE BOOL "Whether to enable GENIE (reweight) support. Requires external libraries. " FORCE) + +cmessage(STATUS "GENIE") +cmessage(STATUS " Version : ${GENIE_VERSION}") +cmessage(STATUS " Flags : ${GENIE_CXX_FLAGS}") +cmessage(STATUS " Includes : ${GENIE_INCLUDE_DIRS}") +cmessage(STATUS " Link Dirs : ${GENIE_LINK_DIRS}") +cmessage(STATUS " Libs : ${GENIE_LIBS}") diff --git a/cmake/InputHandlerSetup.cmake b/cmake/InputHandlerSetup.cmake index e69e227..6970f7d 100644 --- a/cmake/InputHandlerSetup.cmake +++ b/cmake/InputHandlerSetup.cmake @@ -1,56 +1,63 @@ # Copyright 2018 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 . ################################################################################ ################################# NuWro ###################################### if(USE_NuWro) include(${CMAKE_SOURCE_DIR}/cmake/NuWroSetup.cmake) cmessage(STATUS "Using NuWro.") set(USE_NuWro TRUE CACHE BOOL "Whether to enable NuWro support. " FORCE) endif() ################################# NEUT ####################################### if(USE_NEUT) include(${CMAKE_SOURCE_DIR}/cmake/NEUTSetup.cmake) cmessage(STATUS "Using NEUT.") set(USE_NEUT TRUE CACHE BOOL "Whether to enable NEUT support. " FORCE) endif() +################################ GENIE ####################################### +if(USE_GENIE) + include(${CMAKE_SOURCE_DIR}/cmake/GENIESetup.cmake) + cmessage(STATUS "Using GENIE.") + set(USE_GENIE TRUE CACHE BOOL "Whether to enable GENIE support. " FORCE) +endif() + if(NEED_ROOTEVEGEN) cmessage(STATUS "Require ROOT eve generation libraries") LIST(REVERSE ROOT_LIBS) LIST(APPEND ROOT_LIBS Gui Ged Geom TreePlayer EG Eve) LIST(REVERSE ROOT_LIBS) endif() if(NEED_ROOTPYTHIA6) cmessage(STATUS "Require ROOT Pythia6 libraries") LIST(APPEND ROOT_LIBS EGPythia6 Pythia6) endif() LIST(APPEND EXTRA_LIBS ${ROOT_LIBS}) diff --git a/cmake/NEUTSetup.cmake b/cmake/NEUTSetup.cmake index 2f7c60b..a40b869 100644 --- a/cmake/NEUTSetup.cmake +++ b/cmake/NEUTSetup.cmake @@ -1,130 +1,127 @@ # Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ if(NEUT_ROOT STREQUAL "") cmessage(FATAL_ERROR "Variable NEUT_ROOT is not defined. Please export environment variable NEUT_ROOT or configure with -DNEUT_ROOT=/path/to/NEUT. This must be set to point to a prebuilt NEUT instance.") endif() if(CERN STREQUAL "") cmessage(FATAL_ERROR "Variable CERN is not defined. Please export environment variable CERN or configure with -DCERN=/path/to/CERNLIB. This must be set to point to a prebuilt CERNLIB instance.") endif() if(CERN_LEVEL STREQUAL "") cmessage(FATAL_ERROR "Variable CERN_LEVEL is not defined. Please export environment variable CERN_LEVEL or configure with -DCERN_LEVEL=XXXX (likely to be 2005).") endif() if(${NEUT_VERSION} VERSION_LESS 5.4.0) set(NEUT_LIB_DIR ${NEUT_ROOT}/lib/Linux_pc) else() set(NEUT_LIB_DIR ${NEUT_ROOT}/lib) endif() set(NEUT_CLASS ${NEUT_ROOT}/src/neutclass) -LIST(APPEND EXTRA_CXX_FLAGS -DNEUT_ENABLED -DNEUT_VERSION=${NEUT_VERSION}) +LIST(APPEND EXTRA_CXX_FLAGS -DUSE_NEUT -DNEUT_VERSION=${NEUT_VERSION}) if(${NEUT_VERSION} VERSION_GREATER 5.4.0) LIST(APPEND EXTRA_CXX_FLAGS -DNEUT_COMMON_QEAV) endif() -LIST(APPEND EXTRA_CXX_FLAGS - -I${NEUT_ROOT}/include - -I${NEUT_ROOT}/src/neutclass - -I${NEUT_ROOT}/src/reweight) +include_directories(${NEUT_ROOT}/include ${NEUT_ROOT}/src/neutclass ${NEUT_ROOT}/src/reweight) LIST(APPEND EXTRA_LINK_DIRS ${NEUT_LIB_DIR} ${CERN}/${CERN_LEVEL}/lib ${NEUT_ROOT}/src/reweight) LIST(APPEND EXTRA_LIBS NReWeight) if(${NEUT_VERSION} VERSION_EQUAL 5.4.2) LIST(APPEND EXTRA_LIBS neutcore_5.4.2 nuccorspl_5.4.2 #typo in NEUT, may hopefully disappear nuceff_5.4.2 partnuck_5.4.2 skmcsvc_5.4.2 tauola_5.4.2 HT2p2h_5.4.0 N1p1h_5.4.0) LIST(APPEND EXTRA_CXX_FLAGS -DNEUT_COMMON_QEAV) elseif(${NEUT_VERSION} VERSION_EQUAL 5.4.0) LIST(APPEND EXTRA_LIBS NReWeight neutcore_5.4.0 nuccorspl_5.4.0 #typo in NEUT, may hopefully disappear nuceff_5.4.0 partnuck_5.4.0 skmcsvc_5.4.0 tauola_5.4.0 HT2p2h_5.4.0 N1p1h_5.4.0) else() LIST(APPEND EXTRA_LIBS NReWeight neutcore nuccorrspl nuceff partnuck skmcsvc tauola) endif() LIST(APPEND EXTRA_LIBS jetset74 pdflib804 mathlib packlib pawlib gfortran) set(NEUT_ROOT_LIBS) LIST(APPEND NEUT_ROOT_LIBS ${NEUT_CLASS}/neutctrl.so ${NEUT_CLASS}/neutfsivert.so) # Check for new versions of NEUT with NUCLEON FSI if(EXISTS "${NEUT_CLASS}/neutnucfsistep.so") set(NEUT_NUCFSI 1) LIST(APPEND EXTRA_CXX_FLAGS -DNEUT_NUCFSI_ENABLED) LIST(APPEND NEUT_ROOT_LIBS ${NEUT_CLASS}/neutnucfsistep.so ${NEUT_CLASS}/neutnucfsivert.so ) endif() if(${NEUT_VERSION} VERSION_LESS 5.4.0) LIST(APPEND NEUT_ROOT_LIBS ${NEUT_CLASS}/neutrootTreeSingleton.so) endif() LIST(APPEND NEUT_ROOT_LIBS ${NEUT_CLASS}/neutvtx.so ${NEUT_CLASS}/neutfsipart.so ${NEUT_CLASS}/neutpart.so ${NEUT_CLASS}/neutvect.so ) foreach(OBJ ${NEUT_ROOT_LIBS}) LIST(APPEND EXTRA_SHAREDOBJS ${OBJ}) endforeach() diff --git a/cmake/NuWroSetup.cmake b/cmake/NuWroSetup.cmake index 971cdf7..26ccc68 100644 --- a/cmake/NuWroSetup.cmake +++ b/cmake/NuWroSetup.cmake @@ -1,48 +1,48 @@ # Copyright 2018 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ if(NUWRO STREQUAL "") cmessage(FATAL_ERROR "Variable NUWRO is not defined. " "This must be set to point to a prebuilt NuWro instance.") endif() -LIST(APPEND EXTRA_CXX_FLAGS -DNUWRO_ENABLED -Wno-sign-compare -Wno-unused-variable -Wno-reorder) +LIST(APPEND EXTRA_CXX_FLAGS -DUSE_NUWRO -Wno-sign-compare -Wno-unused-variable -Wno-reorder) -LIST(APPEND EXTRA_CXX_FLAGS -I${NUWRO}/src) +include_directories(${NUWRO}/src) if(NOT EXISTS ${NUWRO}/bin/event1.so) if(EXISTS ${NUWRO}/build/${CMAKE_SYSTEM_NAME}/lib) if(NUWRO_INC STREQUAL "") cmessage(FATAL_ERROR "Variable NUWRO_INC is not defined. " "This must be set to point to an installed NuWro instance.") endif() LIST(APPEND EXTRA_LINK_DIRS ${NUWRO}/build/${CMAKE_SYSTEM_NAME}/lib) LIST(APPEND EXTRA_LIBS event) else() cmessage(FATAL_ERROR "Expected to find the NuWro event library in: ${NUWRO}/bin/event1.so, or if using NuWro with reweight support: ${NUWRO}/build/${CMAKE_SYSTEM_NAME}/lib/libevent.a. Is NuWro built?") endif() else() LIST(APPEND EXTRA_SHAREDOBJS ${NUWRO}/bin/event1.so) endif() set(NEED_PYTHIA6 TRUE) set(NEED_ROOTPYTHIA6 TRUE) diff --git a/cmake/ROOTSetup.cmake b/cmake/ROOTSetup.cmake index 7ec33b1..d5d73c9 100644 --- a/cmake/ROOTSetup.cmake +++ b/cmake/ROOTSetup.cmake @@ -1,170 +1,170 @@ # Copyright 2018 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ -if ( NOT DEFINED ENV{ROOTSYS} ) +if (NOT DEFINED ENV{ROOTSYS}) cmessage (FATAL_ERROR "$ROOTSYS is not defined, please set up ROOT first.") else() cmessage(STATUS "Using ROOT installed at $ENV{ROOTSYS}") set(CMAKE_ROOTSYS $ENV{ROOTSYS}) endif() # Get cflags from ROOT execute_process (COMMAND root-config --cflags OUTPUT_VARIABLE ROOT_CXX_FLAGS_RAW OUTPUT_STRIP_TRAILING_WHITESPACE) string(REPLACE " " ";" ROOT_CXX_FLAGS "${ROOT_CXX_FLAGS_RAW}") # Get libdir from ROOT execute_process (COMMAND root-config --libdir OUTPUT_VARIABLE ROOT_LIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE) # Get version from ROOT execute_process (COMMAND root-config --version OUTPUT_VARIABLE ROOT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) # Get features from ROOT execute_process (COMMAND root-config --features OUTPUT_VARIABLE ROOT_FEATURES OUTPUT_STRIP_TRAILING_WHITESPACE) LIST(APPEND EXTRA_LINK_DIRS ${ROOT_LIBDIR}) LIST(APPEND ROOT_LIBS Core Cint RIO XMLIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread EG Geom GenVector) if(USE_MINIMIZER) if("${ROOT_FEATURES}" MATCHES "minuit2") cmessage(STATUS "ROOT built with MINUIT2 support") LIST(APPEND EXTRA_CXX_FLAGS -D__MINUIT2_ENABLED__) else() cmessage(FATAL_ERROR "ROOT built without MINUIT2 support but minimizer functionality requested. Either configure with -DUSE_MINIMIZER=FALSE or use a version of ROOT with MINUIT2 support.") endif() string(REGEX MATCH "6.*" ROOTVERSIXMATCH ${ROOT_VERSION}) if(ROOTVERSIXMATCH) cmessage(STATUS "Using ROOT6, We are essentially flying blind here.") LIST(REMOVE_ITEM ROOT_LIBS Cint) LIST(APPEND EXTRA_CXX_FLAGS -DROOT6_USE_FIT_FITTER_INTERFACE) set(USE_ROOT6 True) else() string(REGEX MATCH "5.34/([0-9]+)" ROOTVERSMATCH ${ROOT_VERSION}) if(NOT ROOTVERSMATCH OR ${CMAKE_MATCH_1} LESS "19") cmessage(FATAL_ERROR "ROOT Version: ${ROOT_VERSION} has out of date minimizer interface, but minimizer functionality requested. Please configure with -DUSE_MINIMIZER=FALSE or update to 5.34/19 or greater to enable minimization features.") endif() endif() endif() if("${ROOT_FEATURES}" MATCHES "opengl") cmessage(STATUS "ROOT built with OpenGL support") LIST(APPEND ROOT_LIBS RGL) endif() if(DEFINED NEED_ROOTPYTHIA6 AND NEED_ROOTPYTHIA6) LIST(APPEND ROOT_LIBS EGPythia6 Pythia6) endif() cmessage ( STATUS "[ROOT]: root-config --version: ${ROOT_VERSION} ") cmessage ( STATUS "[ROOT]: root-config --cflags : ${ROOT_CXX_FLAGS} ") cmessage ( STATUS "[ROOT]: root-config --libs : ${ROOT_LD_FLAGS} ") LIST(APPEND EXTRA_CXX_FLAGS ${ROOT_CXX_FLAGS}) #Helper functions for building dictionaries function(GenROOTDictionary OutputDictName Header LinkDef) get_directory_property(incdirs INCLUDE_DIRECTORIES) string(REPLACE ";" ";-I" LISTDIRINCLUDES "-I${incdirs}") string(REPLACE " " ";" LISTCPPFLAGS "${EXTRA_CXX_FLAGS}") #ROOT5 CINT cannot handle it. list(REMOVE_ITEM LISTCPPFLAGS "-std=c++11") message(STATUS "LISTCPPFLAGS: ${LISTCPPFLAGS}") message(STATUS "LISTINCLUDES: ${LISTDIRINCLUDES}") #Learn how to generate the Dict.cxx and Dict.hxx add_custom_command( OUTPUT "${OutputDictName}.cxx" "${OutputDictName}.h" COMMAND rootcint ARGS -f ${OutputDictName}.cxx -c -p ${LISTDIRINCLUDES} ${LISTCPPFLAGS} ${Header} ${LinkDef} DEPENDS ${Header};${LinkDef}) endfunction() function(BuildROOTProject ProjectName InputFile CommaSeparatedClassesToDump LIBLINKMODE) string(REPLACE "," ";" HeadersToDump ${CommaSeparatedClassesToDump}) set(OUTPUTFILES ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectSource.cxx ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}LinkDef.h ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectHeaders.h ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectInstances.h) cmessage(STATUS "As part of ROOT project: ${ProjectName}") foreach (header ${HeadersToDump}) LIST(APPEND OUTPUTFILES "${CMAKE_BINARY_DIR}/${ProjectName}/${header}.h") cmessage(STATUS "Will generate: ${CMAKE_BINARY_DIR}/${ProjectName}/${header}.h") endforeach() add_custom_command( OUTPUT ${OUTPUTFILES} COMMAND ${CMAKE_BINARY_DIR}/src/Utils/DumpROOTClassesFromVector ARGS ${InputFile} ${CMAKE_BINARY_DIR}/${ProjectName} ${CommaSeparatedClassesToDump} VERBATIM DEPENDS DumpROOTClassesFromVector) add_custom_target(${ProjectName}_sources DEPENDS ${OUTPUTFILES}) GenROOTDictionary( ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectDict ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectHeaders.h ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}LinkDef.h ) add_custom_target(${ProjectName}ProjectDict DEPENDS ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectDict.cxx ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectDict.h ) # add_dependencies(${ProjectName}ProjectDict ${ProjectName}_sources) #ProjectSource.cxx includes ProjectDict.cxx, so no need to add to compilation. set(ROAA_SOURCEFILES ${CMAKE_BINARY_DIR}/${ProjectName}/${ProjectName}ProjectSource.cxx) add_library(${ProjectName} ${LIBLINKMODE} ${ROAA_SOURCEFILES}) add_dependencies(${ProjectName} ${ProjectName}ProjectDict) endfunction() diff --git a/cmake/StringAndListUtils.cmake b/cmake/StringAndListUtils.cmake new file mode 100644 index 0000000..f6fa641 --- /dev/null +++ b/cmake/StringAndListUtils.cmake @@ -0,0 +1,34 @@ +function(BuildFlagString OUTPUTLIST DELIMITER) + LIST(APPEND INPUT_LIST ${ARGN}) + if(NOT DELIMITER STREQUAL "") + string(STRIP ${DELIMITER} DELIMITER) + endif() + if(NOT "${INPUT_LIST}" STREQUAL "") + string(REPLACE ";" " ${DELIMITER}" LIST_STR "${DELIMITER}${INPUT_LIST}") + string(STRIP ${LIST_STR} LIST_STR) + set(${OUTPUTLIST} ${LIST_STR} PARENT_SCOPE) + else() + set(${OUTPUTLIST} PARENT_SCOPE) + endif() +endfunction() + +#Here we want to look for linker flags in a list of libraries and escape them +function(BuildLibraryFlagString OUTPUTLIST) + set(INPUT_LIST ${ARGN}) + BuildFlagString(NEED_SCRUB_LINKOPTS "-l" ${INPUT_LIST}) + string(REPLACE "-l-" "-" LIST_STR ${NEED_SCRUB_LINKOPTS}) + set(${OUTPUTLIST} ${LIST_STR} PARENT_SCOPE) +endfunction() + +function(CatStringsIfNotEmpty OUTPUT_STRING) + set(BUILD_STR) + foreach(I ${ARGN}) + if(NOT I STREQUAL "") + set(BUILD_STR "${BUILD_STR} ${I}") + endif() + endforeach() + if(NOT BUILD_STR STREQUAL "") + string(STRIP ${BUILD_STR} BUILD_STR) + endif() + set(${OUTPUT_STRING} ${BUILD_STR} PARENT_SCOPE) +endfunction() diff --git a/cmake/c++CompilerSetup.cmake b/cmake/c++CompilerSetup.cmake index a6dd6cc..aec1ad2 100644 --- a/cmake/c++CompilerSetup.cmake +++ b/cmake/c++CompilerSetup.cmake @@ -1,83 +1,58 @@ # Copyright 2018 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(CXX_WARNINGS -Wall ) +set(CXX_WARNINGS -Wall -Wextra) -LIST(APPEND EXTRA_CXX_FLAGS -Wall -Wextra -Werror -Wno-delete-non-virtual-dtor -Wno-unused "-D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") +LIST(APPEND EXTRA_CXX_FLAGS ${CXX_WARNINGS} -Werror -Wno-delete-non-virtual-dtor -Wno-unused "-D__FILENAME__=\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"") -cmessage(DEBUG "EXTRA_CXX_FLAGS: ${EXTRA_CXX_FLAGS}") -string(REPLACE ";" " " STR_EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STR_EXTRA_CXX_FLAGS} ${CXX_WARNINGS}") - -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") - -SET(STR_EXTRA_LINK_DIRS) -if(NOT EXTRA_LINK_DIRS STREQUAL "") - string(REPLACE ";" " -L" STR_EXTRA_LINK_DIRS "-L${EXTRA_LINK_DIRS}") -endif() +BuildFlagString(NUISANCE_LINK_DIRS "-L" ${EXTRA_LINK_DIRS}) LIST(APPEND EXTRA_LIBS dl) +BuildLibraryFlagString(STR_EXTRA_LIBS ${EXTRA_LIBS}) +BuildFlagString(STR_EXTRA_SHAREDOBJS " " ${EXTRA_SHAREDOBJS}) -SET(STR_EXTRA_LIBS) -if(NOT EXTRA_LIBS STREQUAL "") - SET(STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS) - string(REPLACE ";" " -l" STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS "-l${EXTRA_LIBS}") - string(REPLACE "-l-" "-" STR_EXTRA_LIBS ${STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS}) -endif() - -SET(STR_EXTRA_SHAREDOBJS) -if(NOT EXTRA_SHAREDOBJS STREQUAL "") - string(REPLACE ";" " " STR_EXTRA_SHAREDOBJS "${EXTRA_SHAREDOBJS}") -endif() +#This ends up holding all of the libraries and search paths for extenal dependencies +CatStringsIfNotEmpty(NUISANCE_DEPEND_LIBS + ${STR_EXTRA_SHAREDOBJS} + ${STR_EXTRA_LIBS}) LIST(APPEND EXTRA_LINK_FLAGS -Wl,--no-as-needed) -SET(STR_EXTRA_LINK_FLAGS) -if(NOT EXTRA_LINK_FLAGS STREQUAL "") - string(REPLACE ";" " " STR_EXTRA_LINK_FLAGS "${EXTRA_LINK_FLAGS}") -endif() +BuildFlagString(STR_EXTRA_LINK_FLAGS " " ${EXTRA_LINK_FLAGS}) -cmessage(DEBUG "EXTRA_LINK_DIRS: ${STR_EXTRA_LINK_DIRS}") -cmessage(DEBUG "EXTRA_LIBS: ${STR_EXTRA_LIBS}") -cmessage(DEBUG "EXTRA_SHAREDOBJS: ${STR_EXTRA_SHAREDOBJS}") -cmessage(DEBUG "EXTRA_LINK_FLAGS: ${STR_EXTRA_LINK_FLAGS}") +CatStringsIfNotEmpty(CMAKE_LINK_FLAGS + ${CMAKE_LINK_FLAGS} + ${STR_EXTRA_LINK_FLAGS}) -if(NOT STR_EXTRA_LINK_DIRS STREQUAL "" AND NOT STR_EXTRA_LIBS STREQUAL "") - SET(CMAKE_DEPENDLIB_FLAGS "${STR_EXTRA_LINK_DIRS} ${STR_EXTRA_LIBS}") -endif() -if(NOT STR_EXTRA_SHAREDOBJS STREQUAL "") - SET(CMAKE_DEPENDLIB_FLAGS "${CMAKE_DEPENDLIB_FLAGS} ${STR_EXTRA_SHAREDOBJS}") -endif() +get_directory_property(NUISANCE_INCLUDE_DIRS INCLUDE_DIRECTORIES) -if(NOT EXTRA_LINK_FLAGS STREQUAL "") - if(NOT CMAKE_LINK_FLAGS STREQUAL "") - SET(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${STR_EXTRA_LINK_FLAGS}") - else() - SET(CMAKE_LINK_FLAGS "${STR_EXTRA_LINK_FLAGS}") - endif() -endif() +BuildFlagString(NUISANCE_CXX_FLAGS " " ${EXTRA_CXX_FLAGS}) +CatStringsIfNotEmpty(NUISANCE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${NUISANCE_CXX_FLAGS} ) if (VERBOSE) cmessage (STATUS "C++ Compiler : ${CXX_COMPILER_NAME}") - cmessage (STATUS " flags : ${CMAKE_CXX_FLAGS}") - cmessage (STATUS " Release flags : ${CMAKE_CXX_FLAGS_RELEASE}") - cmessage (STATUS " Debug flags : ${CMAKE_CXX_FLAGS_DEBUG}") - cmessage (STATUS " Link Flags : ${CMAKE_LINK_FLAGS}") - cmessage (STATUS " Lib Flags : ${CMAKE_DEPENDLIB_FLAGS}") + cmessage (STATUS " Flags : ${NUISANCE_CXX_FLAGS}") + cmessage (STATUS " Release Flags : ${CMAKE_CXX_FLAGS_RELEASE}") + cmessage (STATUS " Debug Flags : ${CMAKE_CXX_FLAGS_DEBUG}") + cmessage (STATUS " Include Dris : ${NUISANCE_INCLUDE_DIRS}") + cmessage (STATUS " Linker Flags : ${CMAKE_LINK_FLAGS}") + cmessage (STATUS " Link Dirs : ${NUISANCE_LINK_DIRS}") + cmessage (STATUS " Lib Flags : ${NUISANCE_DEPEND_LIBS}") endif() + +add_compile_options(${EXTRA_CXX_FLAGS}) diff --git a/cmake/cacheVariables.cmake b/cmake/cacheVariables.cmake index 0c45699..ebf15a6 100644 --- a/cmake/cacheVariables.cmake +++ b/cmake/cacheVariables.cmake @@ -1,99 +1,116 @@ # Copyright 2018 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 . ################################################################################ function(CheckAndSetDefaultEnv VARNAME DEFAULT CACHETYPE DOCSTRING ENVNAME) #cmessage(DEBUG "Trying to assign variable ${VARNAME} into the cache.") if(NOT DEFINED ${VARNAME}) if(DEFINED ENV{${ENVNAME}} AND NOT $ENV{${ENVNAME}} STREQUAL "") set(${VARNAME} $ENV{${ENVNAME}} CACHE ${CACHETYPE} ${DOCSTRING}) cmessage(DEBUG " Read ${VARNAME} from ENVVAR ${ENVNAME} as $ENV{${ENVNAME}}.") else() set(${VARNAME} ${DEFAULT} CACHE ${CACHETYPE} ${DOCSTRING}) endif() else() set(${VARNAME} ${${VARNAME}} CACHE ${CACHETYPE} ${DOCSTRING}) unset(${VARNAME}) endif() cmessage(CACHE "--Set cache variable: \"${VARNAME}\" to \"${${VARNAME}}\", in cache ${CACHETYPE}.") endfunction() function(CheckAndSetDefaultCache VARNAME DEFAULT CACHETYPE DOCSTRING) # cmessage(DEBUG "Trying to assign variable ${VARNAME} into the cache.") if(NOT DEFINED ${VARNAME}) set(${VARNAME} ${DEFAULT} CACHE ${CACHETYPE} ${DOCSTRING}) else() set(${VARNAME} ${${VARNAME}} CACHE ${CACHETYPE} ${DOCSTRING}) unset(${VARNAME}) endif() cmessage(CACHE "--Set cache variable: \"${VARNAME}\" to \"${${VARNAME}}\", in cache ${CACHETYPE}.") endfunction() function(CheckAndSetDefault VARNAME DEFAULT) # cmessage(DEBUG "Trying to assign variable ${VARNAME}.") if(NOT DEFINED ${VARNAME}) set(${VARNAME} ${DEFAULT} PARENT_SCOPE) set(${VARNAME} ${DEFAULT}) endif() cmessage(CACHE "--Set variable: \"${VARNAME}\" to \"${${VARNAME}}\".") endfunction() CheckAndSetDefaultCache(VERBOSE TRUE BOOL "Whether to configure loudly.") set (CMAKE_SKIP_BUILD_RPATH TRUE) #Changes default install path to be a subdirectory of the build dir. #Can set build dir at configure time with -DCMAKE_INSTALL_PREFIX=/install/path if(CMAKE_INSTALL_PREFIX STREQUAL "" OR CMAKE_INSTALL_PREFIX STREQUAL "/usr/local") set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}") elseif(NOT DEFINED CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}") endif() if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE DEBUG) elseif(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE DEBUG) endif() # Misc CheckAndSetDefaultCache(EXTRA_SETUP_SCRIPT "" PATH "The path to an extra script to inject into the NUISANCE setup script. <>") CheckAndSetDefaultCache(USE_MINIMIZER TRUE INTERNAL "Whether we are using the ROOT minimization libraries. ") +CheckAndSetDefaultCache(USE_GENERATOR_REWEIGHT TRUE BOOL "Whether we are using the generator reweighting libraries. ") + CheckAndSetDefaultCache(USE_ROOT6 FALSE INTERNAL "Whether we are using the ROOT 6. ") # NuWro CheckAndSetDefaultCache(USE_NuWro FALSE BOOL "Whether to enable NuWro support. ") CheckAndSetDefaultEnv(NUWRO "" PATH "Path to NuWro source tree root directory. Overrides environment variable \$NUWRO <>" NUWRO) CheckAndSetDefaultEnv(NUWRO_INC "" PATH "Path to NuWro installed includes directory, needs to contain \"params_all.h\". Overrides environment variable \$NUWRO_INC <>" NUWRO_INC) # NEUT CheckAndSetDefaultCache(USE_NEUT FALSE BOOL "Whether to enable NEUT (reweight) support. Requires external libraries. ") CheckAndSetDefaultEnv(NEUT_VERSION FALSE STRING "NEUT version string, e.g. 5.4.0. <5.4.0>" NEUT_VERSION) CheckAndSetDefaultEnv(NEUT_ROOT "" PATH "Path to NEUT source tree root directory. Overrides environment variable \$NEUT_ROOT <>" NEUT_ROOT) CheckAndSetDefaultEnv(CERN "" PATH "Path to CERNLIB source tree root directory that NEUT was built against. Overrides environment variable \$CERN <>" CERN) CheckAndSetDefaultEnv(CERN_LEVEL "" STRING "CERNLIB Library version. Overrides environment variable \$CERN_LEVEL <>" CERN_LEVEL) +# GENIE +CheckAndSetDefaultCache(USE_GENIE FALSE BOOL "Whether to enable GENIE (reweight) support. Requires external libraries. ") +CheckAndSetDefaultCache(GENIE_VERSION "AUTO" STRING "GENIE Version ") +CheckAndSetDefaultEnv(GENIE "" PATH "Path to GENIE source tree root directory. Overrides environment variable \$GENIE <>" GENIE) +CheckAndSetDefaultEnv(GENIE_REWEIGHT "" PATH "Path to GENIE ReWeight directory. Only relevant for GENIE v3+. Overrides environment variable \$GENIE_REWEIGHT <>" GENIE_REWEIGHT) +CheckAndSetDefaultEnv(LHAPDF_LIB "" PATH "Path to pre-built LHAPDF libraries. Overrides environment variable \$LHAPDF_LIB. <>" LHAPDF_LIB) +CheckAndSetDefaultEnv(LHAPDF_INC "" PATH "Path to installed LHAPDF headers. Overrides environment variable \$LHAPDF_INC. <>" LHAPDF_INC) +CheckAndSetDefaultEnv(LHAPATH "" PATH "Path to LHA PDF inputs. Overrides environment variable \$LHAPATH. <>" LHAPATH) +CheckAndSetDefaultEnv(LIBXML2_LIB "" PATH "Path to pre-built LIBXML2 libraries. Overrides environment variable \$LIBXML2_LIB. <>" LIBXML2_LIB) +CheckAndSetDefaultEnv(LIBXML2_INC "" PATH "Path to installed LIBXML2 headers. Overrides environment variable \$LIBXML2_INC. <>" LIBXML2_INC) +CheckAndSetDefaultEnv(LOG4CPP_LIB "" PATH "Path to pre-built LOG4CPP libraries. Overrides environment variable \$LOG4CPP_LIB. <>" LOG4CPP_LIB) +CheckAndSetDefaultEnv(LOG4CPP_INC "" PATH "Path to installed LOG4CPP headers. Overrides environment variable \$LOG4CPP_INC. <>" LOG4CPP_INC) +CheckAndSetDefaultEnv(GSL_LIB "" PATH "Path to pre-built gsl libraries. Overrides environment variable \$GSL_LIB. <>" GSL_LIB) +CheckAndSetDefaultEnv(GSL_INC "" PATH "Path to installed gsl headers. Overrides environment variable \$GSL_INC. <>" GSL_INC) + # Pythia CheckAndSetDefaultEnv(PYTHIA6 "" PATH "Path to directory containing libPythia6.so. Overrides environment variable \$PYTHIA6 <>" PYTHIA6) CheckAndSetDefault(NEED_PYTHIA6 FALSE) CheckAndSetDefault(NEED_ROOTEVEGEN FALSE) CheckAndSetDefault(NEED_ROOTPYTHIA6 FALSE) diff --git a/cmake/fhiclcppSetup.cmake b/cmake/fhiclcppSetup.cmake index 4af68fe..021bd29 100644 --- a/cmake/fhiclcppSetup.cmake +++ b/cmake/fhiclcppSetup.cmake @@ -1,16 +1,16 @@ ###### FHICL set up include(ExternalProject) ExternalProject_Add(fhiclcpp-simple PREFIX "${PROJECT_BINARY_DIR}/fhiclcpp-simple" GIT_REPOSITORY https://github.com/luketpickering/fhiclcpp-simple.git GIT_TAG stable UPDATE_DISCONNECTED 1 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DSETUPFILENAME=fhiclcpp.setup.sh) -LIST(APPEND EXTRA_CXX_FLAGS -I${CMAKE_INSTALL_PREFIX}/include) +include_directories(${CMAKE_INSTALL_PREFIX}/include) diff --git a/cmake/parseConfigApp.cmake b/cmake/parseConfigApp.cmake new file mode 100644 index 0000000..0096a14 --- /dev/null +++ b/cmake/parseConfigApp.cmake @@ -0,0 +1,140 @@ +function(GETFIRSTMATCHINGDELMIMMEDDIR DELIM CONFIGAPP ARG DIR_OUT FAILURE_IS_NOT_ERROR) + + if(DELIM STREQUAL "") + cmessage(FATAL_ERROR "GETFIRSTMATCHINGDELMIMMEDDIR Passed no delimiter. This is a build configuration bug in NUISANCE, please report to the developers.") + endif() + + if(CONFIGAPP STREQUAL "") + cmessage(FATAL_ERROR "GETFIRSTMATCHINGDELMIMMEDDIR Passed no configuration application. This is a build configuration bug in NUISANCE, please report to the developers.") + endif() + + SET(CONFIGAPP_LOCATION "CONFIGAPP_LOCATION-NOTFOUND") + find_program(CONFIGAPP_LOCATION ${CONFIGAPP}) + if(NOT CONFIGAPP_LOCATION STREQUAL "CONFIGAPP_LOCATION-NOTFOUND") + execute_process (COMMAND ${CONFIGAPP_LOCATION} + ${ARG} OUTPUT_VARIABLE CONFIGAPP_RESPONSE_RAW OUTPUT_STRIP_TRAILING_WHITESPACE) + + cmessage(DEBUG "${CONFIGAPP_LOCATION} ${ARG} responded with: \"${CONFIGAPP_RESPONSE_RAW}\"") + + if(CONFIGAPP_RESPONSE_RAW STREQUAL "") + if(FAILURE_IS_NOT_ERROR) + cmessage(DEBUG "\"${CONFIGAPP_LOCATION} ${ARG}\" produced no output and was expected to.") + set(${DIR_OUT} "" PARENT_SCOPE) + else() + cmessage(FATAL_ERROR "\"${CONFIGAPP_LOCATION} ${ARG}\" produced no output and was required to.") + endif() + else() + string(REGEX MATCH "${DELIM}\([^ ]+\)" PARSE_CONFIGAPP_RESPONSE_MATCH ${CONFIGAPP_RESPONSE_RAW}) + + if(NOT PARSE_CONFIGAPP_RESPONSE_MATCH) + if(FAILURE_IS_NOT_ERROR) + cmessage(DEBUG "Couldn't find ${DELIM} flag, found: \"${CONFIGAPP_RESPONSE_RAW}\"") + set(${CMAKE_MATCH_1} "") + else() + cmessage(FATAL_ERROR "Expected to be able to parse the result of ${CONFIGAPP} ${ARG} to a lib directory, but couldn't find a ${DELIM} flag, found: \"${CONFIGAPP_RESPONSE_RAW}\"") + endif() + endif() + + set(${DIR_OUT} ${CMAKE_MATCH_1} PARENT_SCOPE) + endif() + else() + cmessage(FATAL_ERROR "[ERROR]: Failed to find dependency configuration application: \"${CONFIGAPP}\"") + endif() +endfunction() + +#Uselike GETLIBDIR(gsl-config --libs GSL_LIB_DIR) +function(GETLIBDIR CONFIGAPP ARG LIBDIR_OUT) + if(ARGN) + set(FAILURE_IS_NOT_ERROR TRUE) + else() + set(FAILURE_IS_NOT_ERROR FALSE) + endif() + GETFIRSTMATCHINGDELMIMMEDDIR( + "-L" + ${CONFIGAPP} + ${ARG} + MATCHING_DIR + ${FAILURE_IS_NOT_ERROR}) + set(${LIBDIR_OUT} ${MATCHING_DIR} PARENT_SCOPE) +endfunction() + +#Uselike GETINCDIR(gsl-config --cflags GSL_INC_DIR) +function(GETINCDIR CONFIGAPP ARG INCDIR_OUT) + if(ARGN) + set(FAILURE_IS_NOT_ERROR TRUE) + else() + set(FAILURE_IS_NOT_ERROR FALSE) + endif() + GETFIRSTMATCHINGDELMIMMEDDIR( + "-I" + ${CONFIGAPP} + ${ARG} + MATCHING_DIR + ${FAILURE_IS_NOT_ERROR}) + set(${INCDIR_OUT} ${MATCHING_DIR} PARENT_SCOPE) +endfunction() + +function(GETALLMATCHINGDELMIMMEDDIR DELIM CONFIGAPP ARG LIST_OUT) + if(DELIM STREQUAL "") + cmessage(FATAL_ERROR "GETALLMATCHINGDELMIMMEDDIR Passed no delimiter. This is a build configuration bug in NUISANCE, please report to the developers.") + endif() + + if(CONFIGAPP STREQUAL "") + cmessage(FATAL_ERROR "GETALLMATCHINGDELMIMMEDDIR Passed no configuration application. This is a build configuration bug in NUISANCE, please report to the developers.") + endif() + + SET(CONFIGAPP_LOCATION "CONFIGAPP_LOCATION-NOTFOUND") + find_program(CONFIGAPP_LOCATION ${CONFIGAPP}) + if(NOT CONFIGAPP_LOCATION STREQUAL "CONFIGAPP_LOCATION-NOTFOUND") + execute_process (COMMAND ${CONFIGAPP_LOCATION} + ${ARG} OUTPUT_VARIABLE CONFIGAPP_RESPONSE_RAW OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(REPLACE " " ";" CONFIGAPP_RESPONSE_LIST "${CONFIGAPP_RESPONSE_RAW}") + + set(LIST_BUILD) + + foreach(I ${CONFIGAPP_RESPONSE_LIST}) + if(I) + string(REGEX MATCH "^${DELIM}" WASMATCHED ${I}) + if(WASMATCHED) + string(REPLACE "${DELIM}" "" I_STRIPPED "${I}") + LIST(APPEND LIST_BUILD ${I_STRIPPED}) + endif() + endif() + endforeach() + + set(${LIST_OUT} ${LIST_BUILD} PARENT_SCOPE) + else() + cmessage(FATAL_ERROR "[ERROR]: Failed to find dependency configuration application: \"${CONFIGAPP}\"") + endif() +endfunction() + +#Uselike GETLIBDIRS(gsl-config --libs GSL_LIB_DIR) +function(GETLIBDIRS CONFIGAPP ARG LIBDIR_OUT) + GETALLMATCHINGDELMIMMEDDIR( + "-L" + ${CONFIGAPP} + ${ARG} + MATCHING_DIR) + set(${LIBDIR_OUT} ${MATCHING_DIR} PARENT_SCOPE) +endfunction() + +#Uselike GETINCDIRS(gsl-config --cflags GSL_INC_DIR) +function(GETINCDIRS CONFIGAPP ARG INCDIR_OUT) + GETALLMATCHINGDELMIMMEDDIR( + "-I" + ${CONFIGAPP} + ${ARG} + MATCHING_DIR) + set(${INCDIR_OUT} ${MATCHING_DIR} PARENT_SCOPE) +endfunction() + +#Uselike GETLIBS(gsl-config --libs GSL_LIB_DIR) +function(GETLIBS CONFIGAPP ARG LIBLIST_OUT) + GETALLMATCHINGDELMIMMEDDIR( + "-l" + ${CONFIGAPP} + ${ARG} + MATCHING_ITEMS) + set(${LIBLIST_OUT} ${MATCHING_ITEMS} PARENT_SCOPE) +endfunction() diff --git a/cmake/pythia6Setup.cmake b/cmake/pythia6Setup.cmake index 012fa34..1a89b0c 100644 --- a/cmake/pythia6Setup.cmake +++ b/cmake/pythia6Setup.cmake @@ -1,31 +1,29 @@ # Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ if(NEED_PYTHIA6) if(PYTHIA6 STREQUAL "") cmessage(FATAL_ERROR "Variable PYTHIA6 is not defined. This must be set to point to a prebuilt PYTHIA6 instance, please set the \$PYTHIA6 environment variable or configure with -DPYTHIA6=/path/to/pythia6.") endif() LIST(APPEND EXTRA_LINK_DIRS ${PYTHIA6}) - LIST(REVERSE EXTRA_LIBS) LIST(APPEND EXTRA_LIBS Pythia6 gfortran) - LIST(REVERSE EXTRA_LIBS) endif() diff --git a/cmake/setup.sh.in b/cmake/setup.sh.in index 95e2b09..7d1fdd8 100644 --- a/cmake/setup.sh.in +++ b/cmake/setup.sh.in @@ -1,112 +1,152 @@ # 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 . ################################################################################ #!/bin/sh ### Adapted from https://unix.stackexchange.com/questions/4965/keep-duplicates-out-of-path-on-source function add_to_PATH () { for d; do d=$(cd -- "$d" && { pwd -P || pwd; }) 2>/dev/null # canonicalize symbolic links if [ -z "$d" ]; then continue; fi # skip nonexistent directory if [ "$d" == "/usr/bin" ] || [ "$d" == "/usr/bin64" ] || [ "$d" == "/usr/local/bin" ] || [ "$d" == "/usr/local/bin64" ]; then case ":$PATH:" in *":$d:"*) :;; *) export PATH=$PATH:$d;; esac else case ":$PATH:" in *":$d:"*) :;; *) export PATH=$d:$PATH;; esac fi done } function add_to_LD_LIBRARY_PATH () { for d; do d=$(cd -- "$d" && { pwd -P || pwd; }) 2>/dev/null # canonicalize symbolic links if [ -z "$d" ]; then continue; fi # skip nonexistent directory if [ "$d" == "/usr/lib" ] || [ "$d" == "/usr/lib64" ] || [ "$d" == "/usr/local/lib" ] || [ "$d" == "/usr/local/lib64" ]; then case ":$LD_LIBRARY_PATH:" in *":$d:"*) :;; *) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$d;; esac else case ":$LD_LIBRARY_PATH:" in *":$d:"*) :;; *) export LD_LIBRARY_PATH=$d:$LD_LIBRARY_PATH;; esac fi done } if [ "@EXTRA_SETUP_SCRIPT@" ]; then if [ ! -e @EXTRA_SETUP_SCRIPT@ ]; then echo "[WARN]: Extra setup script \"@EXTRA_SETUP_SCRIPT@\" requested, but could not be found. Skipping..." else echo "[INFO]: Sourcing extra setup from \"@EXTRA_SETUP_SCRIPT@\"." . @EXTRA_SETUP_SCRIPT@ fi fi add_to_PATH "@CMAKE_INSTALL_PREFIX@/bin" add_to_LD_LIBRARY_PATH "@CMAKE_INSTALL_PREFIX@/lib" if [ ! "${ROOTSYS}" ]; then echo "[INFO]: Sourcing ROOT from: @CMAKE_ROOTSYS@" source "@CMAKE_ROOTSYS@/bin/thisroot.sh" fi if [ "@USE_NEUT@" != "FALSE" ]; then echo "[INFO]: Adding NEUT library paths to the environment." export NEUT_ROOT=@NEUT_ROOT@ export CERN=@CERN@ export CERN_LEVEL=@CERN_LEVEL@ add_to_LD_LIBRARY_PATH "${NEUT_LIB_DIR}" "${NEUT_ROOT}/src/reweight" fi -if [ "@USE_NuWro@" != "FALSE" ]; then +if [ "@USE_NUWRO@" != "FALSE" ]; then echo "[INFO]: Adding NuWro library paths to the environment." export NUWRO="@NUWRO@" add_to_PATH "@NUWRO@/bin" add_to_LD_LIBRARY_PATH "@NUWRO@/build/@CMAKE_SYSTEM_NAME@/lib" if [ "@NUWRO_INC@" ]; then export NUWRO_INC=@NUWRO_INC@ fi fi if [ "@NEED_PYTHIA6@" != "FALSE" ]; then echo "[INFO]: Adding PYTHIA6 library paths to the environment." export PYTHIA6="@PYTHIA6@" add_to_LD_LIBRARY_PATH "@PYTHIA6@" fi +if [ "@USE_GENIE@" != "FALSE" ]; then + echo "[INFO]: Adding GENIE paths to the environment." + + export GENIE="@GENIE@" + + export LHAPDF_LIB="@LHAPDF_LIB@" + export LHAPDF_INC="@LHAPDF_INC@" + + export LIBXML2_LIB="@LIBXML2_LIB@" + export LIBXML2_INC="@LIBXML2_INC@" + + export LOG4CPP_LIB="@LOG4CPP_LIB@" + export LOG4CPP_INC="@LOG4CPP_INC@" + + if [ "@GSL_INC@" ]; then + export GSL_INC="@GSL_INC@" + fi + + if [ "@GSL_LIB@" ]; then + export GSL_LIB="@GSL_LIB@" + fi + + if [ "@LHAPATH@" ]; then + export LHAPATH="@LHAPATH@" + fi + + add_to_PATH "@GENIE@/bin" + + add_to_LD_LIBRARY_PATH "@GENIE@/lib" "@LHAPDF_LIB@" "@LIBXML2_LIB@" "@LOG4CPP_LIB@" + + if [ "@GENIE_REWEIGHT@" ]; then + add_to_LD_LIBRARY_PATH "@GENIE_REWEIGHT@/lib" + fi + + if [ "@GSL_LIB@" ]; then + add_to_LD_LIBRARY_PATH "@GSL_LIB@" + fi + +fi + source @CMAKE_INSTALL_PREFIX@/fhiclcpp.setup.sh add_to_FHICL_FILE_PATH @CMAKE_INSTALL_PREFIX@/fcl export NUISANCE="@CMAKE_SOURCE_DIR@" diff --git a/cmake_old/BuildDynamicSample.in b/cmake_old/BuildDynamicSample.in index 6ed170f..d11283d 100644 --- a/cmake_old/BuildDynamicSample.in +++ b/cmake_old/BuildDynamicSample.in @@ -1,87 +1,87 @@ # 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 . ################################################################################ #!/bin/bash if [ ! "${1}" ] || [ ! -e ${1} ] || [ ! "${2}" ]; then echo "[USAGE]: ${0} input.cxx outputLibName.so [classname]" exit 1 fi if [ ! "${3}" ]; then CN=$(grep "class .*" $1 | sed "s/^class \([0-9a-zA-Z]\+\).*$/\1/g") else CN=${3} fi if [ ! "${CN}" ]; then echo "[ERROR]: Couldn't find class name -- Expected to find a line like: \"class XXXX : public Measurement1D\" in \"$1\". You can also forcibly specify your classes name by passing a third argument to this script." exit 1 fi if [ ! -e compile.tmp ]; then mkdir compile.tmp fi cat $1 > compile.tmp/$1 echo -e "static char const * SampleNames[] = {\"${CN}\"};\n"\ "static int const NSamples = 1;\n"\ "\n"\ "extern \"C\" {\n"\ "int DSF_NSamples() { return NSamples; }\n"\ "char const* DSF_GetSampleName(int i) {\n"\ " if (i < NSamples) {\n"\ " return SampleNames[i];\n"\ " }\n"\ " return 0;\n"\ "}\n"\ "MeasurementBase* DSF_GetSample(int i, void* samplekey) {\n"\ " nuiskey* sk = reinterpret_cast(samplekey);\n"\ " if (!sk) {\n"\ " return 0;\n"\ " }\n"\ "\n"\ " if (sk->GetS(\"name\") != DSF_GetSampleName(i)) {\n"\ " std::cout\n"\ " << \"[ERROR]: When instantiating dynamic sample. Samplekey named: \"\n"\ " << sk->GetS(\"name\") << \", but requested sample named: \"\n"\ " << DSF_GetSampleName(i)\n"\ " << \". It is possible that the nuiskey object is lost in translation. \"\n"\ " \"Was NUISANCE and this dynamic sample manifest built with the same \"\n"\ " \"environment and compiler?\"\n"\ " << std::endl;\n"\ " }\n"\ "\n"\ " if (i == 0) {\n"\ " return new ${CN}(*sk);\n"\ " }\n"\ " return 0;\n"\ "}\n"\ "void DSF_DestroySample(MeasurementBase* mb) { delete mb; }\n"\ "}" >> compile.tmp/$1 -echo "g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@" +echo "g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @NUISANCE_DEPEND_LIBS@" -if ! g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@; then +if ! g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @NUISANCE_DEPEND_LIBS@; then echo "[ERROR]: Failed to compile $1. Generated code can be found in ./compile.tmp/$1" else rm -r compile.tmp echo "Successfully build: $2." fi diff --git a/cmake_old/BuildDynamicSmearcepter.in b/cmake_old/BuildDynamicSmearcepter.in index dce4633..feb960e 100644 --- a/cmake_old/BuildDynamicSmearcepter.in +++ b/cmake_old/BuildDynamicSmearcepter.in @@ -1,89 +1,89 @@ # 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 . ################################################################################ #!/bin/bash if [ ! "${1}" ] || [ ! -e ${1} ] || [ ! "${2}" ]; then echo "[USAGE]: ${0} input.cxx outputLibName.so [classname]" exit 1 fi if [ ! "${3}" ]; then CN=$(grep "class .*" $1 | sed "s/^class \([0-9a-zA-Z]\+\).*$/\1/g") else CN=${3} fi if [ ! "${CN}" ]; then echo "[ERROR]: Couldn't find class name -- Expected to find a line like: \"class XXXX : public ISmearcepter\" in \"$1\". You can also forcibly specify your classes name by passing a third argument to this script." exit 1 fi if [ ! -e compile.tmp ]; then mkdir compile.tmp fi cat $1 > compile.tmp/$1 echo -e "static char const * SmearceptorNames[] = {\"${CN}\"};\n"\ "static int const NSmearceptors = 1;\n"\ "\n"\ "extern \"C\" {\n"\ "int DSF_NSmearceptors() { return NSmearceptors; }\n"\ "char const* DSF_GetSmearceptorName(int i) {\n"\ " if (i < NSmearceptors) {\n"\ " return SmearceptorNames[i];\n"\ " }\n"\ " return 0;\n"\ "}\n"\ "ISmearcepter* DSF_GetSmearceptor(int i, void* smearceptorkey) {\n"\ " nuiskey* sk = reinterpret_cast(smearceptorkey);\n"\ " if (!sk) {\n"\ " return 0;\n"\ " }\n"\ "\n"\ " if (sk->GetElementName() != DSF_GetSmearceptorName(i)) {\n"\ " std::cout\n"\ " << \"[ERROR]: When instantiating dynamic smearceptor. Smearceptorkey named: \"\n"\ " << sk->GetElementName() << \", but requested smearceptor named: \"\n"\ " << DSF_GetSmearceptorName(i)\n"\ " << \". It is possible that the nuiskey object is lost in translation. \"\n"\ " \"Was NUISANCE and this dynamic smearceptor manifest built with the same \"\n"\ " \"environment and compiler?\"\n"\ " << std::endl;\n"\ " }\n"\ "\n"\ " if (i == 0) {\n"\ " ISmearcepter* sm = new ${CN}();\n"\ " sm->Setup(*sk);\n"\ " return sm;\n"\ " }\n"\ " return 0;\n"\ "}\n"\ "void DSF_DestroySmearceptor(ISmearcepter* mb) { delete mb; }\n"\ "}" >> compile.tmp/$1 -echo "g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@" +echo "g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @NUISANCE_DEPEND_LIBS@" -if ! g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @CMAKE_DEPENDLIB_FLAGS@; then +if ! g++ ${DYNSAMPLE_EXTRA_BUILD_FLAGS} compile.tmp/$1 -shared -o $2 -fPIC @CMAKE_CXX_FLAGS@ -I. -I@ALL_INCLUDES_STR@ -L@CMAKE_INSTALL_PREFIX@/lib -l@ALL_MODULETARGETS_STR@ @CMAKE_LINK_FLAGS@ @NUISANCE_DEPEND_LIBS@; then echo "[ERROR]: Failed to compile $1. Generated code can be found in ./compile.tmp/$1" else rm -r compile.tmp echo "Successfully build: $2." fi diff --git a/cmake_old/c++CompilerSetup.cmake b/cmake_old/c++CompilerSetup.cmake index 67b0361..29d518b 100644 --- a/cmake_old/c++CompilerSetup.cmake +++ b/cmake_old/c++CompilerSetup.cmake @@ -1,109 +1,109 @@ # Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret ################################################################################ # This file is part of NUISANCE. # # NUISANCE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # NUISANCE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with NUISANCE. If not, see . ################################################################################ if(USE_OMP) LIST(APPEND EXTRA_CXX_FLAGS -fopenmp) endif() if(USE_DYNSAMPLES) LIST(APPEND EXTRA_LIBS dl) LIST(APPEND EXTRA_CXX_FLAGS -D__USE_DYNSAMPLES__) endif() set(CXX_WARNINGS -Wall ) cmessage(DEBUG "EXTRA_CXX_FLAGS: ${EXTRA_CXX_FLAGS}") string(REPLACE ";" " " STR_EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STR_EXTRA_CXX_FLAGS} ${CXX_WARNINGS}") set(CMAKE_Fortran_FLAGS_RELEASE "-fPIC") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") if(USE_DYNSAMPLES) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC") set(CMAKE_Fortran_FLAGS_DEBUG "-fPIC") endif() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC -O3") if(CMAKE_BUILD_TYPE MATCHES DEBUG) set(CURRENT_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}) elseif(CMAKE_BUILD_TYPE MATCHES RELEASE) set(CURRENT_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE}) else() cmessage(FATAL_ERROR "[ERROR]: Unknown CMAKE_BUILD_TYPE (\"${CMAKE_BUILD_TYPE}\"): Should be \"DEBUG\" or \"RELEASE\".") endif() SET(STR_EXTRA_LINK_DIRS) if(NOT EXTRA_LINK_DIRS STREQUAL "") string(REPLACE ";" " -L" STR_EXTRA_LINK_DIRS "-L${EXTRA_LINK_DIRS}") endif() SET(STR_EXTRA_LIBS) if(NOT EXTRA_LIBS STREQUAL "") SET(STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS) string(REPLACE ";" " -l" STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS "-l${EXTRA_LIBS}") string(REPLACE "-l-" "-" STR_EXTRA_LIBS ${STR_EXTRA_LIBS_NO_SCRUB_LINKOPTS}) endif() SET(STR_EXTRA_SHAREDOBJS) if(NOT EXTRA_SHAREDOBJS STREQUAL "") string(REPLACE ";" " " STR_EXTRA_SHAREDOBJS "${EXTRA_SHAREDOBJS}") endif() LIST(APPEND EXTRA_LINK_FLAGS -Wl,--no-as-needed) SET(STR_EXTRA_LINK_FLAGS) if(NOT EXTRA_LINK_FLAGS STREQUAL "") string(REPLACE ";" " " STR_EXTRA_LINK_FLAGS "${EXTRA_LINK_FLAGS}") endif() cmessage(DEBUG "EXTRA_LINK_DIRS: ${STR_EXTRA_LINK_DIRS}") cmessage(DEBUG "EXTRA_LIBS: ${STR_EXTRA_LIBS}") cmessage(DEBUG "EXTRA_SHAREDOBJS: ${STR_EXTRA_SHAREDOBJS}") cmessage(DEBUG "EXTRA_LINK_FLAGS: ${STR_EXTRA_LINK_FLAGS}") if(NOT STR_EXTRA_LINK_DIRS STREQUAL "" AND NOT STR_EXTRA_LIBS STREQUAL "") - SET(CMAKE_DEPENDLIB_FLAGS "${STR_EXTRA_LINK_DIRS} ${STR_EXTRA_LIBS}") + SET(NUISANCE_DEPEND_LIBS "${STR_EXTRA_LINK_DIRS} ${STR_EXTRA_LIBS}") endif() if(NOT STR_EXTRA_SHAREDOBJS STREQUAL "") - SET(CMAKE_DEPENDLIB_FLAGS "${CMAKE_DEPENDLIB_FLAGS} ${STR_EXTRA_SHAREDOBJS}") + SET(NUISANCE_DEPEND_LIBS "${NUISANCE_DEPEND_LIBS} ${STR_EXTRA_SHAREDOBJS}") endif() if(NOT EXTRA_LINK_FLAGS STREQUAL "") if(NOT CMAKE_LINK_FLAGS STREQUAL "") SET(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${STR_EXTRA_LINK_FLAGS}") else() SET(CMAKE_LINK_FLAGS "${STR_EXTRA_LINK_FLAGS}") endif() endif() if(USE_OMP) cmessage(FATAL_ERROR "No OMP features currently enabled so this is a FATAL_ERROR to let you know that you don't gain anything with this declaration.") endif() if (VERBOSE) cmessage (STATUS "C++ Compiler : ${CXX_COMPILER_NAME}") cmessage (STATUS " flags : ${CMAKE_CXX_FLAGS}") cmessage (STATUS " Release flags : ${CMAKE_CXX_FLAGS_RELEASE}") cmessage (STATUS " Debug flags : ${CMAKE_CXX_FLAGS_DEBUG}") cmessage (STATUS " Link Flags : ${CMAKE_LINK_FLAGS}") - cmessage (STATUS " Lib Flags : ${CMAKE_DEPENDLIB_FLAGS}") + cmessage (STATUS " Lib Flags : ${NUISANCE_DEPEND_LIBS}") endif() diff --git a/old_src/InputHandler/GENIEInputHandler.cxx b/old_src/InputHandler/GENIEInputHandler.cxx index 9881c1f..569fa77 100644 --- a/old_src/InputHandler/GENIEInputHandler.cxx +++ b/old_src/InputHandler/GENIEInputHandler.cxx @@ -1,566 +1,566 @@ // 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 . *******************************************************************************/ #ifdef __GENIE_ENABLED__ #include "GENIEInputHandler.h" #include "InputUtils.h" #ifdef __DUNERWT_ENABLED__ #include "systematicstools/utility/ParameterAndProviderConfigurationUtility.hh" #include "fhiclcpp/make_ParameterSet.h" #endif #ifdef __GENIE_ENABLED__ #pragma push_macro("ERROR") #pragma push_macro("LOG") #undef ERROR #undef LOG #include "Messenger/Messenger.h" #undef ERROR #undef LOG #pragma pop_macro("LOG") #pragma pop_macro("ERROR") #endif GENIEGeneratorInfo::~GENIEGeneratorInfo() { DeallocateParticleStack(); } void GENIEGeneratorInfo::AddBranchesToTree(TTree *tn) { tn->Branch("GenieParticlePDGs", &fGenieParticlePDGs, "GenieParticlePDGs/I"); } void GENIEGeneratorInfo::SetBranchesFromTree(TTree *tn) { tn->SetBranchAddress("GenieParticlePDGs", &fGenieParticlePDGs); } void GENIEGeneratorInfo::AllocateParticleStack(int stacksize) { fGenieParticlePDGs = new int[stacksize]; } void GENIEGeneratorInfo::DeallocateParticleStack() { delete fGenieParticlePDGs; } void GENIEGeneratorInfo::FillGeneratorInfo(NtpMCEventRecord *ntpl) { Reset(); // Check for GENIE Event if (!ntpl) return; if (!ntpl->event) return; // Cast Event Record GHepRecord *ghep = static_cast(ntpl->event); if (!ghep) return; // Fill Particle Stack GHepParticle *p = 0; TObjArrayIter iter(ghep); // Loop over all particles int i = 0; while ((p = (dynamic_cast((iter).Next())))) { if (!p) continue; // Get PDG fGenieParticlePDGs[i] = p->Pdg(); i++; } } void GENIEGeneratorInfo::Reset() { for (int i = 0; i < kMaxParticles; i++) { fGenieParticlePDGs[i] = 0; } } GENIEInputHandler::GENIEInputHandler(std::string const &handle, std::string const &rawinputs) { LOG(SAM) << "Creating GENIEInputHandler : " << handle << std::endl; genie::Messenger::Instance()->SetPriorityLevel("ReW", pFATAL); genie::Messenger::Instance()->SetPriorityLevel("GHepUtils", pFATAL); // Run a joint input handling fName = handle; // Setup the TChain fGENIETree = new TChain("gtree"); fSaveExtra = FitPar::Config().GetParB("SaveExtraGenie"); fCacheSize = FitPar::Config().GetParI("CacheSize"); fMaxEvents = FitPar::Config().GetParI("MAXEVENTS"); // Loop over all inputs and grab flux, eventhist, and nevents std::vector inputs = InputUtils::ParseInputFileList(rawinputs); for (size_t inp_it = 0; inp_it < inputs.size(); ++inp_it) { // Open File for histogram access TFile *inp_file = new TFile( InputUtils::ExpandInputDirectories(inputs[inp_it]).c_str(), "READ"); if (!inp_file or inp_file->IsZombie()) { THROW("GENIE File IsZombie() at : '" << inputs[inp_it] << "'" << std::endl << "Check that your file paths are correct and the file exists!" << std::endl << "$ ls -lh " << inputs[inp_it]); } // Get Flux/Event hist TH1D *fluxhist = (TH1D *)inp_file->Get("nuisance_flux"); TH1D *eventhist = (TH1D *)inp_file->Get("nuisance_events"); if (!fluxhist or !eventhist) { ERROR(FTL, "Input File Contents: " << inputs[inp_it]); inp_file->ls(); THROW("GENIE FILE doesn't contain flux/xsec info." << std::endl << "Try running the app PrepareGENIE first on :" << inputs[inp_it] << std::endl << "$ PrepareGENIE -h"); } // Get N Events TTree *genietree = (TTree *)inp_file->Get("gtree"); if (!genietree) { ERROR(FTL, "gtree not located in GENIE file: " << inputs[inp_it]); THROW("Check your inputs, they may need to be completely regenerated!"); throw; } int nevents = genietree->GetEntries(); if (nevents <= 0) { THROW("Trying to a TTree with " << nevents << " to TChain from : " << inputs[inp_it]); } // Register input to form flux/event rate hists RegisterJointInput(inputs[inp_it], nevents, fluxhist, eventhist); // Add To TChain fGENIETree->AddFile(inputs[inp_it].c_str()); } // Registor all our file inputs SetupJointInputs(); // Assign to tree fEventType = kGENIE; fGenieNtpl = NULL; fGENIETree->SetBranchAddress("gmcrec", &fGenieNtpl); // Libraries should be seen but not heard... StopTalking(); fGENIETree->GetEntry(0); StartTalking(); #ifndef __DUNERWT_ENABLED__ // Create Fit Event fNUISANCEEvent = new FitEvent(); fNUISANCEEvent->SetGenieEvent(fGenieNtpl); if (fSaveExtra) { fGenieInfo = new GENIEGeneratorInfo(); fNUISANCEEvent->AddGeneratorInfo(fGenieInfo); } fNUISANCEEvent->HardReset(); #else std::vector HandlerOpts = Config::QueryKeys("GENIEInputHandler"); fUseCache = HandlerOpts.size() && HandlerOpts.front().Has("UseCache") && HandlerOpts.front().GetB("UseCache"); DUNERwtCachedResponseReader = nullptr; HaveCachedResponseReader = false; if (fUseCache && (inputs.size() == 1)) { std::vector DuneRwtCacheParams = Config::QueryKeys("DUNERwtResponseCache"); for (nuiskey &key : DuneRwtCacheParams) { bool has_input = key.Has("Input"); bool has_cachefile = key.Has("CacheFile"); bool has_paramheaders = key.Has("ParameterFHiCL"); std::string input = InputUtils::ExpandInputDirectories(key.GetS("Input")); std::cout << "[INFO]: Checking Input " << inputs.front() << " against cache input: " << input << std::endl; if (has_input && (input == inputs.front()) && has_cachefile && has_paramheaders) { fhicl::ParameterSet ps = fhicl::make_ParameterSet(key.GetS("ParameterFHiCL")); fhicl::ParameterSet syst_providers = ps.get( "generated_systematic_provider_configuration"); systtools::param_header_map_t configuredParameterHeaders = systtools::BuildParameterHeaders(syst_providers); DUNERwtCachedResponseReader = std::make_unique>( InputUtils::ExpandInputDirectories(key.GetS("CacheFile")), "resp_tree", configuredParameterHeaders.size()); HaveCachedResponseReader = true; break; } } } else { fNUISANCEEvent = new FitEvent(); fNUISANCEEvent->SetGenieEvent(fGenieNtpl); if (fSaveExtra) { fGenieInfo = new GENIEGeneratorInfo(); fNUISANCEEvent->AddGeneratorInfo(fGenieInfo); } fNUISANCEEvent->HardReset(); } #endif }; GENIEInputHandler::~GENIEInputHandler() { // if (fGenieGHep) delete fGenieGHep; // if (fGenieNtpl) delete fGenieNtpl; // if (fGENIETree) delete fGENIETree; // if (fGenieInfo) delete fGenieInfo; } void GENIEInputHandler::CreateCache() { if (fCacheSize > 0) { // fGENIETree->SetCacheEntryRange(0, fNEvents); fGENIETree->AddBranchToCache("*", 1); fGENIETree->SetCacheSize(fCacheSize); } } void GENIEInputHandler::RemoveCache() { // fGENIETree->SetCacheEntryRange(0, fNEvents); fGENIETree->AddBranchToCache("*", 0); fGENIETree->SetCacheSize(0); } FitEvent *GENIEInputHandler::GetNuisanceEvent(const UInt_t entry, const bool lightweight) { if (entry >= (UInt_t)fNEvents) return NULL; #ifdef __DUNERWT_ENABLED__ // Reduce memory pressure from the cache by clearing out the last entry each // time. if (entry && rwEvs[entry - 1].NParticles()) { rwEvs[entry - 1].DeallocateParticleStack(); } #endif // Read Entry from TTree to fill NEUT Vect in BaseFitEvt; fGENIETree->GetEntry(entry); #ifdef __DUNERWT_ENABLED__ if (entry >= rwEvs.size()) { rwEvs.push_back(FitEvent()); if (HaveCachedResponseReader) { rwEvs.back().DUNERwtPolyResponses = DUNERwtCachedResponseReader->GetEventResponse(entry); rwEvs.back().HasDUNERwtPolyResponses = true; } } rwEvs[entry].SetGenieEvent(fGenieNtpl); fNUISANCEEvent = &rwEvs[entry]; #endif // Run NUISANCE Vector Filler if (!lightweight) { CalcNUISANCEKinematics(); } #ifdef __PROB3PP_ENABLED__ else { // Check for GENIE Event if (!fGenieNtpl) return NULL; if (!fGenieNtpl->event) return NULL; // Cast Event Record fGenieGHep = fGenieNtpl->event; if (!fGenieGHep) return NULL; TObjArrayIter iter(fGenieGHep); genie::GHepParticle *p; while ((p = (dynamic_cast((iter).Next())))) { if (!p) { continue; } // Get Status - int state = GetGENIEParticleStatus(p, fNUISANCEEvent->Mode); + int state = GetGetParticleStatus(p, fNUISANCEEvent->Mode); if (state != genie::kIStInitialState) { continue; } fNUISANCEEvent->probe_E = p->E() * 1.E3; fNUISANCEEvent->probe_pdg = p->Pdg(); break; } } #endif // Setup Input scaling for joint inputs fNUISANCEEvent->InputWeight = GetInputWeight(entry); return fNUISANCEEvent; } -int GENIEInputHandler::GetGENIEParticleStatus(genie::GHepParticle *p, +int GENIEInputHandler::GetGetParticleStatus(genie::GHepParticle *p, int mode) { /* kIStUndefined = -1, kIStInitialState = 0, / generator-level initial state / kIStStableFinalState = 1, / generator-level final state: particles to be tracked by detector-level MC / kIStIntermediateState = 2, kIStDecayedState = 3, kIStCorrelatedNucleon = 10, kIStNucleonTarget = 11, kIStDISPreFragmHadronicState = 12, kIStPreDecayResonantState = 13, kIStHadronInTheNucleus = 14, / hadrons inside the nucleus: marked for hadron transport modules to act on / kIStFinalStateNuclearRemnant = 15, / low energy nuclear fragments entering the record collectively as a 'hadronic blob' pseudo-particle / kIStNucleonClusterTarget = 16, // for composite nucleons before phase space decay */ int state = kUndefinedState; switch (p->Status()) { case genie::kIStNucleonTarget: case genie::kIStInitialState: case genie::kIStCorrelatedNucleon: case genie::kIStNucleonClusterTarget: state = kInitialState; break; case genie::kIStStableFinalState: state = kFinalState; break; case genie::kIStHadronInTheNucleus: if (abs(mode) == 2) state = kInitialState; else state = kFSIState; break; case genie::kIStPreDecayResonantState: case genie::kIStDISPreFragmHadronicState: case genie::kIStIntermediateState: state = kFSIState; break; case genie::kIStFinalStateNuclearRemnant: case genie::kIStUndefined: case genie::kIStDecayedState: default: break; } // Flag to remove nuclear part in genie if (p->Pdg() > 1000000) { if (state == kInitialState) state = kNuclearInitial; else if (state == kFinalState) state = kNuclearRemnant; } return state; } #endif #ifdef __GENIE_ENABLED__ int GENIEInputHandler::ConvertGENIEReactionCode(GHepRecord *gheprec) { // Electron Scattering if (gheprec->Summary()->ProcInfo().IsEM()) { if (gheprec->Summary()->InitState().ProbePdg() == 11) { if (gheprec->Summary()->ProcInfo().IsQuasiElastic()) return 1; else if (gheprec->Summary()->ProcInfo().IsMEC()) return 2; else if (gheprec->Summary()->ProcInfo().IsResonant()) return 13; else if (gheprec->Summary()->ProcInfo().IsDeepInelastic()) return 26; else { ERROR(WRN, "Unknown GENIE Electron Scattering Mode!" << std::endl << "ScatteringTypeId = " << gheprec->Summary()->ProcInfo().ScatteringTypeId() << " " << "InteractionTypeId = " << gheprec->Summary()->ProcInfo().InteractionTypeId() << std::endl << genie::ScatteringType::AsString( gheprec->Summary()->ProcInfo().ScatteringTypeId()) << " " << genie::InteractionType::AsString( gheprec->Summary()->ProcInfo().InteractionTypeId()) << " " << gheprec->Summary()->ProcInfo().IsMEC()); return 0; } } // Weak CC } else if (gheprec->Summary()->ProcInfo().IsWeakCC()) { // CC MEC if (gheprec->Summary()->ProcInfo().IsMEC()) { if (pdg::IsNeutrino(gheprec->Summary()->InitState().ProbePdg())) return 2; else if (pdg::IsAntiNeutrino(gheprec->Summary()->InitState().ProbePdg())) return -2; // CC OTHER } else { return utils::ghep::NeutReactionCode(gheprec); } // Weak NC } else if (gheprec->Summary()->ProcInfo().IsWeakNC()) { // NC MEC if (gheprec->Summary()->ProcInfo().IsMEC()) { if (pdg::IsNeutrino(gheprec->Summary()->InitState().ProbePdg())) return 32; else if (pdg::IsAntiNeutrino(gheprec->Summary()->InitState().ProbePdg())) return -32; // NC OTHER } else { return utils::ghep::NeutReactionCode(gheprec); } } return 0; } void GENIEInputHandler::CalcNUISANCEKinematics() { // Reset all variables fNUISANCEEvent->ResetEvent(); // Check for GENIE Event if (!fGenieNtpl) return; if (!fGenieNtpl->event) return; // Cast Event Record fGenieGHep = fGenieNtpl->event; if (!fGenieGHep) return; // Convert GENIE Reaction Code fNUISANCEEvent->Mode = ConvertGENIEReactionCode(fGenieGHep); // Set Event Info fNUISANCEEvent->fEventNo = 0.0; fNUISANCEEvent->fTotCrs = fGenieGHep->XSec(); fNUISANCEEvent->fTargetA = 0.0; fNUISANCEEvent->fTargetZ = 0.0; fNUISANCEEvent->fTargetH = 0; fNUISANCEEvent->fBound = 0.0; fNUISANCEEvent->InputWeight = 1.0; //(1E+38 / genie::units::cm2) * fGenieGHep->XSec(); // Get N Particle Stack unsigned int npart = fGenieGHep->GetEntries(); unsigned int kmax = fNUISANCEEvent->kMaxParticles; if (npart > kmax) { fNUISANCEEvent->ExpandParticleStack(npart); } // Fill Particle Stack GHepParticle *p = 0; TObjArrayIter iter(fGenieGHep); fNUISANCEEvent->fNParticles = 0; // Loop over all particles while ((p = (dynamic_cast((iter).Next())))) { if (!p) continue; // Get Status - int state = GetGENIEParticleStatus(p, fNUISANCEEvent->Mode); + int state = GetGetParticleStatus(p, fNUISANCEEvent->Mode); // Remove Undefined if (kRemoveUndefParticles && state == kUndefinedState) continue; // Remove FSI if (kRemoveFSIParticles && state == kFSIState) continue; if (kRemoveNuclearParticles && (state == kNuclearInitial || state == kNuclearRemnant)) continue; // Fill Vectors int curpart = fNUISANCEEvent->fNParticles; fNUISANCEEvent->fParticleState[curpart] = state; // Mom fNUISANCEEvent->fParticleMom[curpart][0] = p->Px() * 1.E3; fNUISANCEEvent->fParticleMom[curpart][1] = p->Py() * 1.E3; fNUISANCEEvent->fParticleMom[curpart][2] = p->Pz() * 1.E3; fNUISANCEEvent->fParticleMom[curpart][3] = p->E() * 1.E3; // PDG fNUISANCEEvent->fParticlePDG[curpart] = p->Pdg(); // Add to N particle count fNUISANCEEvent->fNParticles++; // Extra Check incase GENIE fails. if ((UInt_t)fNUISANCEEvent->fNParticles == kmax) { ERR(WRN) << "Number of GENIE Particles exceeds maximum (Max: " << kmax << ", GHEP: " << fGenieGHep->GetEntries() << ", Added: " << fNUISANCEEvent->fNParticles << ")!" << std::endl; ERR(WRN) << "Extend kMax, or run without including FSI particles!" << std::endl; break; } } // Fill Extra Stack if (fSaveExtra) fGenieInfo->FillGeneratorInfo(fGenieNtpl); // Run Initial, FSI, Final, Other ordering. fNUISANCEEvent->OrderStack(); FitParticle *ISNeutralLepton = fNUISANCEEvent->GetHMISParticle(PhysConst::pdg_neutrinos); if (ISNeutralLepton) { fNUISANCEEvent->probe_E = ISNeutralLepton->E(); fNUISANCEEvent->probe_pdg = ISNeutralLepton->PDG(); } return; } void GENIEInputHandler::Print() {} #endif diff --git a/old_src/InputHandler/GENIEInputHandler.h b/old_src/InputHandler/GENIEInputHandler.h index e21cd74..be09bd1 100644 --- a/old_src/InputHandler/GENIEInputHandler.h +++ b/old_src/InputHandler/GENIEInputHandler.h @@ -1,134 +1,134 @@ // 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 GENIEINPUTHANDLER_H #define GENIEINPUTHANDLER_H /*! * \addtogroup InputHandler * @{ */ #ifdef __GENIE_ENABLED__ #include "InputHandler.h" #include "InputUtils.h" #include "PlotUtils.h" #include "Conventions/Units.h" #include "EVGCore/EventRecord.h" #include "GHEP/GHepParticle.h" #include "GHEP/GHepUtils.h" #include "Ntuple/NtpMCEventRecord.h" #include "PDG/PDGUtils.h" using namespace genie; /// GENIE Generator Container to save extra particle status codes. class GENIEGeneratorInfo : public GeneratorInfoBase { public: GENIEGeneratorInfo(){}; virtual ~GENIEGeneratorInfo(); /// Assigns information to branches void AddBranchesToTree(TTree *tn); /// Setup reading information from branches void SetBranchesFromTree(TTree *tn); /// Allocate any dynamic arrays for a new particle stack size void AllocateParticleStack(int stacksize); /// Clear any dynamic arrays void DeallocateParticleStack(); /// Read extra genie information from the event void FillGeneratorInfo(NtpMCEventRecord *ntpl); /// Reset extra information to default/empty values void Reset(); int kMaxParticles; ///< Number of particles in stack int *fGenieParticlePDGs; ///< GENIE Particle PDGs (example) }; /// Main GENIE InputHandler class GENIEInputHandler : public InputHandlerBase { public: #ifdef __DUNERWT_ENABLED__ std::vector rwEvs; #endif /// Standard constructor given a name and input files GENIEInputHandler(std::string const &handle, std::string const &rawinputs); virtual ~GENIEInputHandler(); /// Create a TTree Cache to speed up file read void CreateCache(); /// Remove TTree Cache to save memory void RemoveCache(); /// Returns a NUISANCE format event from the GENIE TTree. If !lightweight /// then CalcNUISANCEKinematics() is called to convert the GENIE event into /// a standard NUISANCE format. FitEvent *GetNuisanceEvent(const UInt_t entry, const bool lightweight = false); #ifdef __DUNERWT_ENABLED__ // Returns filled BaseFitEvent for a given entry; BaseFitEvt *GetBaseEvent(const UInt_t entry) { if (rwEvs.size() <= entry) { THROW("Tried to get cached BaseFitEv[" << entry << "], but only have " << rwEvs.size() << " in the cache."); } // Here the GENIE record is no longer valid. if (rwEvs[entry].genie_event) { rwEvs[entry].genie_event = 0; } return &rwEvs[entry]; } #endif /// Converts GENIE event into standard NUISANCE FitEvent by looping over all /// particles in the event and adding them to stack in fNUISANCEEvent. void CalcNUISANCEKinematics(); /// Placeholder for GENIE related event printing. void Print(); /// Converts GENIE particle status codes into NUISANCE status codes. - int GetGENIEParticleStatus(genie::GHepParticle *part, int mode = 0); + int GetGetParticleStatus(genie::GHepParticle *part, int mode = 0); /// Converts GENIE event reaction codes into NUISANCE reaction codes. int ConvertGENIEReactionCode(GHepRecord *gheprec); EventRecord *fGenieGHep; ///< Pointer to actual event record NtpMCEventRecord *fGenieNtpl; ///< Ntpl Wrapper Class TChain *fGENIETree; ///< Main GENIE Event TTree bool fSaveExtra; ///< Flag to save Extra GENIE info into Nuisance Event GENIEGeneratorInfo *fGenieInfo; ///< Extra GENIE Generator Info Writer #ifdef __DUNERWT_ENABLED__ std::unique_ptr> DUNERwtCachedResponseReader; bool HaveCachedResponseReader; bool fUseCache; #endif }; /*! @} */ #endif #endif diff --git a/old_src/Tests/CMakeLists.txt b/old_src/Tests/CMakeLists.txt index f02aea6..3c4e639 100644 --- a/old_src/Tests/CMakeLists.txt +++ b/old_src/Tests/CMakeLists.txt @@ -1,58 +1,58 @@ # 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_directories(${MINIMUM_INCLUDE_DIRECTORIES}) include_directories(${CMAKE_SOURCE_DIR}/src/Routines) 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}) SET(TESTAPPS SignalDefTests ParserTests SmearceptanceTests) if(USE_MINIMIZER) # LIST(APPEND TESTAPPS FitMechanicsTests) endif() foreach(appimpl ${TESTAPPS}) add_executable(${appimpl} ${appimpl}.cxx) set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};${appimpl}) target_link_libraries(${appimpl} ${MODULETargets}) - target_link_libraries(${appimpl} ${CMAKE_DEPENDLIB_FLAGS}) + target_link_libraries(${appimpl} ${NUISANCE_DEPEND_LIBS}) target_link_libraries(${appimpl} ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(${appimpl} PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() install(TARGETS ${appimpl} DESTINATION tests) add_test(${appimpl} ${appimpl} 1) endforeach() list (FIND TESTAPPS FitMechanicsTests _index) if (${_index} GREATER -1) add_library(DummySample SHARED DummySample.cxx) target_link_libraries(DummySample ${MODULETargets}) - target_link_libraries(DummySample ${CMAKE_DEPENDLIB_FLAGS}) + target_link_libraries(DummySample ${NUISANCE_DEPEND_LIBS}) target_link_libraries(DummySample ${ROOT_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(DummySample PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() install(TARGETS DummySample DESTINATION tests) endif() diff --git a/old_src/Utils/CMakeLists.txt b/old_src/Utils/CMakeLists.txt index 25a22c4..3657eae 100644 --- a/old_src/Utils/CMakeLists.txt +++ b/old_src/Utils/CMakeLists.txt @@ -1,77 +1,77 @@ # 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 FitUtils.h GeneralUtils.h ParserUtils.h PlotUtils.h SignalDef.h BeamUtils.h TargetUtils.h OpenMPWrapper.h PhysConst.h ) set(IMPLFILES FitUtils.cxx GeneralUtils.cxx PlotUtils.cxx SignalDef.cxx BeamUtils.cxx TargetUtils.cxx ParserUtils.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) include_directories(${CMAKE_SOURCE_DIR}/src/Statistical) 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}\"") +# string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${NUISANCE_DEPEND_LIBS}) +# cmessage(DEBUG "Attempted to strip out nuwro library: \"${NUISANCE_DEPEND_LIBS}\" -> \"${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) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index f11b727..f8d6367 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,13 +1,14 @@ SET(APPS nuissamples nuiscomp nuisevsum) foreach(a ${APPS}) add_executable(${a} ${a}.cxx) target_link_libraries(${a} nuis_event nuis_input nuis_utility nuis_config nuis_persistency nuis_plugins nuis_params nuis_variation) - target_link_libraries(${a} ${CMAKE_DEPENDLIB_FLAGS}) + target_link_libraries(${a} ${NUISANCE_LINK_DIRS}) + target_link_libraries(${a} ${NUISANCE_DEPEND_LIBS}) if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "") set_target_properties(${a} PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS}) endif() install(TARGETS ${a} DESTINATION bin) endforeach() diff --git a/src/event/MinimalEvent.cxx b/src/event/MinimalEvent.cxx index 875b99f..a7cae61 100644 --- a/src/event/MinimalEvent.cxx +++ b/src/event/MinimalEvent.cxx @@ -1,49 +1,34 @@ #include "event/MinimalEvent.hxx" namespace nuis { namespace event { MinimalEvent::MinimalEvent() : mode(Channel_t::kUndefined), probe_E(0), probe_pdg(0), XSecWeight(1), - RWWeight(1) { -#ifdef __NUWRO_ENABLED__ - fNuWroEvent = nullptr; -#endif -} + RWWeight(1) {} MinimalEvent::MinimalEvent(MinimalEvent &&other) : mode(other.mode), probe_E(other.probe_E), probe_pdg(other.probe_pdg), - XSecWeight(other.XSecWeight), RWWeight(other.RWWeight) { -#ifdef __NUWRO_ENABLED__ - fNuWroEvent = other.fNuWroEvent; - other.fNuWroEvent = nullptr; -#endif -} + XSecWeight(other.XSecWeight), RWWeight(other.RWWeight) {} MinimalEvent &MinimalEvent::operator=(MinimalEvent &&other) { mode = other.mode; probe_E = other.probe_E; probe_pdg = other.probe_pdg; XSecWeight = other.XSecWeight; RWWeight = other.RWWeight; -#ifdef __NUWRO_ENABLED__ - fNuWroEvent = other.fNuWroEvent; - other.fNuWroEvent = nullptr; -#endif + return *this; } MinimalEvent MinimalEvent::Clone() const { MinimalEvent clone; clone.mode = mode; clone.probe_E = probe_E; clone.probe_pdg = probe_pdg; clone.XSecWeight = XSecWeight; clone.RWWeight = RWWeight; -#ifdef __NUWRO_ENABLED__ - clone.fNuWroEvent = fNuWroEvent; -#endif return clone; } } // namespace event } // namespace nuis diff --git a/src/event/MinimalEvent.hxx b/src/event/MinimalEvent.hxx index 83f36f1..a025044 100644 --- a/src/event/MinimalEvent.hxx +++ b/src/event/MinimalEvent.hxx @@ -1,78 +1,56 @@ // Copyright 2018 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 EVENT_MINIMALEVENT_HXX_SEEN #define EVENT_MINIMALEVENT_HXX_SEEN -#ifdef NUWRO_ENABLED -#include "event1.h" -typedef ::event NuWroEvent; -#endif - -#ifdef NEUT_ENABLED -#include "neutpart.h" -#include "neutvect.h" -#endif - #include "event/types.hxx" namespace nuis { namespace event { ///\brief The minimal event information needed to perform reweights. /// /// Most often, event selections cannot be applied using this reduced format. class MinimalEvent { public: MinimalEvent(); MinimalEvent(MinimalEvent const &) = delete; MinimalEvent(MinimalEvent &&); MinimalEvent &operator=(MinimalEvent &&); /// Make a clone of this MinimalEvent MinimalEvent Clone() const; /// True interaction mode Channel_t mode; /// True probe energy double probe_E; /// True probe particle code PDG_t probe_pdg; PDG_t target_pdg; /// Event-weight that can be used to scale to a cross-section prediction double XSecWeight; /// Event weight incurred from current reweight engine state. double RWWeight; - -#ifdef NUWRO_ENABLED - ///\brief Pointer to Nuwro event - /// - /// This will usually be tied to a TTree and so we are not responsible for - /// deleting it - NuWroEvent *fNuWroEvent; -#endif - -#ifdef NEUT_ENABLED - NeutVect *fNeutVect; -#endif }; } // namespace core } // namespace nuis #endif diff --git a/src/event/types.hxx b/src/event/types.hxx index 5553f8c..f40e5f0 100644 --- a/src/event/types.hxx +++ b/src/event/types.hxx @@ -1,104 +1,125 @@ // Copyright 2018 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 EVENT_TYPES_HXX_SEEN #define EVENT_TYPES_HXX_SEEN #include "exception/exception.hxx" namespace nuis { namespace event { +// Modelled off the NEUT interaction codes. #define NUIS_INTERACTION_CHANNEL_LIST \ X(kCCQE, 1) \ X(kCC2p2h, 2) \ X(kCCSPP_PPip, 11) \ X(kCCSPP_PPi0, 12) \ X(kCCSPP_NPip, 13) \ X(kCCCohPi, 16) \ X(kCCResGamma, 17) \ X(kCCTransitionMPi, 21) \ X(kCCResEta0, 22) \ X(kCCResK, 23) \ X(kCCDIS, 26) \ \ X(kNCSPP_NPi0, 31) \ X(kNCSPP_PPi0, 32) \ X(kNCSPP_PPim, 33) \ X(kNCSPP_NPip, 34) \ X(kNCCohPi, 36) \ X(kNCResNGamma, 38) \ X(kNCResPGamma, 39) \ X(kNCTransitionMPi, 41) \ X(kNCResNEta0, 42) \ X(kNCResPEta0, 43) \ X(kNCResK0, 44) \ X(kNCResKp, 45) \ X(kNCDIS, 46) \ X(kNCELP, 51) \ X(kNCELN, 52) \ + X(kNC2p2h, 53) \ \ X(kCCQE_nub, -1) \ X(kCC2p2h_nub, -2) \ X(kCCSPP_NPim_nub, -11) \ X(kCCSPP_NPi0_nub, -12) \ X(kCCSPP_PPim_nub, -13) \ X(kCCCohPi_nub, -16) \ X(kCCResGamma_nub, -17) \ X(kCCTransitionMPi_nub, -21) \ X(kCCResEta0_nub, -22) \ X(kCCResK_nub, -23) \ X(kCCDIS_nub, -26) \ \ X(kNCSPP_NPi0_nub, -31) \ X(kNCSPP_PPi0_nub, -32) \ X(kNCSPP_PPim_nub, -33) \ X(kNCSPP_NPip_nub, -34) \ X(kNCCohPi_nub, -36) \ X(kNCResNGamma_nub, -38) \ X(kNCResPGamma_nub, -39) \ X(kNCTransitionMPi_nub, -41) \ X(kNCResNEta0_nub, -42) \ X(kNCResPEta0_nub, -43) \ X(kNCResK0_nub, -44) \ X(kNCResKp_nub, -45) \ X(kNCDIS_nub, -46) \ X(kNCELP_nub, -51) \ X(kNCELN_nub, -52) \ + X(kNC2p2h_nub, -53) \ \ X(kUndefined, 0) #define X(A, B) A = B, enum class Channel_t { NUIS_INTERACTION_CHANNEL_LIST }; #undef X -typedef long PDG_t; +#define X(A, B) \ + case B: { \ + return Channel_t::A; \ + } +inline Channel_t FromNEUTCode(int nc) { + switch (nc) { + NUIS_INTERACTION_CHANNEL_LIST + default: { return Channel_t::kUndefined; } + } +} +#undef X + +using PDG_t = long; + +inline bool Is2p2h(Channel_t chan) { + return ((chan == Channel_t::kCC2p2h) || (chan == Channel_t::kNC2p2h) || + (chan == Channel_t::kCC2p2h_nub) || (chan == Channel_t::kNC2p2h_nub)); +} + } // namespace event } // namespace nuis #define X(A, B) \ case nuis::event::Channel_t::A: { \ return os << #A; \ } inline std::ostream &operator<<(std::ostream &os, nuis::event::Channel_t te) { switch (te) { NUIS_INTERACTION_CHANNEL_LIST } return os; } #undef X #endif diff --git a/src/generator/input/CMakeLists.txt b/src/generator/input/CMakeLists.txt index e84aa10..46354e6 100644 --- a/src/generator/input/CMakeLists.txt +++ b/src/generator/input/CMakeLists.txt @@ -1,17 +1,31 @@ LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_event nuis_config) if(USE_NuWro) LIST(APPEND INPUT_HANDLERS_IMPL NuWroInputHandler.cxx) + LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_generator_utility) endif(USE_NuWro) if(USE_NEUT) LIST(APPEND INPUT_HANDLERS_IMPL NEUTInputHandler.cxx) LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_generator_utility) endif(USE_NEUT) +if(USE_GENIE) + LIST(APPEND INPUT_HANDLERS_IMPL GENIEInputHandler.cxx) + LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_generator_utility) +endif(USE_GENIE) + if(INPUT_HANDLERS_IMPL) add_library(InputHandlers SHARED ${INPUT_HANDLERS_IMPL}) target_link_libraries(InputHandlers ${INPUT_HANDLERS_LINK_LIBS}) + if(USE_GENIE) + target_compile_options(InputHandlers PUBLIC ${GENIE_CXX_FLAGS}) + include_directories(${GENIE_INCLUDE_DIRS}) + + target_link_libraries(InputHandlers ${GENIE_LINK_DIRS}) + target_link_libraries(InputHandlers ${GENIE_LIBS}) + endif() + install(TARGETS InputHandlers DESTINATION plugins) endif() diff --git a/src/generator/input/GENIEInputHandler.cxx b/src/generator/input/GENIEInputHandler.cxx new file mode 100644 index 0000000..f6a1d59 --- /dev/null +++ b/src/generator/input/GENIEInputHandler.cxx @@ -0,0 +1,144 @@ +#include "generator/input/GENIEInputHandler.hxx" + +#include "generator/utility/GENIEUtility.hxx" + +#include "utility/PDGCodeUtility.hxx" + +#ifdef GENIE_V3_INTERFACE +#include "Framework/EventGen/EventRecord.h" +#include "Framework/GHEP/GHepParticle.h" +#include "Framework/GHEP/GHepRecord.h" +#else +#include "EVGCore/EventRecord.h" +#include "GHEP/GHepParticle.h" +#include "GHEP/GHepRecord.h" +#endif + +#include "fhiclcpp/ParameterSet.h" + +using namespace nuis::event; +using namespace nuis::utility; +using namespace nuis::genietools; + +GENIEInputHandler::GENIEInputHandler() : fInputTree(), fGenieNtpl(nullptr) {} +GENIEInputHandler::GENIEInputHandler(GENIEInputHandler &&other) + : fInputTree(std::move(other.fInputTree)), + fReaderEvent(std::move(other.fReaderEvent)), fGenieNtpl(nullptr) {} + +void GENIEInputHandler::Initialize(fhicl::ParameterSet const &ps) { + + fInputTree = CheckGetTTree(ps.get("file"), "gtree"); + + fInputTree.tree->SetBranchAddress("gmcrec", &fGenieNtpl); + + fKeepIntermediates = ps.get("keep_intermediates", false); + fKeepNuclearParticles = ps.get("keep_nuclear_particles", false); +} + +MinimalEvent const &GENIEInputHandler::GetMinimalEvent(ev_index_t idx) const { + if (idx >= GetNEvents()) { + throw IInputHandler::invalid_entry() + << "[ERROR]: Attempted to get entry " << idx + << " from an InputHandler with only " << GetNEvents(); + } + + fInputTree.tree->GetEntry(idx); + + genie::GHepRecord *GHep = static_cast(fGenieNtpl->event); + if (!GHep) { + throw invalid_GENIE_event() + << "[ERROR]: GENIE event " << idx << " failed to contain a GHepRecord"; + } + + fReaderEvent.mode = GetEventChannel(*GHep); + + TObjArrayIter iter(GHep); + genie::GHepParticle *p; + while ((p = (dynamic_cast((iter).Next())))) { + if (!p) { + continue; + } + + Particle::Status_t state = GetParticleStatus(*p, fReaderEvent.mode); + if (state != Particle::Status_t::kPrimaryInitialState) { + continue; + } + if (!IsNeutralLepton(p->Pdg(), pdgcodes::kMatterAntimatter) && + !IsChargedLepton(p->Pdg(), pdgcodes::kMatterAntimatter)) { + continue; + } + fReaderEvent.probe_E = p->E() * 1.E3; + fReaderEvent.probe_pdg = p->Pdg(); + break; + } + + fReaderEvent.XSecWeight = 1; + + if (fWeightCache.size() <= idx) { + fWeightCache.push_back(fReaderEvent.XSecWeight); + } + + return fReaderEvent; +} + +FullEvent const &GENIEInputHandler::GetFullEvent(ev_index_t idx) const { + (void)GetMinimalEvent(idx); + + fReaderEvent.ClearParticleStack(); + + genie::GHepRecord *GHep = static_cast(fGenieNtpl->event); + + unsigned int npart = GHep->GetEntries(); + + // Fill Particle Stack + genie::GHepParticle *p = 0; + TObjArrayIter iter(GHep); + + // Loop over all particles + while ((p = (dynamic_cast((iter).Next())))) { + if (!p) { + continue; + } + + // Get Status + Particle::Status_t state = GetParticleStatus(*p, fReaderEvent.mode); + + if (!fKeepIntermediates) { + continue; + } + + if (!fKeepNuclearParticles && IsNuclearPDG(p->Pdg())) { + continue; + } + + Particle nuis_part; + + nuis_part.pdg = p->Pdg(); + nuis_part.P4 = TLorentzVector(p->Px(), p->Py(), p->Pz(), p->E()) * 1E3; + + fReaderEvent.ParticleStack[static_cast(state)].particles.push_back( + nuis_part); + } + + return fReaderEvent; +} + +double GENIEInputHandler::GetEventWeight(ev_index_t idx) const { + if (idx > fWeightCache.size()) { + throw weight_cache_miss() + << "[ERROR]: Failed to get cached weight for event index: " << idx; + } + return fWeightCache[idx]; +} + +double GENIEInputHandler::GetXSecScaleFactor( + std::pair const &EnuRange) const { + throw input_handler_feature_unimplemented() + << "[ERROR]: Flux cuts not yet implemented for GENIE input handler."; +} + +size_t GENIEInputHandler::GetNEvents() const { + return fInputTree.tree->GetEntries(); +} + +DECLARE_PLUGIN(IInputHandler, GENIEInputHandler); diff --git a/src/generator/input/NuWroInputHandler.hxx b/src/generator/input/GENIEInputHandler.hxx similarity index 82% copy from src/generator/input/NuWroInputHandler.hxx copy to src/generator/input/GENIEInputHandler.hxx index a7fc22c..558d070 100644 --- a/src/generator/input/NuWroInputHandler.hxx +++ b/src/generator/input/GENIEInputHandler.hxx @@ -1,59 +1,67 @@ // Copyright 2018 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 . *******************************************************************************/ #pragma once #include "event/FullEvent.hxx" #include "input/IInputHandler.hxx" #include "exception/exception.hxx" #include "utility/ROOTUtility.hxx" +#ifdef GENIE_V3_INTERFACE +#include "Framework/Ntuple/NtpMCEventRecord.h" +#else +#include "Ntuple/NtpMCEventRecord.h" +#endif + #include namespace fhicl { class ParameterSet; } -class NuWroInputHandler : public IInputHandler { +class GENIEInputHandler : public IInputHandler { mutable nuis::utility::TreeFile fInputTree; mutable nuis::event::FullEvent fReaderEvent; mutable std::vector fWeightCache; + mutable genie::NtpMCEventRecord* fGenieNtpl; bool fKeepIntermediates; + bool fKeepNuclearParticles; public: NEW_NUIS_EXCEPT(weight_cache_miss); - NuWroInputHandler(); - NuWroInputHandler(NuWroInputHandler const &) = delete; - NuWroInputHandler(NuWroInputHandler &&); + GENIEInputHandler(); + GENIEInputHandler(GENIEInputHandler const &) = delete; + GENIEInputHandler(GENIEInputHandler &&); void Initialize(fhicl::ParameterSet const &); nuis::event::MinimalEvent const &GetMinimalEvent(ev_index_t idx) const; nuis::event::FullEvent const &GetFullEvent(ev_index_t idx) const; double GetEventWeight(ev_index_t idx) const; size_t GetNEvents() const; double GetXSecScaleFactor( std::pair const &EnuRange) const; }; diff --git a/src/generator/input/NuWroInputHandler.cxx b/src/generator/input/NuWroInputHandler.cxx index 52f2a7e..c0c02bc 100644 --- a/src/generator/input/NuWroInputHandler.cxx +++ b/src/generator/input/NuWroInputHandler.cxx @@ -1,121 +1,122 @@ #include "generator/input/NuWroInputHandler.hxx" #include "generator/utility/NuWroUtility.hxx" -#include "utility/ROOTUtility.hxx" - #include "fhiclcpp/ParameterSet.h" #include "particle.h" using NuWroParticle = ::particle; using namespace nuis::event; using namespace nuis::utility; using namespace nuis::nuwrotools; -NuWroInputHandler::NuWroInputHandler() : fInputTree() {} +NuWroInputHandler::NuWroInputHandler() : fInputTree(), fTreeEvent(nullptr) {} NuWroInputHandler::NuWroInputHandler(NuWroInputHandler &&other) : fInputTree(std::move(other.fInputTree)), - fReaderEvent(std::move(other.fReaderEvent)) {} + fReaderEvent(std::move(other.fReaderEvent)), + fTreeEvent(other.fTreeEvent) {} void NuWroInputHandler::Initialize(fhicl::ParameterSet const &ps) { fInputTree = CheckGetTTree(ps.get("file"), "treeout"); - fReaderEvent.fNuWroEvent = nullptr; - fInputTree.tree->SetBranchAddress("e", &fReaderEvent.fNuWroEvent); + fTreeEvent = nullptr; + fInputTree.tree->SetBranchAddress("e", &fTreeEvent); fKeepIntermediates = ps.get("keep_intermediates", false); } MinimalEvent const &NuWroInputHandler::GetMinimalEvent(ev_index_t idx) const { if (idx >= GetNEvents()) { throw IInputHandler::invalid_entry() << "[ERROR]: Attempted to get entry " << idx << " from an InputHandler with only " << GetNEvents(); } fInputTree.tree->GetEntry(idx); - fReaderEvent.mode = NuWroEventChannel(*fReaderEvent.fNuWroEvent); - fReaderEvent.probe_E = fReaderEvent.fNuWroEvent->in[0].E(); - fReaderEvent.probe_pdg = fReaderEvent.fNuWroEvent->in[0].pdg; - fReaderEvent.XSecWeight = - fReaderEvent.fNuWroEvent->weight / double(GetNEvents()); + fReaderEvent.mode = NuWroEventChannel(*fTreeEvent); + fReaderEvent.probe_E = fTreeEvent->in[0].E(); + fReaderEvent.probe_pdg = fTreeEvent->in[0].pdg; + fReaderEvent.XSecWeight = fTreeEvent->weight / double(GetNEvents()); if (fWeightCache.size() <= idx) { fWeightCache.push_back(fReaderEvent.XSecWeight); } return fReaderEvent; } FullEvent const &NuWroInputHandler::GetFullEvent(ev_index_t idx) const { (void)GetMinimalEvent(idx); fReaderEvent.ClearParticleStack(); - for (size_t p_it = 0; p_it < fReaderEvent.fNuWroEvent->in.size(); ++p_it) { - NuWroParticle &part = fReaderEvent.fNuWroEvent->in[p_it]; + for (size_t p_it = 0; p_it < fTreeEvent->in.size(); ++p_it) { + NuWroParticle &part = fTreeEvent->in[p_it]; Particle nuis_part; nuis_part.pdg = part.pdg; nuis_part.P4 = TLorentzVector(part[1], part[2], part[3], part[0]); fReaderEvent .ParticleStack[static_cast( Particle::Status_t::kPrimaryInitialState)] .particles.push_back(nuis_part); } - for (size_t p_it = 0; - p_it < fKeepIntermediates && fReaderEvent.fNuWroEvent->out.size(); + for (size_t p_it = 0; p_it < fKeepIntermediates && fTreeEvent->out.size(); ++p_it) { - NuWroParticle &part = fReaderEvent.fNuWroEvent->out[p_it]; + NuWroParticle &part = fTreeEvent->out[p_it]; Particle nuis_part; nuis_part.pdg = part.pdg; nuis_part.P4 = TLorentzVector(part[1], part[2], part[3], part[0]); fReaderEvent .ParticleStack[static_cast( Particle::Status_t::kPrimaryFinalState)] .particles.push_back(nuis_part); } - for (size_t p_it = 0; (p_it < fReaderEvent.fNuWroEvent->post.size()); - ++p_it) { - NuWroParticle &part = fReaderEvent.fNuWroEvent->post[p_it]; + for (size_t p_it = 0; (p_it < fTreeEvent->post.size()); ++p_it) { + NuWroParticle &part = fTreeEvent->post[p_it]; Particle nuis_part; nuis_part.pdg = part.pdg; nuis_part.P4 = TLorentzVector(part[1], part[2], part[3], part[0]); fReaderEvent .ParticleStack[static_cast(Particle::Status_t::kNuclearLeaving)] .particles.push_back(nuis_part); } return fReaderEvent; } +NuWroEvent const &NuWroInputHandler::GetNuWroEvent(ev_index_t idx) const { + (void)GetMinimalEvent(idx); + return *fTreeEvent; +} + double NuWroInputHandler::GetEventWeight(ev_index_t idx) const { if (idx > fWeightCache.size()) { throw weight_cache_miss() << "[ERROR]: Failed to get cached weight for event index: " << idx; } return fWeightCache[idx]; } double NuWroInputHandler::GetXSecScaleFactor( std::pair const &EnuRange) const { throw input_handler_feature_unimplemented() << "[ERROR]: Flux cuts not yet implemented for NuWro input handler."; } size_t NuWroInputHandler::GetNEvents() const { return fInputTree.tree->GetEntries(); } DECLARE_PLUGIN(IInputHandler, NuWroInputHandler); diff --git a/src/generator/input/NuWroInputHandler.hxx b/src/generator/input/NuWroInputHandler.hxx index a7fc22c..2885db0 100644 --- a/src/generator/input/NuWroInputHandler.hxx +++ b/src/generator/input/NuWroInputHandler.hxx @@ -1,59 +1,66 @@ // Copyright 2018 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 . *******************************************************************************/ #pragma once #include "event/FullEvent.hxx" #include "input/IInputHandler.hxx" #include "exception/exception.hxx" #include "utility/ROOTUtility.hxx" +#include "event1.h" +using NuWroEvent = ::event; + #include namespace fhicl { class ParameterSet; } class NuWroInputHandler : public IInputHandler { mutable nuis::utility::TreeFile fInputTree; mutable nuis::event::FullEvent fReaderEvent; mutable std::vector fWeightCache; + mutable NuWroEvent *fTreeEvent; bool fKeepIntermediates; public: NEW_NUIS_EXCEPT(weight_cache_miss); NuWroInputHandler(); NuWroInputHandler(NuWroInputHandler const &) = delete; NuWroInputHandler(NuWroInputHandler &&); void Initialize(fhicl::ParameterSet const &); nuis::event::MinimalEvent const &GetMinimalEvent(ev_index_t idx) const; nuis::event::FullEvent const &GetFullEvent(ev_index_t idx) const; + + NuWroEvent const &GetNuWroEvent(ev_index_t idx) const; + double GetEventWeight(ev_index_t idx) const; size_t GetNEvents() const; double GetXSecScaleFactor( std::pair const &EnuRange) const; }; diff --git a/src/generator/utility/CMakeLists.txt b/src/generator/utility/CMakeLists.txt index 437ae87..65b82ae 100644 --- a/src/generator/utility/CMakeLists.txt +++ b/src/generator/utility/CMakeLists.txt @@ -1,20 +1,34 @@ if(USE_NuWro) LIST(APPEND GENERATOR_UTILS_IMPL NuWroUtility.cxx) LIST(APPEND GENERATOR_UTILS_HDR NuWroUtility.hxx) endif(USE_NuWro) if(USE_NEUT) LIST(APPEND GENERATOR_UTILS_IMPL NEUTUtility.cxx) LIST(APPEND GENERATOR_UTILS_HDR NEUTUtility.hxx) endif(USE_NEUT) +if(USE_GENIE) + LIST(APPEND GENERATOR_UTILS_IMPL GENIEUtility.cxx) + LIST(APPEND GENERATOR_UTILS_HDR GENIEUtility.hxx) +endif(USE_GENIE) + + if(GENERATOR_UTILS_IMPL) add_library(nuis_generator_utility SHARED ${GENERATOR_UTILS_IMPL}) target_link_libraries(nuis_generator_utility nuis_event) + if(USE_GENIE) + target_compile_options(nuis_generator_utility PUBLIC ${GENIE_CXX_FLAGS}) + include_directories(${GENIE_INCLUDE_DIRS}) + + target_link_libraries(nuis_generator_utility ${GENIE_LINK_DIRS}) + target_link_libraries(nuis_generator_utility ${GENIE_LIBS}) + endif() + install(TARGETS nuis_generator_utility DESTINATION plugins) endif() if(GENERATOR_UTILS_HDR) install(FILES ${GENERATOR_UTILS_HDR} DESTINATION include/generator/utility) endif() diff --git a/src/generator/utility/GENIEUtility.cxx b/src/generator/utility/GENIEUtility.cxx new file mode 100644 index 0000000..2d93aea --- /dev/null +++ b/src/generator/utility/GENIEUtility.cxx @@ -0,0 +1,298 @@ +// Copyright 2018 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 "generator/utility/GENIEUtility.hxx" + +#include "utility/PDGCodeUtility.hxx" + +#ifdef GENIE_V3_INTERFACE +#include "Framework/GHEP/GHepParticle.h" +#include "Framework/GHEP/GHepRecord.h" +#include "Framework/GHEP/GHepUtils.h" +#include "Framework/ParticleData/PDGCodes.h" +#else +#include "GHEP/GHepParticle.h" +#include "GHEP/GHepRecord.h" +#include "GHEP/GHepUtils.h" +#include "PDG/PDGCodes.h" +#endif + +#include "TGraph.h" + +namespace nuis { + +using namespace event; + +namespace genietools { + +static std::map SplineCache; + +TGraph dum; + +TGraph const &GetGENIESpline(std::string const &SplineFile, + std::string const &SplineIdentifier) { + if (SplineCache.find(SplineFile + SplineIdentifier) != SplineCache.end()) { + return SplineCache.find(SplineFile + SplineIdentifier)->second; + } + return dum; +} + +struct NFSParticleCount { + size_t NProton; + size_t NNeutron; + size_t NPip; + size_t NPi0; + size_t NPim; + size_t NOther; +}; + +NFSParticleCount CountPreFSIParticles(genie::GHepRecord const &ev) { + // This code in this method is adapted from the GENIE source code found in + // GHep/GHepUtils.cxx This method therefore carries the GENIE copyright + // licence as copied below: + // + /// Copyright (c) 2003-2017, GENIE Neutrino MC Generator Collaboration + /// For the full text of the license visit http://copyright.genie-mc.org + /// or see $GENIE/LICENSE + // + + genie::Target const &tgt = ev.Summary()->InitState().Tgt(); + if (!tgt.HitNucIsSet()) { + throw invalid_GENIE_event() + << "[ERROR]: Failed to get hit nucleon kinematics as it was not " + "included in this GHep event. This is a fatal error."; + } + + genie::GHepParticle *FSLep = ev.FinalStatePrimaryLepton(); + genie::GHepParticle *ISLep = ev.Probe(); + + if (!FSLep || !ISLep) { + throw invalid_GENIE_event() + << "[ERROR]: Failed to find IS and FS lepton in event: " + << ev.Summary()->AsString(); + } + + size_t NPi0 = 0, NPip = 0, NPim = 0, NProton = 0, NNeutron = 0, NOther = 0; + + bool nuclear_target = tgt.IsNucleus(); + + TIter event_iter(&ev); + genie::GHepParticle *p = 0; + + while ((p = dynamic_cast(event_iter.Next()))) { + genie::GHepStatus_t ghep_ist = (genie::GHepStatus_t)p->Status(); + int ghep_pdgc = p->Pdg(); + int ghep_fm = p->FirstMother(); + int ghep_fmpdgc = (ghep_fm == -1) ? 0 : ev.Particle(ghep_fm)->Pdg(); + + // For nuclear targets use hadrons marked as 'hadron in the nucleus' + // which are the ones passed in the intranuclear rescattering + // For free nucleon targets use particles marked as 'final state' + // but make an exception for decayed pi0's,eta's (count them and not their + // daughters) + + bool decayed = + (ghep_ist == genie::kIStDecayedState && + (ghep_pdgc == genie::kPdgPi0 || ghep_pdgc == genie::kPdgEta)); + bool parent_included = + (ghep_fmpdgc == genie::kPdgPi0 || ghep_fmpdgc == genie::kPdgEta); + + bool count_it = + (nuclear_target && ghep_ist == genie::kIStHadronInTheNucleus) || + (!nuclear_target && decayed) || + (!nuclear_target && ghep_ist == genie::kIStStableFinalState && + !parent_included); + + if (!count_it) { + continue; + } + + if (ghep_pdgc == genie::kPdgPiP) { + NPip++; + } else if (ghep_pdgc == genie::kPdgPiM) { + NPim++; + } else if (ghep_pdgc == genie::kPdgPi0) { + NPi0++; + } else if (ghep_pdgc == genie::kPdgProton) { + NProton++; + } else if (ghep_pdgc == genie::kPdgNeutron) { + NNeutron++; + } else if (!utility::IsNeutralLepton( + ghep_pdgc, utility::pdgcodes::kMatterAntimatter) && + !utility::IsChargedLepton( + ghep_pdgc, utility::pdgcodes::kMatterAntimatter)) { + NOther++; + } + } + + return NFSParticleCount{NProton, NNeutron, NPip, NPi0, NPim, NOther}; +} + +Channel_t GetEventChannel(genie::GHepRecord const &gev) { + // Electron Scattering + if (gev.Summary()->ProcInfo().IsEM()) { + if (gev.Summary()->InitState().ProbePdg() == utility::pdgcodes::kElectron) { + if (gev.Summary()->ProcInfo().IsQuasiElastic()) { + NFSParticleCount fsparts = CountPreFSIParticles(gev); + if (fsparts.NProton) { + return Channel_t::kNCELP; + } else { + return Channel_t::kNCELN; + } + } else if (gev.Summary()->ProcInfo().IsMEC()) { + return Channel_t::kNC2p2h; + } else if (gev.Summary()->ProcInfo().IsResonant()) { + + NFSParticleCount fsparts = CountPreFSIParticles(gev); + if (fsparts.NOther || + ((fsparts.NPip + fsparts.NPi0 + fsparts.NPim) > 1)) { + return Channel_t::kNCTransitionMPi; + } else if (fsparts.NPip) { + return Channel_t::kNCSPP_NPip; + } else if (fsparts.NPi0) { + return fsparts.NProton ? Channel_t::kNCSPP_PPi0 + : Channel_t::kNCSPP_NPi0; + } else if (fsparts.NPim) { + return Channel_t::kNCSPP_PPim; + } + + return Channel_t::kNCTransitionMPi; + + } else if (gev.Summary()->ProcInfo().IsDeepInelastic()) { + return Channel_t::kNCDIS; + } else { + std::cout << "Unknown GENIE Electron Scattering Mode!" << std::endl + << "ScatteringTypeId = " + << gev.Summary()->ProcInfo().ScatteringTypeId() << " " + << "InteractionTypeId = " + << gev.Summary()->ProcInfo().InteractionTypeId() << std::endl + << genie::ScatteringType::AsString( + gev.Summary()->ProcInfo().ScatteringTypeId()) + << " " + << genie::InteractionType::AsString( + gev.Summary()->ProcInfo().InteractionTypeId()) + << " " << gev.Summary()->ProcInfo().IsMEC() << std::endl; + return Channel_t::kUndefined; + } + } + + // Weak CC + } else if (gev.Summary()->ProcInfo().IsWeakCC()) { + // CC MEC + if (gev.Summary()->ProcInfo().IsMEC()) { + if (utility::IsNeutralLepton(gev.Summary()->InitState().ProbePdg(), + utility::pdgcodes::kMatter)) { + return Channel_t::kCC2p2h; + } else if (utility::IsNeutralLepton(gev.Summary()->InitState().ProbePdg(), + utility::pdgcodes::kAntimatter)) { + return Channel_t::kCC2p2h_nub; + } + // CC OTHER + } else { + return FromNEUTCode(genie::utils::ghep::NeutReactionCode(&gev)); + } + + // Weak NC + } else if (gev.Summary()->ProcInfo().IsWeakNC()) { + // NC MEC + if (gev.Summary()->ProcInfo().IsMEC()) { + if (utility::IsNeutralLepton(gev.Summary()->InitState().ProbePdg(), + utility::pdgcodes::kMatter)) { + return Channel_t::kNC2p2h; + } else if (utility::IsNeutralLepton(gev.Summary()->InitState().ProbePdg(), + utility::pdgcodes::kAntimatter)) { + return Channel_t::kNC2p2h_nub; + } + + // NC OTHER + } else { + return FromNEUTCode(genie::utils::ghep::NeutReactionCode(&gev)); + } + } + + return Channel_t::kUndefined; +} + +Particle::Status_t GetParticleStatus(genie::GHepParticle const &p, + Channel_t chan) { + /* + kIStUndefined = -1, + kIStInitialState = 0, / generator-level initial state / + kIStStableFinalState = 1, / generator-level final state: + particles to be tracked by detector-level MC / + kIStIntermediateState = 2, + kIStDecayedState = 3, + kIStCorrelatedNucleon = 10, + kIStNucleonTarget = 11, + kIStDISPreFragmHadronicState = 12, + kIStPreDecayResonantState = 13, + kIStHadronInTheNucleus = 14, / hadrons inside the nucleus: marked + for hadron transport modules to act on / + kIStFinalStateNuclearRemnant = 15, / low energy nuclear fragments + entering the record collectively as a 'hadronic blob' pseudo-particle / + kIStNucleonClusterTarget = 16, // for composite nucleons before + phase space decay + */ + + Particle::Status_t state = Particle::Status_t::kUnknown; + switch (p.Status()) { + case genie::kIStNucleonTarget: + case genie::kIStInitialState: + case genie::kIStCorrelatedNucleon: + case genie::kIStNucleonClusterTarget: { + state = Particle::Status_t::kPrimaryInitialState; + break; + } + + case genie::kIStStableFinalState: { + state = Particle::Status_t::kNuclearLeaving; + break; + } + + case genie::kIStHadronInTheNucleus: { + state = Is2p2h(chan) ? Particle::Status_t::kPrimaryInitialState + : Particle::Status_t::kIntermediate; + break; + } + + case genie::kIStPreDecayResonantState: + case genie::kIStDISPreFragmHadronicState: + case genie::kIStIntermediateState: { + state = Particle::Status_t::kIntermediate; + break; + } + + case genie::kIStFinalStateNuclearRemnant: + case genie::kIStUndefined: + case genie::kIStDecayedState: + default: { state = Particle::Status_t::kUnknown; } + } + + if (utility::IsNuclearPDG(p.Pdg())) { + if (state == Particle::Status_t::kPrimaryInitialState) { + state = Particle::Status_t::kPrimaryInitialState; + } else if (state == Particle::Status_t::kNuclearLeaving) { + state = Particle::Status_t::kPrimaryFinalState; + } + } + return state; +} + +} // namespace genietools +} // namespace nuis diff --git a/src/generator/input/NuWroInputHandler.hxx b/src/generator/utility/GENIEUtility.hxx similarity index 50% copy from src/generator/input/NuWroInputHandler.hxx copy to src/generator/utility/GENIEUtility.hxx index a7fc22c..b95f450 100644 --- a/src/generator/input/NuWroInputHandler.hxx +++ b/src/generator/utility/GENIEUtility.hxx @@ -1,59 +1,47 @@ // Copyright 2018 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 . *******************************************************************************/ #pragma once -#include "event/FullEvent.hxx" +#include "event/Particle.hxx" -#include "input/IInputHandler.hxx" +#include "event/types.hxx" -#include "exception/exception.hxx" +class TGraph; -#include "utility/ROOTUtility.hxx" +namespace genie { +class GHepRecord; +class GHepParticle; +} // namespace genie -#include +namespace nuis { +namespace genietools { -namespace fhicl { -class ParameterSet; -} +NEW_NUIS_EXCEPT(invalid_GENIE_event); -class NuWroInputHandler : public IInputHandler { - mutable nuis::utility::TreeFile fInputTree; - mutable nuis::event::FullEvent fReaderEvent; - mutable std::vector fWeightCache; +TGraph const &GetGENIESpline(std::string const &SplineFile, + std::string const &SplineIdentifier); - bool fKeepIntermediates; +event::Channel_t GetEventChannel(genie::GHepRecord const &); -public: +event::Particle::Status_t GetParticleStatus(genie::GHepParticle const &p, + event::Channel_t chan); - NEW_NUIS_EXCEPT(weight_cache_miss); - - NuWroInputHandler(); - NuWroInputHandler(NuWroInputHandler const &) = delete; - NuWroInputHandler(NuWroInputHandler &&); - - void Initialize(fhicl::ParameterSet const &); - nuis::event::MinimalEvent const &GetMinimalEvent(ev_index_t idx) const; - nuis::event::FullEvent const &GetFullEvent(ev_index_t idx) const; - double GetEventWeight(ev_index_t idx) const; - size_t GetNEvents() const; - - double GetXSecScaleFactor( - std::pair const &EnuRange) const; -}; +} // namespace genietools +} // namespace nuis diff --git a/src/generator/utility/NuWroUtility.hxx b/src/generator/utility/NuWroUtility.hxx index 141bcd9..6efafa0 100644 --- a/src/generator/utility/NuWroUtility.hxx +++ b/src/generator/utility/NuWroUtility.hxx @@ -1,19 +1,20 @@ #ifndef GENERATOR_UTILITY_NUWROUTILITY_HXX_SEEN #define GENERATOR_UTILITY_NUWROUTILITY_HXX_SEEN -#include "event/types.hxx" #include "event/MinimalEvent.hxx" +#include "event/types.hxx" #include "event1.h" -typedef ::flags NuWroFlags; +using NuWroFlags = ::flags; +using NuWroEvent = ::event; #include namespace nuis { namespace nuwrotools { std::pair GetFlagsDynEquivalent(nuis::event::Channel_t); nuis::event::Channel_t NuWroEventChannel(NuWroEvent const &); -} +} // namespace nuwrotools } // namespace nuis #endif diff --git a/src/samples/nuA/BubbleChamber/ANL/ANL_CCQE_Evt_1DQ2_nu.cxx b/src/samples/nuA/BubbleChamber/ANL/ANL_CCQE_Evt_1DQ2_nu.cxx index ebfd897..5562945 100644 --- a/src/samples/nuA/BubbleChamber/ANL/ANL_CCQE_Evt_1DQ2_nu.cxx +++ b/src/samples/nuA/BubbleChamber/ANL/ANL_CCQE_Evt_1DQ2_nu.cxx @@ -1,195 +1,195 @@ // Copyright 2018 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 "samples/SimpleDataComparison.hxx" #include "utility/FullEventUtility.hxx" #include "utility/KinematicUtility.hxx" #include "utility/PDGCodeUtility.hxx" using namespace nuis::event; using namespace nuis::utility; class ANL_CCQE_Evt_1DQ2_nu : public SimpleDataComparison_1D { public: NEW_NUIS_EXCEPT(invalid_publication_specifier); enum Publication { kPRL31, kPRD16, kPRD26 }; Publication Pub; std::string Pub_str; bool UseD2Corr; - std::unique_ptr fD2CorrHist; - std::unique_ptr fPrediction_Uncorr; + std::unique_ptr fD2CorrHist; + std::unique_ptr fPrediction_Uncorr; ANL_CCQE_Evt_1DQ2_nu() : Pub(kPRD26), Pub_str(""), UseD2Corr(false), fD2CorrHist(nullptr) { ReadGlobalConfigDefaults(); } std::string GetDocumentation() { return "Can specify \"publication: \", where is one of [ PRL31, " "PRD16, PRD26 ] to clarify a publication for comparison. Defaults " "to PRD26.\n" "Can enable deuterium Q2 correction by specifying " "\"use_D2_correction: true\""; } fhicl::ParameterSet GetExampleConfiguration() { fhicl::ParameterSet exps = SimpleDataComparison_1D::GetExampleConfiguration(); exps.put("publication", "PRD26"); exps.put("use_D2_correction", false); return exps; } void Initialize(fhicl::ParameterSet const &instance_sample_configuration) { if (instance_sample_configuration.has_key("verbosity")) { SetSampleVerbosity( instance_sample_configuration.get("verbosity")); } std::string publication = instance_sample_configuration.get("publication", "PRD26"); if (publication == "PRL31") { Pub = kPRL31; } else if (publication == "PRD16") { Pub = kPRD16; } else if (publication == "PRD26") { Pub = kPRD26; } else { throw invalid_publication_specifier() << "[ERROR]: Found unexpected publication specifier " << std::quoted(publication) << ". Expected one of [ PRL31, PRD16, PRD26 ]"; } switch (Pub) { case kPRL31: { Pub_str = "PRL31_844"; energy_cut = std::pair{0, 3E3}; IEventProcessor_INFO( "Sample " << Name() << " specialized for publication: " << Pub_str); break; } case kPRD16: { Pub_str = "PRD16_3103"; energy_cut = std::pair{0, 6E3}; IEventProcessor_INFO( "Sample " << Name() << " specialized for publication: " << Pub_str); break; } case kPRD26: { Pub_str = "PRD26_537"; energy_cut = std::pair{0, 6E3}; IEventProcessor_INFO( "Sample " << Name() << " specialized for publication: " << Pub_str); break; } } fhicl::ParameterSet const &global_sample_configuration = nuis::config::GetDocument().get( std::string("global.sample_configuration.") + Name(), fhicl::ParameterSet()); SetData(GetDataDir() + "nuA/BubbleChamber/ANL/CCQE/ANL_CCQE_Data_" + Pub_str + ".root;ANL_1DQ2_Data"); SimpleDataComparison_1D::Initialize(instance_sample_configuration); UseD2Corr = instance_sample_configuration.get( "use_D2_correction", global_sample_configuration.get("use_D2_correction", false)); if (UseD2Corr) { - fD2CorrHist = nuis::utility::GetHistogram( + fD2CorrHist = nuis::utility::GetHistogram( GetDataDir() + "nuA/BubbleChamber/ANL/CCQE/" "ANL_CCQE_Data_PRL31_844.root;ANL_1DQ2_Correction"); fPrediction_Uncorr = Clone(fPrediction, true); } // Signal selection function IsSigFunc = [&](FullEvent const &fev) -> bool { if (fev.mode != Channel_t::kCCQE) { return false; } Particle ISNumu = GetHMISNeutralLepton(fev); if (!ISNumu) { return false; } if (ISNumu.pdg != pdgcodes::kNuMu) { return false; } if (!energy_cut.IsInRange(ISNumu.P4.E())) { return false; } double Q2 = GetNeutrinoQ2QERec(fev, 0); if (Q2 <= 0) { return false; } return true; }; // 1D Projection function CompProjFunc = [](FullEvent const &fev) -> std::array { return {GetNeutrinoQ2QERec(fev, 0)}; }; } // Used to apply D2 correction if requested virtual void FillProjection(std::array const &proj, double event_weight) { if (UseD2Corr) { TH_Help::Fill(fPrediction_Uncorr, proj, event_weight); event_weight *= fD2CorrHist->Interpolate(proj[0]); } TH_Help::Fill(fPrediction, proj, event_weight); } void FinalizeComparison() { SimpleDataComparison_1D::FinalizeComparison(); if (UseD2Corr) { fPrediction_Uncorr->Scale(1.0, "width"); } } void Write() { SimpleDataComparison_1D::Write(); if (UseD2Corr) { - nuis::persistency::WriteToOutputFile( + nuis::persistency::WriteToOutputFile( fPrediction_Uncorr, "Prediction_Uncorr", write_directory); } } std::string Name() { return "ANL_CCQE_Evt_1DQ2_nu"; } }; DECLARE_PLUGIN(IDataComparison, ANL_CCQE_Evt_1DQ2_nu); DECLARE_PLUGIN(IEventProcessor, ANL_CCQE_Evt_1DQ2_nu); diff --git a/src/utility/PDGCodeUtility.cxx b/src/utility/PDGCodeUtility.cxx index c5fc138..f777df9 100644 --- a/src/utility/PDGCodeUtility.cxx +++ b/src/utility/PDGCodeUtility.cxx @@ -1,116 +1,118 @@ #include "utility/PDGCodeUtility.hxx" #include #include using namespace nuis::event; using namespace nuis::utility::pdgcodes; using namespace nuis::utility::pdgmasses; namespace nuis { namespace utility { static std::map const PDGMasses{ {kNuMu, kNuMuMass_MeV}, {kNuMuBar, kNuMuBarMass_MeV}, {kMu, kMuMass_MeV}, {kMuPlus, kMuPlusMass_MeV}, {kNue, kNueMass_MeV}, {kNueBar, kNueBarMass_MeV}, {kPiPlus, kPiPlusMass_MeV}, {kPiMinus, kPiMinusMass_MeV}, {kPi0, kPi0Mass_MeV}, {kProton, kNeutronMass_MeV}, {kNeutron, kProtonMass_MeV}}; double GetPDGMass(PDG_t pdg) { if (PDGMasses.find(pdg) == PDGMasses.end()) { throw unhandled_pdg_code() << "[ERROR]: Unknown mass for particle with PDG code: " << pdg << ", please add it to src/utility/PDGCodeUtility.cxx:PDGMasses"; } return PDGMasses.at(pdg); } NEW_NUIS_EXCEPT(invalid_MatterType); bool IsInPDGList(PDG_t pdg, std::vector const &MatterList, std::vector const &AntiMatterList, MatterType type) { switch (type) { case kMatter: { return std::count(MatterList.begin(), MatterList.end(), pdg); } case kMatterAntimatter: { return std::count(MatterList.begin(), MatterList.end(), pdg) || std::count(AntiMatterList.begin(), AntiMatterList.end(), pdg); } case kAntimatter: { return std::count(AntiMatterList.begin(), AntiMatterList.end(), pdg); } default: { throw invalid_MatterType(); } } } bool IsNeutralLepton(PDG_t pdg, MatterType type) { return IsInPDGList(pdg, NeutralLeptons_matter, NeutralLeptons_antimatter, type); } bool IsChargedLepton(PDG_t pdg, MatterType type) { return IsInPDGList(pdg, ChargedLeptons_matter, ChargedLeptons_antimatter, type); } bool IsProton(PDG_t pdg, MatterType type) { return IsInPDGList(pdg, Proton_matter, Proton_antimatter, type); } bool IsNeutron(PDG_t pdg) { return pdg == Neutron[0]; } bool IsChargedPion(PDG_t pdg) { return std::count(ChargedPions.begin(), ChargedPions.end(), pdg); } bool IsNeutralPion(PDG_t pdg) { return std::count(NeutralPions.begin(), NeutralPions.end(), pdg); } bool IsPion(PDG_t pdg) { return std::count(Pions.begin(), Pions.end(), pdg); } bool IsOther(PDG_t pdg) { return !std::count(CommonParticles.begin(), CommonParticles.end(), pdg); } bool IsMatter(PDG_t pdg) { // Special cases switch (pdg) { case kPiPlus: { return true; } case kPiMinus: { return true; } case kPi0: { return true; } case kNeutron: { return true; } } return (pdg > 0); } bool IsAntiMatter(PDG_t pdg) { // Special cases switch (pdg) { case kPiPlus: { return true; } case kPiMinus: { return true; } case kPi0: { return true; } case kNeutron: { return true; } } return (pdg < 0); } +bool IsNuclearPDG(event::PDG_t pdg) { return (pdg > 1000000000); } + PDG_t MakeNuclearPDG(size_t A, size_t Z) { return 1000 * Z + 10 * A + 1000000000; } size_t GetA(PDG_t pdg) { return ((pdg / 10) % 1000); } size_t GetZ(PDG_t pdg) { return ((pdg / 1000) % 1000); } } // namespace utility } // namespace nuis diff --git a/src/utility/PDGCodeUtility.hxx b/src/utility/PDGCodeUtility.hxx index 0cb2f30..e76aa7f 100644 --- a/src/utility/PDGCodeUtility.hxx +++ b/src/utility/PDGCodeUtility.hxx @@ -1,127 +1,131 @@ // Copyright 2018 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 UTILITY_PDGCODEUTILITY_HXX_SEEN -#define UTILITY_PDGCODEUTILITY_HXX_SEEN +#pragma once #include "event/types.hxx" #include "exception/exception.hxx" #include namespace nuis { namespace utility { namespace pdgcodes { NEW_NUIS_EXCEPT(unhandled_pdg_code); enum MatterType { kMatter = 1, kMatterAntimatter = 0, kAntimatter = -1 }; static event::PDG_t const kNuMu = 14; static event::PDG_t const kNuMuBar = -14; static event::PDG_t const kMu = 13; static event::PDG_t const kMuPlus = -13; +static event::PDG_t const kElectron = 11; +static event::PDG_t const kPositron = -11; + static event::PDG_t const kNue = 12; static event::PDG_t const kNueBar = 12; static event::PDG_t const kPiPlus = 211; static event::PDG_t const kPiMinus = -211; static event::PDG_t const kPi0 = 111; static event::PDG_t const kProton = 2212; static event::PDG_t const kNeutron = 2112; -static std::vector const ChargedLeptons{11, kMu, 15, - -11, kMuPlus, -15}; -static std::vector const ChargedLeptons_matter{11, kMu, 15}; -static std::vector const ChargedLeptons_antimatter{-11, kMuPlus, - -15}; +static std::vector const ChargedLeptons{kElectron, kMu, 15, + kPositron, kMuPlus, -15}; +static std::vector const ChargedLeptons_matter{kElectron, kMu, + 15}; +static std::vector const ChargedLeptons_antimatter{kPositron, + kMuPlus, -15}; static std::vector const NeutralLeptons{kNue, kNuMu, 16, - kNueBar, kNuMuBar, -16}; + kNueBar, kNuMuBar, -16}; static std::vector const NeutralLeptons_matter{kNue, kNuMu, 16}; static std::vector const NeutralLeptons_antimatter{kNueBar, - kNuMuBar, -16}; + kNuMuBar, -16}; static std::vector const ChargedPions{kPiPlus, kPiMinus}; static std::vector const NeutralPions{kPi0}; static std::vector const Pions{kPiPlus, kPiMinus, kPi0}; static std::vector const Protons{kProton, -kProton}; static std::vector const Proton_matter{kProton}; static std::vector const Proton_antimatter{-kProton}; static std::vector const Neutron{kNeutron}; static std::vector const Nucleons{kProton, kNeutron, -kProton}; static std::vector const Nucleons_matter{kProton, kNeutron}; static std::vector const Nucleons_antimatter{-kProton, kNeutron}; static std::vector const CommonParticles{ - 11, kMu, 15, -11, kMuPlus, -15, kNue, kNuMu, 16, - kNueBar, kNuMuBar, -16, kPiPlus, kPiMinus, kPi0, kProton, kNeutron}; + kElectron, kMu, 15, kPositron, kMuPlus, -15, kNue, kNuMu, 16, + kNueBar, kNuMuBar, -16, kPiPlus, kPiMinus, kPi0, kProton, kNeutron}; } // namespace pdgcodes namespace pdgmasses { static double const kNuMuMass_MeV = 0; static double const kNuMuBarMass_MeV = 0; static double const kMuMass_MeV = 105.65; static double const kMuPlusMass_MeV = 105.65; static double const kNueMass_MeV = 0; static double const kNueBarMass_MeV = 0; static double const kPiPlusMass_MeV = 139.57; static double const kPiMinusMass_MeV = 139.57; static double const kPi0Mass_MeV = 134.97; static double const kNeutronMass_MeV = 939.56; static double const kProtonMass_MeV = 938.27; } // namespace pdgmasses double GetPDGMass(event::PDG_t); bool IsInPDGList(event::PDG_t pdg, std::vector const &MatterList, std::vector const &AntiMatterList, pdgcodes::MatterType type = pdgcodes::kMatterAntimatter); bool IsNeutralLepton(event::PDG_t pdg, pdgcodes::MatterType type = pdgcodes::kMatterAntimatter); bool IsChargedLepton(event::PDG_t pdg, pdgcodes::MatterType type = pdgcodes::kMatterAntimatter); bool IsProton(event::PDG_t pdg, pdgcodes::MatterType type = pdgcodes::kMatterAntimatter); + bool IsNeutron(event::PDG_t pdg); bool IsChargedPion(event::PDG_t pdg); bool IsNeutralPion(event::PDG_t pdg); bool IsPion(event::PDG_t pdg); bool IsOther(event::PDG_t pdg); bool IsMatter(event::PDG_t pdg); bool IsAntiMatter(event::PDG_t pdg); +bool IsNuclearPDG(event::PDG_t pdg); + event::PDG_t MakeNuclearPDG(size_t A, size_t Z); size_t GetA(event::PDG_t); size_t GetZ(event::PDG_t); } // namespace utility } // namespace nuis - -#endif