diff --git a/Common/SimConfig/include/SimConfig/G4Params.h b/Common/SimConfig/include/SimConfig/G4Params.h index 216f6f8d71cf2..0d05de1106060 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,9 @@ 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; + /// 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/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/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; } } 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 bbbc2539bfad3..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; } @@ -140,7 +142,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) { @@ -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()); } } 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 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