File indexing completed on 2026-09-19 08:38:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "Run.hh"
0030
0031 #include "DetectorConstruction.hh"
0032 #include "PrimaryGeneratorAction.hh"
0033
0034 #include "G4Electron.hh"
0035 #include "G4Gamma.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleTable.hh"
0038 #include "G4Positron.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4Track.hh"
0041 #include "G4UnitsTable.hh"
0042
0043 #include <iomanip>
0044
0045
0046
0047 Run::Run(DetectorConstruction* det)
0048 : G4Run(),
0049 fDetector(det),
0050 fParticle(nullptr),
0051 fEkin(0.),
0052 fChargedStep(0),
0053 fNeutralStep(0),
0054 fN_gamma(0),
0055 fN_elec(0),
0056 fN_pos(0)
0057 {
0058
0059
0060 for (G4int k = 0; k < kMaxAbsor; k++) {
0061 fSumEAbs[k] = fSum2EAbs[k] = fSumLAbs[k] = fSum2LAbs[k] = 0.;
0062 fEnergyDeposit[k].clear();
0063 }
0064 }
0065
0066
0067
0068 Run::~Run() {}
0069
0070
0071
0072 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0073 {
0074 fParticle = particle;
0075 fEkin = energy;
0076 }
0077
0078
0079
0080 void Run::FillPerEvent(G4int kAbs, G4double EAbs, G4double LAbs)
0081 {
0082
0083
0084 fEnergyDeposit[kAbs].push_back(EAbs);
0085 fSumEAbs[kAbs] += EAbs;
0086 fSum2EAbs[kAbs] += EAbs * EAbs;
0087 fSumLAbs[kAbs] += LAbs;
0088 fSum2LAbs[kAbs] += LAbs * LAbs;
0089 }
0090
0091
0092
0093 void Run::AddChargedStep()
0094 {
0095 fChargedStep += 1.0;
0096 }
0097
0098
0099
0100 void Run::AddNeutralStep()
0101 {
0102 fNeutralStep += 1.0;
0103 }
0104
0105
0106
0107 void Run::AddSecondaryTrack(const G4Track* track)
0108 {
0109 const G4ParticleDefinition* d = track->GetDefinition();
0110 if (d == G4Gamma::Gamma()) {
0111 ++fN_gamma;
0112 }
0113 else if (d == G4Electron::Electron()) {
0114 ++fN_elec;
0115 }
0116 else if (d == G4Positron::Positron()) {
0117 ++fN_pos;
0118 }
0119 }
0120
0121
0122
0123 void Run::Merge(const G4Run* run)
0124 {
0125 const Run* localRun = static_cast<const Run*>(run);
0126
0127
0128 fParticle = localRun->fParticle;
0129 fEkin = localRun->fEkin;
0130
0131
0132
0133 for (G4int k = 0; k < kMaxAbsor; k++) {
0134 fSumEAbs[k] += localRun->fSumEAbs[k];
0135 fSum2EAbs[k] += localRun->fSum2EAbs[k];
0136 fSumLAbs[k] += localRun->fSumLAbs[k];
0137 fSum2LAbs[k] += localRun->fSum2LAbs[k];
0138 }
0139
0140 fChargedStep += localRun->fChargedStep;
0141 fNeutralStep += localRun->fNeutralStep;
0142
0143 fN_gamma += localRun->fN_gamma;
0144 fN_elec += localRun->fN_elec;
0145 fN_pos += localRun->fN_pos;
0146
0147 G4Run::Merge(run);
0148 }
0149
0150
0151
0152 void Run::EndOfRun()
0153 {
0154 G4int nEvt = numberOfEvent;
0155 G4double norm = G4double(nEvt);
0156 if (norm > 0) norm = 1. / norm;
0157 G4double qnorm = std::sqrt(norm);
0158
0159 fChargedStep *= norm;
0160 fNeutralStep *= norm;
0161
0162
0163
0164 G4double beamEnergy = fEkin;
0165 G4double sqbeam = std::sqrt(beamEnergy / GeV);
0166
0167 G4double MeanEAbs, MeanEAbs2, rmsEAbs, resolution, rmsres;
0168 G4double MeanLAbs, MeanLAbs2, rmsLAbs;
0169
0170 std::ios::fmtflags mode = G4cout.flags();
0171 G4int prec = G4cout.precision(2);
0172 G4cout << "\n------------------------------------------------------------\n";
0173 G4cout << std::setw(14) << "material" << std::setw(17) << "Edep RMS" << std::setw(33)
0174 << "sqrt(E0(GeV))*rmsE/Emean" << std::setw(23) << "total tracklen \n \n";
0175
0176 for (G4int k = 1; k <= fDetector->GetNbOfAbsor(); k++) {
0177 MeanEAbs = fSumEAbs[k] * norm;
0178 MeanEAbs2 = fSum2EAbs[k] * norm;
0179 rmsEAbs = std::sqrt(std::abs(MeanEAbs2 - MeanEAbs * MeanEAbs));
0180
0181 resolution = 100. * sqbeam * rmsEAbs / MeanEAbs;
0182 rmsres = resolution * qnorm;
0183
0184
0185 fSumEAbs[k] = MeanEAbs;
0186 fSum2EAbs[k] = rmsEAbs;
0187
0188 MeanLAbs = fSumLAbs[k] * norm;
0189 MeanLAbs2 = fSum2LAbs[k] * norm;
0190 rmsLAbs = std::sqrt(std::abs(MeanLAbs2 - MeanLAbs * MeanLAbs));
0191
0192
0193
0194 G4cout << std::setw(14) << fDetector->GetAbsorMaterial(k)->GetName() << ": "
0195 << std::setprecision(5) << std::setw(6) << G4BestUnit(MeanEAbs, "Energy") << " : "
0196 << std::setprecision(4) << std::setw(5) << G4BestUnit(rmsEAbs, "Energy") << std::setw(10)
0197 << resolution << " +- " << std::setw(5) << rmsres << " %" << std::setprecision(3)
0198 << std::setw(10) << G4BestUnit(MeanLAbs, "Length") << " +- " << std::setw(4)
0199 << G4BestUnit(rmsLAbs, "Length") << G4endl;
0200 }
0201 G4cout << "\n------------------------------------------------------------\n";
0202
0203 G4cout << " Beam particle " << fParticle->GetParticleName()
0204 << " E = " << G4BestUnit(beamEnergy, "Energy") << G4endl;
0205 G4cout << " Mean number of gamma " << (G4double)fN_gamma * norm << G4endl;
0206 G4cout << " Mean number of e- " << (G4double)fN_elec * norm << G4endl;
0207 G4cout << " Mean number of e+ " << (G4double)fN_pos * norm << G4endl;
0208 G4cout << std::setprecision(6) << " Mean number of charged steps " << fChargedStep << G4endl;
0209 G4cout << " Mean number of neutral steps " << fNeutralStep << G4endl;
0210 G4cout << "------------------------------------------------------------\n" << G4endl;
0211
0212 G4cout.setf(mode, std::ios::floatfield);
0213 G4cout.precision(prec);
0214 }
0215
0216