File indexing completed on 2025-02-23 09:20:52
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 "G4Material.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4UnitsTable.hh"
0042
0043
0044
0045 Run::Run(DetectorConstruction* detector) : fDetector(detector) {}
0046
0047
0048
0049 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0050 {
0051 fParticle = particle;
0052 fEkin = energy;
0053 }
0054
0055
0056
0057 void Run::AddEdep(G4double e)
0058 {
0059 fEdeposit += e;
0060 fEdeposit2 += e * e;
0061 }
0062
0063
0064
0065 void Run::AddTrackLength(G4double t)
0066 {
0067 fTrackLen += t;
0068 fTrackLen2 += t * t;
0069 }
0070
0071
0072
0073 void Run::AddProjRange(G4double x)
0074 {
0075 fProjRange += x;
0076 fProjRange2 += x * x;
0077 }
0078
0079
0080
0081 void Run::AddStepSize(G4int nb, G4double st)
0082 {
0083 fNbOfSteps += nb;
0084 fNbOfSteps2 += nb * nb;
0085 fStepSize += st;
0086 fStepSize2 += st * st;
0087 }
0088
0089
0090
0091 void Run::SetCsdaRange(G4double value)
0092 {
0093 fCsdaRange = value;
0094 }
0095
0096
0097
0098 G4double Run::GetCsdaRange()
0099 {
0100 return fCsdaRange;
0101 }
0102
0103
0104
0105 void Run::Merge(const G4Run* run)
0106 {
0107 const Run* localRun = static_cast<const Run*>(run);
0108
0109
0110 fParticle = localRun->fParticle;
0111 fEkin = localRun->fEkin;
0112
0113
0114 fEdeposit += localRun->fEdeposit;
0115 fEdeposit2 += localRun->fEdeposit2;
0116 fTrackLen += localRun->fTrackLen;
0117 fTrackLen2 += localRun->fTrackLen2;
0118 fProjRange += localRun->fProjRange;
0119 fProjRange2 += localRun->fProjRange2;
0120 fNbOfSteps += localRun->fNbOfSteps;
0121 fNbOfSteps2 += localRun->fNbOfSteps2;
0122 fStepSize += localRun->fStepSize;
0123 fStepSize2 += localRun->fStepSize2;
0124
0125 fCsdaRange = localRun->fCsdaRange;
0126
0127 G4Run::Merge(run);
0128 }
0129
0130
0131
0132 void Run::EndOfRun()
0133 {
0134 std::ios::fmtflags mode = G4cout.flags();
0135 G4cout.setf(std::ios::fixed, std::ios::floatfield);
0136 G4int prec = G4cout.precision(2);
0137
0138
0139
0140 G4Material* material = fDetector->GetAbsorMaterial();
0141 G4double density = material->GetDensity();
0142 G4String partName = fParticle->GetParticleName();
0143
0144 G4cout << "\n ======================== run summary =====================\n";
0145 G4cout << "\n The run is " << numberOfEvent << " " << partName << " of "
0146 << G4BestUnit(fEkin, "Energy") << " through "
0147 << G4BestUnit(fDetector->GetAbsorRadius(), "Length") << " of " << material->GetName()
0148 << " (density: " << G4BestUnit(density, "Volumic Mass") << ")" << G4endl;
0149
0150 if (numberOfEvent == 0) {
0151 G4cout.setf(mode, std::ios::floatfield);
0152 G4cout.precision(prec);
0153 return;
0154 }
0155
0156 fEdeposit /= numberOfEvent;
0157 fEdeposit2 /= numberOfEvent;
0158 G4double rms = fEdeposit2 - fEdeposit * fEdeposit;
0159 if (rms > 0.)
0160 rms = std::sqrt(rms);
0161 else
0162 rms = 0.;
0163
0164 G4cout.precision(3);
0165 G4cout << "\n Total Energy deposited = " << G4BestUnit(fEdeposit, "Energy") << " +- "
0166 << G4BestUnit(rms, "Energy") << G4endl;
0167
0168
0169
0170 fTrackLen /= numberOfEvent;
0171 fTrackLen2 /= numberOfEvent;
0172 rms = fTrackLen2 - fTrackLen * fTrackLen;
0173 if (rms > 0.)
0174 rms = std::sqrt(rms);
0175 else
0176 rms = 0.;
0177
0178 G4cout.precision(3);
0179 G4cout << "\n Track length of primary track = " << G4BestUnit(fTrackLen, "Length") << " +- "
0180 << G4BestUnit(rms, "Length");
0181
0182
0183
0184 G4cout << "\n Range from EmCalculator = " << G4BestUnit(fCsdaRange, "Length")
0185 << " (from full dE/dx)" << G4endl;
0186
0187
0188
0189 fProjRange /= numberOfEvent;
0190 fProjRange2 /= numberOfEvent;
0191 rms = fProjRange2 - fProjRange * fProjRange;
0192 if (rms > 0.)
0193 rms = std::sqrt(rms);
0194 else
0195 rms = 0.;
0196
0197 G4cout << "\n Projected range = " << G4BestUnit(fProjRange, "Length") << " +- "
0198 << G4BestUnit(rms, "Length") << G4endl;
0199
0200
0201
0202 G4double dNofEvents = double(numberOfEvent);
0203 G4double fNbSteps = fNbOfSteps / dNofEvents, fNbSteps2 = fNbOfSteps2 / dNofEvents;
0204 rms = fNbSteps2 - fNbSteps * fNbSteps;
0205 if (rms > 0.)
0206 rms = std::sqrt(rms);
0207 else
0208 rms = 0.;
0209
0210 G4cout.precision(2);
0211 G4cout << "\n Nb of steps of primary track = " << fNbSteps << " +- " << rms;
0212
0213 fStepSize /= numberOfEvent;
0214 fStepSize2 /= numberOfEvent;
0215 rms = fStepSize2 - fStepSize * fStepSize;
0216 if (rms > 0.)
0217 rms = std::sqrt(rms);
0218 else
0219 rms = 0.;
0220
0221 G4cout.precision(3);
0222 G4cout << "\t Step size= " << G4BestUnit(fStepSize, "Length") << " +- "
0223 << G4BestUnit(rms, "Length") << G4endl;
0224
0225
0226
0227 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0228 G4int ih = 1;
0229 G4double binWidth = analysisManager->GetH1Width(ih) * analysisManager->GetH1Unit(ih);
0230 G4double fac = (1. / (numberOfEvent * binWidth)) * (mm / MeV);
0231 analysisManager->ScaleH1(ih, fac);
0232
0233
0234
0235 ih = 8;
0236 binWidth = analysisManager->GetH1Width(ih);
0237 fac = 1. / (numberOfEvent * binWidth * fEkin);
0238 analysisManager->ScaleH1(ih, fac);
0239
0240
0241 G4cout.setf(mode, std::ios::floatfield);
0242 G4cout.precision(prec);
0243 }
0244
0245