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 { }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
54 Run::~Run()
55 { }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
62  fEkin = energy;
63 }
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 {
68  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
69  if ( it == fProcCounter.end()) {
70  fProcCounter[procName] = 1;
71  }
72  else {
73  fProcCounter[procName]++;
74  }
75 }
76 
77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78 
79 void Run::Merge(const G4Run* run)
80 {
81  const Run* localRun = static_cast<const Run*>(run);
82 
83  // pass information about primary particle
84  fParticle = localRun->fParticle;
85  fEkin = localRun->fEkin;
86 
87  //map: processes count
88  std::map<G4String,G4int>::const_iterator it;
89  for (it = localRun->fProcCounter.begin();
90  it !=localRun->fProcCounter.end(); ++it) {
91 
92  G4String procName = it->first;
93  G4int localCount = it->second;
94  if ( fProcCounter.find(procName) == fProcCounter.end()) {
95  fProcCounter[procName] = localCount;
96  }
97  else {
98  fProcCounter[procName] += localCount;
99  }
100  }
101 
102  G4Run::Merge(run);
103 }
104 
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
106 
107 void Run::EndOfRun()
108 {
109  G4int prec = 5;
110  G4int dfprec = G4cout.precision(prec);
111 
112  //run condition
113  //
114  G4String partName = fParticle->GetParticleName();
116  G4double density = material->GetDensity();
117  G4double tickness = fDetector->GetSize();
118 
119  G4cout << "\n ======================== run summary ======================\n";
120  G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of "
121  << G4BestUnit(fEkin,"Energy") << " through "
122  << G4BestUnit(tickness,"Length") << " of "
123  << material->GetName() << " (density: "
124  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
125 
126  //frequency of processes
127  G4int totalCount = 0;
128  G4int survive = 0;
129  G4cout << "\n Process calls frequency --->";
130  std::map<G4String,G4int>::iterator it;
131  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
132  G4String procName = it->first;
133  G4int count = it->second;
134  totalCount += count;
135  G4cout << "\t" << procName << " = " << count;
136  if (procName == "Transportation") survive = count;
137  }
138  G4cout << G4endl;
139 
140  if (totalCount == 0) { G4cout.precision(dfprec); return;};
141  G4double ratio = double(survive)/totalCount;
142 
143  G4cout << "\n Nb of incident particles unaltered after "
144  << G4BestUnit(tickness,"Length") << " of "
145  << material->GetName() << " : " << survive
146  << " over " << totalCount << " incident particles."
147  << " Ratio = " << 100*ratio << " %" << G4endl;
148 
149  if (ratio == 0.) return;
150 
151  //compute cross section and related quantities
152  //
153  G4double CrossSection = - std::log(ratio)/tickness;
154  G4double massicCS = CrossSection/density;
155 
156  G4cout << " ---> CrossSection per volume:\t" << CrossSection*cm << " cm^-1 "
157  << "\tCrossSection per mass: " << G4BestUnit(massicCS, "Surface/Mass")
158  << G4endl;
159 
160  //check cross section from G4EmCalculator
161  //
162  G4cout << "\n Verification from G4EmCalculator: \n";
163  G4EmCalculator emCalculator;
164  G4double sumc = 0.0;
165  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
166  G4String procName = it->first;
167  G4double massSigma =
169  procName,material)/density;
170  if (fParticle == G4Gamma::Gamma())
171  massSigma =
173  procName,material)/density;
174  sumc += massSigma;
175  if (procName != "Transportation")
176  G4cout << "\t" << procName << "= "
177  << G4BestUnit(massSigma, "Surface/Mass");
178  }
179  G4cout << "\ttotal= "
180  << G4BestUnit(sumc, "Surface/Mass") << G4endl;
181 
182  //expected ratio of transmitted particles
183  G4double Ratio = std::exp(-sumc*density*tickness);
184  G4cout << "\tExpected ratio of transmitted particles= "
185  << 100*Ratio << " %" << G4endl;
186 
187  // remove all contents in fProcCounter
188  fProcCounter.clear();
189 
190  //restore default format
191  G4cout.precision(dfprec);
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......