File indexing completed on 2026-05-21 07:54:01
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
0035 #include "G4IonTable.hh"
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
0048
0049 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0050 {
0051 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0052
0053 G4ParticleDefinition* particle = track->GetDefinition();
0054 G4String name = particle->GetParticleName();
0055 G4double meanLife = particle->GetPDGLifeTime();
0056 G4double ekin = track->GetKineticEnergy();
0057 fTimeBirth = track->GetGlobalTime();
0058
0059
0060 if ((track->GetTrackID() > 1) && (meanLife != 0.)) run->ParticleCount(name, ekin, meanLife);
0061 }
0062
0063
0064
0065 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0066 {
0067 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0068
0069 G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0070
0071 const G4ParticleDefinition* particle = track->GetParticleDefinition();
0072 G4String name = particle->GetParticleName();
0073 G4double meanLife = particle->GetPDGLifeTime();
0074 G4double ekin = track->GetKineticEnergy();
0075 fTimeEnd = track->GetGlobalTime();
0076 if ((particle->GetPDGStable()) && (ekin == 0.)) fTimeEnd = DBL_MAX;
0077
0078
0079 if ((G4IonTable::IsIon(particle)) && (meanLife != 0.)) {
0080 G4int id = run->GetIonId(name);
0081 G4double unit = analysis->GetH1Unit(id);
0082 G4double tmin = analysis->GetH1Xmin(id) * unit;
0083 G4double tmax = analysis->GetH1Xmax(id) * unit;
0084 G4double binWidth = analysis->GetH1Width(id) * unit;
0085 G4double weight = track->GetWeight();
0086
0087 G4double t1 = std::max(fTimeBirth, tmin);
0088 G4double t2 = std::min(fTimeEnd, tmax);
0089 for (G4double time = t1; time < t2; time += binWidth)
0090 analysis->FillH1(id, time, weight);
0091 }
0092
0093
0094 G4StepStatus status = track->GetStep()->GetPostStepPoint()->GetStepStatus();
0095 if (status != fWorldBoundary) return;
0096
0097 fEventAction->AddEflow(ekin);
0098 run->ParticleFlux(name, ekin);
0099
0100
0101
0102 G4int ih1 = 0, ih2 = 0;
0103 G4String type = particle->GetParticleType();
0104 G4double charge = particle->GetPDGCharge();
0105 G4double time = track->GetGlobalTime();
0106 G4double weight = track->GetWeight();
0107 if (charge > 3.) {
0108 ih1 = 10;
0109 ih2 = 20;
0110 }
0111 else if (particle == G4Gamma::Gamma()) {
0112 ih1 = 4;
0113 ih2 = 14;
0114 }
0115 else if (particle == G4Electron::Electron()) {
0116 ih1 = 5;
0117 ih2 = 15;
0118 }
0119 else if (particle == G4Positron::Positron()) {
0120 ih1 = 5;
0121 ih2 = 15;
0122 }
0123 else if (particle == G4Neutron::Neutron()) {
0124 ih1 = 6;
0125 ih2 = 16;
0126 }
0127 else if (particle == G4Proton::Proton()) {
0128 ih1 = 7;
0129 ih2 = 17;
0130 }
0131 else if (particle == G4Deuteron::Deuteron()) {
0132 ih1 = 8;
0133 ih2 = 18;
0134 }
0135 else if (particle == G4Alpha::Alpha()) {
0136 ih1 = 9;
0137 ih2 = 19;
0138 }
0139 else if (type == "nucleus") {
0140 ih1 = 10;
0141 ih2 = 20;
0142 }
0143 else if (type == "baryon") {
0144 ih1 = 11;
0145 ih2 = 21;
0146 }
0147 else if (type == "meson") {
0148 ih1 = 12;
0149 ih2 = 22;
0150 }
0151 else if (type == "lepton") {
0152 ih1 = 13;
0153 ih2 = 23;
0154 };
0155 if (ih1 > 0) analysis->FillH1(ih1, ekin, weight);
0156 if (ih2 > 0) analysis->FillH1(ih2, time, weight);
0157 }
0158
0159