Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file SteppingAction.cc 27 /// \brief Implementation of the SteppingActio 28 // 29 // 30 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oo 33 34 #include "SteppingAction.hh" 35 36 #include "Run.hh" 37 38 #include "G4IonTable.hh" 39 #include "G4LossTableManager.hh" 40 #include "G4ParticleDefinition.hh" 41 #include "G4ParticleTypes.hh" 42 #include "G4Step.hh" 43 #include "G4StepPoint.hh" 44 #include "G4SystemOfUnits.hh" 45 #include "G4TouchableHistory.hh" 46 #include "G4Track.hh" 47 #include "G4VPhysicalVolume.hh" 48 #include "G4VSolid.hh" 49 #include "G4VTouchable.hh" 50 51 const std::array<G4String, SteppingAction::fkN 52 SteppingAction::fkArrayScoringShellNames = { 53 54 const std::array<G4String, SteppingAction::fkN 55 SteppingAction::fkArrayKinematicRegionNames 56 57 const std::array<G4String, SteppingAction::fkN 58 SteppingAction::fkArrayScoringPositionNames 59 60 const std::array<G4String, SteppingAction::fkN 61 SteppingAction::fkArrayParticleTypeNames = { 62 63 64 65 //....oooOO0OOooo........oooOO0OOooo........oo 66 67 G4int SteppingAction::GetIndex(const G4int iSc 68 const G4int iSc 69 { 70 G4int index = -1; 71 if (iScoringShell >= 0 && iScoringShell < fk 72 && iKinematicRegion < fkNumberKinematicR 73 && iScoringPosition < fkNumberScoringPos 74 && iParticleType < fkNumberParticleTypes 75 { 76 index = 77 iScoringShell * fkNumberKinematicRegions 78 + iKinematicRegion * fkNumberScoringPosi 79 + iScoringPosition * fkNumberParticleTyp 80 } 81 if (index < 0 || index >= fkNumberCombinatio 82 G4cerr << "SteppingAction::GetIndex : WRON 83 index = 0; 84 } 85 return index; 86 } 87 88 //....oooOO0OOooo........oooOO0OOooo........oo 89 90 SteppingAction::SteppingAction() : G4UserStepp 91 { 92 Initialize(); 93 } 94 95 //....oooOO0OOooo........oooOO0OOooo........oo 96 97 void SteppingAction::Initialize() 98 { 99 // Initialization needed at the beginning of 100 fPrimaryParticleId = 0; 101 fPrimaryParticleEnergy = 0.0; 102 fPrimaryParticleDirection = G4ThreeVector(0. 103 fTrackerMaterialName = fEmCaloMaterialName = 104 fIsFirstStepOfTheEvent = true; 105 fIsFirstStepInTracker = fIsFirstStepInEmCalo 106 fIsFirstStepInScoringTrackerShell = fIsFirst 107 fIsFirstStepInScoringHadCaloShell = true; 108 fCubicVolumeScoringTrackerShell = fCubicVolu 109 fCubicVolumeScoringHadCaloShell = 1.0; 110 for (G4int i = 0; i < fkNumberCombinations; 111 fArraySumStepLengths[i] = 0.0; 112 } 113 /* 114 for ( G4int i = 0; i < fkNumberCombinations; 115 G4cout << " fkNumberCombinations=" << fkNumb 116 for ( G4int i = 0; i < fkNumberScoringShells 117 for ( G4int j = 0; j < fkNumberKinematicRe 118 for ( G4int k = 0; k < fkNumberScoringPo 119 for ( G4int ll = 0; ll < fkNumberParti 120 G4int index = GetIndex( i, j, k, ll 121 G4cout << "(i, j, k, ll)=(" << i << 122 << ll << ") ->" << index; 123 if ( fArraySumStepLengths[ index ] < 124 else 125 G4cout << G4endl; 126 } 127 } 128 } 129 } 130 for ( G4int i = 0; i < fkNumberCombinations; 131 if ( fArraySumStepLengths[i] > 999.0 ) G4c 132 } 133 */ 134 } 135 136 //....oooOO0OOooo........oooOO0OOooo........oo 137 138 void SteppingAction::UserSteppingAction(const 139 { 140 // Get information on the primary particle 141 if (fIsFirstStepOfTheEvent) { 142 if (theStep->GetTrack()->GetParentID() == 143 fPrimaryParticleId = theStep->GetTrack() 144 fPrimaryParticleEnergy = theStep->GetPre 145 fPrimaryParticleDirection = theStep->Get 146 if (fRunPtr) { 147 fRunPtr->SetPrimaryParticleId(fPrimary 148 fRunPtr->SetPrimaryParticleEnergy(fPri 149 fRunPtr->SetPrimaryParticleDirection(f 150 } 151 fIsFirstStepOfTheEvent = false; 152 } 153 } 154 // Get information on the materials 155 if (fIsFirstStepInTracker 156 && theStep->GetPreStepPoint()->GetPhysic 157 { 158 fTrackerMaterialName = theStep->GetPreStep 159 if (fRunPtr) fRunPtr->SetTrackerMaterialNa 160 fIsFirstStepInTracker = false; 161 } 162 if (fIsFirstStepInEmCalo 163 && theStep->GetPreStepPoint()->GetPhysic 164 { 165 fEmCaloMaterialName = theStep->GetPreStepP 166 if (fRunPtr) fRunPtr->SetEmCaloMaterialNam 167 fIsFirstStepInEmCalo = false; 168 } 169 if (fIsFirstStepInHadCalo 170 && theStep->GetPreStepPoint()->GetPhysic 171 { 172 fHadCaloMaterialName = theStep->GetPreStep 173 if (fRunPtr) fRunPtr->SetHadCaloMaterialNa 174 fIsFirstStepInHadCalo = false; 175 } 176 // Get information on step lengths in the sc 177 G4int iScoringShell = -1; 178 if (theStep->GetPreStepPoint()->GetPhysicalV 179 iScoringShell = 0; 180 if (fIsFirstStepInScoringTrackerShell) { 181 fCubicVolumeScoringTrackerShell = 182 theStep->GetTrack()->GetVolume()->GetL 183 if (fRunPtr) fRunPtr->SetCubicVolumeScor 184 fIsFirstStepInScoringTrackerShell = fals 185 } 186 } 187 else if (theStep->GetPreStepPoint()->GetPhys 188 { 189 iScoringShell = 1; 190 if (fIsFirstStepInScoringEmCaloShell) { 191 fCubicVolumeScoringEmCaloShell = 192 theStep->GetTrack()->GetVolume()->GetL 193 if (fRunPtr) fRunPtr->SetCubicVolumeScor 194 fIsFirstStepInScoringEmCaloShell = false 195 } 196 } 197 else if (theStep->GetPreStepPoint()->GetPhys 198 { 199 iScoringShell = 2; 200 if (fIsFirstStepInScoringHadCaloShell) { 201 fCubicVolumeScoringHadCaloShell = 202 theStep->GetTrack()->GetVolume()->GetL 203 if (fRunPtr) fRunPtr->SetCubicVolumeScor 204 fIsFirstStepInScoringHadCaloShell = fals 205 } 206 } 207 if (iScoringShell >= 0) { 208 G4double stepLength = theStep->GetTrack()- 209 G4int absPdg = theStep->GetTrack()->GetDef 210 ? 0 211 : std::abs(theStep->GetTr 212 /* 213 G4cout << theStep->GetTrack()->GetDefiniti 214 << " Ekin[MeV]=" << theStep->GetPr 215 << " r[mm]=" << theStep->GetTrack( 216 << " z[mm]=" << theStep->GetTrack( 217 << " " << theStep->GetTrack()->Get 218 << " " << theStep->GetTrack()->Get 219 << " L[mm]=" << stepLength << " " 220 << ( fPrimaryParticleDirection.dot( 221 ? "forward" : "backward" ) << 222 */ 223 // Three kinematical regions: [0] : any v 224 G4int iKinematicRegion = theStep->GetPreSt 225 // Two scoring positions: [0] : forward h 226 // (with respect to the primary particle i 227 G4int iScoringPosition = 228 fPrimaryParticleDirection.dot(theStep->G 229 G4int iParticleType = -1; 230 if (absPdg == 11) 231 iParticleType = 1; // electron (and pos 232 else if (absPdg == 22) 233 iParticleType = 2; // gamma 234 else if (absPdg == 13) 235 iParticleType = 3; // muons (mu- and mu 236 else if (absPdg == 12 || absPdg == 14 || a 237 iParticleType = 4; // neutrinos 238 // (and anti-neutrinos), all flavors 239 else if (absPdg == 111 || absPdg == 211) 240 iParticleType = 5; // (charged) pions 241 else if (absPdg == 2112) 242 iParticleType = 6; // neutron (and anti 243 else if (absPdg == 2212) 244 iParticleType = 7; // proton (and anti 245 else if (G4IonTable::IsIon(theStep->GetTra 246 G4IonTable::IsAntiIon(theStep->Ge 247 iParticleType = 8; 248 else if (absPdg < 1000) 249 iParticleType = 9; // other mesons (e.g 250 // in most cases, bu 251 else if (absPdg > 1000) 252 iParticleType = 10; // other baryons (e 253 // etc.) 254 // Consider the specific case : scoring sh 255 // particle type 256 G4int index = GetIndex(iScoringShell, iKin 257 fArraySumStepLengths[index] += stepLength; 258 // Consider the "all" particle case, with 259 // scoring position 260 index = GetIndex(iScoringShell, iKinematic 261 fArraySumStepLengths[index] += stepLength; 262 // Consider the "any" kinematic region cas 263 // and particle type 264 index = GetIndex(iScoringShell, 0, iScorin 265 fArraySumStepLengths[index] += stepLength; 266 // Consider the "any" kinematic region and 267 // scoring position 268 index = GetIndex(iScoringShell, 0, iScorin 269 fArraySumStepLengths[index] += stepLength; 270 if (fRunPtr) fRunPtr->SetSteppingArray(fAr 271 } 272 } 273 274 //....oooOO0OOooo........oooOO0OOooo........oo 275