Geant4  10.02.p02
RunAction.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 // $Id: RunAction.cc 82283 2014-06-13 14:49:40Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 
36 #include "DetectorConstruction.hh"
37 #include "PrimaryGeneratorAction.hh"
38 #include "HistoManager.hh"
39 
40 #include "G4Run.hh"
41 #include "G4RunManager.hh"
42 #include "G4UnitsTable.hh"
43 #include "G4EmCalculator.hh"
44 
45 #include "Randomize.hh"
46 #include "G4SystemOfUnits.hh"
47 #include <iomanip>
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52  : G4UserRunAction(),fDetector(det), fPrimary(prim), fProcCounter(0),
53  fHistoManager(0)
54 {
55  fHistoManager = new HistoManager();
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62  delete fHistoManager;
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  // save Rndm status
71  CLHEP::HepRandom::showEngineStatus();
72 
74  fTotalCount = 0;
75 
76  fTruePL = fTruePL2 = fGeomPL = fGeomPL2 = 0.;
77  fLDispl = fLDispl2 = fPsiSpa = fPsiSpa2 = 0.;
78  fTetPrj = fTetPrj2 = 0.;
79  fPhiCor = fPhiCor2 = 0.;
80 
81  //histograms
82  //
83  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
84  if ( analysisManager->IsActive() ) {
85  analysisManager->OpenFile();
86  }
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  //does the process already encounted ?
94  size_t nbProc = fProcCounter->size();
95  size_t i = 0;
96  while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
97  if (i == nbProc) fProcCounter->push_back( new OneProcessCount(procName));
98 
99  (*fProcCounter)[i]->Count();
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
104 void RunAction::EndOfRunAction(const G4Run* aRun)
105 {
106  G4int NbOfEvents = aRun->GetNumberOfEvent();
107  if (NbOfEvents == 0) return;
108 
109  G4int prec = G4cout.precision(5);
110 
111  G4Material* material = fDetector->GetMaterial();
112  G4double density = material->GetDensity();
113 
114  G4ParticleDefinition* particle =
116  G4String Particle = particle->GetParticleName();
118  G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
119  << G4BestUnit(energy,"Energy") << " through "
120  << G4BestUnit(fDetector->GetBoxSize(),"Length") << " of "
121  << material->GetName() << " (density: "
122  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
123 
124  //frequency of processes
125  G4cout << "\n Process calls frequency --->";
126  for (size_t i=0; i< fProcCounter->size();i++) {
127  G4String procName = (*fProcCounter)[i]->GetName();
128  G4int count = (*fProcCounter)[i]->GetCounter();
129  G4cout << "\t" << procName << " = " << count;
130  }
131 
132  if (fTotalCount == 0) return;
133 
134  //compute path length and related quantities
135  //
136  G4double MeanTPL = fTruePL /fTotalCount;
137  G4double MeanTPL2 = fTruePL2/fTotalCount;
138  G4double rmsTPL = std::sqrt(std::fabs(MeanTPL2 - MeanTPL*MeanTPL));
139 
140  G4double MeanGPL = fGeomPL /fTotalCount;
141  G4double MeanGPL2 = fGeomPL2/fTotalCount;
142  G4double rmsGPL = std::sqrt(std::fabs(MeanGPL2 - MeanGPL*MeanGPL));
143 
144  G4double MeanLaD = fLDispl /fTotalCount;
145  G4double MeanLaD2 = fLDispl2/fTotalCount;
146  G4double rmsLaD = std::sqrt(std::fabs(MeanLaD2 - MeanLaD*MeanLaD));
147 
148  G4double MeanPsi = fPsiSpa /(fTotalCount);
149  G4double MeanPsi2 = fPsiSpa2/(fTotalCount);
150  G4double rmsPsi = std::sqrt(std::fabs(MeanPsi2 - MeanPsi*MeanPsi));
151 
152  G4double MeanTeta = fTetPrj /(2*fTotalCount);
153  G4double MeanTeta2 = fTetPrj2/(2*fTotalCount);
154  G4double rmsTeta = std::sqrt(std::fabs(MeanTeta2 - MeanTeta*MeanTeta));
155 
156  G4double MeanCorrel = fPhiCor /(fTotalCount);
157  G4double MeanCorrel2 = fPhiCor2/(fTotalCount);
158  G4double rmsCorrel = std::sqrt(std::fabs(MeanCorrel2-MeanCorrel*MeanCorrel));
159 
160  G4cout << "\n\n truePathLength :\t" << G4BestUnit(MeanTPL,"Length")
161  << " +- " << G4BestUnit( rmsTPL,"Length")
162  << "\n geomPathLength :\t" << G4BestUnit(MeanGPL,"Length")
163  << " +- " << G4BestUnit( rmsGPL,"Length")
164  << "\n lateralDisplac :\t" << G4BestUnit(MeanLaD,"Length")
165  << " +- " << G4BestUnit( rmsLaD,"Length")
166  << "\n Psi :\t" << MeanPsi/mrad << " mrad"
167  << " +- " << rmsPsi /mrad << " mrad"
168  << " (" << MeanPsi/deg << " deg"
169  << " +- " << rmsPsi /deg << " deg)"
170  << G4endl;
171 
172  G4cout << "\n Theta_plane :\t" << rmsTeta/mrad << " mrad"
173  << " (" << rmsTeta/deg << " deg)"
174  << "\n phi correlation:\t" << MeanCorrel
175  << " +- " << rmsCorrel
176  << " (std::cos(phi_pos - phi_dir))"
177  << G4endl;
178 
179 
180  //cross check from G4EmCalculator
181  //
182  G4cout << "\n Verification from G4EmCalculator. \n";
183 
184  G4EmCalculator emCal;
185 
186  //get transport mean free path (for multiple scattering)
187  G4double MSmfp = emCal.GetMeanFreePath(energy,particle,"msc",material);
188 
189  //get range from restricted dedx
190  G4double range = emCal.GetRangeFromRestricteDEDX(energy,particle,material);
191 
192  //effective facRange
193  G4double efFacrange = MeanTPL/std::max(MSmfp, range);
194  if (MeanTPL/range >= 0.99) efFacrange = 1.;
195 
196  G4cout << "\n transport mean free path :\t" << G4BestUnit(MSmfp,"Length")
197  << "\n range from restrict dE/dx:\t" << G4BestUnit(range,"Length")
198  << "\n ---> effective facRange :\t" << efFacrange
199  << G4endl;
200 
201  G4cout << "\n compute theta0 from Highland :\t"
202  << ComputeMscHighland(MeanTPL)/mrad << " mrad"
203  << " (" << ComputeMscHighland(MeanTPL)/deg << " deg)"
204  << G4endl;
205 
206  //restore default format
207  G4cout.precision(prec);
208 
209  // delete and remove all contents in fProcCounter
210  while (fProcCounter->size()>0){
211  OneProcessCount* aProcCount=fProcCounter->back();
212  fProcCounter->pop_back();
213  delete aProcCount;
214  }
215  delete fProcCounter;
216 
217  //save histograms
218  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
219  if ( analysisManager->IsActive() ) {
220  analysisManager->Write();
221  analysisManager->CloseFile();
222  }
223 
224  // show Rndm status
225  CLHEP::HepRandom::showEngineStatus();
226 }
227 
228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
229 
231 {
232  //compute the width of the Gaussian central part of the MultipleScattering
233  //projected angular distribution.
234  //Eur. Phys. Jour. C15 (2000) page 166, formule 23.9
235 
236  G4double t = pathLength/(fDetector->GetMaterial()->GetRadlen());
237  if (t < DBL_MIN) return 0.;
238 
239  G4ParticleGun* particle = fPrimary->GetParticleGun();
240  G4double T = particle->GetParticleEnergy();
241  G4double M = particle->GetParticleDefinition()->GetPDGMass();
242  G4double z = std::abs(particle->GetParticleDefinition()->GetPDGCharge()/eplus);
243 
244  G4double bpc = T*(T+2*M)/(T+M);
245  G4double teta0 = 13.6*MeV*z*std::sqrt(t)*(1.+0.038*std::log(t))/bpc;
246  return teta0;
247 }
248 
249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< OneProcessCount * > ProcessesCount
PrimaryGeneratorAction class.
static const double MeV
Definition: G4SIunits.hh:211
G4double fGeomPL
Definition: RunAction.hh:89
G4double fLDispl
Definition: RunAction.hh:90
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
G4double fPhiCor
Definition: RunAction.hh:93
G4double ComputeMscHighland(G4double pathLength)
Definition: RunAction.cc:230
G4double z
Definition: TRTMaterials.hh:39
const G4String & GetName() const
Definition: G4Material.hh:178
G4double GetDensity() const
Definition: G4Material.hh:180
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4double GetMeanFreePath(G4double kinEnergy, const G4ParticleDefinition *, const G4String &processName, const G4Material *, const G4Region *r=0)
int G4int
Definition: G4Types.hh:78
G4double fPhiCor2
Definition: RunAction.hh:93
DetectorConstruction * fDetector
Definition: RunAction.hh:63
const G4String & GetParticleName() const
HistoManager * fHistoManager
Definition: RunAction.hh:66
G4double fGeomPL2
Definition: RunAction.hh:89
G4int fTotalCount
Definition: RunAction.hh:87
G4double density
Definition: TRTMaterials.hh:39
static const double prec
Definition: RanecuEngine.cc:58
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
static const double deg
Definition: G4SIunits.hh:151
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4double GetRangeFromRestricteDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=0)
Definition: G4Run.hh:46
G4double fPsiSpa
Definition: RunAction.hh:91
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
void CountProcesses(G4String)
Definition: RunAction.cc:91
static const double mrad
Definition: G4SIunits.hh:149
G4double fTetPrj
Definition: RunAction.hh:92
G4double fTruePL2
Definition: RunAction.hh:88
G4double GetRadlen() const
Definition: G4Material.hh:220
G4double fLDispl2
Definition: RunAction.hh:90
~RunAction()
Definition: RunAction.cc:52
ProcessesCount * fProcCounter
Definition: RunAction.hh:84
G4double GetPDGMass() const
G4double fTetPrj2
Definition: RunAction.hh:92
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4ParticleGun * GetParticleGun()
G4double energy(const ThreeVector &p, const G4double m)
G4double fTruePL
Definition: RunAction.hh:88
#define DBL_MIN
Definition: templates.hh:75
G4ParticleDefinition * GetParticleDefinition() const
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static const double eplus
Definition: G4SIunits.hh:196
G4double GetPDGCharge() const
G4double fPsiSpa2
Definition: RunAction.hh:91
G4double GetParticleEnergy() const
PrimaryGeneratorAction * fPrimary
Definition: RunAction.hh:64