Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Geant4 build from 10.5–10.7 and example build for 11.1 onward #1152

Merged
merged 9 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/build-spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ jobs:
matrix:
compiler: [clang]
version: [15]
geant: ["10.5", "10.6", "10.7", "11.1", "11.2"]
experimental: [true]
include:
- geant: "11.0"
experimental: false
compiler: clang
version: 15
geant: ["10.5", "10.6", "10.7", "11.0", "11.1", "11.2"]
experimental: [false]
continue-on-error: ${{matrix.experimental}}
runs-on: ubuntu-22.04
permissions:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ combinations of compilers and dependencies tested under continuous integration:
- Geant4 11.0.3
- VecGeom 1.2.5

Partial compatibility and correctness is available for an extended range of
Geant4:
- 10.5-10.7: no support for tracking manager offload
- 11.0: no support for fast simulation offload
- 11.1-11.2: [no support for default Rayleigh scattering cross section](see
https://github.com/celeritas-project/celeritas/issues/1091)

Since we compile with extra warning flags and avoid non-portable code, most
other compilers *should* work.
The full set of configurations is viewable on CI platforms ([Jenkins][jenkins] and [GitHub Actions][gha]).
Expand Down
5 changes: 3 additions & 2 deletions app/celer-g4/RootIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ RootIO* RootIO::Instance()
*/
void RootIO::Write(G4Event const* event)
{
auto const hit_cols = event->GetHCofThisEvent();
auto* hit_cols = event->GetHCofThisEvent();
if (!hit_cols)
{
return;
Expand All @@ -113,7 +113,8 @@ void RootIO::Write(G4Event const* event)
event_data.event_id = event->GetEventID();
for (auto i : celeritas::range(hit_cols->GetNumberOfCollections()))
{
auto const* hc_id = hit_cols->GetHC(i);
// NOTE: Geant4@10.5 G4VHitsCollection::GetName is not const correct
auto* hc_id = hit_cols->GetHC(i);
std::vector<EventHitData> hits;
hits.resize(hc_id->GetSize());

Expand Down
12 changes: 8 additions & 4 deletions cmake/CeleritasConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ elseif(CELERITAS_USE_HIP)
endif()

if(CELERITAS_USE_Geant4)
# FIXME: needed for Geant4 11.1+ to avoid causing errors in VecGeom's
# FindXercesC
find_dependency(XercesC)
# Geant4 calls `include_directories` for CLHEP :( which is not what we want!
# Save and restore include directories around the call -- even though as a
# standalone project Celeritas will never have directory-level includes
Expand Down Expand Up @@ -104,9 +107,6 @@ if(CELERITAS_USE_VecGeom)
"and Celeritas (CELERITAS_USE_CUDA=${CELERITAS_USE_CUDA})"
)
endif()
if(NOT VecGeom_GDML_FOUND)
message(SEND_ERROR "VecGeom GDML capability is required for Celeritas")
endif()
endif()

if(CELERITAS_BUILD_TESTS)
Expand All @@ -131,8 +131,12 @@ endif()

#-----------------------------------------------------------------------------#

foreach(_dep CUDA ROOT Geant4 VecGeom MPI OpenMP)
foreach(_dep
CUDA HIP # Languages
Geant4 HepMC3 JSON MPI OpenMP ROOT VecGeom SWIG # Packages
)
set(@PROJECT_NAME@_${_dep}_FOUND ${CELERITAS_USE_${_dep}})
endforeach()
unset(_dep)

#-----------------------------------------------------------------------------#
4 changes: 2 additions & 2 deletions cmake/FindGeant4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(Geant4_VERSION VERSION_LESS 10.6)
if(NOT TARGET "${_tgt}")
add_library(${_tgt} INTERFACE)
add_library(celeritas::${_tgt} ALIAS ${_tgt})
target_include_directories(${_tgt} INTERFACE ${Geant4_INCLUDE_DIRS})
target_include_directories(${_tgt} SYSTEM INTERFACE ${Geant4_INCLUDE_DIRS})
target_compile_definitions(${_tgt} INTERFACE ${Geant4_DEFINITIONS})
install(TARGETS ${_tgt} EXPORT celeritas-targets)
endif()
Expand All @@ -55,4 +55,4 @@ if(Geant4_FOUND)
endif()
unset(_include_dirs)

#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
24 changes: 21 additions & 3 deletions example/accel/fastsim-offload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <G4Positron.hh>
#include <G4Region.hh>
#include <G4RegionStore.hh>
#include <G4RunManagerFactory.hh>
#include <G4SystemOfUnits.hh>
#include <G4Threading.hh>
#include <G4ThreeVector.hh>
Expand All @@ -36,6 +35,13 @@
#include <G4VUserActionInitialization.hh>
#include <G4VUserDetectorConstruction.hh>
#include <G4VUserPrimaryGeneratorAction.hh>
#include <G4Version.hh>
#if G4VERSION_NUMBER >= 1100
# include <G4RunManagerFactory.hh>
#else
# include <G4MTRunManager.hh>
#endif

#include <accel/AlongStepFactory.hh>
#include <accel/FastSimulationOffload.hh>
#include <accel/LocalTransporter.hh>
Expand Down Expand Up @@ -176,8 +182,14 @@ class ActionInitialization final : public G4VUserActionInitialization

int main()
{
std::unique_ptr<G4RunManager> run_manager{
G4RunManagerFactory::CreateRunManager()}; // G4RunManagerType::SerialOnly)};
auto run_manager = [] {
#if G4VERSION_NUMBER >= 1100
return std::unique_ptr<G4RunManager>{
G4RunManagerFactory::CreateRunManager()};
#else
return std::make_unique<G4RunManager>();
#endif
}();

run_manager->SetUserInitialization(new DetectorConstruction{});

Expand All @@ -201,6 +213,12 @@ int main()
setup_options.max_num_events = 1024;
// Celeritas does not support EmStandard MSC physics above 100 MeV
setup_options.ignore_processes = {"CoulombScat"};
if (G4VERSION_NUMBER >= 1110)
{
// Default Rayleigh scattering 'MinKinEnergyPrim' is no longer
// consistent
setup_options.ignore_processes.push_back("Rayl");
}

run_manager->Initialize();
run_manager->BeamOn(1);
Expand Down
24 changes: 21 additions & 3 deletions example/accel/simple-offload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <G4ParticleGun.hh>
#include <G4ParticleTable.hh>
#include <G4Positron.hh>
#include <G4RunManagerFactory.hh>
#include <G4SystemOfUnits.hh>
#include <G4Threading.hh>
#include <G4ThreeVector.hh>
Expand All @@ -33,6 +32,13 @@
#include <G4VUserActionInitialization.hh>
#include <G4VUserDetectorConstruction.hh>
#include <G4VUserPrimaryGeneratorAction.hh>
#include <G4Version.hh>
#if G4VERSION_NUMBER >= 1100
# include <G4RunManagerFactory.hh>
#else
# include <G4MTRunManager.hh>
#endif

#include <accel/AlongStepFactory.hh>
#include <accel/LocalTransporter.hh>
#include <accel/SetupOptions.hh>
Expand Down Expand Up @@ -175,8 +181,14 @@ class ActionInitialization final : public G4VUserActionInitialization

int main()
{
std::unique_ptr<G4RunManager> run_manager{
G4RunManagerFactory::CreateRunManager()}; // G4RunManagerType::SerialOnly)};
auto run_manager = [] {
#if G4VERSION_NUMBER >= 1100
return std::unique_ptr<G4RunManager>{
G4RunManagerFactory::CreateRunManager()};
#else
return std::make_unique<G4RunManager>();
#endif
}();

run_manager->SetUserInitialization(new DetectorConstruction{});
run_manager->SetUserInitialization(new FTFP_BERT{/* verbosity = */ 0});
Expand All @@ -189,6 +201,12 @@ int main()
setup_options.max_num_events = 1024;
// Celeritas does not support EmStandard MSC physics above 100 MeV
setup_options.ignore_processes = {"CoulombScat"};
if (G4VERSION_NUMBER >= 1110)
{
// Default Rayleigh scattering 'MinKinEnergyPrim' is no longer
// consistent
setup_options.ignore_processes.push_back("Rayl");
}

run_manager->Initialize();
run_manager->BeamOn(1);
Expand Down
24 changes: 21 additions & 3 deletions example/accel/trackingmanager-offload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <G4Positron.hh>
#include <G4Region.hh>
#include <G4RegionStore.hh>
#include <G4RunManagerFactory.hh>
#include <G4SystemOfUnits.hh>
#include <G4Threading.hh>
#include <G4ThreeVector.hh>
Expand All @@ -36,6 +35,13 @@
#include <G4VUserActionInitialization.hh>
#include <G4VUserDetectorConstruction.hh>
#include <G4VUserPrimaryGeneratorAction.hh>
#include <G4Version.hh>
#if G4VERSION_NUMBER >= 1100
# include <G4RunManagerFactory.hh>
#else
# include <G4MTRunManager.hh>
#endif

#include <accel/AlongStepFactory.hh>
#include <accel/LocalTransporter.hh>
#include <accel/SetupOptions.hh>
Expand Down Expand Up @@ -182,8 +188,14 @@ class ActionInitialization final : public G4VUserActionInitialization

int main()
{
std::unique_ptr<G4RunManager> run_manager{
G4RunManagerFactory::CreateRunManager()}; // G4RunManagerType::SerialOnly)};
auto run_manager = [] {
#if G4VERSION_NUMBER >= 1100
return std::unique_ptr<G4RunManager>{
G4RunManagerFactory::CreateRunManager()};
#else
return std::make_unique<G4RunManager>();
#endif
}();

run_manager->SetUserInitialization(new DetectorConstruction{});

Expand All @@ -202,6 +214,12 @@ int main()
setup_options.max_num_events = 1024;
// Celeritas does not support EmStandard MSC physics above 100 MeV
setup_options.ignore_processes = {"CoulombScat"};
if (G4VERSION_NUMBER >= 1110)
{
// Default Rayleigh scattering 'MinKinEnergyPrim' is no longer
// consistent
setup_options.ignore_processes.push_back("Rayl");
}

run_manager->Initialize();
run_manager->BeamOn(1);
Expand Down
37 changes: 22 additions & 15 deletions src/celeritas/ext/GeantImporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ struct ProcessFilter
//! Retrieve and store optical material properties, if present.
struct MatPropGetter
{
G4MaterialPropertiesTable const& mpt;
using MPT = G4MaterialPropertiesTable;

void scalar(double* dst, std::string name, ImportUnits q)
MPT const& mpt;

void scalar(double* dst, char const* name, ImportUnits q)
{
if (!mpt.ConstPropertyExists(name))
{
Expand All @@ -168,12 +170,17 @@ struct MatPropGetter

void scalar(double* dst, std::string name, int comp, ImportUnits q)
{
this->scalar(dst, name + std::to_string(comp), q);
// Geant4 10.6 and earlier require a const char* argument
name += std::to_string(comp);
this->scalar(dst, name.c_str(), q);
}

void vector(ImportPhysicsVector* dst, std::string name, ImportUnits q)
void
vector(ImportPhysicsVector* dst, std::string const& name, ImportUnits q)
{
auto const* g4vector = mpt.GetProperty(name);
// Geant4@10.7: G4MaterialPropertiesTable.GetProperty is not const
// and <=10.6 require const char*
auto const* g4vector = const_cast<MPT&>(mpt).GetProperty(name.c_str());
if (!g4vector)
{
return;
Expand Down Expand Up @@ -228,16 +235,14 @@ fill_vec_import_scint_comp(MatPropGetter& get_property,
ImportUnits::inv_mev);

// Custom-defined properties not available in G4MaterialPropertyIndex
{
get_property.scalar(&comp.lambda_mean,
particle_name + "SCINTILLATIONLAMBDAMEAN",
comp_idx,
ImportUnits::len);
get_property.scalar(&comp.lambda_sigma,
particle_name + "SCINTILLATIONLAMBDASIGMA",
comp_idx,
ImportUnits::len);
}
get_property.scalar(&comp.lambda_mean,
particle_name + "SCINTILLATIONLAMBDAMEAN",
comp_idx,
ImportUnits::len);
get_property.scalar(&comp.lambda_sigma,
particle_name + "SCINTILLATIONLAMBDASIGMA",
comp_idx,
ImportUnits::len);

// Rise time is not defined for particle type in Geant4
get_property.scalar(&comp.rise_time,
Expand Down Expand Up @@ -900,6 +905,8 @@ ImportEmParameters import_em_parameters()
#if G4VERSION_NUMBER >= 1060
import.msc_safety_factor = g4.MscSafetyFactor();
import.msc_lambda_limit = g4.MscLambdaLimit() * len_scale;
#else
CELER_DISCARD(len_scale);
#endif
import.apply_cuts = g4.ApplyCuts();
import.screening_factor = g4.ScreeningFactor();
Expand Down
2 changes: 2 additions & 0 deletions src/geocel/GeantGeoUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ void reset_geant_geometry()
G4PhysicalVolumeStore::Clean();
G4LogicalVolumeStore::Clean();
G4SolidStore::Clean();
#if G4VERSION_NUMBER >= 1100
G4ReflectionFactory::Instance()->Clean();
#endif
msg = scoped_log.str();
}
if (!msg.empty())
Expand Down
Loading