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 #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 :fPrimary(prim),fHistoManager(histo)
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  G4int id = 0;
67 
68  if(selectedGeneratorAction==2)
69  {
70  //energy spectrum
71  //
72  id = 1;
73  fHistoManager->FillHisto(id, track->GetKineticEnergy());
74  }
75  else if(selectedGeneratorAction==3)
76  {
77  //momentum direction : angular distr dN/dOmega = f(alpha)
78  //
79  id = 2;
80  G4ThreeVector um = track->GetMomentumDirection();
81  G4double alpha = std::acos(fNewUz*um);
82  G4double dalfa = fHistoManager->GetBinWidth(id);
83  G4double dOmega = twopi*std::sin(alpha)*dalfa;
84  if (dOmega > 0.) fHistoManager->FillHisto(id, alpha, 1./dOmega);
85 
86  //momentum direction : angular distr dN/dOmega = f(psi)
87  //
88  id = 3;
89  // complete local frame
90  G4ThreeVector u1(1.,0.,0.); u1.rotateUz(fNewUz);
91  G4ThreeVector u2(0.,1.,0.); u2.rotateUz(fNewUz);
92  //
93  G4double psi = std::atan2(u2*um, u1*um);
94  if (psi < 0.) psi += twopi;
95  G4double dpsi = fHistoManager->GetBinWidth(id);
96  G4double alphaMax = fPrimary->GetAction3()->GetAlphaMax();
97  dOmega = (1. - std::cos(alphaMax))*dpsi;
98  if (dOmega > 0.) fHistoManager->FillHisto(id, psi, 1./dOmega);
99  }
100  else if(selectedGeneratorAction==4)
101  {
102  G4ThreeVector vertex = track->GetVertexPosition();
103  G4double r = vertex.mag();
104  if (r <= 0.0) return;
105  //local frame : new uz = ur
106  G4ThreeVector ur = vertex/r;
107 
108  //vertex position: radial distribution : dN/dv = f(r)
109  //
110  id = 4;
111  G4double dr = fHistoManager->GetBinWidth(id);
112  G4double dv = 2*twopi*r*r*dr;
113  if (dv > 0.) fHistoManager->FillHisto(id, r, 1./dv);
114 
115  //vertex position: angular distribution : dN/dv = f(theta)
116  //
117  id = 5;
118  G4double theta = std::acos(ur.z());
119  G4double dteta = fHistoManager->GetBinWidth(id);
120  dv = fDeltaR3*twopi*std::sin(theta)*dteta;
121  if (dv > 0.) fHistoManager->FillHisto(id, theta, 1./dv);
122 
123  //vertex position: angular distribution : dN/dv = f(phi)
124  //
125  id = 6;
126  G4double phi = std::atan2(ur.y(), ur.x());
127  if (phi < 0.) phi += twopi;
128  G4double dphi = fHistoManager->GetBinWidth(id);
129  dv = 2*fDeltaR3*dphi;
130  if (dv > 0.) fHistoManager->FillHisto(id, phi, 1./dv);
131 
132  //momentum direction : angular distr dN/dOmega = f(alpha)
133  //
134  id = 7;
135  G4ThreeVector um = track->GetMomentumDirection();
136  G4double alpha = std::acos(ur*um);
137  G4double dalfa = fHistoManager->GetBinWidth(id);
138  G4double dOmega = twopi*std::sin(alpha)*dalfa;
139  if (dOmega > 0.) fHistoManager->FillHisto(id, alpha, 1./dOmega);
140 
141  //momentum direction : angular distr dN/dOmega = f(psi)
142  //
143  id = 8;
144  // complete local frame
145  G4ThreeVector u1(1.,0.,0.); u1.rotateUz(ur);
146  G4ThreeVector u2(0.,1.,0.); u2.rotateUz(ur);
147  //
148  G4double psi = std::atan2(u2*um, u1*um);
149  if (psi < 0.) psi += twopi;
150  G4double dpsi = fHistoManager->GetBinWidth(id);
151  dOmega = (fCosAlphaMin - fCosAlphaMax)*dpsi;
152  if (dOmega > 0.) fHistoManager->FillHisto(id, psi, 1./dOmega);
153  }
154 }
155 
156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
157 
159 { }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162