ATLAS Offline Software
VertexRoiSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
12 
14 #include "GaudiKernel/ISvcLocator.h"
15 #include "GaudiKernel/Service.h"
16 
18 #include "VertexRoiSelectionTool.h"
20 #include "TrackParametersHelper.h" // includes VertexParametersHelper.h
21 
23 #include <algorithm> // for std::find
24 
25 
30  const std::string& name ) :
31  asg::AsgTool( name ) { }
32 
33 
38 
40 
41  ATH_MSG_DEBUG( "Initializing " << name() );
42 
43  ATH_CHECK( m_triggerVertexContainerName.initialize(
44  not m_triggerVertexContainerName.key().empty() ) );
45 
46  ATH_CHECK( m_trigDecTool.retrieve() );
47 
48  return StatusCode::SUCCESS;
49 }
50 
51 
55 template< class V >
57  const V& v, const TrigRoiDescriptor* r ) const
58 {
59  if( r==0 ) {
60  ATH_MSG_ERROR( "Called with null RoiDescriptor" );
61  return true;
62  }
63 
64  if( r->composite() ) {
65  for( unsigned i=r->size() ; i-- ; )
66  if( accept( v, (const TrigRoiDescriptor*)r->at(i) ) ) {
67  return true;
68  }
69 
70  } else {
71  if( r->isFullscan() ) return true;
72 
73  bool contained_zed = posZ(v) >= r->zedMinus() and
74  posZ(v) <= r->zedPlus();
75 
76  if( contained_zed ) return true;
77  }
78 
79  return false;
80 }
81 
84  const xAOD::Vertex& v, const TrigRoiDescriptor* r ) const;
85 
88  const xAOD::TruthVertex& v, const TrigRoiDescriptor* r ) const;
89 
90 
94 template< class V >
96  const std::vector< const V* >& vvec,
97  const TrigRoiDescriptor* r ) const {
98 
99  std::vector< const V* > selectedVertices;
100 
101  for( const V* thisVertex : vvec ) {
102  if( accept<V>( *thisVertex, r ) ) {
103  selectedVertices.push_back( thisVertex );
104  }
105  }
106 
107  return selectedVertices;
108 }
109 
111 template std::vector< const xAOD::Vertex* >
112 IDTPM:: VertexRoiSelectionTool::getVertices< xAOD::Vertex >(
113  const std::vector< const xAOD::Vertex* >& vvec,
114  const TrigRoiDescriptor* r ) const;
115 
117 template std::vector< const xAOD::TruthVertex* >
119  const std::vector< const xAOD::TruthVertex* >& vvec,
120  const TrigRoiDescriptor* r ) const;
121 
122 
126 std::vector< const xAOD::Vertex* >
128  const std::vector< const xAOD::Vertex* >& vvec,
129  const ElementLink< TrigRoiDescriptorCollection >& roiLink ) const
130 {
132  SG::ReadHandle< xAOD::VertexContainer > handle( m_triggerVertexContainerName );
133 
136  xAOD::VertexContainer::const_iterator > trigVtxItrPair =
137  m_trigDecTool->associateToEventView( handle, roiLink );
138 
140  std::vector< const xAOD::Vertex* > selectedTrigVertices;
142  for( vtxItr = trigVtxItrPair.first ; vtxItr != trigVtxItrPair.second ; ++vtxItr ) {
145  if( std::find( vvec.begin(), vvec.end(), *vtxItr ) == vvec.end() ) {
146  ATH_MSG_DEBUG( "Trigger vertex does not pass quality selection. Skipping." );
147  continue;
148  }
149  selectedTrigVertices.push_back( *vtxItr );
150  }
151 
152  return selectedTrigVertices;
153 }
154 
155 
160  TrackAnalysisCollections& trkAnaColls,
162 
163  ATH_MSG_DEBUG( "Selecting vertices in RoI" );
164 
166  ISvcLocator* svcLoc = Gaudi::svcLocator();
167  SmartIF< ITrackAnalysisDefinitionSvc > trkAnaDefSvc(
168  svcLoc->service( "TrkAnaDefSvc"+trkAnaColls.anaTag() ) );
169  ATH_CHECK( trkAnaDefSvc.isValid() );
170 
171  const TrigRoiDescriptor* const* roi = roiLink.cptr();
172 
175  if( not m_triggerVertexContainerName.key().empty() ) {
176  ATH_CHECK( trkAnaColls.fillTrigVertexVec(
177  getTrigVertices(
179  roiLink ),
181  }
182 
184  if( trkAnaDefSvc->useOffline() ) {
185  ATH_CHECK( trkAnaColls.fillOfflVertexVec(
186  getVertices(
188  *roi ),
190  }
191 
193  if( trkAnaDefSvc->useTruth() ) {
194  ATH_CHECK( trkAnaColls.fillTruthVertexVec(
195  getVertices(
197  *roi ),
199  }
200 
202  ATH_MSG_DEBUG( "Vertices after RoI selection: " <<
204 
205  return StatusCode::SUCCESS;
206 }
getVertices< xAOD::TruthVertex >
template std::vector< const xAOD::TruthVertex * > IDTPM::VertexRoiSelectionTool::getVertices< xAOD::TruthVertex >(const std::vector< const xAOD::TruthVertex * > &vvec, const TrigRoiDescriptor *r) const
getVertices method for truth vertices
IDTPM::VertexRoiSelectionTool::getVertices
std::vector< const V * > getVertices(const std::vector< const V * > &vvec, const TrigRoiDescriptor *r) const
vertex getter function (for offline tracks or truth particles)
Definition: VertexRoiSelectionTool.cxx:95
beamspotman.r
def r
Definition: beamspotman.py:676
VertexRoiSelectionTool.h
Tool to select reco and truth vertices in given RoI.
IDTPM::VertexRoiSelectionTool::selectVerticesInRoI
StatusCode selectVerticesInRoI(TrackAnalysisCollections &trkAnaColls, const ElementLink< TrigRoiDescriptorCollection > &roiLink)
Main Vertex selection method.
Definition: VertexRoiSelectionTool.cxx:159
IDTPM::TrackAnalysisCollections::printVertexInfo
std::string printVertexInfo(Stage stage=FULL) const
print information about vertices in the collection(s)
Definition: TrackAnalysisCollections.cxx:1089
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:46
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
DataVector::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition: DataVector.h:837
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
IDTPM::VertexRoiSelectionTool::accept
bool accept(const V &v, const TrigRoiDescriptor *r) const
geometric RoI filters - for non-trigger veritices (e.g. offline, truth, etc.)
Definition: VertexRoiSelectionTool.cxx:56
asg
Definition: DataHandleTestTool.h:28
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
IDTPM::TrackAnalysisCollections::fillTruthVertexVec
StatusCode fillTruthVertexVec(const std::vector< const xAOD::TruthVertex * > &vec, Stage stage=FULL)
fill truth/offline/trigger vertex vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.cxx:553
python.PyParticleTools.getVertices
def getVertices(aKey)
Definition: PyParticleTools.py:205
TrackAnalysisCollections.h
Class to hold for each event collections needed in the TrkAnalsis.
IDTPM::TrackAnalysisCollections::fillTrigVertexVec
StatusCode fillTrigVertexVec(const std::vector< const xAOD::Vertex * > &vec, Stage stage=FULL)
Trigger tracks.
Definition: TrackAnalysisCollections.cxx:587
TrackParametersHelper.h
Utility methods to access track/truth particles parmeters in a consitent way in this package.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
IDTPM::VertexRoiSelectionTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: VertexRoiSelectionTool.cxx:37
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
IDTPM::TrackAnalysisCollections::FS
@ FS
Definition: TrackAnalysisCollections.h:54
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::posZ
float posZ(const V &v)
Accessor utility function for getting the value of vertex position z.
Definition: VertexParametersHelper.h:37
IDTPM::TrackAnalysisCollections::truthVertexVec
const std::vector< const xAOD::TruthVertex * > & truthVertexVec(Stage stage=FULL)
get truth/offline/trigger vertex vector (TEST or REFERENCE)
Definition: TrackAnalysisCollections.h:249
IDTPM::TrackAnalysisCollections::trigVertexVec
const std::vector< const xAOD::Vertex * > & trigVertexVec(Stage stage=FULL)
Definition: TrackAnalysisCollections.h:253
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IDTPM::TrackAnalysisCollections::offlVertexVec
const std::vector< const xAOD::Vertex * > & offlVertexVec(Stage stage=FULL)
Definition: TrackAnalysisCollections.h:251
python.PyAthena.v
v
Definition: PyAthena.py:154
IDTPM::VertexRoiSelectionTool::getTrigVertices
std::vector< const xAOD::Vertex * > getTrigVertices(const std::vector< const xAOD::Vertex * > &vvec, const ElementLink< TrigRoiDescriptorCollection > &roiLink) const
TrigDecTool- and EventView-based getter function for trigger vertices.
Definition: VertexRoiSelectionTool.cxx:127
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:54
TrigRoiDescriptor.h
IDTPM::VertexRoiSelectionTool::VertexRoiSelectionTool
VertexRoiSelectionTool(const std::string &name)
Constructor.
Definition: VertexRoiSelectionTool.cxx:29
IDTPM::TrackAnalysisCollections::anaTag
const std::string & anaTag()
— Getter methods —
Definition: TrackAnalysisCollections.h:181
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: AsgTool.h:133
IDTPM::TrackAnalysisCollections::fillOfflVertexVec
StatusCode fillOfflVertexVec(const std::vector< const xAOD::Vertex * > &vec, Stage stage=FULL)
Offline tracks.
Definition: TrackAnalysisCollections.cxx:570