source: trunk/examples/extended/electromagnetic/TestEm5/src/TrackingAction.cc@ 811

Last change on this file since 811 was 807, checked in by garnier, 17 years ago

update

File size: 6.4 KB
Line 
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//
27// $Id: TrackingAction.cc,v 1.16 2007/11/28 12:37:57 maire Exp $
28// GEANT4 tag $Name: $
29//
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33#include "TrackingAction.hh"
34
35#include "DetectorConstruction.hh"
36#include "RunAction.hh"
37#include "EventAction.hh"
38#include "HistoManager.hh"
39
40#include "G4Track.hh"
41
42//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43
44TrackingAction::TrackingAction(DetectorConstruction* DET,RunAction* RA,
45 EventAction* EA, HistoManager* HM)
46:detector(DET), runaction(RA), eventaction(EA), histoManager(HM)
47{ }
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51void TrackingAction::PreUserTrackingAction(const G4Track* aTrack )
52{
53 // few initialisations
54 //
55 if (aTrack->GetTrackID() == 1) {
56 xstartAbs = detector->GetxstartAbs();
57 xendAbs = detector->GetxendAbs();
58 primaryCharge = aTrack->GetDefinition()->GetPDGCharge();
59 }
60}
61
62//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63
64void TrackingAction::PostUserTrackingAction(const G4Track* aTrack)
65{
66 G4ThreeVector position = aTrack->GetPosition();
67 G4double charge = aTrack->GetDefinition()->GetPDGCharge();
68
69 G4bool transmit = (position.x() >= xendAbs);
70 G4bool reflect = (position.x() <= xstartAbs);
71 G4bool notabsor = (transmit || reflect);
72
73 //transmitted + reflected particles counter
74 //
75 G4int flag = 0;
76 if (charge == primaryCharge) flag = 1;
77 if (aTrack->GetTrackID() == 1) flag = 2;
78 if (transmit) eventaction->SetTransmitFlag(flag);
79 if (reflect) eventaction->SetReflectFlag(flag);
80
81 //
82 //histograms
83 //
84 G4int id = 0;
85 G4bool charged = (charge != 0.);
86 G4bool neutral = !charged;
87
88 //energy spectrum at exit
89 //
90 if (transmit && charged) id = 10;
91 else if (transmit && neutral) id = 20;
92 else if (reflect && charged) id = 30;
93 else if (reflect && neutral) id = 40;
94
95 histoManager->FillHisto(id, aTrack->GetKineticEnergy());
96
97 //energy leakage
98 //
99 if (notabsor) {
100 G4int trackID = aTrack->GetTrackID();
101 G4int index = 0; if (trackID > 1) index = 1; //primary=0, secondaries=1
102 G4double eleak = aTrack->GetKineticEnergy();
103 if ((aTrack->GetDefinition() == G4Positron::Positron()) && (trackID > 1))
104 eleak += 2*electron_mass_c2;
105 runaction->AddEnergyLeak(eleak,index);
106 }
107
108 //space angle distribution at exit : dN/dOmega
109 //
110 if (transmit && charged) id = 12;
111 else if (transmit && neutral) id = 22;
112 else if (reflect && charged) id = 32;
113 else if (reflect && neutral) id = 42;
114
115 G4ThreeVector direction = aTrack->GetMomentumDirection();
116 if (histoManager->HistoExist(id)) {
117 G4double theta = std::acos(direction.x());
118 G4double dteta = histoManager->GetBinWidth(id);
119 G4double unit = histoManager->GetHistoUnit(id);
120 G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
121 histoManager->FillHisto(id,theta,weight);
122 }
123
124 //energy fluence at exit : dE(MeV)/dOmega
125 //
126 if (transmit && charged) id = 11;
127 else if (transmit && neutral) id = 21;
128 else if (reflect && charged) id = 31;
129 else if (reflect && neutral) id = 41;
130
131 if (histoManager->HistoExist(id)) {
132 G4double theta = std::acos(direction.x());
133 G4double dteta = histoManager->GetBinWidth(id);
134 G4double unit = histoManager->GetHistoUnit(id);
135 G4double weight = (unit*unit)/(twopi*std::sin(theta)*dteta);
136 weight *= (aTrack->GetKineticEnergy()/MeV);
137 histoManager->FillHisto(id,theta,weight);
138 }
139
140 //projected angles distribution at exit
141 //
142 if (transmit && charged) id = 13;
143 else if (transmit && neutral) id = 23;
144 else if (reflect && charged) id = 33;
145 else if (reflect && neutral) id = 43;
146
147 if(id>0) {
148 G4double tet = std::atan(direction.y()/std::fabs(direction.x()));
149 histoManager->FillHisto(id,tet);
150 if (transmit && (flag == 2)) runaction->AddMscProjTheta(tet);
151
152 tet = std::atan(direction.z()/std::fabs(direction.x()));
153 histoManager->FillHisto(id,tet);
154 if (transmit && (flag == 2)) runaction->AddMscProjTheta(tet);
155 }
156
157 //projected position and radius at exit
158 //
159 if (transmit && charged) id = 14;
160
161 if (id>0) {
162 G4double y = position.y(), z = position.z();
163 G4double r = std::sqrt(y*y + z*z);
164 histoManager->FillHisto(id, y);
165 histoManager->FillHisto(id, z);
166 histoManager->FillHisto(id+1, r);
167 }
168
169 //x-vertex of charged secondaries
170 //
171 if ((aTrack->GetParentID() == 1) && charged) {
172 G4double xVertex = (aTrack->GetVertexPosition()).x();
173 histoManager->FillHisto(4, xVertex);
174 if (notabsor) histoManager->FillHisto(5, xVertex);
175 }
176}
177
178//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179
Note: See TracBrowser for help on using the repository browser.