Skip to content

Commit ad31f64

Browse files
sawenzelclaude
andcommitted
Add a TRD ionisation model independent of the Geant4 energy loss
This adds a collision model for the ionisation in the TRD gas, selected with TRDSimParams.ionisationModel, and a unit test. - With ionisationModel=0, the default, the charge of a hit stays the Geant4 energy deposit divided by Wion. - With ionisationModel=1 the charge comes from a Poisson number of collisions along the step, from the step length, beta*gamma before the step and the charge squared. - The collision rate and energy spectrum below the 10 keV delta-ray cut are tabulated from the Geant4 PAI cross-section for Xe/CO2 and Ar/CO2, with macros/makeIonisationTables.cxx. - Tracks below beta*gamma 0.04 or 30 keV kinetic energy keep the energy deposit, including the step that stops a track. - The run stops if the delta-ray cut of the gas differs from the one of the tables. - Hit class and hit creation points are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4b99887 commit ad31f64

9 files changed

Lines changed: 597 additions & 4 deletions

File tree

‎Detectors/TRD/simulation/CMakeLists.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
o2_add_library(TRDSimulation
1313
TARGETVARNAME targetName
1414
SOURCES src/Detector.cxx
15+
src/IonisationModel.cxx
1516
src/TRsim.cxx
1617
src/DiffAndTimeStructEstimator.cxx
1718
src/Digitizer.cxx
@@ -66,6 +67,12 @@ o2_add_test(PileupTool
6667
ENVIRONMENT VMCWORKDIR=${CMAKE_BINARY_DIR}/stage
6768
LABELS trd)
6869

70+
o2_add_test(IonisationModel
71+
SOURCES test/testTRDIonisationModel.cxx
72+
COMPONENT_NAME trd
73+
PUBLIC_LINK_LIBRARIES O2::TRDSimulation
74+
LABELS trd)
75+
6976
o2_add_test(DiffusionCoefficient
7077
SOURCES test/testTRDDiffusionCoefficient.cxx
7178
COMPONENT_NAME trd

‎Detectors/TRD/simulation/data/simcuts.dat‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
* Med GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA ANNI BREM COMP DCAY DRAY HADR LOSS MULS PAIR PHOT RAYL STRA
55
* Mylar
66
TRD 27 1e-5 1e-5 1e-3 1e-3 1e-5 1e-5 1e-5 1e-5 1e-5 -1. 1 1 1 1 1 1 3 1 1 1 1 0
7-
* Gas mixture
7+
* Gas mixture; its DCUTE must stay the delta-ray cut of the TRD ionisation tables (IonisationModel)
88
TRD 9 1e-5 1e-5 1e-3 1e-3 1e-5 1e-5 1e-5 1e-5 1e-5 -1. 1 1 1 1 1 1 3 1 1 1 1 1
99
*

‎Detectors/TRD/simulation/include/TRDSimulation/Detector.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#ifndef ALICEO2_TRD_DETECTOR_H_
1313
#define ALICEO2_TRD_DETECTOR_H_
1414

15+
#include <memory>
1516
#include <vector>
1617
#include "DetectorsBase/Detector.h"
1718
#include "SimulationDataFormat/BaseHits.h"
1819
#include "CommonUtils/ShmAllocator.h"
1920

2021
#include "DataFormatsTRD/Hit.h"
22+
#include "TRDSimulation/IonisationModel.h"
2123

2224
class FairVolume;
2325

@@ -90,6 +92,17 @@ class Detector : public o2::base::DetImpl<Detector>
9092

9193
float mWion; // Ionization potential
9294

95+
// Energy (eV) from which the charge of the current step is made
96+
double ionisationEnergy(float edep) const;
97+
98+
// Checks once that the gas has the delta-ray cut of the collision tables
99+
void checkDeltaRayCut();
100+
bool mDeltaRayCutChecked = false; //!
101+
102+
std::unique_ptr<IonisationModel> mIonisation; //! collision model in the gas, null when the energy deposit is used
103+
double mIonMinBetaGamma = 0.; //!
104+
double mIonMinEkin = 0.; //! eV
105+
93106
Geometry* mGeom = nullptr;
94107

95108
// Volume-id lookup tables, resolved once at initialisation so that ProcessHits does
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef ALICEO2_TRD_IONISATIONMODEL_H_
13+
#define ALICEO2_TRD_IONISATIONMODEL_H_
14+
15+
#include "TRDSimulation/SimParam.h"
16+
17+
class TRandom;
18+
19+
namespace o2
20+
{
21+
namespace trd
22+
{
23+
24+
/// Primary ionisation in the TRD gas from tabulated collision spectra, independent of the transport engine's
25+
/// energy-loss model. The tables hold the number of collisions per cm with an energy transfer below the delta-ray
26+
/// production cut of the gas (10 keV) and their energy distribution, as functions of beta*gamma, taken from
27+
/// Geant4's photo-absorption ionisation (PAI) cross-section for the Xe/CO2 and Ar/CO2 mixtures.
28+
class IonisationModel
29+
{
30+
public:
31+
explicit IonisationModel(SimParam::GasMixture gas);
32+
33+
/// Energy (eV) lost in collisions along a step of length (cm) at beta*gamma, for a particle of charge squared z2
34+
double stepEnergy(double length, double betaGamma, double z2, TRandom& rnd) const;
35+
36+
/// Mean number of collisions per cm for unit charge
37+
double collisionsPerCm(double betaGamma) const;
38+
39+
/// Mean energy loss (eV/cm) below the delta-ray cut for unit charge, from the tables
40+
double restrictedDEdx(double betaGamma) const;
41+
42+
/// Lowest beta*gamma of the tables
43+
static double minBetaGamma();
44+
45+
/// Delta-ray production cut (eV) the tables were made for
46+
static double deltaRayCut();
47+
48+
private:
49+
double sampleCollision(int row, double u) const;
50+
51+
int mNEnergy = 0;
52+
const double* mEnergy = nullptr; ///< energy grid (eV)
53+
const double* mCollisions = nullptr; ///< collisions per cm, per beta*gamma row
54+
const double* mDEdx = nullptr; ///< restricted dE/dx (eV/cm), per beta*gamma row
55+
const float* mFractionAbove = nullptr; ///< fraction of collisions above each grid energy, per row
56+
};
57+
58+
} // namespace trd
59+
} // namespace o2
60+
61+
#endif

‎Detectors/TRD/simulation/include/TRDSimulation/TRDSimParams.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct TRDSimParams : public o2::conf::ConfigurableParamHelper<TRDSimParams> {
3737
float maxMCStepSize = 0.1; ///< maximum size of MC steps
3838
bool doTR = true; ///< switch for transition radiation
3939
SimParam::GasMixture gas = SimParam::GasMixture::Xenon; ///< the gas mixture in the TRD
40+
// ionisation in the gas
41+
int ionisationModel = 0; ///< charge from 0: Geant4 energy deposit with PAI, 1: TRD collision tables, no PAI
42+
float ionisationMinBetaGamma = 0.04; ///< below this beta*gamma the charge comes from the energy deposit
43+
float ionisationMinEkin = 30e3; ///< (eV) below this kinetic energy the charge comes from the energy deposit
4044
// TRF parameters
4145
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)
4246
float trf_landau_mu = 0.; // Mu of the Landau distribution used to describe TRF
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
// Writes the TRD gas collision tables (C++) from Geant4's PAI cross-section: number of collisions per cm with an
13+
// energy transfer below the delta-ray cut, restricted dE/dx, and N(>E)/N on a log energy grid, per beta*gamma.
14+
// Standalone program, not built with O2. Build: g++ -O2 $(geant4-config --cflags) makeIonisationTables.cxx -o makeIonisationTables $(geant4-config --libs)
15+
#include "G4Element.hh"
16+
#include "G4Material.hh"
17+
#include "G4PAIxSection.hh"
18+
#include "G4SandiaTable.hh"
19+
#include "G4SystemOfUnits.hh"
20+
#include "G4Version.hh"
21+
#include <cmath>
22+
#include <cstdio>
23+
#include <string>
24+
#include <vector>
25+
26+
constexpr int kNBetaGamma = 31;
27+
constexpr double kLogBetaGammaMin = -1.4;
28+
constexpr double kLogBetaGammaStep = 0.2;
29+
30+
struct Gas {
31+
std::string name;
32+
double z, a, nNoble, nC, nO, fNoble, dNoble;
33+
};
34+
35+
static void table(const Gas& gas, double cut)
36+
{
37+
const double dco = 0.00186; // CO2 at 20 C, as in Detector::createMaterials
38+
const double dens = (gas.fNoble * gas.dNoble + (1. - gas.fNoble) * dco) * g / cm3;
39+
auto* el = new G4Element(gas.name, gas.name, gas.z, gas.a * g / mole);
40+
auto* c = new G4Element("C_" + gas.name, "C", 6., 12.0107 * g / mole);
41+
auto* o = new G4Element("O_" + gas.name, "O", 8., 15.9994 * g / mole);
42+
const double w[3] = {gas.nNoble * gas.a, gas.nC * 12.0107, gas.nO * 15.9994};
43+
const double ws = w[0] + w[1] + w[2];
44+
auto* mat = new G4Material("TRD_" + gas.name + "CO2", dens, 3, kStateGas, 293.15 * kelvin);
45+
mat->AddElement(el, w[0] / ws);
46+
mat->AddElement(c, w[1] / ws);
47+
mat->AddElement(o, w[2] / ws);
48+
49+
std::vector<double> lbgs;
50+
for (int k = 0; k < kNBetaGamma; ++k) {
51+
lbgs.push_back(kLogBetaGammaMin + kLogBetaGammaStep * k);
52+
}
53+
std::vector<double> egrid;
54+
std::vector<std::vector<double>> ccdf;
55+
std::vector<double> nsub, dedx;
56+
for (double lbg : lbgs) {
57+
const double bg = std::pow(10., lbg);
58+
G4SandiaTable sandia;
59+
sandia.Initialize(mat);
60+
G4PAIxSection xs;
61+
xs.Initialize(mat, 1. * MeV, bg * bg, &sandia);
62+
const int n = xs.GetSplineSize();
63+
std::vector<double> en(n), in(n), de(n);
64+
for (int i = 1; i <= n; ++i) {
65+
en[i - 1] = xs.GetSplineEnergy(i);
66+
in[i - 1] = xs.GetIntegralPAIxSection(i);
67+
de[i - 1] = xs.GetIntegralPAIdEdx(i);
68+
}
69+
auto interp = [&](const std::vector<double>& v, double e) {
70+
if (e <= en.front()) {
71+
return v.front();
72+
}
73+
for (int i = 1; i < n; ++i) {
74+
if (en[i] >= e) {
75+
const double t = std::log(e / en[i - 1]) / std::log(en[i] / en[i - 1]);
76+
return v[i - 1] + t * (v[i] - v[i - 1]);
77+
}
78+
}
79+
return v.back();
80+
};
81+
if (egrid.empty()) {
82+
egrid.push_back(en[0] / eV);
83+
for (int j = 0; j <= 30; ++j) {
84+
const double e = std::pow(10., 1. + 0.1 * j);
85+
if (e > en[0] / eV * 1.001) {
86+
egrid.push_back(e);
87+
}
88+
}
89+
}
90+
const double ns = (in[0] - interp(in, cut)) * 10.; // per cm
91+
nsub.push_back(ns);
92+
dedx.push_back((de[0] - interp(de, cut)) * 10. / eV);
93+
std::vector<double> row;
94+
for (double e : egrid) {
95+
row.push_back(std::max((interp(in, e * eV) - interp(in, cut)) * 10. / ns, 0.));
96+
}
97+
row.front() = 1.;
98+
row.back() = 0.;
99+
ccdf.push_back(row);
100+
}
101+
std::printf("// %s/CO2: density %.6g g/cm3, mean excitation energy %.4g eV\n", gas.name.c_str(), dens / (g / cm3),
102+
mat->GetIonisation()->GetMeanExcitationEnergy() / eV);
103+
std::printf("constexpr double k%sEnergy[%zu] = {", gas.name.c_str(), egrid.size());
104+
for (size_t j = 0; j < egrid.size(); ++j) {
105+
std::printf("%s%.5g", j ? ", " : "", egrid[j]);
106+
}
107+
std::printf("};\nconstexpr double k%sCollisionsPerCm[%zu] = {", gas.name.c_str(), nsub.size());
108+
for (size_t k = 0; k < nsub.size(); ++k) {
109+
std::printf("%s%.6g", k ? ", " : "", nsub[k]);
110+
}
111+
std::printf("};\nconstexpr double k%sRestrictedDEdx[%zu] = {", gas.name.c_str(), dedx.size());
112+
for (size_t k = 0; k < dedx.size(); ++k) {
113+
std::printf("%s%.6g", k ? ", " : "", dedx[k]);
114+
}
115+
std::printf("};\nconstexpr float k%sFractionAbove[%zu][%zu] = {\n", gas.name.c_str(), ccdf.size(), egrid.size());
116+
for (auto& row : ccdf) {
117+
std::printf(" {");
118+
for (size_t j = 0; j < row.size(); ++j) {
119+
std::printf("%s%.5g", j ? ", " : "", row[j]);
120+
}
121+
std::printf("},\n");
122+
}
123+
std::printf("};\n");
124+
}
125+
126+
int main()
127+
{
128+
const double cut = 10. * keV;
129+
std::printf("// Generated with Geant4 %d G4PAIxSection, delta-ray cut %.4g keV\n", G4VERSION_NUMBER, cut / keV);
130+
std::printf("constexpr double kDeltaRayCut = %.6g; // eV\n", cut / eV);
131+
std::printf("constexpr int kNBetaGamma = %d;\n", kNBetaGamma);
132+
std::printf("constexpr double kLogBetaGammaMin = %.6g; // beta*gamma of row k is 10^(min + k * step)\n", kLogBetaGammaMin);
133+
std::printf("constexpr double kLogBetaGammaStep = %.6g;\n", kLogBetaGammaStep);
134+
table({"Xe", 54., 131.29, 8.5, 1.5, 3.0, 0.85, 0.00549}, cut);
135+
table({"Ar", 18., 39.948, 8.2, 1.8, 3.6, 0.82, 0.00166}, cut);
136+
return 0;
137+
}

‎Detectors/TRD/simulation/src/Detector.cxx‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#include "DataFormatsTRD/Hit.h"
1919

2020
#include "CommonUtils/ShmAllocator.h"
21+
#include "DetectorsBase/MaterialManager.h"
2122
#include "DetectorsBase/Stack.h"
2223
#include "FairVolume.h"
2324
#include "FairRootManager.h"
2425

2526
#include <TGeoManager.h>
2627
#include <TVirtualMC.h>
2728

29+
#include <cmath>
2830
#include <cstdio>
2931
#include <vector>
3032
#include <stdexcept>
@@ -120,6 +122,56 @@ void Detector::InitializeParams()
120122
}
121123
mTR = new TRsim();
122124
mMaxMCStepDef = TRDSimParams::Instance().maxMCStepSize;
125+
126+
const auto& simParams = TRDSimParams::Instance();
127+
if (simParams.ionisationModel == 1) {
128+
mIonisation = std::make_unique<IonisationModel>(simParams.gas);
129+
// the tables start at minBetaGamma; below it the energy deposit is used
130+
mIonMinBetaGamma = std::max<double>(simParams.ionisationMinBetaGamma, IonisationModel::minBetaGamma());
131+
mIonMinEkin = simParams.ionisationMinEkin;
132+
LOG(info) << "TRD: ionisation from collision tables, energy deposit below beta*gamma " << mIonMinBetaGamma
133+
<< " or kinetic energy " << mIonMinEkin << " eV";
134+
} else if (simParams.ionisationModel != 0) {
135+
LOG(fatal) << "TRD: unknown ionisationModel " << simParams.ionisationModel;
136+
}
137+
}
138+
139+
void Detector::checkDeltaRayCut()
140+
{
141+
// The collision tables end at the delta-ray cut they were made for. Above it Geant4 makes delta electrons
142+
// with their own hits, so a different cut in the gas (medium 9, Gas-mix) would double count or lose energy.
143+
auto& mgr = o2::base::MaterialManager::Instance();
144+
std::vector<std::pair<o2::base::ECut, Float_t>> cuts;
145+
mgr.getSpecialCuts(GetName(), 9, cuts);
146+
double dcute = -1.; // eV
147+
for (const auto& [cut, value] : cuts) {
148+
if (cut == o2::base::ECut::kDCUTE) {
149+
dcute = value * 1e9;
150+
}
151+
}
152+
const double tableCut = IonisationModel::deltaRayCut();
153+
if (!mgr.specialCutsEnabled() || std::abs(dcute - tableCut) > 1e-3 * tableCut) {
154+
LOG(fatal) << "TRD: the ionisation tables need DCUTE = " << tableCut << " eV in the gas, the medium has "
155+
<< (mgr.specialCutsEnabled() ? dcute : -1.) << " eV; use TRDSimParams.ionisationModel=0 with other cuts";
156+
}
157+
mDeltaRayCutChecked = true;
158+
}
159+
160+
double Detector::ionisationEnergy(float edep) const
161+
{
162+
double px, py, pz, etot;
163+
fMC->TrackMomentum(px, py, pz, etot);
164+
const double mass = fMC->TrackMass();
165+
const double epre = etot + fMC->Edep(); // total energy before the step
166+
const double ekin = (epre - mass) * 1e9;
167+
const double betaGamma = std::sqrt(std::max(epre * epre - mass * mass, 0.)) / mass;
168+
// slow tracks, including the step that stops a track, keep the energy deposit
169+
if (betaGamma < mIonMinBetaGamma || ekin < mIonMinEkin) {
170+
return edep;
171+
}
172+
// bare charge, no effective charge: an ion is close to bare for beta >> Z/137, for alphas above the beta*gamma cut
173+
const double z = fMC->TrackCharge();
174+
return std::min(mIonisation->stepEnergy(fMC->TrackStep(), betaGamma, z * z, *o2::base::simRandom()), ekin);
123175
}
124176

125177
bool Detector::ProcessHits(FairVolume* v)
@@ -221,10 +273,14 @@ bool Detector::ProcessHits(FairVolume* v)
221273
trkStat = 2;
222274
}
223275

224-
// Calculate the charge according to GEANT Edep
276+
// Calculate the charge from the collision model, or from the transport engine's energy deposit
225277
// Create a new dEdx hit
226-
const float enDep = std::max(fMC->Edep(), 0.0) * 1e9; // Energy in eV
227-
const int totalChargeDep = (int)(enDep / mWion); // Total charge
278+
const float edep = std::max(fMC->Edep(), 0.0) * 1e9; // Energy in eV
279+
if (mIonisation && !mDeltaRayCutChecked) {
280+
checkDeltaRayCut();
281+
}
282+
const float enDep = mIonisation ? ionisationEnergy(edep) : edep;
283+
const int totalChargeDep = (int)(enDep / mWion); // Total charge
228284

229285
// Store those hits with enDep bigger than the ionization potential of the gas mixture for in-flight tracks
230286
// or store hits of tracks that are entering or exiting

0 commit comments

Comments
 (0)