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