ATLAS Offline Software
GenParticlePositionFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // GenParticlePositionFilter.cxx, (c) ATLAS Detector software
8 
9 // class header include
11 
12 // HepMC includes
13 #include "AtlasHepMC/GenParticle.h"
14 #include "AtlasHepMC/GenVertex.h"
16 
19  const std::string& n,
20  const IInterface* p )
21  : base_class(t,n,p),
22  m_geoIDSvc("ISF_GeoIDSvc", n),
23  m_checkRegion()
24 {
25  // the GeoID indentification service
26  declareProperty("GeoIDService",
27  m_geoIDSvc,
28  "The GeoID Service");
29  declareProperty("CheckRegion",
31  "Check if the given particles are within the specified regions");
32 }
33 
34 
35 // Athena algtool's Hooks
37 {
38  ATH_MSG_VERBOSE("initialize()");
39 
40  // retrieve the GeoIDService
41  if ( m_geoIDSvc.retrieve().isFailure()){
42  ATH_MSG_ERROR( "Could not retrieve " << m_geoIDSvc << ". Abort.");
43  return StatusCode::FAILURE;
44  }
45 
46  ATH_MSG_VERBOSE("initialize() successful");
47  return StatusCode::SUCCESS;
48 }
49 
50 
52 #ifdef HEPMC3
54 {
55  // the GenParticle production vertex
56  auto vtx = particle->production_vertex();
57 #else
59 {
60  // the GenParticle production vertex
61  HepMC::GenVertexPtr vtx = particle.production_vertex();
62 #endif
63 
64  // no production vertex?
65  if (!vtx) {
66  ATH_MSG_DEBUG("GenParticle does not have a production vertex, filtering it out");
67  return false;
68  }
69 
70  // (x,y,z,t) position
71  HepMC::FourVector pos = vtx->position();
72 
73  bool inside = false;
74  // check if the particle position is inside (or on surface)
75  // of any of the given ISF Simulation GeoIDs
76  std::vector<int>::const_iterator checkRegionIt = m_checkRegion.begin();
77  std::vector<int>::const_iterator checkRegionItEnd = m_checkRegion.end();
78  for ( ; (checkRegionIt!=checkRegionItEnd) && (!inside); ++checkRegionIt) {
79  // consult the GeoID identification service
80  ISF::InsideType insideCheck = m_geoIDSvc->inside( pos.x(),
81  pos.y(),
82  pos.z(),
83  AtlasDetDescr::AtlasRegion(*checkRegionIt) );
84  // is inside only if ==fInside or ==fSurface
85  inside |= (insideCheck==ISF::fInside) || (insideCheck==ISF::fSurface);
86  }
87 
88 
89  // return whether pos was inside any of the simulation geometries
90  if (inside)
91  ATH_MSG_VERBOSE("GenParticle is inside AtlasVolume and passed the filter");
92  else
93  ATH_MSG_VERBOSE("GenParticle is outside AtlasVolume and got fitered out");
94  return inside;
95 }
96 
97 
99 {
100  ATH_MSG_VERBOSE("Finalizing ...");
101  return StatusCode::SUCCESS;
102 }
103 
HepMC::GenVertexPtr
HepMC::GenVertex * GenVertexPtr
Definition: GenVertex.h:59
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
AtlasDetDescr::AtlasRegion
AtlasRegion
Definition: AtlasRegion.h:27
GenVertex.h
ISF::InsideType
InsideType
Definition: IGeoIDSvc.h:22
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ISF::GenParticlePositionFilter::m_checkRegion
std::vector< int > m_checkRegion
Definition: GenParticlePositionFilter.h:56
GenParticle.h
ISF::GenParticlePositionFilter::initialize
StatusCode initialize()
Athena algtool's Hooks.
Definition: GenParticlePositionFilter.cxx:36
ISF::fSurface
@ fSurface
Definition: IGeoIDSvc.h:24
ISF::fInside
@ fInside
Definition: IGeoIDSvc.h:25
SimpleVector.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ISF::GenParticlePositionFilter::finalize
StatusCode finalize()
Definition: GenParticlePositionFilter.cxx:98
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ISF::GenParticlePositionFilter::GenParticlePositionFilter
GenParticlePositionFilter(const std::string &t, const std::string &n, const IInterface *p)
Constructor.
Definition: GenParticlePositionFilter.cxx:18
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::inside
@ inside
Definition: PropDirection.h:29
GenParticlePositionFilter.h
ISF::GenParticlePositionFilter::pass
bool pass(const HepMC::GenParticle &particle) const
does the given particle pass the filter?
Definition: GenParticlePositionFilter.cxx:58
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
ISF::GenParticlePositionFilter::m_geoIDSvc
ServiceHandle< IGeoIDSvc > m_geoIDSvc
Definition: GenParticlePositionFilter.h:55
GenParticle
@ GenParticle
Definition: TruthClasses.h:30