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