ATLAS Offline Software
Loading...
Searching...
No Matches
TrackIsolationDecorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
10
11//**********************************************************************
12
16
17#include "format"
18
19namespace DerivationFramework {
20
22
24 m_trk_corr.trackbitset.set(static_cast<unsigned int>(xAOD::Iso::coreTrackPtr));
25 ATH_CHECK(m_idTrkKey.initialize());
26 ATH_CHECK(m_toDeorTrkKey.initialize());
27 for (const std::string& decor : m_trkSel_Decors) {
28 m_trkSel_keys.emplace_back(m_toDeorTrkKey, decor);
29 }
30 ATH_CHECK(m_trkSel_keys.initialize());
31 ATH_CHECK(m_vtx_key.initialize());
32 m_ptcone20_key = std::format("ptcone20{:}{:}", m_customName.empty() ? "" : "_" , m_customName.value());
33 m_ptcone30_key = std::format("ptcone30{:}{:}", m_customName.empty() ? "" : "_" , m_customName.value());
34 m_ptcone40_key = std::format("ptcone40{:}{:}", m_customName.empty() ? "" : "_" , m_customName.value());
35
36 m_ptvarcone20_key = std::format("ptvarcone20{:}{:}", m_customName.empty() ? "" : "_", m_customName.value());
37 m_ptvarcone30_key = std::format("ptvarcone30{:}{:}", m_customName.empty() ? "" : "_", m_customName.value());
38 m_ptvarcone40_key = std::format("ptvarcone40{:}{:}", m_customName.empty() ? "" : "_", m_customName.value());
39
40 ATH_CHECK(m_ptcone20_key.initialize());
41 ATH_CHECK(m_ptcone30_key.initialize());
42 ATH_CHECK(m_ptcone40_key.initialize());
43
44 ATH_CHECK(m_ptvarcone20_key.initialize());
45 ATH_CHECK(m_ptvarcone30_key.initialize());
46 ATH_CHECK(m_ptvarcone40_key.initialize());
47 ATH_CHECK(m_isoTool.retrieve());
48
49 return StatusCode::SUCCESS;
50}
52 if (P == P1) { return true; }
53 const xAOD::IParticle* OrigP1 = xAOD::getOriginalObject(*P1);
55 if (OrigP == OrigP1) { return OrigP != nullptr; }
56 return (OrigP == P1 || OrigP1 == P);
57
58}
59StatusCode TrackIsolationDecorAlg::execute(const EventContext& ctx) const {
60
61 const xAOD::TrackParticleContainer* idTracks{nullptr}, *tracks{nullptr};
62 const xAOD::VertexContainer* vertices{nullptr};
63 ATH_CHECK(SG::get(idTracks , m_idTrkKey, ctx));
64 ATH_CHECK(SG::get(tracks , m_toDeorTrkKey, ctx));
65 ATH_CHECK(SG::get(vertices, m_vtx_key, ctx));
66
68 IsoDecorator decor_ptcone20{m_ptcone20_key, ctx, -Gaudi::Units::GeV};
69 IsoDecorator decor_ptcone30{m_ptcone30_key, ctx, -Gaudi::Units::GeV};
70 IsoDecorator decor_ptcone40{m_ptcone40_key, ctx, -Gaudi::Units::GeV};
71
72 IsoDecorator decor_ptvarcone20{m_ptvarcone20_key, ctx, -Gaudi::Units::GeV};
73 IsoDecorator decor_ptvarcone30{m_ptvarcone30_key, ctx, -Gaudi::Units::GeV};
74 IsoDecorator decor_ptvarcone40{m_ptvarcone40_key, ctx, -Gaudi::Units::GeV};
75
76 if (vertices->empty() ||
77 std::find_if(vertices->begin(), vertices->end(), [](const xAOD::Vertex* vtx){
78 return vtx->vertexType() == xAOD::VxType::PriVtx;
79 }) == vertices->end()) return StatusCode::SUCCESS;
80 Muon::MuonSectorMapping sector_mapping{};
81
83 using TrkViewContainer = ConstDataVector<xAOD::TrackParticleContainer>;
84 using view_map = std::map<int, std::vector<const xAOD::TrackParticle*> >;
85 view_map track_sectors;
86
87 for (const xAOD::TrackParticle* trk : *idTracks) {
88 const int sec = sector_mapping.getSector(trk->phi());
89 std::vector<const xAOD::TrackParticle*>& container = track_sectors[sec];
90 if (container.empty()) container.reserve(idTracks->size());
91 container.push_back(trk);
92 }
93
94
95 std::vector<SelDecorator> selDecors;
97 selDecors.emplace_back(key, ctx);
98 }
99 for (const xAOD::TrackParticle* trk : *tracks) {
100 if (trk->pt() < m_pt_min) continue;
101 if (!selDecors.empty() && std::ranges::find_if(selDecors, [trk](const SelDecorator& dec){
102 return dec(*trk);
103 }) == selDecors.end()) continue;
104 std::vector<int> sectors;
105 sector_mapping.getSectors(trk->phi(), sectors);
106 TrkViewContainer iso_tracks{SG::VIEW_ELEMENTS};
107 iso_tracks.reserve(tracks->size());
108 for (const int sector : sectors) {
109 view_map::iterator itr = track_sectors.find(sector);
110 if (itr == track_sectors.end()) continue;
111 for (const xAOD::TrackParticle* to_copy : itr->second) {
112 if(!isSame(trk, to_copy)) iso_tracks.push_back(to_copy);
113 }
114 }
116 if (!m_isoTool->trackIsolation(result, *trk, m_trk_iso_types, m_trk_corr, nullptr, nullptr, iso_tracks.asDataVector())) {
117 ATH_MSG_WARNING("Unable to decorate track isolation!!");
118 }
119 decor_ptcone40(*trk) = result.ptcones[0];
120 decor_ptcone30(*trk) = result.ptcones[1];
121 decor_ptcone20(*trk) = result.ptcones[2];
122
123 decor_ptvarcone40(*trk) = result.ptvarcones_10GeVDivPt[0];
124 decor_ptvarcone30(*trk) = result.ptvarcones_10GeVDivPt[1];
125 decor_ptvarcone20(*trk) = result.ptvarcones_10GeVDivPt[2];
126 }
127 return StatusCode::SUCCESS;
128}
129}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
DataVector adapter that acts like it holds const pointers.
static Double_t P(Double_t *tt, Double_t *par)
Handle class for adding a decoration to an object.
DataVector adapter that acts like it holds const pointers.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone20_key
StatusCode execute(const EventContext &ctx) const override
static bool isSame(const xAOD::IParticle *a, const xAOD::IParticle *b)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone20_key
Now let's come to the WriteDecorHandleKeys.
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone30_key
StatusCode initialize() override
Athena algorithm's Hooks.
ToolHandle< xAOD::ITrackIsolationTool > m_isoTool
Gaudi::Property< std::vector< std::string > > m_trkSel_Decors
Optional list of decorators to select only the good tracks for the isolation decoration.
SG::ReadDecorHandleKeyArray< xAOD::TrackParticleContainer > m_trkSel_keys
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_toDeorTrkKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone40_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vtx_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone40_key
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_idTrkKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone30_key
std::vector< xAOD::Iso::IsolationType > m_trk_iso_types
void getSectors(double phi, std::vector< int > &sectors) const
returns the main sector plus neighboring if the phi position is in an overlap region
int getSector(double phi) const
returns the sector corresponding to the phi position
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state.
Class providing the definition of the 4-vector interface.
THE reconstruction tool.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
const IParticle * getOriginalObject(const IParticle &copy)
This function can be used to conveniently get a pointer back to the original object from which a copy...
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".