Geant4_10
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 
61 { }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
67  fParticle = particle;
68  fEkin = energy;
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
73 void Run::PrintSummary() const
74 {
75  G4int prec = G4cout.precision(5);
76 
77  G4int nbOfEvents = GetNumberOfEvent();
78  G4String partName = fParticle->GetParticleName();
79  G4double length = fDetector->GetSize();
80  G4Material* material = fDetector->GetMaterial();
81  G4double density = material->GetDensity();
82 
83  G4cout << "\n ======================== run summary ======================\n";
84  G4cout << "\n The run was: " << nbOfEvents << " " << partName << " of "
85  << G4BestUnit(fEkin,"Energy") << " through "
86  << G4BestUnit(length,"Length") << " of "
87  << material->GetName() << " (density: "
88  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
89  G4cout << "\n ============================================================\n";
90 
91  // reset default precision
92  G4cout.precision(prec);
93 }
94 
95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
96 
98 {
99  G4int prec = 5, wid = prec + 2;
100  G4int dfprec = G4cout.precision(prec);
101 
102  G4double dNbOfEvents = double(numberOfEvent);
103  G4cout << "\n total energy deposit: "
104  << G4BestUnit(fEdep/dNbOfEvents, "Energy") << G4endl;
105 
106  //nb of tracks and steps per event
107  //
108  G4cout << "\n nb tracks/event"
109  << " neutral: " << std::setw(wid) << fNbOfTraks0/dNbOfEvents
110  << " charged: " << std::setw(wid) << fNbOfTraks1/dNbOfEvents
111  << "\n nb steps/event"
112  << " neutral: " << std::setw(wid) << fNbOfSteps0/dNbOfEvents
113  << " charged: " << std::setw(wid) << fNbOfSteps1/dNbOfEvents
114  << G4endl;
115 
116  //frequency of processes call
117  std::map<G4String,G4int>::iterator it;
118  G4cout << "\n nb of process calls per event: \n ";
119  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++)
120  G4cout << std::setw(12) << it->first;
121 
122  G4cout << "\n ";
123  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++)
124  G4cout << std::setw(12) << (it->second)/dNbOfEvents;
125  G4cout << G4endl;
126 
127  //compute true and projected ranges, and transverse dispersion
128  //
129  fTrueRange /= numberOfEvent; fTrueRange2 /= numberOfEvent;
130  G4double trueRms = fTrueRange2 - fTrueRange*fTrueRange;
131  if (trueRms>0.) trueRms = std::sqrt(trueRms); else trueRms = 0.;
132 
133  fProjRange /= numberOfEvent; fProjRange2 /= numberOfEvent;
134  G4double projRms = fProjRange2 - fProjRange*fProjRange;
135  if (projRms>0.) projRms = std::sqrt(projRms); else projRms = 0.;
136 
137  fTransvDev /= 2*numberOfEvent; fTransvDev2 /= 2*numberOfEvent;
138  G4double trvsRms = fTransvDev2 - fTransvDev*fTransvDev;
139  if (trvsRms>0.) trvsRms = std::sqrt(trvsRms); else trvsRms = 0.;
140 
141  //compare true range with csda range from PhysicsTables
142  //
143  G4Material* material = fDetector->GetMaterial();
144  G4double density = material->GetDensity();
145  //
146  G4EmCalculator emCalculator;
147  G4double rangeTable = 0.;
148  if (fParticle->GetPDGCharge() != 0.)
149  rangeTable = emCalculator.GetCSDARange(fEkin,fParticle,material);
150 
151  G4cout << "\n---------------------------------------------------------\n";
152  G4cout << " Primary particle : " ;
153  G4cout << "\n true Range = " << G4BestUnit(fTrueRange,"Length")
154  << " rms = " << G4BestUnit(trueRms, "Length");
155 
156  G4cout << "\n proj Range = " << G4BestUnit(fProjRange,"Length")
157  << " rms = " << G4BestUnit(projRms, "Length");
158 
159  G4cout << "\n proj/true = " << fProjRange/fTrueRange;
160 
161  G4cout << "\n transverse dispersion at end = "
162  << G4BestUnit(trvsRms,"Length");
163 
164  G4cout << "\n mass true Range from simulation = "
165  << G4BestUnit(fTrueRange*density, "Mass/Surface")
166  << "\n from PhysicsTable (csda range) = "
167  << G4BestUnit(rangeTable*density, "Mass/Surface");
168  G4cout << "\n---------------------------------------------------------\n";
169  G4cout << G4endl;
170 
171  //restore default format
172  G4cout.precision(dfprec);
173 
174  // remove all contents in fProcCounter
175  fProcCounter.clear();
176 }
177 
178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179 
180 void Run::Merge(const G4Run* run)
181 {
182  const Run* localRun = static_cast<const Run*>(run);
183 
184  // pass information about primary particle
185  fParticle = localRun->fParticle;
186  fEkin = localRun->fEkin;
187 
188  // accumulate sums
189  //
190  fNbOfTraks0 += localRun->fNbOfTraks0;
191  fNbOfTraks1 += localRun->fNbOfTraks1;
192  fNbOfSteps0 += localRun->fNbOfSteps0;
193  fNbOfSteps1 += localRun->fNbOfSteps1;
194  fEdep += localRun->fEdep;
195  fTrueRange += localRun->fTrueRange;
196  fTrueRange2 += localRun->fTrueRange2;
197  fProjRange += localRun->fProjRange;
198  fProjRange2 += localRun->fProjRange2;
199  fTransvDev += localRun->fTransvDev;
200  fTransvDev2 += localRun->fTransvDev2;
201 
202  //map
203  std::map<G4String,G4int>::const_iterator it;
204  for (it = localRun->fProcCounter.begin();
205  it !=localRun->fProcCounter.end(); ++it) {
206  fProcCounter[it->first] += it->second;
207  }
208 
209  G4Run::Merge(run);
210 }
211 
212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int numberOfEvent
Definition: G4Run.hh:59
const G4String & GetName() const
Definition: G4Material.hh:176
G4double GetDensity() const
Definition: G4Material.hh:178
#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
G4double GetCSDARange(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=0)
G4double density
Definition: TRTMaterials.hh:39
G4GLOB_DLL std::ostream G4cout
double energy
Definition: plottest35.C:25
void PrintSummary() const
Definition: Run.cc:73
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
Definition: G4Run.hh:46
void ComputeStatistics()
Definition: Run.cc:97
#define G4endl
Definition: G4ios.hh:61
void SetPrimary(G4ParticleDefinition *particle, G4double energy)
Definition: Run.cc:65
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4double GetPDGCharge() const
virtual void Merge(const G4Run *)
Definition: Run.cc:180
~Run()
Definition: Run.cc:60
Run(DetectorConstruction *)
Definition: Run.cc:46