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p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/hadronic/ParticleFluence/Calo/src/TrackingAction.cc (Version 11.3.0) and /examples/extended/hadronic/ParticleFluence/Calo/src/TrackingAction.cc (Version 11.2.2)


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