Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:06:17

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file TrackingAction.cc
0027 /// \brief Implementation of the TrackingAction class
0028 //
0029 //
0030 
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 = {"tracker", "emCalo", "hadCalo"};
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0074 
0075 TrackingAction::TrackingAction() : G4UserTrackingAction()
0076 {
0077   Initialize();
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void TrackingAction::Initialize()
0083 {
0084   // Initialization needed at the beginning of each Run
0085   fArrayMultiplicities.fill(0);
0086   fArraySumKineticEnergies.fill(0.0);
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0090 
0091 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack)
0092 {
0093   // This method is called not only once when a particle is created,
0094   // but also each time it is resumed, in the case the track gets suspended,
0095   // as it happens in the case of neutrons with _HP Physics Lists.
0096   // To be sure that we collect information about a track one and only once,
0097   // we require that the current step be the first one.
0098   if (aTrack == nullptr || aTrack->GetCurrentStepNumber() != 0 || aTrack->GetDefinition() == nullptr
0099       || aTrack->GetLogicalVolumeAtVertex() == nullptr)
0100     return;
0101   G4int iScoringVolume = -1;
0102   if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicTrackerShell") {
0103     iScoringVolume = 0;
0104   }
0105   else if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicEmCaloShell") {
0106     iScoringVolume = 1;
0107   }
0108   else if (aTrack->GetLogicalVolumeAtVertex()->GetName() == "logicHadCaloShell") {
0109     iScoringVolume = 2;
0110   }
0111   if (iScoringVolume < 0) return;
0112   // Three kinematical regions:  [0] : any value ;  [1] : below 20 MeV ;  [2] : above 20 MeV
0113   G4int iKinematicRegion = aTrack->GetKineticEnergy() < 20.0 ? 1 : 2;
0114   G4int absPdg = std::abs(aTrack->GetDefinition()->GetPDGEncoding());
0115   G4int iParticleType = -1;
0116   if (absPdg == 11)
0117     iParticleType = 1;  // electron (and positron)
0118   else if (absPdg == 22)
0119     iParticleType = 2;  // gamma
0120   else if (absPdg == 13)
0121     iParticleType = 3;  // muons (mu- and mu+)
0122   else if (absPdg == 12 || absPdg == 14 || absPdg == 16)
0123     iParticleType = 4;
0124   // neutrinos (and anti-neutrinos), all flavors
0125   else if (absPdg == 111 || absPdg == 211)
0126     iParticleType = 5;  // (charged) pions
0127   else if (absPdg == 2112)
0128     iParticleType = 6;  // neutron (and anti-neutron)
0129   else if (absPdg == 2212)
0130     iParticleType = 7;  // proton  (and anti-proton)
0131   else if (G4IonTable::IsIon(aTrack->GetDefinition())
0132            || G4IonTable::IsAntiIon(aTrack->GetDefinition()))
0133     iParticleType = 8;
0134   // ions (and anti-ions)
0135   else if (absPdg < 1000)
0136     iParticleType = 9;  // other mesons (e.g. kaons)
0137   // (Note: this works in most cases, but not always!)
0138   else if (absPdg > 1000)
0139     iParticleType = 10;  // other baryons (e.g. hyperons,
0140                          // anti-hyperons, etc.)
0141   // Consider the specific case : scoring volume, kinematic region and particle type
0142   G4int index = GetIndex(iScoringVolume, iKinematicRegion, iParticleType);
0143   ++fArrayMultiplicities[index];
0144   fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0145   // Consider the "all" particle case, with the same scoring volume and kinematic region
0146   index = GetIndex(iScoringVolume, iKinematicRegion, 0);
0147   ++fArrayMultiplicities[index];
0148   fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0149   // Consider the "any" kinematic region case, with the same scoring volume and particle type
0150   index = GetIndex(iScoringVolume, 0, iParticleType);
0151   ++fArrayMultiplicities[index];
0152   fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0153   // Consider the "any" kinematic region and "all" particle, with the same scoring volume
0154   index = GetIndex(iScoringVolume, 0, 0);
0155   ++fArrayMultiplicities[index];
0156   fArraySumKineticEnergies[index] += aTrack->GetKineticEnergy();
0157   if (fRunPtr) {
0158     fRunPtr->SetTrackingArray1(fArrayMultiplicities);
0159     fRunPtr->SetTrackingArray2(fArraySumKineticEnergies);
0160   }
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void TrackingAction::PostUserTrackingAction(const G4Track* /* aTrack  */) {}
0166 
0167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......