ATLAS Offline Software
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 
21 namespace G4UA
22 {
23 
24  //---------------------------------------------------------------------------
26  AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"FastIDKiller"),
27  m_config(config),
28  m_report(),
29  m_init(false)
30  {
31  }
32 
33  //---------------------------------------------------------------------------
34  void FastIDKiller::BeginOfRunAction(const G4Run*)
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  }
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
G4UA::FastIDKiller::KillParticle
void KillParticle(const G4Step *aStep)
Definition: FastIDKiller.cxx:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4UA::FastIDKiller::FastIDKiller
FastIDKiller(const Config &config)
Constructor.
Definition: FastIDKiller.cxx:25
G4UA::FastIDKiller::Report::killCount
int killCount
Definition: FastIDKiller.h:39
G4UA::FastIDKiller::Config
Configuration parameters.
Definition: FastIDKiller.h:26
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
G4UA::FastIDKiller::Config::isDalek
bool isDalek
Definition: FastIDKiller.h:30
G4UA::FastIDKiller::m_init
bool m_init
Definition: FastIDKiller.h:57
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
G4UA::FastIDKiller::Config::R
float R
Definition: FastIDKiller.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
G4UA::FastIDKiller::Config::energyCut
float energyCut
Definition: FastIDKiller.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FastIDKiller.h
G4UA::FastIDKiller::Config::Z
float Z
Definition: FastIDKiller.h:28
DEBUG
#define DEBUG
Definition: page_access.h:11
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
G4UA::FastIDKiller::m_report
Report m_report
Definition: FastIDKiller.h:56
G4UA::FastIDKiller::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: FastIDKiller.cxx:83
G4UA::FastIDKiller::m_config
Config m_config
Definition: FastIDKiller.h:55
fitman.rho
rho
Definition: fitman.py:532
G4UA::FastIDKiller::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: FastIDKiller.cxx:34