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