I’m trying to record the initial angle of each particle I generate with respect to its (planar) source, its initial energy and the energy it deposits in my detector. I thought I could do this with the TrackingAction class, because track has the GetMomentumDirection function, so my TrackingAction.cc looks like this:
TrackingAction::TrackingAction()
:G4UserTrackingAction()
{}
void TrackingAction::PreUserTrackingAction(const G4Track* track) {
//record with particle info
G4ThreeVector direction = track->GetMomentumDirection();
G4double pi = 3.14159;
G4double theta = (180 / pi) * direction.theta();
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->FillNtupleDColumn(2,theta);
std::cout << “pre user tracking action called” << ‘\n’;
analysisManager->AddNtupleRow();
}
What happens is that this gets called multiple times per particle, so I wind up with incorrect data. Is there a proper place to record the initial momentum direction of the particle? I’m using a general particle source macro file.