Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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$
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "DetectorConstruction.hh"
36 #include "PhysicsList.hh"
37 #include "StepMax.hh"
38 #include "PrimaryGeneratorAction.hh"
39 #include "HistoManager.hh"
40 
41 #include "G4Run.hh"
42 #include "G4RunManager.hh"
43 #include "G4UnitsTable.hh"
44 #include "G4EmCalculator.hh"
45 
46 #include "Randomize.hh"
47 #include "G4SystemOfUnits.hh"
48 #include <iomanip>
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
54 :fDetector(det),fPhysics(phys),fKinematic(kin),fHistoManager(histo)
55 { }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 { }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
64 void RunAction::BeginOfRunAction(const G4Run* aRun)
65 {
66  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
67 
68  // save Rndm status
71 
72  //initialize total energy deposit
73  //
74  fEdeposit = fEdeposit2 = 0.;
75 
76  //initialize track legth of primary
77  //
78  fTrackLen = fTrackLen2 = 0.;
79 
80  //initialize projected range
81  //
82  fProjRange = fProjRange2 = 0.;
83 
84  //initialize mean step size
85  //
86  fNbOfSteps = fNbOfSteps2 = 0; fStepSize = fStepSize2 = 0.;
87 
88  //get fCsdaRange from EmCalculator
89  //
90  G4EmCalculator emCalculator;
91  G4Material* material = fDetector->GetAbsorMaterial();
92  G4ParticleDefinition* particle = fKinematic->GetParticleGun()
95  fCsdaRange = DBL_MAX;
96  if (particle->GetPDGCharge() != 0.)
97  fCsdaRange = emCalculator.GetCSDARange(energy,particle,material);
98 
99  //histograms
100  //
101  fHistoManager->book();
102 
103  //set StepMax from histos
104  //
105  G4double stepMax = fHistoManager->ComputeStepMax(fCsdaRange);
106  fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
111 void RunAction::EndOfRunAction(const G4Run* aRun)
112 {
113  std::ios::fmtflags mode = G4cout.flags();
114  G4cout.setf(std::ios::fixed,std::ios::floatfield);
115 
116  G4int NbofEvents = aRun->GetNumberOfEvent();
117  if (NbofEvents == 0) return;
118  G4double fNbofEvents = double(NbofEvents);
119 
120  //run conditions
121  //
122  G4Material* material = fDetector->GetAbsorMaterial();
123  G4double density = material->GetDensity();
124 
125  G4ParticleDefinition* particle = fKinematic->GetParticleGun()
127  G4String partName = particle->GetParticleName();
128  G4double energy = fKinematic->GetParticleGun()->GetParticleEnergy();
129 
130  G4cout << "\n ======================== run summary ======================\n";
131 
132  G4int prec = G4cout.precision(2);
133 
134  G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of "
135  << G4BestUnit(energy,"Energy") << " through "
136  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << " of "
137  << material->GetName() << " (density: "
138  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
139 
140  G4cout << "\n ============================================================\n";
141 
142  //compute total energy deposit
143  //
144  fEdeposit /= NbofEvents; fEdeposit2 /= NbofEvents;
145  G4double rms = fEdeposit2 - fEdeposit*fEdeposit;
146  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
147 
148  G4cout.precision(3);
149  G4cout
150  << "\n Total Energy deposited = " << G4BestUnit(fEdeposit,"Energy")
151  << " +- " << G4BestUnit( rms,"Energy")
152  << G4endl;
153 
154  //compute track length of primary track
155  //
156  fTrackLen /= NbofEvents; fTrackLen2 /= NbofEvents;
157  rms = fTrackLen2 - fTrackLen*fTrackLen;
158  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
159 
160  G4cout.precision(3);
161  G4cout
162  << "\n Track length of primary track = " << G4BestUnit(fTrackLen,"Length")
163  << " +- " << G4BestUnit( rms,"Length");
164 
165  //compare with csda range
166  //
167  //G4EmCalculator emCalculator;
168  //G4double fCsdaRange = 0.;
169  //if (particle->GetPDGCharge() != 0.)
170  // fCsdaRange = emCalculator.GetCSDARange(energy,particle,material);
171  G4cout
172  << "\n Range from EmCalculator = " << G4BestUnit(fCsdaRange,"Length")
173  << " (from full dE/dx)" << G4endl;
174 
175  //compute projected range of primary track
176  //
177  fProjRange /= NbofEvents; fProjRange2 /= NbofEvents;
178  rms = fProjRange2 - fProjRange*fProjRange;
179  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
180 
181  G4cout
182  << "\n Projected range = " << G4BestUnit(fProjRange,"Length")
183  << " +- " << G4BestUnit( rms,"Length")
184  << G4endl;
185 
186  //nb of steps and step size of primary track
187  //
188  G4double fNbSteps = fNbOfSteps/fNbofEvents, fNbSteps2 = fNbOfSteps2/fNbofEvents;
189  rms = fNbSteps2 - fNbSteps*fNbSteps;
190  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
191 
192  G4cout.precision(2);
193  G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms;
194 
195  fStepSize /= NbofEvents; fStepSize2 /= NbofEvents;
196  rms = fStepSize2 - fStepSize*fStepSize;
197  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
198 
199  G4cout.precision(3);
200  G4cout
201  << "\t Step size= " << G4BestUnit(fStepSize,"Length")
202  << " +- " << G4BestUnit( rms,"Length")
203  << G4endl;
204 
205  // normalize histogram of longitudinal energy profile
206  //
207  G4int ih = 1;
208  G4double binWidth = fHistoManager->GetBinWidth(ih);
209  G4double fac = (1./(NbofEvents*binWidth))*(mm/MeV);
210  fHistoManager->Normalize(ih,fac);
211 
212  // normalize histogram d(E/E0)/d(r/r0)
213  //
214  ih = 8;
215  binWidth = fHistoManager->GetBinWidth(ih);
216  fac = 1./(NbofEvents*binWidth*energy);
217  fHistoManager->Normalize(ih,fac);
218 
219  // reset default formats
220  G4cout.setf(mode,std::ios::floatfield);
221  G4cout.precision(prec);
222 
223  // save histograms
224  fHistoManager->save();
225 
226  // show Rndm status
228 }
229 
230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......