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