ATLAS Offline Software
TrackIsolationDecorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
5 
11 
12 //**********************************************************************
13 
16 
17 namespace DerivationFramework {
18 TrackIsolationDecorAlg::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));
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 
41 
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);
52  const xAOD::IParticle* OrigP = xAOD::getOriginalObject(*P);
53  if (OrigP == OrigP1) { return OrigP != nullptr; }
54  return (OrigP == P1 || OrigP1 == P);
55 
56 }
57 StatusCode 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 retrive 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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::TrackIsolationDecorAlg::m_ptcone40_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone40_key
Definition: TrackIsolationDecorAlg.h:53
DerivationFramework::TrackIsolationDecorAlg::m_trkSel_keys
SG::ReadDecorHandleKeyArray< xAOD::TrackParticleContainer > m_trkSel_keys
Definition: TrackIsolationDecorAlg.h:47
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
Utils.h
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
DerivationFramework::TrackIsolationDecorAlg::m_toDeorTrkKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_toDeorTrkKey
Definition: TrackIsolationDecorAlg.h:35
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::Iso::coreTrackPtr
@ coreTrackPtr
tracks pointer
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:66
xAOD::TrackCorrection::trackbitset
Iso::IsolationTrackCorrectionBitset trackbitset
Definition: IsolationCommon.h:19
DerivationFramework::TrackIsolationDecorAlg::m_isoTool
ToolHandle< xAOD::ITrackIsolationTool > m_isoTool
Definition: TrackIsolationDecorAlg.h:59
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
DerivationFramework::TrackIsolationDecorAlg::m_idTrkKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_idTrkKey
Definition: TrackIsolationDecorAlg.h:32
DerivationFramework::TrackIsolationDecorAlg::m_trk_corr
xAOD::TrackCorrection m_trk_corr
Definition: TrackIsolationDecorAlg.h:62
DerivationFramework::TrackIsolationDecorAlg::m_ptvarcone40_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone40_key
Definition: TrackIsolationDecorAlg.h:57
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
DerivationFramework::TrackIsolationDecorAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: TrackIsolationDecorAlg.cxx:57
TrackIsolationDecorAlg.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
DerivationFramework::TrackIsolationDecorAlg::m_ptcone30_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone30_key
Definition: TrackIsolationDecorAlg.h:52
DerivationFramework::TrackIsolationDecorAlg::m_ptcone20_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptcone20_key
Now let's come to the WriteDecorHandleKeys.
Definition: TrackIsolationDecorAlg.h:51
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::TrackIsolationDecorAlg::m_trkSel_Decors
Gaudi::Property< std::vector< std::string > > m_trkSel_Decors
Optional list of decorators to select only the good tracks for the isolation decoration.
Definition: TrackIsolationDecorAlg.h:45
DerivationFramework::TrackIsolationDecorAlg::m_trk_iso_types
std::vector< xAOD::Iso::IsolationType > m_trk_iso_types
Definition: TrackIsolationDecorAlg.h:61
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
DerivationFramework::TrackIsolationDecorAlg::TrackIsolationDecorAlg
TrackIsolationDecorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: TrackIsolationDecorAlg.cxx:18
WriteDecorHandle.h
Handle class for adding a decoration to an object.
DerivationFramework::TrackIsolationDecorAlg::m_pt_min
Gaudi::Property< float > m_pt_min
Definition: TrackIsolationDecorAlg.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
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
DerivationFramework::TrackIsolationDecorAlg::isSame
static bool isSame(const xAOD::IParticle *a, const xAOD::IParticle *b)
Definition: TrackIsolationDecorAlg.cxx:49
DerivationFramework::TrackIsolationDecorAlg::m_customName
Gaudi::Property< std::string > m_customName
Definition: TrackIsolationDecorAlg.h:39
DerivationFramework::TrackIsolationDecorAlg::m_ptvarcone30_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone30_key
Definition: TrackIsolationDecorAlg.h:56
xAOD::TrackIsolation
Definition: IsolationCommon.h:33
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonContainer.h
MuonSectorMapping.h
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.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
DerivationFramework::TrackIsolationDecorAlg::~TrackIsolationDecorAlg
~TrackIsolationDecorAlg()
Destructor:
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
IParticleHelpers.h
DerivationFramework::TrackIsolationDecorAlg::m_ptvarcone20_key
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_ptvarcone20_key
Definition: TrackIsolationDecorAlg.h:55
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::getOriginalObject
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...
Definition: IParticleHelpers.cxx:140
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
TrackParticleContainer.h
DerivationFramework::TrackIsolationDecorAlg::m_vtx_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vtx_key
Definition: TrackIsolationDecorAlg.h:37
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DerivationFramework::TrackIsolationDecorAlg::initialize
StatusCode initialize() override
Athena algorithm's Hooks.
Definition: TrackIsolationDecorAlg.cxx:23