Geant4  9.6.p02
 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 //
30 // $Id$
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "TrackingAction.hh"
36 
37 #include "DetectorConstruction.hh"
38 #include "RunAction.hh"
39 #include "EventAction.hh"
40 #include "HistoManager.hh"
41 
42 #include "G4Track.hh"
43 #include "G4PhysicalConstants.hh"
44 #include "G4SystemOfUnits.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49  EventAction* EA)
50 :fDetector(DET), fRunAction(RA), 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 
73  G4ThreeVector vertex = aTrack->GetVertexPosition();
74  G4double charge = aTrack->GetDefinition()->GetPDGCharge();
75 
76  G4bool transmit = ((position.x() >= fXendAbs) && (vertex.x() < fXendAbs));
77  G4bool reflect = (position.x() <= fXstartAbs);
78  G4bool notabsor = (transmit || reflect);
79 
80  //transmitted + reflected particles counter
81  //
82  G4int flag = 0;
83  if (charge == fPrimaryCharge) flag = 1;
84  if (aTrack->GetTrackID() == 1) flag = 2;
85  if (transmit) fEventAction->SetTransmitFlag(flag);
86  if (reflect) fEventAction->SetReflectFlag(flag);
87 
88  //
89  //histograms
90  //
91  G4bool charged = (charge != 0.);
92  G4bool neutral = !charged;
93 
94  //energy spectrum at exit
95  //
96  G4int id = 0;
97  if (transmit && charged) id = 10;
98  else if (transmit && neutral) id = 20;
99  else if (reflect && charged) id = 30;
100  else if (reflect && neutral) id = 40;
101 
102  if (id>0)
103  analysisManager->FillH1(id, aTrack->GetKineticEnergy());
104 
105  //energy leakage
106  //
107  if (notabsor) {
108  G4int trackID = aTrack->GetTrackID();
109  G4int index = 0; if (trackID > 1) index = 1; //primary=0, secondaries=1
110  G4double eleak = aTrack->GetKineticEnergy();
111  if ((aTrack->GetDefinition() == G4Positron::Positron()) && (trackID > 1))
112  eleak += 2*electron_mass_c2;
113  fRunAction->AddEnergyLeak(eleak,index);
114  }
115 
116  //space angle distribution at exit : dN/dOmega
117  //
118  G4ThreeVector direction = aTrack->GetMomentumDirection();
119  id = 0;
120  if (transmit && charged) id = 12;
121  else if (transmit && neutral) id = 22;
122  else if (reflect && charged) id = 32;
123  else if (reflect && neutral) id = 42;
124 
125  if (id>0) {
126  G4double theta = std::acos(direction.x());
127  if (theta > 0.0) {
128  G4double dteta = analysisManager->GetH1Width(id);
129  G4double unit = analysisManager->GetH1Unit(id);
130  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
131  /*
132  G4cout << "theta, dteta, unit, weight: "
133  << theta << " "
134  << dteta << " "
135  << unit << " "
136  << weight << G4endl;
137  */
138  analysisManager->FillH1(id,theta,weight);
139  }
140  }
141 
142  //energy fluence at exit : dE(MeV)/dOmega
143  //
144  id = 0;
145  if (transmit && charged) id = 11;
146  else if (transmit && neutral) id = 21;
147  else if (reflect && charged) id = 31;
148  else if (reflect && neutral) id = 41;
149 
150  if (id>0) {
151  G4double theta = std::acos(direction.x());
152  if (theta > 0.0) {
153  G4double dteta = analysisManager->GetH1Width(id);
154  G4double unit = analysisManager->GetH1Unit(id);
155  G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
156  weight *= (aTrack->GetKineticEnergy()/MeV);
157  analysisManager->FillH1(id,theta,weight);
158  }
159  }
160 
161  //projected angles distribution at exit
162  //
163  id = 0;
164  if (transmit && charged) id = 13;
165  else if (transmit && neutral) id = 23;
166  else if (reflect && charged) id = 33;
167  else if (reflect && neutral) id = 43;
168 
169  if (id>0) {
170  if (direction.x() != 0.0) {
171  G4double tet = std::atan(direction.y()/std::fabs(direction.x()));
172  analysisManager->FillH1(id,tet);
173  if (transmit && (flag == 2)) fRunAction->AddMscProjTheta(tet);
174 
175  tet = std::atan(direction.z()/std::fabs(direction.x()));
176  analysisManager->FillH1(id,tet);
177  if (transmit && (flag == 2)) fRunAction->AddMscProjTheta(tet);
178  }
179  }
180 
181  //projected position and radius at exit
182  //
183  id = 0;
184  if (transmit && charged) id = 14;
185 
186  if (id>0) {
187  G4double y = position.y(), z = position.z();
188  G4double r = std::sqrt(y*y + z*z);
189  analysisManager->FillH1(id, y);
190  analysisManager->FillH1(id, z);
191  analysisManager->FillH1(id+1, r);
192  }
193 
194  //x-vertex of charged secondaries
195  //
196  if ((aTrack->GetParentID() == 1) && charged) {
197  G4double xVertex = (aTrack->GetVertexPosition()).x();
198  analysisManager->FillH1(6, xVertex);
199  if (notabsor) analysisManager->FillH1(7, xVertex);
200  }
201 }
202 
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204