ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
12namespace Analysis {
13
14 JetSecVtxFindingAlg::JetSecVtxFindingAlg(const std::string& name, ISvcLocator* pSvcLocator):
15 AthReentrantAlgorithm(name,pSvcLocator),
17 {
18 //List of the secondary vertex finders in jet to be run
20 }
21
23 {
24 // This will check that the properties were initialized properly
25 // by job configuration.
27
28 ATH_CHECK( m_JetCollectionName.initialize() );
29 ATH_CHECK( m_TracksToTag.initialize() );
30 ATH_CHECK( m_VertexCollectionName.initialize() );
31 ATH_CHECK( m_VxSecVertexInfoName.initialize() );
32
33 /* ----------------------------------------------------------------------------------- */
34 /* RETRIEVE SERVICES FROM STOREGATE */
35 /* ----------------------------------------------------------------------------------- */
36
37 if ( m_secVertexFinderToolHandle.retrieve().isFailure() ) {
38 ATH_MSG_ERROR("#BTAG# Failed to retrieve " << m_secVertexFinderToolHandle);
39 } else {
40 ATH_MSG_DEBUG("#BTAG# Retrieved " << m_secVertexFinderToolHandle);
41 }
42
43 return StatusCode::SUCCESS;
44 }
45
46
47 StatusCode JetSecVtxFindingAlg::execute(const EventContext& ctx) const {
48 //retrieve the Jet container
50 if (!h_JetCollectionName.isValid()) {
51 ATH_MSG_ERROR( " cannot retrieve jet container with key " << m_JetCollectionName.key() );
52 return StatusCode::FAILURE;
53 }
54
55 /* Record the VxSecVertexInfo output container */
57 ATH_CHECK( h_VxSecVertexInfoName.record(std::make_unique<Trk::VxSecVertexInfoContainer>()));
58
59 if (h_JetCollectionName->empty()) {
60 ATH_MSG_DEBUG("#BTAG# Empty Jet collection");
61 return StatusCode::SUCCESS;
62 }
63
65 h_TracksToTag (m_TracksToTag, ctx);
66
67 if (!h_TracksToTag.isAvailable()) {
68 ATH_MSG_ERROR( "cannot retrieve jet container particle EL decoration with key " << h_TracksToTag.decorKey() );
69 return StatusCode::FAILURE;
70 }
71
72 const xAOD::Vertex* primaryVertex(nullptr);
73
74 //retrieve primary vertex
76 if (!h_VertexCollectionName.isValid()) {
77 ATH_MSG_ERROR( " cannot retrieve primary vertex container with key " << m_VertexCollectionName.key() );
78 return StatusCode::FAILURE;
79 }
80 unsigned int nVertexes = h_VertexCollectionName->size();
81 if (nVertexes == 0) {
82 ATH_MSG_DEBUG("#BTAG# Vertex container is empty");
83 return StatusCode::SUCCESS;
84 }
85 for (const auto *fz : *h_VertexCollectionName) {
86 if (fz->vertexType() == xAOD::VxType::PriVtx) {
87 primaryVertex = fz;
88 break;
89 }
90 }
91
92
93 if (! primaryVertex) {
94 ATH_MSG_DEBUG("#BTAG# No vertex labeled as VxType::PriVtx!");
95 xAOD::VertexContainer::const_iterator fz = h_VertexCollectionName->begin();
96 primaryVertex = *fz;
97 if (primaryVertex->nTrackParticles() == 0) {
98 ATH_MSG_DEBUG("#BTAG# PV==BeamSpot: probably poor tagging");
99 }
100 }
101
102 const xAOD::Vertex& PrimaryVtx = *primaryVertex;
103
104 const xAOD::IParticleContainer* trackContainer = nullptr;
105 for (const auto *jetIter : *h_JetCollectionName) {
106 const xAOD::Jet& jetToTag = *jetIter;
107
108 const std::vector<ElementLink< xAOD::IParticleContainer > >& tracksInJet
109 = h_TracksToTag(jetToTag);
110
111 if(tracksInJet.empty()){
112 ATH_MSG_DEBUG("#BTAG# No track in Jet");
113 h_VxSecVertexInfoName->push_back(nullptr);
114 continue;
115 }
116
117 if (!trackContainer) {
118 trackContainer = tracksInJet.front().getDataPtr();
119 }
120
121 std::vector<const xAOD::IParticle*> inputIParticles;
122
123
124 inputIParticles.reserve(tracksInJet.size());
125 for (const auto& iparticle : tracksInJet)
127 inputIParticles.push_back(*iparticle);
128
129 ATH_MSG_DEBUG("#BTAG# Running " << m_secVertexFinderToolHandle);
130
131 Trk::VxSecVertexInfo* myVertexInfo = m_secVertexFinderToolHandle->findSecVertex(PrimaryVtx, jetIter->p4(), inputIParticles);
132 ATH_MSG_DEBUG("#BTAG# Number of vertices found: " << myVertexInfo->vertices().size());
133 h_VxSecVertexInfoName->push_back(myVertexInfo);
134 }// for loop on jets
135
136 // If we haven't done so yet, collect the IDs of the decorations
137 // that we produce.
138 if (!m_decorIDs.isValid()) {
139 std::vector<std::string> decorationNames =
140 m_secVertexFinderToolHandle->trackDecorationNames();
141 std::vector<SG::auxid_t> decorIDs;
142 decorIDs.reserve (decorationNames.size());
143 const auto& r = SG::AuxTypeRegistry::instance();
144 for (const std::string& s : decorationNames) {
145 SG::auxid_t id = r.findAuxID (s);
146 if (id != SG::null_auxid) {
147 decorIDs.push_back (id);
148 }
149 }
150 m_decorIDs.set (std::move (decorIDs));
151 }
152
153 // Explicitly lock the decorations.
154 if (trackContainer) {
155 // Ok --- we just made these decorations; no one else should be accessing
156 // them yet.
157 xAOD::IParticleContainer* trackContainer_nc ATLAS_THREAD_SAFE = const_cast<xAOD::IParticleContainer*>(trackContainer);
158 for (SG::auxid_t id : *m_decorIDs.ptr()) {
159 trackContainer_nc->lockDecoration (id);
160 }
161 }
162
163 return StatusCode::SUCCESS;
164 }
165
166} // namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle mappings between names and auxid_t.
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
ToolHandle< InDet::ISecVertexInJetFinder > m_secVertexFinderToolHandle
SG::ReadDecorHandleKey< xAOD::JetContainer > m_TracksToTag
virtual StatusCode execute(const EventContext &ctx) const override final
JetSecVtxFindingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructors and destructors.
SG::ReadHandleKey< xAOD::VertexContainer > m_VertexCollectionName
CxxUtils::CachedValue< std::vector< SG::auxid_t > > m_decorIDs
List of the track decorations that we produce.
SG::ReadHandleKey< xAOD::JetContainer > m_JetCollectionName
SG::WriteHandleKey< Trk::VxSecVertexInfoContainer > m_VxSecVertexInfoName
virtual StatusCode initialize() override final
Main routines specific to an ATHENA algorithm.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Handle class for reading a decoration on an object.
const std::string & decorKey() const
Return the name of the decoration alias (CONT.DECOR).
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
const std::vector< xAOD::Vertex * > & vertices() const
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
int r
Definition globals.cxx:22
The namespace of all packages in PhysicsAnalysis/JetTagging.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.