ATLAS Offline Software
Loading...
Searching...
No Matches
FastIDKiller.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 "FastIDKiller.h"
6
7#include <iostream>
8
9#include "G4MuonPlus.hh"
10#include "G4MuonMinus.hh"
11#include "G4Electron.hh"
12#include "G4Positron.hh"
13#include "G4Gamma.hh"
14#include "G4Step.hh"
15#include "G4TrackVector.hh"
16
17#include "GaudiKernel/Bootstrap.h"
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/IMessageSvc.h"
20
21namespace G4UA
22{
23
24 //---------------------------------------------------------------------------
26 AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"FastIDKiller"),
28 m_report(),
29 m_init(false)
30 {
31 }
32
33 //---------------------------------------------------------------------------
35 {
36 if (m_config.isDalek==false){
37 ATH_MSG_INFO( "Including the Fast Inner Detector Killer." << std::endl
38 << "\t This piece of code will kill all particles leaving the" << std::endl
39 << "\t inner detector region (which should be defined in your" << std::endl
40 << "\t job options) except those satisfying certain criteria." << std::endl
41 << "\t (e/gamma will not be killed above " << m_config.energyCut/1000. << " GeV)" );
42 }
43 else{
44 ATH_MSG_INFO( "Including Fast Inner Detector Killer as DALEK (Domain Actuated" << std::endl
45 << "\t Low Energy Killer). It will exterminate all particles with kin." << std::endl
46 << "\t energy below " << m_config.energyCut << " MeV leaving the inner detector" << std::endl
47 << "\t region (which should be defined in your job options)." );
48 }
49
50
51 //FIXME need a nice way of getting the maximum size of the ID envelope in R and Z.
52 // EnvelopeGeometryManager *gm=EnvelopeGeometryManager::GetGeometryManager();
53
54 // // if not set through jobOptions, get values from envelope manager
55 // if(m_config.R==0.)
56 // m_config.R = gm->IdetOuterRadius();
57 // if(m_config.Z==0.)
58 // m_config.Z = gm->IdetMaxZ();
59
60 ATH_MSG_INFO( "Fast ID Killer initialized with radius " << m_config.R << " and Z " << m_config.Z);
61
62 m_init=true;
63
64 }
65
66 //---------------------------------------------------------------------------
67 void FastIDKiller::KillParticle(const G4Step* aStep)
68 {
69 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
70 const G4TrackVector *tv = aStep->GetSecondary();
71 for (unsigned int i=0;i<tv->size();i++){
72 if ( (*tv)[i]->GetPosition().rho() < m_config.R &&
73 (*tv)[i]->GetPosition().z() < m_config.Z &&
74 (*tv)[i]->GetPosition().z() > -m_config.Z
75 ) continue;
76 (*tv)[i]->SetTrackStatus(fStopAndKill);
77 }
78 m_report.killCount++;
79 }
80
81
82 //---------------------------------------------------------------------------
83 void FastIDKiller::UserSteppingAction(const G4Step* aStep){
84
85 if (msgLvl(MSG::VERBOSE)){
86 ATH_MSG_DEBUG( " ===================================================== " );
87 ATH_MSG_DEBUG( " Writing out Information for debugging: " );
88 ATH_MSG_DEBUG( " Track-Pointer: " << aStep->GetTrack() );
89 ATH_MSG_DEBUG( " GetDefinition is in the next line " );
90 ATH_MSG_DEBUG( aStep->GetTrack()->GetDefinition() );
91 ATH_MSG_DEBUG( " still going on ? " );
92 ATH_MSG_DEBUG( " ===================================================== " );
93 }
94
95 // Outside DALEK mode: first ignore muons
96 if ( m_config.isDalek==false &&
97 ( G4MuonPlus::MuonPlusDefinition() == aStep->GetTrack()->GetDefinition() ||
98 G4MuonMinus::MuonMinusDefinition() == aStep->GetTrack()->GetDefinition() ) ) return;
99
100 // Now we check if the particle is outside the Z or R edges of the inner detector envelope
101 if (msgLvl(MSG::VERBOSE)){
102 ATH_MSG_VERBOSE( " Checking pointers ... " );
103
104 if ( !aStep->GetPostStepPoint() ||
105 !aStep->GetPreStepPoint() )
106 {
107 ATH_MSG_ERROR( " One of the pointers was null! This should never happen!!!" );
108 throw "Null position pointer";
109 }
110 }
111
112 if ( aStep->GetPreStepPoint()->GetPosition().rho() > m_config.R ||
113 aStep->GetPreStepPoint()->GetPosition().z() > m_config.Z ||
114 aStep->GetPreStepPoint()->GetPosition().z() < -m_config.Z
115 )
116 {
117 return; // We started outside the ID envelope
118 }
119
120 if ( aStep->GetPostStepPoint()->GetPosition().rho() < m_config.R &&
121 aStep->GetPostStepPoint()->GetPosition().z() < m_config.Z &&
122 aStep->GetPostStepPoint()->GetPosition().z() > -m_config.Z
123 )
124 {
125 return; // We finished inside the ID envelope
126 }
127
128 // Otherwise we have a non-muon that started inside and ended outside the ID envelope! KILL IT!
129
130 ATH_MSG_VERBOSE( " We have a " << aStep->GetTrack()->GetDefinition()->GetParticleName()
131 << " going from " << std::endl
132 << " ----> " << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()->GetName()
133 << " to "
134 << aStep->GetPostStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()->GetName()
135 << std::endl
136 << " with attributes: " << std::endl
137 << " Energy: " << aStep->GetTrack()->GetTotalEnergy()
138 << " Eta: " << aStep->GetTrack()->GetMomentum ().getEta()
139 << " Pt: " << aStep->GetTrack()->GetMomentum ().perp()
140 << " and at coordinates: " << std::endl
141 << " R: " << aStep->GetPostStepPoint()->GetPosition().rho()
142 << " Z: " << aStep->GetPostStepPoint()->GetPosition().z()
143 << " Phi: " << aStep->GetPostStepPoint()->GetPosition().phi() );
144
145 // Outside DALEK mode: ignore electrons above a certain energy
146 // at some point it might be interesting to see what effect this has on other particles (eg pi0)
147 if ( m_config.isDalek==false &&
148 ( G4Electron::ElectronDefinition() == aStep->GetTrack()->GetDefinition() ||
149 G4Positron::PositronDefinition() == aStep->GetTrack()->GetDefinition() ||
150 G4Gamma::GammaDefinition() == aStep->GetTrack()->GetDefinition() ) &&
151 m_config.energyCut < aStep->GetTrack()->GetTotalEnergy() ) return;
152
153 // In DALEK mode: kill particles below threshold regardless of particle type
154 if ( m_config.isDalek && m_config.energyCut < aStep->GetTrack()->GetKineticEnergy() ) return;
155
156 if (msgLvl(MSG::DEBUG)){
157 std::string name = aStep->GetTrack()->GetDefinition()->GetParticleName();
158 ATH_MSG_DEBUG( " -------> The particle passed. It is a " << name << " and will be killed ! " );
159 }
160
161 // Otherwise kill the particle now
162 KillParticle( aStep );
163 }
164
165} // namespace G4UA
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
bool msgLvl(const MSG::Level lvl) const
Test the output level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
FastIDKiller(const Config &config)
Constructor.
virtual void UserSteppingAction(const G4Step *) override
void KillParticle(const G4Step *aStep)
virtual void BeginOfRunAction(const G4Run *) override
=============================================================================
Configuration parameters.