Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions examples/TestEm3/electrons.cu
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

int activeSize = active->size();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const int slot = (*active)[i];
Track &currentTrack = electrons[slot];
auto volume = currentTrack.navState.Top();
int volumeID = volume->id();
int theMCIndex = MCIndex[volumeID];
const int slot = (*active)[i];
Track &currentTrack = electrons[slot];
const int volumeID = currentTrack.navState.Top()->id();
const int theMCIndex = MCIndex[volumeID];

auto survive = [&] {
activeQueue->push_back(slot);
};

// Init a track with the needed data to call into G4HepEm.
G4HepEmElectronTrack elTrack;
Expand Down Expand Up @@ -218,21 +221,21 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

// Kill the particle if it left the world.
if (nextState.Top() != nullptr) {
activeQueue->push_back(slot);
BVHNavigator::RelocateToNextVolume(currentTrack.pos, currentTrack.dir, nextState);

// Move to the next boundary.
currentTrack.navState = nextState;
survive();
}
continue;
} else if (!propagated) {
// Did not yet reach the interaction point due to error in the magnetic
// field propagation. Try again next time.
activeQueue->push_back(slot);
survive();
continue;
} else if (winnerProcessIndex < 0) {
// No discrete process, move on.
activeQueue->push_back(slot);
survive();
continue;
}

Expand All @@ -243,7 +246,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
// Check if a delta interaction happens instead of the real discrete process.
if (G4HepEmElectronManager::CheckDelta(&g4HepEmData, theTrack, currentTrack.Uniform())) {
// A delta interaction happened, move on.
activeQueue->push_back(slot);
survive();
continue;
}

Expand Down Expand Up @@ -277,8 +280,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
activeQueue->push_back(slot);
survive();
break;
}
case 1: {
Expand All @@ -304,8 +306,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
activeQueue->push_back(slot);
survive();
break;
}
case 2: {
Expand Down
25 changes: 13 additions & 12 deletions examples/TestEm3/gammas.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
{
int activeSize = active->size();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const int slot = (*active)[i];
Track &currentTrack = gammas[slot];
auto volume = currentTrack.navState.Top();
int volumeID = volume->id();
int theMCIndex = MCIndex[volumeID];
const int slot = (*active)[i];
Track &currentTrack = gammas[slot];
const int volumeID = currentTrack.navState.Top()->id();
const int theMCIndex = MCIndex[volumeID];

auto survive = [&] {
activeQueue->push_back(slot);
};

// Init a track with the needed data to call into G4HepEm.
G4HepEmGammaTrack gammaTrack;
Expand Down Expand Up @@ -86,16 +89,16 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec

// Kill the particle if it left the world.
if (nextState.Top() != nullptr) {
activeQueue->push_back(slot);
BVHNavigator::RelocateToNextVolume(currentTrack.pos, currentTrack.dir, nextState);

// Move to the next boundary.
currentTrack.navState = nextState;
survive();
}
continue;
} else if (winnerProcessIndex < 0) {
// No discrete process, move on.
activeQueue->push_back(slot);
survive();
continue;
}

Expand All @@ -114,7 +117,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
case 0: {
// Invoke gamma conversion to e-/e+ pairs, if the energy is above the threshold.
if (energy < 2 * copcore::units::kElectronMassC2) {
activeQueue->push_back(slot);
survive();
continue;
}

Expand Down Expand Up @@ -151,7 +154,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
// Invoke Compton scattering of gamma.
constexpr double LowEnergyThreshold = 100 * copcore::units::eV;
if (energy < LowEnergyThreshold) {
activeQueue->push_back(slot);
survive();
continue;
}
const double origDirPrimary[] = {currentTrack.dir.x(), currentTrack.dir.y(), currentTrack.dir.z()};
Expand Down Expand Up @@ -180,9 +183,7 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
if (newEnergyGamma > LowEnergyThreshold) {
currentTrack.energy = newEnergyGamma;
currentTrack.dir = newDirGamma;

// The current track continues to live.
activeQueue->push_back(slot);
survive();
} else {
atomicAdd(&globalScoring->energyDeposit, newEnergyGamma);
atomicAdd(&scoringPerVolume->energyDeposit[volumeID], newEnergyGamma);
Expand Down
27 changes: 14 additions & 13 deletions examples/TestEm3Compact/electrons.cu
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr

int activeSize = electrons->fActiveTracks->size();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const int slot = (*electrons->fActiveTracks)[i];
Track &currentTrack = (*electrons)[slot];
auto volume = currentTrack.navState.Top();
int volumeID = volume->id();
int theMCIndex = MCIndex[volumeID];
const int slot = (*electrons->fActiveTracks)[i];
Track &currentTrack = (*electrons)[slot];
const int volumeID = currentTrack.navState.Top()->id();
const int theMCIndex = MCIndex[volumeID];

auto survive = [&] {
electrons->fNextTracks->push_back(slot);
};

// Init a track with the needed data to call into G4HepEm.
G4HepEmElectronTrack elTrack;
Expand Down Expand Up @@ -217,21 +220,21 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr

// Kill the particle if it left the world.
if (nextState.Top() != nullptr) {
electrons->fNextTracks->push_back(slot);
BVHNavigator::RelocateToNextVolume(currentTrack.pos, currentTrack.dir, nextState);

// Move to the next boundary.
currentTrack.navState = nextState;
survive();
}
continue;
} else if (!propagated) {
// Did not yet reach the interaction point due to error in the magnetic
// field propagation. Try again next time.
electrons->fNextTracks->push_back(slot);
survive();
continue;
} else if (winnerProcessIndex < 0) {
// No discrete process, move on.
electrons->fNextTracks->push_back(slot);
survive();
continue;
}

Expand All @@ -242,7 +245,7 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr
// Check if a delta interaction happens instead of the real discrete process.
if (G4HepEmElectronManager::CheckDelta(&g4HepEmData, theTrack, currentTrack.Uniform())) {
// A delta interaction happened, move on.
electrons->fNextTracks->push_back(slot);
survive();
continue;
}

Expand Down Expand Up @@ -276,8 +279,7 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
electrons->fNextTracks->push_back(slot);
survive();
break;
}
case 1: {
Expand All @@ -303,8 +305,7 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
electrons->fNextTracks->push_back(slot);
survive();
break;
}
case 2: {
Expand Down
25 changes: 13 additions & 12 deletions examples/TestEm3Compact/gammas.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries
{
int activeSize = gammas->fActiveTracks->size();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const int slot = (*gammas->fActiveTracks)[i];
Track &currentTrack = (*gammas)[slot];
auto volume = currentTrack.navState.Top();
int volumeID = volume->id();
int theMCIndex = MCIndex[volumeID];
const int slot = (*gammas->fActiveTracks)[i];
Track &currentTrack = (*gammas)[slot];
const int volumeID = currentTrack.navState.Top()->id();
const int theMCIndex = MCIndex[volumeID];

auto survive = [&] {
gammas->fNextTracks->push_back(slot);
};

// Init a track with the needed data to call into G4HepEm.
G4HepEmGammaTrack gammaTrack;
Expand Down Expand Up @@ -85,16 +88,16 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries

// Kill the particle if it left the world.
if (nextState.Top() != nullptr) {
gammas->fNextTracks->push_back(slot);
BVHNavigator::RelocateToNextVolume(currentTrack.pos, currentTrack.dir, nextState);

// Move to the next boundary.
currentTrack.navState = nextState;
survive();
}
continue;
} else if (winnerProcessIndex < 0) {
// No discrete process, move on.
gammas->fNextTracks->push_back(slot);
survive();
continue;
}

Expand All @@ -113,7 +116,7 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries
case 0: {
// Invoke gamma conversion to e-/e+ pairs, if the energy is above the threshold.
if (energy < 2 * copcore::units::kElectronMassC2) {
gammas->fNextTracks->push_back(slot);
survive();
continue;
}

Expand Down Expand Up @@ -150,7 +153,7 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries
// Invoke Compton scattering of gamma.
constexpr double LowEnergyThreshold = 100 * copcore::units::eV;
if (energy < LowEnergyThreshold) {
gammas->fNextTracks->push_back(slot);
survive();
continue;
}
const double origDirPrimary[] = {currentTrack.dir.x(), currentTrack.dir.y(), currentTrack.dir.z()};
Expand Down Expand Up @@ -179,9 +182,7 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries
if (newEnergyGamma > LowEnergyThreshold) {
currentTrack.energy = newEnergyGamma;
currentTrack.dir = newDirGamma;

// The current track continues to live.
gammas->fNextTracks->push_back(slot);
survive();
} else {
atomicAdd(&globalScoring->energyDeposit, newEnergyGamma);
atomicAdd(&scoringPerVolume->energyDeposit[volumeID], newEnergyGamma);
Expand Down
27 changes: 14 additions & 13 deletions examples/TestEm3MT/electrons.cu
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

int activeSize = active->size();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const int slot = (*active)[i];
Track &currentTrack = electrons[slot];
auto volume = currentTrack.navState.Top();
int volumeID = volume->id();
int theMCIndex = MCIndex[volumeID];
const int slot = (*active)[i];
Track &currentTrack = electrons[slot];
const int volumeID = currentTrack.navState.Top()->id();
const int theMCIndex = MCIndex[volumeID];

auto survive = [&] {
activeQueue->push_back(slot);
};

// Init a track with the needed data to call into G4HepEm.
G4HepEmElectronTrack elTrack;
Expand Down Expand Up @@ -219,21 +222,21 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

// Kill the particle if it left the world.
if (nextState.Top() != nullptr) {
activeQueue->push_back(slot);
BVHNavigator::RelocateToNextVolume(currentTrack.pos, currentTrack.dir, nextState);

// Move to the next boundary.
currentTrack.navState = nextState;
survive();
}
continue;
} else if (!propagated) {
// Did not yet reach the interaction point due to error in the magnetic
// field propagation. Try again next time.
activeQueue->push_back(slot);
survive();
continue;
} else if (winnerProcessIndex < 0) {
// No discrete process, move on.
activeQueue->push_back(slot);
survive();
continue;
}

Expand All @@ -244,7 +247,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
// Check if a delta interaction happens instead of the real discrete process.
if (G4HepEmElectronManager::CheckDelta(&g4HepEmData, theTrack, currentTrack.Uniform())) {
// A delta interaction happened, move on.
activeQueue->push_back(slot);
survive();
continue;
}

Expand Down Expand Up @@ -278,8 +281,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
activeQueue->push_back(slot);
survive();
break;
}
case 1: {
Expand All @@ -305,8 +307,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons

currentTrack.energy = energy - deltaEkin;
currentTrack.dir.Set(dirPrimary[0], dirPrimary[1], dirPrimary[2]);
// The current track continues to live.
activeQueue->push_back(slot);
survive();
break;
}
case 2: {
Expand Down
Loading