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