Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /// \file TrackingAction.cc 27 /// \brief Implementation of the TrackingAction class 28 // 29 // 30 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 #include "TrackingAction.hh" 35 36 #include "Run.hh" 37 38 #include "G4IonTable.hh" 39 #include "G4ParticleDefinition.hh" 40 #include "G4ParticleTypes.hh" 41 #include "G4Step.hh" 42 #include "G4StepPoint.hh" 43 #include "G4SystemOfUnits.hh" 44 #include "G4Track.hh" 45 46 const std::array<G4String, TrackingAction::fkNumberScoringVolumes> 47 TrackingAction::fkArrayScoringVolumeNames = {"tracker", "emCalo", "hadCalo"}; 48 49 const std::array<G4String, TrackingAction::fkNumberKinematicRegions> 50 TrackingAction::fkArrayKinematicRegionNames = {"", "below 20 MeV", "above 20 MeV"}; 51 52 const std::array<G4String, TrackingAction::fkNumberParticleTypes> 53 TrackingAction::fkArrayParticleTypeNames = {"all", "electron", "gamma", "muon", 54 "neutrino", "pion", "neutron", "proton", 55 "ion", "otherMeson", "otherBaryon"}; 56 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 59 G4int TrackingAction::GetIndex(const G4int iScoringVolume, const G4int iKinematicRegion, 60 const G4int iParticleType) 61 { 62 G4int index = -1; 63 if (iScoringVolume >= 0 && iScoringVolume < fkNumberScoringVolumes && iKinematicRegion >= 0 64 && iKinematicRegion < fkNumberKinematicRegions && iParticleType >= 0 65 && iParticleType < fkNumberParticleTypes) 66 { 67 index = iScoringVolume * fkNumberKinematicRegions * fkNumberParticleTypes 68 + iKinematicRegion * fkNumberParticleTypes + iParticleType; 69 } 70 return index; 71 } 72 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 74 75 TrackingAction::TrackingAction() : G4UserTrackingAction() 76 { 77 Initialize(); 78 } 79 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 81 82 void TrackingAction::Initialize() 83 { 84 // Initialization needed at the beginning of each Run 85 fArrayMultiplicities.fill(0); 86 fArraySumKineticEnergies.fill(0.0); 87 } 88 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 91 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack) 92 { 93 // This method is called not only once when a particle is created, 94 // but also each time it is resumed, in the case the track gets suspended, 95 // as it happens in the case of neutrons with _HP Physics Lists. 96 // To be sure that we collect information about a track one and only once, 97 // we require that the current step be the first one. 98 if (aTrack == nullptr || aTrack->GetCurrentStepNumber() != 0 || aTrack->GetDefinition() == nullptr 99 || aTrack->GetLogicalVolumeAtVertex() == nullptr) 100 return; 101 G4int iScoringVolume = -1; 102 if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicTrackerShell") { 103 iScoringVolume = 0; 104 } 105 else if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicEmCaloShell") { 106 iScoringVolume = 1; 107 } 108 else if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicHadCaloShell") { 109 iScoringVolume = 2; 110 } 111 if (iScoringVolume < 0) return; 112 // Three kinematical regions: [0] : any value ; [1] : below 20 MeV ; [2] : above 20 MeV 113 G4int iKinematicRegion = aTrack->GetKineticEnergy() < 20.0 ? 1 : 2; 114 G4int absPdg = std::abs(aTrack->GetDefinition()->GetPDGEncoding()); 115 G4int iParticleType = -1; 116 if (absPdg == 11) 117 iParticleType = 1; // electron (and positron) 118 else if (absPdg == 22) 119 iParticleType = 2; // gamma 120 else if (absPdg == 13) 121 iParticleType = 3; // muons (mu- and mu+) 122 else if (absPdg == 12 || absPdg == 14 || absPdg == 16) 123 iParticleType = 4; 124 // neutrinos (and anti-neutrinos), all flavors 125 else if (absPdg == 111 || absPdg == 211) 126 iParticleType = 5; // (charged) pions 127 else if (absPdg == 2112) 128 iParticleType = 6; // neutron (and anti-neutron) 129 else if (absPdg == 2212) 130 iParticleType = 7; // proton (and anti-proton) 131 else if (G4IonTable::IsIon(aTrack->GetDefinition()) 132 || G4IonTable::IsAntiIon(aTrack->GetDefinition())) 133 iParticleType = 8; 134 // ions (and anti-ions) 135 else if (absPdg < 1000) 136 iParticleType = 9; // other mesons (e.g. kaons) 137 // (Note: this works in most cases, but not always!) 138 else if (absPdg > 1000) 139 iParticleType = 10; // other baryons (e.g. hyperons, 140 // anti-hyperons, etc.) 141 // Consider the specific case : scoring volume, kinematic region and particle type 142 G4int index = GetIndex(iScoringVolume, iKinematicRegion, iParticleType); 143 ++fArrayMultiplicities[index]; 144 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy(); 145 // Consider the "all" particle case, with the same scoring volume and kinematic region 146 index = GetIndex(iScoringVolume, iKinematicRegion, 0); 147 ++fArrayMultiplicities[index]; 148 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy(); 149 // Consider the "any" kinematic region case, with the same scoring volume and particle type 150 index = GetIndex(iScoringVolume, 0, iParticleType); 151 ++fArrayMultiplicities[index]; 152 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy(); 153 // Consider the "any" kinematic region and "all" particle, with the same scoring volume 154 index = GetIndex(iScoringVolume, 0, 0); 155 ++fArrayMultiplicities[index]; 156 fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy(); 157 if (fRunPtr) { 158 fRunPtr->SetTrackingArray1(fArrayMultiplicities); 159 fRunPtr->SetTrackingArray2(fArraySumKineticEnergies); 160 } 161 } 162 163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 164 165 void TrackingAction::PostUserTrackingAction(const G4Track* /* aTrack */) {} 166 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168