Geant4  10.02
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 94333 2015-11-12 09:57:47Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "TrackingAction.hh"
36 
37 #include "DetectorConstruction.hh"
38 #include "Run.hh"
39 #include "EventAction.hh"
40 #include "HistoManager.hh"
41 
42 #include "G4RunManager.hh"
43 #include "G4Track.hh"
44 #include "G4PhysicalConstants.hh"
45 #include "G4SystemOfUnits.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
50 :G4UserTrackingAction(),fDetector(DET), fEventAction(EA)
51 {
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 {
59  // few initialisations
60  //
61  if (aTrack->GetTrackID() == 1) {
65  fDirX = aTrack->GetMomentumDirection().x();
66  }
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72 {
73  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
74 
75  Run* run = static_cast<Run*>(
77 
79  G4ThreeVector vertex = aTrack->GetVertexPosition();
80  G4double charge = aTrack->GetDefinition()->GetPDGCharge();
81  G4double energy = aTrack->GetKineticEnergy();
82 
83  G4bool transmit = (((fDirX >= 0.0 && position.x() >= fXendAbs) ||
84  (fDirX < 0.0 && position.x() <= fXstartAbs))
85  && energy > 0.0);
86  G4bool reflect = (((fDirX >= 0.0 && position.x() <= fXstartAbs) ||
87  (fDirX < 0.0 && position.x() <= fXendAbs))
88  && energy > 0.0);
89  G4bool notabsor = (transmit || reflect);
90 
91  //transmitted + reflected particles counter
92  //
93  G4int flag = 0;
94  if (charge == fPrimaryCharge) flag = 1;
95  if (aTrack->GetTrackID() == 1) flag = 2;
96  if (transmit) fEventAction->SetTransmitFlag(flag);
97  if (reflect) fEventAction->SetReflectFlag(flag);
98 
99  //
100  //histograms
101  //
102  G4bool charged = (charge != 0.);
103  G4bool neutral = !charged;
104 
105  //energy spectrum at exit
106  //zero energy charged particle are not taken into account
107  //
108  G4int id = 0;
109  if (transmit && charged) id = 10;
110  else if (transmit && neutral) id = 20;
111  else if (reflect && charged) id = 30;
112  else if (reflect && neutral) id = 40;
113 
114  if (id>0) { analysisManager->FillH1(id, energy); }
115 
116  //energy leakage
117  //
118  if (notabsor) {
119  G4int trackID = aTrack->GetTrackID();
120  G4int index = 0; if (trackID > 1) index = 1; //primary=0, secondaries=1
121  G4double eleak = aTrack->GetKineticEnergy();
122  if ((aTrack->GetDefinition() == G4Positron::Positron()) && (trackID > 1))
123  eleak += 2*electron_mass_c2;
124  run->AddEnergyLeak(eleak,index);
125  }
126 
127  //space angle distribution at exit : dN/dOmega
128  //
129  G4ThreeVector direction = aTrack->GetMomentumDirection();
130  id = 0;
131  if (transmit && charged) id = 12;
132  else if (transmit && neutral) id = 22;
133  else if (reflect && charged) id = 32;
134  else if (reflect && neutral) id = 42;
135 
136  if (id>0) {
137  G4double theta = std::acos(direction.x());
138  if (theta > 0.0) {
139  G4double dteta = analysisManager->GetH1Width(id);
140  G4double unit = analysisManager->GetH1Unit(id);
141  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
142  /*
143  G4cout << "theta, dteta, unit, weight: "
144  << theta << " "
145  << dteta << " "
146  << unit << " "
147  << weight << G4endl;
148  */
149  analysisManager->FillH1(id,theta,weight);
150  }
151  }
152 
153  //energy fluence at exit : dE(MeV)/dOmega
154  //
155  id = 0;
156  if (transmit && charged) id = 11;
157  else if (reflect && charged) id = 31;
158  else if (transmit && neutral) id = 21;
159  else if (reflect && neutral) id = 41;
160 
161  if (id>0) {
162  G4double theta = std::acos(direction.x());
163  if (theta > 0.0) {
164  G4double dteta = analysisManager->GetH1Width(id);
165  G4double unit = analysisManager->GetH1Unit(id);
166  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
167  weight *= (aTrack->GetKineticEnergy()/MeV);
168  analysisManager->FillH1(id,theta,weight);
169  }
170  }
171 
172  //projected angles distribution at exit
173  //
174  id = 0;
175  if (transmit && charged) id = 13;
176  else if (transmit && neutral) id = 23;
177  else if (reflect && charged) id = 33;
178  else if (reflect && neutral) id = 43;
179 
180  if (id>0) {
181  if (direction.x() != 0.0) {
182  G4double tet = std::atan(direction.y()/std::fabs(direction.x()));
183  analysisManager->FillH1(id,tet);
184  if (transmit && (flag == 2)) run->AddMscProjTheta(tet);
185 
186  tet = std::atan(direction.z()/std::fabs(direction.x()));
187  analysisManager->FillH1(id,tet);
188  if (transmit && (flag == 2)) run->AddMscProjTheta(tet);
189  }
190  }
191 
192  //projected position and radius at exit
193  //
194  if (transmit && energy > 0.0) {
195  G4double y = position.y(), z = position.z();
196  G4double r = std::sqrt(y*y + z*z);
197  analysisManager->FillH1(14, y);
198  analysisManager->FillH1(14, z);
199  analysisManager->FillH1(15, r);
200  }
201 
202  //x-vertex of charged secondaries
203  //
204  if ((aTrack->GetParentID() == 1) && charged && energy > 0.0) {
205  G4double xVertex = (aTrack->GetVertexPosition()).x();
206  analysisManager->FillH1(6, xVertex);
207  if (notabsor) analysisManager->FillH1(7, xVertex);
208  }
209 }
210 
211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212 
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
EventAction * fEventAction
void SetReflectFlag(G4int flag)
Definition: EventAction.hh:61
static const double MeV
Definition: G4SIunits.hh:211
G4double fXstartAbs
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
const G4ThreeVector & GetPosition() const
Event action class.
Definition: EventAction.hh:45
int G4int
Definition: G4Types.hh:78
G4double GetKineticEnergy() const
#define position
Definition: xmlparse.cc:622
void PreUserTrackingAction(const G4Track *)
bool G4bool
Definition: G4Types.hh:79
void AddMscProjTheta(G4double theta)
Definition: Run.hh:69
static const double twopi
Definition: G4SIunits.hh:75
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
void SetTransmitFlag(G4int flag)
Definition: EventAction.hh:59
G4int GetTrackID() const
void PostUserTrackingAction(const G4Track *)
const G4ThreeVector & GetVertexPosition() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4Positron * Positron()
Definition: G4Positron.cc:94
const G4ThreeVector & GetMomentumDirection() const
G4double energy(const ThreeVector &p, const G4double m)
const G4double x[NPOINTSGL]
Detector construction class to demonstrate various ways of placement.
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4double GetPDGCharge() const
G4double fPrimaryCharge
G4Run * GetNonConstCurrentRun() const
DetectorConstruction * fDetector
void AddEnergyLeak(G4double eleak, G4int index)
Definition: Run.hh:93