File indexing completed on 2025-02-23 09:21:12
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 #include "Run.hh"
0031
0032 #include "TestParameters.hh"
0033
0034 #include "G4ElectronIonPair.hh"
0035 #include "G4LossTableManager.hh"
0036 #include "G4PhysicalConstants.hh"
0037 #include "G4Run.hh"
0038 #include "G4Step.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "Randomize.hh"
0041
0042
0043
0044 Run::Run() : G4Run(), fParam(TestParameters::GetPointer())
0045 {
0046 fTotStepGas = fOverflow = fTotEdep = fStepGas = fMaxEnergy = 0.0;
0047 fEvt = fNbins = 0;
0048 }
0049
0050
0051
0052 Run::~Run() {}
0053
0054
0055
0056 void Run::BeginOfRun()
0057 {
0058
0059 fTotStepGas = fOverflow = fTotEdep = fStepGas = fMaxEnergy = 0.0;
0060 fEvt = 0;
0061
0062 SetVerbose(1);
0063
0064 fNbins = fParam->GetNumberBins();
0065 fMaxEnergy = fParam->GetMaxEnergy();
0066
0067 fEgas.resize(fNbins, 0.0);
0068 fEdep.reset();
0069
0070 if (fVerbose > 0) {
0071 G4cout << " BinsE= " << fNbins << " Emax(keV)= " << fMaxEnergy / keV << G4endl;
0072 }
0073 }
0074
0075
0076
0077 void Run::EndOfRun()
0078 {
0079 G4int nEvt = GetNumberOfEvent();
0080
0081 G4double norm = (nEvt > 0) ? 1.0 / (G4double)nEvt : 0.0;
0082
0083 fTotStepGas *= norm;
0084 fOverflow *= norm;
0085
0086 G4double y1 = fEdep.mean();
0087 G4double y2 = fEdep.rms();
0088
0089
0090
0091
0092 G4cout << " ====================================================" << G4endl;
0093 G4cout << " Beam Particle: " << fParam->GetBeamParticle()->GetParticleName() << G4endl
0094 << " Ekin(GeV) = " << fParam->GetBeamEnergy() / GeV << G4endl
0095 << " Z(mm) = " << fParam->GetPositionZ() / mm << G4endl;
0096 G4cout << " ================== run summary =====================" << G4endl;
0097 G4int prec = G4cout.precision(5);
0098 G4cout << " End of Run TotNbofEvents = " << nEvt << G4endl;
0099
0100 G4cout << G4endl;
0101 G4cout << " Mean energy deposit in absorber = " << y1 / GeV << " +- "
0102 << y2 * std::sqrt(norm) / GeV << " GeV; ";
0103 if (y1 > 0.0) {
0104 G4cout << " RMS/Emean = " << y2 / y1;
0105 }
0106 G4cout << G4endl;
0107 G4cout << " Mean number of steps in absorber= " << fTotStepGas << G4endl;
0108 G4cout << G4endl;
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 G4cout.precision(prec);
0125
0126 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0127
0128
0129
0130 analysisManager->ScaleH1(1, norm);
0131
0132 G4cout << " ================== run end ==========================" << G4endl;
0133 }
0134
0135
0136
0137 void Run::BeginOfEvent()
0138 {
0139 fTotEdep = 0.0;
0140 fStepGas = 0;
0141 ++fEvt;
0142 }
0143
0144
0145
0146 void Run::EndOfEvent()
0147 {
0148
0149
0150
0151
0152
0153 fTotStepGas += fStepGas;
0154
0155 G4int idx = G4lrint(fTotEdep * fNbins / fMaxEnergy);
0156
0157 if (idx < 0) {
0158 fEgas[0] += 1.0;
0159 }
0160 if (idx >= fNbins) {
0161 fOverflow += 1.0;
0162 }
0163 else {
0164 fEgas[idx] += 1.0;
0165 }
0166
0167 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0168
0169
0170
0171 analysisManager->FillH1(1, fTotEdep / GeV, 1.0);
0172 fEdep.fill(fTotEdep, 1.0);
0173 }
0174
0175
0176
0177
0178
0179 void Run::Merge(const G4Run* run)
0180 {
0181 const Run* localRun = static_cast<const Run*>(run);
0182
0183 fTotStepGas += localRun->fTotStepGas;
0184 fOverflow += localRun->fOverflow;
0185
0186 G4StatDouble* stat = const_cast<G4StatDouble*>(localRun->GetStat());
0187
0188 fEdep.add(stat);
0189
0190 for (G4int j = 0; j < fNbins; ++j) {
0191 fEgas[j] += localRun->fEgas[j];
0192 }
0193
0194 G4Run::Merge(run);
0195 }
0196
0197
0198
0199
0200
0201 void Run::AddEnergy(G4double edep, const G4Step* step)
0202 {
0203 if (1 < fVerbose) {
0204 G4cout << "Run::AddEnergy: e(keV)= " << edep / keV << G4endl;
0205 }
0206 fTotEdep += edep;
0207
0208 if (step) {
0209 if (1 == step->GetTrack()->GetTrackID()) {
0210 fStepGas += 1.0;
0211 }
0212 }
0213 }
0214
0215