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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 ]

Diff markup

Differences between /examples/extended/runAndEvent/RE07/src/Run.cc (Version 11.3.0) and /examples/extended/runAndEvent/RE07/src/Run.cc (Version 11.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /// \file src/Run.cc                               26 /// \file src/Run.cc
 27 /// \brief Implementation of the Run class         27 /// \brief Implementation of the Run class
 28 //                                                 28 //
 29 //                                                 29 //
 30 //....oooOO0OOooo........oooOO0OOooo........oo     30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31 //....oooOO0OOooo........oooOO0OOooo........oo     31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32                                                    32 
 33 #include "Run.hh"                                  33 #include "Run.hh"
 34                                                << 
 35 #include "DetectorConstruction.hh"                 34 #include "DetectorConstruction.hh"
 36 #include "PrimaryGeneratorAction.hh"               35 #include "PrimaryGeneratorAction.hh"
 37                                                    36 
 38 #include "G4Electron.hh"                           37 #include "G4Electron.hh"
 39 #include "G4Gamma.hh"                              38 #include "G4Gamma.hh"
 40 #include "G4ParticleDefinition.hh"                 39 #include "G4ParticleDefinition.hh"
 41 #include "G4ParticleTable.hh"                      40 #include "G4ParticleTable.hh"
 42 #include "G4Positron.hh"                           41 #include "G4Positron.hh"
 43 #include "G4SystemOfUnits.hh"                  << 
 44 #include "G4Track.hh"                              42 #include "G4Track.hh"
                                                   >>  43 
                                                   >>  44 #include "G4SystemOfUnits.hh"
 45 #include "G4UnitsTable.hh"                         45 #include "G4UnitsTable.hh"
 46                                                    46 
 47 #include <iomanip>                                 47 #include <iomanip>
 48                                                    48 
 49 //....oooOO0OOooo........oooOO0OOooo........oo     49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50                                                    50 
 51 Run::Run(DetectorConstruction* det)                51 Run::Run(DetectorConstruction* det)
 52   : G4Run(),                                   <<  52   : G4Run()
 53     fDetector(det),                            <<  53   , fDetector(det)
 54     fParticle(nullptr),                        <<  54   , fParticle(nullptr)
 55     fEkin(0.),                                 <<  55   , fEkin(0.)
 56     fChargedStep(0),                           <<  56   , fChargedStep(0)
 57     fNeutralStep(0),                           <<  57   , fNeutralStep(0)
 58     fN_gamma(0),                               <<  58   , fN_gamma(0)
 59     fN_elec(0),                                <<  59   , fN_elec(0)
 60     fN_pos(0)                                  <<  60   , fN_pos(0)
 61 {                                                  61 {
 62   // initialize cumulative quantities              62   // initialize cumulative quantities
 63   //                                               63   //
 64   for (G4int k = 0; k < kMaxAbsor; k++) {      <<  64   for(G4int k = 0; k < kMaxAbsor; k++)
                                                   >>  65   {
 65     fSumEAbs[k] = fSum2EAbs[k] = fSumLAbs[k] =     66     fSumEAbs[k] = fSum2EAbs[k] = fSumLAbs[k] = fSum2LAbs[k] = 0.;
 66     fEnergyDeposit[k].clear();                     67     fEnergyDeposit[k].clear();
 67   }                                                68   }
 68 }                                                  69 }
 69                                                    70 
 70 //....oooOO0OOooo........oooOO0OOooo........oo     71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71                                                    72 
 72 Run::~Run() {}                                     73 Run::~Run() {}
 73                                                    74 
 74 //....oooOO0OOooo........oooOO0OOooo........oo     75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 75                                                    76 
 76 void Run::SetPrimary(G4ParticleDefinition* par     77 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
 77 {                                                  78 {
 78   fParticle = particle;                            79   fParticle = particle;
 79   fEkin = energy;                              <<  80   fEkin     = energy;
 80 }                                                  81 }
 81                                                    82 
 82 //....oooOO0OOooo........oooOO0OOooo........oo     83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 83                                                    84 
 84 void Run::FillPerEvent(G4int kAbs, G4double EA     85 void Run::FillPerEvent(G4int kAbs, G4double EAbs, G4double LAbs)
 85 {                                                  86 {
 86   // accumulate statistic with restriction         87   // accumulate statistic with restriction
 87   //                                               88   //
 88   fEnergyDeposit[kAbs].push_back(EAbs);            89   fEnergyDeposit[kAbs].push_back(EAbs);
 89   fSumEAbs[kAbs] += EAbs;                          90   fSumEAbs[kAbs] += EAbs;
 90   fSum2EAbs[kAbs] += EAbs * EAbs;                  91   fSum2EAbs[kAbs] += EAbs * EAbs;
 91   fSumLAbs[kAbs] += LAbs;                          92   fSumLAbs[kAbs] += LAbs;
 92   fSum2LAbs[kAbs] += LAbs * LAbs;                  93   fSum2LAbs[kAbs] += LAbs * LAbs;
 93 }                                                  94 }
 94                                                    95 
 95 //....oooOO0OOooo........oooOO0OOooo........oo     96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 96                                                    97 
 97 void Run::AddChargedStep()                     <<  98 void Run::AddChargedStep() { fChargedStep += 1.0; }
 98 {                                              << 
 99   fChargedStep += 1.0;                         << 
100 }                                              << 
101                                                    99 
102 //....oooOO0OOooo........oooOO0OOooo........oo    100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103                                                   101 
104 void Run::AddNeutralStep()                     << 102 void Run::AddNeutralStep() { fNeutralStep += 1.0; }
105 {                                              << 
106   fNeutralStep += 1.0;                         << 
107 }                                              << 
108                                                   103 
109 //....oooOO0OOooo........oooOO0OOooo........oo    104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110                                                   105 
111 void Run::AddSecondaryTrack(const G4Track* tra    106 void Run::AddSecondaryTrack(const G4Track* track)
112 {                                                 107 {
113   const G4ParticleDefinition* d = track->GetDe    108   const G4ParticleDefinition* d = track->GetDefinition();
114   if (d == G4Gamma::Gamma()) {                 << 109   if(d == G4Gamma::Gamma())
                                                   >> 110   {
115     ++fN_gamma;                                   111     ++fN_gamma;
116   }                                               112   }
117   else if (d == G4Electron::Electron()) {      << 113   else if(d == G4Electron::Electron())
                                                   >> 114   {
118     ++fN_elec;                                    115     ++fN_elec;
119   }                                               116   }
120   else if (d == G4Positron::Positron()) {      << 117   else if(d == G4Positron::Positron())
                                                   >> 118   {
121     ++fN_pos;                                     119     ++fN_pos;
122   }                                               120   }
123 }                                                 121 }
124                                                   122 
125 //....oooOO0OOooo........oooOO0OOooo........oo    123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126                                                   124 
127 void Run::Merge(const G4Run* run)                 125 void Run::Merge(const G4Run* run)
128 {                                                 126 {
129   const Run* localRun = static_cast<const Run*    127   const Run* localRun = static_cast<const Run*>(run);
130                                                   128 
131   // pass information about primary particle      129   // pass information about primary particle
132   fParticle = localRun->fParticle;                130   fParticle = localRun->fParticle;
133   fEkin = localRun->fEkin;                     << 131   fEkin     = localRun->fEkin;
134                                                   132 
135   // accumulate sums                              133   // accumulate sums
136   //                                              134   //
137   for (G4int k = 0; k < kMaxAbsor; k++) {      << 135   for(G4int k = 0; k < kMaxAbsor; k++)
                                                   >> 136   {
138     fSumEAbs[k] += localRun->fSumEAbs[k];         137     fSumEAbs[k] += localRun->fSumEAbs[k];
139     fSum2EAbs[k] += localRun->fSum2EAbs[k];       138     fSum2EAbs[k] += localRun->fSum2EAbs[k];
140     fSumLAbs[k] += localRun->fSumLAbs[k];         139     fSumLAbs[k] += localRun->fSumLAbs[k];
141     fSum2LAbs[k] += localRun->fSum2LAbs[k];       140     fSum2LAbs[k] += localRun->fSum2LAbs[k];
142   }                                               141   }
143                                                   142 
144   fChargedStep += localRun->fChargedStep;         143   fChargedStep += localRun->fChargedStep;
145   fNeutralStep += localRun->fNeutralStep;         144   fNeutralStep += localRun->fNeutralStep;
146                                                   145 
147   fN_gamma += localRun->fN_gamma;                 146   fN_gamma += localRun->fN_gamma;
148   fN_elec += localRun->fN_elec;                   147   fN_elec += localRun->fN_elec;
149   fN_pos += localRun->fN_pos;                     148   fN_pos += localRun->fN_pos;
150                                                   149 
151   G4Run::Merge(run);                              150   G4Run::Merge(run);
152 }                                                 151 }
153                                                   152 
154 //....oooOO0OOooo........oooOO0OOooo........oo    153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155                                                   154 
156 void Run::EndOfRun()                              155 void Run::EndOfRun()
157 {                                                 156 {
158   G4int nEvt = numberOfEvent;                  << 157   G4int nEvt    = numberOfEvent;
159   G4double norm = G4double(nEvt);                 158   G4double norm = G4double(nEvt);
160   if (norm > 0) norm = 1. / norm;              << 159   if(norm > 0)
                                                   >> 160     norm = 1. / norm;
161   G4double qnorm = std::sqrt(norm);               161   G4double qnorm = std::sqrt(norm);
162                                                   162 
163   fChargedStep *= norm;                           163   fChargedStep *= norm;
164   fNeutralStep *= norm;                           164   fNeutralStep *= norm;
165                                                   165 
166   // compute and print statistic                  166   // compute and print statistic
167   //                                              167   //
168   G4double beamEnergy = fEkin;                    168   G4double beamEnergy = fEkin;
169   G4double sqbeam = std::sqrt(beamEnergy / GeV << 169   G4double sqbeam     = std::sqrt(beamEnergy / GeV);
170                                                   170 
171   G4double MeanEAbs, MeanEAbs2, rmsEAbs, resol    171   G4double MeanEAbs, MeanEAbs2, rmsEAbs, resolution, rmsres;
172   G4double MeanLAbs, MeanLAbs2, rmsLAbs;          172   G4double MeanLAbs, MeanLAbs2, rmsLAbs;
173                                                   173 
174   std::ios::fmtflags mode = G4cout.flags();       174   std::ios::fmtflags mode = G4cout.flags();
175   G4int prec = G4cout.precision(2);            << 175   G4int prec              = G4cout.precision(2);
176   G4cout << "\n-------------------------------    176   G4cout << "\n------------------------------------------------------------\n";
177   G4cout << std::setw(14) << "material" << std << 177   G4cout << std::setw(14) << "material" << std::setw(17) << "Edep       RMS"
178          << "sqrt(E0(GeV))*rmsE/Emean" << std: << 178          << std::setw(33) << "sqrt(E0(GeV))*rmsE/Emean" << std::setw(23)
179                                                << 179          << "total tracklen \n \n";
180   for (G4int k = 1; k <= fDetector->GetNbOfAbs << 180 
181     MeanEAbs = fSumEAbs[k] * norm;             << 181   for(G4int k = 1; k <= fDetector->GetNbOfAbsor(); k++)
                                                   >> 182   {
                                                   >> 183     MeanEAbs  = fSumEAbs[k] * norm;
182     MeanEAbs2 = fSum2EAbs[k] * norm;              184     MeanEAbs2 = fSum2EAbs[k] * norm;
183     rmsEAbs = std::sqrt(std::abs(MeanEAbs2 - M << 185     rmsEAbs   = std::sqrt(std::abs(MeanEAbs2 - MeanEAbs * MeanEAbs));
184                                                   186 
185     resolution = 100. * sqbeam * rmsEAbs / Mea    187     resolution = 100. * sqbeam * rmsEAbs / MeanEAbs;
186     rmsres = resolution * qnorm;               << 188     rmsres     = resolution * qnorm;
187                                                   189 
188     // Save mean and RMS                          190     // Save mean and RMS
189     fSumEAbs[k] = MeanEAbs;                    << 191     fSumEAbs[k]  = MeanEAbs;
190     fSum2EAbs[k] = rmsEAbs;                       192     fSum2EAbs[k] = rmsEAbs;
191                                                   193 
192     MeanLAbs = fSumLAbs[k] * norm;             << 194     MeanLAbs  = fSumLAbs[k] * norm;
193     MeanLAbs2 = fSum2LAbs[k] * norm;              195     MeanLAbs2 = fSum2LAbs[k] * norm;
194     rmsLAbs = std::sqrt(std::abs(MeanLAbs2 - M << 196     rmsLAbs   = std::sqrt(std::abs(MeanLAbs2 - MeanLAbs * MeanLAbs));
195                                                   197 
196     // print                                      198     // print
197     //                                            199     //
198     G4cout << std::setw(14) << fDetector->GetA    200     G4cout << std::setw(14) << fDetector->GetAbsorMaterial(k)->GetName() << ": "
199            << std::setprecision(5) << std::set << 201            << std::setprecision(5) << std::setw(6)
200            << std::setprecision(4) << std::set << 202            << G4BestUnit(MeanEAbs, "Energy") << " :  " << std::setprecision(4)
201            << resolution << " +- " << std::set << 203            << std::setw(5) << G4BestUnit(rmsEAbs, "Energy") << std::setw(10)
202            << std::setw(10) << G4BestUnit(Mean << 204            << resolution << " +- " << std::setw(5) << rmsres << " %"
                                                   >> 205            << std::setprecision(3) << std::setw(10)
                                                   >> 206            << G4BestUnit(MeanLAbs, "Length") << " +- " << std::setw(4)
203            << G4BestUnit(rmsLAbs, "Length") <<    207            << G4BestUnit(rmsLAbs, "Length") << G4endl;
204   }                                               208   }
205   G4cout << "\n-------------------------------    209   G4cout << "\n------------------------------------------------------------\n";
206                                                   210 
207   G4cout << " Beam particle " << fParticle->Ge    211   G4cout << " Beam particle " << fParticle->GetParticleName()
208          << "  E = " << G4BestUnit(beamEnergy,    212          << "  E = " << G4BestUnit(beamEnergy, "Energy") << G4endl;
209   G4cout << " Mean number of gamma       " <<  << 213   G4cout << " Mean number of gamma       " << (G4double) fN_gamma * norm
210   G4cout << " Mean number of e-          " <<  << 214          << G4endl;
211   G4cout << " Mean number of e+          " <<  << 215   G4cout << " Mean number of e-          " << (G4double) fN_elec * norm
212   G4cout << std::setprecision(6) << " Mean num << 216          << G4endl;
                                                   >> 217   G4cout << " Mean number of e+          " << (G4double) fN_pos * norm
                                                   >> 218          << G4endl;
                                                   >> 219   G4cout << std::setprecision(6) << " Mean number of charged steps  "
                                                   >> 220          << fChargedStep << G4endl;
213   G4cout << " Mean number of neutral steps  "     221   G4cout << " Mean number of neutral steps  " << fNeutralStep << G4endl;
214   G4cout << "--------------------------------- << 222   G4cout << "------------------------------------------------------------\n"
                                                   >> 223          << G4endl;
215                                                   224 
216   G4cout.setf(mode, std::ios::floatfield);        225   G4cout.setf(mode, std::ios::floatfield);
217   G4cout.precision(prec);                         226   G4cout.precision(prec);
218 }                                                 227 }
219                                                   228 
220 //....oooOO0OOooo........oooOO0OOooo........oo    229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
221                                                   230