Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Run.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: Run.cc 71376 2013-06-14 07:44:50Z maire $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "Run.hh"
35 #include "DetectorConstruction.hh"
36 #include "PrimaryGeneratorAction.hh"
37 
38 #include "G4UnitsTable.hh"
39 #include "G4SystemOfUnits.hh"
40 #include "G4EmCalculator.hh"
41 
42 #include <iomanip>
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47 : G4Run(),
48  fDetector(det),
49  fParticle(0), fEkin(0.),
50  fNbOfTraks0(0), fNbOfTraks1(0),
51  fNbOfSteps0(0), fNbOfSteps1(0),
52  fEdep(0),
53  fTrueRange(0.), fTrueRange2(0.),
54  fProjRange(0.), fProjRange2(0.),
55  fTransvDev(0.), fTransvDev2(0.)
56 { }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
60 Run::~Run()
61 { }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
67  fParticle = particle;
68  fEkin = energy;
69 }
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 {
74  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
75  if ( it == fProcCounter.end()) {
76  fProcCounter[procName] = 1;
77  }
78  else {
79  fProcCounter[procName]++;
80  }
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
85 void Run::Merge(const G4Run* run)
86 {
87  const Run* localRun = static_cast<const Run*>(run);
88 
89  // pass information about primary particle
90  fParticle = localRun->fParticle;
91  fEkin = localRun->fEkin;
92 
93  // accumulate sums
94  //
95  fNbOfTraks0 += localRun->fNbOfTraks0;
96  fNbOfTraks1 += localRun->fNbOfTraks1;
97  fNbOfSteps0 += localRun->fNbOfSteps0;
98  fNbOfSteps1 += localRun->fNbOfSteps1;
99  fEdep += localRun->fEdep;
100  fTrueRange += localRun->fTrueRange;
101  fTrueRange2 += localRun->fTrueRange2;
102  fProjRange += localRun->fProjRange;
103  fProjRange2 += localRun->fProjRange2;
104  fTransvDev += localRun->fTransvDev;
105  fTransvDev2 += localRun->fTransvDev2;
106 
107  //map: processes count
108  std::map<G4String,G4int>::const_iterator it;
109  for (it = localRun->fProcCounter.begin();
110  it !=localRun->fProcCounter.end(); ++it) {
111 
112  G4String procName = it->first;
113  G4int localCount = it->second;
114  if ( fProcCounter.find(procName) == fProcCounter.end()) {
115  fProcCounter[procName] = localCount;
116  }
117  else {
118  fProcCounter[procName] += localCount;
119  }
120  }
121 
122  G4Run::Merge(run);
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
127 void Run::EndOfRun()
128 {
129  G4int prec = 5, wid = prec + 2;
130  G4int dfprec = G4cout.precision(prec);
131 
132  //run condition
133  //
134  G4String partName = fParticle->GetParticleName();
135  G4Material* material = fDetector->GetMaterial();
136  G4double density = material->GetDensity();
137 
138  G4cout << "\n ======================== run summary ======================\n";
139  G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of "
140  << G4BestUnit(fEkin,"Energy") << " through "
141  << G4BestUnit(fDetector->GetSize(),"Length") << " of "
142  << material->GetName() << " (density: "
143  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
144 
145  if (numberOfEvent == 0) { G4cout.precision(dfprec); return;}
146 
147  G4double dNbOfEvents = double(numberOfEvent);
148  G4cout << "\n total energy deposit: "
149  << G4BestUnit(fEdep/dNbOfEvents, "Energy") << G4endl;
150 
151  //nb of tracks and steps per event
152  //
153  G4cout << "\n nb tracks/event"
154  << " neutral: " << std::setw(wid) << fNbOfTraks0/dNbOfEvents
155  << " charged: " << std::setw(wid) << fNbOfTraks1/dNbOfEvents
156  << "\n nb steps/event"
157  << " neutral: " << std::setw(wid) << fNbOfSteps0/dNbOfEvents
158  << " charged: " << std::setw(wid) << fNbOfSteps1/dNbOfEvents
159  << G4endl;
160 
161  //frequency of processes
162  //
163  G4cout << "\n Process calls frequency :" << G4endl;
164  G4int index = 0;
165  std::map<G4String,G4int>::iterator it;
166  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
167  G4String procName = it->first;
168  G4int count = it->second;
169  G4String space = " "; if (++index%3 == 0) space = "\n";
170  G4cout << " " << std::setw(20) << procName << "="<< std::setw(7) << count
171  << space;
172  }
173  G4cout << G4endl;
174 
175  //compute true and projected ranges, and transverse dispersion
176  //
177  fTrueRange /= numberOfEvent; fTrueRange2 /= numberOfEvent;
178  G4double trueRms = fTrueRange2 - fTrueRange*fTrueRange;
179  if (trueRms>0.) trueRms = std::sqrt(trueRms); else trueRms = 0.;
180 
181  fProjRange /= numberOfEvent; fProjRange2 /= numberOfEvent;
182  G4double projRms = fProjRange2 - fProjRange*fProjRange;
183  if (projRms>0.) projRms = std::sqrt(projRms); else projRms = 0.;
184 
185  fTransvDev /= 2*numberOfEvent; fTransvDev2 /= 2*numberOfEvent;
186  G4double trvsRms = fTransvDev2 - fTransvDev*fTransvDev;
187  if (trvsRms>0.) trvsRms = std::sqrt(trvsRms); else trvsRms = 0.;
188 
189  //compare true range with csda range from PhysicsTables
190  //
191  G4EmCalculator emCalculator;
192  G4double rangeTable = 0.;
193  if (fParticle->GetPDGCharge() != 0.)
194  rangeTable = emCalculator.GetCSDARange(fEkin,fParticle,material);
195 
196  G4cout << "\n---------------------------------------------------------\n";
197  G4cout << " Primary particle : " ;
198  G4cout << "\n true Range = " << G4BestUnit(fTrueRange,"Length")
199  << " rms = " << G4BestUnit(trueRms, "Length");
200 
201  G4cout << "\n proj Range = " << G4BestUnit(fProjRange,"Length")
202  << " rms = " << G4BestUnit(projRms, "Length");
203 
204  G4cout << "\n proj/true = " << fProjRange/fTrueRange;
205 
206  G4cout << "\n transverse dispersion at end = "
207  << G4BestUnit(trvsRms,"Length");
208 
209  G4cout << "\n mass true Range from simulation = "
210  << G4BestUnit(fTrueRange*density, "Mass/Surface")
211  << "\n from PhysicsTable (csda range) = "
212  << G4BestUnit(rangeTable*density, "Mass/Surface");
213  G4cout << "\n---------------------------------------------------------\n";
214  G4cout << G4endl;
215 
216  // remove all contents in fProcCounter
217  fProcCounter.clear();
218 
219  //restore default format
220  G4cout.precision(dfprec);
221 }
222 
223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int numberOfEvent
Definition: G4Run.hh:59
void CountProcesses(G4String procName)
Definition: Run.cc:72
Run()
Definition: Run.cc:43
G4int first(char) const
const G4String & GetName() const
Definition: G4Material.hh:178
G4double GetDensity() const
Definition: G4Material.hh:180
G4double GetCSDARange(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
string material
Definition: eplot.py:19
static const double prec
Definition: RanecuEngine.cc:58
G4GLOB_DLL std::ostream G4cout
Definition: G4Run.hh:46
G4double energy(const ThreeVector &p, const G4double m)
Detector construction class to define materials and geometry.
void EndOfRun()
Definition: Run.cc:147
#define G4endl
Definition: G4ios.hh:61
void SetPrimary(G4ParticleDefinition *particle, G4double energy)
Definition: Run.cc:77
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4double GetPDGCharge() const
virtual void Merge(const G4Run *)
Definition: Run.cc:115
~Run()
Definition: Run.cc:72