@@ -103,6 +103,7 @@ Stack::Stack(Int_t size)
103103 if (!mTransportPrimary ) {
104104 LOG (FATAL) << " Failed to retrieve external \' transportPrimary\' function: problem with configuration " ;
105105 }
106+ LOG (INFO) << " Successfully retrieve external \' transportPrimary\' frunction: " << param.transportPrimaryFileName ;
106107 } else {
107108 LOG (FATAL) << " unsupported \' trasportPrimary\' mode: " << param.transportPrimary ;
108109 }
@@ -183,12 +184,13 @@ void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px
183184 Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
184185 TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId)
185186{
186- PushTrack (toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, secondparentId, -1 , -1 );
187+ PushTrack (toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, secondparentId, -1 , -1 , proc );
187188}
188189
189190void Stack::PushTrack (Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e,
190191 Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz,
191- TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId, Int_t daughter1Id, Int_t daughter2Id)
192+ TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is, Int_t secondparentId, Int_t daughter1Id, Int_t daughter2Id,
193+ TMCProcess proc2)
192194{
193195 // printf("Pushing %s toBeDone %5d parentId %5d pdgCode %5d is %5d entries %5d \n",
194196 // proc == kPPrimary ? "Primary: " : "Secondary: ",
@@ -214,36 +216,38 @@ void Stack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px
214216 p.SetPolarisation (polx, poly, polz);
215217 p.SetWeight (weight);
216218 p.SetUniqueID (proc); // using the unique ID to transfer process ID
219+ p.SetBit (ParticleStatus::kPrimary , proc == kPPrimary ? 1 : 0 ); // set primary bit
220+ p.SetBit (ParticleStatus::kToBeDone , toBeDone == 1 ? 1 : 0 ); // set to be done bit
217221 mNumberOfEntriesInParticles ++;
218222
219223 insertInVector (mTrackIDtoParticlesEntry , trackId, (int )(mParticles .size ()));
220224
225+ handleTransportPrimary (p); // handle selective transport of primary particles
226+
221227 // Push particle on the stack if toBeDone is set
222- if (proc == kPPrimary ) {
228+ if (p. TestBit (ParticleStatus:: kPrimary ) ) {
223229 // This is a particle from the primary particle generator
224230 //
225231 // SetBit is used to pass information about the primary particle to the stack during transport.
226232 // Sime particles have already decayed or are partons from a shower. They are needed for the
227233 // event history in the stack, but not for transport.
228234 //
235+
236+ // primary particles might have been pushed with a second creation process
237+ // in case we pushed a secondary track of a previous simulation to be continued.
238+ // We save therefore in the UniqueID the correct process
239+ // while the particle will still be treated as a primary given its bit settings
240+ p.SetUniqueID (proc2);
241+
229242 mIndexMap [trackId] = trackId;
230- p.SetBit (ParticleStatus::kKeep );
231- p.SetBit (ParticleStatus::kPrimary );
232- if (toBeDone == 1 ) {
233- handleTransportPrimary (p);
234- } else {
235- p.SetBit (ParticleStatus::kToBeDone , 0 );
243+ p.SetBit (ParticleStatus::kKeep , 1 );
244+ if (p.TestBit (ParticleStatus::kToBeDone )) {
245+ mNumberOfPrimariesforTracking ++;
236246 }
237247 mNumberOfPrimaryParticles ++;
238248 mPrimaryParticles .push_back (p);
239249 mTracks ->emplace_back (p);
240250 } else {
241- p.SetBit (ParticleStatus::kPrimary , 0 );
242- if (toBeDone == 1 ) {
243- p.SetBit (ParticleStatus::kToBeDone , 1 );
244- } else {
245- p.SetBit (ParticleStatus::kToBeDone , 0 );
246- }
247251 mParticles .emplace_back (p);
248252 mCurrentParticle0 = p;
249253 }
@@ -255,10 +259,11 @@ void Stack::handleTransportPrimary(TParticle& p)
255259 // this function tests whether we really want to transport
256260 // this particle and sets the relevant bits accordingly
257261
258- if (mTransportPrimary (p, mPrimaryParticles )) {
259- p.SetBit (ParticleStatus::kToBeDone , 1 );
260- mNumberOfPrimariesforTracking ++;
261- } else {
262+ if (!p.TestBit (ParticleStatus::kToBeDone ) || !p.TestBit (ParticleStatus::kPrimary )) {
263+ return ;
264+ }
265+
266+ if (!mTransportPrimary (p, mPrimaryParticles )) {
262267 p.SetBit (ParticleStatus::kToBeDone , 0 );
263268 p.SetBit (ParticleStatus::kInhibited , 1 );
264269 }
@@ -271,15 +276,15 @@ void Stack::PushTrack(int toBeDone, TParticle& p)
271276 // This method is called
272277 //
273278 // - during parallel simulation to push primary particles (called by the stack itself)
274- if (p.GetUniqueID () == 0 ) {
279+ if (p.TestBit (ParticleStatus:: kPrimary ) ) {
275280 // one to one mapping for primaries
276281 mIndexMap [mNumberOfPrimaryParticles ] = mNumberOfPrimaryParticles ;
277- // Push particle on the stack
278- if (p.TestBit (ParticleStatus::kPrimary ) && p.TestBit (ParticleStatus::kToBeDone )) {
279- handleTransportPrimary (p);
280- }
281282 mNumberOfPrimaryParticles ++;
282283 mPrimaryParticles .push_back (p);
284+ // Push particle on the stack
285+ if (p.TestBit (ParticleStatus::kToBeDone )) {
286+ mNumberOfPrimariesforTracking ++;
287+ }
283288 mStack .push (p);
284289 mTracks ->emplace_back (p);
285290 }
0 commit comments