From bc5b7c33b201ff5a57e0973a06edc7014f18145d Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sat, 10 Jan 2026 23:35:52 +0100 Subject: [PATCH 01/10] refactor(atima):Added atima version for display --- CMakeLists.txt | 1 + cmake/modules/FindAtima.cmake | 26 +++++++++++++++++++------- cmake/modules/FindEPICS.cmake | 2 +- cmake/modules/Finducesb.cmake | 14 +++++++------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a873cd036..2d90b7598 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,6 +457,7 @@ else(EPICS_FOUND) endif(EPICS_FOUND) find_package(Atima) + if(ATIMA_FOUND) set(atima_summary "${BGreen}YES${CR} ${BMagenta}$ENV{ATIMAPATH}${CR}") else(ATIMA_FOUND) diff --git a/cmake/modules/FindAtima.cmake b/cmake/modules/FindAtima.cmake index 8ceb8b061..1b0b8d40f 100644 --- a/cmake/modules/FindAtima.cmake +++ b/cmake/modules/FindAtima.cmake @@ -15,7 +15,7 @@ # FindAtima.cmake - Find module for CaTima / Atima using $ENV{ATIMAPATH} ################################################################################ -message(STATUS "Looking for Atima...") +message(STATUS "Looking for ATIMA...") if(NOT DEFINED ENV{ATIMAPATH}) message(" - Environment variable ATIMAPATH is not set.") @@ -26,22 +26,31 @@ else() NAMES catima/catima.h HINTS ${CATIMA_ROOT}/include PATH_SUFFIXES catima - DOC "Path to CaTima include directory" + DOC "Path to ATIMA include directory" ) find_library(Atima_LIBRARY_SHARED NAMES catima libcatima HINTS ${CATIMA_ROOT}/lib - DOC "Path to CaTima shared library" + DOC "Path to ATIMA shared library" ) if(Atima_LIBRARY_SHARED) set(Atima_LIBRARY ${Atima_LIBRARY_SHARED}) endif() + + set(Atima_VERSION "") + if(EXISTS "${CATIMA_ROOT}/share/catima/catimaConfigVersion.cmake") + include("${CATIMA_ROOT}/share/catima/catimaConfigVersion.cmake") + if(DEFINED PACKAGE_VERSION) + set(Atima_VERSION "${PACKAGE_VERSION}") + endif() + endif() include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Atima + find_package_handle_standard_args(Atima REQUIRED_VARS Atima_LIBRARY Atima_INCLUDE_DIR + VERSION_VAR Atima_VERSION ) if(ATIMA_FOUND AND NOT TARGET Atima::Atima) @@ -55,9 +64,12 @@ else() endif() message(" - ${Cyan}ATIMAPATH${CR} = ${BGreen}$ENV{ATIMAPATH}${CR}") -message(" - ${Cyan}Atima_INCLUDE_DIR${CR} = ${BGreen}${Atima_INCLUDE_DIR}${CR}") -message(" - ${Cyan}Atima_LIBRARY${CR} = ${BGreen}${Atima_LIBRARY}${CR}") +message(" - ${Cyan}ATIMA_INCLUDE_DIR${CR} = ${BGreen}${Atima_INCLUDE_DIR}${CR}") +message(" - ${Cyan}ATIMA_LIBRARY${CR} = ${BGreen}${Atima_LIBRARY}${CR}") if(ATIMA_FOUND) - add_definitions(-DWITH_ATIMA) + message(STATUS "${BGreen}ATIMA was FOUND${CR} (version ${Atima_VERSION})") + add_definitions(-DWITH_ATIMA) +else() + message(STATUS "${BYellow}Could not find package ATIMA${CR}") endif() diff --git a/cmake/modules/FindEPICS.cmake b/cmake/modules/FindEPICS.cmake index 43045ac45..8ef7724f7 100644 --- a/cmake/modules/FindEPICS.cmake +++ b/cmake/modules/FindEPICS.cmake @@ -1,6 +1,6 @@ ################################################################################ # Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH # -# Copyright (C) 2019-2025 Members of R3B Collaboration # +# Copyright (C) 2019-2026 Members of R3B Collaboration # # # # This software is distributed under the terms of the # # GNU General Public Licence (GPL) version 3, # diff --git a/cmake/modules/Finducesb.cmake b/cmake/modules/Finducesb.cmake index eb816828d..04218488e 100644 --- a/cmake/modules/Finducesb.cmake +++ b/cmake/modules/Finducesb.cmake @@ -1,6 +1,6 @@ ################################################################################ -# Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH # -# Copyright (C) 2019-2025 Members of R3B Collaboration # +# Copyright (C) 2015 GSI Helmholtzzentrum für Schwerionenforschung GmbH # +# Copyright (C) 2015-2026 Members of R3B Collaboration # # # # This software is distributed under the terms of the # # GNU General Public Licence (GPL) version 3, # @@ -23,7 +23,7 @@ # More information: http://fy.chalmers.se/~f96hajo/ucesb/ # ################################################################################ -message(STATUS "Looking for ucesb...") +message(STATUS "Looking for UCESB...") set(ucesb_LIBRARY_SHARED ext_data_clnt) @@ -78,10 +78,10 @@ endif( AND ucesb_LIBRARY_DIR) message(" - ${Cyan}UCESB_DIR${CR} = ${BGreen}$ENV{UCESB_DIR}${CR}") -message(" - ${Cyan}ucesb_INCLUDE_DIR${CR} = ${BGreen}${ucesb_INCLUDE_DIR}${CR}") -message(" - ${Cyan}ucesb_LIBRARY_SHARED${CR} = ${BGreen}${ucesb_LIBRARY_SHARED}${CR}") -message(" - ${Cyan}ucesb_LIBRARY_STATIC${CR} = ${BGreen}${ucesb_LIBRARY_STATIC}${CR}") -message(" - ${Cyan}ucesb_LIBRARY_DIR${CR} = ${BGreen}${ucesb_LIBRARY_DIR}${CR}") +message(" - ${Cyan}UCESB_INCLUDE_DIR${CR} = ${BGreen}${ucesb_INCLUDE_DIR}${CR}") +message(" - ${Cyan}UCESB_LIBRARY_SHARED${CR} = ${BGreen}${ucesb_LIBRARY_SHARED}${CR}") +message(" - ${Cyan}UCESB_LIBRARY_STATIC${CR} = ${BGreen}${ucesb_LIBRARY_STATIC}${CR}") +message(" - ${Cyan}UCESB_LIBRARY_DIR${CR} = ${BGreen}${ucesb_LIBRARY_DIR}${CR}") if(ucesb_FOUND) add_definitions(-DWITH_UCESB) From 91332ff2329e1256cafe62a83dfd6e730e68fcba Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 14:33:49 +0100 Subject: [PATCH 02/10] feat(atima):Added CI test for Atima --- CMakeLists.txt | 13 +++++++++---- atima/test/CMakeLists.txt | 13 ++++++++++--- atima/test/testR3BAtima.cxx | 6 +++--- cmake/modules/FindAtima.cmake | 7 +++++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d90b7598..494b8b855 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -447,7 +447,7 @@ else(ucesb_FOUND) " to a ucesb installation to fix this.${CR}") endif(ucesb_FOUND) -find_package(EPICS) +find_package2(PUBLIC EPICS) if(EPICS_FOUND) set(WITH_EPICS ON) set(epics_summary "${BGreen}YES${CR} ${BMagenta}${EPICS_LIBRARY_DIR}${CR}") @@ -456,8 +456,7 @@ else(EPICS_FOUND) set(epics_summary "${BYellow}NO${CR}") endif(EPICS_FOUND) -find_package(Atima) - +find_package2(PUBLIC Atima) if(ATIMA_FOUND) set(atima_summary "${BGreen}YES${CR} ${BMagenta}$ENV{ATIMAPATH}${CR}") else(ATIMA_FOUND) @@ -768,7 +767,13 @@ if(PROJECT_PACKAGE_DEPENDENCIES) get_filename_component(prefix ${IWYU_BINARY}/.. ABSOLUTE) elseif(${dep} STREQUAL yaml-cpp) get_filename_component(prefix ${YAML_CPP_INCLUDE_DIR}/.. ABSOLUTE) - endif() + elseif(${dep} STREQUAL Atima) + if(DEFINED ENV{ATIMAPATH}) + get_filename_component(prefix $ENV{ATIMAPATH} ABSOLUTE) + else() + set(prefix "unknown") + endif() + endif() message(STATUS " ${BWhite}${dep_padded}${CR}${version_padded}${prefix}") if(${dep} STREQUAL Geant4) foreach(dataset IN LISTS Geant4_DATASETS) diff --git a/atima/test/CMakeLists.txt b/atima/test/CMakeLists.txt index 29a260e40..17aa98b4f 100644 --- a/atima/test/CMakeLists.txt +++ b/atima/test/CMakeLists.txt @@ -1,6 +1,6 @@ ############################################################################## -# Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH # -# Copyright (C) 2019-2025 Members of R3B Collaboration # +# Copyright (C) 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH # +# Copyright (C) 2020-2026 Members of R3B Collaboration # # # # This software is distributed under the terms of the # # GNU General Public Licence (GPL) version 3, # @@ -11,7 +11,14 @@ # or submit itself to any jurisdiction. # ############################################################################## -#cmake_minimum_required(VERSION 3.0) +if(GTEST_FOUND) + add_executable( + testR3BAtima + testR3BAtima.cxx) + target_link_libraries(testR3BAtima PRIVATE GTest::gtest_main GTest::gmock_main + R3BAtima) + gtest_discover_tests(testR3BAtima DISCOVERY_TIMEOUT "100") +endif(GTEST_FOUND) #enable_testing() #set(PROJECT_TEST_NAME AtimaUnitTests) diff --git a/atima/test/testR3BAtima.cxx b/atima/test/testR3BAtima.cxx index 1cf84c70e..5241cbe99 100644 --- a/atima/test/testR3BAtima.cxx +++ b/atima/test/testR3BAtima.cxx @@ -1,6 +1,6 @@ /****************************************************************************** - * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * - * Copyright (C) 2019-2025 Members of R3B Collaboration * + * Copyright (C) 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2020-2026 Members of R3B Collaboration * * * * This software is distributed under the terms of the * * GNU General Public Licence (GPL) version 3, * @@ -13,7 +13,7 @@ #include "R3BAtima.h" #include "R3BAtimaCache.h" -#include "gtest/gtest.h" +#include namespace { diff --git a/cmake/modules/FindAtima.cmake b/cmake/modules/FindAtima.cmake index 1b0b8d40f..ac641d67d 100644 --- a/cmake/modules/FindAtima.cmake +++ b/cmake/modules/FindAtima.cmake @@ -17,6 +17,10 @@ message(STATUS "Looking for ATIMA...") +set(Atima_INCLUDE_DIR Atima_INCLUDE_DIR-NOTFOUND) +set(Atima_LIBRARY Atima_LIBRARY-NOTFOUND) +set(Atima_VERSION "") + if(NOT DEFINED ENV{ATIMAPATH}) message(" - Environment variable ATIMAPATH is not set.") else() @@ -38,8 +42,7 @@ else() if(Atima_LIBRARY_SHARED) set(Atima_LIBRARY ${Atima_LIBRARY_SHARED}) endif() - - set(Atima_VERSION "") + if(EXISTS "${CATIMA_ROOT}/share/catima/catimaConfigVersion.cmake") include("${CATIMA_ROOT}/share/catima/catimaConfigVersion.cmake") if(DEFINED PACKAGE_VERSION) From 83d00624ae2cac16efc20b532131fa8c4335010a Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 14:52:38 +0100 Subject: [PATCH 03/10] Added atima installation in the CIs --- .github/actions/install-deps/action.yml | 8 +++++++- .github/actions/pre-build/action.yml | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/actions/install-deps/action.yml b/.github/actions/install-deps/action.yml index 346631f3a..59e78e1ad 100644 --- a/.github/actions/install-deps/action.yml +++ b/.github/actions/install-deps/action.yml @@ -37,8 +37,14 @@ runs: - name: build ucesb if: steps.cache-ucesb.outputs.cache-hit == '' run: | - echo "ucesb directory is set as ${UCESB_DIR}" + echo "UCESB directory is set as ${UCESB_DIR}" export LD_LIBRARY_PATH="${SIMPATH}/lib/:${LD_LIBRARY_PATH}" git clone https://git.chalmers.se/expsubphys/ucesb.git ${UCESB_DIR} cd ${UCESB_DIR} && make -j${NUM_THREADS} empty/empty + echo "ATIMA directory is set as ${ATIMAPATH}" + git clone https://github.com/hrosiak/catima.git ${ATIMAPATH} + cd ${ATIMAPATH} && mkdir build && mkdir install && cd build + cmake ../ -DCMAKE_INSTALL_PREFIX=../install/ && make -j${NUM_THREADS} && make install + export ATIMAPATH="${ATIMAPATH}/install" + echo "ATIMA install directory is set as ${ATIMAPATH}" shell: bash diff --git a/.github/actions/pre-build/action.yml b/.github/actions/pre-build/action.yml index 2c6dba7e5..2bbb7db53 100644 --- a/.github/actions/pre-build/action.yml +++ b/.github/actions/pre-build/action.yml @@ -8,6 +8,7 @@ runs: run: | git config --global --add safe.directory $GITHUB_WORKSPACE echo "UCESB_DIR=$GITHUB_WORKSPACE/ucesb/" >> $GITHUB_ENV + echo "ATIMAPATH=$GITHUB_WORKSPACE/catima/" >> $GITHUB_ENV if [ "${{ matrix.cpp }}" == "20" ]; then export SIMPATH=${CVMDIR}/${{ matrix.os }}/fairsoft/cpp20/${{ matrix.fsv }} echo "SIMPATH=${SIMPATH}" >> $GITHUB_ENV @@ -49,5 +50,6 @@ runs: mkdir -p ${CVMDIR} mount -t cvmfs fairsoft.gsi.de ${CVMDIR} mkdir -p ${UCESB_DIR} + mkdir -p ${ATIMAPATH} mkdir -p ${CCACHE_DIR} shell: bash From 6c170ada598cd9426e26744efa1b142422e0325d Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 15:00:52 +0100 Subject: [PATCH 04/10] Minor change --- .github/actions/install-deps/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/install-deps/action.yml b/.github/actions/install-deps/action.yml index 59e78e1ad..ee4a693ec 100644 --- a/.github/actions/install-deps/action.yml +++ b/.github/actions/install-deps/action.yml @@ -45,6 +45,6 @@ runs: git clone https://github.com/hrosiak/catima.git ${ATIMAPATH} cd ${ATIMAPATH} && mkdir build && mkdir install && cd build cmake ../ -DCMAKE_INSTALL_PREFIX=../install/ && make -j${NUM_THREADS} && make install - export ATIMAPATH="${ATIMAPATH}/install" + echo "ATIMAPATH=${ATIMAPATH}/install" >> $GITHUB_ENV echo "ATIMA install directory is set as ${ATIMAPATH}" shell: bash From ee5d3ab1dde706fd4f2237183661c7e16c2b52f8 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 15:10:30 +0100 Subject: [PATCH 05/10] Minor change for test --- .github/actions/install-deps/action.yml | 1 - atima/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/install-deps/action.yml b/.github/actions/install-deps/action.yml index ee4a693ec..9d02a0c2f 100644 --- a/.github/actions/install-deps/action.yml +++ b/.github/actions/install-deps/action.yml @@ -46,5 +46,4 @@ runs: cd ${ATIMAPATH} && mkdir build && mkdir install && cd build cmake ../ -DCMAKE_INSTALL_PREFIX=../install/ && make -j${NUM_THREADS} && make install echo "ATIMAPATH=${ATIMAPATH}/install" >> $GITHUB_ENV - echo "ATIMA install directory is set as ${ATIMAPATH}" shell: bash diff --git a/atima/CMakeLists.txt b/atima/CMakeLists.txt index 51012b326..24ec16595 100644 --- a/atima/CMakeLists.txt +++ b/atima/CMakeLists.txt @@ -35,4 +35,4 @@ add_library_with_dictionary( DEPENDENCIES Atima::Atima R3BBase) -add_subdirectory(test) +#add_subdirectory(test) From 475d2794dc337bb2cbefa2e930fbccdd40464de0 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 19:37:29 +0100 Subject: [PATCH 06/10] Change for atima compilation with fortran --- atima/CMakeLists.txt | 2 +- atima/test/CMakeLists.txt | 28 ---------------------------- cmake/modules/FindAtima.cmake | 2 +- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/atima/CMakeLists.txt b/atima/CMakeLists.txt index 24ec16595..51012b326 100644 --- a/atima/CMakeLists.txt +++ b/atima/CMakeLists.txt @@ -35,4 +35,4 @@ add_library_with_dictionary( DEPENDENCIES Atima::Atima R3BBase) -#add_subdirectory(test) +add_subdirectory(test) diff --git a/atima/test/CMakeLists.txt b/atima/test/CMakeLists.txt index 17aa98b4f..3647ae410 100644 --- a/atima/test/CMakeLists.txt +++ b/atima/test/CMakeLists.txt @@ -19,31 +19,3 @@ if(GTEST_FOUND) R3BAtima) gtest_discover_tests(testR3BAtima DISCOVERY_TIMEOUT "100") endif(GTEST_FOUND) - -#enable_testing() -#set(PROJECT_TEST_NAME AtimaUnitTests) -#set(GTEST_ROOT ${SIMPATH}) -#find_package(GTest) - -#if(GTEST_FOUND) -#file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/atima/test/*.cxx) - -#include_directories(${GTEST_INCLUDE_DIRS} -# ${SYSTEM_INCLUDE_DIRECTORIES} -# ${BASE_INCLUDE_DIRECTORIES} -# ${R3BROOT_SOURCE_DIR}/atima) - -#link_directories(${GTEST_LIBS_DIR} -# ${ROOT_LIBRARY_DIR} -# ${FAIRROOT_LIBRARY_DIR} -# ${Boost_LIBRARY_DIRS}) - -#set(TEST_DEPENDENCIES -# ${GTEST_BOTH_LIBRARIES} -# ${ROOT_LIBRARIES} -# R3BAtima) - -#add_executable(${PROJECT_TEST_NAME} ${TEST_SRC_FILES}) -#target_link_libraries(${PROJECT_TEST_NAME} ${TEST_DEPENDENCIES}) -#add_test(${PROJECT_TEST_NAME} ${EXECUTABLE_OUTPUT_PATH}/${PROJECT_TEST_NAME}) -#endif(GTEST_FOUND) diff --git a/cmake/modules/FindAtima.cmake b/cmake/modules/FindAtima.cmake index ac641d67d..64f4d92e6 100644 --- a/cmake/modules/FindAtima.cmake +++ b/cmake/modules/FindAtima.cmake @@ -61,7 +61,7 @@ else() set_target_properties(Atima::Atima PROPERTIES IMPORTED_LOCATION "${Atima_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${Atima_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES "${Atima_LIBRARY}" + INTERFACE_LINK_LIBRARIES Fortran ) endif() endif() From ac2e7e8c4c801d890c7c1046a2545c01ed038f14 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 19:56:30 +0100 Subject: [PATCH 07/10] Minor change --- cmake/modules/FindAtima.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/FindAtima.cmake b/cmake/modules/FindAtima.cmake index 64f4d92e6..c594d0776 100644 --- a/cmake/modules/FindAtima.cmake +++ b/cmake/modules/FindAtima.cmake @@ -61,7 +61,7 @@ else() set_target_properties(Atima::Atima PROPERTIES IMPORTED_LOCATION "${Atima_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${Atima_INCLUDE_DIR}" - INTERFACE_LINK_LIBRARIES Fortran + INTERFACE_LINK_LIBRARIES gfortran ) endif() endif() From 13184b69014933054294e37090e26e5f9fdd3bfe Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 20:07:08 +0100 Subject: [PATCH 08/10] Minor change --- atima/test/testR3BAtima.cxx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/atima/test/testR3BAtima.cxx b/atima/test/testR3BAtima.cxx index 5241cbe99..82799ee64 100644 --- a/atima/test/testR3BAtima.cxx +++ b/atima/test/testR3BAtima.cxx @@ -13,7 +13,8 @@ #include "R3BAtima.h" #include "R3BAtimaCache.h" -#include +#include "gtest/gtest.h" +#include namespace { @@ -50,9 +51,3 @@ namespace } } // namespace - -int main(int argc, char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} From 09163aa3f5ef50fcb125aab476fc8d1564a15f96 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 21:14:53 +0100 Subject: [PATCH 09/10] Change to catima --- atima/CMakeLists.txt | 6 +- atima/R3BAtima.cxx | 181 +++++++++++++++++------------------- atima/R3BAtima.h | 117 +++++++++-------------- atima/test/testR3BAtima.cxx | 112 ++++++++++++++++------ 4 files changed, 218 insertions(+), 198 deletions(-) diff --git a/atima/CMakeLists.txt b/atima/CMakeLists.txt index 51012b326..64ab69f86 100644 --- a/atima/CMakeLists.txt +++ b/atima/CMakeLists.txt @@ -13,12 +13,10 @@ set(SRCS R3BAtima.cxx -R3BAtimaCache.cxx ) set(HEADERS R3BAtima.h -R3BAtimaCache.h ) add_library_with_dictionary( @@ -35,4 +33,6 @@ add_library_with_dictionary( DEPENDENCIES Atima::Atima R3BBase) -add_subdirectory(test) +#target_link_libraries(R3BAtima PUBLIC gfortran) + +#add_subdirectory(test) diff --git a/atima/R3BAtima.cxx b/atima/R3BAtima.cxx index 8cf5afca6..8c507b4dd 100644 --- a/atima/R3BAtima.cxx +++ b/atima/R3BAtima.cxx @@ -1,6 +1,6 @@ /****************************************************************************** - * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * - * Copyright (C) 2019-2025 Members of R3B Collaboration * + * Copyright (C) 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2020-2026 Members of R3B Collaboration * * * * This software is distributed under the terms of the * * GNU General Public Licence (GPL) version 3, * @@ -13,113 +13,100 @@ #include "R3BAtima.h" -#include +#include -extern "C" +R3B::Atima::Atima(double density, std::vector> materialComponents) { - void calculate_(double* proj, - int* pn, - double* ein, - double* targ, - int* nnuca, - int* tm, - double* rhoa, - int* igasa, - double* thick, - double* eout, - double* range, - double* dedxi, - double* dedxo, - double* remra, - double* rstr, - double* estr, - double* astr, - double* tof, - double* intrthick); + fMaterial = std::make_unique(); + + for (auto materialComponent : materialComponents) + fMaterial->add_element( + std::get<0>(materialComponent), std::get<1>(materialComponent), std::get<2>(materialComponent)); } -namespace R3BAtima +double R3B::Atima::GetdEdx(double energy) const { + if (fProjectile == nullptr) + { + LOG(warning) + << " Warning in AtTools::AtELossCATIMA::GetdEdx : The projectile was not set! GetdEdx will return 0!"; + return 0; + } - const TargetMaterial TargetMaterial::Air = TargetMaterial({ MaterialCompound(14, 7, 0.755267), - MaterialCompound(16, 8, 0.231781), - MaterialCompound(39.948, 18, 0.012827), - MaterialCompound(12, 6, 0.000124) }, - 0.0012, - kTRUE); - const TargetMaterial TargetMaterial::LH2 = TargetMaterial({ MaterialCompound(1, 1) }, 0.0708, kFALSE); - const TargetMaterial TargetMaterial::Si = TargetMaterial({ MaterialCompound(28, 14) }, 2.336, kFALSE); - const TargetMaterial TargetMaterial::BC400 = - TargetMaterial({ MaterialCompound(1, 1, 0.085292), MaterialCompound(12, 6, 0.914708) }, 1.032, kFALSE); - - TransportResult Calculate(Double_t projMass_u, - Double_t projCharge_e, - Double_t projEnergy_MeV_per_u, - const TargetMaterial& targetMaterial, - Double_t tarThickness_mg_per_cm2) + if (fProjectileMassUma <= 0) { - TransportResult res; + LOG(error) << " Error in AtTools::AtELossCATIMA::GetdEdx : The projectile's mass in umas can not be <= 0! " + "GetdEdx will return 0!"; + return 0; + } - const auto invTotRatio = std::accumulate(targetMaterial.Compounds.begin(), - targetMaterial.Compounds.end(), - 0., - [](const Double_t sum, const MaterialCompound& comp) -> Double_t - { return sum + comp.Ratio; }); + catima::Result result = catima::calculate(*fProjectile, *fMaterial, energy / fProjectileMassUma); + double dEdx = result.dEdxi * fDensity; + return dEdx; +} - Int_t tcompsize = 3, tcompnum = targetMaterial.Compounds.size(), pn = 2; - std::vector tarFortran; - tarFortran.resize(tcompnum * tcompsize); - for (int i = 0; i < tcompnum; ++i) - { - tarFortran[i + tcompnum * 0] = targetMaterial.Compounds[i].Mass_u; - tarFortran[i + tcompnum * 1] = targetMaterial.Compounds[i].Charge_e; - tarFortran[i + tcompnum * 2] = targetMaterial.Compounds[i].Ratio * invTotRatio; - } +double R3B::Atima::GetRange(double energyIni, double energyFin) const +{ + if (energyFin < 0) + { + LOG(warning) << " Warning in AtTools::AtELossCATIMA::GetRange : The final energy was set to a negative value! " + "Setting energyFin to 0!"; + energyFin = 0; + } - Double_t proj[2] = { projMass_u, projCharge_e }; - Double_t density = targetMaterial.Density; - Int_t tGas = 0; - if (targetMaterial.IsGas) - tGas = 1; + if (energyFin == 0) + { + fProjectile->T = energyIni / fProjectileMassUma; + return catima::range(*fProjectile, *fMaterial) / fDensity * 10.; + } - calculate_(proj, - &pn, - &projEnergy_MeV_per_u, - &tarFortran[0], - &tcompnum, - &tcompsize, - &density, - &tGas, - &tarThickness_mg_per_cm2, - &res.EnergyOut_MeV_per_u, - &res.Range_mg_per_cm2, - &res.dEdXIn_MeVcm2_per_mg, - &res.dEdXOut_MeVcm2_per_mg, - &res.RemainingRange_mg_per_cm2, - &res.RangeStrag_mg_per_cm2, - &res.EStrag_MeV_per_u, - &res.AngStrag_mRad, - &res.ToF_ns, - &res.InterpolatedTargetThickness); + double remainingEnergy{ energyIni }; + double range{ 0 }; + while (remainingEnergy > energyFin) + { + catima::Result result = catima::calculate(*fProjectile, *fMaterial, remainingEnergy / fProjectileMassUma); + double dEdx = result.dEdxi * fDensity; + double DE = dEdx * fRangeStepSize / 10.; - res.EnergyIn_MeV_per_u = projEnergy_MeV_per_u; - res.EStrag_MeV_per_u *= res.dEdXOut_MeVcm2_per_mg; - res.ELoss_MeV_per_u = res.EnergyIn_MeV_per_u - res.EnergyOut_MeV_per_u; - res.AngStrag_mRad *= 1e3; - res.dEdXIn_MeVcm2_per_mg *= projMass_u; - res.dEdXOut_MeVcm2_per_mg *= projMass_u; - return res; + if (remainingEnergy - energyFin > DE) + { + range += fRangeStepSize; + remainingEnergy -= DE; + } + else + { + range += (remainingEnergy - energyFin) / dEdx * 10.; + remainingEnergy = energyFin; + break; + } } - TransportResult Calculate_mm(Double_t projMass_u, - Double_t projCharge_e, - Double_t projEnergy_MeV_per_u, - const TargetMaterial& targetMaterial, - Double_t tarThickness_mm) + return range; +} + +double R3B::Atima::GetEnergy(double energyIni, double distance) const +{ + double remainingEnergy{ energyIni }; + double range{ 0 }; + while (range < distance) { - return Calculate(projMass_u, - projCharge_e, - projEnergy_MeV_per_u, - targetMaterial, - targetMaterial.Density * tarThickness_mm * 100); + catima::Result result = catima::calculate(*fProjectile, *fMaterial, remainingEnergy / fProjectileMassUma); + double dEdx = result.dEdxi * fDensity; + double DE{}; + + if (range + fRangeStepSize < distance) + { + DE = dEdx * fRangeStepSize / 10.; + range += fRangeStepSize; + remainingEnergy -= DE; + } + else + { + DE = dEdx * (distance - range) / 10.; + range = distance; + remainingEnergy -= DE; + break; + } } -} // namespace R3BAtima + + return remainingEnergy; +} diff --git a/atima/R3BAtima.h b/atima/R3BAtima.h index 601dc23fb..a0ed9d222 100644 --- a/atima/R3BAtima.h +++ b/atima/R3BAtima.h @@ -14,89 +14,62 @@ #pragma once #include "Rtypes.h" +#include -#include +#include "R3BAtima.h" + +#include +#include +#include #include -namespace R3BAtima +namespace R3B { - struct MaterialCompound + class Atima : public TObject { - MaterialCompound(const Double_t mass_u = 1, const Double_t charge_e = 1) - : Mass_u(mass_u) - , Charge_e(charge_e) - , Ratio(1.) - { - } - MaterialCompound(const Double_t mass_u, const Double_t charge_e, const Double_t ratio) - : Mass_u(mass_u) - , Charge_e(charge_e) - , Ratio(ratio) - { - } - MaterialCompound(const std::array& arr) - : Mass_u(arr[0]) - , Charge_e(arr[1]) - , Ratio(arr[2]) - { - } + protected: + std::unique_ptr fMaterial{ nullptr }; + std::unique_ptr fProjectile{ nullptr }; - bool operator==(const MaterialCompound& other) const - { - return (Mass_u == other.Mass_u && Charge_e == other.Charge_e && Ratio == other.Ratio); - } - bool operator!=(const MaterialCompound& other) const { return !(*this == other); } + double fProjectileMassUma{ -1 }; - Double_t Mass_u; - Double_t Charge_e; - Double_t Ratio; - }; + double fRangeStepSize{ 0.1 }; // mm - struct TargetMaterial - { - static const TargetMaterial Air; - static const TargetMaterial LH2; - static const TargetMaterial Si; - static const TargetMaterial BC400; + public: + /** + * Initializer of the CATIMA ELossModel wrapper. + * @param[in] density Density of the material. + * @param[in] materialComponents Components of the material. They are passed as a vector of tuples (A, Z, + * stoichiometry). + */ + Atima(double density, std::vector> materialComponents); + + double fDensity = 0.; - TargetMaterial(const std::vector& compounds, const Double_t density, const Bool_t isGas) - : Compounds(compounds) - , Density(density) - , IsGas(isGas) + virtual double GetdEdx(double energy) const; + virtual double GetRange(double energyIni, double energyFin = 0) const; + virtual double GetEnergyLoss(double energyIni, double distance) const { + return energyIni - GetEnergy(energyIni, distance); } + virtual double GetEnergy(double energyIni, double distance) const; - std::vector Compounds; - Double_t Density; - Bool_t IsGas; - }; - - struct TransportResult - { - Double_t EnergyIn_MeV_per_u; - Double_t EnergyOut_MeV_per_u; - Double_t ELoss_MeV_per_u; - Double_t EStrag_MeV_per_u; - Double_t AngStrag_mRad; - Double_t Range_mg_per_cm2; - Double_t RangeStrag_mg_per_cm2; - Double_t RemainingRange_mg_per_cm2; - Double_t dEdXIn_MeVcm2_per_mg; - Double_t dEdXOut_MeVcm2_per_mg; - Double_t ToF_ns; - Double_t InterpolatedTargetThickness; + /** + * Setter of the catima projectile used for calculations. + * @param[in] A Mass number of the projectile. + * @param[in] Z Charge number of the projectile. + * @param[in] massUma Mass of the projectile in umas. + */ + void SetProjectile(double A, double Z, double massUma) + { + fProjectile = std::make_unique(A, Z); + fProjectileMassUma = massUma; + } + /** + * Setter of the range step size used for calculations. By default it is set to 0.1mm. + * @param[in] stepSize The step size used for ranges. It must be input in mm. + */ + void SetRangeStepSize(double stepSize) { fRangeStepSize = stepSize; } }; - TransportResult Calculate(Double_t projMass_u, - Double_t projCharge_e, - Double_t projEnergy_MeV_per_u, - const TargetMaterial& targetMaterial, - Double_t tarThickness_mg_per_cm2); - - TransportResult Calculate_mm(Double_t projMass_u, - Double_t projCharge_e, - Double_t projEnergy_per_u, - const TargetMaterial& targetMaterial, - Double_t tarThickness_mm); - -}; // namespace R3BAtima +}; // namespace R3B diff --git a/atima/test/testR3BAtima.cxx b/atima/test/testR3BAtima.cxx index 82799ee64..6e2aab52c 100644 --- a/atima/test/testR3BAtima.cxx +++ b/atima/test/testR3BAtima.cxx @@ -12,42 +12,102 @@ ******************************************************************************/ #include "R3BAtima.h" -#include "R3BAtimaCache.h" -#include "gtest/gtest.h" + +#include +#include #include +#include +#include +#include namespace { - constexpr auto ELOSS_Prot100 = 1.085; - TEST(testR3BAtima, basicCalculation) { - // Eloss of 100 MeV Protons in 1cm LH2 - const auto eloss = R3BAtima::Calculate_mm(1., 1., 100., R3BAtima::TargetMaterial::LH2, 10).ELoss_MeV_per_u; + // Create the vector with the gas components for H2. + std::vector> components; + components.push_back({ 1, 1, 2 }); // (A, Z, stoichiometry) - EXPECT_NEAR(eloss, ELOSS_Prot100, 0.01); - } + // Calculate the gas density for 600Torr H2 from LISE. + double density = 6.5643e-5; // g/cm3 - TEST(testR3BAtima, cacheCalculation) - { - const auto cache = R3BAtima::Cache(1., 1., { 100., 200., 10 }, R3BAtima::TargetMaterial::LH2, { 10., 50., 4 }); - EXPECT_GT(cache(100., 18.).ELoss_MeV_per_u, ELOSS_Prot100); - EXPECT_LT(cache(107., 10.).ELoss_MeV_per_u, ELOSS_Prot100); - } + // Create the CATIMA ELoss model. + R3B::Atima catimaModel(density, components); - TEST(testR3BAtima, writeReadCache) - { + // Set the projectile to proton. + catimaModel.SetProjectile(1, 1, 1.007825031898); // (A, Z, massUMA) + + // Calculate ranges for different energies with LISE. + std::vector> kinEnergyRange; // (MeV, mm) + kinEnergyRange.push_back(std::make_pair(1, 1.33e2)); + kinEnergyRange.push_back(std::make_pair(5, 2.2381e3)); + kinEnergyRange.push_back(std::make_pair(10, 7.8883e3)); + + // Compare with the results from this class. + for (auto pair : kinEnergyRange) { - // create cache file - const auto cache1 = R3BAtima::Cache( - 1., 1., { 100., 200., 10 }, R3BAtima::TargetMaterial::LH2, { 10., 50., 4 }, "test.atima"); + double energy = pair.first; + double rangeLISE = pair.second; + + double range = catimaModel.GetRange(energy); + EXPECT_TRUE(std::abs(range - rangeLISE) / rangeLISE < 0.05); } - // read cache file - const auto cache1 = - R3BAtima::Cache(1., 1., { 100., 200., 10 }, R3BAtima::TargetMaterial::LH2, { 10., 50., 4 }, "test.atima"); - // calculate without cache file - const auto cache2 = R3BAtima::Cache(1., 1., { 100., 200., 10 }, R3BAtima::TargetMaterial::LH2, { 10., 50., 4 }); - EXPECT_EQ(cache1(100., 20.).ELoss_MeV_per_u, cache2(100., 20.).ELoss_MeV_per_u); - } + // Calculate ELosses for different distances using LISE at 10MeV initial energy. + std::vector> distanceELoss; // (mm, MeV) + distanceELoss.push_back(std::make_pair(100, 0.0694)); + distanceELoss.push_back(std::make_pair(1000, 0.7138)); + distanceELoss.push_back(std::make_pair(5000, 4.2409)); + + // Compare with the results from this class. + for (auto pair : distanceELoss) + { + double distance = pair.first; + double ELossLISE = pair.second; + + double ELoss = catimaModel.GetEnergyLoss(10, distance); + EXPECT_TRUE(std::abs(ELoss - ELossLISE) / ELossLISE < 0.05); + } + + // Do the same for 4He projectile. + catimaModel.SetProjectile(4, 2, 4.00260325413); // (A, Z, massUMA) + + std::vector> kinEnergyRange4He; // (MeV, mm) + kinEnergyRange4He.push_back(std::make_pair(1, 2.5742e1)); + kinEnergyRange4He.push_back(std::make_pair(5, 2.0547e2)); + kinEnergyRange4He.push_back(std::make_pair(10, 6.5724e2)); + + // Compare with the results from this class. + for (auto pair : kinEnergyRange4He) + { + double energy = pair.first; + double rangeLISE = pair.second; + + double range = catimaModel.GetRange(energy); + EXPECT_TRUE(std::abs(range - rangeLISE) / rangeLISE < 0.05); + } + + // Calculate ELosses for different distances using LISE at 10MeV initial energy. + std::vector> distanceELoss4He; // (mm, MeV) + distanceELoss4He.push_back(std::make_pair(100, 0.9121)); + distanceELoss4He.push_back(std::make_pair(500, 5.7726)); + distanceELoss4He.push_back(std::make_pair(1000, 10)); + + // Compare with the results from this class. + for (auto pair : distanceELoss4He) + { + double distance = pair.first; + double ELossLISE = pair.second; + + double ELoss = catimaModel.GetEnergyLoss(10, distance); + EXPECT_TRUE(std::abs(ELoss - ELossLISE) / ELossLISE < 0.05); + } + + // Finally, for 4He, we test if GetRange works when setting a non-zero final energy. + double energyIni{ 10 }; + double energyFin{ 4.227 }; + double rangeLISE{ 500 }; + double range = catimaModel.GetRange(energyIni, energyFin); + EXPECT_TRUE(std::abs(range - rangeLISE) / rangeLISE < 0.05); + } } // namespace From 8375747a288d32f58b6d36d4aeab71f847ac64c2 Mon Sep 17 00:00:00 2001 From: jose-luis-rs Date: Sun, 11 Jan 2026 21:42:47 +0100 Subject: [PATCH 10/10] Minor change --- atima/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/atima/CMakeLists.txt b/atima/CMakeLists.txt index 64ab69f86..73e0b37e4 100644 --- a/atima/CMakeLists.txt +++ b/atima/CMakeLists.txt @@ -33,6 +33,4 @@ add_library_with_dictionary( DEPENDENCIES Atima::Atima R3BBase) -#target_link_libraries(R3BAtima PUBLIC gfortran) - -#add_subdirectory(test) +add_subdirectory(test)