Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackingAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 // $Id$
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "TrackingAction.hh"
36 #include "RunAction.hh"
37 #include "HistoManager.hh"
38 #include "RunAction.hh"
39 #include "EventAction.hh"
40 #include "TrackingMessenger.hh"
41 
42 #include "G4Track.hh"
43 #include "G4ParticleTypes.hh"
44 #include "G4RunManager.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 :fRun(RA),fEvent(EA)
50 {
51  fullChain = false;
52  fTrackMessenger = new TrackingMessenger(this);
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 {
59  delete fTrackMessenger;
60 }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  G4ParticleDefinition* particle = track->GetDefinition();
67  G4String name = particle->GetParticleName();
68  fCharge = particle->GetPDGCharge();
69  fMass = particle->GetPDGMass();
70 
71  G4double Ekin = track->GetKineticEnergy();
72  G4int ID = track->GetTrackID();
73 
74  G4bool condition = false;
75 
76  //count particles
77  //
78  fRun->ParticleCount(name, Ekin);
79 
80  //energy spectrum
81  //
82  G4int ih = 0;
83  if (particle == G4Electron::Electron()||
84  particle == G4Positron::Positron()) ih = 1;
85  else if (particle == G4NeutrinoE::NeutrinoE()||
86  particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
87  else if (particle == G4Gamma::Gamma()) ih = 3;
88  else if (particle == G4Alpha::Alpha()) ih = 4;
89  else if (fCharge > 2.) ih = 5;
90  if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
91 
92  //fullChain: stop ion and print decay chain
93  //
94  if (fCharge > 2.) {
95  G4Track* tr = (G4Track*) track;
96  if (fullChain) tr->SetTrackStatus(fStopButAlive);
97  if (ID == 1) fEvent->AddDecayChain(name);
98  else fEvent->AddDecayChain(" ---> " + name);
99  }
100 
101  //example of saving random number seed of this fEvent, under condition
102  //
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 
110 {
111  //keep only ions
112  //
113  if (fCharge < 3. ) return;
114 
115  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
116 
117  //get time
118  //
119  G4double time = track->GetGlobalTime();
120  G4int ID = track->GetTrackID();
121  if (ID == 1) fRun->PrimaryTiming(time); //time of life of primary ion
122 
123  //energy and momentum balance (from secondaries)
124  //
126  size_t nbtrk = (*secondaries).size();
127  if (nbtrk) {
128  //there are secondaries --> it is a decay
129  //
130  //force 'single' decay
131  if ((!fullChain)&&(ID > 1)) G4RunManager::GetRunManager()->AbortEvent();
132  //
133  //balance
134  G4double EkinTot = 0.;
135  G4ThreeVector Pbalance = - track->GetMomentum();
136  for (size_t itr=0; itr<nbtrk; itr++) {
137  G4Track* trk = (*secondaries)[itr];
138  EkinTot += trk->GetKineticEnergy();
139  //exclude gamma desexcitation from momentum balance
140  if (trk->GetDefinition() != G4Gamma::Gamma())
141  Pbalance += trk->GetMomentum();
142  }
143  G4double Pbal = Pbalance.mag();
144  fRun->Balance(EkinTot,Pbal);
145  analysis->FillH1(6,EkinTot);
146  analysis->FillH1(7,Pbal);
147  }
148 
149  //no secondaries --> end of chain
150  //
151  if (!nbtrk) {
152  fRun->EventTiming(time); //total time of life
153  analysis->FillH1(8,time);
154  }
155 }
156 
157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158