Geant4  10.03.p03
 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 // $Id: TrackingAction.cc 98257 2016-07-04 17:39:46Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "TrackingAction.hh"
35 
36 #include "HistoManager.hh"
37 #include "Run.hh"
38 #include "EventAction.hh"
39 #include "TrackingMessenger.hh"
40 
41 #include "G4Track.hh"
42 #include "G4ParticleTypes.hh"
43 #include "G4RunManager.hh"
44 
45 #include "G4SystemOfUnits.hh"
46 #include "G4UnitsTable.hh"
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
52  fEvent(EA),fTrackMessenger(0),
53  fFullChain(true)
54 
55 {
56  fTrackMessenger = new TrackingMessenger(this);
57 
58  fTimeWindow1 = fTimeWindow2 = 0.;
59 }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  delete fTrackMessenger;
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
71 {
72  fTimeWindow1 = t1;
73  fTimeWindow2 = fTimeWindow1 + dt;
74 }
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
79 {
80  Run* run
82 
83  G4ParticleDefinition* particle = track->GetDefinition();
84  G4String name = particle->GetParticleName();
85  fCharge = particle->GetPDGCharge();
86  fMass = particle->GetPDGMass();
87 
88  G4double Ekin = track->GetKineticEnergy();
89  G4int ID = track->GetTrackID();
90 
91  G4bool condition = false;
92 
93  //count particles
94  //
95  if (ID>1) run->ParticleCount(name, Ekin);
96 
97  //energy spectrum
98  //
99  G4int ih = 0;
100  if (particle == G4Electron::Electron()||
101  particle == G4Positron::Positron()) ih = 1;
102  else if (particle == G4NeutrinoE::NeutrinoE()||
103  particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
104  else if (particle == G4Gamma::Gamma()) ih = 3;
105  else if (particle == G4Alpha::Alpha()) ih = 4;
106  else if (fCharge > 2.) ih = 5;
107  if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
108 
109  //Ion
110  //
111  if (fCharge > 2.) {
112  //build decay chain
113  if (ID == 1) fEvent->AddDecayChain(name);
114  else fEvent->AddDecayChain(" ---> " + name);
115  //
116  //full chain: put at rest; if not: kill secondary
117  G4Track* tr = (G4Track*) track;
118  if (fFullChain) tr->SetTrackStatus(fStopButAlive);
119  else if (ID>1) tr->SetTrackStatus(fStopAndKill);
120  //
121  fTime_birth = track->GetGlobalTime();
122  }
123 
124  //example of saving random number seed of this fEvent, under condition
125  //
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
133 {
134  //keep only ions
135  //
136  if (fCharge < 3. ) return;
137 
138  Run* run
140 
141  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
142 
143  //get time
144  //
145  G4double time = track->GetGlobalTime();
146  G4int ID = track->GetTrackID();
147  if (ID == 1) run->PrimaryTiming(time); //time of life of primary ion
148  fTime_end = time;
149 
150  //energy and momentum balance (from secondaries)
151  //
152  const std::vector<const G4Track*>* secondaries
153  = track->GetStep()->GetSecondaryInCurrentStep();
154  size_t nbtrk = (*secondaries).size();
155  if (nbtrk) {
156  //there are secondaries --> it is a decay
157  //
158  //balance
159  G4double EkinTot = 0., EkinVis = 0.;
160  G4ThreeVector Pbalance = - track->GetMomentum();
161  for (size_t itr=0; itr<nbtrk; itr++) {
162  const G4Track* trk = (*secondaries)[itr];
163  G4ParticleDefinition* particle = trk->GetDefinition();
164  G4double Ekin = trk->GetKineticEnergy();
165  EkinTot += Ekin;
166  G4bool visible = !((particle == G4NeutrinoE::NeutrinoE())||
167  (particle == G4AntiNeutrinoE::AntiNeutrinoE()));
168  if (visible) EkinVis += Ekin;
169  //exclude gamma desexcitation from momentum balance
170  if (particle != G4Gamma::Gamma()) Pbalance += trk->GetMomentum();
171  }
172  G4double Pbal = Pbalance.mag();
173  run->Balance(EkinTot,Pbal);
174  analysis->FillH1(6,EkinTot);
175  analysis->FillH1(7,Pbal);
176  fEvent->AddEvisible(EkinVis);
177  }
178 
179  //no secondaries --> end of chain
180  //
181  if (!nbtrk) {
182  run->EventTiming(time); //total time of life
183  analysis->FillH1(8,time);
184  fTime_end = DBL_MAX;
185  }
186 
187  //count activity in time window
188  //
189  run->SetTimeWindow(fTimeWindow1, fTimeWindow2);
190 
191  G4String name = track->GetDefinition()->GetParticleName();
192  G4bool life1(false), life2(false), decay(false);
193  if ((fTime_birth <= fTimeWindow1)&&(fTime_end > fTimeWindow1)) life1 = true;
194  if ((fTime_birth <= fTimeWindow2)&&(fTime_end > fTimeWindow2)) life2 = true;
195  if ((fTime_end > fTimeWindow1)&&(fTime_end < fTimeWindow2)) decay = true;
196  if (life1||life2||decay) run->CountInTimeWindow(name,life1,life2,decay);
197 }
198 
199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
200 
G4double condition(const G4ErrorSymMatrix &m)
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4ParticleDefinition * GetDefinition() const
const XML_Char * name
Definition: expat.h:151
void AddEvisible(G4double val)
Definition: EventAction.hh:53
void PrimaryTiming(G4double)
Definition: Run.cc:147
void CountInTimeWindow(G4String, G4bool, G4bool, G4bool)
Definition: Run.cc:97
Definition of the TrackingMessenger class.
void EventTiming(G4double)
Definition: Run.cc:136
Event action class.
Definition: EventAction.hh:45
void Balance(G4double)
Definition: Run.cc:133
const G4Step * GetStep() const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
void SetTimeWindow(G4double, G4double)
Definition: Run.cc:89
static G4AntiNeutrinoE * AntiNeutrinoE()
G4double GetKineticEnergy() const
void PreUserTrackingAction(const G4Track *)
ParticleList decay(Cluster *const c)
Carries out a cluster decay.
void SetTimeWindow(G4double, G4double)
bool G4bool
Definition: G4Types.hh:79
virtual void rndmSaveThisEvent()
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:79
G4ThreeVector GetMomentum() const
static G4NeutrinoE * NeutrinoE()
Definition: G4NeutrinoE.cc:85
static G4Positron * Positron()
Definition: G4Positron.cc:94
G4double GetPDGMass() const
tuple t1
Definition: plottest35.py:33
static G4Electron * Electron()
Definition: G4Electron.cc:94
static G4Alpha * Alpha()
Definition: G4Alpha.cc:89
void AddDecayChain(G4String val)
Definition: EventAction.hh:52
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4double GetPDGCharge() const
double mag() const
#define DBL_MAX
Definition: templates.hh:83
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
G4Run * GetNonConstCurrentRun() const
void ParticleCount(G4String, G4double)
Definition: Run.cc:114