Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extended/eventgenerator/particleGun/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 eventgenerator/particleGun/src/TrackingAction.cc
27 /// \brief Implementation of the TrackingAction class
28 //
29 //
30 // $Id: TrackingAction.cc 68734 2013-04-05 09:47:02Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "TrackingAction.hh"
36 #include "PrimaryGeneratorAction.hh"
40 #include "RunAction.hh"
41 #include "HistoManager.hh"
42 
43 #include "G4Track.hh"
44 #include "G4PhysicalConstants.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 :G4UserTrackingAction(), fPrimary(prim)
50 {
51  // parameters for generator action #3
52  fNewUz = fPrimary->GetAction3()->GetNewUz();
53 
54  // parameters for generator action #4
55  fDeltaR3 =
56  (fPrimary->GetAction4()->GetRmax3() - fPrimary->GetAction4()->GetRmin3())/3.;
57  fCosAlphaMin = fPrimary->GetAction4()->GetCosAlphaMin();
58  fCosAlphaMax = fPrimary->GetAction4()->GetCosAlphaMax();
59 }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  G4int selectedGeneratorAction = fPrimary->GetSelectedAction();
66  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
67  G4int id = 0;
68 
69  if(selectedGeneratorAction==2)
70  {
71  //energy spectrum
72  //
73  id = 1;
74  analysis->FillH1(id, track->GetKineticEnergy());
75  }
76  else if(selectedGeneratorAction==3)
77  {
78  //momentum direction : angular distr dN/dOmega = f(alpha)
79  //
80  id = 2;
81  G4ThreeVector um = track->GetMomentumDirection();
82  G4double alpha = std::acos(fNewUz*um);
83  G4double dalfa = analysis->GetH1Width(id);
84  G4double dOmega = twopi*std::sin(alpha)*dalfa;
85  if (dOmega > 0.) analysis->FillH1(id, alpha, 1./dOmega);
86 
87  //momentum direction : angular distr dN/dOmega = f(psi)
88  //
89  id = 3;
90  // complete local frame
91  G4ThreeVector u1(1.,0.,0.); u1.rotateUz(fNewUz);
92  G4ThreeVector u2(0.,1.,0.); u2.rotateUz(fNewUz);
93  //
94  G4double psi = std::atan2(u2*um, u1*um);
95  if (psi < 0.) psi += twopi;
96  G4double dpsi = analysis->GetH1Width(id);
97  G4double alphaMax = fPrimary->GetAction3()->GetAlphaMax();
98  dOmega = (1. - std::cos(alphaMax))*dpsi;
99  if (dOmega > 0.) analysis->FillH1(id, psi, 1./dOmega);
100  }
101  else if(selectedGeneratorAction==4)
102  {
103  G4ThreeVector vertex = track->GetVertexPosition();
104  G4double r = vertex.mag();
105  if (r <= 0.0) return;
106  //local frame : new uz = ur
107  G4ThreeVector ur = vertex/r;
108 
109  //vertex position: radial distribution : dN/dv = f(r)
110  //
111  id = 4;
112  G4double dr = analysis->GetH1Width(id);
113  G4double dv = 2*twopi*r*r*dr;
114  if (dv > 0.) analysis->FillH1(id, r, 1./dv);
115 
116  //vertex position: angular distribution : dN/dv = f(theta)
117  //
118  id = 5;
119  G4double theta = std::acos(ur.z());
120  G4double dteta = analysis->GetH1Width(id);
121  dv = fDeltaR3*twopi*std::sin(theta)*dteta;
122  if (dv > 0.) analysis->FillH1(id, theta, 1./dv);
123 
124  //vertex position: angular distribution : dN/dv = f(phi)
125  //
126  id = 6;
127  G4double phi = std::atan2(ur.y(), ur.x());
128  if (phi < 0.) phi += twopi;
129  G4double dphi = analysis->GetH1Width(id);
130  dv = 2*fDeltaR3*dphi;
131  if (dv > 0.) analysis->FillH1(id, phi, 1./dv);
132 
133  //momentum direction : angular distr dN/dOmega = f(alpha)
134  //
135  id = 7;
136  G4ThreeVector um = track->GetMomentumDirection();
137  G4double alpha = std::acos(ur*um);
138  G4double dalfa = analysis->GetH1Width(id);
139  G4double dOmega = twopi*std::sin(alpha)*dalfa;
140  if (dOmega > 0.) analysis->FillH1(id, alpha, 1./dOmega);
141 
142  //momentum direction : angular distr dN/dOmega = f(psi)
143  //
144  id = 8;
145  // complete local frame
146  G4ThreeVector u1(1.,0.,0.); u1.rotateUz(ur);
147  G4ThreeVector u2(0.,1.,0.); u2.rotateUz(ur);
148  //
149  G4double psi = std::atan2(u2*um, u1*um);
150  if (psi < 0.) psi += twopi;
151  G4double dpsi = analysis->GetH1Width(id);
152  dOmega = (fCosAlphaMin - fCosAlphaMax)*dpsi;
153  if (dOmega > 0.) analysis->FillH1(id, psi, 1./dOmega);
154  }
155 }
156 
157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158 
160 { }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 
Definition of the PrimaryGeneratorAction2 class.
double x() const
int G4int
Definition: G4Types.hh:78
double z() const
G4double GetKineticEnergy() const
void PreUserTrackingAction(const G4Track *)
Definition of the PrimaryGeneratorAction3 class.
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
void PostUserTrackingAction(const G4Track *)
const G4ThreeVector & GetVertexPosition() const
const G4ThreeVector & GetMomentumDirection() const
double y() const
double G4double
Definition: G4Types.hh:76
double mag() const
Definition of the PrimaryGeneratorAction4 class.