Skip to content
Open
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
38 changes: 35 additions & 3 deletions src/GPURaytrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,42 @@ struct SteppingAction : G4UserSteppingAction
<< G4endl;
return;
}
G4double SCINTILLATIONTIMECONSTANT1 = MPT->GetConstProperty(kSCINTILLATIONTIMECONSTANT1);
// G4 11.x supports up to 3 scintillation components
const G4int tcKeys[3] = {kSCINTILLATIONTIMECONSTANT1, kSCINTILLATIONTIMECONSTANT2,
kSCINTILLATIONTIMECONSTANT3};
const G4int yieldKeys[3] = {kSCINTILLATIONYIELD1, kSCINTILLATIONYIELD2, kSCINTILLATIONYIELD3};

U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, fNumPhotons, 1,
SCINTILLATIONTIMECONSTANT1);
G4double tc[3] = {0, 0, 0};
G4double yield[3] = {0, 0, 0};
G4double yieldSum = 0;
G4int nComp = 0;

for (G4int c = 0; c < 3; c++)
{
if (MPT->ConstPropertyExists(tcKeys[c]))
{
tc[c] = MPT->GetConstProperty(tcKeys[c]);
yield[c] = MPT->ConstPropertyExists(yieldKeys[c]) ? MPT->GetConstProperty(yieldKeys[c])
: (c == 0 ? 1.0 : 0.0);
yieldSum += yield[c];
nComp = c + 1;
}
}

G4AutoLock lock(&genstep_mutex);
G4int nRemaining = fNumPhotons;
for (G4int c = 0; c < nComp; c++)
{
G4int nPhotComp;
if (c == nComp - 1)
nPhotComp = nRemaining; // last component gets remainder
else
nPhotComp = static_cast<G4int>(fNumPhotons * yield[c] / yieldSum);
Comment on lines +553 to +556
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match Geant4 split for third scintillation component

When nComp == 3, this branch gives all rounding remainder to component 3 (nPhotComp = nRemaining), but Geant4’s G4Scintillation::PostStepDoIt computes component 3 as yield3/sum * fNumPhotons (no remainder redistribution). That means the GPU gensteps can overpopulate the slow component (especially for low fNumPhotons, e.g. 1–2 photons/step), which breaks CPU/GPU agreement for 3-component scintillation timing in this path.

Useful? React with 👍 / 👎.

nRemaining -= nPhotComp;

if (nPhotComp > 0)
U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, nPhotComp, c + 1, tc[c]);
}
}
}
}
Expand Down
Loading