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