File indexing completed on 2025-04-04 08:05:15
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
0030
0031
0032
0033 #include "Run.hh"
0034
0035 #include "DetectorConstruction.hh"
0036 #include "HistoManager.hh"
0037 #include "PrimaryGeneratorAction.hh"
0038
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4UnitsTable.hh"
0041
0042
0043
0044 Run::Run(DetectorConstruction* det) : fDetector(det) {}
0045
0046
0047
0048 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0049 {
0050 fParticle = particle;
0051 fEkin = energy;
0052 }
0053
0054
0055
0056 void Run::CountProcesses(const G4VProcess* process)
0057 {
0058 if (process == nullptr) return;
0059 G4String procName = process->GetProcessName();
0060 std::map<G4String, G4int>::iterator it = fProcCounter.find(procName);
0061 if (it == fProcCounter.end()) {
0062 fProcCounter[procName] = 1;
0063 }
0064 else {
0065 fProcCounter[procName]++;
0066 }
0067 }
0068
0069
0070
0071 void Run::ParticleCount(G4String name, G4double Ekin)
0072 {
0073 std::map<G4String, ParticleData>::iterator it = fParticleDataMap.find(name);
0074 if (it == fParticleDataMap.end()) {
0075 fParticleDataMap[name] = ParticleData(1, Ekin, Ekin, Ekin);
0076 }
0077 else {
0078 ParticleData& data = it->second;
0079 data.fCount++;
0080 data.fEmean += Ekin;
0081
0082 G4double emin = data.fEmin;
0083 if (Ekin < emin) data.fEmin = Ekin;
0084 G4double emax = data.fEmax;
0085 if (Ekin > emax) data.fEmax = Ekin;
0086 }
0087 }
0088
0089
0090
0091 void Run::SumTrackLength(G4int nstep1, G4int nstep2, G4double trackl1, G4double trackl2,
0092 G4double time1, G4double time2)
0093 {
0094 fNbStep1 += nstep1;
0095 fNbStep2 += nstep2;
0096 fTrackLen1 += trackl1;
0097 fTrackLen2 += trackl2;
0098 fTime1 += time1;
0099 fTime2 += time2;
0100 }
0101
0102
0103
0104 void Run::Merge(const G4Run* run)
0105 {
0106 const Run* localRun = static_cast<const Run*>(run);
0107
0108
0109
0110 fParticle = localRun->fParticle;
0111 fEkin = localRun->fEkin;
0112
0113
0114
0115 fNbStep1 += localRun->fNbStep1;
0116 fNbStep2 += localRun->fNbStep2;
0117 fTrackLen1 += localRun->fTrackLen1;
0118 fTrackLen2 += localRun->fTrackLen2;
0119 fTime1 += localRun->fTime1;
0120 fTime2 += localRun->fTime2;
0121
0122
0123 std::map<G4String, G4int>::const_iterator itp;
0124 for (itp = localRun->fProcCounter.begin(); itp != localRun->fProcCounter.end(); ++itp) {
0125 G4String procName = itp->first;
0126 G4int localCount = itp->second;
0127 if (fProcCounter.find(procName) == fProcCounter.end()) {
0128 fProcCounter[procName] = localCount;
0129 }
0130 else {
0131 fProcCounter[procName] += localCount;
0132 }
0133 }
0134
0135
0136 std::map<G4String, ParticleData>::const_iterator itn;
0137 for (itn = localRun->fParticleDataMap.begin(); itn != localRun->fParticleDataMap.end(); ++itn) {
0138 G4String name = itn->first;
0139 const ParticleData& localData = itn->second;
0140 if (fParticleDataMap.find(name) == fParticleDataMap.end()) {
0141 fParticleDataMap[name] =
0142 ParticleData(localData.fCount, localData.fEmean, localData.fEmin, localData.fEmax);
0143 }
0144 else {
0145 ParticleData& data = fParticleDataMap[name];
0146 data.fCount += localData.fCount;
0147 data.fEmean += localData.fEmean;
0148 G4double emin = localData.fEmin;
0149 if (emin < data.fEmin) data.fEmin = emin;
0150 G4double emax = localData.fEmax;
0151 if (emax > data.fEmax) data.fEmax = emax;
0152 }
0153 }
0154
0155 G4Run::Merge(run);
0156 }
0157
0158
0159
0160 void Run::EndOfRun()
0161 {
0162 G4int prec = 5, wid = prec + 2;
0163 G4int dfprec = G4cout.precision(prec);
0164
0165
0166
0167 G4Material* material = fDetector->GetMaterial();
0168 G4double density = material->GetDensity();
0169
0170 G4String Particle = fParticle->GetParticleName();
0171 G4cout << "\n The run is " << numberOfEvent << " " << Particle << " of "
0172 << G4BestUnit(fEkin, "Energy") << " through "
0173 << G4BestUnit(0.5 * (fDetector->GetSize()), "Length") << " of " << material->GetName()
0174 << " (density: " << G4BestUnit(density, "Volumic Mass") << ")" << G4endl;
0175
0176 if (numberOfEvent == 0) {
0177 G4cout.precision(dfprec);
0178 return;
0179 }
0180
0181
0182
0183 G4cout << "\n Process calls frequency :" << G4endl;
0184 G4int survive = 0;
0185 std::map<G4String, G4int>::iterator it;
0186 for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
0187 G4String procName = it->first;
0188 G4int count = it->second;
0189 G4cout << "\t" << procName << "= " << count;
0190 if (procName == "Transportation") survive = count;
0191 }
0192 G4cout << G4endl;
0193
0194 if (survive > 0) {
0195 G4cout << "\n Nb of incident particles surviving after "
0196 << G4BestUnit(0.5 * (fDetector->GetSize()), "Length") << " of "
0197 << fDetector->GetMaterial()->GetName() << " : " << survive << G4endl;
0198 }
0199
0200
0201
0202 G4cout << "\n Parcours of incident neutron:";
0203
0204 G4double meanCollision1 = (G4double)fNbStep1 / numberOfEvent;
0205 G4double meanCollision2 = (G4double)fNbStep2 / numberOfEvent;
0206 G4double meanCollisTota = meanCollision1 + meanCollision2;
0207
0208 G4cout << "\n nb of collisions E>1*eV= " << meanCollision1
0209 << " E<1*eV= " << meanCollision2 << " total= " << meanCollisTota;
0210
0211 G4double meanTrackLen1 = fTrackLen1 / numberOfEvent;
0212 G4double meanTrackLen2 = fTrackLen2 / numberOfEvent;
0213 G4double meanTrackLtot = meanTrackLen1 + meanTrackLen2;
0214
0215 G4cout << "\n track length E>1*eV= " << G4BestUnit(meanTrackLen1, "Length")
0216 << " E<1*eV= " << G4BestUnit(meanTrackLen2, "Length")
0217 << " total= " << G4BestUnit(meanTrackLtot, "Length");
0218
0219 G4double meanTime1 = fTime1 / numberOfEvent;
0220 G4double meanTime2 = fTime2 / numberOfEvent;
0221 G4double meanTimeTo = meanTime1 + meanTime2;
0222
0223 G4cout << "\n time of flight E>1*eV= " << G4BestUnit(meanTime1, "Time")
0224 << " E<1*eV= " << G4BestUnit(meanTime2, "Time")
0225 << " total= " << G4BestUnit(meanTimeTo, "Time") << G4endl;
0226
0227
0228
0229 G4cout << "\n List of generated particles:" << G4endl;
0230
0231 std::map<G4String, ParticleData>::iterator itn;
0232 for (itn = fParticleDataMap.begin(); itn != fParticleDataMap.end(); itn++) {
0233 G4String name = itn->first;
0234 ParticleData data = itn->second;
0235 G4int count = data.fCount;
0236 G4double eMean = data.fEmean / count;
0237 G4double eMin = data.fEmin;
0238 G4double eMax = data.fEmax;
0239
0240 G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count
0241 << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy") << "\t( "
0242 << G4BestUnit(eMin, "Energy") << " --> " << G4BestUnit(eMax, "Energy") << ")" << G4endl;
0243 }
0244
0245
0246
0247
0248
0249
0250
0251 fProcCounter.clear();
0252 fParticleDataMap.clear();
0253
0254
0255 G4cout.precision(dfprec);
0256 }
0257
0258