ATLAS Offline Software
JetSecVtxFindingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "StoreGate/ReadHandle.h"
9 
10 namespace Analysis {
11 
12  JetSecVtxFindingAlg::JetSecVtxFindingAlg(const std::string& name, ISvcLocator* pSvcLocator):
13  AthReentrantAlgorithm(name,pSvcLocator),
14  m_secVertexFinderToolHandle(this)
15  {
16  //List of the secondary vertex finders in jet to be run
18  }
19 
21  {
22  // This will check that the properties were initialized properly
23  // by job configuration.
24  m_TracksToTag = m_JetCollectionName.key() + "." + m_TracksToTag.key();
25 
26  ATH_CHECK( m_JetCollectionName.initialize() );
27  ATH_CHECK( m_TracksToTag.initialize() );
28  ATH_CHECK( m_VertexCollectionName.initialize() );
29  ATH_CHECK( m_VxSecVertexInfoName.initialize() );
30 
31  /* ----------------------------------------------------------------------------------- */
32  /* RETRIEVE SERVICES FROM STOREGATE */
33  /* ----------------------------------------------------------------------------------- */
34 
35  if ( m_secVertexFinderToolHandle.retrieve().isFailure() ) {
36  ATH_MSG_ERROR("#BTAG# Failed to retrieve " << m_secVertexFinderToolHandle);
37  } else {
38  ATH_MSG_DEBUG("#BTAG# Retrieved " << m_secVertexFinderToolHandle);
39  }
40 
41  return StatusCode::SUCCESS;
42  }
43 
44 
45  StatusCode JetSecVtxFindingAlg::execute(const EventContext& ctx) const {
46  //retrieve the Jet container
48  if (!h_JetCollectionName.isValid()) {
49  ATH_MSG_ERROR( " cannot retrieve jet container with key " << m_JetCollectionName.key() );
50  return StatusCode::FAILURE;
51  }
52 
53  /* Record the VxSecVertexInfo output container */
55  ATH_CHECK( h_VxSecVertexInfoName.record(std::make_unique<Trk::VxSecVertexInfoContainer>()));
56 
57  if (h_JetCollectionName->empty()) {
58  ATH_MSG_DEBUG("#BTAG# Empty Jet collection");
59  return StatusCode::SUCCESS;
60  }
61 
63  h_TracksToTag (m_TracksToTag, ctx);
64 
65  if (!h_TracksToTag.isAvailable()) {
66  ATH_MSG_ERROR( "cannot retrieve jet container particle EL decoration with key " << h_TracksToTag.decorKey() );
67  return StatusCode::FAILURE;
68  }
69 
70  const xAOD::Vertex* primaryVertex(nullptr);
71 
72  //retrieve primary vertex
74  if (!h_VertexCollectionName.isValid()) {
75  ATH_MSG_ERROR( " cannot retrieve primary vertex container with key " << m_VertexCollectionName.key() );
76  return StatusCode::FAILURE;
77  }
78  unsigned int nVertexes = h_VertexCollectionName->size();
79  if (nVertexes == 0) {
80  ATH_MSG_DEBUG("#BTAG# Vertex container is empty");
81  return StatusCode::SUCCESS;
82  }
83  for (const auto *fz : *h_VertexCollectionName) {
84  if (fz->vertexType() == xAOD::VxType::PriVtx) {
85  primaryVertex = fz;
86  break;
87  }
88  }
89 
90 
91  if (! primaryVertex) {
92  ATH_MSG_DEBUG("#BTAG# No vertex labeled as VxType::PriVtx!");
93  xAOD::VertexContainer::const_iterator fz = h_VertexCollectionName->begin();
94  primaryVertex = *fz;
95  if (primaryVertex->nTrackParticles() == 0) {
96  ATH_MSG_DEBUG("#BTAG# PV==BeamSpot: probably poor tagging");
97  }
98  }
99 
100  const xAOD::Vertex& PrimaryVtx = *primaryVertex;
101 
102  for (const auto *jetIter : *h_JetCollectionName) {
103  const xAOD::Jet& jetToTag = *jetIter;
104 
105  const std::vector<ElementLink< xAOD::IParticleContainer > >& tracksInJet
106  = h_TracksToTag(jetToTag);
107 
108  if(tracksInJet.empty()){
109  ATH_MSG_DEBUG("#BTAG# No track in Jet");
110  h_VxSecVertexInfoName->push_back(nullptr);
111  continue;
112  }
113 
114  std::vector<const xAOD::IParticle*> inputIParticles;
115 
116 
117  inputIParticles.reserve(tracksInJet.size());
118  for (const auto& iparticle : tracksInJet)
120  inputIParticles.push_back(*iparticle);
121 
122  ATH_MSG_DEBUG("#BTAG# Running " << m_secVertexFinderToolHandle);
123 
124  Trk::VxSecVertexInfo* myVertexInfo = m_secVertexFinderToolHandle->findSecVertex(PrimaryVtx, jetIter->p4(), inputIParticles);
125  ATH_MSG_DEBUG("#BTAG# Number of vertices found: " << myVertexInfo->vertices().size());
126  h_VxSecVertexInfoName->push_back(myVertexInfo);
127  }// for loop on jets
128 
129  return StatusCode::SUCCESS;
130  }
131 
132 } // namespace
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Analysis::JetSecVtxFindingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: JetSecVtxFindingAlg.cxx:45
Trk::VxSecVertexInfo::vertices
const std::vector< xAOD::Vertex * > & vertices() const
Definition: VxSecVertexInfo.cxx:100
Analysis::JetSecVtxFindingAlg::m_secVertexFinderToolHandle
ToolHandle< InDet::ISecVertexInJetFinder > m_secVertexFinderToolHandle
Definition: JetSecVtxFindingAlg.h:40
Analysis::JetSecVtxFindingAlg::m_VxSecVertexInfoName
SG::WriteHandleKey< Trk::VxSecVertexInfoContainer > m_VxSecVertexInfoName
Definition: JetSecVtxFindingAlg.h:45
Analysis::JetSecVtxFindingAlg::m_JetCollectionName
SG::ReadHandleKey< xAOD::JetContainer > m_JetCollectionName
Definition: JetSecVtxFindingAlg.h:42
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
JetSecVtxFindingAlg.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
Analysis::JetSecVtxFindingAlg::initialize
virtual StatusCode initialize() override final
Main routines specific to an ATHENA algorithm.
Definition: JetSecVtxFindingAlg.cxx:20
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Analysis::JetSecVtxFindingAlg::m_VertexCollectionName
SG::ReadHandleKey< xAOD::VertexContainer > m_VertexCollectionName
Definition: JetSecVtxFindingAlg.h:44
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Trk::VxSecVertexInfo
Definition: VxSecVertexInfo.h:63
Analysis::JetSecVtxFindingAlg::JetSecVtxFindingAlg
JetSecVtxFindingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructors and destructors.
Definition: JetSecVtxFindingAlg.cxx:12
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Analysis::JetSecVtxFindingAlg::m_TracksToTag
SG::ReadDecorHandleKey< xAOD::JetContainer > m_TracksToTag
Definition: JetSecVtxFindingAlg.h:43
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::ReadDecorHandle::decorKey
std::string decorKey() const
Return the name of the decoration alias (CONT.DECOR).
ReadDecorHandle.h
Handle class for reading a decoration on an object.
ReadHandle.h
Handle class for reading from StoreGate.
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.