File indexing completed on 2026-06-13 07:54:41
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 "G4ParticleTypes.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4StepStatus.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4Track.hh"
0041 #include "G4UnitsTable.hh"
0042
0043
0044
0045 TrackingAction::TrackingAction(EventAction* event) : fEventAction(event)
0046 {
0047 fTrackMessenger = new TrackingMessenger(this);
0048 }
0049
0050
0051
0052 TrackingAction::~TrackingAction()
0053 {
0054 delete fTrackMessenger;
0055 }
0056
0057
0058
0059 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0060 {
0061
0062 if (track->GetTrackID() == 1) return;
0063
0064 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0065
0066 const G4ParticleDefinition* particle = track->GetParticleDefinition();
0067 G4String name = particle->GetParticleName();
0068 G4double meanLife = particle->GetPDGLifeTime();
0069 G4double energy = track->GetKineticEnergy();
0070 if (fParticleCount) run->ParticleCount(name, energy, meanLife);
0071
0072
0073
0074 G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0075
0076 G4int ih = 0;
0077 G4String type = particle->GetParticleType();
0078 G4double charge = particle->GetPDGCharge();
0079 if (charge > 3.)
0080 ih = 10;
0081 else if (particle == G4Gamma::Gamma())
0082 ih = 4;
0083 else if (particle == G4Electron::Electron())
0084 ih = 5;
0085 else if (particle == G4Positron::Positron())
0086 ih = 5;
0087 else if (particle == G4Neutron::Neutron())
0088 ih = 6;
0089 else if (particle == G4Proton::Proton())
0090 ih = 7;
0091 else if (particle == G4Deuteron::Deuteron())
0092 ih = 8;
0093 else if (particle == G4Alpha::Alpha())
0094 ih = 9;
0095 else if (type == "nucleus")
0096 ih = 10;
0097 else if (type == "baryon")
0098 ih = 11;
0099 else if (type == "meson")
0100 ih = 12;
0101 else if (type == "lepton")
0102 ih = 13;
0103 if (ih > 0) analysis->FillH1(ih, energy);
0104
0105
0106 if (fKillNeutron && (particle == G4Neutron::Neutron())) {
0107 fEventAction->AddEdep(energy);
0108 G4Track* aTrack = (G4Track*)track;
0109 aTrack->SetTrackStatus(fStopAndKill);
0110 }
0111 }
0112
0113
0114
0115 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0116 {
0117
0118 G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0119 if (status != fWorldBoundary) return;
0120
0121 const G4ParticleDefinition* particle = track->GetParticleDefinition();
0122 G4String name = particle->GetParticleName();
0123 G4double energy = track->GetKineticEnergy();
0124
0125 fEventAction->AddEflow(energy);
0126
0127 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0128 run->ParticleFlux(name, energy);
0129
0130
0131
0132 G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0133
0134 G4int ih = 0;
0135 G4String type = particle->GetParticleType();
0136 G4double charge = particle->GetPDGCharge();
0137 if (charge > 3.)
0138 ih = 20;
0139 else if (particle == G4Gamma::Gamma())
0140 ih = 14;
0141 else if (particle == G4Electron::Electron())
0142 ih = 15;
0143 else if (particle == G4Positron::Positron())
0144 ih = 15;
0145 else if (particle == G4Neutron::Neutron())
0146 ih = 16;
0147 else if (particle == G4Proton::Proton())
0148 ih = 17;
0149 else if (particle == G4Deuteron::Deuteron())
0150 ih = 18;
0151 else if (particle == G4Alpha::Alpha())
0152 ih = 19;
0153 else if (type == "nucleus")
0154 ih = 20;
0155 else if (type == "baryon")
0156 ih = 21;
0157 else if (type == "meson")
0158 ih = 22;
0159 else if (type == "lepton")
0160 ih = 23;
0161 if (ih > 0) analysis->FillH1(ih, energy);
0162 }
0163
0164