Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
InDetUsedInFitTrackDecoratorTool.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 // Local include(s):
7 
8 // FrameWork include(s):
9 #include "AthLinks/ElementLink.h"
13 
14 // STL include(s):
15 #include <algorithm>
16 #include <numeric>
17 #include <utility>
18 #include <vector>
19 
20 // Constructor
22  asg::AsgTool(name)
23 { }
24 
25 // Destructor
27 = default;
28 
29 // Initialize
31 {
32  // Print configuration
33  ATH_MSG_DEBUG("Initializing " << name() << "...");
34  ATH_MSG_DEBUG("Using AMVFVerticesDecoName: " << m_vtxDecoName);
35  ATH_MSG_DEBUG("Using AMVFWeightsDecoName: " << m_wgtDecoName);
36  ATH_MSG_DEBUG("Using TrackContainer: " << m_trkContKey);
37  ATH_MSG_DEBUG("Using VertexContainer: " << m_vtxContKey);
38 
39  // Instantiate and initialize our container reads
40  // For tracks:
42  // For vertices:
43  ATH_CHECK(m_vtxContKey.initialize());
44 
45  // Instantiate and initialize our decorator writes
46  // For vertices:
48  this->declare(m_vtxDecoKey);
49  m_vtxDecoKey.setOwner(&(*this));
51  // For weights:
53  this->declare(m_wgtDecoKey);
54  m_wgtDecoKey.setOwner(&(*this));
56 
57  return StatusCode::SUCCESS;
58 }
59 
60 // Finalize
62 {
63  ATH_MSG_DEBUG("Finalizing " << name() << "...");
64 
65  return StatusCode::SUCCESS;
66 }
67 
69 {
70  ATH_MSG_DEBUG("In decorate(...) for " << name() << "...");
71 
72  const EventContext& ctx = Gaudi::Hive::currentContext();
73 
74  // Decor handles for the AMVF vertices and weights
77  bool isVtxDeco_available = vtxDeco.isAvailable();
78  if(isVtxDeco_available) return;
79 
80  //vector to collect results
81  std::vector<std::pair<const xAOD::Vertex*,float> > vxWithWeight;
82 
83  // Iterate over our tracks:
84  for (const xAOD::TrackParticle* trk : *trkCont) {
85  if (!trk) continue;
86 
87  vxWithWeight.clear();
88 
89  // Iterate over our vertices
90  for (const auto *const vtx : *vtxCont) {
91  if (!vtx) continue;
92 
93  //Search for vertex linked to this track
94  const auto& trkLinks=vtx->trackParticleLinks();
95  const size_t nTrackLinks=trkLinks.size();
96  for (unsigned i=0;i<nTrackLinks;++i) {
97  if (trkLinks[i].isValid() && *(trkLinks[i]) == trk) {//ptr comparison
98  vxWithWeight.emplace_back(vtx,vtx->trackWeights()[i]);
99  break; //Found pointer, quit loop
100  }
101  }
102  }//end loop over vertices
103 
104  //sort by weight
105  std::sort(vxWithWeight.begin(),vxWithWeight.end(),
106  [](std::pair<const xAOD::Vertex*,float>& a, std::pair<const xAOD::Vertex*,float>& b){ return a.second > b.second; } );
107 
108  //split vector of pairs into two vectors in sync:
109 
110  std::vector<ElementLink<xAOD::VertexContainer>> AMVFVertices;
111  std::vector<float> AMVFWeights;
112  AMVFVertices.reserve(vxWithWeight.size());
113  AMVFWeights.reserve(vxWithWeight.size());
114 
115  for (const auto& p : vxWithWeight) {
116  AMVFVertices.emplace_back(p.first,*vtxCont,ctx);
117  AMVFWeights.emplace_back(p.second);
118  }
119 
120  // Actually perform the decoration
121  vtxDeco(*trk) = std::move(AMVFVertices);
122  wgtDeco(*trk) = std::move(AMVFWeights);
123 
124  } // end, loop over tracks
125 
126 }
127 
129 {
130  const EventContext& ctx = Gaudi::Hive::currentContext();
131 
132  // Open our track container
134  if (!trkCont.isValid()) {
135  ATH_MSG_WARNING("Unable to retrieve xAOD::TrackParticleContainer, \"" << m_trkContKey.key() << "\", returning without applying decorations!");
136  return;
137  }
138 
139  // Open our vertex container
141  if (!vtxCont.isValid()) {
142  ATH_MSG_WARNING("Unable to retrieve xAOD::VertexContainer, \"" << m_vtxContKey.key() << "\", returning without applying decorations!");
143  return;
144  }
145 
146  // Perform the decoration
147  decorate(trkCont.get(), vtxCont.get());
148 
149 }
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer >
InDet::InDetUsedInFitTrackDecoratorTool::decorate
virtual void decorate() const override
Definition: InDetUsedInFitTrackDecoratorTool.cxx:128
SG::WriteDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
CurrentContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
InDet::InDetUsedInFitTrackDecoratorTool::m_vtxContKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxContKey
Name of the primary vertex container (needed for container-less function calls)
Definition: InDetUsedInFitTrackDecoratorTool.h:99
asg
Definition: DataHandleTestTool.h:28
InDet::InDetUsedInFitTrackDecoratorTool::InDetUsedInFitTrackDecoratorTool
InDetUsedInFitTrackDecoratorTool(const std::string &name)
Constructor.
Definition: InDetUsedInFitTrackDecoratorTool.cxx:21
InDet::InDetUsedInFitTrackDecoratorTool::m_wgtDecoKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_wgtDecoKey
Per-track decorator for the AMVF fit weights.
Definition: InDetUsedInFitTrackDecoratorTool.h:113
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:812
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
InDet::InDetUsedInFitTrackDecoratorTool::finalize
virtual StatusCode finalize() override
Function finalizing the tool.
Definition: InDetUsedInFitTrackDecoratorTool.cxx:61
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
InDet::InDetUsedInFitTrackDecoratorTool::m_trkContKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContKey
Name of the track particle container (needed for container-less function calls)
Definition: InDetUsedInFitTrackDecoratorTool.h:94
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteDecorHandle.h
Handle class for adding a decoration to an object.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::InDetUsedInFitTrackDecoratorTool::~InDetUsedInFitTrackDecoratorTool
~InDetUsedInFitTrackDecoratorTool()
Destructor.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
InDet::InDetUsedInFitTrackDecoratorTool::m_vtxDecoKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_vtxDecoKey
Per-track decorator for the AMVF fit vertices.
Definition: InDetUsedInFitTrackDecoratorTool.h:110
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ReadHandle.h
Handle class for reading from StoreGate.
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
InDet::InDetUsedInFitTrackDecoratorTool::m_wgtDecoName
StringProperty m_wgtDecoName
Name of the per-track decoration for the AMVF fit weights.
Definition: InDetUsedInFitTrackDecoratorTool.h:89
InDet::InDetUsedInFitTrackDecoratorTool::m_vtxDecoName
StringProperty m_vtxDecoName
Name of the per-track decoration for the AMVF fit vertices.
Definition: InDetUsedInFitTrackDecoratorTool.h:84
InDetUsedInFitTrackDecoratorTool.h
InDet::InDetUsedInFitTrackDecoratorTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition: InDetUsedInFitTrackDecoratorTool.cxx:30