Skip to content

Commit cc9dea4

Browse files
author
Ankur Yadav
committed
TPC: add 83mKr calibration generator with Geant4 ionisation-fluctuation support
- TPCDetParam.UseGeant4Edep: use Geant4's own energy deposit for ionisation instead of Bethe-Bloch/NA49, with a configurable SpecialCutsGeV threshold - Adds the Kr-83m decay generator (GeneratorKrDecay) as a compiled Generator subclass in Detectors/TPC/simulation, with a thin krGenerator.C macro for use as an o2-sim external generator - Adds plotCluster.C for viewing the resulting calibration spectrum
1 parent 7f4b3dd commit cc9dea4

10 files changed

Lines changed: 1025 additions & 39 deletions

File tree

Detectors/TPC/base/include/TPCBase/ParameterDetector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ struct ParameterDetector : public o2::conf::ConfigurableParamHelper<ParameterDet
3333
TimeBin TmaxTriggered = 550; ///< Maximum time bin in case of triggered readout mode
3434
float DriftTimeOffset = 7.3; ///< drift time offset in time bins (we observe ~2.4\mus before October 2023 and ~1.45 \mus after)
3535
bool ExcludeFCGap = true; ///< exclude electrons created in the gap between the IFC vessel and OFC vessel and FC strips
36+
bool UseGeant4Edep = false; ///< use Geant4 energy deposit directly for ionisation (for Kr-83m calibration runs)
37+
float SpecialCutsGeV = 1e-6f; ///< CUTELE/CUTGAM/DCUTE/BCUTE applied to TPC drift-gas media by SetSpecialPhysicsCuts() when UseGeant4Edep is set (Kr-83m calibration isolation test); default 1e-6 GeV (1 keV) matches the prior hardcoded value
3638

3739
O2ParamDef(ParameterDetector, "TPCDetParam");
3840
};

Detectors/TPC/simulation/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ o2_add_library(TPCSimulation
1818
src/DigitTime.cxx
1919
src/ElectronTransport.cxx
2020
src/GEMAmplification.cxx
21+
src/GeneratorKrDecay.cxx
2122
src/Point.cxx
2223
src/SAMPAProcessing.cxx
2324
src/IDCSim.cxx
2425
PUBLIC_LINK_LIBRARIES O2::DetectorsBase O2::SimulationDataFormat
2526
O2::TPCBase O2::TPCSpaceCharge O2::TPCSpaceChargeIO O2::TPCCalibration
27+
O2::Generators
2628
ROOT::Physics)
2729

2830
o2_target_root_dictionary(TPCSimulation
@@ -34,6 +36,7 @@ o2_target_root_dictionary(TPCSimulation
3436
include/TPCSimulation/DigitTime.h
3537
include/TPCSimulation/ElectronTransport.h
3638
include/TPCSimulation/GEMAmplification.h
39+
include/TPCSimulation/GeneratorKrDecay.h
3740
include/TPCSimulation/Point.h
3841
include/TPCSimulation/SAMPAProcessing.h
3942
include/TPCSimulation/IDCSim.h)
@@ -54,9 +57,18 @@ if(BUILD_TESTING)
5457
O2::DataFormatsTPC
5558
LABELS tpc)
5659

60+
o2_add_test_root_macro(macro/krGenerator.C
61+
PUBLIC_LINK_LIBRARIES O2::TPCSimulation
62+
LABELS tpc)
63+
5764
o2_add_test_root_macro(macro/toyCluster.C
5865
PUBLIC_LINK_LIBRARIES O2::TPCBase
5966
O2::DataFormatsTPC
6067
LABELS tpc)
6168

69+
o2_add_test_root_macro(macro/plotCluster.C
70+
PUBLIC_LINK_LIBRARIES O2::TPCReconstruction
71+
O2::DataFormatsTPC
72+
LABELS tpc)
73+
6274
endif()

Detectors/TPC/simulation/README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For the digitization as conducted by the [TPC digitizer](include/TPCSimulation/D
1212

1313
* The energy loss of each individual GEANT hit is converted into a number of electrons by dividing by the effective ionization potential W_i. Each of these electrons is in the following treated individually.
1414
* The electron is projected onto the readout plane, taking into account diffusion, i.e. smearing its position by a 3D gaussian function ([ElectronTransport](include/TPCSimulation/ElectronTransport.h)). Then, the position is transformed into the local coordinate system of the Readout Chamber (ROC).
15-
* Having arrived at the amplification stage, the electrons undergo amplification in the GEM stack ([GEMAmplification](include/TPCSimulation/GEMAmplification.h)), taking into account fluctuations of the gain. These fluctuations follow a Polya distribution. For performance considerations, two different versions of the amplification are available (one effective single-stage amplification and a successive simulation of the collection, amplification, and extraction processes in the individual GEMs.
15+
* Having arrived at the amplification stage, the electrons undergo amplification in the GEM stack ([GEMAmplification](include/TPCSimulation/GEMAmplification.h)), taking into account fluctuations of the gain. These fluctuations follow a Polya distribution. For performance considerations, two different versions of the amplification are available (one effective single-stage amplification and a successive simulation of the collection, amplification, and extraction processes in the individual GEMs).
1616
* Capacitive coupling of the amplification structure to the readout anode leads to another contribution to the signal, the so-called Common Mode effect. Since the bottom electrode of GEM 4 is unsegmented, capacitive coupling occurs within a full ROC ([CommonMode](include/TPCSimulation/CommonMode.h))
1717
* The charge signal is then folded with the transfer function of the front-end cards ([SAMPAProcessing](include/TPCSimulation/SAMPAProcessing.h)) and written to the intermediate storage container structure ([DigitContainer](include/TPCSimulation/DigitContainer.h)/[DigitTime](include/TPCSimulation/DigitTime.h)/[DigitGlobalPad](include/TPCSimulation/DigitGlobalPad.h)), which is described below.
1818

@@ -24,7 +24,7 @@ The digitization is conducted for each TPC sector individually in order to ensur
2424
The input can be created by running the simulation `o2-sim`, which produces the file `o2sim.root` with the hits stored in separated branches for all sectors.
2525
It should be noted that due to diffusion and the space-charge distortions, charge leakage between sectors can occur. In order to avoid the unnecessary processing of individual hits, several measures are taken
2626

27-
* for a given sector the hits within an additional safety margin of +/- 10 degree are processed. For this reason, For this reason, the hits are not stored for a given sector, but shifted by 10 degrees. Hence only two branches need to be loaded for the digitization of a given sector.
27+
* for a given sector the hits within an additional safety margin of +/- 10 degree are processed. For this reason, the hits are not stored for a given sector, but shifted by 10 degrees. Hence only two branches need to be loaded for the digitization of a given sector.
2828
* Individual hits are only processed when they are within the processed by 3 sigma of the expected width from diffusion
2929

3030
Hits passing that requirement are further processed by the [TPC digitizer](include/TPCSimulation/Digitizer.h) and undergo the above described physics processes.
@@ -36,7 +36,48 @@ The [DigitContainer](include/TPCSimulation/DigitContainer.h) is a circular buffe
3636
The [DigitTime](include/TPCSimulation/DigitTime.h) is then a flat contained of [DigitGlobalPad](include/TPCSimulation/DigitGlobalPad.h), where the latter correspond to one pad on the pad plane. Accordingly, the buffering of the actual ADC values is conducted using this object.
3737
Similarly, the MC labels are passed throughout the chain, and finally sorted by the number of occurrences, i.e. the track with the largest contribution to the digit is mentioned first etc.
3838

39-
Correlations among digits from different events can only occur within the integration time of the detector (plus additional 50% contigiency), and therefore the digits are written to disk when the processed event is more than 750 time bins after. This means, that saturation effects are applied to the ADC values stored in the [DigitGlobalPad](include/TPCSimulation/DigitGlobalPad.h) and the relevant information is transformed in a [Digit](../../../DataFormats/Detectors/TPC/include/DataFormatsTPC/Digit.h) which is written to disk.
39+
Correlations among digits from different events can only occur within the integration time of the detector (plus additional 50% contingency), and therefore the digits are written to disk when the processed event is more than 750 time bins after. This means, that saturation effects are applied to the ADC values stored in the [DigitGlobalPad](include/TPCSimulation/DigitGlobalPad.h) and the relevant information is transformed in a [Digit](../../../DataFormats/Detectors/TPC/include/DataFormatsTPC/Digit.h) which is written to disk.
4040

4141
### Output data
42-
The digitizer workflow produces the file `tpcdigits.root` by default, data is stored in separated branches for all sectors.
42+
The digitizer workflow produces the file `tpcdigits.root` by default, data is stored in separated branches for all sectors.
43+
44+
# 83mKr calibration generator
45+
46+
[GeneratorKrDecay](include/TPCSimulation/GeneratorKrDecay.h) is a `Generator` producing
47+
83mKr decay vertices uniformly distributed in the TPC drift volume, for gain-map and
48+
energy-resolution calibration simulation with `o2-sim`.
49+
50+
Kr-83m decays via two sequential internal transitions. For each generated vertex, one of
51+
eight decay channels (combinations of the two transitions' internal-conversion/gamma
52+
modes) is sampled according to branching fractions derived from the transition energies
53+
and internal conversion coefficients (ICC), then the corresponding conversion
54+
electrons/Auger electrons/fluorescence photons ([KrDecayTable](include/TPCSimulation/GeneratorKrDecay.h))
55+
are emitted as primary tracks.
56+
57+
Transition energies and ICC values are read at runtime from the installed Geant4
58+
photon-evaporation data file, `$G4LEVELGAMMADATA/z36.a83` (the environment variable is
59+
set automatically by Geant4's own setup, inherited by any O2 session). If the variable
60+
is unset or the file cannot be parsed, hardcoded fallback values from
61+
`PhotonEvaporation5.7/z36.a83` are used instead and a warning is printed.
62+
63+
The number of decays generated per event defaults to 1000 and can be overridden via the
64+
`KR_N_PER_EVENT` environment variable.
65+
66+
## Usage
67+
68+
`GeneratorKrDecay` is used as an `o2-sim` external generator, via the thin macro
69+
[macro/krGenerator.C](macro/krGenerator.C). `fileName` must resolve to that macro; `$O2path`
70+
below is the path to your O2 source checkout:
71+
72+
```shell
73+
export KR_N_PER_EVENT=5000 # decays per event; defaults to 1000 if unset
74+
o2-sim -g external -m TPC -n 100 \
75+
--configKeyValues "GeneratorExternal.fileName=$O2path/Detectors/TPC/simulation/macro/krGenerator.C;GeneratorExternal.funcName=krGenerator();TPCDetParam.UseGeant4Edep=1"
76+
```
77+
78+
To change Geant4-related parameters (e.g. `StepFunction`, fluorescence, Auger cascade),
79+
add `G4.configMacroFile=<path to a Geant4 UI macro>` to `--configKeyValues`.
80+
81+
`TPCDetParam.UseGeant4Edep=1` is required: it switches `Detector::ProcessHits()` to use Geant4's
82+
own energy deposit directly instead of the default Bethe-Bloch/NA49 sampling, which is what
83+
correctly resolves the Kr-83m decay channels into their discrete energy peaks.

Detectors/TPC/simulation/include/TPCSimulation/Detector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class Detector : public o2::base::DetImpl<Detector>
146146
void PostTrack() override { ; }
147147
void PreTrack() override { ; }
148148

149+
void SetSpecialPhysicsCuts() override;
150+
149151
void SetGeoFileName(const TString file) { mGeoFileName = file; }
150152
const TString& GetGeoFileName() const { return mGeoFileName; }
151153

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
/// \file GeneratorKrDecay.h
13+
/// \brief Generator for 83mKr decays, for TPC gain-map calibration simulation
14+
/// \author Ankur Yadav <ankur.yadav@cern.ch>
15+
16+
#ifndef ALICEO2_TPC_GeneratorKrDecay_H_
17+
#define ALICEO2_TPC_GeneratorKrDecay_H_
18+
19+
#include "Generators/Generator.h"
20+
#include <array>
21+
#include <vector>
22+
23+
namespace o2
24+
{
25+
namespace tpc
26+
{
27+
28+
// O2 status encoding from MCGenProperties.h
29+
// bits 0-8: hepmc(9), bits 9-18: gen(10), bits 19-28: reserved(10), bits 29-31: sentinel=5
30+
inline int krO2EncodedStatus(int hepmc, int gen = 0)
31+
{
32+
return (5 << 29) | ((gen & 0x3FF) << 9) | (hepmc & 0x1FF);
33+
}
34+
35+
namespace KrGenConfig
36+
{
37+
inline double rInner = 83.5;
38+
inline double rOuter = 246.5; // TPC outermost pad row outer edge ~247 cm; stay inside
39+
inline double halfZ = 249.7;
40+
inline int nPerEvent = 1000; // override at runtime via KR_N_PER_EVENT env var
41+
} // namespace KrGenConfig
42+
43+
struct KrProduct {
44+
int pdg;
45+
double eKin;
46+
};
47+
48+
/// Table of 83mKr internal-conversion/gamma decay channels and their
49+
/// branching fractions, derived at runtime from Geant4's level/gamma data
50+
/// (falls back to hardcoded PhotonEvaporation5.7/z36.a83 values if
51+
/// unavailable). Used by GeneratorKrDecay to sample one decay channel per
52+
/// generated vertex.
53+
class KrDecayTable
54+
{
55+
public:
56+
struct Channel {
57+
double fraction;
58+
int nProducts;
59+
KrProduct products[6]; // max 5 used; 6 for safety
60+
};
61+
// Eight physically motivated channels (T1 mode x T2 mode):
62+
// T1: ICC_total=2035 -> 99.951% IC (75.163% outer-shell, 24.788% K-shell), 0.049% gamma
63+
// K-shell: 65.2% K-fluorescence (Kalpha), 34.8% K-Auger
64+
// T2: ICC_total=17.09 -> 94.472% IC, 5.528% gamma
65+
// Source: G4 PhotonEvaporation5.7/z36.a83, RadioactiveDecay5.6/z36.a83
66+
static const int kNChannels = 8;
67+
Channel channels[kNChannels];
68+
double cumulative[kNChannels];
69+
KrDecayTable();
70+
const Channel& sample() const;
71+
};
72+
73+
} // namespace tpc
74+
} // namespace o2
75+
76+
namespace o2
77+
{
78+
namespace eventgen
79+
{
80+
81+
/// FairGenerator producing 83mKr decay vertices uniformly distributed in the
82+
/// TPC drift volume, for gain-map/energy-resolution calibration simulation.
83+
/// Each vertex emits the conversion electrons/photons of one randomly
84+
/// sampled o2::tpc::KrDecayTable::Channel.
85+
class GeneratorKrDecay : public Generator
86+
{
87+
public:
88+
GeneratorKrDecay();
89+
~GeneratorKrDecay() override;
90+
Bool_t Init() override;
91+
Bool_t generateEvent() override;
92+
Bool_t importParticles() override;
93+
94+
private:
95+
o2::tpc::KrDecayTable* mTable;
96+
std::vector<std::array<double, 3>> mVertices;
97+
// No ClassDefOverride: the base Generator class's dictionary is sufficient
98+
// for a runtime-only generator that is never streamed via ROOT I/O
99+
// (matches o2::eventgen::GeneratorGeantinos and other Generator subclasses).
100+
};
101+
102+
} // namespace eventgen
103+
} // namespace o2
104+
105+
#endif // ALICEO2_TPC_GeneratorKrDecay_H_
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
/// \file krGenerator
13+
/// \brief This macro instantiates the compiled 83mKr TPC calibration
14+
/// generator (o2::eventgen::GeneratorKrDecay), for use with
15+
/// o2-sim -g external --extGenFile krGenerator.C --extGenFunc krGenerator
16+
/// \author Ankur Yadav <ankur.yadav@cern.ch>
17+
18+
#if !defined(__CLING__) || defined(__ROOTCLING__)
19+
#include "FairGenerator.h"
20+
#include "TPCSimulation/GeneratorKrDecay.h"
21+
#endif
22+
23+
FairGenerator* krGenerator()
24+
{
25+
auto gen = new o2::eventgen::GeneratorKrDecay();
26+
return gen;
27+
}

0 commit comments

Comments
 (0)