source: trunk/examples/extended/electromagnetic/TestEm12/src/RunAction.cc@ 1249

Last change on this file since 1249 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

File size: 7.9 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// $Id: RunAction.cc,v 1.8 2007/08/19 20:57:29 maire Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "RunAction.hh"
33#include "DetectorConstruction.hh"
34#include "PhysicsList.hh"
35#include "StepMax.hh"
36#include "PrimaryGeneratorAction.hh"
37#include "HistoManager.hh"
38
39#include "G4Run.hh"
40#include "G4RunManager.hh"
41#include "G4UnitsTable.hh"
42#include "G4EmCalculator.hh"
43
44#include "Randomize.hh"
45#include <iomanip>
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
49RunAction::RunAction(DetectorConstruction* det, PhysicsList* phys,
50 PrimaryGeneratorAction* kin, HistoManager* histo)
51:detector(det),physics(phys),kinematic(kin),histoManager(histo)
52{ }
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
56RunAction::~RunAction()
57{ }
58
59//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60
61void RunAction::BeginOfRunAction(const G4Run* aRun)
62{
63 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
64
65 // save Rndm status
66 G4RunManager::GetRunManager()->SetRandomNumberStore(true);
67 CLHEP::HepRandom::showEngineStatus();
68
69 //initialize total energy deposit
70 //
71 Edeposit = Edeposit2 = 0.;
72
73 //initialize track legth of primary
74 //
75 trackLen = trackLen2 = 0.;
76
77 //initialize projected range
78 //
79 projRange = projRange2 = 0.;
80
81 //initialize mean step size
82 //
83 nbOfSteps = nbOfSteps2 = 0; stepSize = stepSize2 = 0.;
84
85 //get csdaRange from EmCalculator
86 //
87 G4EmCalculator emCalculator;
88 G4Material* material = detector->GetAbsorMaterial();
89 G4ParticleDefinition* particle = kinematic->GetParticleGun()
90 ->GetParticleDefinition();
91 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy();
92 csdaRange = DBL_MAX;
93 if (particle->GetPDGCharge() != 0.)
94 csdaRange = emCalculator.GetCSDARange(energy,particle,material);
95
96 //histograms
97 //
98 histoManager->book();
99
100 //set StepMax from histos
101 //
102 G4double stepMax = histoManager->ComputeStepMax(csdaRange);
103 physics->GetStepMaxProcess()->SetMaxStep(stepMax);
104}
105
106//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107
108void RunAction::EndOfRunAction(const G4Run* aRun)
109{
110 std::ios::fmtflags mode = G4cout.flags();
111 G4cout.setf(std::ios::fixed,std::ios::floatfield);
112
113 G4int NbofEvents = aRun->GetNumberOfEvent();
114 if (NbofEvents == 0) return;
115 G4double fNbofEvents = double(NbofEvents);
116
117 //run conditions
118 //
119 G4Material* material = detector->GetAbsorMaterial();
120 G4double density = material->GetDensity();
121
122 G4ParticleDefinition* particle = kinematic->GetParticleGun()
123 ->GetParticleDefinition();
124 G4String partName = particle->GetParticleName();
125 G4double energy = kinematic->GetParticleGun()->GetParticleEnergy();
126
127 G4cout << "\n ======================== run summary ======================\n";
128
129 G4int prec = G4cout.precision(2);
130
131 G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of "
132 << G4BestUnit(energy,"Energy") << " through "
133 << G4BestUnit(detector->GetAbsorRadius(),"Length") << " of "
134 << material->GetName() << " (density: "
135 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
136
137 G4cout << "\n ============================================================\n";
138
139 //compute total energy deposit
140 //
141 Edeposit /= NbofEvents; Edeposit2 /= NbofEvents;
142 G4double rms = Edeposit2 - Edeposit*Edeposit;
143 if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
144
145 G4cout.precision(3);
146 G4cout
147 << "\n Total Energy deposited = " << G4BestUnit(Edeposit,"Energy")
148 << " +- " << G4BestUnit( rms,"Energy")
149 << G4endl;
150
151 //compute track length of primary track
152 //
153 trackLen /= NbofEvents; trackLen2 /= NbofEvents;
154 rms = trackLen2 - trackLen*trackLen;
155 if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
156
157 G4cout.precision(3);
158 G4cout
159 << "\n Track length of primary track = " << G4BestUnit(trackLen,"Length")
160 << " +- " << G4BestUnit( rms,"Length");
161
162 //compare with csda range
163 //
164 //G4EmCalculator emCalculator;
165 //G4double csdaRange = 0.;
166 //if (particle->GetPDGCharge() != 0.)
167 // csdaRange = emCalculator.GetCSDARange(energy,particle,material);
168 G4cout
169 << "\n Range from EmCalculator = " << G4BestUnit(csdaRange,"Length")
170 << " (from full dE/dx)" << G4endl;
171
172 //compute projected range of primary track
173 //
174 projRange /= NbofEvents; projRange2 /= NbofEvents;
175 rms = projRange2 - projRange*projRange;
176 if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
177
178 G4cout
179 << "\n Projected range = " << G4BestUnit(projRange,"Length")
180 << " +- " << G4BestUnit( rms,"Length")
181 << G4endl;
182
183 //nb of steps and step size of primary track
184 //
185 G4double fNbSteps = nbOfSteps/fNbofEvents, fNbSteps2 = nbOfSteps2/fNbofEvents;
186 rms = fNbSteps2 - fNbSteps*fNbSteps;
187 if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
188
189 G4cout.precision(2);
190 G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms;
191
192 stepSize /= NbofEvents; stepSize2 /= NbofEvents;
193 rms = stepSize2 - stepSize*stepSize;
194 if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
195
196 G4cout.precision(3);
197 G4cout
198 << "\t Step size= " << G4BestUnit(stepSize,"Length")
199 << " +- " << G4BestUnit( rms,"Length")
200 << G4endl;
201
202 // normalize histogram of longitudinal energy profile
203 //
204 G4int ih = 1;
205 G4double binWidth = histoManager->GetBinWidth(ih);
206 G4double fac = (1./(NbofEvents*binWidth))*(mm/MeV);
207 histoManager->Scale(ih,fac);
208
209 // normalize histogram d(E/E0)/d(r/r0)
210 //
211 ih = 8;
212 binWidth = histoManager->GetBinWidth(ih);
213 fac = 1./(NbofEvents*binWidth*energy);
214 histoManager->Scale(ih,fac);
215
216 // reset default formats
217 G4cout.setf(mode,std::ios::floatfield);
218 G4cout.precision(prec);
219
220 // save histograms
221 histoManager->save();
222
223 // show Rndm status
224 CLHEP::HepRandom::showEngineStatus();
225}
226
227//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.