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 #include "Run.hh"
30 #include "DetectorConstruction.hh"
31 #include "PrimaryGeneratorAction.hh"
32 
33 #include "G4Material.hh"
34 #include "G4SystemOfUnits.hh"
35 #include "G4UnitsTable.hh"
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 
39 Run::Run(const DetectorConstruction* detector)
40 : G4Run(),
41  fDetector(detector),
42  fParticle(0), fEkin(0.),
43  fTotalCount(0), fSumTrack(0.), fSumTrack2(0.), fEnTransfer(0.)
44 {}
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
48 Run::~Run()
49 {}
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
54 {
56  fEkin = energy;
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
61 void Run::CountProcesses(G4String procName)
62 {
63  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
64  if ( it == fProcCounter.end()) {
65  fProcCounter[procName] = 1;
66  }
67  else {
68  fProcCounter[procName]++;
69  }
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  fTotalCount++;
77  fSumTrack += track;
78  fSumTrack2 += track*track;
79 }
80 
81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
82 
84 {
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
90 void Run::Merge(const G4Run* run)
91 {
92  const Run* localRun = static_cast<const Run*>(run);
93 
94  // pass information about primary particle
95  fParticle = localRun->fParticle;
96  fEkin = localRun->fEkin;
97 
98  // map: processes count
99  std::map<G4String,G4int>::const_iterator it;
100  for (it = localRun->fProcCounter.begin();
101  it !=localRun->fProcCounter.end(); ++it) {
102 
103  G4String procName = it->first;
104  G4int localCount = it->second;
105  if ( fProcCounter.find(procName) == fProcCounter.end()) {
106  fProcCounter[procName] = localCount;
107  }
108  else {
109  fProcCounter[procName] += localCount;
110  }
111  }
112 
113  fTotalCount += localRun->fTotalCount;
114  fSumTrack += localRun->fSumTrack;
115  fSumTrack2 += localRun->fSumTrack2;
116  fEnTransfer += localRun->fEnTransfer;
117 
118  G4Run::Merge(run);
119 }
120 
121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
122 
123 void Run::EndOfRun()
124 {
125  std::ios::fmtflags mode = G4cout.flags();
126  G4cout.setf(std::ios::fixed,std::ios::floatfield);
127  G4int prec = G4cout.precision(2);
128 
129  // run conditions
131  G4double density = material->GetDensity();
132  G4String partName = fParticle->GetParticleName();
133 
134  G4cout <<
135  "\n ======================== run summary =====================\n";
136  G4cout
137  << "\n The run is " << numberOfEvent << " "<< partName << " of "
138  << G4BestUnit(fEkin,"Energy") << " through a sphere of radius "
139  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << "of "
140  << material->GetName() << " (density: "
141  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
142 
143  if (numberOfEvent == 0) {
144  G4cout.setf(mode,std::ios::floatfield);
145  G4cout.precision(prec);
146  return;
147  }
148 
149  // frequency of processes
150  G4int survive = 0;
151  G4cout << "\n Process calls frequency --->";
152  std::map<G4String,G4int>::iterator it;
153  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
154  G4String procName = it->first;
155  G4int count = it->second;
156  G4cout << "\t" << procName << " = " << count;
157  if (procName == "Transportation") survive = count;
158  }
159 
160  if (survive > 0) {
161  G4cout << "\n\n Nb of incident particles surviving after "
162  << "a radius of "
163  << G4BestUnit(fDetector->GetAbsorRadius(),"Length") << " of "
164  << material->GetName() << " : " << survive << G4endl;
165  }
166 
167  if (fTotalCount == 0) fTotalCount = 1; //force printing anyway
168 
169  // compute mean free path and related quantities
170  G4double MeanFreePath = fSumTrack /fTotalCount;
171  G4double MeanTrack2 = fSumTrack2/fTotalCount;
172  G4double rmsBis =
173  std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath));
174  G4double CrossSection = 1./MeanFreePath;
175  G4double massicMFP = MeanFreePath*density;
176  G4double massicCS = 1./massicMFP;
177 
178  G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath,"Length")
179  << " +- " << G4BestUnit(rmsBis,"Length")
180  << "\t\t\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface")
181  << "\n CrossSection:\t" << CrossSection*cm << " cm^-1 "
182  << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass")
183  << G4endl;
184 
185  // compute energy transfer coefficient
186  G4double MeanTransfer = fEnTransfer/fTotalCount;
187  G4double massTransfCoef = massicCS*MeanTransfer/fEkin;
188 
189  G4cout << "\n mean energy of charged secondaries: "
190  << G4BestUnit(MeanTransfer, "Energy")
191  << "\tmass_energy_transfer coef: "
192  << G4BestUnit(massTransfCoef, "Surface/Mass")
193  << G4endl;
194 
195  //output file
196  //
197  FILE* myFile;
198  myFile=fopen("mfp.txt","a");
199  fprintf(myFile,"%e %e %e \n",
200  fEkin/eV,
201  MeanFreePath/nm,
202  rmsBis/nm);
203  fclose(myFile);
204 
205  // remove all contents in fProcCounter
206  fProcCounter.clear();
207 
208  //reset default formats
209  //
210  G4cout.setf(mode,std::ios::floatfield);
211  G4cout.precision(prec);
212 
213 }