Skip to content

Commit 7d85fff

Browse files
sawenzelalcaliva
authored andcommitted
Prevent segfault in GeneratorFromFile
There was a segfault when trying to fetch Mass of a TParticle that does not have an entry in the PDG database. This commit fixes this by avoiding the call to the Mass function. (cherry picked from commit 8dbd237)
1 parent 2a1f4a3 commit 7d85fff

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Generators/src/GeneratorFromFile.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ void GeneratorFromFile::SetStartEvent(int start)
6363

6464
bool GeneratorFromFile::rejectOrFixKinematics(TParticle& p)
6565
{
66+
// avoid compute if the particle is not known in the PDG database
67+
if (!p.GetPDG()) {
68+
LOG(warn) << "Particle with pdg " << p.GetPdgCode() << " not known in DB (not fixing mass)";
69+
// still returning true here ... primary will be flagged as non-trackable by primary event generator
70+
return true;
71+
}
72+
6673
const auto nominalmass = p.GetMass();
6774
auto mom2 = p.Px() * p.Px() + p.Py() * p.Py() + p.Pz() * p.Pz();
6875
auto calculatedmass = p.Energy() * p.Energy() - mom2;

Generators/src/PrimaryGenerator.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void PrimaryGenerator::AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t
140140

141141
// check the status encoding
142142
if (!mcgenstatus::isEncoded(generatorStatus) && proc == TMCProcess::kPPrimary) {
143-
LOG(fatal) << "Generatror status " << generatorStatus << " of particle is not encoded properly.";
143+
LOG(fatal) << "Generator status " << generatorStatus << " of particle is not encoded properly.";
144144
}
145145

146146
/** add event vertex to track vertex **/
@@ -151,7 +151,7 @@ void PrimaryGenerator::AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t
151151
/** check if particle to be tracked exists in PDG database **/
152152
auto particlePDG = TDatabasePDG::Instance()->GetParticle(pdgid);
153153
if (wanttracking && !particlePDG) {
154-
LOG(warn) << "Particle to be tracked is not defined in PDG: pdg = " << pdgid;
154+
LOG(warn) << "Particle to be tracked is not defined in PDG: pdg = " << pdgid << " (disabling tracking)";
155155
wanttracking = false;
156156
}
157157

0 commit comments

Comments
 (0)