Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extended/electromagnetic/TestEm5/src/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 //
26 /// \file electromagnetic/TestEm5/src/TrackingAction.cc
27 /// \brief Implementation of the TrackingAction class
28 //
29 //
30 // $Id: TrackingAction.cc 76464 2013-11-11 10:22:56Z 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 { }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {
57  // few initialisations
58  //
59  if (aTrack->GetTrackID() == 1) {
60  fXstartAbs = fDetector->GetxstartAbs();
61  fXendAbs = fDetector->GetxendAbs();
62  fPrimaryCharge = aTrack->GetDefinition()->GetPDGCharge();
63  }
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
71 
72  Run* run = static_cast<Run*>(
74 
76  G4ThreeVector vertex = aTrack->GetVertexPosition();
77  G4double charge = aTrack->GetDefinition()->GetPDGCharge();
78 
79  G4bool transmit = ((position.x() >= fXendAbs) && (vertex.x() < fXendAbs));
80  G4bool reflect = (position.x() <= fXstartAbs);
81  G4bool notabsor = (transmit || reflect);
82 
83  //transmitted + reflected particles counter
84  //
85  G4int flag = 0;
86  if (charge == fPrimaryCharge) flag = 1;
87  if (aTrack->GetTrackID() == 1) flag = 2;
88  if (transmit) fEventAction->SetTransmitFlag(flag);
89  if (reflect) fEventAction->SetReflectFlag(flag);
90 
91  //
92  //histograms
93  //
94  G4bool charged = (charge != 0.);
95  G4bool neutral = !charged;
96 
97  //energy spectrum at exit
98  //
99  G4int id = 0;
100  if (transmit && charged) id = 10;
101  else if (transmit && neutral) id = 20;
102  else if (reflect && charged) id = 30;
103  else if (reflect && neutral) id = 40;
104 
105  if (id>0)
106  analysisManager->FillH1(id, aTrack->GetKineticEnergy());
107 
108  //energy leakage
109  //
110  if (notabsor) {
111  G4int trackID = aTrack->GetTrackID();
112  G4int index = 0; if (trackID > 1) index = 1; //primary=0, secondaries=1
113  G4double eleak = aTrack->GetKineticEnergy();
114  if ((aTrack->GetDefinition() == G4Positron::Positron()) && (trackID > 1))
115  eleak += 2*electron_mass_c2;
116  run->AddEnergyLeak(eleak,index);
117  }
118 
119  //space angle distribution at exit : dN/dOmega
120  //
121  G4ThreeVector direction = aTrack->GetMomentumDirection();
122  id = 0;
123  if (transmit && charged) id = 12;
124  else if (transmit && neutral) id = 22;
125  else if (reflect && charged) id = 32;
126  else if (reflect && neutral) id = 42;
127 
128  if (id>0) {
129  G4double theta = std::acos(direction.x());
130  if (theta > 0.0) {
131  G4double dteta = analysisManager->GetH1Width(id);
132  G4double unit = analysisManager->GetH1Unit(id);
133  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
134  /*
135  G4cout << "theta, dteta, unit, weight: "
136  << theta << " "
137  << dteta << " "
138  << unit << " "
139  << weight << G4endl;
140  */
141  analysisManager->FillH1(id,theta,weight);
142  }
143  }
144 
145  //energy fluence at exit : dE(MeV)/dOmega
146  //
147  id = 0;
148  if (transmit && charged) id = 11;
149  else if (transmit && neutral) id = 21;
150  else if (reflect && charged) id = 31;
151  else if (reflect && neutral) id = 41;
152 
153  if (id>0) {
154  G4double theta = std::acos(direction.x());
155  if (theta > 0.0) {
156  G4double dteta = analysisManager->GetH1Width(id);
157  G4double unit = analysisManager->GetH1Unit(id);
158  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
159  weight *= (aTrack->GetKineticEnergy()/MeV);
160  analysisManager->FillH1(id,theta,weight);
161  }
162  }
163 
164  //projected angles distribution at exit
165  //
166  id = 0;
167  if (transmit && charged) id = 13;
168  else if (transmit && neutral) id = 23;
169  else if (reflect && charged) id = 33;
170  else if (reflect && neutral) id = 43;
171 
172  if (id>0) {
173  if (direction.x() != 0.0) {
174  G4double tet = std::atan(direction.y()/std::fabs(direction.x()));
175  analysisManager->FillH1(id,tet);
176  if (transmit && (flag == 2)) run->AddMscProjTheta(tet);
177 
178  tet = std::atan(direction.z()/std::fabs(direction.x()));
179  analysisManager->FillH1(id,tet);
180  if (transmit && (flag == 2)) run->AddMscProjTheta(tet);
181  }
182  }
183 
184  //projected position and radius at exit
185  //
186  id = 0;
187  if (transmit && charged) id = 14;
188 
189  if (id>0) {
190  G4double y = position.y(), z = position.z();
191  G4double r = std::sqrt(y*y + z*z);
192  analysisManager->FillH1(id, y);
193  analysisManager->FillH1(id, z);
194  analysisManager->FillH1(id+1, r);
195  }
196 
197  //x-vertex of charged secondaries
198  //
199  if ((aTrack->GetParentID() == 1) && charged) {
200  G4double xVertex = (aTrack->GetVertexPosition()).x();
201  analysisManager->FillH1(6, xVertex);
202  if (notabsor) analysisManager->FillH1(7, xVertex);
203  }
204 }
205 
206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
207 
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
double x() const
G4double z
Definition: TRTMaterials.hh:39
const G4ThreeVector & GetPosition() const
int G4int
Definition: G4Types.hh:78
double z() const
G4double GetKineticEnergy() const
void PreUserTrackingAction(const G4Track *)
bool G4bool
Definition: G4Types.hh:79
void AddMscProjTheta(G4double theta)
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
float electron_mass_c2
Definition: hepunit.py:274
G4int GetTrackID() const
void PostUserTrackingAction(const G4Track *)
const G4ThreeVector & GetVertexPosition() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static G4Positron * Positron()
Definition: G4Positron.cc:94
const G4ThreeVector & GetMomentumDirection() const
double y() const
double G4double
Definition: G4Types.hh:76
G4double GetPDGCharge() const
G4Run * GetNonConstCurrentRun() const
void AddEnergyLeak(G4double eleak, G4int index)