From f31d6144a91b93887b845e654fc67ca91c2e7693 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Tue, 10 Nov 2026 20:25:10 +0100 Subject: [PATCH 1/4] Add a G4 parameter to transport e-, e+ and gamma with G4HepEm This adds the switch G4.useG4HepEm, off by default. - It appends _HEP to the hadronic physics list, eg. FTFP_BERT_EMV_HEP+optical, which selects G4HepEm in geant4_vmc. - It needs a geant4_vmc built with G4HepEm. https://its.cern.ch/jira/browse/O2-5901 https://its.cern.ch/jira/browse/O2-7316 Co-Authored-By: Claude Opus 5.5 --- Common/SimConfig/include/SimConfig/G4Params.h | 3 ++- Common/SimConfig/src/G4Params.cxx | 11 +++++++---- Detectors/gconfig/g4Config.C | 2 +- run/g4DetermineUnknownPdgProperties.cxx | 2 +- run/o2sim_g4_particle_table.cxx | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Common/SimConfig/include/SimConfig/G4Params.h b/Common/SimConfig/include/SimConfig/G4Params.h index 216f6f8d71cf2..27d5e92d94899 100644 --- a/Common/SimConfig/include/SimConfig/G4Params.h +++ b/Common/SimConfig/include/SimConfig/G4Params.h @@ -54,6 +54,7 @@ struct G4Params : public o2::conf::ConfigurableParamHelper { std::string configMacroFile = ""; // a user provided g4Config.in file (otherwise standard one fill be taken) std::string userPhysicsList = ""; // possibility to directly give physics list as string + bool useG4HepEm = false; // transport e-, e+ and gamma with G4HepEm (needs geant4_vmc built with G4HepEm) EG4Nav navmode = EG4Nav::kTGeo; // geometry navigation mode (default TGeo) @@ -76,7 +77,7 @@ struct G4Params : public o2::conf::ConfigurableParamHelper { // their placements std::string fluenceWeightFile = ""; // file containing the scoring weights (pdg, ekin, weight) - std::string const& getPhysicsConfigString() const; + std::string getPhysicsConfigString() const; bool g4scoring = false; bool g4fluenceweight = false; diff --git a/Common/SimConfig/src/G4Params.cxx b/Common/SimConfig/src/G4Params.cxx index 37625d914a85b..5db992e92af06 100644 --- a/Common/SimConfig/src/G4Params.cxx +++ b/Common/SimConfig/src/G4Params.cxx @@ -29,12 +29,15 @@ static const std::string confstrings[8] = {"FTFP_BERT+optical", "FTFP_BERT_HP_EMV+optical"}; } -std::string const& G4Params::getPhysicsConfigString() const +std::string G4Params::getPhysicsConfigString() const { - if (physicsmode == o2::conf::EG4Physics::kUSER) { - return userPhysicsList; + std::string conf = physicsmode == o2::conf::EG4Physics::kUSER ? userPhysicsList : confstrings[(int)physicsmode]; + if (useG4HepEm && conf.find("_HEP") == std::string::npos) { + // geant4_vmc selects G4HepEm with the suffix _HEP on the hadronic list, eg. FTFP_BERT_EMV_HEP+optical + const auto pos = conf.find('+'); + conf.insert(pos == std::string::npos ? conf.size() : pos, "_HEP"); } - return confstrings[(int)physicsmode]; + return conf; } } // namespace conf diff --git a/Detectors/gconfig/g4Config.C b/Detectors/gconfig/g4Config.C index bbbc2539bfad3..40a8fe211de40 100644 --- a/Detectors/gconfig/g4Config.C +++ b/Detectors/gconfig/g4Config.C @@ -140,7 +140,7 @@ void Config() // any other choice is dangerously inconsistent with the FinishPrimary() interface of VMCApp auto& g4Params = ::o2::conf::G4Params::Instance(); - auto& physicsSetup = g4Params.getPhysicsConfigString(); + auto physicsSetup = g4Params.getPhysicsConfigString(); std::cout << "PhysicsSetup wanted " << physicsSetup << "\n"; std::string geomNavStr; if (g4Params.navmode == o2::conf::EG4Nav::kTGeo) { diff --git a/run/g4DetermineUnknownPdgProperties.cxx b/run/g4DetermineUnknownPdgProperties.cxx index c2ed4526083aa..0a7a4860ef9f4 100644 --- a/run/g4DetermineUnknownPdgProperties.cxx +++ b/run/g4DetermineUnknownPdgProperties.cxx @@ -50,7 +50,7 @@ int main(int argc, char** argv) // need a dummy VMC App new o2::mc::O2TrivialMCApplication(); // setup G4 as we usually do - auto& physicsSetup = ::o2::conf::G4Params::Instance().getPhysicsConfigString(); + auto physicsSetup = ::o2::conf::G4Params::Instance().getPhysicsConfigString(); auto runConfiguration = new TG4RunConfiguration("geomRoot", physicsSetup); auto vmc = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration); // needs to be initialised to have particle and ion tables / physics entirely ready diff --git a/run/o2sim_g4_particle_table.cxx b/run/o2sim_g4_particle_table.cxx index fc205d92cf8a8..537c2c4b6daf5 100644 --- a/run/o2sim_g4_particle_table.cxx +++ b/run/o2sim_g4_particle_table.cxx @@ -42,7 +42,7 @@ int main(int argc, char** argv) // We use our O2 VMC setup to make sure we are in line with our physics definition. new o2::mc::O2TrivialMCApplication(); - auto& physicsSetup = ::o2::conf::G4Params::Instance().getPhysicsConfigString(); + auto physicsSetup = ::o2::conf::G4Params::Instance().getPhysicsConfigString(); auto runConfiguration = new TG4RunConfiguration("geomRoot", physicsSetup); auto vmc = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration); // needs to be initialised to have the particle table / physics entirely ready From 5ba94b4a66f72db4ea7eafdab552f5fdc6f26d2b Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Tue, 10 Nov 2026 20:43:35 +0100 Subject: [PATCH 2/4] Allow Geant4 to be found more than once This lets FindGeant4 return early when its targets already exist. - A geant4_vmc built with G4HepEm finds G4HepEm, which finds Geant4 again. - FindGeant4 then failed because the geant4 target already existed. Co-Authored-By: Claude Opus 5.5 --- dependencies/FindGeant4.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dependencies/FindGeant4.cmake b/dependencies/FindGeant4.cmake index 0abd8ddfe1ea0..3a3e8b49eaa2f 100644 --- a/dependencies/FindGeant4.cmake +++ b/dependencies/FindGeant4.cmake @@ -17,6 +17,11 @@ if(NOT Geant4_FOUND) return() endif() +# already set up, eg. when found again as a dependency of G4HepEm +if(TARGET geant4) + return() +endif() + add_library(geant4 IMPORTED INTERFACE) set_target_properties(geant4 From 064b5d374033ffa816ecc5b7cbacf522802da6fc Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Fri, 13 Nov 2026 18:46:04 +0100 Subject: [PATCH 3/4] Set the EMCAL sampling factor for the G4HepEm physics list This makes the Geant4 sampling factor for FTFP_BERT_EMV_HEP+optical explicit. - The value 0.808 gives the same EMCAL energy per primary as FTFP_BERT_EMV+optical with 0.821. - It was determined with e- of 1 to 20 GeV and gamma of 1 to 5 GeV; the agreement is within 1 % at all energies. - Before, the list fell back to the default 0.81 by name. https://its.cern.ch/jira/browse/O2-7210 https://its.cern.ch/jira/browse/O2-7316 Co-Authored-By: Claude Opus 5.5 --- Detectors/EMCAL/base/src/Geometry.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Detectors/EMCAL/base/src/Geometry.cxx b/Detectors/EMCAL/base/src/Geometry.cxx index 643cb63cfdf5d..759336b6ef23f 100644 --- a/Detectors/EMCAL/base/src/Geometry.cxx +++ b/Detectors/EMCAL/base/src/Geometry.cxx @@ -290,6 +290,9 @@ void Geometry::DefineSamplingFraction(const std::string_view mcname, const std:: samplingFactorTranportModel = 0.821; } else if (physicslist == "FTFP_BERT_EMV+optical+biasing" || physicslist == "FTFP_INCLXX_EMV+optical") { samplingFactorTranportModel = 0.81; + } else if (physicslist == "FTFP_BERT_EMV_HEP+optical") { + // e-, e+ and gamma with G4HepEm; same energy per primary as FTFP_BERT_EMV+optical with 0.821 (O2-7210) + samplingFactorTranportModel = 0.808; } } From 8e99d0572204049889609844e8a88e9dd6fb36ad Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Mon, 16 Nov 2026 21:54:23 +0100 Subject: [PATCH 4/4] Use the TRD collision model with G4HepEm by default This makes the TRD ionisation model follow the G4HepEm physics. - The new default TRDSimParams.ionisationModel=-1 selects the collision tables (1) when G4HepEm transports e-, e+ and gamma, and the energy deposit with PAI (0) otherwise. - G4HepEm counts as active when the physics list in use has the suffix _HEP, so a list given by name behaves like G4.useG4HepEm=1. - An explicit 0 or 1 still wins; 0 together with G4HepEm gives a warning, since G4HepEm has no PAI model. Co-Authored-By: Claude Opus 5.5 --- Common/SimConfig/include/SimConfig/G4Params.h | 2 ++ Detectors/TRD/simulation/README.md | 3 ++- .../simulation/include/TRDSimulation/TRDSimParams.h | 4 +++- Detectors/TRD/simulation/src/Detector.cxx | 12 +++++++++--- Detectors/gconfig/g4Config.C | 8 +++++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Common/SimConfig/include/SimConfig/G4Params.h b/Common/SimConfig/include/SimConfig/G4Params.h index 27d5e92d94899..0d05de1106060 100644 --- a/Common/SimConfig/include/SimConfig/G4Params.h +++ b/Common/SimConfig/include/SimConfig/G4Params.h @@ -78,6 +78,8 @@ struct G4Params : public o2::conf::ConfigurableParamHelper { std::string fluenceWeightFile = ""; // file containing the scoring weights (pdg, ekin, weight) std::string getPhysicsConfigString() const; + /// whether the physics list in use transports e-, e+ and gamma with G4HepEm (suffix _HEP) + bool isG4HepEmActive() const { return getPhysicsConfigString().find("_HEP") != std::string::npos; } bool g4scoring = false; bool g4fluenceweight = false; diff --git a/Detectors/TRD/simulation/README.md b/Detectors/TRD/simulation/README.md index 563497d0c71ab..f2234a87a4e1c 100644 --- a/Detectors/TRD/simulation/README.md +++ b/Detectors/TRD/simulation/README.md @@ -25,7 +25,8 @@ o2-sim -m PIPE MAG TRD -n 1000 -g boxgen --configKeyValues 'BoxGun.pdg=211;BoxGu --configKeyValues 'TRDSimParams.doTR=false;TRDSimParams.maxMCStepSize=0.1' ``` -The charge of a hit in the gas comes from one of two models, selected with `TRDSimParams.ionisationModel`: +The charge of a hit in the gas comes from one of two models, selected with `TRDSimParams.ionisationModel`. The +default `-1` selects `1` when G4HepEm transports e-, e+ and gamma (`G4.useG4HepEm=1`) and `0` otherwise: - `0`: the Geant4 energy deposit in the gas divided by Wion. Geant4 then uses the PAI model in the TRD gas (`Detectors/gconfig/g4config_trd_pai.in`, applied by `g4Config.C`). - `1`: the TRD collision model (`src/IonisationModel.cxx`). Geant4 runs without PAI in the gas. The tables are made diff --git a/Detectors/TRD/simulation/include/TRDSimulation/TRDSimParams.h b/Detectors/TRD/simulation/include/TRDSimulation/TRDSimParams.h index a187d41d058a5..ed974671e8e09 100644 --- a/Detectors/TRD/simulation/include/TRDSimulation/TRDSimParams.h +++ b/Detectors/TRD/simulation/include/TRDSimulation/TRDSimParams.h @@ -38,7 +38,7 @@ struct TRDSimParams : public o2::conf::ConfigurableParamHelper { bool doTR = true; ///< switch for transition radiation SimParam::GasMixture gas = SimParam::GasMixture::Xenon; ///< the gas mixture in the TRD // ionisation in the gas - int ionisationModel = 0; ///< charge from 0: Geant4 energy deposit with PAI, 1: TRD collision tables, no PAI + int ionisationModel = -1; ///< charge from 0: Geant4 energy deposit with PAI, 1: TRD collision tables, no PAI, -1: 1 with G4HepEm, else 0 float ionisationMinBetaGamma = 0.04; ///< below this beta*gamma the charge comes from the energy deposit float ionisationMinEkin = 30e3; ///< (eV) below this kinetic energy the charge comes from the energy deposit // TRF parameters @@ -46,6 +46,8 @@ struct TRDSimParams : public o2::conf::ConfigurableParamHelper { float trf_landau_mu = 0.; // Mu of the Landau distribution used to describe TRF float trf_landau_sigma = .03; // Sigma of the Landau distribution used to describe TRF float t0 = -0.170; // Time delay before start of amplification peak, in us + /// the ionisation model in use, resolving -1 by whether G4HepEm transports e-, e+ and gamma + int activeIonisationModel(bool useG4HepEm) const { return ionisationModel >= 0 ? ionisationModel : (useG4HepEm ? 1 : 0); } O2ParamDef(TRDSimParams, "TRDSimParams"); }; diff --git a/Detectors/TRD/simulation/src/Detector.cxx b/Detectors/TRD/simulation/src/Detector.cxx index 6760da57f2d52..62df01fd4a082 100644 --- a/Detectors/TRD/simulation/src/Detector.cxx +++ b/Detectors/TRD/simulation/src/Detector.cxx @@ -19,6 +19,7 @@ #include "CommonUtils/ShmAllocator.h" #include "DetectorsBase/MaterialManager.h" +#include "SimConfig/G4Params.h" #include "DetectorsBase/Stack.h" #include "FairVolume.h" #include "FairRootManager.h" @@ -124,15 +125,20 @@ void Detector::InitializeParams() mMaxMCStepDef = TRDSimParams::Instance().maxMCStepSize; const auto& simParams = TRDSimParams::Instance(); - if (simParams.ionisationModel == 1) { + const bool g4HepEm = o2::conf::G4Params::Instance().isG4HepEmActive(); + const int ionisationModel = simParams.activeIonisationModel(g4HepEm); + if (g4HepEm && ionisationModel == 0) { + LOG(warning) << "TRD: energy-deposit charge with G4HepEm, which has no PAI model for e-/e+ in the gas"; + } + if (ionisationModel == 1) { mIonisation = std::make_unique(simParams.gas); // the tables start at minBetaGamma; below it the energy deposit is used mIonMinBetaGamma = std::max(simParams.ionisationMinBetaGamma, IonisationModel::minBetaGamma()); mIonMinEkin = simParams.ionisationMinEkin; LOG(info) << "TRD: ionisation from collision tables, energy deposit below beta*gamma " << mIonMinBetaGamma << " or kinetic energy " << mIonMinEkin << " eV"; - } else if (simParams.ionisationModel != 0) { - LOG(fatal) << "TRD: unknown ionisationModel " << simParams.ionisationModel; + } else if (ionisationModel != 0) { + LOG(fatal) << "TRD: unknown ionisationModel " << ionisationModel; } } diff --git a/Detectors/gconfig/g4Config.C b/Detectors/gconfig/g4Config.C index 40a8fe211de40..431cc779f28c2 100644 --- a/Detectors/gconfig/g4Config.C +++ b/Detectors/gconfig/g4Config.C @@ -87,10 +87,12 @@ R__LOAD_LIBRARY(libgeant4vmc) constexpr const char* kSkipUnknownParticles = "/mcPrimaryGenerator/skipUnknownParticles true"; // whether the TRD charge comes from the Geant4 energy deposit (TRDSimParams.ionisationModel=0), true without TRD -bool trdUsesEnergyDeposit() +bool trdUsesEnergyDeposit(bool useG4HepEm) { try { - return o2::conf::ConfigurableParam::getValueAs("TRDSimParams.ionisationModel") == 0; + const int model = o2::conf::ConfigurableParam::getValueAs("TRDSimParams.ionisationModel"); + // -1 selects the collision tables (1) with G4HepEm and the energy deposit (0) otherwise + return model == 0 || (model < 0 && !useG4HepEm); } catch (...) { return true; } @@ -247,7 +249,7 @@ void Config() geant4->ProcessGeantMacro(configm1.Data()); // PAI in the TRD gas only when the TRD charge comes from the energy deposit - if (trdUsesEnergyDeposit()) { + if (trdUsesEnergyDeposit(g4Params.isG4HepEmActive())) { geant4->ProcessGeantMacro((configm + "/Detectors/gconfig/g4config_trd_pai.in").Data()); } }