Skip to content

Commit 35f4265

Browse files
authored
Compute particle energy is negative value passed to AddTrack (#3711)
* Compute particle energy is negative value passed to AddTrack
1 parent 80e475b commit 35f4265

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Generators/src/PrimaryGenerator.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ void PrimaryGenerator::AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t
128128
vz += fVertex.Z();
129129

130130
/** check if particle to be tracked exists in PDG database **/
131-
if (wanttracking && !TDatabasePDG::Instance()->GetParticle(pdgid)) {
131+
auto particlePDG = TDatabasePDG::Instance()->GetParticle(pdgid);
132+
if (wanttracking && !particlePDG) {
132133
LOG(WARN) << "Particle to be tracked is not defined in PDG: pdg = " << pdgid;
133134
wanttracking = false;
134135
}
@@ -162,6 +163,12 @@ void PrimaryGenerator::AddTrack(Int_t pdgid, Double_t px, Double_t py, Double_t
162163
pdgid = gRandom->Uniform() < 0.5 ? 310 : 130;
163164
}
164165

166+
/** compute particle energy if negative **/
167+
if (e < 0) {
168+
double mass = particlePDG ? particlePDG->Mass() : 0.;
169+
e = std::sqrt(mass * mass + px * px + py * py + pz * pz);
170+
}
171+
165172
/** add track to stack **/
166173
fStack->PushTrack(doTracking, parent, pdgid, px, py, pz,
167174
e, vx, vy, vz, tof, polx, poly, polz, proc, ntr,

0 commit comments

Comments
 (0)