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"
11 
12 namespace Analysis {
13 
14  JetSecVtxFindingAlg::JetSecVtxFindingAlg(const std::string& name, ISvcLocator* pSvcLocator):
15  AthReentrantAlgorithm(name,pSvcLocator),
16  m_secVertexFinderToolHandle(this)
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 
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.
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
beamspotman.r
def r
Definition: beamspotman.py:672
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
xAOD::Vertex_v1::nTrackParticles
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
Definition: Vertex_v1.cxx:270
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
Analysis::JetSecVtxFindingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: JetSecVtxFindingAlg.cxx:47
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
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:41
Analysis::JetSecVtxFindingAlg::m_VxSecVertexInfoName
SG::WriteHandleKey< Trk::VxSecVertexInfoContainer > m_VxSecVertexInfoName
Definition: JetSecVtxFindingAlg.h:46
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Analysis::JetSecVtxFindingAlg::m_JetCollectionName
SG::ReadHandleKey< xAOD::JetContainer > m_JetCollectionName
Definition: JetSecVtxFindingAlg.h:43
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
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
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
SG::ReadDecorHandle::decorKey
const std::string & decorKey() const
Return the name of the decoration alias (CONT.DECOR).
Analysis::JetSecVtxFindingAlg::initialize
virtual StatusCode initialize() override final
Main routines specific to an ATHENA algorithm.
Definition: JetSecVtxFindingAlg.cxx:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.TrackLeptonConfig.trackContainer
string trackContainer
Definition: TrackLeptonConfig.py:23
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
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:45
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
Analysis::JetSecVtxFindingAlg::JetSecVtxFindingAlg
JetSecVtxFindingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructors and destructors.
Definition: JetSecVtxFindingAlg.cxx:14
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
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:44
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Analysis::JetSecVtxFindingAlg::m_decorIDs
CxxUtils::CachedValue< std::vector< SG::auxid_t > > m_decorIDs
List of the track decorations that we produce.
Definition: JetSecVtxFindingAlg.h:50
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
ReadDecorHandle.h
Handle class for reading a decoration on an object.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
ReadHandle.h
Handle class for reading from StoreGate.
checker_macros.h
Define macros for attributes used to control the static checker.
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.