Skip to content

Commit c993a26

Browse files
committed
Add an event decayer that decays generator particles before transport
This commit provides a class EventDecayer that decays unstable generator particles with Pythia8 before transport and keeps the full decay chain in the MC truth. - It works in place on a std::vector<TParticle>, so that a generator can call it directly. - Only primaries flagged for transport are decayed; the products are appended with their displaced vertices. - Decayed particles keep their generator status and get HepMC status 2. - By default it reads the DecayerPythia8 configs and never decays species above tau0Max (10 mm/c) or listed in skipPdg. - Particles left for transport are checked against O2DatabasePDG and the Geant4 particle table. - The settings come from the new param EventDecayer. https://its.cern.ch/jira/browse/O2-5903 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 50ebfc1 commit c993a26

7 files changed

Lines changed: 1257 additions & 0 deletions

File tree

‎Generators/CMakeLists.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ o2_add_library(Generators
4747
$<$<BOOL:${pythia_FOUND}>:src/DecayerPythia8.cxx>
4848
$<$<BOOL:${pythia_FOUND}>:src/GeneratorPythia8Param.cxx>
4949
$<$<BOOL:${pythia_FOUND}>:src/DecayerPythia8Param.cxx>
50+
$<$<BOOL:${pythia_FOUND}>:src/EventDecayer.cxx>
51+
$<$<BOOL:${pythia_FOUND}>:src/EventDecayerParam.cxx>
5052
$<$<BOOL:${HepMC3_FOUND}>:src/GeneratorHepMC.cxx>
5153
$<$<BOOL:${HepMC3_FOUND}>:src/GeneratorHepMCParam.cxx>
5254
$<$<BOOL:${HepMC3_FOUND}>:src/AODToHepMC.cxx>
@@ -103,6 +105,7 @@ if(pythia_FOUND)
103105
include/Generators/DecayerPythia8.h
104106
include/Generators/GeneratorPythia8Param.h
105107
include/Generators/DecayerPythia8Param.h
108+
include/Generators/EventDecayerParam.h
106109
include/Generators/GeneratorFactory.h)
107110
endif()
108111

@@ -147,6 +150,15 @@ if(doBuildSimulation)
147150
PUBLIC_LINK_LIBRARIES O2::Generators)
148151
endif()
149152

153+
if(pythia_FOUND)
154+
o2_add_test(EventDecayer NAME test_Generator_test_EventDecayer
155+
SOURCES test/test_EventDecayer.cxx
156+
COMPONENT_NAME Generator
157+
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
158+
LABELS generator
159+
PUBLIC_LINK_LIBRARIES O2::Generators)
160+
endif()
161+
150162
# o2_add_test(GeneratorPythia8Param NAME test_Generator_test_GeneratorPythia8Param
151163
# SOURCES test/test_GeneratorPythia8Param.cxx
152164
# COMPONENT_NAME Generator
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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_EVENTGEN_EVENTDECAYER_H_
13+
#define ALICEO2_EVENTGEN_EVENTDECAYER_H_
14+
15+
#include "Pythia8/Pythia.h"
16+
#include <TParticle.h>
17+
#include <map>
18+
#include <string>
19+
#include <unordered_map>
20+
#include <utility>
21+
#include <vector>
22+
23+
namespace o2
24+
{
25+
namespace eventgen
26+
{
27+
28+
/// Counts of what one or more EventDecayer::decay calls did, per PDG code
29+
struct EventDecayerReport {
30+
std::map<int, long> decayed; // particles decayed by Pythia8
31+
std::map<int, long> failed; // particles Pythia8 could not decay
32+
std::map<int, long> unknownInO2; // particles to transport unknown to O2DatabasePDG
33+
std::map<int, long> unknownInG4; // particles to transport unknown to Geant4
34+
std::map<int, std::pair<double, double>> lifetimeMismatch; // pdg -> {pythia ctau mm, g4 ctau mm}
35+
void merge(EventDecayerReport const& other);
36+
void print() const;
37+
};
38+
39+
/// One entry of the Geant4 particle table
40+
struct G4ParticleInfo {
41+
std::string name;
42+
double ctauMM;
43+
bool shortLived;
44+
bool hasDecayTable;
45+
};
46+
47+
/// Reads the Geant4 particle table written by o2-sim-g4-particle-table
48+
std::unordered_map<int, G4ParticleInfo> loadG4ParticleTable(std::string const& path);
49+
50+
/// Decays unstable generator particles with Pythia8 before transport, keeping the full chain
51+
class EventDecayer
52+
{
53+
public:
54+
bool init();
55+
/// Sets the caller's units in cm, s, GeV/c and GeV, as the unit setters of Generator (default cm, s, GeV/c, GeV)
56+
void setUnits(double positionUnit, double timeUnit, double momentumUnit = 1., double energyUnit = 1.)
57+
{
58+
mPositionUnit = positionUnit;
59+
mTimeUnit = timeUnit;
60+
mMomentumUnit = momentumUnit;
61+
mEnergyUnit = energyUnit;
62+
}
63+
EventDecayerReport decay(std::vector<TParticle>& particles);
64+
std::string configSummary() const;
65+
bool vertexLimitsActive() const;
66+
int seed() const { return mSeed; }
67+
68+
private:
69+
bool decayable(int pdg) const;
70+
bool decayOne(std::vector<TParticle>& particles, int index);
71+
void checkParticles(std::vector<TParticle> const& particles, EventDecayerReport& report) const;
72+
void checkLifetimes(EventDecayerReport& report) const;
73+
74+
mutable ::Pythia8::Pythia mPythia; // mutable since Pythia8 settings lookups are not const
75+
std::vector<std::string> mConfigs; // expanded config paths
76+
std::unordered_map<int, G4ParticleInfo> mG4Particles; // Geant4 particle table
77+
bool mHasG4Table = false;
78+
bool mVerbose = false;
79+
double mPositionUnit = 1.; // caller's position unit in cm
80+
double mTimeUnit = 1.; // caller's time unit in s
81+
double mMomentumUnit = 1.; // caller's momentum unit in GeV/c
82+
double mEnergyUnit = 1.; // caller's energy unit in GeV
83+
double mTau0Max = 0.; // tau0 limit in mm/c in use after init, 0 when off
84+
int mSeed = 0; // Pythia8 seed in use after init
85+
};
86+
87+
} // namespace eventgen
88+
} // namespace o2
89+
90+
#endif // ALICEO2_EVENTGEN_EVENTDECAYER_H_
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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_EVENTGEN_EVENTDECAYERPARAM_H_
13+
#define ALICEO2_EVENTGEN_EVENTDECAYERPARAM_H_
14+
15+
#include "CommonUtils/ConfigurableParam.h"
16+
#include "CommonUtils/ConfigurableParamHelper.h"
17+
#include <string>
18+
19+
namespace o2
20+
{
21+
namespace eventgen
22+
{
23+
24+
/// Settings of the EventDecayer, which decays generator particles with Pythia8 before transport
25+
struct EventDecayerParam : public o2::conf::ConfigurableParamHelper<EventDecayerParam> {
26+
std::string config[8] = {"", "", "", "", "", "", "", ""}; // Pythia8 config files, an empty slot takes DecayerPythia8.config
27+
double tau0Max = 10.; // species with a larger tau0 in mm/c stay undecayed (<= 0 switches it off)
28+
std::string skipPdg = "115 225 335 10221 10331 20223 20333 102132 102134 9010221"; // PDG codes never decayed, matched on |pdg|
29+
std::string g4ParticleTable = ""; // Geant4 particle table from o2-sim-g4-particle-table
30+
int seed = 0; // Pythia8 random seed (0 derives it from gRandom)
31+
bool verbose = false; // list every Pythia8 decay
32+
bool showChanged = false; // show changed particle data at init
33+
O2ParamDef(EventDecayerParam, "EventDecayer");
34+
};
35+
36+
} // end namespace eventgen
37+
} // end namespace o2
38+
39+
#endif // ALICEO2_EVENTGEN_EVENTDECAYERPARAM_H_

0 commit comments

Comments
 (0)