@@ -25,11 +25,14 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
2525{
2626 int activeSize = active->size ();
2727 for (int i = blockIdx .x * blockDim .x + threadIdx .x ; i < activeSize; i += blockDim .x * gridDim .x ) {
28- const int slot = (*active)[i];
29- Track ¤tTrack = gammas[slot];
30- auto volume = currentTrack.navState .Top ();
31- int volumeID = volume->id ();
32- int theMCIndex = MCIndex[volumeID];
28+ const int slot = (*active)[i];
29+ Track ¤tTrack = gammas[slot];
30+ const int volumeID = currentTrack.navState .Top ()->id ();
31+ const int theMCIndex = MCIndex[volumeID];
32+
33+ auto survive = [&] {
34+ activeQueue->push_back (slot);
35+ };
3336
3437 // Init a track with the needed data to call into G4HepEm.
3538 G4HepEmGammaTrack gammaTrack;
@@ -86,16 +89,16 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
8689
8790 // Kill the particle if it left the world.
8891 if (nextState.Top () != nullptr ) {
89- activeQueue->push_back (slot);
9092 BVHNavigator::RelocateToNextVolume (currentTrack.pos , currentTrack.dir , nextState);
9193
9294 // Move to the next boundary.
9395 currentTrack.navState = nextState;
96+ survive ();
9497 }
9598 continue ;
9699 } else if (winnerProcessIndex < 0 ) {
97100 // No discrete process, move on.
98- activeQueue-> push_back (slot );
101+ survive ( );
99102 continue ;
100103 }
101104
@@ -114,7 +117,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
114117 case 0 : {
115118 // Invoke gamma conversion to e-/e+ pairs, if the energy is above the threshold.
116119 if (energy < 2 * copcore::units::kElectronMassC2 ) {
117- activeQueue-> push_back (slot );
120+ survive ( );
118121 continue ;
119122 }
120123
@@ -151,7 +154,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
151154 // Invoke Compton scattering of gamma.
152155 constexpr double LowEnergyThreshold = 100 * copcore::units::eV;
153156 if (energy < LowEnergyThreshold) {
154- activeQueue-> push_back (slot );
157+ survive ( );
155158 continue ;
156159 }
157160 const double origDirPrimary[] = {currentTrack.dir .x (), currentTrack.dir .y (), currentTrack.dir .z ()};
@@ -180,9 +183,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
180183 if (newEnergyGamma > LowEnergyThreshold) {
181184 currentTrack.energy = newEnergyGamma;
182185 currentTrack.dir = newDirGamma;
183-
184- // The current track continues to live.
185- activeQueue->push_back (slot);
186+ survive ();
186187 } else {
187188 atomicAdd (&globalScoring->energyDeposit , newEnergyGamma);
188189 atomicAdd (&scoringPerVolume->energyDeposit [volumeID], newEnergyGamma);
0 commit comments