ATLAS Offline Software
Loading...
Searching...
No Matches
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
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:
41 ATH_CHECK(m_trkContKey.initialize());
42 // For vertices:
43 ATH_CHECK(m_vtxContKey.initialize());
44
45 // Instantiate and initialize our decorator writes
46 // For vertices:
47 m_vtxDecoKey = SG::WriteDecorHandleKey<xAOD::TrackParticleContainer>(m_trkContKey.key() + "." + m_vtxDecoName); // FIXME Do not assign properties during initialize()
48 this->declare(m_vtxDecoKey);
49 m_vtxDecoKey.setOwner(&(*this));
50 ATH_CHECK(m_vtxDecoKey.initialize());
51 // For weights:
52 m_wgtDecoKey = SG::WriteDecorHandleKey<xAOD::TrackParticleContainer>(m_trkContKey.key() + "." + m_wgtDecoName); // FIXME Do not assign properties during initialize()
53 this->declare(m_wgtDecoKey);
54 m_wgtDecoKey.setOwner(&(*this));
55 ATH_CHECK(m_wgtDecoKey.initialize());
56
57 return StatusCode::SUCCESS;
58}
59
60// Finalize
62{
63 ATH_MSG_DEBUG("Finalizing " << name() << "...");
64
65 return StatusCode::SUCCESS;
66}
67
68void InDet::InDetUsedInFitTrackDecoratorTool::decorate(const xAOD::TrackParticleContainer* trkCont, const xAOD::VertexContainer* vtxCont, const EventContext& ctx) const
69{
70 ATH_MSG_DEBUG("In decorate(...) for " << name() << "...");
71
72 // Decor handles for the AMVF vertices and weights
75 bool isVtxDeco_available = vtxDeco.isAvailable();
76 if(isVtxDeco_available) return;
77
78 //vector to collect results
79 std::vector<std::pair<const xAOD::Vertex*,float> > vxWithWeight;
80
81 // Iterate over our tracks:
82 for (const xAOD::TrackParticle* trk : *trkCont) {
83 if (!trk) continue;
84
85 vxWithWeight.clear();
86
87 // Iterate over our vertices
88 for (const auto *const vtx : *vtxCont) {
89 if (!vtx) continue;
90
91 //Search for vertex linked to this track
92 const auto& trkLinks=vtx->trackParticleLinks();
93 const size_t nTrackLinks=trkLinks.size();
94 for (unsigned i=0;i<nTrackLinks;++i) {
95 if (trkLinks[i].isValid() && *(trkLinks[i]) == trk) {//ptr comparison
96 vxWithWeight.emplace_back(vtx,vtx->trackWeights()[i]);
97 break; //Found pointer, quit loop
98 }
99 }
100 }//end loop over vertices
101
102 //sort by weight
103 std::sort(vxWithWeight.begin(),vxWithWeight.end(),
104 [](std::pair<const xAOD::Vertex*,float>& a, std::pair<const xAOD::Vertex*,float>& b){ return a.second > b.second; } );
105
106 //split vector of pairs into two vectors in sync:
107
108 std::vector<ElementLink<xAOD::VertexContainer>> AMVFVertices;
109 std::vector<float> AMVFWeights;
110 AMVFVertices.reserve(vxWithWeight.size());
111 AMVFWeights.reserve(vxWithWeight.size());
112
113 for (const auto& p : vxWithWeight) {
114 AMVFVertices.emplace_back(p.first,*vtxCont,ctx);
115 AMVFWeights.emplace_back(p.second);
116 }
117
118 // Actually perform the decoration
119 vtxDeco(*trk) = std::move(AMVFVertices);
120 wgtDeco(*trk) = std::move(AMVFWeights);
121
122 } // end, loop over tracks
123
124}
125
126void InDet::InDetUsedInFitTrackDecoratorTool::decorate(const EventContext& ctx) const
127{
128 // Open our track container
130 if (!trkCont.isValid()) {
131 ATH_MSG_WARNING("Unable to retrieve xAOD::TrackParticleContainer, \"" << m_trkContKey.key() << "\", returning without applying decorations!");
132 return;
133 }
134
135 // Open our vertex container
137 if (!vtxCont.isValid()) {
138 ATH_MSG_WARNING("Unable to retrieve xAOD::VertexContainer, \"" << m_vtxContKey.key() << "\", returning without applying decorations!");
139 return;
140 }
141
142 // Perform the decoration
143 decorate(trkCont.get(), vtxCont.get(), ctx);
144
145}
#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)
StringProperty m_vtxDecoName
Name of the per-track decoration for the AMVF fit vertices.
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.
StringProperty m_wgtDecoName
Name of the per-track decoration 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.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
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".