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 #include "G4Gamma.hh"
41 
42 #include <iomanip>
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47 : G4Run(),
48  fDetector(det),
49  fParticle(0), fEkin(0.),
50  fTotalCount(0), fSumTrack(0.), fSumTrack2(0.), fEnTransfer(0.)
51 { }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55 Run::~Run()
56 { }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
63  fEkin = energy;
64 }
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
67 void Run::CountProcesses(G4String procName)
68 {
69  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
70  if ( it == fProcCounter.end()) {
71  fProcCounter[procName] = 1;
72  }
73  else {
74  fProcCounter[procName]++;
75  }
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  fTotalCount++;
83  fSumTrack += track;
84  fSumTrack2 += track*track;
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
96 void Run::Merge(const G4Run* run)
97 {
98  const Run* localRun = static_cast<const Run*>(run);
99 
100  // pass information about primary particle
101  fParticle = localRun->fParticle;
102  fEkin = localRun->fEkin;
103 
104  //map: processes count
105  std::map<G4String,G4int>::const_iterator it;
106  for (it = localRun->fProcCounter.begin();
107  it !=localRun->fProcCounter.end(); ++it) {
108 
109  G4String procName = it->first;
110  G4int localCount = it->second;
111  if ( fProcCounter.find(procName) == fProcCounter.end()) {
112  fProcCounter[procName] = localCount;
113  }
114  else {
115  fProcCounter[procName] += localCount;
116  }
117  }
118 
119  fTotalCount += localRun->fTotalCount;
120  fSumTrack += localRun->fSumTrack;
121  fSumTrack2 += localRun->fSumTrack2;
122  fEnTransfer += localRun->fEnTransfer;
123 
124  G4Run::Merge(run);
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 void Run::EndOfRun()
130 {
131  G4int prec = 5;
132  G4int dfprec = G4cout.precision(prec);
133 
134  //run condition
135  //
136  G4String partName = fParticle->GetParticleName();
138  G4double density = material->GetDensity();
139  G4double tickness = fDetector->GetSize();
140 
141  G4cout << "\n ======================== run summary ======================\n";
142  G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of "
143  << G4BestUnit(fEkin,"Energy") << " through "
144  << G4BestUnit(tickness,"Length") << " of "
145  << material->GetName() << " (density: "
146  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
147 
148  //frequency of processes
149  G4int survive = 0;
150  G4cout << "\n Process calls frequency --->";
151  std::map<G4String,G4int>::iterator it;
152  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
153  G4String procName = it->first;
154  G4int count = it->second;
155  G4cout << "\t" << procName << " = " << count;
156  if (procName == "Transportation") survive = count;
157  }
158 
159  if (survive > 0) {
160  G4cout << "\n\n Nb of incident particles surviving after "
161  << G4BestUnit(fDetector->GetSize(),"Length") << " of "
162  << material->GetName() << " : " << survive << G4endl;
163  }
164 
165  if (fTotalCount == 0) fTotalCount = 1; //force printing anyway
166 
167  //compute mean free path and related quantities
168  //
169  G4double MeanFreePath = fSumTrack /fTotalCount;
170  G4double MeanTrack2 = fSumTrack2/fTotalCount;
171  G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath));
172  G4double CrossSection = 1./MeanFreePath;
173  G4double massicMFP = MeanFreePath*density;
174  G4double massicCS = 1./massicMFP;
175 
176  G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath,"Length")
177  << " +- " << G4BestUnit( rms,"Length")
178  << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface")
179  << "\n CrossSection:\t" << CrossSection*cm << " cm^-1 "
180  << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass")
181  << G4endl;
182 
183  //compute energy transfer coefficient
184  //
185  G4double MeanTransfer = fEnTransfer/fTotalCount;
186  G4double massTransfCoef = massicCS*MeanTransfer/fEkin;
187 
188  G4cout << "\n mean energy of charged secondaries: "
189  << G4BestUnit(MeanTransfer, "Energy")
190  << "\n ---> mass_energy_transfer coef: "
191  << G4BestUnit(massTransfCoef, "Surface/Mass")
192  << G4endl;
193 
194  //check cross section from G4EmCalculator
195  //
196  G4cout << "\n Verification : "
197  << "crossSections from G4EmCalculator \n";
198 
199  G4EmCalculator emCalculator;
200  G4double sumc = 0.0;
201  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
202  G4String procName = it->first;
203  G4double massSigma =
205  procName,material)/density;
206  if (fParticle == G4Gamma::Gamma())
207  massSigma =
209  procName,material)/density;
210  sumc += massSigma;
211  G4cout << " " << procName << "= "
212  << G4BestUnit(massSigma, "Surface/Mass");
213  }
214  G4cout << " total= "
215  << G4BestUnit(sumc, "Surface/Mass") << G4endl;
216 
217  // remove all contents in fProcCounter
218  fProcCounter.clear();
219 
220  //restore default format
221  G4cout.precision(dfprec);
222 }
223 
224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......