File indexing completed on 2026-09-14 08:28:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "TrackingAction.hh"
0030
0031 #include "EventAction.hh"
0032 #include "HistoManager.hh"
0033 #include "Run.hh"
0034 #include "TrackingMessenger.hh"
0035
0036 #include "G4RunManager.hh"
0037 #include "G4StepStatus.hh"
0038 #include "G4Track.hh"
0039
0040
0041
0042 TrackingAction::TrackingAction(EventAction* evt) : fTrackMessenger(nullptr), fEventAct(evt)
0043 {
0044 fTrackMessenger = new TrackingMessenger(this);
0045 }
0046
0047
0048
0049 TrackingAction::~TrackingAction()
0050 {
0051 delete fTrackMessenger;
0052 }
0053
0054
0055
0056 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0057 {
0058
0059 if (track->GetTrackID() == 1) return;
0060
0061 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0062
0063 G4int iabs = track->GetTouchableHandle()->GetCopyNumber();
0064 G4String name = track->GetDefinition()->GetParticleName();
0065 G4double meanLife = track->GetDefinition()->GetPDGLifeTime();
0066 G4double energy = track->GetKineticEnergy();
0067 if (fParticleCount && (iabs > 0)) run->ParticleCount(iabs, name, energy, meanLife);
0068 }
0069
0070
0071
0072 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0073 {
0074
0075 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0076
0077
0078 G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0079
0080
0081 if (track->GetTrackID() == 1) {
0082 G4int flag = 0;
0083 if (status == fWorldBoundary) {
0084 if (track->GetMomentumDirection().x() > 0.)
0085 flag = 1;
0086 else
0087 flag = 2;
0088 }
0089 run->AddTrackStatus(flag);
0090 }
0091
0092
0093 if (status != fWorldBoundary) return;
0094
0095
0096 const G4ParticleDefinition* particle = track->GetParticleDefinition();
0097 G4String name = particle->GetParticleName();
0098 G4double meanLife = particle->GetPDGLifeTime();
0099 G4double energy = track->GetKineticEnergy();
0100 run->ParticleCount(0, name, energy, meanLife);
0101 fEventAct->AddEleak(energy);
0102
0103
0104 }
0105
0106