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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 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 "G4Electron.hh"
 39 #include "G4Gamma.hh"
 40 #include "G4ParticleDefinition.hh"
 41 #include "G4ParticleTable.hh"
 42 #include "G4Positron.hh"
 43 #include "G4SystemOfUnits.hh"
 44 #include "G4Track.hh"
 45 #include "G4UnitsTable.hh"
 46 
 47 #include <iomanip>
 48 
 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50 
 51 Run::Run(DetectorConstruction* det)
 52   : G4Run(),
 53     fDetector(det),
 54     fParticle(nullptr),
 55     fEkin(0.),
 56     fChargedStep(0),
 57     fNeutralStep(0),
 58     fN_gamma(0),
 59     fN_elec(0),
 60     fN_pos(0)
 61 {
 62   // initialize cumulative quantities
 63   //
 64   for (G4int k = 0; k < kMaxAbsor; k++) {
 65     fSumEAbs[k] = fSum2EAbs[k] = fSumLAbs[k] = fSum2LAbs[k] = 0.;
 66     fEnergyDeposit[k].clear();
 67   }
 68 }
 69 
 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71 
 72 Run::~Run() {}
 73 
 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 75 
 76 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
 77 {
 78   fParticle = particle;
 79   fEkin = energy;
 80 }
 81 
 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 83 
 84 void Run::FillPerEvent(G4int kAbs, G4double EAbs, G4double LAbs)
 85 {
 86   // accumulate statistic with restriction
 87   //
 88   fEnergyDeposit[kAbs].push_back(EAbs);
 89   fSumEAbs[kAbs] += EAbs;
 90   fSum2EAbs[kAbs] += EAbs * EAbs;
 91   fSumLAbs[kAbs] += LAbs;
 92   fSum2LAbs[kAbs] += LAbs * LAbs;
 93 }
 94 
 95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 96 
 97 void Run::AddChargedStep()
 98 {
 99   fChargedStep += 1.0;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
104 void Run::AddNeutralStep()
105 {
106   fNeutralStep += 1.0;
107 }
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110 
111 void Run::AddSecondaryTrack(const G4Track* track)
112 {
113   const G4ParticleDefinition* d = track->GetDefinition();
114   if (d == G4Gamma::Gamma()) {
115     ++fN_gamma;
116   }
117   else if (d == G4Electron::Electron()) {
118     ++fN_elec;
119   }
120   else if (d == G4Positron::Positron()) {
121     ++fN_pos;
122   }
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
127 void Run::Merge(const G4Run* run)
128 {
129   const Run* localRun = static_cast<const Run*>(run);
130 
131   // pass information about primary particle
132   fParticle = localRun->fParticle;
133   fEkin = localRun->fEkin;
134 
135   // accumulate sums
136   //
137   for (G4int k = 0; k < kMaxAbsor; k++) {
138     fSumEAbs[k] += localRun->fSumEAbs[k];
139     fSum2EAbs[k] += localRun->fSum2EAbs[k];
140     fSumLAbs[k] += localRun->fSumLAbs[k];
141     fSum2LAbs[k] += localRun->fSum2LAbs[k];
142   }
143 
144   fChargedStep += localRun->fChargedStep;
145   fNeutralStep += localRun->fNeutralStep;
146 
147   fN_gamma += localRun->fN_gamma;
148   fN_elec += localRun->fN_elec;
149   fN_pos += localRun->fN_pos;
150 
151   G4Run::Merge(run);
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155 
156 void Run::EndOfRun()
157 {
158   G4int nEvt = numberOfEvent;
159   G4double norm = G4double(nEvt);
160   if (norm > 0) norm = 1. / norm;
161   G4double qnorm = std::sqrt(norm);
162 
163   fChargedStep *= norm;
164   fNeutralStep *= norm;
165 
166   // compute and print statistic
167   //
168   G4double beamEnergy = fEkin;
169   G4double sqbeam = std::sqrt(beamEnergy / GeV);
170 
171   G4double MeanEAbs, MeanEAbs2, rmsEAbs, resolution, rmsres;
172   G4double MeanLAbs, MeanLAbs2, rmsLAbs;
173 
174   std::ios::fmtflags mode = G4cout.flags();
175   G4int prec = G4cout.precision(2);
176   G4cout << "\n------------------------------------------------------------\n";
177   G4cout << std::setw(14) << "material" << std::setw(17) << "Edep       RMS" << std::setw(33)
178          << "sqrt(E0(GeV))*rmsE/Emean" << std::setw(23) << "total tracklen \n \n";
179 
180   for (G4int k = 1; k <= fDetector->GetNbOfAbsor(); k++) {
181     MeanEAbs = fSumEAbs[k] * norm;
182     MeanEAbs2 = fSum2EAbs[k] * norm;
183     rmsEAbs = std::sqrt(std::abs(MeanEAbs2 - MeanEAbs * MeanEAbs));
184 
185     resolution = 100. * sqbeam * rmsEAbs / MeanEAbs;
186     rmsres = resolution * qnorm;
187 
188     // Save mean and RMS
189     fSumEAbs[k] = MeanEAbs;
190     fSum2EAbs[k] = rmsEAbs;
191 
192     MeanLAbs = fSumLAbs[k] * norm;
193     MeanLAbs2 = fSum2LAbs[k] * norm;
194     rmsLAbs = std::sqrt(std::abs(MeanLAbs2 - MeanLAbs * MeanLAbs));
195 
196     // print
197     //
198     G4cout << std::setw(14) << fDetector->GetAbsorMaterial(k)->GetName() << ": "
199            << std::setprecision(5) << std::setw(6) << G4BestUnit(MeanEAbs, "Energy") << " :  "
200            << std::setprecision(4) << std::setw(5) << G4BestUnit(rmsEAbs, "Energy") << std::setw(10)
201            << resolution << " +- " << std::setw(5) << rmsres << " %" << std::setprecision(3)
202            << std::setw(10) << G4BestUnit(MeanLAbs, "Length") << " +- " << std::setw(4)
203            << G4BestUnit(rmsLAbs, "Length") << G4endl;
204   }
205   G4cout << "\n------------------------------------------------------------\n";
206 
207   G4cout << " Beam particle " << fParticle->GetParticleName()
208          << "  E = " << G4BestUnit(beamEnergy, "Energy") << G4endl;
209   G4cout << " Mean number of gamma       " << (G4double)fN_gamma * norm << G4endl;
210   G4cout << " Mean number of e-          " << (G4double)fN_elec * norm << G4endl;
211   G4cout << " Mean number of e+          " << (G4double)fN_pos * norm << G4endl;
212   G4cout << std::setprecision(6) << " Mean number of charged steps  " << fChargedStep << G4endl;
213   G4cout << " Mean number of neutral steps  " << fNeutralStep << G4endl;
214   G4cout << "------------------------------------------------------------\n" << G4endl;
215 
216   G4cout.setf(mode, std::ios::floatfield);
217   G4cout.precision(prec);
218 }
219 
220 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
221