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 << 27 /// \brief Implementation of the TrackingActio << 28 // 26 // 29 // << 27 // $Id: TrackingAction.cc,v 1.2 2010-10-11 14:31:39 maire Exp $ 30 //....oooOO0OOooo........oooOO0OOooo........oo << 28 // GEANT4 tag $Name: geant4-09-04-patch-01 $ >> 29 // 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 32 33 #include "TrackingAction.hh" 33 #include "TrackingAction.hh" 34 << 34 #include "RunAction.hh" 35 #include "EventAction.hh" << 36 #include "HistoManager.hh" 35 #include "HistoManager.hh" 37 #include "Run.hh" << 36 #include "RunAction.hh" >> 37 #include "EventAction.hh" 38 #include "TrackingMessenger.hh" 38 #include "TrackingMessenger.hh" 39 39 40 #include "G4IonTable.hh" << 40 #include "G4Track.hh" 41 #include "G4ParticleTypes.hh" 41 #include "G4ParticleTypes.hh" 42 #include "G4RunManager.hh" 42 #include "G4RunManager.hh" 43 #include "G4SystemOfUnits.hh" << 44 #include "G4Track.hh" << 45 #include "G4UnitsTable.hh" << 46 43 47 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 45 49 TrackingAction::TrackingAction(EventAction* ev << 46 TrackingAction::TrackingAction(HistoManager* histo, 50 << 47 RunAction* RA, EventAction* EA) >> 48 :histoManager(histo),run(RA),event(EA) 51 { 49 { 52 fTrackMessenger = new TrackingMessenger(this << 50 fullChain = false; >> 51 trackMessenger = new TrackingMessenger(this); 53 } 52 } 54 53 55 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 55 57 TrackingAction::~TrackingAction() 56 TrackingAction::~TrackingAction() 58 { 57 { 59 delete fTrackMessenger; << 58 delete trackMessenger; 60 } << 61 << 62 //....oooOO0OOooo........oooOO0OOooo........oo << 63 << 64 void TrackingAction::SetTimeWindow(G4double t1 << 65 { << 66 fTimeWindow1 = t1; << 67 fTimeWindow2 = fTimeWindow1 + dt; << 68 } 59 } 69 60 70 //....oooOO0OOooo........oooOO0OOooo........oo 61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 62 72 void TrackingAction::PreUserTrackingAction(con 63 void TrackingAction::PreUserTrackingAction(const G4Track* track) 73 { 64 { 74 Run* run = static_cast<Run*>(G4RunManager::G << 75 << 76 G4ParticleDefinition* particle = track->GetD 65 G4ParticleDefinition* particle = track->GetDefinition(); 77 G4String name = particle->GetParticleName(); << 66 G4String name = particle->GetParticleName(); 78 fCharge = particle->GetPDGCharge(); << 67 charge = particle->GetPDGCharge(); 79 fMass = particle->GetPDGMass(); << 68 mass = particle->GetPDGMass(); 80 << 69 81 G4double Ekin = track->GetKineticEnergy(); 70 G4double Ekin = track->GetKineticEnergy(); 82 G4int ID = track->GetTrackID(); << 71 G4int ID = track->GetTrackID(); 83 << 72 84 G4bool condition = false; << 73 G4bool condition = false; 85 << 74 86 // check LifeTime << 75 //count particles 87 // << 76 // 88 G4double meanLife = particle->GetPDGLifeTime << 77 run->ParticleCount(name, Ekin); 89 << 78 90 // count particles << 79 //energy spectrum 91 // << 92 run->ParticleCount(name, Ekin, meanLife); << 93 << 94 // energy spectrum << 95 // 80 // 96 G4int ih = 0; 81 G4int ih = 0; 97 if (particle == G4Electron::Electron() || pa << 82 if (particle == G4Electron::Electron()|| 98 ih = 1; << 83 particle == G4Positron::Positron()) ih = 1; 99 else if (particle == G4NeutrinoE::NeutrinoE( << 84 else if (particle == G4NeutrinoE::NeutrinoE()|| 100 ih = 2; << 85 particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2; 101 else if (particle == G4Gamma::Gamma()) << 86 else if (particle == G4Gamma::Gamma()) ih = 3; 102 ih = 3; << 87 else if (particle == G4Alpha::Alpha()) ih = 4; 103 else if (particle == G4Alpha::Alpha()) << 88 else if (charge > 2.) ih = 5; 104 ih = 4; << 89 if (ih) histoManager->FillHisto(ih, Ekin); 105 else if (fCharge > 2.) << 90 106 ih = 5; << 91 //fullChain: stop ion and print decay chain 107 if (ih) G4AnalysisManager::Instance()->FillH << 92 // 108 << 93 if (charge > 2.) { 109 // Ion << 94 G4Track* tr = (G4Track*) track; 110 // << 95 if (fullChain) tr->SetTrackStatus(fStopButAlive); 111 if (fCharge > 2.) { << 96 if (ID == 1) event->AddDecayChain(name); 112 // build decay chain << 97 else event->AddDecayChain(" ---> " + name); 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 } 98 } 129 << 99 130 // example of saving random number seed of t << 100 //example of saving random number seed of this event, under condition 131 // 101 // 132 ////condition = (ih == 3); 102 ////condition = (ih == 3); 133 if (condition) G4RunManager::GetRunManager() 103 if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent(); 134 } 104 } 135 105 136 //....oooOO0OOooo........oooOO0OOooo........oo 106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 137 107 138 void TrackingAction::PostUserTrackingAction(co 108 void TrackingAction::PostUserTrackingAction(const G4Track* track) 139 { 109 { 140 // keep only ions << 110 //keep only ions 141 // 111 // 142 if (fCharge < 3.) return; << 112 if (charge < 3. ) return; 143 << 144 Run* run = static_cast<Run*>(G4RunManager::G << 145 << 146 G4AnalysisManager* analysis = G4AnalysisMana << 147 113 148 // get time << 114 //get time 149 // << 115 // 150 G4double time = track->GetGlobalTime(); 116 G4double time = track->GetGlobalTime(); 151 G4int ID = track->GetTrackID(); << 117 152 if (ID == 1) run->PrimaryTiming(time); // t << 118 //energy and momentum balance (from secondaries) 153 fTimeEnd = time; << 154 << 155 // energy and momentum balance (from seconda << 156 // 119 // 157 const std::vector<const G4Track*>* secondari << 120 G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries(); 158 size_t nbtrk = (*secondaries).size(); 121 size_t nbtrk = (*secondaries).size(); 159 if (nbtrk) { 122 if (nbtrk) { 160 // there are secondaries --> it is a decay << 123 //there are secondaries --> it is a decay >> 124 // >> 125 //force 'single' decay >> 126 G4int ID = track->GetTrackID(); >> 127 if ((!fullChain)&&(ID > 1)) G4RunManager::GetRunManager()->AbortEvent(); 161 // 128 // 162 // balance << 129 //balance 163 G4double EkinTot = 0., EkinVis = 0.; << 130 G4double Ebalance = - track->GetTotalEnergy(); 164 G4ThreeVector Pbalance = -track->GetMoment << 131 G4ThreeVector Pbalance = - track->GetMomentum(); 165 for (size_t itr = 0; itr < nbtrk; itr++) { << 132 for (size_t itr=0; itr<nbtrk; itr++) { 166 const G4Track* trk = (*secondaries)[itr] << 133 G4Track* trk = (*secondaries)[itr]; 167 G4ParticleDefinition* particle = trk->Ge << 134 Ebalance += trk->GetTotalEnergy(); 168 G4double Ekin = trk->GetKineticEnergy(); << 135 //exclude gamma desexcitation from momentum balance 169 EkinTot += Ekin; << 136 if (trk->GetDefinition() != G4Gamma::Gamma()) 170 G4bool visible = << 137 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 } 138 } 176 G4double Pbal = Pbalance.mag(); << 139 G4double Pbal = Pbalance.mag(); 177 run->Balance(EkinTot, Pbal); << 140 run->Balance(Ebalance,Pbal); 178 analysis->FillH1(6, EkinTot); << 141 histoManager->FillHisto(6,Ebalance); 179 analysis->FillH1(7, Pbal); << 142 histoManager->FillHisto(7,Pbal); 180 fEvent->AddEvisible(EkinVis); << 181 } 143 } 182 << 144 183 // no secondaries --> end of chain << 145 //no secondaries --> end of chain 184 // << 146 // 185 if (!nbtrk) { 147 if (!nbtrk) { 186 run->EventTiming(time); // total time of << 148 run->EventTiming(time); //time of life 187 G4double weight = track->GetWeight(); << 149 histoManager->FillHisto(8,time); 188 analysis->FillH1(8, time, weight); << 150 histoManager->FillHisto(9,time); //activity 189 //// analysis->FillH1(8,time); << 190 fTimeEnd = DBL_MAX; << 191 } 151 } 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 } 152 } 204 153 205 //....oooOO0OOooo........oooOO0OOooo........oo 154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 155 206 156