Skip to content
Open
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
5 changes: 4 additions & 1 deletion Common/SimConfig/include/SimConfig/G4Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct G4Params : public o2::conf::ConfigurableParamHelper<G4Params> {

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)

Expand All @@ -76,7 +77,9 @@ struct G4Params : public o2::conf::ConfigurableParamHelper<G4Params> {
// 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;
Expand Down
11 changes: 7 additions & 4 deletions Common/SimConfig/src/G4Params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Detectors/EMCAL/base/src/Geometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Detectors/TRD/simulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ struct TRDSimParams : public o2::conf::ConfigurableParamHelper<TRDSimParams> {
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
int trf = 1; // Sampled TRF function. 0: default TRF, 1: TRF described in TRF TDR, 2: No TRF, 3: Landau dist as TRF (parameters specified below)
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");
};

Expand Down
12 changes: 9 additions & 3 deletions Detectors/TRD/simulation/src/Detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<IonisationModel>(simParams.gas);
// the tables start at minBetaGamma; below it the energy deposit is used
mIonMinBetaGamma = std::max<double>(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;
}
}

Expand Down
10 changes: 6 additions & 4 deletions Detectors/gconfig/g4Config.C
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>("TRDSimParams.ionisationModel") == 0;
const int model = o2::conf::ConfigurableParam::getValueAs<int>("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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
}
Expand Down
5 changes: 5 additions & 0 deletions dependencies/FindGeant4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run/g4DetermineUnknownPdgProperties.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run/o2sim_g4_particle_table.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading