// M Hentz, 2016 #include "DetectorConstruction.hh" #include "SteppingAction.hh" #include "SteppingActionMessenger.hh" #include "RunAction.hh" #include "G4Step.hh" #include "G4StepPoint.hh" #include "G4VisExtent.hh" #include "G4EventManager.hh" #include "Randomize.hh" SteppingAction::SteppingAction( DetectorConstruction* det, RunAction* runAction ) :G4UserSteppingAction(), fDetector(det), fRunAction(runAction), fSteppingActionMessenger(0), fKillPosition( 1800*CLHEP::mm ) { fSteppingActionMessenger = new SteppingActionMessenger( this ); } SteppingAction::~SteppingAction() {;} void SteppingAction::UserSteppingAction( const G4Step* step ) { G4double edep = step->GetTotalEnergyDeposit(); if (edep <= 0.) return; fRunAction->FillEdep( edep ); G4StepPoint* prePoint = step->GetPreStepPoint(); G4String prePointVol = prePoint->GetTouchableHandle()->GetVolume()->GetName(); // Shift z coordinate to be relative to source rather than origin G4double zposRel = prePoint->GetPosition().z() / CLHEP::mm; G4double zShift = 4200.*CLHEP::mm; // distance from centre of room to source in mm G4double zposPre = zposRel + zShift; // Kill particle if it has travelled beyond fKillPosition if( zposPre > fKillPosition ){ step->GetTrack()->SetTrackStatus( fStopAndKill ); } // Fill layers of the detector if ( prePointVol == "Layer" ) { G4int layerNb = prePoint->GetTouchableHandle()->GetCopyNumber(); fRunAction->FillLayerEdep( layerNb, edep ); } }