Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-18 07:42:23

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. 51 (2024) 5873-5889
0033 // Med. Phys. 45 (2018) e722-e739
0034 // Phys. Med. 31 (2015) 861-874
0035 // Med. Phys. 37 (2010) 4692-4708
0036 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0037 //
0038 // The Geant4-DNA web site is available at http://geant4-dna.org
0039 //
0040 
0041 #include "SteppingAction.hh"
0042 #include "SteppingMessenger.hh"
0043 #include "DetectorConstruction.hh"
0044 #include "PrimaryGeneratorAction.hh"
0045 #include "RunAction.hh"
0046 
0047 #include "G4Alpha.hh"
0048 #include "G4AnalysisManager.hh"
0049 #include "G4DNAGenericIonsManager.hh"
0050 #include "G4Electron.hh"
0051 #include "G4Event.hh"
0052 #include "G4EventManager.hh"
0053 #include "G4Gamma.hh"
0054 #include "G4Proton.hh"
0055 #include "G4SteppingManager.hh"
0056 #include "G4SystemOfUnits.hh"
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 SteppingAction::SteppingAction(DetectorConstruction* det) : G4UserSteppingAction(), 
0061 fpDetectorConstruction(det)
0062 {
0063   fpSteppingMessenger = new SteppingMessenger(this);
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 SteppingAction::~SteppingAction() 
0069 {
0070   delete fpSteppingMessenger;
0071 }
0072 
0073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0074 
0075 void SteppingAction::UserSteppingAction(const G4Step* step)
0076 {
0077   // Protection
0078   if (!step->GetPostStepPoint()) return;
0079   //
0080   
0081   // PreStep point
0082   
0083   G4StepPoint* preStep = step->GetPreStepPoint();
0084 
0085   const G4LogicalVolume* preVolume =
0086     preStep->GetPhysicalVolume()->GetLogicalVolume();
0087 
0088   // PostStep point
0089   
0090   G4StepPoint* postStep = step->GetPostStepPoint();
0091  
0092   // Protection
0093   if (postStep->GetStepStatus() == fWorldBoundary ) return;
0094   //
0095 
0096   const G4LogicalVolume* postVolume = 
0097     postStep->GetPhysicalVolume()->GetLogicalVolume();
0098 
0099   // METHOD 1: kill the particle and sec. if inside the scorer
0100  
0101    if ( postVolume == fpDetectorConstruction->GetLogicalScorer() &&
0102         preVolume  == fpDetectorConstruction->GetLogicalScorer() )
0103   {    
0104     if (fKill) step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
0105   }
0106 
0107   // Information is scored from preStep = WORLD to postStep = SCORER 
0108 
0109   if ( preStep->GetStepStatus() == fGeomBoundary )
0110   {    
0111     // G4cout << "---> One particle has crossed the boundary..." << G4endl;
0112 
0113     G4double PDGCode = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
0114   
0115     G4double x = preStep->GetPosition().x() / micrometer;
0116     G4double y = preStep->GetPosition().y() / micrometer;
0117     G4double z = preStep->GetPosition().z() / micrometer;
0118 
0119     G4ThreeVector direction = preStep->GetMomentumDirection();
0120     G4double xMom = direction.x();
0121     G4double yMom = direction.y();
0122     G4double zMom = direction.z();
0123   
0124     G4double energy = preStep->GetKineticEnergy() / keV;
0125 
0126     //
0127   
0128     G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0129 
0130     analysisManager->FillNtupleDColumn(0, PDGCode);
0131     analysisManager->FillNtupleDColumn(1, x);
0132     analysisManager->FillNtupleDColumn(2, y);
0133     analysisManager->FillNtupleDColumn(3, z);
0134     analysisManager->FillNtupleDColumn(4, xMom);
0135     analysisManager->FillNtupleDColumn(5, yMom);
0136     analysisManager->FillNtupleDColumn(6, zMom);
0137     analysisManager->FillNtupleDColumn(7, energy);
0138 
0139     //
0140     analysisManager->AddNtupleRow();
0141 
0142     // METHOD 2: kill the particle and sec. if entering
0143     // if (fKill) step->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
0144 
0145   } // End of scoring
0146 
0147 }