File indexing completed on 2026-09-20 08:30:22
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 #include "Run.hh"
0030
0031 #include "G4Run.hh"
0032 #include "G4RunManager.hh"
0033 #include "G4SystemOfUnits.hh"
0034
0035
0036
0037 Run::Run()
0038 : G4Run(),
0039 fNumEvents(0),
0040 fPrimaryParticleId(0),
0041 fPrimaryParticleEnergy(0.0),
0042 fPrimaryParticleDirection(G4ThreeVector(0.0, 0.0, 0.0)),
0043 fAbsorberMaterialName(""),
0044 fActiveMaterialName(""),
0045 fCubicVolumeScoringUpDown(1.0),
0046 fCubicVolumeScoringSide(1.0)
0047 {
0048 fSteppingArray.fill(0.0);
0049 fTrackingArray1.fill(0);
0050 fTrackingArray2.fill(0.0);
0051 }
0052
0053
0054
0055 void Run::RecordEvent(const G4Event* anEvent)
0056 {
0057
0058
0059 G4int nEvt = anEvent->GetEventID();
0060 if (nEvt % 10 == 0) G4cout << " Event#=" << nEvt << G4endl;
0061 G4Run::RecordEvent(anEvent);
0062 }
0063
0064
0065
0066 void Run::Merge(const G4Run* aRun)
0067 {
0068
0069
0070 const Run* localRun = static_cast<const Run*>(aRun);
0071 fPrimaryParticleId = localRun->GetPrimaryParticleId();
0072 fPrimaryParticleEnergy = localRun->GetPrimaryParticleEnergy();
0073 fPrimaryParticleDirection = localRun->GetPrimaryParticleDirection();
0074 fAbsorberMaterialName = localRun->GetAbsorberMaterialName();
0075 fActiveMaterialName = localRun->GetActiveMaterialName();
0076 fCubicVolumeScoringUpDown = localRun->GetCubicVolumeScoringUpDown();
0077 fCubicVolumeScoringSide = localRun->GetCubicVolumeScoringSide();
0078 fNumEvents += localRun->GetNumberOfEvent();
0079 for (G4int i = 0; i < SteppingAction::fkNumberCombinations; ++i) {
0080 fSteppingArray[i] += localRun->GetSteppingArray()[i];
0081 }
0082 for (G4int i = 0; i < TrackingAction::fkNumberCombinations; ++i) {
0083 fTrackingArray1[i] += localRun->GetTrackingArray1()[i];
0084 fTrackingArray2[i] += localRun->GetTrackingArray2()[i];
0085 }
0086 G4Run::Merge(aRun);
0087 }
0088
0089
0090
0091 void Run::PrintInfo() const
0092 {
0093
0094
0095 const G4double floatingNumberOfEvents =
0096 std::max(1.0, fNumEvents > 0 ? fNumEvents * 1.0 : GetNumberOfEvent() * 1.0);
0097
0098
0099 const G4double conversionFactor = CLHEP::cm * CLHEP::cm;
0100 const G4double factorUpDown =
0101 conversionFactor / (fCubicVolumeScoringUpDown * floatingNumberOfEvents);
0102 const G4double factorSide = conversionFactor / (fCubicVolumeScoringSide * floatingNumberOfEvents);
0103 G4cout << std::setprecision(6) << G4endl << G4endl
0104 << " =============== Run::PrintInfo() =============== \t RunID = " << GetRunID()
0105 << G4endl << " Primary particle PDG code = " << fPrimaryParticleId << G4endl
0106 << " Primary particle kinetic energy = " << fPrimaryParticleEnergy / CLHEP::GeV << " GeV"
0107 << G4endl << " Primary particle direction = " << fPrimaryParticleDirection << G4endl
0108 << " Absorber material = " << fAbsorberMaterialName << G4endl
0109 << " Active material = " << fActiveMaterialName << G4endl
0110 << " Cubic-volume scoring up-down = " << fCubicVolumeScoringUpDown << " mm^3" << G4endl
0111 << " Cubic-volume scoring side = " << fCubicVolumeScoringSide << " mm^3" << G4endl
0112 << " Number of events = " << floatingNumberOfEvents << G4endl
0113 << " Conversion factor: fluence from mm^-2 to cm^-2 = " << conversionFactor << G4endl
0114 << " Particle fluence in unit of cm^-2 :" << G4endl;
0115 for (G4int i = 0; i < SteppingAction::fkNumberScoringVolumes; ++i) {
0116 G4double factor = (i == 1 ? factorSide : factorUpDown);
0117 for (G4int j = 0; j < SteppingAction::fkNumberKinematicRegions; ++j) {
0118 for (G4int k = 0; k < SteppingAction::fkNumberParticleTypes; ++k) {
0119 G4int index = SteppingAction::GetIndex(i, j, k);
0120
0121 G4cout << " case=" << std::setw(3) << index << " " << std::setw(12)
0122 << SteppingAction::fkArrayScoringVolumeNames[i] << " " << std::setw(12)
0123 << SteppingAction::fkArrayKinematicRegionNames[j] << " " << std::setw(12)
0124 << SteppingAction::fkArrayParticleTypeNames[k] << " " << std::setw(8)
0125 << factor * fSteppingArray[index] << G4endl;
0126 }
0127 }
0128 }
0129 G4cout << " ------------------------------------------------------------- " << G4endl
0130 << " Extra information: particle production \t \t <N> <E_kin> <Sum_Ekin> [MeV]"
0131 << G4endl;
0132 const G4double normalization = 1.0 / floatingNumberOfEvents;
0133 for (G4int i = 0; i < TrackingAction::fkNumberScoringVolumes; ++i) {
0134 for (G4int j = 0; j < TrackingAction::fkNumberKinematicRegions; ++j) {
0135 for (G4int k = 0; k < TrackingAction::fkNumberParticleTypes; ++k) {
0136 G4int index = TrackingAction::GetIndex(i, j, k);
0137
0138 G4cout << " case=" << std::setw(3) << index << " " << std::setw(12)
0139 << TrackingAction::fkArrayScoringVolumeNames[i] << " " << std::setw(12)
0140 << TrackingAction::fkArrayKinematicRegionNames[j] << " " << std::setw(12)
0141 << TrackingAction::fkArrayParticleTypeNames[k] << " " << std::setw(8)
0142 << normalization * fTrackingArray1[index] << " " << std::setw(8)
0143 << (fTrackingArray1[index] > 0 ? fTrackingArray2[index] / fTrackingArray1[index]
0144 : 0.0)
0145 << " " << std::setw(8) << normalization * fTrackingArray2[index] << G4endl;
0146 }
0147 }
0148 }
0149 G4cout << " ============================================================= " << G4endl << G4endl;
0150 }
0151
0152
0153
0154 void Run::SetSteppingArray(
0155 const std::array<G4double, SteppingAction::fkNumberCombinations>& inputArray)
0156 {
0157 for (G4int i = 0; i < SteppingAction::fkNumberCombinations; ++i) {
0158 fSteppingArray[i] = inputArray[i];
0159 }
0160 }
0161
0162
0163
0164 void Run::SetTrackingArray1(
0165 const std::array<G4long, TrackingAction::fkNumberCombinations>& inputArray)
0166 {
0167 for (G4int i = 0; i < TrackingAction::fkNumberCombinations; ++i) {
0168 fTrackingArray1[i] = inputArray[i];
0169 }
0170 }
0171
0172
0173
0174 void Run::SetTrackingArray2(
0175 const std::array<G4double, TrackingAction::fkNumberCombinations>& inputArray)
0176 {
0177 for (G4int i = 0; i < TrackingAction::fkNumberCombinations; ++i) {
0178 fTrackingArray2[i] = inputArray[i];
0179 }
0180 }
0181
0182