Skip to content

Commit

Permalink
FillG4NavigationHistory fix (#303)
Browse files Browse the repository at this point in the history
Fixes for the step object provided by AdePT to Genat4.

This fixes the wrong logic in FillG4NavigationHistory and adds the
missing MaterialCutsCouple pointer in the 'fake' step reconstructed from
AdePT information and used to call the G4 sensitive detectors.
  • Loading branch information
WitekPokorski authored Aug 28, 2024
1 parent 4706df8 commit b07e6ae
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/AdePTGeant4Integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,14 @@ void AdePTGeant4Integration::FillG4NavigationHistory(unsigned int aNavIndex, G4N
// have the correct volume in the history
pnewvol = const_cast<G4VPhysicalVolume *>(fglobal_vecgeom_to_g4_map[vgState.At(aLevel)->id()]);

if (aLevel < aG4HistoryDepth) {
// In G4NavigationHistory, the initial volume has the index 1
pvol = aG4NavigationHistory->GetVolume(aLevel + 1);

if (aG4HistoryDepth && (aLevel <= aG4HistoryDepth)) {
pvol = aG4NavigationHistory->GetVolume(aLevel);
// If they match we do not need to update the history at this level
if (pvol == pnewvol) continue;
// Once we find two non-matching volumes, we need to update the touchable history from this level on
if (aLevel) {
// If we are not in the top level
aG4NavigationHistory->BackLevel(aG4HistoryDepth - aLevel);
aG4NavigationHistory->BackLevel(aG4HistoryDepth - aLevel + 1);
// Update the current level
aG4NavigationHistory->NewLevel(pnewvol, kNormal, pnewvol->GetCopyNo());
} else {
Expand All @@ -354,12 +352,19 @@ void AdePTGeant4Integration::FillG4NavigationHistory(unsigned int aNavIndex, G4N
aG4HistoryDepth = aLevel;
} else {
// If the navigation state is deeper than the current history we need to add the new levels
aG4NavigationHistory->NewLevel(pnewvol, kNormal, pnewvol->GetCopyNo());
aG4HistoryDepth++;
if(aLevel)
{
aG4NavigationHistory->NewLevel(pnewvol, kNormal, pnewvol->GetCopyNo());
aG4HistoryDepth++;
}
else
{
aG4NavigationHistory->SetFirstEntry(pnewvol);
}
}
}
// Once finished, remove the extra levels if the current state is shallower than the previous history
if (aG4HistoryDepth >= aLevel) aG4NavigationHistory->BackLevel(aG4HistoryDepth - aLevel);
if (aG4HistoryDepth >= aLevel) aG4NavigationHistory->BackLevel(aG4HistoryDepth - aLevel + 1);
}

void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4TouchableHandle &aPreG4TouchableHandle,
Expand Down Expand Up @@ -428,7 +433,7 @@ void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4Touc
// aPreStepPoint->SetVelocity(0); // Missing data
aPreStepPoint->SetTouchableHandle(aPreG4TouchableHandle); // Real data
aPreStepPoint->SetMaterial(aPreG4TouchableHandle->GetVolume()->GetLogicalVolume()->GetMaterial()); // Real data
// aPreStepPoint->SetMaterialCutsCouple(nullptr); // Missing data
aPreStepPoint->SetMaterialCutsCouple(aPreG4TouchableHandle->GetVolume()->GetLogicalVolume()->GetMaterialCutsCouple());
// aPreStepPoint->SetSensitiveDetector(nullptr); // Missing data
// aPreStepPoint->SetSafety(0); // Missing data
aPreStepPoint->SetPolarization(G4ThreeVector(aGPUHit->fPreStepPoint.fPolarization)); // Real data
Expand All @@ -450,7 +455,7 @@ void AdePTGeant4Integration::FillG4Step(GPUHit *aGPUHit, G4Step *aG4Step, G4Touc
// aPostStepPoint->SetVelocity(0); // Missing data
aPostStepPoint->SetTouchableHandle(aPostG4TouchableHandle); // Real data
aPostStepPoint->SetMaterial(aPostG4TouchableHandle->GetVolume()->GetLogicalVolume()->GetMaterial()); // Real data
// aPostStepPoint->SetMaterialCutsCouple(nullptr); // Missing data
aPostStepPoint->SetMaterialCutsCouple(aPostG4TouchableHandle->GetVolume()->GetLogicalVolume()->GetMaterialCutsCouple());
// aPostStepPoint->SetSensitiveDetector(nullptr); // Missing data
// aPostStepPoint->SetSafety(0); // Missing data
aPostStepPoint->SetPolarization(*aPostStepPointPolarization); // Real data
Expand Down

0 comments on commit b07e6ae

Please sign in to comment.