@@ -47,11 +47,15 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
4747 for (int i = blockIdx .x * blockDim .x + threadIdx .x ; i < activeSize; i += blockDim .x * gridDim .x ) {
4848 const int globalSlot = (*active)[i];
4949 Track ¤tTrack = electrons[globalSlot];
50- auto volume = currentTrack.navState .Top ();
51- int volumeID = volume->id ();
50+ const auto volume = currentTrack.navState .Top ();
51+ const int volumeID = volume->id ();
5252 // the MCC vector is indexed by the logical volume id
53- int lvolID = volume->GetLogicalVolume ()->id ();
54- int theMCIndex = MCIndex[lvolID];
53+ const int lvolID = volume->GetLogicalVolume ()->id ();
54+ const int theMCIndex = MCIndex[lvolID];
55+
56+ auto survive = [&](bool push = true ) {
57+ if (push) activeQueue->push_back (globalSlot);
58+ };
5559
5660 // Signal that this globalSlot doesn't undergo an interaction (yet)
5761 soaData.nextInteraction [i] = -1 ;
@@ -252,21 +256,21 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
252256
253257 // Kill the particle if it left the world.
254258 if (nextState.Top () != nullptr ) {
255- activeQueue->push_back (globalSlot);
256259 BVHNavigator::RelocateToNextVolume (currentTrack.pos , currentTrack.dir , nextState);
257260
258261 // Move to the next boundary.
259262 currentTrack.navState = nextState;
263+ survive ();
260264 }
261265 continue ;
262266 } else if (!propagated || restrictedPhysicalStepLength) {
263267 // Did not yet reach the interaction point due to error in the magnetic
264268 // field propagation. Try again next time.
265- activeQueue-> push_back (globalSlot );
269+ survive ( );
266270 continue ;
267271 } else if (winnerProcessIndex < 0 ) {
268272 // No discrete process, move on.
269- activeQueue-> push_back (globalSlot );
273+ survive ( );
270274 continue ;
271275 }
272276
@@ -277,11 +281,13 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
277281 // Check if a delta interaction happens instead of the real discrete process.
278282 if (G4HepEmElectronManager::CheckDelta (&g4HepEmData, theTrack, currentTrack.Uniform ())) {
279283 // A delta interaction happened, move on.
280- activeQueue-> push_back (globalSlot );
284+ survive ( );
281285 continue ;
282286 }
283287
284288 soaData.nextInteraction [i] = winnerProcessIndex;
289+
290+ survive (false );
285291 }
286292}
287293
@@ -307,11 +313,13 @@ __device__ void ElectronInteraction(int const globalSlot, SOAData const & /*soaD
307313 GlobalScoring *globalScoring, ScoringPerVolume *scoringPerVolume)
308314{
309315 Track ¤tTrack = particles[globalSlot];
310- auto volume = currentTrack.navState .Top ();
316+ const auto volume = currentTrack.navState .Top ();
311317 // the MCC vector is indexed by the logical volume id
312318 const int lvolID = volume->GetLogicalVolume ()->id ();
313319 const int theMCIndex = MCIndex[lvolID];
314320
321+ auto survive = [&] { activeQueue->push_back (globalSlot); };
322+
315323 const double energy = currentTrack.energy ;
316324 const double theElCut = g4HepEmData.fTheMatCutData ->fMatCutData [theMCIndex].fSecElProdCutE ;
317325
@@ -337,8 +345,7 @@ __device__ void ElectronInteraction(int const globalSlot, SOAData const & /*soaD
337345
338346 currentTrack.energy = energy - deltaEkin;
339347 currentTrack.dir .Set (dirPrimary[0 ], dirPrimary[1 ], dirPrimary[2 ]);
340- // The current track continues to live.
341- activeQueue->push_back (globalSlot);
348+ survive ();
342349 } else if constexpr (ProcessIndex == 1 ) {
343350 // Invoke model for Bremsstrahlung: either SB- or Rel-Brem.
344351 double logEnergy = std::log (energy);
@@ -362,8 +369,7 @@ __device__ void ElectronInteraction(int const globalSlot, SOAData const & /*soaD
362369
363370 currentTrack.energy = energy - deltaEkin;
364371 currentTrack.dir .Set (dirPrimary[0 ], dirPrimary[1 ], dirPrimary[2 ]);
365- // The current track continues to live.
366- activeQueue->push_back (globalSlot);
372+ survive ();
367373 } else if constexpr (ProcessIndex == 2 ) {
368374 // Invoke annihilation (in-flight) for e+
369375 double dirPrimary[] = {currentTrack.dir .x (), currentTrack.dir .y (), currentTrack.dir .z ()};
0 commit comments