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 #include "HistoManager.hh"
37 
38 #include "G4UnitsTable.hh"
39 #include "G4SystemOfUnits.hh"
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
44 : G4Run(),
45  fDetector(det), fParticle(0), fEkin(0.),
46  fNbStep1(0), fNbStep2(0),
47  fTrackLen1(0.), fTrackLen2(0.),
48  fTime1(0.),fTime2(0.)
49 { }
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
52 Run::~Run()
53 { }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 {
60  fEkin = energy;
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
65 void Run::CountProcesses(const G4VProcess* process)
66 {
67  G4String procName = process->GetProcessName();
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 
80 {
81  std::map<G4String, ParticleData>::iterator it = fParticleDataMap.find(name);
82  if ( it == fParticleDataMap.end()) {
83  fParticleDataMap[name] = ParticleData(1, Ekin, Ekin, Ekin);
84  }
85  else {
86  ParticleData& data = it->second;
87  data.fCount++;
88  data.fEmean += Ekin;
89  //update min max
90  G4double emin = data.fEmin;
91  if (Ekin < emin) data.fEmin = Ekin;
92  G4double emax = data.fEmax;
93  if (Ekin > emax) data.fEmax = Ekin;
94  }
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
98 
99 void Run::SumTrackLength(G4int nstep1, G4int nstep2,
100  G4double trackl1, G4double trackl2,
101  G4double time1, G4double time2)
102 {
103  fNbStep1 += nstep1; fNbStep2 += nstep2;
104  fTrackLen1 += trackl1; fTrackLen2 += trackl2;
105  fTime1 += time1; fTime2 += time2;
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
110 void Run::Merge(const G4Run* run)
111 {
112  const Run* localRun = static_cast<const Run*>(run);
113 
114  //primary particle info
115  //
116  fParticle = localRun->fParticle;
117  fEkin = localRun->fEkin;
118 
119  // accumulate sums
120  //
121  fNbStep1 += localRun->fNbStep1;
122  fNbStep2 += localRun->fNbStep2;
123  fTrackLen1 += localRun->fTrackLen1;
124  fTrackLen2 += localRun->fTrackLen2;
125  fTime1 += localRun->fTime1;
126  fTime2 += localRun->fTime2;
127 
128  //map: processes count
129  std::map<G4String,G4int>::const_iterator itp;
130  for ( itp = localRun->fProcCounter.begin();
131  itp != localRun->fProcCounter.end(); ++itp ) {
132 
133  G4String procName = itp->first;
134  G4int localCount = itp->second;
135  if ( fProcCounter.find(procName) == fProcCounter.end()) {
136  fProcCounter[procName] = localCount;
137  }
138  else {
139  fProcCounter[procName] += localCount;
140  }
141  }
142 
143  //map: created particles count
144  std::map<G4String,ParticleData>::const_iterator itn;
145  for (itn = localRun->fParticleDataMap.begin();
146  itn != localRun->fParticleDataMap.end(); ++itn) {
147 
148  G4String name = itn->first;
149  const ParticleData& localData = itn->second;
150  if ( fParticleDataMap.find(name) == fParticleDataMap.end()) {
152  = ParticleData(localData.fCount,
153  localData.fEmean,
154  localData.fEmin,
155  localData.fEmax);
156  }
157  else {
158  ParticleData& data = fParticleDataMap[name];
159  data.fCount += localData.fCount;
160  data.fEmean += localData.fEmean;
161  G4double emin = localData.fEmin;
162  if (emin < data.fEmin) data.fEmin = emin;
163  G4double emax = localData.fEmax;
164  if (emax > data.fEmax) data.fEmax = emax;
165  }
166  }
167 
168  G4Run::Merge(run);
169 }
170 
171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
172 
173 void Run::EndOfRun()
174 {
175  G4int prec = 5, wid = prec + 2;
176  G4int dfprec = G4cout.precision(prec);
177 
178  //run condition
179  //
181  G4double density = material->GetDensity();
182 
183  G4String Particle = fParticle->GetParticleName();
184  G4cout << "\n The run is " << numberOfEvent << " "<< Particle << " of "
185  << G4BestUnit(fEkin,"Energy") << " through "
186  << G4BestUnit(0.5*(fDetector->GetSize()),"Length") << " of "
187  << material->GetName() << " (density: "
188  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
189 
190  if (numberOfEvent == 0) { G4cout.precision(dfprec); return;}
191 
192  //frequency of processes
193  //
194  G4cout << "\n Process calls frequency :" << G4endl;
195  G4int survive = 0;
196  std::map<G4String,G4int>::iterator it;
197  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
198  G4String procName = it->first;
199  G4int count = it->second;
200  G4cout << "\t" << procName << "= " << count;
201  if (procName == "Transportation") survive = count;
202  }
203  G4cout << G4endl;
204 
205  if (survive > 0) {
206  G4cout << "\n Nb of incident particles surviving after "
207  << G4BestUnit(0.5*(fDetector->GetSize()),"Length") << " of "
208  << fDetector->GetMaterial()->GetName() << " : " << survive << G4endl;
209  }
210 
211  // total track length of incident neutron
212  //
213  G4cout << "\n Parcours of incident neutron:";
214 
215  G4double meanCollision1 = (G4double)fNbStep1/numberOfEvent;
216  G4double meanCollision2 = (G4double)fNbStep2/numberOfEvent;
217  G4double meanCollisTota = meanCollision1 + meanCollision2;
218 
219  G4cout << "\n nb of collisions E>1*eV= " << meanCollision1
220  << " E<1*eV= " << meanCollision2
221  << " total= " << meanCollisTota;
222 
223  G4double meanTrackLen1 = fTrackLen1/numberOfEvent;
224  G4double meanTrackLen2 = fTrackLen2/numberOfEvent;
225  G4double meanTrackLtot = meanTrackLen1 + meanTrackLen2;
226 
227  G4cout
228  << "\n track length E>1*eV= " << G4BestUnit(meanTrackLen1,"Length")
229  << " E<1*eV= " << G4BestUnit(meanTrackLen2, "Length")
230  << " total= " << G4BestUnit(meanTrackLtot, "Length");
231 
232  G4double meanTime1 = fTime1/numberOfEvent;
233  G4double meanTime2 = fTime2/numberOfEvent;
234  G4double meanTimeTo = meanTime1 + meanTime2;
235 
236  G4cout
237  << "\n time of flight E>1*eV= " << G4BestUnit(meanTime1,"Time")
238  << " E<1*eV= " << G4BestUnit(meanTime2, "Time")
239  << " total= " << G4BestUnit(meanTimeTo, "Time") << G4endl;
240 
241  //particles count
242  //
243  G4cout << "\n List of generated particles:" << G4endl;
244 
245  std::map<G4String,ParticleData>::iterator itn;
246  for (itn = fParticleDataMap.begin(); itn != fParticleDataMap.end(); itn++) {
247  G4String name = itn->first;
248  ParticleData data = itn->second;
249  G4int count = data.fCount;
250  G4double eMean = data.fEmean/count;
251  G4double eMin = data.fEmin;
252  G4double eMax = data.fEmax;
253 
254  G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count
255  << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy")
256  << "\t( " << G4BestUnit(eMin, "Energy")
257  << " --> " << G4BestUnit(eMax, "Energy")
258  << ")" << G4endl;
259  }
260 
261  //normalize histograms
265 
266  //remove all contents in fProcCounter, fCount
267  fProcCounter.clear();
268  fParticleDataMap.clear();
269 
270  //restore default format
271  G4cout.precision(dfprec);
272 }
273 
274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......