Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 08:31:59

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 SteppingAction.cc
0027 /// \brief Implementation of the SteppingAction class
0028 
0029 // This example is provided by the Geant4-DNA collaboration
0030 // Any report or published results obtained using the Geant4-DNA software
0031 // shall cite the following Geant4-DNA collaboration publications:
0032 // Med. Phys. 45 (2018) e722-e739
0033 // Phys. Med. 31 (2015) 861-874
0034 // Med. Phys. 37 (2010) 4692-4708
0035 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0036 //
0037 // The Geant4-DNA web site is available at http://geant4-dna.org
0038 //
0039 
0040 #include "SteppingAction.hh"
0041 
0042 #include "G4DNAGenericIonsManager.hh"
0043 #include "G4Electron.hh"
0044 #include "G4Gamma.hh"
0045 #include "G4Proton.hh"
0046 #include "G4RunManager.hh"
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0049 
0050 SteppingAction::SteppingAction() : G4UserSteppingAction()
0051 {
0052   fSumOfStepLength = 0;
0053   fLength = 0;
0054   fDeltaE = -7;
0055   fTotalStoppingPower = -8;
0056   fTotalNumberOfSteps = 0;
0057   fNumberOfSteps = 0;
0058   fDepositedEnergy = 0;
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 
0063 SteppingAction::~SteppingAction() {}
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void SteppingAction::UserSteppingAction(const G4Step* step)
0068 {
0069   //*** WARNING: this line will kill all secondary e- and gammas ***
0070 
0071   if (step->GetTrack()->GetDefinition() == G4Electron::ElectronDefinition()
0072       && step->GetTrack()->GetTrackID() != 1)
0073     step->GetTrack()->SetTrackStatus(fStopAndKill);
0074 
0075   if (step->GetTrack()->GetDefinition() == G4Gamma::GammaDefinition())
0076     step->GetTrack()->SetTrackStatus(fStopAndKill);
0077 
0078   //
0079 
0080   G4double charge = step->GetTrack()->GetDefinition()->GetPDGCharge();
0081   G4double steplen = step->GetStepLength();
0082   G4double edep = step->GetTotalEnergyDeposit();
0083   G4int maxNumberOfSteps = -1;
0084 
0085   G4DNAGenericIonsManager* instance;
0086   instance = G4DNAGenericIonsManager::Instance();
0087 
0088   if (
0089     // ELECTRONS
0090     (step->GetTrack()->GetTrackID() == 1
0091      && step->GetTrack()->GetParticleDefinition() == G4Electron::ElectronDefinition())
0092 
0093     ||
0094 
0095     // PROTONS, HYDROGEN, ALPHA PARTICLES AND CHARGED STATES, IONS
0096     (charge != -1. && step->GetTrack()->GetParticleDefinition() != G4Gamma::GammaDefinition())
0097 
0098   )
0099   {
0100     fSumOfStepLength = fSumOfStepLength + steplen;
0101     fDepositedEnergy = fDepositedEnergy + edep;
0102     fNumberOfSteps = fNumberOfSteps + 1;
0103 
0104     // G4cout << fSumOfStepLength << " " << fDepositedEnergy << " " << fNumberOfSteps << G4endl;
0105 
0106     // ELECTRONS
0107 
0108     if (step->GetTrack()->GetParticleDefinition() == G4Electron::ElectronDefinition())
0109       maxNumberOfSteps = 1000;
0110 
0111     // PROTONS, HYDROGEN
0112 
0113     if (step->GetTrack()->GetParticleDefinition() == G4Proton::ProtonDefinition()
0114         || step->GetTrack()->GetParticleDefinition() == instance->GetIon("hydrogen"))
0115       maxNumberOfSteps = 1000;
0116 
0117     // He0, He+, He2+
0118 
0119     if (step->GetTrack()->GetParticleDefinition() == instance->GetIon("alpha++")
0120         || step->GetTrack()->GetParticleDefinition() == instance->GetIon("alpha+")
0121         || step->GetTrack()->GetParticleDefinition() == instance->GetIon("helium"))
0122       maxNumberOfSteps = 10000;
0123 
0124     // IONS (above helium)
0125     if (charge > 2) maxNumberOfSteps = 10000;
0126 
0127     // ALL
0128 
0129     if (fNumberOfSteps > maxNumberOfSteps) {
0130       fLength = fSumOfStepLength;
0131 
0132       fTotalStoppingPower = fDepositedEnergy / fLength;
0133       // G4cout << fTotalStoppingPower/(MeV/cm) << G4endl;
0134 
0135       // *** Default method to stop calculation (no secondary electrons tracked)
0136       // G4RunManager::GetRunManager()->AbortEvent();
0137 
0138       // *** Alternative method when secondary electrons are scored in TrackingAction (slower)
0139       step->GetTrack()->SetTrackStatus(fStopAndKill);
0140 
0141       fSumOfStepLength = 0.;
0142       fDepositedEnergy = 0;
0143       fNumberOfSteps = 0;
0144     };
0145   };
0146 }