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 #include "TrackingMessenger.hh"
0039
0040 #include "G4IonTable.hh"
0041 #include "G4ParticleTypes.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Track.hh"
0045 #include "G4UnitsTable.hh"
0046
0047
0048
0049 TrackingAction::TrackingAction(EventAction* event) : fEvent(event)
0050
0051 {
0052 fTrackMessenger = new TrackingMessenger(this);
0053 }
0054
0055
0056
0057 TrackingAction::~TrackingAction()
0058 {
0059 delete fTrackMessenger;
0060 }
0061
0062
0063
0064 void TrackingAction::SetTimeWindow(G4double t1, G4double dt)
0065 {
0066 fTimeWindow1 = t1;
0067 fTimeWindow2 = fTimeWindow1 + dt;
0068 }
0069
0070
0071
0072 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0073 {
0074 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0075
0076 G4ParticleDefinition* particle = track->GetDefinition();
0077 G4String name = particle->GetParticleName();
0078 fCharge = particle->GetPDGCharge();
0079 fMass = particle->GetPDGMass();
0080
0081 G4double Ekin = track->GetKineticEnergy();
0082 G4int ID = track->GetTrackID();
0083
0084 G4bool condition = false;
0085
0086
0087
0088 G4double meanLife = particle->GetPDGLifeTime();
0089
0090
0091
0092 run->ParticleCount(name, Ekin, meanLife);
0093
0094
0095
0096 G4int ih = 0;
0097 if (particle == G4Electron::Electron() || particle == G4Positron::Positron())
0098 ih = 1;
0099 else if (particle == G4NeutrinoE::NeutrinoE() || particle == G4AntiNeutrinoE::AntiNeutrinoE())
0100 ih = 2;
0101 else if (particle == G4Gamma::Gamma())
0102 ih = 3;
0103 else if (particle == G4Alpha::Alpha())
0104 ih = 4;
0105 else if (fCharge > 2.)
0106 ih = 5;
0107 if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
0108
0109
0110
0111 if (fCharge > 2.) {
0112
0113 if (ID == 1)
0114 fEvent->AddDecayChain(name);
0115 else
0116 fEvent->AddDecayChain(" ---> " + name);
0117
0118
0119 G4Track* tr = (G4Track*)track;
0120 if (fFullChain) {
0121 tr->SetKineticEnergy(0.);
0122 tr->SetTrackStatus(fStopButAlive);
0123 }
0124 else if (ID > 1)
0125 tr->SetTrackStatus(fStopAndKill);
0126
0127 fTimeBirth = track->GetGlobalTime();
0128 }
0129
0130
0131
0132
0133 if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent();
0134 }
0135
0136
0137
0138 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0139 {
0140
0141
0142 if (fCharge < 3.) return;
0143
0144 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0145
0146 G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0147
0148
0149
0150 G4double time = track->GetGlobalTime();
0151 G4int ID = track->GetTrackID();
0152 if (ID == 1) run->PrimaryTiming(time);
0153 fTimeEnd = time;
0154
0155
0156
0157 const std::vector<const G4Track*>* secondaries = track->GetStep()->GetSecondaryInCurrentStep();
0158 size_t nbtrk = (*secondaries).size();
0159 if (nbtrk) {
0160
0161
0162
0163 G4double EkinTot = 0., EkinVis = 0.;
0164 G4ThreeVector Pbalance = -track->GetMomentum();
0165 for (size_t itr = 0; itr < nbtrk; itr++) {
0166 const G4Track* trk = (*secondaries)[itr];
0167 G4ParticleDefinition* particle = trk->GetDefinition();
0168 G4double Ekin = trk->GetKineticEnergy();
0169 EkinTot += Ekin;
0170 G4bool visible =
0171 !((particle == G4NeutrinoE::NeutrinoE()) || (particle == G4AntiNeutrinoE::AntiNeutrinoE()));
0172 if (visible) EkinVis += Ekin;
0173
0174 if (particle != G4Gamma::Gamma()) Pbalance += trk->GetMomentum();
0175 }
0176 G4double Pbal = Pbalance.mag();
0177 run->Balance(EkinTot, Pbal);
0178 analysis->FillH1(6, EkinTot);
0179 analysis->FillH1(7, Pbal);
0180 fEvent->AddEvisible(EkinVis);
0181 }
0182
0183
0184
0185 if (!nbtrk) {
0186 run->EventTiming(time);
0187 G4double weight = track->GetWeight();
0188 analysis->FillH1(8, time, weight);
0189
0190 fTimeEnd = DBL_MAX;
0191 }
0192
0193
0194
0195 run->SetTimeWindow(fTimeWindow1, fTimeWindow2);
0196
0197 G4String name = track->GetDefinition()->GetParticleName();
0198 G4bool life1(false), life2(false), decay(false);
0199 if ((fTimeBirth <= fTimeWindow1) && (fTimeEnd > fTimeWindow1)) life1 = true;
0200 if ((fTimeBirth <= fTimeWindow2) && (fTimeEnd > fTimeWindow2)) life2 = true;
0201 if ((fTimeEnd > fTimeWindow1) && (fTimeEnd < fTimeWindow2)) decay = true;
0202 if (life1 || life2 || decay) run->CountInTimeWindow(name, life1, life2, decay);
0203 }
0204
0205