diff --git a/README b/README index 9568090..1c42f35 100644 --- a/README +++ b/README @@ -1,38 +1,38 @@ Author Luke Pickering, Patrick Stowell, Callum Wilkinson, Clarence Wret Package Manager: (p.stowell@sheffield.ac.uk) NUISANCE Package v2r7 README 20/07/2016 --- Compilation The following instructions should be used to build the fitter after checking out from scratch. 1. Make sure environmental variables required for the generators you wish to build against are set. 2. In the top nuisance directory make a new build directory: "$mkdir build && cd build" 3. Run CMAKE with compiler flags for which generators are required - "$ cmake -DUSE_NuWro=1 -DUSE_NEUT=1 -DUSE_GENIE=0 ../" + "$ cmake -DUSE_NUWRO=1 -DUSE_NEUT=1 -DUSE_GENIE=0 ../" 4. Build the fitter "$ make -j" 5. Build documentation "$ make docs" 6. Install to build location "$ make install" 7. Source the setup script "$ source Linux/setup.sh" If you prefer, most configure variables can be entered through a cmake UI, such as ccmake. e.g. "$ mkdir build && cd build && ccmake ../" --- Adding Classes The fitter is designed to be easily extended by adding new measurement classes whilst keeping the input convertors and tuning functionality the same. The Devel module folder is setup with some examples of how to add new classes into the framework. Feel free to email me if there are difficulties adding new measurements. --- Running Fits Whilst running fits is relatively quick and simple, there are now a large range of possible options. Doxygen Documentation is being added to the $NUISANCE/doc/html folder. Refer thre for guidance on how to properly formulate a card file. diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 35aaabb..7865834 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,225 +1,224 @@ # 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 ${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 ${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) +if (USE_NUWRO) 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 ${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 ${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 ${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 ${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 ${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 ${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 ${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 ${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 ${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 ${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 ${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 ${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) +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 ${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 ${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 ${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 index 43051c0..bdc730a 100644 --- a/cmake/GENIESetup.cmake +++ b/cmake/GENIESetup.cmake @@ -1,192 +1,191 @@ # 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 -Wl,--as-needed ) 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}) +PrefixList(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) +SET(USE_GENIE TRUE CACHE BOOL "Whether to enable GENIE 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 6970f7d..4fe175e 100644 --- a/cmake/InputHandlerSetup.cmake +++ b/cmake/InputHandlerSetup.cmake @@ -1,63 +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) +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) + 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 a40b869..1e9b0a4 100644 --- a/cmake/NEUTSetup.cmake +++ b/cmake/NEUTSetup.cmake @@ -1,127 +1,147 @@ # 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 -DUSE_NEUT -DNEUT_VERSION=${NEUT_VERSION}) +LIST(APPEND NEUT_CXX_FLAGS -DUSE_NEUT -DNEUT_VERSION=${NEUT_VERSION}) if(${NEUT_VERSION} VERSION_GREATER 5.4.0) - LIST(APPEND EXTRA_CXX_FLAGS -DNEUT_COMMON_QEAV) + LIST(APPEND NEUT_CXX_FLAGS -DNEUT_COMMON_QEAV) endif() -include_directories(${NEUT_ROOT}/include ${NEUT_ROOT}/src/neutclass ${NEUT_ROOT}/src/reweight) +LIST(APPEND NEUT_INCLUDE_DIRS + ${NEUT_ROOT}/include + ${NEUT_ROOT}/src/neutclass) -LIST(APPEND EXTRA_LINK_DIRS +LIST(APPEND NEUT_LINK_DIRS ${NEUT_LIB_DIR} - ${CERN}/${CERN_LEVEL}/lib - ${NEUT_ROOT}/src/reweight) + ${CERN}/${CERN_LEVEL}/lib) + +if(USE_GENERATOR_REWEIGHT) + LIST(APPEND NEUT_INCLUDE_DIRS + ${NEUT_ROOT}/src/reweight) + LIST(APPEND NEUT_LINK_DIRS + ${NEUT_ROOT}/src/reweight) + LIST(APPEND NEUT_LIBS NReWeight) +endif() -LIST(APPEND EXTRA_LIBS NReWeight) -if(${NEUT_VERSION} VERSION_EQUAL 5.4.2) - LIST(APPEND EXTRA_LIBS +if(${NEUT_VERSION} VERSION_GREATER 5.4.1.999) + LIST(APPEND NEUT_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 + LIST(APPEND NEUT_CXX_FLAGS -DNEUT_COMMON_QEAV) +elseif(${NEUT_VERSION} VERSION_GREATER 5.3.999) + LIST(APPEND NEUT_LIBS 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 + LIST(APPEND NEUT_LIBS NReWeight neutcore nuccorrspl nuceff partnuck skmcsvc tauola) endif() -LIST(APPEND EXTRA_LIBS +LIST(APPEND NEUT_LIBS jetset74 pdflib804 mathlib packlib pawlib gfortran) -set(NEUT_ROOT_LIBS) +set(NEUT_ROOT_SHAREDOBJS) -LIST(APPEND NEUT_ROOT_LIBS +LIST(APPEND NEUT_ROOT_SHAREDOBJS ${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_CXX_FLAGS -DNEUT_NUCFSI_ENABLED) - LIST(APPEND NEUT_ROOT_LIBS + LIST(APPEND NEUT_ROOT_SHAREDOBJS ${NEUT_CLASS}/neutnucfsistep.so ${NEUT_CLASS}/neutnucfsivert.so ) endif() if(${NEUT_VERSION} VERSION_LESS 5.4.0) - LIST(APPEND NEUT_ROOT_LIBS + LIST(APPEND NEUT_ROOT_SHAREDOBJS ${NEUT_CLASS}/neutrootTreeSingleton.so) endif() -LIST(APPEND NEUT_ROOT_LIBS +LIST(APPEND NEUT_ROOT_SHAREDOBJS ${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}) +foreach(so ${NEUT_ROOT_SHAREDOBJS}) + get_filename_component(SONAME ${so} NAME_WE) + add_library(${SONAME} SHARED IMPORTED) + set_property(TARGET ${SONAME} PROPERTY IMPORTED_LOCATION ${so}) + LIST(APPEND NEUT_IMPORTED_TARGETS ${SONAME}) endforeach() + +PrefixList(NEUT_LINK_DIRS "-L" ${NEUT_LINK_DIRS}) + +cmessage(STATUS "NEUT") +cmessage(STATUS " Version : ${NEUT_VERSION}") +cmessage(STATUS " Flags : ${NEUT_CXX_FLAGS}") +cmessage(STATUS " Includes : ${NEUT_INCLUDE_DIRS}") +cmessage(STATUS " Link Dirs : ${NEUT_LINK_DIRS}") +cmessage(STATUS " Libs : ${NEUT_LIBS}") +cmessage(STATUS " SOs : ${NEUT_IMPORTED_TARGETS}") diff --git a/cmake/NuWroSetup.cmake b/cmake/NuWroSetup.cmake index 26ccc68..daa9c4c 100644 --- a/cmake/NuWroSetup.cmake +++ b/cmake/NuWroSetup.cmake @@ -1,48 +1,39 @@ # 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 -DUSE_NUWRO -Wno-sign-compare -Wno-unused-variable -Wno-reorder) - -include_directories(${NUWRO}/src) +LIST(APPEND NUWRO_CXX_FLAGS -DUSE_NUWRO -Wno-sign-compare -Wno-unused-variable -Wno-reorder) -if(NOT EXISTS ${NUWRO}/bin/event1.so) - if(EXISTS ${NUWRO}/build/${CMAKE_SYSTEM_NAME}/lib) +LIST(APPEND NUWRO_INCLUDE_DIRS ${NUWRO}/src) - 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() +add_library(NuWro_event1 SHARED IMPORTED) +set_property(TARGET NuWro_event1 PROPERTY IMPORTED_LOCATION ${NUWRO}/bin/event1.so) +LIST(APPEND NUWRO_IMPORTED_TARGETS NuWro_event1) set(NEED_PYTHIA6 TRUE) set(NEED_ROOTPYTHIA6 TRUE) + +cmessage(STATUS "NuWro") +cmessage(STATUS " Flags : ${NUWRO_CXX_FLAGS}") +cmessage(STATUS " Includes : ${NUWRO_INCLUDE_DIRS}") +cmessage(STATUS " SOs : ${NUWRO_IMPORTED_TARGETS}") diff --git a/cmake/StringAndListUtils.cmake b/cmake/StringAndListUtils.cmake index e3005aa..d47be3e 100644 --- a/cmake/StringAndListUtils.cmake +++ b/cmake/StringAndListUtils.cmake @@ -1,34 +1,44 @@ 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() + +function(PrefixList OUTPUT_LIST PREFIX) + set(${OUTPUT_LIST}) + foreach(I ${ARGN}) + if(NOT I STREQUAL "") + LIST(APPEND ${OUTPUT_LIST} "${PREFIX}${I}") + endif() + endforeach() + set(${OUTPUT_LIST} ${${OUTPUT_LIST}} PARENT_SCOPE) +endfunction() diff --git a/cmake/cacheVariables.cmake b/cmake/cacheVariables.cmake index ebf15a6..336be79 100644 --- a/cmake/cacheVariables.cmake +++ b/cmake/cacheVariables.cmake @@ -1,116 +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. ") +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_old/MakeBinaryBlob.in b/cmake_old/MakeBinaryBlob.in index b6554b9..502cbdf 100644 --- a/cmake_old/MakeBinaryBlob.in +++ b/cmake_old/MakeBinaryBlob.in @@ -1,173 +1,173 @@ # 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 if [ ! ${NUISANCE} ]; then echo "[ERROR]; NUISANCE envrionment variable is not defined, please source NUSIANCE before trying to make a binary blob." exit 1 fi mkdir BinBlob cd BinBlob echo "#!/bin/sh" > setup.sh cat @PROJECT_SOURCE_DIR@/cmake/BinBlobSetup.header >> setup.sh mkdir deps exes mkdir root mkdir -p root/lib/root echo "[INFO]: Copying ROOT libraries from @CMAKE_ROOTSYS@/lib/root" cp @CMAKE_ROOTSYS@/lib/root/*.so* root/lib/root/ mkdir root/bin echo "[INFO]: Copying ROOT binary from @CMAKE_ROOTSYS@/bin" cp @CMAKE_ROOTSYS@/bin/* root/bin mkdir -p root/share/man/man1 echo "[INFO]: Copying ROOT man pages from @CMAKE_ROOTSYS@/share/man/man1" cp -r @CMAKE_ROOTSYS@/share/man/man1 root/share/man/man1 cat root/bin/thisroot.sh | sed 's:@CMAKE_ROOTSYS@:__INST_ROOT__:g' > root/bin/thisroot.sh_tmp rm root/bin/thisroot.sh echo "cat \$NUISANCE/root/bin/thisroot.sh_tmp | sed \"s:__INST_ROOT__:\$NUISANCE/root:g\" > \$NUISANCE/root/bin/thisroot.sh" >> setup.sh cat root/bin/thisroot.csh | sed 's:@CMAKE_ROOTSYS@:__INST_ROOT__:g' > root/bin/thisroot.csh_tmp rm root/bin/thisroot.csh echo "cat \$NUISANCE/root/bin/thisroot.csh_tmp | sed \"s:__INST_ROOT__:\$NUISANCE/root:g\" > \$NUISANCE/root/bin/thisroot.csh" >> setup.sh echo "source \$NUISANCE/root/bin/thisroot.sh" >> setup.sh if [ "@USE_T2K@" != "FALSE" ]; then mkdir deps/t2k echo "[INFO]: Copying T2K libraries from @T2KREWEIGHT@" cp @T2KREWEIGHT@/lib/*.so deps/t2k/ echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/t2k" >> setup.sh fi if [ "@USE_NIWG@" != "FALSE" ]; then mkdir deps/niwg echo "[INFO]: Copying NIWG libraries from @NIWG@" cp @NIWG@/lib/*.so deps/niwg/ echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/niwg" >> setup.sh fi if [ "@USE_NEUT@" != "FALSE" ]; then mkdir deps/neut mkdir exes/neut echo "[INFO]: Copying NEUT libraries from @NEUT_ROOT@" cp @NEUT_ROOT@/src/reweight/*.so* deps/neut cp @NEUT_ROOT@/src/neutclass/*.so* deps/neut cp @NEUT_ROOT@/src/neutsmpl/neutroot2 exes/neut echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/neut" >> setup.sh fi -if [ "@USE_NuWro@" != "FALSE" ]; then +if [ "@USE_NUWRO@" != "FALSE" ]; then if [ "@NUWRO_BUILT_FROM_FILE@" == "FALSE" ]; then mkdir deps/nuwro mkdir exes/nuwro mkdir data mkdir data/nuwro echo "[INFO]: Copying NuWro libraries from @NUWRO@" cp @NUWRO@/lib/*.so deps/nuwro cp @NUWRO@/bin/nuwro exes/nuwro/ cp -r @NUWRO@/data data/nuwro echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/nuwro" >> setup.sh echo "export NUWRO=\$NUISANCE/data/nuwro" >> setup.sh else echo "[INFO]: NuWro support included from input event file." fi fi if [ "@NEED_PYTHIA6@" != "FALSE" ]; then mkdir deps/pythia echo "[INFO]: Copying PYTHIA libraries from @PYTHIA6@" cp @PYTHIA6@/*.so deps/pythia/ echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/pythia" >> setup.sh fi if [ "@USE_GENIE@" != "FALSE" ]; then mkdir -p deps/genie/{,libxml2,lhapdf,log4cpp} mkdir exes/genie echo "[INFO]: Copying LHAPDF libraries from @LHAPDF_LIB@" cp @LHAPDF_LIB@/libLHAPDF.so* deps/genie/lhapdf echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/genie/lhapdf" >> setup.sh echo "[INFO]: Copying LIBXML2 libraries from @LIBXML2_LIB@" cp @LIBXML2_LIB@/libxml2.so* deps/genie/libxml2 echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/genie/libxml2" >> setup.sh echo "[INFO]: Copying LOG4CPP libraries from @LOG4CPP_LIB@" cp @LOG4CPP_LIB@/liblog4cpp.so* deps/genie/log4cpp echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/genie/log4cpp" >> setup.sh if [ "@LHAPATH@" ]; then mkdir -p data/genie/lhapdf cp @LHAPATH@/*.LHgrid data/genie/lhapdf/ echo "export LHAPATH=\"\$NUISANCE/data/genie/lhapdf\"" >> setup.sh fi echo "[INFO]: Copying GENIE libraries from @GENIE@/lib" cp @GENIE@/lib/*.so* deps/genie/ echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/genie" >> setup.sh echo "[INFO]: Copying GENIE binaries from @GENIE@/bin" cp @GENIE@/bin/* exes/genie/ echo "add_to_PATH \$NUISANCE/exes/genie" >> setup.sh fi mkdir exes/nuisance cp @CMAKE_INSTALL_PREFIX@/bin/* exes/nuisance/ echo "add_to_PATH \$NUISANCE/exes/nuisance" >> setup.sh rm exes/nuisance/BuildDynamic* if [ @CMAKE_BUILD_TYPE@ == "RELEASE" ]; then mkdir deps/nuisance echo "add_to_LD_LIBRARY_PATH \$NUISANCE/deps/nuisance" >> setup.sh cp @CMAKE_INSTALL_PREFIX@/lib/*.so deps/nuisance/ fi if [ -e data ]; then tar -zcvf nuisblob.tar.gz setup.sh exes/* deps/* root/* data/* else tar -zcvf nuisblob.tar.gz setup.sh exes/* deps/* root/* fi cd ../ diff --git a/cmake_old/NuWroSetup.cmake b/cmake_old/NuWroSetup.cmake index f649bff..eb8eb11 100644 --- a/cmake_old/NuWroSetup.cmake +++ b/cmake_old/NuWroSetup.cmake @@ -1,112 +1,112 @@ # 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(NOT NUWRO_INPUT_FILE STREQUAL "") if(NOT EXISTS ${NUWRO_INPUT_FILE}) cmessage(FATAL_ERROR "Expected -DNUWRO_INPUT_FILE to point to a valid input file. Cannot find: '${NUWRO_INPUT_FILE}'") endif() if(CMAKE_BUILD_TYPE MATCHES DEBUG) BuildROOTProject(NuWro_event1 ${NUWRO_INPUT_FILE} "event,vec,vect,particle,flags,params,line" STATIC) SET(ROOTLIBNAME "libNuWro_event1.a") else(CMAKE_BUILD_TYPE MATCHES RELEASE) BuildROOTProject(NuWro_event1 ${NUWRO_INPUT_FILE} "event,vec,vect,particle,flags,params,line" SHARED) SET(ROOTLIBNAME "libNuWro_event1.so") endif() ADD_CUSTOM_TARGET(NuWro_event1HeaderLink ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/NuWro_event1/event.h ${CMAKE_BINARY_DIR}/NuWro_event1/event1.h DEPENDS NuWro_event1) LIST(APPEND EXTRA_CXX_FLAGS -D__NUWRO_ENABLED__) LIST(APPEND RWENGINE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/NuWro_event1) LIST(APPEND EXTRA_LINK_DIRS ${CMAKE_BINARY_DIR}) LIST(APPEND EXTRA_LIBS NuWro_event1) LIST(APPEND PROJECTWIDE_EXTRA_DEPENDENCIES NuWro_event1HeaderLink ) install(TARGETS NuWro_event1 DESTINATION lib) SET(NUWRO_BUILT_FROM_FILE TRUE) else() if(NUWRO STREQUAL "") cmessage(FATAL_ERROR "Variable NUWRO is not defined. " "This must be set to point to a prebuilt NuWro instance.") endif() # If you are using a version of NuWro without reweighting use this to compile. - if(USE_NuWro_RW) + if(USE_NUWRO_RW) 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_CXX_FLAGS -D__NUWRO_ENABLED__ -D__NUWRO_REWEIGHT_ENABLED__) - if(USE_NuWro_SRW_Event) + if(USE_NUWRO_SRW_Event) LIST(APPEND EXTRA_CXX_FLAGS -D__USE_NUWRO_SRW_EVENTS__) endif() LIST(APPEND RWENGINE_INCLUDE_DIRECTORIES ${NUWRO}/src ${NUWRO}/src/reweight ${NUWRO_INC}/nuwro) LIST(APPEND EXTRA_LINK_DIRS ${NUWRO}/build/${CMAKE_SYSTEM_NAME}/lib) LIST(APPEND EXTRA_LIBS reweight event) else () LIST(APPEND EXTRA_CXX_FLAGS -D__NUWRO_ENABLED__) LIST(APPEND RWENGINE_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 RWENGINE_INCLUDE_DIRECTORIES ${NUWRO_INC}/nuwro) 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() endif() set(NEED_PYTHIA6 TRUE) set(NEED_ROOTPYTHIA6 TRUE) endif() diff --git a/cmake_old/ReweightEnginesSetup.cmake b/cmake_old/ReweightEnginesSetup.cmake index 231ce12..1f3a4c5 100644 --- a/cmake_old/ReweightEnginesSetup.cmake +++ b/cmake_old/ReweightEnginesSetup.cmake @@ -1,93 +1,93 @@ # 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 . ################################################################################ ################################## T2K ###################################### if(USE_T2K) include(${CMAKE_SOURCE_DIR}/cmake/T2KSetup.cmake) cmessage(STATUS "Using T2K Reweight engine.") set(USE_T2K TRUE CACHE BOOL "Whether to enable T2KReWeight support. Requires external libraries. " FORCE) endif() ################################## NIWG ###################################### if(USE_NIWG) include(${CMAKE_SOURCE_DIR}/cmake/NIWGSetup.cmake) cmessage(STATUS "Using NIWG Reweight engine.") set(USE_NIWG TRUE CACHE BOOL "Whether to enable (T2K) NIWG ReWeight support. Requires external libraries. " FORCE) endif() ################################## NIWG ###################################### if(USE_DUNERWT) include(${CMAKE_SOURCE_DIR}/cmake/DUNERwtSetup.cmake) cmessage(STATUS "Using DUNE Reweight engine.") set(USE_DUNERWT TRUE CACHE BOOL "Whether to enable DUNE ReWeight support. Requires external libraries. " FORCE) endif() ################################## MINERvA ###################################### if(USE_MINERvA_RW) include(${CMAKE_SOURCE_DIR}/cmake/MINERvASetup.cmake) cmessage(STATUS "Using MINERvA Reweight engine.") set(USE_MINERvA_RW TRUE CACHE BOOL "Whether to enable MINERvA ReWeight support. " FORCE) endif() ################################## NEUT ###################################### if(USE_NEUT) include(${CMAKE_SOURCE_DIR}/cmake/NEUTSetup.cmake) cmessage(STATUS "Using NEUT Reweight engine.") set(USE_NEUT TRUE CACHE BOOL "Whether to enable NEUT (reweight) support. Requires external libraries. " FORCE) endif() ################################# NuWro ###################################### -if(USE_NuWro) +if(USE_NUWRO) include(${CMAKE_SOURCE_DIR}/cmake/NuWroSetup.cmake) cmessage(STATUS "Using NuWro Reweight engine.") - set(USE_NuWro TRUE CACHE BOOL "Whether to enable NuWro support. " FORCE) + set(USE_NUWRO TRUE CACHE BOOL "Whether to enable NuWro support. " FORCE) endif() ################################## GENIE ##################################### if(USE_GENIE) include(${CMAKE_SOURCE_DIR}/cmake/GENIESetup.cmake) cmessage(STATUS "Using GENIE Reweight engine.") set(USE_GENIE TRUE CACHE BOOL "Whether to enable GENIE (reweight) support. Requires external libraries. " FORCE) endif() ################################################################################ ################################ Prob3++ #################################### include(${CMAKE_SOURCE_DIR}/cmake/Prob3++Setup.cmake) ################################################################################ cmessage(STATUS "Reweight engine include directories: ${RWENGINE_INCLUDE_DIRECTORIES}") 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_old/cacheVariables.cmake b/cmake_old/cacheVariables.cmake index 6ab9bb0..54572c8 100644 --- a/cmake_old/cacheVariables.cmake +++ b/cmake_old/cacheVariables.cmake @@ -1,220 +1,220 @@ # 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 . ################################################################################ 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() 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_ROOT6 FALSE INTERNAL "Whether we are using the ROOT 6. ") CheckAndSetDefaultCache(USE_HEPMC FALSE BOOL "Whether to enable HepMC input support. ") CheckAndSetDefaultEnv(HEPMC "" PATH "Path to HepMC source tree root directory. Overrides environment variable \$HEPMC <>" HEPMC) CheckAndSetDefaultCache(HEPMC_MOMUNIT "GEV" STRING "HepMC momentum units [MEV|GEV]. ") CheckAndSetDefaultCache(HEPMC_LENUNIT "CM" STRING "HepMC momentum units [MM|CM]. ") CheckAndSetDefaultCache(HEPMC_USED_EP FALSE INTERNAL "Whether we built HepMC or not. ") CheckAndSetDefaultCache(USE_NEUT FALSE BOOL "Whether to enable NEUT (reweight) support. Requires external libraries. ") CheckAndSetDefaultCache(IS_NEUT_54 FALSE BOOL "Whether to enabled NEUT is version 5.4 or greater. ") 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) -CheckAndSetDefaultCache(USE_NuWro FALSE BOOL "Whether to enable NuWro support. ") +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) CheckAndSetDefaultCache(NUWRO_INPUT_FILE "" FILEPATH "Path to an input NuWro event vector, which can be used to build NuWro i/o libraries. <>") CheckAndSetDefaultCache(NUWRO_BUILT_FROM_FILE FALSE INTERNAL "Whether the NuWro libraries were built by NUISANCE. ") -CheckAndSetDefaultCache(USE_NuWro_RW FALSE BOOL "Whether to try and build support for NuWro reweighting. ") -CheckAndSetDefaultCache(USE_NuWro_SRW_Event FALSE BOOL "Whether to use cut down NuWro reweight event format. Requires NuWro reweight. ") +CheckAndSetDefaultCache(USE_NUWRO_RW FALSE BOOL "Whether to try and build support for NuWro reweighting. ") +CheckAndSetDefaultCache(USE_NUWRO_SRW_Event FALSE BOOL "Whether to use cut down NuWro reweight event format. Requires NuWro reweight. ") 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(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) CheckAndSetDefaultCache(BUILD_GEVGEN FALSE BOOL "Whether to build nuisance_gevgen app.") CheckAndSetDefaultCache(USE_T2K FALSE BOOL "Whether to enable T2KReWeight support. Requires external libraries. ") CheckAndSetDefaultEnv(T2KREWEIGHT "" PATH "Path to installed T2KREWEIGHTReWeight. Overrides environment variable \$T2KREWEIGHT. <>" T2KREWEIGHT) CheckAndSetDefaultCache(USE_NIWG FALSE BOOL "Whether to enable (T2K) NIWG ReWeight support. Requires external libraries. ") CheckAndSetDefaultEnv(NIWG_ROOT "" PATH "Path to installed NIWGReWeight. Overrides environment variable \$NIWG. <>" NIWG) CheckAndSetDefaultCache(USE_DUNERWT FALSE BOOL "Whether to enable DUNE ReWeight support. Requires external libraries. ") CheckAndSetDefaultEnv(NUSYST_ROOT "" PATH "Path to installed NuSystematics. Overrides environment variable \$NUSYST_ROOT. <>" DUNERWT_ROOT) CheckAndSetDefaultEnv(SYSTTOOLS_ROOT "" PATH "Path to installed ART Systematics Tools. Overrides environment variable \$SYSTTOOLS_ROOT. <>" SYSTTOOLS_ROOT) CheckAndSetDefaultCache(USE_MINERvA_RW FALSE BOOL "Whether to enable MINERvA ReWeight support. ") CheckAndSetDefaultEnv(PYTHIA6 "" PATH "Path to directory containing libPythia6.so. Overrides environment variable \$PYTHIA6 <>" PYTHIA6) CheckAndSetDefaultEnv(PYTHIA8 "" PATH "Path to directory containing libPythia8.so. Overrides environment variable \$PYTHIA8 <>" PYTHIA8) CheckAndSetDefaultCache(USE_PYTHIA8 FALSE BOOL "Whether to enable PYTHIA8 event support. ") CheckAndSetDefaultCache(USE_GiBUU TRUE BOOL "Whether to enable GiBUU event support. ") CheckAndSetDefaultCache(BUILD_GiBUU FALSE BOOL "Whether to build supporting GiBUU event tools along with a patched version of GiBUU. ") CheckAndSetDefaultCache(USE_NUANCE TRUE BOOL "Whether to enable NUANCE event support. ") CheckAndSetDefaultCache(USE_PROB3PP FALSE BOOL "Whether to download and compile in Prob3++ support. ") CheckAndSetDefaultCache(NO_EXTERNAL_UPDATE FALSE BOOL "Whether to perform the update target for external dependencies. Note this may produce errors for CMake < 3.8 where a bug was fixed for the feature that this option invokes. ") CheckAndSetDefaultCache(USE_GPERFTOOLS FALSE BOOL "Whether to compile in google performance tools. ") CheckAndSetDefault(NEED_PYTHIA6 FALSE) CheckAndSetDefault(NEED_PYTHIA8 FALSE) CheckAndSetDefault(NEED_ROOTEVEGEN FALSE) CheckAndSetDefault(NEED_ROOTPYTHIA6 FALSE) CheckAndSetDefaultCache(USE_OMP FALSE BOOL "Whether to enable multicore features (there currently are none...). ") CheckAndSetDefaultCache(USE_DYNSAMPLES TRUE BOOL "Whether to enable the dynamic sample loader. ") CheckAndSetDefault(NO_EXPERIMENTS FALSE) cmessage(STATUS "NO_EXPERIMENTS: ${NO_EXPERIMENTS}") CheckAndSetDefaultCache(NO_ANL ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build ANL samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_ArgoNeuT ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build ArgoNeuT samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_BEBC ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build BEBC samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_BNL ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build BNL samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_FNAL ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build FNAL samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_GGM ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build GGM samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_K2K ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build K2K samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_MINERvA ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build MINERvA samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_MiniBooNE ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build MiniBooNE samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_T2K ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build T2K samples. <-DNO_EXPERIMENTS=FALSE>") CheckAndSetDefaultCache(NO_SciBooNE ${NO_EXPERIMENTS} BOOL "Whether to *NOT* build SciBooNE samples. <-DNO_EXPERIMENTS=FALSE>") function(SAYVARS) LIST(APPEND VARS USE_HEPMC HEPMC HEPMC_MOMUNIT HEPMC_LENUNIT HEPMC_USED_EP USE_NEUT NEUT_ROOT CERN CERN_LEVEL - USE_NuWro + USE_NUWRO NUWRO NUWRO_INC NUWRO_INPUT_FILE NUWRO_BUILT_FROM_FILE USE_GENIE GENIE LHAPDF_LIB LHAPDF_INC LIBXML2_LIB LIBXML2_INC LOG4CPP_LIB GENIE_LOG4CPP_INC BUILD_GEVGEN USE_T2K USE_NIWG USE_GiBUU BUILD_GiBUU USE_NUANCE NO_EXTERNAL_UPDATE USE_GPERFTOOLS NO_ANL NO_ArgoNeuT NO_BEBC NO_BNL NO_FNAL NO_GGM NO_K2K NO_MINERvA NO_MiniBooNE NO_T2K NO_SciBooNE) foreach(v ${VARS}) if(DEFINED ${v}) cmessage(DEBUG "VARIABLE: \"${v}\" = \"${${v}}\"") endif() endforeach(v) endfunction() diff --git a/cmake_old/setup.sh.in b/cmake_old/setup.sh.in index 44d8d3f..1d4ff6b 100644 --- a/cmake_old/setup.sh.in +++ b/cmake_old/setup.sh.in @@ -1,159 +1,159 @@ # 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_T2K@" != "FALSE" ]; then echo "[INFO]: Adding T2K paths to the environment." export T2KREWEIGHT=@T2KREWEIGHT@ add_to_LD_LIBRARY_PATH "@T2KREWEIGHT@/lib" fi if [ "@USE_NIWG@" != "FALSE" ]; then echo "[INFO]: Adding NIWG paths to the environment." export NIWG=@NIWG_ROOT@ export NIWGREWEIGHT_INPUTS=@NIWG_ROOT@/inputs add_to_LD_LIBRARY_PATH "@NIWG_ROOT@" 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 if [ "@NUWRO_BUILT_FROM_FILE@" == "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 else echo "[INFO]: NuWro support included from input event file." 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 [ "@LHAPATH@" ]; then export LHAPATH="@LHAPATH@" fi add_to_PATH "@GENIE@/bin" add_to_LD_LIBRARY_PATH "@GENIE@/lib" "@LHAPDF_LIB@" "@LIBXML2_LIB@" "@LOG4CPP_LIB@" fi if [ "@BUILD_GiBUU@" != "FALSE" ]; then echo "[INFO]: Sourcing GiBUU tools." source @CMAKE_BINARY_DIR@/GiBUUTools/src/GiBUUTools-build/Linux/setup.sh fi if [ "@NUSYST_ROOT@" != "" ]; then source @NUSYST_ROOT@/setup.sh fi export NUISANCE="@CMAKE_SOURCE_DIR@" diff --git a/config/global/nuis.global.config.fcl.in b/config/global/nuis.global.config.fcl.in index 2682d54..b086b65 100644 --- a/config/global/nuis.global.config.fcl.in +++ b/config/global/nuis.global.config.fcl.in @@ -1,20 +1,21 @@ plugins: { search_paths: { #Default plugin install directory - installed_plugins: [ @CMAKE_INSTALL_PREFIX@/plugins ] + installed_plugins: [ "@CMAKE_INSTALL_PREFIX@/plugins" ] + local_plugins: [ "./" ] } } data_dir: @CMAKE_INSTALL_PREFIX@/data persistency: { default: { output_file: nuis.out.root } } global: { sample: { verbosity_default: Reticent } } diff --git a/freshbuild.sh b/freshbuild.sh index 8018e18..3c8fc92 100644 --- a/freshbuild.sh +++ b/freshbuild.sh @@ -1,5 +1,5 @@ mkdir build cd ./build -cmake -DUSE_NuWro=0 -DUSE_NIWG=0 -DUSE_NEUT=1 -DUSE_GENIE=0 -DUSE_T2K=0 -DUSE_GiBUU=0 -DUSE_NUANCE=0 -DUSE_MINIMIZER=false ../ +cmake -DUSE_NUWRO=0 -DUSE_NIWG=0 -DUSE_NEUT=1 -DUSE_GENIE=0 -DUSE_T2K=0 -DUSE_GiBUU=0 -DUSE_NUANCE=0 -DUSE_MINIMIZER=false ../ make clean && make -j8 cd - diff --git a/scripts/to_configure/setup.sh.in b/scripts/to_configure/setup.sh.in index 7d1fdd8..a1353ae 100644 --- a/scripts/to_configure/setup.sh.in +++ b/scripts/to_configure/setup.sh.in @@ -1,152 +1,154 @@ # 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 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 + echo "[INFO]: Adding GENIE ReWeight library paths to the environment." + export GENIE_REWEIGHT="@GENIE_REWEIGHT@" 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/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index f8d6367..560710b 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,14 +1,14 @@ -SET(APPS nuissamples nuiscomp nuisevsum) +SET(APPS nuissamples nuiscomp nuisevsum nuisstudy) 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} -Wl,--no-as-needed nuis_event nuis_input nuis_utility nuis_config nuis_persistency nuis_plugins nuis_params nuis_variation nuis_generator -Wl,--as-needed) 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/app/nuiscomp.cxx b/src/app/nuiscomp.cxx index c69028f..ff37d81 100644 --- a/src/app/nuiscomp.cxx +++ b/src/app/nuiscomp.cxx @@ -1,57 +1,58 @@ #include "config/GlobalConfiguration.hxx" #include "input/IInputHandler.hxx" #include "event/MinimalEvent.hxx" #include "samples/IDataComparison.hxx" #include "plugins/Instantiate.hxx" #include "exception/exception.hxx" #include "persistency/ROOTOutput.hxx" #include "fhiclcpp/make_ParameterSet.h" #include NEW_NUIS_EXCEPT(invalid_cli_arguments); int main(int argc, char const *argv[]) { nuis::config::EnsureConfigurationRead("nuis.global.config.fcl"); nuis::config::EnsureConfigurationRead("nuis.datacomparisons.fcl"); - if (argc != 2) { + if (argc != 2 || (std::string(argv[1]) == "-?") || + (std::string(argv[1]) == "--help")) { throw invalid_cli_arguments() << "[ERROR]: Expected to be passed a single FHiCL file name or " "absolute or relative path. N.B. Files in the local directory must " "be fully qualified like \"$ " << argv[0] << " ./myconf.fcl\"."; } nuis::config::EnsureConfigurationRead(argv[1]); size_t NMax = nuis::config::GetDocument().get( "nmax", std::numeric_limits::max()); for (fhicl::ParameterSet const &samp_config : nuis::config::GetDocument().get>( "samples")) { std::cout << "[INFO]: Reading sample: " << samp_config.get("name") << std::endl; nuis::plugins::plugin_traits::unique_ptr_t sample = nuis::plugins::Instantiate( samp_config.get("name")); sample->Initialize(samp_config); sample->ProcessSample(NMax); std::cout << "[INFO]:\t Sample GOF = " << sample->GetGOF() << " / " << sample->GetNDOGuess() << std::endl; sample->Write(); } nuis::persistency::CloseOpenTFiles(); } diff --git a/src/app/nuiscomp.cxx b/src/app/nuisstudy.cxx similarity index 82% copy from src/app/nuiscomp.cxx copy to src/app/nuisstudy.cxx index c69028f..17e18b8 100644 --- a/src/app/nuiscomp.cxx +++ b/src/app/nuisstudy.cxx @@ -1,57 +1,56 @@ #include "config/GlobalConfiguration.hxx" #include "input/IInputHandler.hxx" #include "event/MinimalEvent.hxx" -#include "samples/IDataComparison.hxx" +#include "samples/IEventProcessor.hxx" #include "plugins/Instantiate.hxx" #include "exception/exception.hxx" #include "persistency/ROOTOutput.hxx" #include "fhiclcpp/make_ParameterSet.h" #include NEW_NUIS_EXCEPT(invalid_cli_arguments); int main(int argc, char const *argv[]) { nuis::config::EnsureConfigurationRead("nuis.global.config.fcl"); nuis::config::EnsureConfigurationRead("nuis.datacomparisons.fcl"); - if (argc != 2) { + if (argc != 2 || (std::string(argv[1]) == "-?") || + (std::string(argv[1]) == "--help")) { throw invalid_cli_arguments() << "[ERROR]: Expected to be passed a single FHiCL file name or " "absolute or relative path. N.B. Files in the local directory must " "be fully qualified like \"$ " << argv[0] << " ./myconf.fcl\"."; } nuis::config::EnsureConfigurationRead(argv[1]); size_t NMax = nuis::config::GetDocument().get( "nmax", std::numeric_limits::max()); for (fhicl::ParameterSet const &samp_config : nuis::config::GetDocument().get>( "samples")) { std::cout << "[INFO]: Reading sample: " << samp_config.get("name") << std::endl; - nuis::plugins::plugin_traits::unique_ptr_t sample = - nuis::plugins::Instantiate( + nuis::plugins::plugin_traits::unique_ptr_t sample = + nuis::plugins::Instantiate( samp_config.get("name")); sample->Initialize(samp_config); sample->ProcessSample(NMax); - std::cout << "[INFO]:\t Sample GOF = " << sample->GetGOF() << " / " - << sample->GetNDOGuess() << std::endl; sample->Write(); } nuis::persistency::CloseOpenTFiles(); } diff --git a/src/event/MinimalEvent.cxx b/src/event/MinimalEvent.cxx index a7cae61..3043f65 100644 --- a/src/event/MinimalEvent.cxx +++ b/src/event/MinimalEvent.cxx @@ -1,34 +1,36 @@ #include "event/MinimalEvent.hxx" namespace nuis { namespace event { MinimalEvent::MinimalEvent() : mode(Channel_t::kUndefined), probe_E(0), probe_pdg(0), XSecWeight(1), - RWWeight(1) {} + RWWeight(1), fGenEvent(nullptr) {} MinimalEvent::MinimalEvent(MinimalEvent &&other) : mode(other.mode), probe_E(other.probe_E), probe_pdg(other.probe_pdg), - XSecWeight(other.XSecWeight), RWWeight(other.RWWeight) {} + XSecWeight(other.XSecWeight), RWWeight(other.RWWeight), fGenEvent(other.fGenEvent) {} MinimalEvent &MinimalEvent::operator=(MinimalEvent &&other) { mode = other.mode; probe_E = other.probe_E; probe_pdg = other.probe_pdg; XSecWeight = other.XSecWeight; RWWeight = other.RWWeight; + fGenEvent = other.fGenEvent; 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; + clone.fGenEvent = fGenEvent; return clone; } } // namespace event } // namespace nuis diff --git a/src/event/MinimalEvent.hxx b/src/event/MinimalEvent.hxx index a025044..fde0be9 100644 --- a/src/event/MinimalEvent.hxx +++ b/src/event/MinimalEvent.hxx @@ -1,56 +1,61 @@ // 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 #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; + + /// Pointer to the generator event + /// + /// This is quite dangerous, but the results of getting it wrong should be garbage, so, we'll live with it. Generator-dependent code can static_cast this to an assumed type. The GeneratorManager can be used to check if a given input handler should pass events to a given reweighter. + void const *fGenEvent; }; -} // namespace core +} // namespace event } // namespace nuis #endif diff --git a/src/event/Particle.hxx b/src/event/Particle.hxx index dc6f4c0..04fcfe8 100644 --- a/src/event/Particle.hxx +++ b/src/event/Particle.hxx @@ -1,77 +1,78 @@ // 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_PARTICLE_HXX_SEEN #define EVENT_PARTICLE_HXX_SEEN #include "event/types.hxx" #include "TLorentzVector.h" namespace nuis { namespace event { class Particle { public: NEW_NUIS_EXCEPT(invalid_particle); #define STATUS_LIST \ X(kNuclearLeaving, 0) \ X(kPrimaryInitialState, 1) \ X(kPrimaryFinalState, 2) \ X(kIntermediate, 3) \ X(kUnknown, 4) \ X(kBlocked, 5) \ X(kNParticleStatus, 6) #define X(A, B) A = B, enum class Status_t { STATUS_LIST }; #undef X Particle(); Particle(Particle const &); PDG_t pdg; TLorentzVector P4; bool operator!() const { return (pdg == std::numeric_limits::max()); } double E() const { return P4.E(); } + double KE() const { return P4.E() - P4.M(); } double P() const { return P4.Vect().Mag(); } TVector3 P3() const { return P4.Vect(); } double M() const { return P4.M(); } double Theta() const { return P4.Vect().Theta(); } double CosTheta() const { return P4.Vect().CosTheta(); } }; } // namespace event } // namespace nuis #define X(A, B) \ case nuis::event::Particle::Status_t::A: { \ return os << #A; \ } inline std::ostream &operator<<(std::ostream &os, nuis::event::Particle::Status_t te) { switch (te) { STATUS_LIST } return os; } #undef X #undef STATUS_LIST #endif diff --git a/src/generator/CMakeLists.txt b/src/generator/CMakeLists.txt index eda12fb..35b98cb 100644 --- a/src/generator/CMakeLists.txt +++ b/src/generator/CMakeLists.txt @@ -1,3 +1,13 @@ add_subdirectory(input) add_subdirectory(utility) add_subdirectory(variation) + +SET(input_implementation_files + GeneratorManager.cxx) + +SET(input_header_files + GeneratorManager.hxx) + +add_library(nuis_generator SHARED ${input_implementation_files}) +install(TARGETS nuis_generator DESTINATION lib) +install(FILES ${input_header_files} DESTINATION include/generator) diff --git a/src/generator/GeneratorManager.cxx b/src/generator/GeneratorManager.cxx new file mode 100644 index 0000000..47de316 --- /dev/null +++ b/src/generator/GeneratorManager.cxx @@ -0,0 +1,46 @@ +#include "generator/GeneratorManager.hxx" + +#include + +namespace nuis { + +GeneratorManager *GeneratorManager::_global_inst = nullptr; + +GeneratorManager::GeneratorManager() : Generators() {} + +GeneratorManager &GeneratorManager::Get() { + if (!_global_inst) { + _global_inst = new GeneratorManager(); + } + return *_global_inst; +} + +GeneratorManager::Generator_id_t +GeneratorManager::EnsureGeneratorRegistered(std::string const &gname) { + for (size_t i = 0; i < Generators.size(); ++i) { + if (Generators[i] == gname) { + return i; + } + } + + Generator_id_t iid = Generators.size(); + Generators.push_back(gname); + return iid; +} +GeneratorManager::Generator_id_t +GeneratorManager::GetGeneratorId(std::string const &gname) const { + for (size_t i = 0; i < Generators.size(); ++i) { + if (Generators[i] == gname) { + return i; + } + } + throw unknown_generator() + << "[ERROR]: Generator " << std::quoted(gname) << " has not been loaded."; +} +bool GeneratorManager::AreCompatible(Generator_id_t g1, Generator_id_t g2) { + if ((g1 == GeneratorManager::kAll) || (g2 == GeneratorManager::kAll)) { + return true; + } + return (g1 == g2); +} +} // namespace nuis diff --git a/src/input/InputManager.hxx b/src/generator/GeneratorManager.hxx similarity index 55% copy from src/input/InputManager.hxx copy to src/generator/GeneratorManager.hxx index 80a421d..0891c4e 100644 --- a/src/input/InputManager.hxx +++ b/src/generator/GeneratorManager.hxx @@ -1,64 +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 INPUT_INPUTMANAGER_HXX_SEEN -#define INPUT_INPUTMANAGER_HXX_SEEN - -#include "input/IInputHandler.hxx" - -#include "plugins/traits.hxx" +#pragma once #include "exception/exception.hxx" #include #include -namespace fhicl { -class ParameterSet; -} - namespace nuis { -namespace input { -class InputManager { - struct NamedInputHandler { - NamedInputHandler(std::string const &, - plugins::plugin_traits::unique_ptr_t &&); - std::string name; - plugins::plugin_traits::unique_ptr_t handler; - }; - std::vector Inputs; +/// Singleton class used to register generator compatibilty by string. +/// +/// Used for +class GeneratorManager { - InputManager(); + GeneratorManager(); + + static GeneratorManager *_global_inst; + + std::vector Generators; - static InputManager *_global_inst; public: + static GeneratorManager &Get(); - static InputManager &Get(); + NEW_NUIS_EXCEPT(unknown_generator); + using Generator_id_t = size_t; - NEW_NUIS_EXCEPT(unknown_input); - typedef size_t Input_id_t; + static Generator_id_t const kAll = std::numeric_limits::max(); - Input_id_t EnsureInputLoaded(fhicl::ParameterSet const &); - Input_id_t GetInputId(std::string const &) const; - IInputHandler const &GetInputHandler(Input_id_t) const; + Generator_id_t EnsureGeneratorRegistered(std::string const &); + Generator_id_t GetGeneratorId(std::string const &) const; + /// Checks whether two generator ids are compatible + /// + /// Generator id's are compatible if either one is equal to kAll (i.e. that an + /// event plugin doesn't need any generator-specific information) or they are + /// equal. + static bool AreCompatible(Generator_id_t, Generator_id_t); }; -} // namespace input } // namespace nuis - -#endif diff --git a/src/generator/input/CMakeLists.txt b/src/generator/input/CMakeLists.txt index 46354e6..fc9daea 100644 --- a/src/generator/input/CMakeLists.txt +++ b/src/generator/input/CMakeLists.txt @@ -1,31 +1,46 @@ -LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_event nuis_config) - -if(USE_NuWro) +if(USE_NUWRO) LIST(APPEND INPUT_HANDLERS_IMPL NuWroInputHandler.cxx) - LIST(APPEND INPUT_HANDLERS_LINK_LIBS nuis_generator_utility) -endif(USE_NuWro) +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}) + target_link_libraries(InputHandlers -Wl,--no-as-needed ${GENIE_LIBS}) + endif() + + if(USE_NEUT) + target_compile_options(InputHandlers PUBLIC ${NEUT_CXX_FLAGS}) + include_directories(${NEUT_INCLUDE_DIRS}) + + target_link_libraries(InputHandlers ${NEUT_LINK_DIRS}) + target_link_libraries(InputHandlers -Wl,--no-as-needed ${NEUT_LIBS}) + target_link_libraries(InputHandlers ${NEUT_IMPORTED_TARGETS}) + endif() + + if(USE_NUWRO) + target_compile_options(InputHandlers PUBLIC ${NUWRO_CXX_FLAGS}) + include_directories(${NUWRO_INCLUDE_DIRS}) + target_link_libraries(InputHandlers -Wl,--no-as-needed ${NUWRO_IMPORTED_TARGETS}) + endif() + + if(${NEED_PYTHIA6}) + target_link_libraries(InputHandlers -L${PYTHIA6}) endif() + target_link_libraries(InputHandlers -L${ROOT_LIBDIR} ${ROOT_LIBS}) install(TARGETS InputHandlers DESTINATION plugins) endif() diff --git a/src/generator/input/GENIEInputHandler.cxx b/src/generator/input/GENIEInputHandler.cxx index f6a1d59..68a169c 100644 --- a/src/generator/input/GENIEInputHandler.cxx +++ b/src/generator/input/GENIEInputHandler.cxx @@ -1,144 +1,149 @@ #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; 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(); } +GeneratorManager::Generator_id_t GENIEInputHandler::GetGeneratorId() { + return GeneratorManager::Get().EnsureGeneratorRegistered("GENIE"); +} + DECLARE_PLUGIN(IInputHandler, GENIEInputHandler); diff --git a/src/generator/input/GENIEInputHandler.hxx b/src/generator/input/GENIEInputHandler.hxx index 558d070..f1086f1 100644 --- a/src/generator/input/GENIEInputHandler.hxx +++ b/src/generator/input/GENIEInputHandler.hxx @@ -1,67 +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 GENIEInputHandler : public IInputHandler { mutable nuis::utility::TreeFile fInputTree; mutable nuis::event::FullEvent fReaderEvent; mutable std::vector fWeightCache; - mutable genie::NtpMCEventRecord* fGenieNtpl; + mutable genie::NtpMCEventRecord *fGenieNtpl; bool fKeepIntermediates; bool fKeepNuclearParticles; public: - NEW_NUIS_EXCEPT(weight_cache_miss); 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; + double GetXSecScaleFactor(std::pair const &EnuRange) const; + + nuis::GeneratorManager::Generator_id_t GetGeneratorId(); }; diff --git a/src/generator/input/NEUTInputHandler.cxx b/src/generator/input/NEUTInputHandler.cxx index 798299e..dda5a6d 100644 --- a/src/generator/input/NEUTInputHandler.cxx +++ b/src/generator/input/NEUTInputHandler.cxx @@ -1,119 +1,129 @@ #include "generator/input/NEUTInputHandler.hxx" +#include "utility/HistogramUtility.hxx" #include "utility/InteractionChannelUtility.hxx" #include "utility/PDGCodeUtility.hxx" -#include "utility/ROOTUtility.hxx" #include "generator/utility/NEUTUtility.hxx" +#include "neutpart.h" +#include "neutvect.h" + #include "fhiclcpp/ParameterSet.h" +using namespace nuis; using namespace nuis::event; using namespace nuis::utility; using namespace nuis::neuttools; -NEUTInputHandler::NEUTInputHandler() : fInputTreeFile(nullptr) {} +NEUTInputHandler::NEUTInputHandler() : fInputTreeFile() {} NEUTInputHandler::NEUTInputHandler(NEUTInputHandler &&other) : fInputTreeFile(std::move(other.fInputTreeFile)), fReaderEvent(std::move(other.fReaderEvent)) {} void NEUTInputHandler::Initialize(fhicl::ParameterSet const &ps) { fInputTreeFile = CheckGetTTree(ps.get("file"), "neuttree"); - fReaderEvent.fNeutVect = nullptr; - fInputTreeFile->tree->SetBranchAddress("vectorbranch", - &fReaderEvent.fNeutVect); + fNeutVect = nullptr; + fInputTreeFile.tree->SetBranchAddress("vectorbranch", &fNeutVect); fKeepIntermediates = ps.get("keep_intermediates", false); -} -double NEUTInputHandler::GetXSecScaleFactor(std::pair const &) const { - // check input file for histograms - std::unique_ptr flux = - GetHistogramFromROOTFile(fInputTreeFile->file, "flux_numu"); - std::unique_ptr evtrt = - GetHistogramFromROOTFile(fInputTreeFile->file, "evtrt_numu"); + fFlux = GetHistogramFromROOTFile(fInputTreeFile.file, "flux_numu"); + fEvtrt = GetHistogramFromROOTFile(fInputTreeFile.file, "evtrt_numu"); - if (flux && evtrt) { - return evtrt->Integral() / (flux->Integral() * double(GetNEvents())); - } + fFileWeight = fEvtrt->Integral() / (fFlux->Integral() * double(GetNEvents())); +} + +double +NEUTInputHandler::GetXSecScaleFactor(std::pair const &) const { - // try and build them - throw; + throw input_handler_feature_unimplemented() + << "[ERROR]: Flux cuts not yet implemented for NEUT input handler."; } MinimalEvent const &NEUTInputHandler::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(); } - fInputTreeFile->tree->GetEntry(idx); + fInputTreeFile.tree->GetEntry(idx); - fReaderEvent.mode = IntToChannel(fReaderEvent.fNeutVect->Mode); + fReaderEvent.mode = IntToChannel(fNeutVect->Mode); - size_t NPart = fReaderEvent.fNeutVect->Npart(); + size_t NPart = fNeutVect->Npart(); for (size_t part_it = 0; part_it < NPart; part_it++) { - NeutPart const &part = (*fReaderEvent.fNeutVect->PartInfo(part_it)); + NeutPart const &part = (*fNeutVect->PartInfo(part_it)); if ((part.fIsAlive == false) && (part.fStatus == -1) && IsNeutralLepton(part.fPID)) { fReaderEvent.probe_E = part.fP.T(); fReaderEvent.probe_pdg = part.fPID; break; } } + fReaderEvent.XSecWeight = fFileWeight; + + if (fWeightCache.size() <= idx) { + fWeightCache.push_back(fReaderEvent.XSecWeight); + } + return fReaderEvent; } FullEvent const &NEUTInputHandler::GetFullEvent(ev_index_t idx) const { (void)GetMinimalEvent(idx); fReaderEvent.ClearParticleStack(); - if (fReaderEvent.fNeutVect->Ibound) { - fReaderEvent.target_pdg = MakeNuclearPDG(fReaderEvent.fNeutVect->TargetA, - fReaderEvent.fNeutVect->TargetZ); + if (fNeutVect->Ibound) { + fReaderEvent.target_pdg = + MakeNuclearPDG(fNeutVect->TargetA, fNeutVect->TargetZ); } else { fReaderEvent.target_pdg = MakeNuclearPDG(1, 1); } - size_t NPart = fReaderEvent.fNeutVect->Npart(); - size_t NPrimary = fReaderEvent.fNeutVect->Nprimary(); + size_t NPart = fNeutVect->Npart(); + size_t NPrimary = fNeutVect->Nprimary(); for (size_t part_it = 0; part_it < NPart; part_it++) { - NeutPart const &part = (*fReaderEvent.fNeutVect->PartInfo(part_it)); + NeutPart const &part = (*fNeutVect->PartInfo(part_it)); Particle nuis_part; nuis_part.pdg = part.fPID; nuis_part.P4 = part.fP; Particle::Status_t state = GetNeutParticleStatus(part, fReaderEvent.mode); if (!fKeepIntermediates && (state == Particle::Status_t::kIntermediate)) { continue; } size_t state_int = static_cast(state); // Add status == 0 particles as pre-FSI particles until we find an // intermediate state particle if ((part_it < NPrimary) && (state != Particle::Status_t::kPrimaryInitialState)) { fReaderEvent .ParticleStack[static_cast( Particle::Status_t::kPrimaryFinalState)] .particles.push_back(nuis_part); } fReaderEvent.ParticleStack[state_int].particles.push_back(nuis_part); } return fReaderEvent; } size_t NEUTInputHandler::GetNEvents() const { - return fInputTreeFile->tree->GetEntries(); + return fInputTreeFile.tree->GetEntries(); +} + +GeneratorManager::Generator_id_t NEUTInputHandler::GetGeneratorId(){ + return GeneratorManager::Get().EnsureGeneratorRegistered("NEUT"); } DECLARE_PLUGIN(IInputHandler, NEUTInputHandler); diff --git a/src/generator/input/NEUTInputHandler.hxx b/src/generator/input/NEUTInputHandler.hxx index 4d063ea..55cbf8c 100644 --- a/src/generator/input/NEUTInputHandler.hxx +++ b/src/generator/input/NEUTInputHandler.hxx @@ -1,58 +1,61 @@ // 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 GENERATOR_INPUT_NEUTINPUTHANDLER_HXX_SEEN -#define GENERATOR_INPUT_NEUTINPUTHANDLER_HXX_SEEN +#pragma once #include "event/FullEvent.hxx" #include "input/IInputHandler.hxx" +#include "utility/ROOTUtility.hxx" + #include +class NeutVect; +class TH1; + namespace fhicl { class ParameterSet; } -namespace nuis { -namespace utility { -class TreeFile; -} -} // namespace nuis - class NEUTInputHandler : public IInputHandler { - mutable std::unique_ptr fInputTreeFile; + mutable nuis::utility::TreeFile fInputTreeFile; mutable nuis::event::FullEvent fReaderEvent; + mutable NeutVect *fNeutVect; + mutable std::vector fWeightCache; + + std::unique_ptr fFlux; + std::unique_ptr fEvtrt; + double fFileWeight; bool fKeepIntermediates; public: NEUTInputHandler(); NEUTInputHandler(NEUTInputHandler const &) = delete; NEUTInputHandler(NEUTInputHandler &&); 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; size_t GetNEvents() const; - double GetXSecScaleFactor( - std::pair const &EnuRange) const; -}; + double GetXSecScaleFactor(std::pair const &EnuRange) const; -#endif + nuis::GeneratorManager::Generator_id_t GetGeneratorId(); +}; diff --git a/src/generator/input/NuWroInputHandler.cxx b/src/generator/input/NuWroInputHandler.cxx index c0c02bc..7769c14 100644 --- a/src/generator/input/NuWroInputHandler.cxx +++ b/src/generator/input/NuWroInputHandler.cxx @@ -1,122 +1,127 @@ #include "generator/input/NuWroInputHandler.hxx" #include "generator/utility/NuWroUtility.hxx" #include "fhiclcpp/ParameterSet.h" #include "particle.h" using NuWroParticle = ::particle; +using namespace nuis; using namespace nuis::event; using namespace nuis::utility; using namespace nuis::nuwrotools; NuWroInputHandler::NuWroInputHandler() : fInputTree(), fTreeEvent(nullptr) {} NuWroInputHandler::NuWroInputHandler(NuWroInputHandler &&other) : fInputTree(std::move(other.fInputTree)), fReaderEvent(std::move(other.fReaderEvent)), fTreeEvent(other.fTreeEvent) {} void NuWroInputHandler::Initialize(fhicl::ParameterSet const &ps) { fInputTree = CheckGetTTree(ps.get("file"), "treeout"); 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(*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 < 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 && fTreeEvent->out.size(); ++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 < 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(); } +GeneratorManager::Generator_id_t NuWroInputHandler::GetGeneratorId(){ + return GeneratorManager::Get().EnsureGeneratorRegistered("NuWro"); +} + DECLARE_PLUGIN(IInputHandler, NuWroInputHandler); diff --git a/src/generator/input/NuWroInputHandler.hxx b/src/generator/input/NuWroInputHandler.hxx index 2885db0..d985f2d 100644 --- a/src/generator/input/NuWroInputHandler.hxx +++ b/src/generator/input/NuWroInputHandler.hxx @@ -1,66 +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; + double GetXSecScaleFactor(std::pair const &EnuRange) const; + + nuis::GeneratorManager::Generator_id_t GetGeneratorId(); }; diff --git a/src/generator/utility/CMakeLists.txt b/src/generator/utility/CMakeLists.txt index 65b82ae..be747b1 100644 --- a/src/generator/utility/CMakeLists.txt +++ b/src/generator/utility/CMakeLists.txt @@ -1,34 +1,53 @@ -if(USE_NuWro) +if(USE_NUWRO) LIST(APPEND GENERATOR_UTILS_IMPL NuWroUtility.cxx) LIST(APPEND GENERATOR_UTILS_HDR NuWroUtility.hxx) -endif(USE_NuWro) +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}) + target_link_libraries(nuis_generator_utility -Wl,--no-as-needed ${GENIE_LIBS}) endif() + if(USE_NEUT) + target_compile_options(nuis_generator_utility PUBLIC ${NEUT_CXX_FLAGS}) + include_directories(${NEUT_INCLUDE_DIRS}) + + target_link_libraries(nuis_generator_utility ${NEUT_LINK_DIRS}) + target_link_libraries(nuis_generator_utility -Wl,--no-as-needed ${NEUT_LIBS}) + target_link_libraries(nuis_generator_utility ${NEUT_IMPORTED_TARGETS}) + endif() + + if(USE_NUWRO) + target_compile_options(nuis_generator_utility PUBLIC ${NUWRO_CXX_FLAGS}) + include_directories(${NUWRO_INCLUDE_DIRS}) + target_link_libraries(nuis_generator_utility -Wl,--no-as-needed ${NUWRO_IMPORTED_TARGETS}) + endif() + + if(${NEED_PYTHIA6}) + target_link_libraries(nuis_generator_utility -L${PYTHIA6}) + endif() + target_link_libraries(nuis_generator_utility -L${ROOT_LIBDIR} ${ROOT_LIBS}) + 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/variation/CMakeLists.txt b/src/generator/variation/CMakeLists.txt index 6cd1d8d..175cabd 100644 --- a/src/generator/variation/CMakeLists.txt +++ b/src/generator/variation/CMakeLists.txt @@ -1,13 +1,31 @@ -LIST(APPEND WEIGHT_ENGINES_LINK_LIBS nuis_event nuis_config nuis_params) - if(USE_NEUT) LIST(APPEND WEIGHT_ENGINES_IMPL NEUTWeightEngine.cxx) LIST(APPEND WEIGHT_ENGINES_LINK_LIBS nuis_generator_utility) endif(USE_NEUT) if(WEIGHT_ENGINES_IMPL) add_library(generator_weight_engines SHARED ${WEIGHT_ENGINES_IMPL}) target_link_libraries(generator_weight_engines ${WEIGHT_ENGINES_LINK_LIBS}) + if(USE_NEUT) + target_compile_options(generator_weight_engines PUBLIC ${NEUT_CXX_FLAGS}) + include_directories(${NEUT_INCLUDE_DIRS}) + + target_link_libraries(generator_weight_engines ${NEUT_LINK_DIRS}) + target_link_libraries(generator_weight_engines -Wl,--no-as-needed ${NEUT_LIBS}) + target_link_libraries(generator_weight_engines ${NEUT_IMPORTED_TARGETS}) + endif() + + if(USE_NUWRO) + target_compile_options(generator_weight_engines PUBLIC ${NUWRO_CXX_FLAGS}) + include_directories(${NUWRO_INCLUDE_DIRS}) + target_link_libraries(generator_weight_engines -Wl,--no-as-needed ${NUWRO_IMPORTED_TARGETS}) + endif() + + if(${NEED_PYTHIA6}) + target_link_libraries(generator_weight_engines -L${PYTHIA6}) + endif() + target_link_libraries(generator_weight_engines -L${ROOT_LIBDIR} ${ROOT_LIBS}) + install(TARGETS generator_weight_engines DESTINATION plugins) endif() diff --git a/src/generator/variation/FillNEUTCommons.hxx b/src/generator/variation/FillNEUTCommons.hxx index 8240d31..3b45df5 100644 --- a/src/generator/variation/FillNEUTCommons.hxx +++ b/src/generator/variation/FillNEUTCommons.hxx @@ -1,159 +1,161 @@ -#ifndef GENERATOR_VARIATION_FILLENEUTCOMMONS_HXX_SEEN -#define GENERATOR_VARIATION_FILLENEUTCOMMONS_HXX_SEEN +#pragma once #include "NFortFns.h" // Contains all the NEUT common blocks namespace NEUTUtils { -inline void FillNeutCommons(NeutVect *nvect) { +inline void FillNeutCommons(NeutVect const *nvect_const) { // WARNING: This has only been implemented for a neuttree and not GENIE // This should be kept in sync with T2KNIWGUtils::GetNIWGEvent(TTree) // NEUT version info. Can't get it to compile properly with this yet // neutversion_.corev = nvect->COREVer; // neutversion_.nucev = nvect->NUCEVer; // neutversion_.nuccv = nvect->NUCCVer; // Documentation: See nework.h + + // Dangerous... but hoping that these methods don't actually modify the + // vector. + NeutVect *nvect = const_cast(nvect_const); + nework_.modene = nvect->Mode; nework_.numne = nvect->Npart(); #ifdef NEUT_COMMON_QEAV nemdls_.mdlqeaf = nvect->QEAVForm; #else nemdls_.mdlqeaf = nvect->QEVForm; #endif nemdls_.mdlqe = nvect->QEModel; nemdls_.mdlspi = nvect->SPIModel; nemdls_.mdldis = nvect->DISModel; nemdls_.mdlcoh = nvect->COHModel; neutcoh_.necohepi = nvect->COHModel; nemdls_.xmaqe = nvect->QEMA; nemdls_.xmvqe = nvect->QEMV; nemdls_.kapp = nvect->KAPPA; // nemdls_.sccfv = SCCFVdef; // nemdls_.sccfa = SCCFAdef; // nemdls_.fpqe = FPQEdef; nemdls_.xmaspi = nvect->SPIMA; nemdls_.xmvspi = nvect->SPIMV; nemdls_.xmares = nvect->RESMA; nemdls_.xmvres = nvect->RESMV; neut1pi_.xmanffres = nvect->SPIMA; neut1pi_.xmvnffres = nvect->SPIMV; neut1pi_.xmarsres = nvect->RESMA; neut1pi_.xmvrsres = nvect->RESMV; neut1pi_.neiff = nvect->SPIForm; neut1pi_.nenrtype = nvect->SPINRType; neut1pi_.rneca5i = nvect->SPICA5I; neut1pi_.rnebgscl = nvect->SPIBGScale; nemdls_.xmacoh = nvect->COHMA; nemdls_.rad0nu = nvect->COHR0; // nemdls_.fa1coh = nvect->COHA1err; // nemdls_.fb1coh = nvect->COHb1err; // neutdis_.nepdf = NEPDFdef; // neutdis_.nebodek = NEBODEKdef; neutcard_.nefrmflg = nvect->FrmFlg; neutcard_.nepauflg = nvect->PauFlg; neutcard_.nenefo16 = nvect->NefO16; neutcard_.nemodflg = nvect->ModFlg; // neutcard_.nenefmodl = 1; // neutcard_.nenefmodh = 1; // neutcard_.nenefkinh = 1; // neutpiabs_.neabspiemit = 1; nenupr_.iformlen = nvect->FormLen; neutpiless_.ipilessdcy = nvect->IPilessDcy; neutpiless_.rpilessdcy = nvect->RPilessDcy; neutpiless_.ipilessdcy = nvect->IPilessDcy; neutpiless_.rpilessdcy = nvect->RPilessDcy; neffpr_.fefqe = nvect->NuceffFactorPIQE; neffpr_.fefqeh = nvect->NuceffFactorPIQEH; neffpr_.fefinel = nvect->NuceffFactorPIInel; neffpr_.fefabs = nvect->NuceffFactorPIAbs; neffpr_.fefcx = nvect->NuceffFactorPICX; neffpr_.fefcxh = nvect->NuceffFactorPICXH; neffpr_.fefcoh = nvect->NuceffFactorPICoh; neffpr_.fefqehf = nvect->NuceffFactorPIQEHKin; neffpr_.fefcxhf = nvect->NuceffFactorPICXKin; neffpr_.fefcohf = nvect->NuceffFactorPIQELKin; for (int i = 0; i < nework_.numne; i++) { nework_.ipne[i] = nvect->PartInfo(i)->fPID; nework_.pne[i][0] = (float)nvect->PartInfo(i)->fP.X() / 1000; // VC(NE)WORK in M(G)eV nework_.pne[i][1] = (float)nvect->PartInfo(i)->fP.Y() / 1000; // VC(NE)WORK in M(G)eV nework_.pne[i][2] = (float)nvect->PartInfo(i)->fP.Z() / 1000; // VC(NE)WORK in M(G)eV } // fsihist.h // neutroot fills a dummy object for events with no FSI to prevent memory leak // when // reading the TTree, so check for it here if ((int)nvect->NfsiVert() == 1) { // An event with FSI must have at least two vertices // if (nvect->NfsiPart()!=1 || nvect->Fsiprob!=-1) // ERR(WRN) << "T2KNeutUtils::fill_neut_commons(TTree) NfsiPart!=1 or // Fsiprob!=-1 when NfsiVert==1" << std::endl; fsihist_.nvert = 0; fsihist_.nvcvert = 0; fsihist_.fsiprob = 1; } else { // Real FSI event fsihist_.nvert = (int)nvect->NfsiVert(); for (int ivert = 0; ivert < fsihist_.nvert; ivert++) { fsihist_.iflgvert[ivert] = nvect->FsiVertInfo(ivert)->fVertID; fsihist_.posvert[ivert][0] = (float)nvect->FsiVertInfo(ivert)->fPos.X(); fsihist_.posvert[ivert][1] = (float)nvect->FsiVertInfo(ivert)->fPos.Y(); fsihist_.posvert[ivert][2] = (float)nvect->FsiVertInfo(ivert)->fPos.Z(); } fsihist_.nvcvert = nvect->NfsiPart(); for (int ip = 0; ip < fsihist_.nvcvert; ip++) { fsihist_.abspvert[ip] = (float)nvect->FsiPartInfo(ip)->fMomLab; fsihist_.abstpvert[ip] = (float)nvect->FsiPartInfo(ip)->fMomNuc; fsihist_.ipvert[ip] = nvect->FsiPartInfo(ip)->fPID; fsihist_.iverti[ip] = nvect->FsiPartInfo(ip)->fVertStart; fsihist_.ivertf[ip] = nvect->FsiPartInfo(ip)->fVertEnd; fsihist_.dirvert[ip][0] = (float)nvect->FsiPartInfo(ip)->fDir.X(); fsihist_.dirvert[ip][1] = (float)nvect->FsiPartInfo(ip)->fDir.Y(); fsihist_.dirvert[ip][2] = (float)nvect->FsiPartInfo(ip)->fDir.Z(); } fsihist_.fsiprob = nvect->Fsiprob; } neutcrscom_.crsx = nvect->Crsx; neutcrscom_.crsy = nvect->Crsy; neutcrscom_.crsz = nvect->Crsz; neutcrscom_.crsphi = nvect->Crsphi; neutcrscom_.crsq2 = nvect->Crsq2; neuttarget_.numbndn = nvect->TargetA - nvect->TargetZ; neuttarget_.numbndp = nvect->TargetZ; neuttarget_.numfrep = nvect->TargetH; neuttarget_.numatom = nvect->TargetA; posinnuc_.ibound = nvect->Ibound; // put empty nucleon FSI history (since it is not saved in the NeutVect // format) // Comment out as NEUT does not have the necessary proton FSI information yet // nucleonfsihist_.nfnvert = 0; // nucleonfsihist_.nfnstep = 0; } } // namespace NEUTUtils - -#endif diff --git a/src/generator/variation/NEUTWeightEngine.cxx b/src/generator/variation/NEUTWeightEngine.cxx index 51c1977..e2b6db6 100644 --- a/src/generator/variation/NEUTWeightEngine.cxx +++ b/src/generator/variation/NEUTWeightEngine.cxx @@ -1,114 +1,120 @@ #include "generator/variation/NEUTWeightEngine.hxx" #include "generator/variation/FillNEUTCommons.hxx" #include "fhiclcpp/ParameterSet.h" #include "event/MinimalEvent.hxx" // NEUT Engine includes #include "NReWeight.h" #include "NReWeightCasc.h" #include "NReWeightNuXSecCCQE.h" #include "NReWeightNuXSecCCRES.h" #include "NReWeightNuXSecCOH.h" #include "NReWeightNuXSecDIS.h" #include "NReWeightNuXSecNC.h" #include "NReWeightNuXSecNCEL.h" #include "NReWeightNuXSecNCRES.h" #include "NReWeightNuXSecRES.h" #include "NReWeightNuclPiless.h" #include "NSystUncertainty.h" #include using namespace nuis; using namespace nuis::params; using namespace nuis::event; void NEUTWeightEngine::Initialize(fhicl::ParameterSet const &ps) { fNeutRW = std::make_unique(); TDirectory *dir = gDirectory; fNeutRW->AdoptWghtCalc("xsec_ccqe", new neut::rew::NReWeightNuXSecCCQE); fNeutRW->AdoptWghtCalc("xsec_res", new neut::rew::NReWeightNuXSecRES); fNeutRW->AdoptWghtCalc("xsec_ccres", new neut::rew::NReWeightNuXSecCCRES); fNeutRW->AdoptWghtCalc("xsec_coh", new neut::rew::NReWeightNuXSecCOH); fNeutRW->AdoptWghtCalc("xsec_dis", new neut::rew::NReWeightNuXSecDIS); fNeutRW->AdoptWghtCalc("xsec_ncel", new neut::rew::NReWeightNuXSecNCEL); fNeutRW->AdoptWghtCalc("xsec_nc", new neut::rew::NReWeightNuXSecNC); fNeutRW->AdoptWghtCalc("xsec_ncres", new neut::rew::NReWeightNuXSecNCRES); fNeutRW->AdoptWghtCalc("nucl_casc", new neut::rew::NReWeightCasc); fNeutRW->AdoptWghtCalc("nucl_piless", new neut::rew::NReWeightNuclPiless); dir->cd(); for (fhicl::ParameterSet param_ps : ps.get>("parameters")) { param_ps.put("type", GetName()); std::string const ¶m_name = param_ps.get("name"); NEUTSystParam nsp; nsp.nsyst = neut::rew::NSyst::FromString(param_name); if (nsp.nsyst == neut::rew::kNullSystematic) { - throw invalid_NEUT_syst_name() << "[ERROR]: NReWeight failed to parse " - << std::quoted(param_name) << " as a NEUT dial."; + throw invalid_NEUT_syst_name() + << "[ERROR]: NReWeight failed to parse " << std::quoted(param_name) + << " as a NEUT dial."; } fNeutRW->Systematics().Init(nsp.nsyst); nsp.pid = ParameterManager::Get().EnsureParameterRegistered(param_ps); fNEUTSysts.push_back(nsp); } Reconfigure(); } void NEUTWeightEngine::Reconfigure() { for (NEUTSystParam const &nsp : fNEUTSysts) { double val = ParameterManager::Get().GetParameterValue(nsp.pid); fNeutRW->Systematics().Set(nsp.nsyst, val); } fNeutRW->Reconfigure(); } double NEUTWeightEngine::GetEventWeight(nuis::event::MinimalEvent const &ev) { - if (!ev.fNeutVect) { + NeutVect const *nv = static_cast(ev.fGenEvent); + if (!nv) { return 1.0; } - NEUTUtils::FillNeutCommons(ev.fNeutVect); + NEUTUtils::FillNeutCommons(nv); return fNeutRW->CalcWeight(); } std::string NEUTWeightEngine::GetName() { return "NEUTWeightEngine"; } std::string NEUTWeightEngine::GetDocumentation() { return ""; } fhicl::ParameterSet NEUTWeightEngine::GetExampleConfiguration() { fhicl::ParameterSet ps; ps.put("weight_engine_name", GetName()); fhicl::ParameterSet dial_maqe; dial_maqe.put("name", "MAQE"); dial_maqe.put("start", 0); dial_maqe.put("min", -3); dial_maqe.put("max", 3); dial_maqe.put("step", 0.1); fhicl::ParameterSet dial_mares; dial_mares.put("name", "MARES"); dial_mares.put("start", 0); dial_mares.put("min", -3); dial_mares.put("max", 3); dial_mares.put("step", 0.1); ps.put>( "parameters", std::vector{{dial_maqe, dial_mares}}); return ps; } +GeneratorManager::Generator_id_t NEUTWeightEngine::GetGeneratorId(){ + return GeneratorManager::Get().EnsureGeneratorRegistered("NEUT"); +} + DECLARE_PLUGIN(IWeightProvider, NEUTWeightEngine); diff --git a/src/generator/variation/NEUTWeightEngine.hxx b/src/generator/variation/NEUTWeightEngine.hxx index b7581c8..1ee6ea1 100644 --- a/src/generator/variation/NEUTWeightEngine.hxx +++ b/src/generator/variation/NEUTWeightEngine.hxx @@ -1,61 +1,62 @@ // 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 GENERATOR_VARIATION_NEUTREWEIGHT_HXX_SEEN #define GENERATOR_VARIATION_NEUTREWEIGHT_HXX_SEEN #include "variation/IWeightProvider.hxx" #include "exception/exception.hxx" #include "parameters/ParameterManager.hxx" #include "NSyst.h" #include #include namespace neut { namespace rew { class NReWeight; } } // namespace neut class NEUTWeightEngine : public IWeightProvider { struct NEUTSystParam { nuis::params::paramId_t pid; neut::rew::NSyst_t nsyst; }; std::vector fNEUTSysts; std::unique_ptr fNeutRW; public: NEW_NUIS_EXCEPT(invalid_NEUT_syst_name); void Initialize(fhicl::ParameterSet const &); void Reconfigure(); double GetEventWeight(nuis::event::MinimalEvent const &); std::string GetName(); std::string GetDocumentation(); fhicl::ParameterSet GetExampleConfiguration(); + nuis::GeneratorManager::Generator_id_t GetGeneratorId(); }; #endif diff --git a/src/input/IInputHandler.hxx b/src/input/IInputHandler.hxx index 58ea6c0..cb0babd 100644 --- a/src/input/IInputHandler.hxx +++ b/src/input/IInputHandler.hxx @@ -1,118 +1,122 @@ // 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 "plugins/traits.hxx" #include "exception/exception.hxx" +#include "generator/GeneratorManager.hxx" + #include #include namespace fhicl { class ParameterSet; } namespace nuis { namespace event { class MinimalEvent; class FullEvent; } // namespace event } // namespace nuis class IInputHandler { public: struct FullEvent_const_iterator : public std::iterator< std::input_iterator_tag, nuis::event::FullEvent const, size_t, nuis::event::FullEvent const *, nuis::event::FullEvent const &> { FullEvent_const_iterator(size_t _idx, IInputHandler const *_ih) { idx = _idx; ih = _ih; } FullEvent_const_iterator(FullEvent_const_iterator const &other) { idx = other.idx; ih = other.ih; } FullEvent_const_iterator operator=(FullEvent_const_iterator const &other) { idx = other.idx; ih = other.ih; return (*this); } bool operator==(FullEvent_const_iterator const &other) { return (idx == other.idx); } bool operator!=(FullEvent_const_iterator const &other) { return !(*this == other); } nuis::event::FullEvent const &operator*() { return ih->GetFullEvent(idx); } nuis::event::FullEvent const *operator->() { return &ih->GetFullEvent(idx); } FullEvent_const_iterator operator++() { idx++; return *this; } FullEvent_const_iterator operator++(int) { FullEvent_const_iterator tmp(*this); idx++; return tmp; } private: size_t idx; IInputHandler const *ih; }; NEW_NUIS_EXCEPT(invalid_input_file); NEW_NUIS_EXCEPT(invalid_entry); NEW_NUIS_EXCEPT(input_handler_feature_unimplemented); typedef size_t ev_index_t; virtual void Initialize(fhicl::ParameterSet const &) = 0; virtual nuis::event::MinimalEvent const & GetMinimalEvent(ev_index_t idx) const = 0; virtual nuis::event::FullEvent const &GetFullEvent(ev_index_t idx) const = 0; virtual void RecalculateEventWeights(){}; virtual double GetEventWeight(ev_index_t) const { return 1; }; /// Allows samples that implement flux cuts to request an appropriate virtual double GetXSecScaleFactor( std::pair const &EnuRange = std::pair{ std::numeric_limits::max(), std::numeric_limits::max()}) const = 0; virtual size_t GetNEvents() const = 0; FullEvent_const_iterator begin() const { return FullEvent_const_iterator(0, this); } FullEvent_const_iterator end() const { return FullEvent_const_iterator(GetNEvents(), this); } virtual ~IInputHandler() {} + + virtual nuis::GeneratorManager::Generator_id_t GetGeneratorId() = 0; }; DECLARE_PLUGIN_INTERFACE(IInputHandler); diff --git a/src/input/InputManager.cxx b/src/input/InputManager.cxx index 6e2dbca..bfcdb87 100644 --- a/src/input/InputManager.cxx +++ b/src/input/InputManager.cxx @@ -1,66 +1,72 @@ #include "input/InputManager.hxx" #include "plugins/Instantiate.hxx" #include "fhiclcpp/ParameterSet.h" #include namespace nuis { namespace input { InputManager *InputManager::_global_inst = nullptr; InputManager::NamedInputHandler::NamedInputHandler( std::string const &file, plugins::plugin_traits::unique_ptr_t &&IH) { name = file; handler = std::move(IH); } InputManager::InputManager() : Inputs() {} InputManager &InputManager::Get() { if (!_global_inst) { _global_inst = new InputManager(); } return *_global_inst; } InputManager::Input_id_t InputManager::EnsureInputLoaded(fhicl::ParameterSet const &ps) { std::string const &file_name = ps.get("file"); for (size_t i = 0; i < Inputs.size(); ++i) { if (Inputs[i].name == file_name) { return i; } } Input_id_t iid = Inputs.size(); - Inputs.emplace_back(file_name, - nuis::plugins::Instantiate( - ps.get("input_type") + "InputHandler")); + try { + Inputs.emplace_back( + file_name, nuis::plugins::Instantiate( + ps.get("input_type") + "InputHandler")); + } catch (plugins::failed_to_find_instantiator const &ex) { + throw unsupported_input_type() + << "Failed to find input handler support for: \"" << ps.get("input_type") + << "\", does the plugin definitely exist?"; + } Inputs.back().handler->Initialize(ps); return iid; } InputManager::Input_id_t InputManager::GetInputId(std::string const &file_name) const { for (size_t i = 0; i < Inputs.size(); ++i) { if (Inputs[i].name == file_name) { return i; } } throw unknown_input() << "[ERROR]: Input file " << std::quoted(file_name) << " has not been loaded."; } IInputHandler const & InputManager::GetInputHandler(InputManager::Input_id_t id) const { if (id >= Inputs.size()) { throw unknown_input() << "[ERROR]: Attempted to get input with id " << id << ", but only have " << Inputs.size() << " loaded inputs."; } return *Inputs[id].handler.get(); } } // namespace input } // namespace nuis diff --git a/src/input/InputManager.hxx b/src/input/InputManager.hxx index 80a421d..59b75f5 100644 --- a/src/input/InputManager.hxx +++ b/src/input/InputManager.hxx @@ -1,64 +1,62 @@ // 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 INPUT_INPUTMANAGER_HXX_SEEN -#define INPUT_INPUTMANAGER_HXX_SEEN +#pragma once #include "input/IInputHandler.hxx" #include "plugins/traits.hxx" #include "exception/exception.hxx" #include #include namespace fhicl { class ParameterSet; } namespace nuis { namespace input { class InputManager { struct NamedInputHandler { NamedInputHandler(std::string const &, plugins::plugin_traits::unique_ptr_t &&); std::string name; plugins::plugin_traits::unique_ptr_t handler; }; std::vector Inputs; InputManager(); static InputManager *_global_inst; -public: +public: static InputManager &Get(); NEW_NUIS_EXCEPT(unknown_input); - typedef size_t Input_id_t; + NEW_NUIS_EXCEPT(unsupported_input_type); + using Input_id_t = size_t; Input_id_t EnsureInputLoaded(fhicl::ParameterSet const &); Input_id_t GetInputId(std::string const &) const; IInputHandler const &GetInputHandler(Input_id_t) const; }; } // namespace input } // namespace nuis - -#endif diff --git a/src/plugins/Instantiate.hxx b/src/plugins/Instantiate.hxx index 8e7bf57..818d778 100644 --- a/src/plugins/Instantiate.hxx +++ b/src/plugins/Instantiate.hxx @@ -1,254 +1,252 @@ // 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 PLUGINS_PLUGINMANAGER_HXX_SEEN -#define PLUGINS_PLUGINMANAGER_HXX_SEEN +#pragma once #include "plugins/NamedSO.hxx" #include "plugins/traits.hxx" #include "config/GlobalConfiguration.hxx" #include "utility/FileSystemUtility.hxx" #include "exception/exception.hxx" #include "fhiclcpp/ParameterSet.h" #include "string_parsers/to_string.hxx" // linux #include #include #include #include #include #include #include // #define DEBUG_INSTANTIATE namespace nuis { namespace plugins { extern std::vector LoadedSharedObjects; NEW_NUIS_EXCEPT(failed_to_find_instantiator); NEW_NUIS_EXCEPT(malformed_plugin_interface); NEW_NUIS_EXCEPT(failed_to_load_so); typedef void *(*inst_fcn)(); typedef void (*dltr_fcn)(void *); template struct PluginInstantiator { std::string FQ_so_path; std::string Base_classname; std::string Classname; void *dllib; inst_fcn Instantiator; dltr_fcn Deleter; PluginInstantiator() : FQ_so_path(""), Base_classname(""), Classname(""), dllib(nullptr), Instantiator(nullptr), Deleter(nullptr) {} PluginInstantiator(PluginInstantiator const &) = delete; PluginInstantiator(PluginInstantiator &&other) { FQ_so_path = std::move(other.FQ_so_path); Base_classname = std::move(other.Base_classname); Classname = std::move(other.Classname); dllib = other.dllib; Instantiator = other.Instantiator; Deleter = other.Deleter; other.FQ_so_path = ""; other.Base_classname = ""; other.Classname = ""; other.dllib = nullptr; other.Instantiator = nullptr; other.Deleter = nullptr; } typename plugin_traits::unique_ptr_t Instantiate() { T *inst = reinterpret_cast((*Instantiator)()); dltr_fcn dltr = Deleter; std::string cln = Classname; std::function deleter = [=](T *inst) { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Deleting instance of " << cln << " with " << (void *)dltr << std::endl; #endif (*dltr)(inst); }; return typename plugin_traits::unique_ptr_t(inst, deleter); } }; NamedSO &GetSharedObject(std::string const &FQPath) { for (NamedSO &so : LoadedSharedObjects) { if (so.name == FQPath) { return so; } } NamedSO so; so.name = FQPath; so.dllib = dlopen(FQPath.c_str(), RTLD_NOW | RTLD_GLOBAL); char const *dlerr_cstr = dlerror(); std::string dlerr; if (dlerr_cstr) { dlerr = dlerr_cstr; } if (dlerr.length()) { throw failed_to_load_so() << "[INFO]: Failed to load shared object: " << FQPath << " with dlerror: " << dlerr; } else { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Loaded shared object " << FQPath << std::endl; #endif } LoadedSharedObjects.push_back(std::move(so)); return LoadedSharedObjects.back(); } template typename plugin_traits::unique_ptr_t Instantiate(std::string const &classname) { static std::vector> LoadedPlugins; fhicl::ParameterSet const &plugins = config::GetDocument().get("plugins"); fhicl::ParameterSet const &search_paths = plugins.get("search_paths"); std::vector plugin_search_dirs; // Look for plugin search paths in sequence elements of the // plugins.search_paths table for (std::string const &key : search_paths.get_names()) { if (!search_paths.is_key_to_sequence(key)) { continue; } for (std::string const &path : search_paths.get>(key)) { plugin_search_dirs.push_back(path); } } for (std::string path : plugin_search_dirs) { path = utility::EnsureTrailingSlash(path); for (std::string const &so_name : utility::GetMatchingFiles(path, ".*\\.so")) { for (PluginInstantiator &plugin : LoadedPlugins) { if (plugin.FQ_so_path == (path + so_name) && (plugin.Base_classname == plugin_traits::interface_name()) && (plugin.Classname == classname)) { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Using already loaded PluginInstantiator" << std::endl; #endif return plugin.Instantiate(); } } PluginInstantiator plugin; plugin.FQ_so_path = path + so_name; plugin.Base_classname = plugin_traits::interface_name(); plugin.Classname = classname; plugin.dllib = GetSharedObject(plugin.FQ_so_path).dllib; char const *dlerr_cstr = nullptr; std::string dlerr(""); plugin.Instantiator = reinterpret_cast(dlsym( plugin.dllib, plugin_traits::instantiator_function_name(classname).c_str())); dlerr_cstr = dlerror(); if (dlerr_cstr) { dlerr = dlerr_cstr; } if (dlerr_cstr) { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Failed to load appropriate instantiator method: " << plugin_traits::instantiator_function_name(classname) - << " from shared object " << plugin.FQ_so_path; + << " from shared object " << plugin.FQ_so_path << std::endl; #endif continue; } else { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Loaded instantiator method: " << plugin_traits::instantiator_function_name(classname) << " from shared object " << plugin.FQ_so_path << std::endl; #endif } plugin.Deleter = reinterpret_cast( dlsym(plugin.dllib, plugin_traits::deleter_function_name(classname).c_str())); dlerr_cstr = dlerror(); if (dlerr_cstr) { dlerr = dlerr_cstr; } if (dlerr_cstr) { throw malformed_plugin_interface() << "[ERROR]: Failed to load appropriate deleter method: " << plugin_traits::deleter_function_name(classname) << " from shared object " << plugin.FQ_so_path << " with error: " << std::quoted(dlerr); } else { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Loaded deleter method: " << plugin_traits::deleter_function_name(classname) << " from shared object " << plugin.FQ_so_path << std::endl; #endif } #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: Checking if shared object " << std::quoted(plugin.FQ_so_path) << " knows how to instantiate class " << std::quoted(classname) << " via interface " << std::quoted(plugin_traits::interface_name()) << std::endl; #endif LoadedPlugins.push_back(std::move(plugin)); return LoadedPlugins.back().Instantiate(); } } throw failed_to_find_instantiator() << "[ERROR]: Failed to find instantiator for classname: " << std::quoted(classname) << " using interface " << std::quoted(plugin_traits::interface_name()) << " from configured search paths: " << fhicl::string_parsers::T2Str>( plugin_search_dirs); } } // namespace plugins } // namespace nuis -#endif diff --git a/src/plugins/NamedSO.hxx b/src/plugins/NamedSO.hxx index 5137700..b4b9207 100644 --- a/src/plugins/NamedSO.hxx +++ b/src/plugins/NamedSO.hxx @@ -1,32 +1,29 @@ -#ifndef PLUGINS_NAMEDSO_HXX_SEEN -#define PLUGINS_NAMEDSO_HXX_SEEN +#pragma once // linux #include #include #include #include struct NamedSO { std::string name; void *dllib; NamedSO() : name(""), dllib(nullptr) {} NamedSO(NamedSO const &) = delete; NamedSO(NamedSO &&other) : name(std::move(other.name)), dllib(other.dllib) { other.dllib = nullptr; } ~NamedSO() { if (dllib) { #ifdef DEBUG_INSTANTIATE std::cout << "[INFO]: dlclose on shared object: " << std::quoted(name) << std::endl; #endif dlclose(dllib); } } }; - -#endif diff --git a/src/plugins/traits.hxx b/src/plugins/traits.hxx index 09dd3d4..b797f67 100644 --- a/src/plugins/traits.hxx +++ b/src/plugins/traits.hxx @@ -1,76 +1,73 @@ // 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 PLUGINS_TRAITS_HXX_SEEN -#define PLUGINS_TRAITS_HXX_SEEN +#pragma once #include #include #include namespace nuis { namespace plugins { template struct plugin_traits {}; } // namespace plugins } // namespace nuis #define DECLARE_PLUGIN_INTERFACE(INTERFACE_CLASS_NAME) \ namespace nuis { \ namespace plugins { \ template <> struct plugin_traits { \ typedef std::unique_ptr> \ unique_ptr_t; \ static std::string interface_name() { return #INTERFACE_CLASS_NAME; } \ static std::string \ instantiator_function_name(std::string const &classname) { \ return std::string("nuis_plugins_") + \ plugin_traits::interface_name() + "_" + \ classname + "_instantiator"; \ } \ static std::string \ check_manifest_function_name(std::string const &classname) { \ return std::string("nuis_plugins_") + \ plugin_traits::interface_name() + "_" + \ classname + "_check_manifest"; \ } \ static std::string deleter_function_name(std::string const &classname) { \ return std::string("nuis_plugins_") + \ plugin_traits::interface_name() + "_" + \ classname + "_deleter"; \ } \ }; \ } \ } #define BUILDMETHODNAME(CN, PN, POST) nuis_plugins_##CN##_##PN##POST #define DECLARE_PLUGIN(INTERFACE_CLASS_NAME, PLUGIN_CLASS_NAME) \ extern "C" { \ void *BUILDMETHODNAME(INTERFACE_CLASS_NAME, PLUGIN_CLASS_NAME, \ _instantiator)() { \ return new PLUGIN_CLASS_NAME(); \ } \ void BUILDMETHODNAME(INTERFACE_CLASS_NAME, PLUGIN_CLASS_NAME, \ _deleter)(void *instance) { \ delete reinterpret_cast(instance); \ } \ } - -#endif diff --git a/src/samples/MCTools/CMakeLists.txt b/src/samples/MCTools/CMakeLists.txt index a7a2ee2..236fdfa 100644 --- a/src/samples/MCTools/CMakeLists.txt +++ b/src/samples/MCTools/CMakeLists.txt @@ -1,13 +1,16 @@ -LIST(APPEND SAMPLES_MCTOOLS_LIBS nuis_event nuis_input nuis_config) - -if(USE_NuWro) +if(USE_NUWRO) LIST(APPEND MC_TOOL_IMPL NuisToNuWro.cxx) - LIST(APPEND SAMPLES_MCTOOLS_LIBS nuis_generator_utility) -endif(USE_NuWro) +endif(USE_NUWRO) LIST(APPEND MC_TOOL_IMPL VerboseEventSummary.cxx) add_library(MCTools SHARED ${MC_TOOL_IMPL}) target_link_libraries(MCTools ${SAMPLES_MCTOOLS_LIBS}) +if(USE_NUWRO) + target_compile_options(MCTools PUBLIC ${NUWRO_CXX_FLAGS}) + include_directories(${NUWRO_INCLUDE_DIRS}) + target_link_libraries(MCTools -Wl,--no-as-needed ${NUWRO_IMPORTED_TARGETS}) +endif() + install(TARGETS MCTools DESTINATION plugins) diff --git a/src/utility/InteractionChannelUtility.hxx b/src/utility/InteractionChannelUtility.hxx index 54b1c78..1bced13 100644 --- a/src/utility/InteractionChannelUtility.hxx +++ b/src/utility/InteractionChannelUtility.hxx @@ -1,66 +1,74 @@ #ifndef UTILITY_CHANNELUTILITY_HXX_SEEN #define UTILITY_CHANNELUTILITY_HXX_SEEN #include "event/types.hxx" #include "exception/exception.hxx" #include namespace nuis { namespace utility { NEW_NUIS_EXCEPT(invalid_channel_conversion); #define X(A, B) \ case B: { \ - return nuis::event::Channel_t::A; \ + return nuis::event::Channel_t::A; \ } inline event::Channel_t IntToChannel(int mode) { switch (mode) { NUIS_INTERACTION_CHANNEL_LIST default: { throw invalid_channel_conversion() << "[ERROR]: Failed to parse mode integer " << mode << " as a nuis::event::Channel_t."; } } } #undef X #define X(A, B) \ - case event::Channel_t::A: { \ + case event::Channel_t::A: { \ return B; \ } inline int ChannelToInt(event::Channel_t mode) { switch (mode) { NUIS_INTERACTION_CHANNEL_LIST default: { throw invalid_channel_conversion() << "[ERROR]: Attempting to convert " "undefined nuis::event::Channel_t to an " "integer."; } } } #undef X inline bool IsNC(event::Channel_t mode) { return abs(ChannelToInt(mode) > 30); } inline bool IsCC(event::Channel_t mode) { return !IsNC(mode); } inline bool IsNu(event::Channel_t mode) { return ChannelToInt(mode) > 0; } inline bool IsNub(event::Channel_t mode) { return !IsNu(mode); } inline bool IsCoh(event::Channel_t mode) { return ((mode == event::Channel_t::kCCCohPi) || (mode == event::Channel_t::kNCCohPi) || (mode == event::Channel_t::kCCCohPi_nub) || (mode == event::Channel_t::kNCCohPi_nub)); } +inline bool IsQE(event::Channel_t mode) { + return ((mode == event::Channel_t::kCCQE) || + (mode == event::Channel_t::kNCELP) || + (mode == event::Channel_t::kNCELN) || + (mode == event::Channel_t::kCCQE_nub) || + (mode == event::Channel_t::kNCELP_nub) || + (mode == event::Channel_t::kNCELN_nub)); +} } // namespace utility } // namespace nuis #endif diff --git a/src/utility/KinematicUtility.cxx b/src/utility/KinematicUtility.cxx index 8337a7f..8fda873 100644 --- a/src/utility/KinematicUtility.cxx +++ b/src/utility/KinematicUtility.cxx @@ -1,86 +1,106 @@ #include "utility/KinematicUtility.hxx" #include "event/FullEvent.hxx" #include "event/Particle.hxx" #include "utility/FullEventUtility.hxx" #include "utility/PDGCodeUtility.hxx" using namespace nuis::event; namespace nuis { namespace utility { double GetNeutrinoEQERec(FullEvent const &fev, double SeparationEnergy_MeV) { Particle const &neutrino = GetHMISNeutralLepton(fev); if (!neutrino) { throw Particle::invalid_particle() << "[ERROR]: In GetNeutrinoEQERec, expected to be able to get IS " "neutral lepton, but found none:" << "\n" << fev.to_string(); } Particle const &charged_lepton = GetHMFSChargedLepton(fev); if (!charged_lepton) { throw Particle::invalid_particle() << "[ERROR]: In GetNeutrinoEQERec, expected to be able to get FS " "charged lepton, but found none:" << "\n" << fev.to_string(); } double mass_ISN = (IsMatter(neutrino.pdg) ? (pdgmasses::kNeutronMass_MeV - SeparationEnergy_MeV) : (pdgmasses::kProtonMass_MeV - SeparationEnergy_MeV)) / 1000.0; double mass_FSN = (IsMatter(neutrino.pdg) ? pdgmasses::kProtonMass_MeV : pdgmasses::kNeutronMass_MeV) / 1000.0; double el_GeV = charged_lepton.E() / 1000.0; double pl_GeV = charged_lepton.P() / 1000.0; // momentum of lepton double ml_GeV = charged_lepton.M() / 1000.0; // lepton mass double Theta_nu_mu = neutrino.P3().Angle(charged_lepton.P3()); return (2.0 * mass_ISN * el_GeV - ml_GeV * ml_GeV + mass_FSN * mass_FSN - mass_ISN * mass_ISN) / (2.0 * (mass_ISN - el_GeV + pl_GeV * cos(Theta_nu_mu))); } double GetNeutrinoQ2QERec(FullEvent const &fev, double SeparationEnergy_MeV) { Particle const &neutrino = GetHMISNeutralLepton(fev); if (!neutrino) { throw Particle::invalid_particle() << "[ERROR]: In GetNeutrinoQ2QERec, expected to be able to get IS " "neutral lepton, but found none:" << "\n" << fev.to_string(); } Particle const &charged_lepton = GetHMFSChargedLepton(fev); if (!charged_lepton) { throw Particle::invalid_particle() << "[ERROR]: In GetNeutrinoQ2QERec, expected to be able to get FS " "charged lepton, but found none:" << "\n" << fev.to_string(); } double el_GeV = charged_lepton.E() / 1000.0; double pl_GeV = charged_lepton.P() / 1000.0; // momentum of lepton double ml_GeV = charged_lepton.M() / 1000.0; // lepton mass double Theta_nu_mu = neutrino.P3().Angle(charged_lepton.P3()); return -ml_GeV * ml_GeV + 2.0 * GetNeutrinoEQERec(fev, SeparationEnergy_MeV) * (el_GeV - pl_GeV * cos(Theta_nu_mu)); } +TLorentzVector GetEnergyMomentumTransfer(event::FullEvent const &fev) { + Particle const &neutrino = GetHMISNeutralLepton(fev); + if (!neutrino) { + throw Particle::invalid_particle() + << "[ERROR]: In GetEnergyMomentumTransfer, expected to be able to get " + "IS neutral lepton, but found none: \n" + << fev.to_string(); + } + + Particle const &charged_lepton = GetHMFSChargedLepton(fev); + if (!charged_lepton) { + throw Particle::invalid_particle() + << "[ERROR]: In GetEnergyMomentumTransfer, expected to be able to get " + "FS charged lepton, but found none: \n" + << fev.to_string(); + } + + return (neutrino.P4 - charged_lepton.P4); +} + } // namespace utility } // namespace nuis diff --git a/src/utility/KinematicUtility.hxx b/src/utility/KinematicUtility.hxx index 5143d44..f44547a 100644 --- a/src/utility/KinematicUtility.hxx +++ b/src/utility/KinematicUtility.hxx @@ -1,53 +1,57 @@ // 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_KINEMATICUTILITY_HXX_SEEN #define UTILITY_KINEMATICUTILITY_HXX_SEEN +#include "TLorentzVector.h" + #include #include namespace nuis { namespace event { class FullEvent; } } // namespace nuis namespace nuis { namespace utility { double GetNeutrinoEQERec(event::FullEvent const &fev, double SeparationEnergy_MeV); double GetNeutrinoQ2QERec(event::FullEvent const &fev, double SeparationEnergy_MeV); +TLorentzVector GetEnergyMomentumTransfer(event::FullEvent const &fev); + struct ENuRange : public std::pair { using std::pair::pair; using std::pair::operator=; ENuRange() : std::pair(0, std::numeric_limits::max()) {} bool IsInRange(double enu) { return (enu > second) || (enu < first); } }; } // namespace utility } // namespace nuis #endif diff --git a/src/utility/ROOTUtility.hxx b/src/utility/ROOTUtility.hxx index 1eef043..bc62623 100644 --- a/src/utility/ROOTUtility.hxx +++ b/src/utility/ROOTUtility.hxx @@ -1,142 +1,142 @@ // 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_ROOTUTILITY_HXX_SEEN #define UTILITY_ROOTUTILITY_HXX_SEEN #include "exception/exception.hxx" #include "TFile.h" #include "TTree.h" #include #include #include #include namespace nuis { namespace utility { NEW_NUIS_EXCEPT(failed_to_open_TFile); NEW_NUIS_EXCEPT(failed_to_get_TTree); -void CloseTFile(TFile *f = nullptr) { +inline void CloseTFile(TFile *f = nullptr) { if (f) { std::cout << "[INFO]: Shutting TFile: " << f->GetName() << ", " << f << std::endl; f->Close(); } delete f; } using TFile_ptr = std::unique_ptr; inline TFile_ptr make_unique_TFile(TFile *f) { return TFile_ptr(f, &CloseTFile); } inline TFile_ptr CheckOpenTFile(std::string const &fname, char const *opts = "") { TDirectory *ogDir = gDirectory; TFile *inpF = new TFile(fname.c_str(), opts); if (!inpF || !inpF->IsOpen()) { throw failed_to_open_TFile() << "[ERROR]: Couldn't open input file: " << std::quoted(fname); } if (ogDir) { ogDir->cd(); } return make_unique_TFile(inpF); } struct TreeFile { TFile_ptr file; TTree *tree; bool file_owned; TreeFile() : file(make_unique_TFile(nullptr)), tree(nullptr), file_owned(false) {} TreeFile(TreeFile const &other) = delete; TreeFile &operator=(TreeFile &&other) { file = std::move(other.file); tree = other.tree; file_owned = other.file_owned; other.file = nullptr; other.tree = nullptr; other.file_owned = false; return *this; } TreeFile(TreeFile &&other) : file(std::move(other.file)), tree(other.tree), file_owned(other.file_owned) { other.file = nullptr; other.tree = nullptr; other.file_owned = false; } ~TreeFile() { if (!file_owned) { file.release(); } } }; inline TreeFile CheckGetTTree(TFile *file, std::string const &tname) { TreeFile tf; tf.file = make_unique_TFile(file); tf.tree = dynamic_cast(tf.file->Get(tname.c_str())); tf.file_owned = false; if (!tf.tree) { throw failed_to_get_TTree() << "[ERROR]: Failed to get TTree named: " << std::quoted(tname) << " from TFile: " << std::quoted(file->GetName()); } std::cout << "[INFO]: Opened TFile: " << file->GetName() << ", " << file << std::endl; return tf; } inline TreeFile CheckGetTTree(std::string const &fname, std::string const &tname, char const *opts = "") { TreeFile tf = CheckGetTTree(CheckOpenTFile(fname, opts).release(), tname); tf.file_owned = true; return tf; } inline TreeFile MakeNewTTree(std::string const &fname, std::string const &tname, char const *opts = "") { TreeFile tf; tf.file = CheckOpenTFile(fname, opts); tf.tree = new TTree(tname.c_str(), ""); tf.tree->SetDirectory(tf.file.get()); tf.file_owned = true; return tf; } -std::string SanitizeROOTObjectName(std::string name) { return name; } +inline std::string SanitizeROOTObjectName(std::string name) { return name; } } // namespace utility } // namespace nuis #endif diff --git a/src/variation/IVariationProvider.hxx b/src/variation/IVariationProvider.hxx index 3c4a577..424af55 100644 --- a/src/variation/IVariationProvider.hxx +++ b/src/variation/IVariationProvider.hxx @@ -1,55 +1,60 @@ // 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 "plugins/traits.hxx" +#include "generator/GeneratorManager.hxx" + namespace fhicl { class ParameterSet; } namespace nuis { namespace event { class MinimalEvent; class FullEvent; } // namespace event } // namespace nuis class IVariationProvider { public: virtual void Initialize(fhicl::ParameterSet const &) = 0; virtual void Reconfigure() = 0; virtual nuis::event::FullEvent VaryFullEvent(nuis::event::FullEvent const &) = 0; virtual std::string GetName() = 0; virtual std::string GetDocumentation() { return "No documentation for IVariationProvider: " + GetName(); } virtual fhicl::ParameterSet GetExampleConfiguration() = 0; + /// Plugins must signify if they only interact with certain generator + virtual nuis::GeneratorManager::Generator_id_t GetGeneratorId() = 0; + virtual ~IVariationProvider() {} }; DECLARE_PLUGIN_INTERFACE(IVariationProvider); diff --git a/validation/nightly-test/base-comparisons-1/build-script.sh b/validation/nightly-test/base-comparisons-1/build-script.sh index aef4a7d..3df1c79 100644 --- a/validation/nightly-test/base-comparisons-1/build-script.sh +++ b/validation/nightly-test/base-comparisons-1/build-script.sh @@ -1,23 +1,23 @@ #!/bin/sh # Checkout nuisance git clone http://nuisance.hepforge.org/git/nuisance.git # Setup Generators source $PWD/generator-setup.sh # Build NUISANCE mkdir nuisance/build/ cd nuisance/build/ -cmake ../ -DUSE_NEUT=1 -DUSE_GENIE=1 -DUSE_NuWro=1 -DBUILD_GEVGEN=0 +cmake ../ -DUSE_NEUT=1 -DUSE_GENIE=1 -DUSE_NUWRO=1 -DBUILD_GEVGEN=0 make -j6 make install source Linux/setup.sh cd ../../ pwd echo "Finished building"