Geant4  10.01.p03
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 78307 2013-12-11 10:55:57Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "TrackingAction.hh"
36 
37 #include "HistoManager.hh"
38 #include "Run.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  fEvent(EA),fTrackMessenger(0),
51  fFullChain(true)
52 
53 {
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  delete fTrackMessenger;
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  Run* run
70 
71  G4ParticleDefinition* particle = track->GetDefinition();
72  G4String name = particle->GetParticleName();
73  fCharge = particle->GetPDGCharge();
74  fMass = particle->GetPDGMass();
75 
76  G4double Ekin = track->GetKineticEnergy();
77  G4int ID = track->GetTrackID();
78 
79  G4bool condition = false;
80 
81  //count particles
82  //
83  if (ID>1) run->ParticleCount(name, Ekin);
84 
85  //energy spectrum
86  //
87  G4int ih = 0;
88  if (particle == G4Electron::Electron()||
89  particle == G4Positron::Positron()) ih = 1;
90  else if (particle == G4NeutrinoE::NeutrinoE()||
91  particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
92  else if (particle == G4Gamma::Gamma()) ih = 3;
93  else if (particle == G4Alpha::Alpha()) ih = 4;
94  else if (fCharge > 2.) ih = 5;
95  if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
96 
97  //Ion
98  //
99  if (fCharge > 2.) {
100  //build decay chain
101  if (ID == 1) fEvent->AddDecayChain(name);
102  else fEvent->AddDecayChain(" ---> " + name);
103  //
104  //full chain: put at rest; if not: kill secondary
105  G4Track* tr = (G4Track*) track;
107  else if (ID>1) tr->SetTrackStatus(fStopAndKill);
108  }
109 
110  //example of saving random number seed of this fEvent, under condition
111  //
114 }
115 
116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
117 
119 {
120  //keep only ions
121  //
122  if (fCharge < 3. ) return;
123 
124  Run* run
126 
127  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
128 
129  //get time
130  //
131  G4double time = track->GetGlobalTime();
132  G4int ID = track->GetTrackID();
133  if (ID == 1) run->PrimaryTiming(time); //time of life of primary ion
134 
135  //energy and momentum balance (from secondaries)
136  //
137  const std::vector<const G4Track*>* secondaries
138  = track->GetStep()->GetSecondaryInCurrentStep();
139  size_t nbtrk = (*secondaries).size();
140  if (nbtrk) {
141  //there are secondaries --> it is a decay
142  //
143  //balance
144  G4double EkinTot = 0.;
145  G4ThreeVector Pbalance = - track->GetMomentum();
146  for (size_t itr=0; itr<nbtrk; itr++) {
147  const G4Track* trk = (*secondaries)[itr];
148  EkinTot += trk->GetKineticEnergy();
149  //exclude gamma desexcitation from momentum balance
150  if (trk->GetDefinition() != G4Gamma::Gamma())
151  Pbalance += trk->GetMomentum();
152  }
153  G4double Pbal = Pbalance.mag();
154  run->Balance(EkinTot,Pbal);
155  analysis->FillH1(6,EkinTot);
156  analysis->FillH1(7,Pbal);
157  }
158 
159  //no secondaries --> end of chain
160  //
161  if (!nbtrk) {
162  run->EventTiming(time); //total time of life
163  analysis->FillH1(8,time);
164  }
165 }
166 
167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168 
G4double condition(const G4ErrorSymMatrix &m)
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4ParticleDefinition * GetDefinition() const
void PrimaryTiming(G4double)
Definition: Run.cc:117
CLHEP::Hep3Vector G4ThreeVector
Definition of the TrackingMessenger class.
G4String name
Definition: TRTMaterials.hh:40
void EventTiming(G4double)
Definition: Run.cc:106
void Balance(G4double)
Definition: Run.cc:133
const G4Step * GetStep() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static G4AntiNeutrinoE * AntiNeutrinoE()
G4double GetKineticEnergy() const
void PreUserTrackingAction(const G4Track *)
bool G4bool
Definition: G4Types.hh:79
virtual void rndmSaveThisEvent()
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:61
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 *)
EventAction * fEvent
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4ThreeVector GetMomentum() const
static G4NeutrinoE * NeutrinoE()
Definition: G4NeutrinoE.cc:85
static G4Positron * Positron()
Definition: G4Positron.cc:94
G4double GetPDGMass() const
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
Definition: Run.hh:46
G4double GetPDGCharge() const
G4Run * GetNonConstCurrentRun() const
TrackingMessenger * fTrackMessenger
void ParticleCount(G4String, G4double)
Definition: Run.cc:114