ATLAS Offline Software
Loading...
Searching...
No Matches
InDetUsedInFitTrackDecoratorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
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_vtxDecoKey);
35 ATH_MSG_DEBUG("Using AMVFWeightsDecoName: " << m_wgtDecoKey);
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 ATH_CHECK(m_trkContKey.initialize());
41 ATH_CHECK(m_vtxContKey.initialize());
42
43 // Instantiate and initialize our decorator writes
44 ATH_CHECK(m_vtxDecoKey.initialize());
45 ATH_CHECK(m_wgtDecoKey.initialize());
46
47 return StatusCode::SUCCESS;
48}
49
50// Finalize
52{
53 ATH_MSG_DEBUG("Finalizing " << name() << "...");
54
55 return StatusCode::SUCCESS;
56}
57
58void InDet::InDetUsedInFitTrackDecoratorTool::decorate(const xAOD::TrackParticleContainer* trkCont, const xAOD::VertexContainer* vtxCont, const EventContext& ctx) const
59{
60 ATH_MSG_DEBUG("In decorate(...) for " << name() << "...");
61
62 // Decor handles for the AMVF vertices and weights
65 bool isVtxDeco_available = vtxDeco.isAvailable();
66 if(isVtxDeco_available) return;
67
68 //vector to collect results
69 std::vector<std::pair<const xAOD::Vertex*,float> > vxWithWeight;
70
71 // Iterate over our tracks:
72 for (const xAOD::TrackParticle* trk : *trkCont) {
73 if (!trk) continue;
74
75 vxWithWeight.clear();
76
77 // Iterate over our vertices
78 for (const auto *const vtx : *vtxCont) {
79 if (!vtx) continue;
80
81 //Search for vertex linked to this track
82 const auto& trkLinks=vtx->trackParticleLinks();
83 const size_t nTrackLinks=trkLinks.size();
84 for (unsigned i=0;i<nTrackLinks;++i) {
85 if (trkLinks[i].isValid() && *(trkLinks[i]) == trk) {//ptr comparison
86 vxWithWeight.emplace_back(vtx,vtx->trackWeights()[i]);
87 break; //Found pointer, quit loop
88 }
89 }
90 }//end loop over vertices
91
92 //sort by weight
93 std::sort(vxWithWeight.begin(),vxWithWeight.end(),
94 [](std::pair<const xAOD::Vertex*,float>& a, std::pair<const xAOD::Vertex*,float>& b){ return a.second > b.second; } );
95
96 //split vector of pairs into two vectors in sync:
97
98 std::vector<ElementLink<xAOD::VertexContainer>> AMVFVertices;
99 std::vector<float> AMVFWeights;
100 AMVFVertices.reserve(vxWithWeight.size());
101 AMVFWeights.reserve(vxWithWeight.size());
102
103 for (const auto& p : vxWithWeight) {
104 AMVFVertices.emplace_back(p.first,*vtxCont,ctx);
105 AMVFWeights.emplace_back(p.second);
106 }
107
108 // Actually perform the decoration
109 vtxDeco(*trk) = std::move(AMVFVertices);
110 wgtDeco(*trk) = std::move(AMVFWeights);
111
112 } // end, loop over tracks
113
114}
115
116void InDet::InDetUsedInFitTrackDecoratorTool::decorate(const EventContext& ctx) const
117{
118 // Open our track container
120 if (!trkCont.isValid()) {
121 ATH_MSG_WARNING("Unable to retrieve xAOD::TrackParticleContainer, \"" << m_trkContKey.key() << "\", returning without applying decorations!");
122 return;
123 }
124
125 // Open our vertex container
127 if (!vtxCont.isValid()) {
128 ATH_MSG_WARNING("Unable to retrieve xAOD::VertexContainer, \"" << m_vtxContKey.key() << "\", returning without applying decorations!");
129 return;
130 }
131
132 // Perform the decoration
133 decorate(trkCont.get(), vtxCont.get(), ctx);
134
135}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
static Double_t a
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trkContKey
Name of the track particle container (needed for container-less function calls)
virtual StatusCode initialize() override
Function initialising the tool.
virtual StatusCode finalize() override
Function finalizing the tool.
virtual void decorate(const xAOD::TrackParticleContainer *trkCont, const xAOD::VertexContainer *vtxCont, const EventContext &ctx) const override
Function for decorating tracks with their used-in-fit AMVF vertices and weights.
InDetUsedInFitTrackDecoratorTool(const std::string &name)
Constructor.
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_wgtDecoKey
Per-track decorator for the AMVF fit weights.
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxContKey
Name of the primary vertex container (needed for container-less function calls)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_vtxDecoKey
Per-track decorator for the AMVF fit vertices.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
Handle class for adding a decoration to an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".