ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonKiller.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "PhotonKiller.h"
6
7#include "G4Step.hh"
8#include "G4Event.hh"
9
10#include "G4Gamma.hh"
11#include "G4RunManagerKernel.hh"
12
13namespace G4UA
14{
15
16 //---------------------------------------------------------------------------
20
21 //---------------------------------------------------------------------------
23 {
24 // reset counters
25 m_count=0;
26 m_energy=0;
27 }
28
29 //---------------------------------------------------------------------------
30 void PhotonKiller::UserSteppingAction(const G4Step* aStep)
31 {
32 if ( fabs(m_energy-aStep->GetTrack()->GetKineticEnergy())<0.00001 ){
33 // same energy as last time
34 m_count++;
35 } else {
36 m_count=0;
37 m_energy = aStep->GetTrack()->GetKineticEnergy();
38 return;
39 }
40
41 if (aStep->GetTrack()->GetKineticEnergy() < 0.0001){ // Less than one hundred eV
42 if ( (m_count>3 && aStep->GetTrack()->GetDefinition() == G4Gamma::Gamma() ) ||
43 (m_count>10000) ){ // more than three steps with less than one keV of energy...
44 // Drop the photon
45 aStep->GetTrack()->SetTrackStatus( fStopAndKill );
46 }
47 } else if (m_count>1000000){
48 // Looper Killer functionality
49 aStep->GetTrack()->SetTrackStatus( fStopAndKill );
50 G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
51 rmk->GetEventManager()->AbortCurrentEvent();
52 rmk->GetEventManager()->GetNonconstCurrentEvent()->SetEventAborted();
53 }
54 }
55
56} // namespace G4UA
virtual void UserSteppingAction(const G4Step *) override final
virtual void PreUserTrackingAction(const G4Track *) override final