ATLAS Offline Software
egammaTrackThinner.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 NAME: egammaTrackThinner.cxx
7 PACKAGE: offline/Reconstruction/egammaRec
8 ********************************************************************/
9 
10 // INCLUDE HEADER FILES:
11 
12 #include "egammaTrackThinner.h"
13 
19 
20 #include "StoreGate/ReadHandle.h"
22 
23 // END OF HEADER FILES INCLUDE
24 
26 
27 
28 // INITIALIZE METHOD:
29 
31 {
32 
33  // initialize data handles
36  bool includeFwdEl =
41 
42  return StatusCode::SUCCESS;
43 }
44 
45 // FINALIZE METHOD:
46 
48  return StatusCode::SUCCESS;
49 }
50 
52 // ATHENA EXECUTE METHOD:
53 
54 StatusCode egammaTrackThinner::execute (const EventContext& ctx) const {
55 
56  ATH_MSG_DEBUG("Executing egammaTrackThinner");
57  if(!m_doThinning){
58  ATH_MSG_DEBUG("Thinning not requested do nothing");
59  return StatusCode::SUCCESS;
60  }
61 
62  /*
63  * GSF Track Particles
64  * The vector that we'll use to filter the track particles:
65  */
66  std::vector<bool> keptTrackParticles;
68  // check is only used for serial running; remove when MT scheduler used
69  ATH_CHECK(trackPC.isValid());
70  ATH_MSG_DEBUG("Number of TrackParticles "<< trackPC->size());
71  keptTrackParticles.resize( trackPC->size(), false );
72 
73  /*
74  * GSF Vertices
75  * The vector that we'll use to filter the GSF vertices:
76  */
77  std::vector<bool> keptVertices;
79  // check is only used for serial running; remove when MT scheduler used
80  ATH_CHECK(vertices.isValid());
81  ATH_MSG_DEBUG("Number of Vertices "<< vertices->size());
82  keptVertices.resize( vertices->size(), false );
83 
84  /*
85  * In Det Track Particles
86  * TRT standalone tracks are now centrally thinned by ThinTRTStandaloneTrackAlg for e/gamma and taus
87  */
88 
89  /*
90  * Electron track particle Thinning
91  */
93  // check is only used for serial running; remove when MT scheduler used
94  ATH_CHECK(electrons.isValid());
95 
96  //Loop over electrons
97  auto el_itr = electrons->begin();
98  auto el_end = electrons->end();
99  for( ; el_itr != el_end; ++el_itr ) {
100 
101  auto trackParticleLinks = (*el_itr)->trackParticleLinks();
102  for (const auto& link : trackParticleLinks){
103  if( ! link.isValid() ){
104  continue;
105  }
106  ATH_MSG_DEBUG("Electrons : Keeping GSF Track Particle with index : "<< link.index() );
107  keptTrackParticles[link.index() ] = true;
108  }
109  }
110 
111  /*
112  * Photon Vertex and track particle Thinning
113  */
115  // check is only used for serial running; remove when MT scheduler used
116  ATH_CHECK(photons.isValid());
117 
118  //Loop over photons
119  auto ph_itr = photons->begin();
120  auto ph_end = photons->end();
121  for( ; ph_itr != ph_end; ++ph_itr ) {
122 
123  auto vertexLinks= (*ph_itr) ->vertexLinks();
124  for ( const auto& vxlink : vertexLinks){
125  if( ! vxlink.isValid() ){
126  continue;
127  }
128  ATH_MSG_DEBUG("Photons : Keeping GSF Vertex with index : "<< vxlink.index() );
129  keptVertices[vxlink.index()]=true;
130  const xAOD::Vertex* vx = *(vxlink);
131  if(!vx){
132  continue;
133  }
134 
136  for ( const auto& link : trackParticleLinks){
137  if( ! link.isValid() ){
138  continue;
139  }
140  ATH_MSG_DEBUG("Photons : Keeping GSF Track Particle with index : "<< link.index() );
141  keptTrackParticles[link.index() ] = true;
142  }
143  }
144  }
145 
148  fwdelectrons(m_InputForwardElectronContainerKey, ctx);
149  // check is only used for serial running; remove when MT scheduler used
150  ATH_CHECK(fwdelectrons.isValid());
151 
152  //Loop over forward electrons
153  for (const auto *el : *fwdelectrons) {
154 
155  auto trackParticleLinks = el->trackParticleLinks();
156  for (const auto& link : trackParticleLinks){
157  if (!link.isValid()) {
158  continue;
159  }
160  ATH_MSG_DEBUG("ForwardElectrons : "
161  "Keeping GSF Track Particle with index : "
162  << link.index());
163  keptTrackParticles[link.index()] = true;
164  }
165  }
166  }
167 
168  //Do the Thinning
169  ATH_MSG_DEBUG("Do the Thinning");
170  trackPC.keep (keptTrackParticles);
171  vertices.keep (keptVertices);
172  ATH_MSG_DEBUG("completed successfully");
173 
174  //Return Gracefully
175  return StatusCode::SUCCESS;
176 }
177 
egammaTrackThinner::m_streamName
StringProperty m_streamName
Name of the stream being thinned.
Definition: egammaTrackThinner.h:75
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
egammaTrackThinner::finalize
StatusCode finalize() override final
finalize method
Definition: egammaTrackThinner.cxx:47
egammaTrackThinner::m_VertexKey
SG::ThinningHandleKey< xAOD::VertexContainer > m_VertexKey
GSF vertex container to thin.
Definition: egammaTrackThinner.h:68
egammaTrackThinner.h
egammaTrackThinner::m_InputPhotonContainerKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_InputPhotonContainerKey
photon collection input name
Definition: egammaTrackThinner.h:49
egammaTrackThinner::execute
StatusCode execute(const EventContext &ctx) const override final
execute method
Definition: egammaTrackThinner.cxx:54
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:68
EgammaxAODHelpers.h
egammaTrackThinner::m_doThinning
Gaudi::Property< bool > m_doThinning
Bool to decide if we actually do the Thinning.
Definition: egammaTrackThinner.h:78
ElectronContainer.h
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
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAOD::TauHelpers::trackParticleLinks
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
Definition: TauxAODHelpers.cxx:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
egammaTrackThinner::m_InputForwardElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_InputForwardElectronContainerKey
forward electron collection input name
Definition: egammaTrackThinner.h:56
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
egammaTrackThinner::m_InputElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_InputElectronContainerKey
electron collection input name
Definition: egammaTrackThinner.h:43
ReadHandle.h
Handle class for reading from StoreGate.
PhotonContainer.h
TrackParticleContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
egammaTrackThinner::m_TrackParticlesKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_TrackParticlesKey
GSF Track Particle container to thin.
Definition: egammaTrackThinner.h:62
egammaTrackThinner::initialize
StatusCode initialize() override final
initialize method
Definition: egammaTrackThinner.cxx:30