File indexing completed on 2026-09-16 08:29:12
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 "G4EmCalculator.hh"
0035 #include "G4Gamma.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4UnitsTable.hh"
0038
0039 #include <iomanip>
0040
0041
0042
0043 Run::Run(DetectorConstruction* det) : fDetector(det) {}
0044
0045
0046
0047 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0048 {
0049 fParticle = particle;
0050 fEkin = energy;
0051 }
0052
0053
0054 void Run::CountProcesses(G4String procName)
0055 {
0056 std::map<G4String, G4int>::iterator it = fProcCounter.find(procName);
0057 if (it == fProcCounter.end()) {
0058 fProcCounter[procName] = 1;
0059 }
0060 else {
0061 fProcCounter[procName]++;
0062 }
0063 }
0064
0065
0066
0067 void Run::SumTrack(G4double track)
0068 {
0069 fTotalCount++;
0070 fSumTrack += track;
0071 fSumTrack2 += track * track;
0072 }
0073
0074
0075
0076 void Run::SumeTransf(G4double energy)
0077 {
0078 fEnTransfer += energy;
0079 }
0080
0081
0082
0083 void Run::Merge(const G4Run* run)
0084 {
0085 const Run* localRun = static_cast<const Run*>(run);
0086
0087
0088 fParticle = localRun->fParticle;
0089 fEkin = localRun->fEkin;
0090
0091
0092 std::map<G4String, G4int>::const_iterator it;
0093 for (it = localRun->fProcCounter.begin(); it != localRun->fProcCounter.end(); ++it) {
0094 G4String procName = it->first;
0095 G4int localCount = it->second;
0096 if (fProcCounter.find(procName) == fProcCounter.end()) {
0097 fProcCounter[procName] = localCount;
0098 }
0099 else {
0100 fProcCounter[procName] += localCount;
0101 }
0102 }
0103
0104 fTotalCount += localRun->fTotalCount;
0105 fSumTrack += localRun->fSumTrack;
0106 fSumTrack2 += localRun->fSumTrack2;
0107 fEnTransfer += localRun->fEnTransfer;
0108
0109 G4Run::Merge(run);
0110 }
0111
0112
0113
0114 void Run::EndOfRun()
0115 {
0116 G4int prec = 5;
0117 G4int dfprec = G4cout.precision(prec);
0118
0119
0120
0121 G4String partName = fParticle->GetParticleName();
0122 G4Material* material = fDetector->GetMaterial();
0123 G4double density = material->GetDensity();
0124 G4double tickness = fDetector->GetSize();
0125
0126 G4cout << "\n ======================== run summary ======================\n";
0127 G4cout << "\n The run is: " << numberOfEvent << " " << partName << " of "
0128 << G4BestUnit(fEkin, "Energy") << " through " << G4BestUnit(tickness, "Length") << " of "
0129 << material->GetName() << " (density: " << G4BestUnit(density, "Volumic Mass") << ")"
0130 << G4endl;
0131
0132
0133 G4int survive = 0;
0134 G4cout << "\n Process calls frequency --->";
0135 std::map<G4String, G4int>::iterator it;
0136 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
0137 G4String procName = it->first;
0138 G4int count = it->second;
0139 G4cout << "\t" << procName << " = " << count;
0140 if (procName == "Transportation") survive = count;
0141 }
0142
0143 if (survive > 0) {
0144 G4cout << "\n\n Nb of incident particles surviving after "
0145 << G4BestUnit(fDetector->GetSize(), "Length") << " of " << material->GetName() << " : "
0146 << survive << G4endl;
0147 }
0148
0149 if (fTotalCount == 0) fTotalCount = 1;
0150
0151
0152
0153 G4double MeanFreePath = fSumTrack / fTotalCount;
0154 G4double MeanTrack2 = fSumTrack2 / fTotalCount;
0155 G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath * MeanFreePath));
0156 G4double CrossSection = 1. / MeanFreePath;
0157 G4double massicMFP = MeanFreePath * density;
0158 G4double massicCS = 1. / massicMFP;
0159
0160 G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath, "Length") << " +- "
0161 << G4BestUnit(rms, "Length") << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface")
0162 << "\n CrossSection:\t" << CrossSection * cm << " cm^-1 "
0163 << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass") << G4endl;
0164
0165
0166
0167 G4double MeanTransfer = fEnTransfer / fTotalCount;
0168 G4double massTransfCoef = massicCS * MeanTransfer / fEkin;
0169
0170 G4cout << "\n mean energy of charged secondaries: " << G4BestUnit(MeanTransfer, "Energy")
0171 << "\n ---> mass_energy_transfer coef: " << G4BestUnit(massTransfCoef, "Surface/Mass")
0172 << G4endl;
0173
0174
0175
0176 G4cout << "\n Verification : "
0177 << "crossSections from G4EmCalculator \n";
0178
0179 G4EmCalculator emCalculator;
0180 G4double sumc = 0.0;
0181 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
0182 G4String procName = it->first;
0183 G4double massSigma =
0184 emCalculator.GetCrossSectionPerVolume(fEkin, fParticle, procName, material) / density;
0185 if (fParticle == G4Gamma::Gamma())
0186 massSigma =
0187 emCalculator.ComputeCrossSectionPerVolume(fEkin, fParticle, procName, material) / density;
0188 sumc += massSigma;
0189 G4cout << " " << procName << "= " << G4BestUnit(massSigma, "Surface/Mass");
0190 }
0191 G4cout << " total= " << G4BestUnit(sumc, "Surface/Mass") << G4endl;
0192
0193
0194 fProcCounter.clear();
0195
0196
0197 G4cout.precision(dfprec);
0198 }
0199
0200