Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file TrackingAction.cc 27 /// \brief Implementation of the TrackingActio 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 33 #include "TrackingAction.hh" 34 35 #include "EventAction.hh" 36 #include "HistoManager.hh" 37 #include "Run.hh" 38 #include "TrackingMessenger.hh" 39 40 #include "G4IonTable.hh" 41 #include "G4ParticleTypes.hh" 42 #include "G4RunManager.hh" 43 #include "G4SystemOfUnits.hh" 44 #include "G4Track.hh" 45 #include "G4UnitsTable.hh" 46 47 //....oooOO0OOooo........oooOO0OOooo........oo 48 49 TrackingAction::TrackingAction(EventAction* ev 50 51 { 52 fTrackMessenger = new TrackingMessenger(this 53 } 54 55 //....oooOO0OOooo........oooOO0OOooo........oo 56 57 TrackingAction::~TrackingAction() 58 { 59 delete fTrackMessenger; 60 } 61 62 //....oooOO0OOooo........oooOO0OOooo........oo 63 64 void TrackingAction::SetTimeWindow(G4double t1 65 { 66 fTimeWindow1 = t1; 67 fTimeWindow2 = fTimeWindow1 + dt; 68 } 69 70 //....oooOO0OOooo........oooOO0OOooo........oo 71 72 void TrackingAction::PreUserTrackingAction(con 73 { 74 Run* run = static_cast<Run*>(G4RunManager::G 75 76 G4ParticleDefinition* particle = track->GetD 77 G4String name = particle->GetParticleName(); 78 fCharge = particle->GetPDGCharge(); 79 fMass = particle->GetPDGMass(); 80 81 G4double Ekin = track->GetKineticEnergy(); 82 G4int ID = track->GetTrackID(); 83 84 G4bool condition = false; 85 86 // check LifeTime 87 // 88 G4double meanLife = particle->GetPDGLifeTime 89 90 // count particles 91 // 92 run->ParticleCount(name, Ekin, meanLife); 93 94 // energy spectrum 95 // 96 G4int ih = 0; 97 if (particle == G4Electron::Electron() || pa 98 ih = 1; 99 else if (particle == G4NeutrinoE::NeutrinoE( 100 ih = 2; 101 else if (particle == G4Gamma::Gamma()) 102 ih = 3; 103 else if (particle == G4Alpha::Alpha()) 104 ih = 4; 105 else if (fCharge > 2.) 106 ih = 5; 107 if (ih) G4AnalysisManager::Instance()->FillH 108 109 // Ion 110 // 111 if (fCharge > 2.) { 112 // build decay chain 113 if (ID == 1) 114 fEvent->AddDecayChain(name); 115 else 116 fEvent->AddDecayChain(" ---> " + name); 117 // 118 // full chain: put at rest; if not: kill s 119 G4Track* tr = (G4Track*)track; 120 if (fFullChain) { 121 tr->SetKineticEnergy(0.); 122 tr->SetTrackStatus(fStopButAlive); 123 } 124 else if (ID > 1) 125 tr->SetTrackStatus(fStopAndKill); 126 // 127 fTimeBirth = track->GetGlobalTime(); 128 } 129 130 // example of saving random number seed of t 131 // 132 ////condition = (ih == 3); 133 if (condition) G4RunManager::GetRunManager() 134 } 135 136 //....oooOO0OOooo........oooOO0OOooo........oo 137 138 void TrackingAction::PostUserTrackingAction(co 139 { 140 // keep only ions 141 // 142 if (fCharge < 3.) return; 143 144 Run* run = static_cast<Run*>(G4RunManager::G 145 146 G4AnalysisManager* analysis = G4AnalysisMana 147 148 // get time 149 // 150 G4double time = track->GetGlobalTime(); 151 G4int ID = track->GetTrackID(); 152 if (ID == 1) run->PrimaryTiming(time); // t 153 fTimeEnd = time; 154 155 // energy and momentum balance (from seconda 156 // 157 const std::vector<const G4Track*>* secondari 158 size_t nbtrk = (*secondaries).size(); 159 if (nbtrk) { 160 // there are secondaries --> it is a decay 161 // 162 // balance 163 G4double EkinTot = 0., EkinVis = 0.; 164 G4ThreeVector Pbalance = -track->GetMoment 165 for (size_t itr = 0; itr < nbtrk; itr++) { 166 const G4Track* trk = (*secondaries)[itr] 167 G4ParticleDefinition* particle = trk->Ge 168 G4double Ekin = trk->GetKineticEnergy(); 169 EkinTot += Ekin; 170 G4bool visible = 171 !((particle == G4NeutrinoE::NeutrinoE( 172 if (visible) EkinVis += Ekin; 173 // exclude gamma desexcitation from mome 174 if (particle != G4Gamma::Gamma()) Pbalan 175 } 176 G4double Pbal = Pbalance.mag(); 177 run->Balance(EkinTot, Pbal); 178 analysis->FillH1(6, EkinTot); 179 analysis->FillH1(7, Pbal); 180 fEvent->AddEvisible(EkinVis); 181 } 182 183 // no secondaries --> end of chain 184 // 185 if (!nbtrk) { 186 run->EventTiming(time); // total time of 187 G4double weight = track->GetWeight(); 188 analysis->FillH1(8, time, weight); 189 //// analysis->FillH1(8,time); 190 fTimeEnd = DBL_MAX; 191 } 192 193 // count activity in time window 194 // 195 run->SetTimeWindow(fTimeWindow1, fTimeWindow 196 197 G4String name = track->GetDefinition()->GetP 198 G4bool life1(false), life2(false), decay(fal 199 if ((fTimeBirth <= fTimeWindow1) && (fTimeEn 200 if ((fTimeBirth <= fTimeWindow2) && (fTimeEn 201 if ((fTimeEnd > fTimeWindow1) && (fTimeEnd < 202 if (life1 || life2 || decay) run->CountInTim 203 } 204 205 //....oooOO0OOooo........oooOO0OOooo........oo 206