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
11
12//**********************************************************************
13
16
17namespace DerivationFramework {
18TrackIsolationDecorAlg::TrackIsolationDecorAlg(const std::string& name, ISvcLocator* pSvcLocator) :
19 AthReentrantAlgorithm(name, pSvcLocator) {}
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) m_trkSel_keys.emplace_back(m_toDeorTrkKey, decor);
28 ATH_CHECK(m_trkSel_keys.initialize());
29 ATH_CHECK(m_vtx_key.initialize());
30 m_ptcone20_key = std::string("ptcone20") + (m_customName.empty() ? "" : "_") + m_customName;
31 m_ptcone30_key = std::string("ptcone30") + (m_customName.empty() ? "" : "_") + m_customName;
32 m_ptcone40_key = std::string("ptcone40") + (m_customName.empty() ? "" : "_") + m_customName;
33
34 m_ptvarcone20_key = std::string("ptvarcone20") + (m_customName.empty() ? "" : "_") + m_customName;
35 m_ptvarcone30_key = std::string("ptvarcone30") + (m_customName.empty() ? "" : "_") + m_customName;
36 m_ptvarcone40_key = std::string("ptvarcone40") + (m_customName.empty() ? "" : "_") + m_customName;
37
38 ATH_CHECK(m_ptcone20_key.initialize());
39 ATH_CHECK(m_ptcone30_key.initialize());
40 ATH_CHECK(m_ptcone40_key.initialize());
41
42 ATH_CHECK(m_ptvarcone20_key.initialize());
43 ATH_CHECK(m_ptvarcone30_key.initialize());
44 ATH_CHECK(m_ptvarcone40_key.initialize());
45 ATH_CHECK(m_isoTool.retrieve());
46
47 return StatusCode::SUCCESS;
48}
50 if (P == P1) { return true; }
51 const xAOD::IParticle* OrigP1 = xAOD::getOriginalObject(*P1);
53 if (OrigP == OrigP1) { return OrigP != nullptr; }
54 return (OrigP == P1 || OrigP1 == P);
55
56}
57StatusCode TrackIsolationDecorAlg::execute(const EventContext& ctx) const {
59 if (!idTracks.isPresent()) {
60 ATH_MSG_FATAL("Failed to load "<<m_idTrkKey.fullKey());
61 return StatusCode::FAILURE;
62 }
63
65 if (!tracks.isPresent()) {
66 ATH_MSG_FATAL("Failed to retrieve track collection " << m_toDeorTrkKey.fullKey());
67 return StatusCode::FAILURE;
68 }
70 if (!vertices.isPresent()) {
71 ATH_MSG_FATAL("Failed to retrieve vertex collection " << m_vtx_key.fullKey());
72 return StatusCode::FAILURE;
73 }
75 IsoDecorator decor_ptcone20{makeHandle<float>(ctx, m_ptcone20_key, -Gaudi::Units::GeV)};
76 IsoDecorator decor_ptcone30{makeHandle<float>(ctx, m_ptcone30_key, -Gaudi::Units::GeV)};
77 IsoDecorator decor_ptcone40{makeHandle<float>(ctx, m_ptcone40_key, -Gaudi::Units::GeV)};
78
79 IsoDecorator decor_ptvarcone20{makeHandle<float>(ctx, m_ptvarcone20_key, -Gaudi::Units::GeV)};
80 IsoDecorator decor_ptvarcone30{makeHandle<float>(ctx, m_ptvarcone30_key, -Gaudi::Units::GeV)};
81 IsoDecorator decor_ptvarcone40{makeHandle<float>(ctx, m_ptvarcone40_key, -Gaudi::Units::GeV)};
82
83 if (vertices->empty() ||
84 std::find_if(vertices->begin(), vertices->end(), [](const xAOD::Vertex* vtx){
85 return vtx->vertexType() == xAOD::VxType::PriVtx;
86 }) == vertices->end()) return StatusCode::SUCCESS;
87 Muon::MuonSectorMapping sector_mapping{};
88
90 using TrkViewContainer = ConstDataVector<xAOD::TrackParticleContainer>;
91 using view_map = std::map<int, std::vector<const xAOD::TrackParticle*> >;
92 view_map track_sectors;
93
94 for (const xAOD::TrackParticle* trk : *idTracks) {
95 if (!trk) continue;
96 const int sec = sector_mapping.getSector(trk->phi());
97 std::vector<const xAOD::TrackParticle*>& container = track_sectors[sec];
98 if (container.empty()) container.reserve(idTracks->size());
99 container.push_back(trk);
100 }
101
102
103 std::vector<SelDecorator> selDecors;
105 selDecors.emplace_back(key, ctx);
106 }
107 for (const xAOD::TrackParticle* trk : *tracks) {
108 if (trk->pt() < m_pt_min) continue;
109 if (!selDecors.empty() && std::find_if(selDecors.begin(), selDecors.end(), [trk](const SelDecorator& dec){
110 return dec(*trk);
111 }) == selDecors.end()) continue;
112 std::vector<int> sectors;
113 sector_mapping.getSectors(trk->phi(), sectors);
114 TrkViewContainer iso_tracks{SG::VIEW_ELEMENTS};
115 iso_tracks.reserve(tracks->size());
116 for (const int sector : sectors) {
117 view_map::iterator itr = track_sectors.find(sector);
118 if (itr == track_sectors.end()) continue;
119 for (const xAOD::TrackParticle* to_copy : itr->second) {
120 if(!isSame(trk, to_copy)) iso_tracks.push_back(to_copy);
121 }
122 }
124 if (!m_isoTool->trackIsolation(result, *trk, m_trk_iso_types, m_trk_corr, nullptr, nullptr, iso_tracks.asDataVector())) {
125 ATH_MSG_WARNING("Unable to decorate track isolation!!");
126 }
127 decor_ptcone40(*trk) = result.ptcones[0];
128 decor_ptcone30(*trk) = result.ptcones[1];
129 decor_ptcone20(*trk) = result.ptcones[2];
130
131 decor_ptvarcone40(*trk) = result.ptvarcones_10GeVDivPt[0];
132 decor_ptvarcone30(*trk) = result.ptvarcones_10GeVDivPt[1];
133 decor_ptvarcone20(*trk) = result.ptvarcones_10GeVDivPt[2];
134 }
135 return StatusCode::SUCCESS;
136}
137}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#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.
An algorithm that can be simultaneously executed in multiple threads.
DataVector adapter that acts like it holds const pointers.
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
TrackIsolationDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
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.
bool isPresent() const
Is the referenced object present in SG?
Handle class for adding a decoration to an object.
Class providing the definition of the 4-vector interface.
THE reconstruction tool.
SG::WriteDecorHandle< ContType, dType > makeHandle(const EventContext &ctx, const SG::WriteDecorHandleKey< ContType > &key, const dType &defValue=dType{})
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
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...
Vertex_v1 Vertex
Define the latest version of the vertex class.