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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.1)


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