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.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 //
 26 /// \file Run.cc
 27 /// \brief Implementation of the Run class
 28 //
 29 //
 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32 
 33 #include "Run.hh"
 34 
 35 #include "DetectorConstruction.hh"
 36 #include "HistoManager.hh"
 37 #include "PrimaryGeneratorAction.hh"
 38 
 39 #include "G4SystemOfUnits.hh"
 40 #include "G4UnitsTable.hh"
 41 
 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 43 
 44 Run::Run(DetectorConstruction* det) : fDetector(det) {}
 45 
 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 47 
 48 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
 49 {
 50   fParticle = particle;
 51   fEkin = energy;
 52 }
 53 
 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 55 
 56 void Run::CountProcesses(const G4VProcess* process)
 57 {
 58   if (process == nullptr) return;
 59   G4String procName = process->GetProcessName();
 60   std::map<G4String, G4int>::iterator it = fProcCounter.find(procName);
 61   if (it == fProcCounter.end()) {
 62     fProcCounter[procName] = 1;
 63   }
 64   else {
 65     fProcCounter[procName]++;
 66   }
 67 }
 68 
 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 70 
 71 void Run::ParticleCount(G4String name, G4double Ekin, G4double meanLife)
 72 {
 73   std::map<G4String, ParticleData>::iterator it = fParticleDataMap1.find(name);
 74   if (it == fParticleDataMap1.end()) {
 75     fParticleDataMap1[name] = ParticleData(1, Ekin, Ekin, Ekin, meanLife);
 76   }
 77   else {
 78     ParticleData& data = it->second;
 79     data.fCount++;
 80     data.fEmean += Ekin;
 81     // update min max
 82     G4double emin = data.fEmin;
 83     if (Ekin < emin) data.fEmin = Ekin;
 84     G4double emax = data.fEmax;
 85     if (Ekin > emax) data.fEmax = Ekin;
 86     data.fTmean = meanLife;
 87   }
 88 }
 89 
 90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 91 
 92 void Run::AddEdep(G4double edep)
 93 {
 94   fEnergyDeposit += edep;
 95   fEnergyDeposit2 += edep * edep;
 96 }
 97 
 98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 99 
100 void Run::AddEflow(G4double eflow)
101 {
102   fEnergyFlow += eflow;
103   fEnergyFlow2 += eflow * eflow;
104 }
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
106 
107 void Run::ParticleFlux(G4String name, G4double Ekin)
108 {
109   std::map<G4String, ParticleData>::iterator it = fParticleDataMap2.find(name);
110   if (it == fParticleDataMap2.end()) {
111     fParticleDataMap2[name] = ParticleData(1, Ekin, Ekin, Ekin, -1 * ns);
112   }
113   else {
114     ParticleData& data = it->second;
115     data.fCount++;
116     data.fEmean += Ekin;
117     // update min max
118     G4double emin = data.fEmin;
119     if (Ekin < emin) data.fEmin = Ekin;
120     G4double emax = data.fEmax;
121     if (Ekin > emax) data.fEmax = Ekin;
122     data.fTmean = -1 * ns;
123   }
124 }
125 
126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127 
128 void Run::Merge(const G4Run* run)
129 {
130   const Run* localRun = static_cast<const Run*>(run);
131 
132   // primary particle info
133   //
134   fParticle = localRun->fParticle;
135   fEkin = localRun->fEkin;
136 
137   // accumulate sums
138   //
139   fEnergyDeposit += localRun->fEnergyDeposit;
140   fEnergyDeposit2 += localRun->fEnergyDeposit2;
141   fEnergyFlow += localRun->fEnergyFlow;
142   fEnergyFlow2 += localRun->fEnergyFlow2;
143 
144   // map: processes count
145   std::map<G4String, G4int>::const_iterator itp;
146   for (itp = localRun->fProcCounter.begin(); itp != localRun->fProcCounter.end(); ++itp) {
147     G4String procName = itp->first;
148     G4int localCount = itp->second;
149     if (fProcCounter.find(procName) == fProcCounter.end()) {
150       fProcCounter[procName] = localCount;
151     }
152     else {
153       fProcCounter[procName] += localCount;
154     }
155   }
156 
157   // map: created particles count
158   std::map<G4String, ParticleData>::const_iterator itc;
159   for (itc = localRun->fParticleDataMap1.begin(); itc != localRun->fParticleDataMap1.end(); ++itc) {
160     G4String name = itc->first;
161     const ParticleData& localData = itc->second;
162     if (fParticleDataMap1.find(name) == fParticleDataMap1.end()) {
163       fParticleDataMap1[name] = ParticleData(localData.fCount, localData.fEmean, localData.fEmin,
164                                              localData.fEmax, localData.fTmean);
165     }
166     else {
167       ParticleData& data = fParticleDataMap1[name];
168       data.fCount += localData.fCount;
169       data.fEmean += localData.fEmean;
170       G4double emin = localData.fEmin;
171       if (emin < data.fEmin) data.fEmin = emin;
172       G4double emax = localData.fEmax;
173       if (emax > data.fEmax) data.fEmax = emax;
174       data.fTmean = localData.fTmean;
175     }
176   }
177 
178   // map: particles flux count
179   std::map<G4String, ParticleData>::const_iterator itn;
180   for (itn = localRun->fParticleDataMap2.begin(); itn != localRun->fParticleDataMap2.end(); ++itn) {
181     G4String name = itn->first;
182     const ParticleData& localData = itn->second;
183     if (fParticleDataMap2.find(name) == fParticleDataMap2.end()) {
184       fParticleDataMap2[name] = ParticleData(localData.fCount, localData.fEmean, localData.fEmin,
185                                              localData.fEmax, localData.fTmean);
186     }
187     else {
188       ParticleData& data = fParticleDataMap2[name];
189       data.fCount += localData.fCount;
190       data.fEmean += localData.fEmean;
191       G4double emin = localData.fEmin;
192       if (emin < data.fEmin) data.fEmin = emin;
193       G4double emax = localData.fEmax;
194       if (emax > data.fEmax) data.fEmax = emax;
195       data.fTmean = localData.fTmean;
196     }
197   }
198 
199   G4Run::Merge(run);
200 }
201 
202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
203 
204 void Run::EndOfRun()
205 {
206   G4int prec = 5, wid = prec + 2;
207   G4int dfprec = G4cout.precision(prec);
208 
209   // run condition
210   //
211   G4Material* material = fDetector->GetAbsorMaterial();
212   G4String Particle = fParticle->GetParticleName();
213   G4cout << "\n The run is " << numberOfEvent << " " << Particle << " of "
214          << G4BestUnit(fEkin, "Energy") << " within " << material->GetName()
215          << " (D =  " << G4BestUnit(2 * (fDetector->GetAbsorRadius()), "Length")
216          << " L = " << G4BestUnit(fDetector->GetAbsorLength(), "Length") << ")" << G4endl;
217 
218   if (numberOfEvent == 0) {
219     G4cout.precision(dfprec);
220     return;
221   }
222 
223   // frequency of processes
224   //
225   G4cout << "\n Process calls frequency :" << G4endl;
226   G4int index = 0;
227   std::map<G4String, G4int>::iterator it;
228   for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
229     G4String procName = it->first;
230     G4int count = it->second;
231     G4String space = " ";
232     if (++index % 3 == 0) space = "\n";
233     G4cout << " " << std::setw(20) << procName << "=" << std::setw(7) << count << space;
234   }
235   G4cout << G4endl;
236 
237   // particles count
238   //
239   G4cout << "\n List of generated particles (with meanLife != 0) :" << G4endl;
240 
241   std::map<G4String, ParticleData>::iterator itc;
242   for (itc = fParticleDataMap1.begin(); itc != fParticleDataMap1.end(); itc++) {
243     G4String name = itc->first;
244     ParticleData data = itc->second;
245     G4int count = data.fCount;
246     G4double eMean = data.fEmean / count;
247     G4double eMin = data.fEmin;
248     G4double eMax = data.fEmax;
249     G4double meanLife = data.fTmean;
250 
251     G4cout << "  " << std::setw(13) << name << ": " << std::setw(7) << count
252            << "  Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy") << "\t( "
253            << G4BestUnit(eMin, "Energy") << " --> " << G4BestUnit(eMax, "Energy") << ")";
254     if (meanLife >= 0.)
255       G4cout << "\tmean life = " << G4BestUnit(meanLife, "Time") << G4endl;
256     else
257       G4cout << "\tstable" << G4endl;
258   }
259 
260   // compute mean Energy deposited and rms
261   //
262   G4int TotNbofEvents = numberOfEvent;
263   fEnergyDeposit /= TotNbofEvents;
264   fEnergyDeposit2 /= TotNbofEvents;
265   G4double rmsEdep = fEnergyDeposit2 - fEnergyDeposit * fEnergyDeposit;
266   if (rmsEdep > 0.)
267     rmsEdep = std::sqrt(rmsEdep);
268   else
269     rmsEdep = 0.;
270 
271   G4cout << "\n Mean energy deposit per event = " << G4BestUnit(fEnergyDeposit, "Energy")
272          << ";  rms = " << G4BestUnit(rmsEdep, "Energy") << G4endl;
273 
274   // compute mean Energy flow and rms
275   //
276   fEnergyFlow /= TotNbofEvents;
277   fEnergyFlow2 /= TotNbofEvents;
278   G4double rmsEflow = fEnergyFlow2 - fEnergyFlow * fEnergyFlow;
279   if (rmsEflow > 0.)
280     rmsEflow = std::sqrt(rmsEflow);
281   else
282     rmsEflow = 0.;
283 
284   G4cout << " Mean energy flow per event    = " << G4BestUnit(fEnergyFlow, "Energy")
285          << ";  rms = " << G4BestUnit(rmsEflow, "Energy") << G4endl;
286 
287   // particles flux
288   //
289   G4cout << "\n List of particles emerging from the container :" << G4endl;
290 
291   std::map<G4String, ParticleData>::iterator itn;
292   for (itn = fParticleDataMap2.begin(); itn != fParticleDataMap2.end(); itn++) {
293     G4String name = itn->first;
294     ParticleData data = itn->second;
295     G4int count = data.fCount;
296     G4double eMean = data.fEmean / count;
297     G4double eMin = data.fEmin;
298     G4double eMax = data.fEmax;
299     G4double Eflow = data.fEmean / TotNbofEvents;
300 
301     G4cout << "  " << std::setw(13) << name << ": " << std::setw(7) << count
302            << "  Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy") << "\t( "
303            << G4BestUnit(eMin, "Energy") << " --> " << G4BestUnit(eMax, "Energy")
304            << ") \tEflow/event = " << G4BestUnit(Eflow, "Energy") << G4endl;
305   }
306 
307   // remove all contents in fProcCounter, fCount
308   fProcCounter.clear();
309   fParticleDataMap2.clear();
310 
311   // restore default format
312   G4cout.precision(dfprec);
313 }
314 
315 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316