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