Skip to content

Commit 05912e0

Browse files
sawenzelclaude
andcommitted
Keep only known PDG codes as Stack prototypes
A code missing from TDatabasePDG may still be added at run time, e.g. an ion added by geant4_vmc, so it is no longer cached as unknown. https://its.cern.ch/jira/browse/O2-7305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent da49f26 commit 05912e0

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎Detectors/Base/src/Stack.cxx‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "CommonUtils/ConfigurationMacroHelper.h"
2828

2929
#include "TLorentzVector.h" // for TLorentzVector
30-
#include "TDatabasePDG.h" // for TDatabasePDG
3130
#include "TParticle.h" // for TParticle
3231
#include "TRefArray.h" // for TRefArray
3332
#include "TVirtualMC.h" // for VMC
@@ -37,7 +36,6 @@
3736
#include <cassert>
3837
#include <cstddef> // for NULL
3938
#include <cmath>
40-
#include <optional>
4139
#include <unordered_map>
4240
#include "DetectorsBase/SimRandom.h"
4341

@@ -48,24 +46,20 @@ using namespace o2::data;
4846

4947
namespace
5048
{
51-
// a TParticle whose PDG record is looked up once per thread and PDG code, since every TDatabasePDG lookup takes ROOT's global lock
49+
// a TParticle copied from a per-thread prototype per PDG code, avoiding the ROOT-locked PDG lookup
5250
TParticle makeParticle(int pdg, int status, int mother1, int mother2, int daughter1, int daughter2,
5351
double px, double py, double pz, double e, double vx, double vy, double vz, double t)
5452
{
55-
// an empty optional marks a PDG code that is not in TDatabasePDG
56-
thread_local std::unordered_map<int, std::optional<TParticle>> prototypes;
53+
thread_local std::unordered_map<int, TParticle> prototypes;
5754
auto it = prototypes.find(pdg);
5855
if (it == prototypes.end()) {
59-
std::optional<TParticle> proto;
60-
if (TDatabasePDG::Instance()->GetParticle(pdg)) {
61-
proto.emplace(pdg, 0, -1, -1, -1, -1, 0., 0., 0., 0., 0., 0., 0., 0.);
56+
TParticle p(pdg, status, mother1, mother2, daughter1, daughter2, px, py, pz, e, vx, vy, vz, t);
57+
if (p.GetPDG(1)) { // unknown codes may still be added to TDatabasePDG later
58+
prototypes.emplace(pdg, p);
6259
}
63-
it = prototypes.emplace(pdg, std::move(proto)).first;
60+
return p;
6461
}
65-
if (!it->second) { // the mass then comes from the 4-momentum
66-
return TParticle(pdg, status, mother1, mother2, daughter1, daughter2, px, py, pz, e, vx, vy, vz, t);
67-
}
68-
TParticle p(*it->second); // the copy keeps the PDG record and the mass
62+
TParticle p(it->second); // the copy keeps the PDG record and the mass
6963
p.SetStatusCode(status);
7064
p.SetFirstMother(mother1);
7165
p.SetLastMother(mother2);

0 commit comments

Comments
 (0)