ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Run.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Run.cc
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 //
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33 #include "Run.hh"
34 #include "DetectorConstruction.hh"
35 #include "PrimaryGeneratorAction.hh"
36 
37 #include "G4UnitsTable.hh"
38 #include "G4SystemOfUnits.hh"
39 #include "G4EmCalculator.hh"
40 
41 #include <iomanip>
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
46 : G4Run(),
47  fDetector(det),
48  fParticle(0), fEkin(0.),
49  fNbOfTraks0(0), fNbOfTraks1(0),
50  fNbOfSteps0(0), fNbOfSteps1(0),
51  fEdep(0.), fNIEL(0.),
52  fTrueRange(0.), fTrueRange2(0.),
53  fProjRange(0.), fProjRange2(0.),
54  fTransvDev(0.), fTransvDev2(0.)
55 { }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 Run::~Run()
60 { }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
67  fEkin = energy;
68 }
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
71 void Run::CountProcesses(const G4String& procName)
72 {
73  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
74  if ( it == fProcCounter.end()) {
75  fProcCounter[procName] = 1;
76  }
77  else {
78  fProcCounter[procName]++;
79  }
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
84 void Run::Merge(const G4Run* run)
85 {
86  const Run* localRun = static_cast<const Run*>(run);
87 
88  // pass information about primary particle
89  fParticle = localRun->fParticle;
90  fEkin = localRun->fEkin;
91 
92  // accumulate sums
93  //
94  fNbOfTraks0 += localRun->fNbOfTraks0;
95  fNbOfTraks1 += localRun->fNbOfTraks1;
96  fNbOfSteps0 += localRun->fNbOfSteps0;
97  fNbOfSteps1 += localRun->fNbOfSteps1;
98  fEdep += localRun->fEdep;
99  fNIEL += localRun->fNIEL;
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();
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 = (G4double)numberOfEvent;
148  G4cout << "\n Total energy deposit: "
149  << G4BestUnit(fEdep/dNbOfEvents, "Energy") << G4endl;
150  G4cout << " NIEL energy calculated: "
151  << G4BestUnit(fNIEL/dNbOfEvents, "Energy") << G4endl;
152 
153  //nb of tracks and steps per event
154  //
155  G4cout << "\n Nb tracks/event"
156  << " neutral: " << std::setw(wid) << fNbOfTraks0/dNbOfEvents
157  << " charged: " << std::setw(wid) << fNbOfTraks1/dNbOfEvents
158  << "\n Nb steps/event"
159  << " neutral: " << std::setw(wid) << fNbOfSteps0/dNbOfEvents
160  << " charged: " << std::setw(wid) << fNbOfSteps1/dNbOfEvents
161  << G4endl;
162 
163  //frequency of processes
164  //
165  G4cout << "\n Process calls frequency :" << G4endl;
166  G4int index = 0;
167  std::map<G4String,G4int>::iterator it;
168  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
169  G4String procName = it->first;
170  G4int count = it->second;
171  G4String space = " "; if (++index%3 == 0) space = "\n";
172  G4cout << " " << std::setw(20) << procName << "="<< std::setw(7) << count
173  << space;
174  }
175  G4cout << G4endl;
176 
177  //compute true and projected ranges, and transverse dispersion
178  //
181  if (trueRms>0.) trueRms = std::sqrt(trueRms); else trueRms = 0.;
182 
185  if (projRms>0.) projRms = std::sqrt(projRms); else projRms = 0.;
186 
189  if (trvsRms>0.) trvsRms = std::sqrt(trvsRms); else trvsRms = 0.;
190 
191  //compare true range with csda range from PhysicsTables
192  //
193  G4EmCalculator emCalculator;
194  G4double rangeTable = 0.;
195  if (fParticle->GetPDGCharge() != 0.)
196  rangeTable = emCalculator.GetCSDARange(fEkin,fParticle,material);
197 
198  G4cout << "\n---------------------------------------------------------\n";
199  G4cout << " Primary particle : " ;
200  G4cout << "\n true Range = " << G4BestUnit(fTrueRange,"Length")
201  << " rms = " << G4BestUnit(trueRms, "Length");
202 
203  G4cout << "\n proj Range = " << G4BestUnit(fProjRange,"Length")
204  << " rms = " << G4BestUnit(projRms, "Length");
205 
206  G4cout << "\n proj/true = " << fProjRange/fTrueRange;
207 
208  G4cout << "\n transverse dispersion at end = "
209  << G4BestUnit(trvsRms,"Length");
210 
211  G4cout << "\n mass true Range from simulation = "
212  << G4BestUnit(fTrueRange*density, "Mass/Surface")
213  << "\n from PhysicsTable (csda range) = "
214  << G4BestUnit(rangeTable*density, "Mass/Surface");
215  G4cout << "\n---------------------------------------------------------\n";
216  G4cout << G4endl;
217 
218  // remove all contents in fProcCounter
219  fProcCounter.clear();
220 
221  //restore default format
222  G4cout.precision(dfprec);
223 }
224 
225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......