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 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collaboration publications: 29 // Med. Phys. 45 (2018) e722-e739 30 // Phys. Med. 31 (2015) 861-874 31 // Med. Phys. 37 (2010) 4692-4708 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178 33 // 34 // The Geant4-DNA web site is available at http://geant4-dna.org 35 // 36 /// \file SteppingAction.cc 37 /// \brief Implementation of the SteppingAction class 38 39 #include "SteppingAction.hh" 40 41 #include "DetectorConstruction.hh" 42 #include "PrimaryGeneratorAction.hh" 43 #include "RunAction.hh" 44 45 #include "G4Alpha.hh" 46 #include "G4AnalysisManager.hh" 47 #include "G4DNAGenericIonsManager.hh" 48 #include "G4Electron.hh" 49 #include "G4Event.hh" 50 #include "G4EventManager.hh" 51 #include "G4Gamma.hh" 52 #include "G4Proton.hh" 53 #include "G4SteppingManager.hh" 54 #include "G4SystemOfUnits.hh" 55 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 58 SteppingAction::SteppingAction() : G4UserSteppingAction() {} 59 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 61 62 SteppingAction::~SteppingAction() {} 63 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 65 66 void SteppingAction::UserSteppingAction(const G4Step* step) 67 { 68 // Protection 69 if (!step->GetPostStepPoint()) return; 70 if (!step->GetPostStepPoint()->GetProcessDefinedStep()) return; 71 72 // 73 G4double flagParticle = -1.; 74 G4double flagProcess = -1.; 75 G4double x, y, z, xp, yp, zp; 76 77 // Particle identification 78 79 // The following method avoids the usage of string comparison 80 G4ParticleDefinition* partDef = step->GetTrack()->GetDynamicParticle()->GetDefinition(); 81 82 if (partDef == G4Gamma::GammaDefinition()) flagParticle = 0; 83 84 if (partDef == G4Electron::ElectronDefinition()) flagParticle = 1; 85 86 if (partDef == G4Proton::ProtonDefinition()) flagParticle = 2; 87 88 if (partDef == G4Alpha::AlphaDefinition()) flagParticle = 4; 89 90 G4DNAGenericIonsManager* instance; 91 instance = G4DNAGenericIonsManager::Instance(); 92 93 // Usage example 94 /* 95 G4ParticleDefinition* protonDef = G4Proton::ProtonDefinition(); 96 G4ParticleDefinition* hydrogenDef = instance->GetIon("hydrogen"); 97 G4ParticleDefinition* alphaPlusPlusDef = instance->GetIon("alpha++"); 98 G4ParticleDefinition* alphaPlusDef = instance->GetIon("alpha+"); 99 G4ParticleDefinition* heliumDef = instance->GetIon("helium"); 100 */ 101 102 if (partDef == instance->GetIon("hydrogen")) flagParticle = 3; 103 104 if (partDef == instance->GetIon("alpha+")) flagParticle = 5; 105 106 if (partDef == instance->GetIon("helium")) flagParticle = 6; 107 108 // Alternative method (based on string comparison) 109 110 /* 111 const G4String& particleName = step->GetTrack()->GetDynamicParticle()-> 112 GetDefinition()->GetParticleName(); 113 114 if (particleName == "gamma") flagParticle = 0; 115 else if (particleName == "e-") flagParticle = 1; 116 else if (particleName == "proton") flagParticle = 2; 117 else if (particleName == "hydrogen") flagParticle = 3; 118 else if (particleName == "alpha") flagParticle = 4; 119 else if (particleName == "alpha+") flagParticle = 5; 120 else if (particleName == "helium") flagParticle = 6; 121 */ 122 123 // Process identification 124 125 // Process sub-types are listed in G4PhysicsListHelper.cc 126 // or in Geant4-DNA process class implementation files (*.cc) 127 128 G4StepPoint* preStep = step->GetPreStepPoint(); 129 G4StepPoint* postStep = step->GetPostStepPoint(); 130 G4int procID = postStep->GetProcessDefinedStep()->GetProcessSubType(); 131 132 const G4String& processName = postStep->GetProcessDefinedStep()->GetProcessName(); 133 134 if (processName == "Capture") flagProcess = 1; 135 // (no subType and procID exists at the moment for this process) 136 // used to kill ions below tracking cut 137 138 else if (flagParticle == 0) { 139 if (procID == 12) 140 flagProcess = 81; 141 else if (procID == 13) 142 flagProcess = 82; 143 else if (procID == 14) 144 flagProcess = 83; 145 else if (procID == 11) 146 flagProcess = 84; 147 } 148 149 else if (flagParticle == 1) { 150 if (procID == 58) 151 flagProcess = 10; 152 else if (procID == 51) 153 flagProcess = 11; 154 else if (procID == 52) 155 flagProcess = 12; 156 else if (procID == 53) 157 flagProcess = 13; 158 else if (procID == 55) 159 flagProcess = 14; 160 else if (procID == 54) 161 flagProcess = 15; 162 else if (procID == 10) 163 flagProcess = 110; 164 else if (procID == 1) 165 flagProcess = 120; 166 else if (procID == 2) 167 flagProcess = 130; 168 } 169 170 else if (flagParticle == 2) { 171 if (procID == 51) 172 flagProcess = 21; 173 else if (procID == 52) 174 flagProcess = 22; 175 else if (procID == 53) 176 flagProcess = 23; 177 else if (procID == 56) 178 flagProcess = 24; 179 else if (procID == 10) 180 flagProcess = 210; 181 else if (procID == 1) 182 flagProcess = 220; 183 else if (procID == 2) 184 flagProcess = 230; 185 else if (procID == 8) 186 flagProcess = 240; 187 } 188 189 else if (flagParticle == 3) { 190 if (procID == 51) 191 flagProcess = 31; 192 else if (procID == 52) 193 flagProcess = 32; 194 else if (procID == 53) 195 flagProcess = 33; 196 else if (procID == 57) 197 flagProcess = 35; 198 } 199 200 else if (flagParticle == 4) { 201 if (procID == 51) 202 flagProcess = 41; 203 else if (procID == 52) 204 flagProcess = 42; 205 else if (procID == 53) 206 flagProcess = 43; 207 else if (procID == 56) 208 flagProcess = 44; 209 else if (procID == 10) 210 flagProcess = 410; 211 else if (procID == 1) 212 flagProcess = 420; 213 else if (procID == 2) 214 flagProcess = 430; 215 else if (procID == 8) 216 flagProcess = 440; 217 } 218 219 else if (flagParticle == 5) { 220 if (procID == 51) 221 flagProcess = 51; 222 else if (procID == 52) 223 flagProcess = 52; 224 else if (procID == 53) 225 flagProcess = 53; 226 else if (procID == 56) 227 flagProcess = 54; 228 else if (procID == 57) 229 flagProcess = 55; 230 else if (procID == 10) 231 flagProcess = 510; 232 else if (procID == 1) 233 flagProcess = 520; 234 else if (procID == 2) 235 flagProcess = 530; 236 else if (procID == 8) 237 flagProcess = 540; 238 } 239 240 else if (flagParticle == 6) { 241 if (procID == 51) 242 flagProcess = 61; 243 else if (procID == 52) 244 flagProcess = 62; 245 else if (procID == 53) 246 flagProcess = 63; 247 else if (procID == 57) 248 flagProcess = 65; 249 } 250 251 else if (processName == "GenericIon_G4DNAIonisation") 252 flagProcess = 73; 253 else if (processName == "msc") 254 flagProcess = 710; 255 else if (processName == "CoulombScat") 256 flagProcess = 720; 257 else if (processName == "ionIoni") 258 flagProcess = 730; 259 else if (processName == "nuclearStopping") 260 flagProcess = 740; 261 // (for all GenericIons) 262 263 // Alternatively, using process names 264 265 /* 266 else if (processName=="e-_G4DNAElectronSolvation") flagProcess =10; 267 else if (processName=="e-_G4DNAElastic") flagProcess =11; 268 else if (processName=="e-_G4DNAExcitation") flagProcess =12; 269 else if (processName=="e-_G4DNAIonisation") flagProcess =13; 270 else if (processName=="e-_G4DNAAttachment") flagProcess =14; 271 else if (processName=="e-_G4DNAVibExcitation") flagProcess =15; 272 273 else if (processName=="proton_G4DNAElastic") flagProcess =21; 274 else if (processName=="proton_G4DNAExcitation") flagProcess =22; 275 else if (processName=="proton_G4DNAIonisation") flagProcess =23; 276 else if (processName=="proton_G4DNAChargeDecrease") flagProcess =24; 277 278 else if (processName=="hydrogen_G4DNAElastic") flagProcess =31; 279 else if (processName=="hydrogen_G4DNAExcitation") flagProcess =32; 280 else if (processName=="hydrogen_G4DNAIonisation") flagProcess =33; 281 else if (processName=="hydrogen_G4DNAChargeIncrease") flagProcess =35; 282 283 else if (processName=="alpha_G4DNAElastic") flagProcess =41; 284 else if (processName=="alpha_G4DNAExcitation") flagProcess =42; 285 else if (processName=="alpha_G4DNAIonisation") flagProcess =43; 286 else if (processName=="alpha_G4DNAChargeDecrease") flagProcess =44; 287 288 else if (processName=="alpha+_G4DNAElastic") flagProcess =51; 289 else if (processName=="alpha+_G4DNAExcitation") flagProcess =52; 290 else if (processName=="alpha+_G4DNAIonisation") flagProcess =53; 291 else if (processName=="alpha+_G4DNAChargeDecrease") flagProcess =54; 292 else if (processName=="alpha+_G4DNAChargeIncrease") flagProcess =55; 293 294 else if (processName=="helium_G4DNAElastic") flagProcess =61; 295 else if (processName=="helium_G4DNAExcitation") flagProcess =62; 296 else if (processName=="helium_G4DNAIonisation") flagProcess =63; 297 else if (processName=="helium_G4DNAChargeIncrease") flagProcess =65; 298 299 else if (processName=="GenericIon_G4DNAIonisation") flagProcess =73; 300 301 */ 302 303 if (processName != "Transportation") { 304 x = preStep->GetPosition().x() / nanometer; 305 y = preStep->GetPosition().y() / nanometer; 306 z = preStep->GetPosition().z() / nanometer; 307 308 xp = postStep->GetPosition().x() / nanometer; 309 yp = postStep->GetPosition().y() / nanometer; 310 zp = postStep->GetPosition().z() / nanometer; 311 312 // get analysis manager 313 314 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 315 316 // fill ntuple 317 analysisManager->FillNtupleDColumn(0, flagParticle); 318 analysisManager->FillNtupleDColumn(1, flagProcess); 319 analysisManager->FillNtupleDColumn(2, xp); 320 analysisManager->FillNtupleDColumn(3, yp); 321 analysisManager->FillNtupleDColumn(4, zp); 322 analysisManager->FillNtupleDColumn(5, step->GetTotalEnergyDeposit() / eV); 323 324 analysisManager->FillNtupleDColumn( 325 6, std::sqrt((x - xp) * (x - xp) + (y - yp) * (y - yp) + (z - zp) * (z - zp))); 326 327 analysisManager->FillNtupleDColumn( 328 7, (preStep->GetKineticEnergy() - postStep->GetKineticEnergy()) / eV); 329 330 analysisManager->FillNtupleDColumn(8, preStep->GetKineticEnergy() / eV); 331 332 analysisManager->FillNtupleDColumn(9, preStep->GetMomentumDirection() 333 * postStep->GetMomentumDirection()); 334 335 analysisManager->FillNtupleIColumn( 336 10, G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()); 337 338 analysisManager->FillNtupleIColumn(11, step->GetTrack()->GetTrackID()); 339 340 analysisManager->FillNtupleIColumn(12, step->GetTrack()->GetParentID()); 341 342 analysisManager->FillNtupleIColumn(13, step->GetTrack()->GetCurrentStepNumber()); 343 344 analysisManager->AddNtupleRow(); 345 } 346 } 347