File indexing completed on 2025-02-23 09:22:06
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 "PrimaryGeneratorAction.hh"
0042
0043 #include "G4Material.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4UnitsTable.hh"
0046
0047
0048
0049 Run::Run(const DetectorConstruction* detector)
0050 : G4Run(),
0051 fDetector(detector),
0052 fParticle(0),
0053 fEkin(0.),
0054 fEdeposit(0.),
0055 fEdeposit2(0.),
0056 fTrackLen(0.),
0057 fTrackLen2(0.),
0058 fProjRange(0.),
0059 fProjRange2(0.),
0060 fPenetration(0.),
0061 fPenetration2(0.),
0062 fNbOfSteps(0),
0063 fNbOfSteps2(0),
0064 fStepSize(0.),
0065 fStepSize2(0.)
0066 {}
0067
0068
0069
0070 Run::~Run() {}
0071
0072
0073
0074 void Run::SetPrimary(G4ParticleDefinition* particle, G4double energy)
0075 {
0076 fParticle = particle;
0077 fEkin = energy;
0078 }
0079
0080
0081
0082 void Run::AddEdep(G4double e)
0083 {
0084 fEdeposit += e;
0085 fEdeposit2 += e * e;
0086 }
0087
0088
0089
0090 void Run::AddTrackLength(G4double t)
0091 {
0092 fTrackLen += t;
0093 fTrackLen2 += t * t;
0094 }
0095
0096
0097
0098 void Run::AddProjRange(G4double x)
0099 {
0100 fProjRange += x;
0101 fProjRange2 += x * x;
0102 }
0103
0104
0105
0106 void Run::AddPenetration(G4double x)
0107 {
0108 fPenetration += x;
0109 fPenetration2 += x * x;
0110 }
0111
0112
0113
0114 void Run::AddStepSize(G4int nb, G4double st)
0115 {
0116 fNbOfSteps += nb;
0117 fNbOfSteps2 += nb * nb;
0118 fStepSize += st;
0119 fStepSize2 += st * st;
0120 }
0121
0122
0123
0124 void Run::Merge(const G4Run* run)
0125 {
0126 const Run* localRun = static_cast<const Run*>(run);
0127
0128
0129 fParticle = localRun->fParticle;
0130 fEkin = localRun->fEkin;
0131
0132
0133 fEdeposit += localRun->fEdeposit;
0134 fEdeposit2 += localRun->fEdeposit2;
0135 fTrackLen += localRun->fTrackLen;
0136 fTrackLen2 += localRun->fTrackLen2;
0137 fProjRange += localRun->fProjRange;
0138 fProjRange2 += localRun->fProjRange2;
0139 fPenetration += localRun->fPenetration;
0140 fPenetration2 += localRun->fPenetration2;
0141 fNbOfSteps += localRun->fNbOfSteps;
0142 fNbOfSteps2 += localRun->fNbOfSteps2;
0143 fStepSize += localRun->fStepSize;
0144 fStepSize2 += localRun->fStepSize2;
0145
0146 G4Run::Merge(run);
0147 }
0148
0149
0150
0151 void Run::EndOfRun()
0152 {
0153 std::ios::fmtflags mode = G4cout.flags();
0154 G4cout.setf(std::ios::fixed, std::ios::floatfield);
0155 G4int prec = G4cout.precision(2);
0156
0157
0158 G4Material* material = fDetector->GetAbsorMaterial();
0159 G4double density = material->GetDensity();
0160 G4String partName = fParticle->GetParticleName();
0161
0162 G4cout << "\n ======================= run summary ====================\n";
0163 G4cout << "\n The run is " << numberOfEvent << " " << partName << " of "
0164 << G4BestUnit(fEkin, "Energy") << " through a sphere of radius "
0165 << G4BestUnit(fDetector->GetAbsorRadius(), "Length") << "of " << material->GetName()
0166 << " (density: " << G4BestUnit(density, "Volumic Mass") << ")" << G4endl;
0167
0168 if (numberOfEvent == 0) {
0169 G4cout.setf(mode, std::ios::floatfield);
0170 G4cout.precision(prec);
0171 return;
0172 }
0173
0174
0175 fTrackLen /= numberOfEvent;
0176 fTrackLen2 /= numberOfEvent;
0177 G4double rmsTrack = fTrackLen2 - fTrackLen * fTrackLen;
0178
0179 if (rmsTrack > 0.)
0180 rmsTrack = std::sqrt(rmsTrack);
0181 else
0182 rmsTrack = 0.;
0183
0184 G4cout.precision(3);
0185 G4cout << "\n Track length of primary track = " << G4BestUnit(fTrackLen, "Length") << " +- "
0186 << G4BestUnit(rmsTrack, "Length");
0187
0188
0189 fProjRange /= numberOfEvent;
0190 fProjRange2 /= numberOfEvent;
0191 G4double rmsProj = fProjRange2 - fProjRange * fProjRange;
0192 if (rmsProj > 0.)
0193 rmsProj = std::sqrt(rmsProj);
0194 else
0195 rmsProj = 0.;
0196
0197 G4cout << "\n Projected range = " << G4BestUnit(fProjRange, "Length") << " +- "
0198 << G4BestUnit(rmsProj, "Length");
0199
0200
0201 fPenetration /= numberOfEvent;
0202 fPenetration2 /= numberOfEvent;
0203 G4double rmsPene = fPenetration2 - fPenetration * fPenetration;
0204 if (rmsPene > 0.)
0205 rmsPene = std::sqrt(rmsPene);
0206 else
0207 rmsPene = 0.;
0208
0209 G4cout << "\n Penetration = " << G4BestUnit(fPenetration, "Length") << " +- "
0210 << G4BestUnit(rmsPene, "Length") << G4endl;
0211
0212
0213
0214
0215 FILE* myFile;
0216 myFile = fopen("range.txt", "a");
0217 fprintf(myFile, "%e %e %e %e %e %e %e\n", fEkin / eV, fTrackLen / nm, rmsTrack / nm,
0218 fProjRange / nm, rmsProj / nm, fPenetration / nm, rmsPene / nm);
0219 fclose(myFile);
0220
0221
0222 G4cout.setf(mode, std::ios::floatfield);
0223 G4cout.precision(prec);
0224 }