Dear experts, I have a simple geometry of particle gun → target with a certain material → detectors. I want to calculate the cross section through the target and the energy deposition in the detectors.
I implemented the process counter of example extended-electromagnetic-TestEm13 for cross section but everytime its counter adds an interaction it uses G4RunManager::GetRunManager()->AbortEvent(); and therefore any particle gets into the detector.
I want to count the same interaction the example does without aborting the event to let the primary and secundary particles hit the detector. The problem here is that without aborting event the counter adds way more interactions as a result of secundary generated particles.
My approach was to use the counter only when trackID = 1 but its still counting more interactions. What can i do?
_Geant4 Version: 11.2.1
Operating System: Windows - Ubuntu
#include "stepping.hh"
MySteppingAction::MySteppingAction(MyEventAction *eventAction)
{
fEventAction = eventAction;
}
MySteppingAction::~MySteppingAction()
{}
void MySteppingAction::UserSteppingAction(const G4Step *step)
{
//Search the volume that has a particle
G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
//Create an object to store the scoring volume
const MyDetectorConstruction *detectorConstruction = static_cast<const MyDetectorConstruction*> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
//Tracking
G4Track* track = step->GetTrack();
// Check if this trackID has already interacted
G4int trackID = track->GetTrackID();
CrossRun *run = static_cast<CrossRun*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
//Scoring volume
G4LogicalVolume *fScoringVolume = detectorConstruction->GetScoringVolume();
//We dont consider volumes other than the wall
if(volume != fScoringVolume)
return;
//Gets the total energy of all detector
G4double edep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edep);
if(trackID == 1)
{
//Process Counter
G4StepPoint* endPoint = step->GetPostStepPoint();
G4String procName = endPoint->GetProcessDefinedStep()->GetProcessName();
run->CountProcesses(procName);
}
}