Geant4_10
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: TrackingAction.cc 71485 2013-06-17 08:14:54Z gcosmo $
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 
50  fRun(RA),fEvent(EA),fTrackMessenger(0),
51  fFullChain(false)
52 
53 {
54  fTrackMessenger = new TrackingMessenger(this);
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  delete fTrackMessenger;
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  G4ParticleDefinition* particle = track->GetDefinition();
69  G4String name = particle->GetParticleName();
70  fCharge = particle->GetPDGCharge();
71  fMass = particle->GetPDGMass();
72 
73  G4double Ekin = track->GetKineticEnergy();
74  G4int ID = track->GetTrackID();
75 
76  G4bool condition = false;
77 
78  //count particles
79  //
80  fRun->ParticleCount(name, Ekin);
81 
82  //energy spectrum
83  //
84  G4int ih = 0;
85  if (particle == G4Electron::Electron()||
86  particle == G4Positron::Positron()) ih = 1;
87  else if (particle == G4NeutrinoE::NeutrinoE()||
88  particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
89  else if (particle == G4Gamma::Gamma()) ih = 3;
90  else if (particle == G4Alpha::Alpha()) ih = 4;
91  else if (fCharge > 2.) ih = 5;
92  if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
93 
94  //fFullChain: stop ion and print decay chain
95  //
96  if (fCharge > 2.) {
97  G4Track* tr = (G4Track*) track;
98  if (fFullChain) tr->SetTrackStatus(fStopButAlive);
99  if (ID == 1) fEvent->AddDecayChain(name);
100  else fEvent->AddDecayChain(" ---> " + name);
101  }
102 
103  //example of saving random number seed of this fEvent, under condition
104  //
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
112 {
113  //keep only ions
114  //
115  if (fCharge < 3. ) return;
116 
117  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
118 
119  //get time
120  //
121  G4double time = track->GetGlobalTime();
122  G4int ID = track->GetTrackID();
123  if (ID == 1) fRun->PrimaryTiming(time); //time of life of primary ion
124 
125  //energy and momentum balance (from secondaries)
126  //
127  const std::vector<const G4Track*>* secondaries
128  = track->GetStep()->GetSecondaryInCurrentStep();
129  size_t nbtrk = (*secondaries).size();
130  if (nbtrk) {
131  //there are secondaries --> it is a decay
132  //
133  //balance
134  G4double EkinTot = 0.;
135  G4ThreeVector Pbalance = - track->GetMomentum();
136  for (size_t itr=0; itr<nbtrk; itr++) {
137  const 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 
G4double condition(const G4ErrorSymMatrix &m)
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4ParticleDefinition * GetDefinition() const
Definition of the TrackingMessenger class.
const XML_Char * name
Definition: expat.h:151
const G4Step * GetStep() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static G4AntiNeutrinoE * AntiNeutrinoE()
void PrimaryTiming(G4double)
Definition: RunAction.cc:127
G4double GetKineticEnergy() const
void PreUserTrackingAction(const G4Track *)
bool G4bool
Definition: G4Types.hh:79
virtual void rndmSaveThisEvent()
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
G4int GetTrackID() const
const std::vector< const G4Track * > * GetSecondaryInCurrentStep() const
Definition: G4Step.cc:193
G4double GetGlobalTime() const
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
void PostUserTrackingAction(const G4Track *)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4ThreeVector GetMomentum() const
static G4NeutrinoE * NeutrinoE()
Definition: G4NeutrinoE.cc:85
static G4Positron * Positron()
Definition: G4Positron.cc:94
G4double GetPDGMass() const
void ParticleCount(G4String, G4double)
Definition: RunAction.cc:90
void EventTiming(G4double)
Definition: RunAction.cc:116
static G4Electron * Electron()
Definition: G4Electron.cc:94
static G4Alpha * Alpha()
Definition: G4Alpha.cc:89
void AddDecayChain(G4String val)
Definition: EventAction.hh:55
double G4double
Definition: G4Types.hh:76
void Balance(G4double)
Definition: RunAction.cc:110
G4double GetPDGCharge() const
double mag() const