Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:50:27

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 #include "SteppingAction.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "G4RunManager.hh"
0033 #include "G4AnalysisManager.hh"
0034 #include "G4DNAElastic.hh"
0035 #include "G4DNAElectronSolvation.hh"
0036 #include "G4Event.hh"
0037 #include "G4EventManager.hh"
0038 #include "G4ITTrackHolder.hh"
0039 #include "G4Molecule.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4Track.hh"
0042 #include "globals.hh"
0043 
0044 #include <map>
0045 
0046 using MapOfDelayedLists = std::map<double, std::map<int, G4TrackList*>>;
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0049 
0050 SteppingAction::SteppingAction()
0051   : G4UserSteppingAction()
0052 {
0053   if (!fpDetector) {
0054     fpDetector = static_cast<const DetectorConstruction*>
0055                     (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0056   }
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0060 
0061 void SteppingAction::UserSteppingAction(const G4Step* step)
0062 {
0063   SetupFlags(step);
0064 
0065   if (fVolumeType == DNAVolumeType::physWorld) {
0066     step->GetTrack()->SetTrackStatus(fStopAndKill);
0067   }
0068 
0069   if (fVolumeType == DNAVolumeType::VoxelStraight) {
0070     return;
0071   }
0072 
0073   G4double dE = step->GetTotalEnergyDeposit() / eV;
0074   const G4VProcess* pProcess = step->GetPostStepPoint()->GetProcessDefinedStep();
0075 
0076   // get all processes except G4DNAElectronSolvation
0077   if ((0 > dE) || (nullptr != dynamic_cast<const G4DNAElectronSolvation*>(pProcess))) {
0078     return;
0079   }
0080 
0081   G4double x = step->GetPreStepPoint()->GetPosition().x() / nanometer;
0082   G4double y = step->GetPreStepPoint()->GetPosition().y() / nanometer;
0083   G4double z = step->GetPreStepPoint()->GetPosition().z() / nanometer;
0084 
0085   G4double copyNo = G4double(step->GetPreStepPoint()->GetTouchable()->GetVolume()->GetCopyNo());
0086 
0087   G4double eventId =
0088     G4double(G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID());
0089 
0090   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0091   analysisManager->FillNtupleDColumn(1, 0, x);
0092   analysisManager->FillNtupleDColumn(1, 1, y);
0093   analysisManager->FillNtupleDColumn(1, 2, z);
0094   analysisManager->FillNtupleDColumn(1, 3, dE);
0095   analysisManager->FillNtupleDColumn(
0096     1, 4,
0097     (step->GetPreStepPoint()->GetKineticEnergy() - step->GetPostStepPoint()->GetKineticEnergy())
0098       / eV);
0099   analysisManager->FillNtupleIColumn(1, 5, G4int(fVolumeType));
0100   analysisManager->FillNtupleDColumn(1, 6, copyNo);
0101   analysisManager->FillNtupleIColumn(1, 7, eventId);
0102   analysisManager->AddNtupleRow(1);
0103 
0104   MapOfDelayedLists delayList = G4ITTrackHolder::Instance()->GetDelayedLists();
0105   for (auto& delayedmap_it : delayList) {
0106     for (auto& trackList : delayedmap_it.second) {
0107       if (nullptr == trackList.second) {
0108         return;
0109       }
0110       G4TrackList::iterator itt = trackList.second->begin();
0111       G4TrackList::iterator endd = trackList.second->end();
0112       for (; itt != endd; ++itt) {
0113         G4Track* track = *itt;
0114         if (track->GetParentID() != step->GetTrack()->GetTrackID()
0115             || track->GetPosition() != step->GetPostStepPoint()->GetPosition())
0116         {
0117           return;
0118         }
0119 
0120         track->SetTrackStatus(fStopAndKill);
0121       }
0122     }
0123   }
0124 }
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0126 
0127 void SteppingAction::SetupFlags(const G4Step* step)
0128 {
0129   fVolumeType = SetupVolumeType(step->GetPreStepPoint()->GetPhysicalVolume());
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0133 
0134 DNAVolumeType SteppingAction::SetupVolumeType(const G4VPhysicalVolume* pPhyVolume)
0135 {
0136   auto it = (fpDetector->GetGeoDataMap()).find(pPhyVolume);
0137 
0138   if (it == (fpDetector->GetGeoDataMap()).end()) {
0139     G4ExceptionDescription exceptionDescription;
0140     exceptionDescription << pPhyVolume->GetName() << " is wrong physical volume";
0141     G4Exception("SteppingAction::SetupVolumeFlag()", "SteppingAction01", FatalException,
0142                 exceptionDescription);
0143   }
0144 
0145   return it->second;
0146 }
0147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....