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