File indexing completed on 2025-04-10 08:06:18
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 #include "TrackingAction.hh"
0035
0036 #include "Run.hh"
0037
0038 #include "G4IonTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040 #include "G4ParticleTypes.hh"
0041 #include "G4Step.hh"
0042 #include "G4StepPoint.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Track.hh"
0045
0046 const std::array<G4String, TrackingAction::fkNumberScoringVolumes>
0047 TrackingAction::fkArrayScoringVolumeNames = {"layer"};
0048
0049 const std::array<G4String, TrackingAction::fkNumberKinematicRegions>
0050 TrackingAction::fkArrayKinematicRegionNames = {"", "below 20 MeV", "above 20 MeV"};
0051
0052 const std::array<G4String, TrackingAction::fkNumberParticleTypes>
0053 TrackingAction::fkArrayParticleTypeNames = {"all", "electron", "gamma", "muon",
0054 "neutrino", "pion", "neutron", "proton",
0055 "ion", "otherMeson", "otherBaryon"};
0056
0057
0058
0059 G4int TrackingAction::GetIndex(const G4int iScoringVolume, const G4int iKinematicRegion,
0060 const G4int iParticleType)
0061 {
0062 G4int index = -1;
0063 if (iScoringVolume >= 0 && iScoringVolume < fkNumberScoringVolumes && iKinematicRegion >= 0
0064 && iKinematicRegion < fkNumberKinematicRegions && iParticleType >= 0
0065 && iParticleType < fkNumberParticleTypes)
0066 {
0067 index = iScoringVolume * fkNumberKinematicRegions * fkNumberParticleTypes
0068 + iKinematicRegion * fkNumberParticleTypes + iParticleType;
0069 }
0070 return index;
0071 }
0072
0073
0074
0075 TrackingAction::TrackingAction() : G4UserTrackingAction()
0076 {
0077 Initialize();
0078 }
0079
0080
0081
0082 void TrackingAction::Initialize()
0083 {
0084
0085 fArrayMultiplicities.fill(0);
0086 fArraySumKineticEnergies.fill(0.0);
0087 }
0088
0089
0090
0091 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack)
0092 {
0093
0094
0095
0096
0097
0098 if (aTrack == nullptr || aTrack->GetCurrentStepNumber() != 0 || aTrack->GetDefinition() == nullptr
0099 || aTrack->GetLogicalVolumeAtVertex() == nullptr
0100 || aTrack->GetLogicalVolumeAtVertex()->GetName() != "logicLayer")
0101 return;
0102 G4int iScoringVolume = 0;
0103
0104 G4int iKinematicRegion = aTrack->GetKineticEnergy() < 20.0 ? 1 : 2;
0105 G4int absPdg = std::abs(aTrack->GetDefinition()->GetPDGEncoding());
0106 G4int iParticleType = -1;
0107 if (absPdg == 11)
0108 iParticleType = 1;
0109 else if (absPdg == 22)
0110 iParticleType = 2;
0111 else if (absPdg == 13)
0112 iParticleType = 3;
0113 else if (absPdg == 12 || absPdg == 14 || absPdg == 16)
0114 iParticleType = 4;
0115
0116 else if (absPdg == 111 || absPdg == 211)
0117 iParticleType = 5;
0118 else if (absPdg == 2112)
0119 iParticleType = 6;
0120 else if (absPdg == 2212)
0121 iParticleType = 7;
0122 else if (G4IonTable::IsIon(aTrack->GetDefinition())
0123 || G4IonTable::IsAntiIon(aTrack->GetDefinition()))
0124 iParticleType = 8;
0125
0126 else if (absPdg < 1000)
0127 iParticleType = 9;
0128
0129 else if (absPdg > 1000)
0130 iParticleType = 10;
0131
0132
0133 G4int index = GetIndex(iScoringVolume, iKinematicRegion, iParticleType);
0134 ++fArrayMultiplicities[index];
0135 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0136
0137 index = GetIndex(iScoringVolume, iKinematicRegion, 0);
0138 ++fArrayMultiplicities[index];
0139 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0140
0141 index = GetIndex(iScoringVolume, 0, iParticleType);
0142 ++fArrayMultiplicities[index];
0143 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0144
0145 index = GetIndex(iScoringVolume, 0, 0);
0146 ++fArrayMultiplicities[index];
0147 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0148 if (fRunPtr) {
0149 fRunPtr->SetTrackingArray1(fArrayMultiplicities);
0150 fRunPtr->SetTrackingArray2(fArraySumKineticEnergies);
0151 }
0152 }
0153
0154
0155
0156 void TrackingAction::PostUserTrackingAction(const G4Track* ) {}
0157
0158