ATLAS Offline Software
Loading...
Searching...
No Matches
IsoCloseByCorrectionTrkSelAlg.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4*/
6
8
9#include <algorithm>
10
18
19namespace CP {
20
21 IsoCloseByCorrectionTrkSelAlg::IsoCloseByCorrectionTrkSelAlg(const std::string& name, ISvcLocator* svcLoc) :
22 AthReentrantAlgorithm(name, svcLoc) {}
24 ATH_CHECK(m_muonKey.initialize(!m_muonKey.empty()));
25 ATH_CHECK(m_elecKey.initialize(!m_elecKey.empty()));
26 ATH_CHECK(m_photKey.initialize(!m_photKey.empty()));
27 if (!m_selDecoration.empty()) {
28 m_elecSelKey = m_elecKey.empty() ? "" : m_elecKey.key() + "." + m_selDecoration.value();
29 m_mounSelKey = m_muonKey.empty() ? "" : m_muonKey.key() + "." + m_selDecoration.value();
30 m_photSelKey = m_photKey.empty() ? "" : m_photKey.key() + "." + m_selDecoration.value();
31 }
33 ATH_CHECK(m_elecSelKey.initialize(!m_elecSelKey.empty()));
34 ATH_CHECK(m_mounSelKey.initialize(!m_mounSelKey.empty()));
35 ATH_CHECK(m_photSelKey.initialize(!m_photSelKey.empty()));
36 if (!m_muonKey.empty() && !m_muonSelTool.empty())
37 ATH_CHECK(m_muonSelTool.retrieve());
38 else
39 m_muonSelTool.disable();
40 if (!m_elecKey.empty() && !m_elecSelTool.empty())
41 ATH_CHECK(m_elecSelTool.retrieve());
42 else
43 m_elecSelTool.disable();
44 if (!m_photSelTool.empty() && !m_photSelTool.empty())
45 ATH_CHECK(m_photSelTool.retrieve());
46 else
47 m_photSelTool.disable();
48 ATH_CHECK(m_closeByCorrTool.retrieve());
50 ATH_CHECK(m_trkKey.initialize(!m_trkKey.empty()));
51 ATH_CHECK(m_thinKey.initialize(m_stream, !m_stream.empty()));
52 return StatusCode::SUCCESS;
53 }
55 const Long64_t tot_acc = m_accepted_trks[0] + m_accepted_trks[1] + m_accepted_trks[2];
56 ATH_MSG_INFO("Accepted " << tot_acc << " tracks associated with collimated lepton pairs."
57 << " Track association split into particle type");
58 ATH_MSG_INFO(" --- Muons: " << m_accepted_trks[0] << " out of " << m_selected_obj[0] << " ("
59 << (m_selected_obj[0] ? 100. * m_accepted_trks[0] / m_selected_obj[0] : 0.) << "%).");
60 ATH_MSG_INFO(" --- Electrons: " << m_accepted_trks[1] << " out of " << m_selected_obj[1] << " ("
61 << (m_selected_obj[1] ? 100. * m_accepted_trks[1] / m_selected_obj[1] : 0.) << "%).");
62 ATH_MSG_INFO(" --- Photons: " << m_accepted_trks[2] << " out of " << m_selected_obj[2] << " ("
63 << (m_selected_obj[2] ? 100. * m_accepted_trks[2] / m_selected_obj[2] : 0.) << "%).");
64 ATH_MSG_INFO("Rate w.r.t. all inner detector tracks (" << m_tot_trks << "): " << (m_tot_trks ? 100. * tot_acc / m_tot_trks : 0.)
65 << "%");
66 return StatusCode::SUCCESS;
67 }
68 StatusCode IsoCloseByCorrectionTrkSelAlg::execute(const EventContext& ctx) const {
69
70 TrackSet assoc_trks{};
71 LepContainer prim_objs{};
72 ATH_CHECK(loadTracks(ctx, m_muonKey, assoc_trks, prim_objs));
73 const size_t n_muons = prim_objs.size();
74 ATH_CHECK(loadTracks(ctx, m_elecKey, assoc_trks, prim_objs));
75 const size_t n_elecs = prim_objs.size() - n_muons;
76 ATH_CHECK(loadTracks(ctx, m_photKey, assoc_trks, prim_objs));
77 const size_t n_phots = prim_objs.size() - n_muons - n_elecs;
78 m_selected_obj[0] += n_muons;
79 m_selected_obj[1] += n_elecs;
80 m_selected_obj[2] += n_phots;
81
83 {
84 TrackSet pruned_trks{};
85 std::copy_if(assoc_trks.begin(), assoc_trks.end(), std::inserter(pruned_trks, pruned_trks.begin()),
86 [this, &prim_objs, &ctx](const TrackPtr& track) -> bool {
87 int trk_idx{-1};
88 bool ret_code{false};
89 for (const xAOD::IParticle* prim : prim_objs) {
90 TrackSet assoc_trk = m_closeByCorrTool->getTrackCandidates(ctx, prim);
92 if (assoc_trk.count(track)) {
94 if (prim->type() == xAOD::Type::ObjectType::Muon)
95 trk_idx = 0;
96 else if (prim->type() == xAOD::Type::ObjectType::Electron)
97 trk_idx = 1;
98 else if (prim->type() == xAOD::Type::ObjectType::Photon)
99 trk_idx = 2;
100 if (ret_code) break;
101 continue;
102 }
104 if (xAOD::P4Helpers::deltaR(track, m_closeByCorrTool->isoRefParticle(prim)) > m_maxConeSize)
105 continue;
106 ret_code = true;
107 if (trk_idx != -1) break;
108 }
109 if (ret_code) ++m_accepted_trks[trk_idx];
110 return ret_code;
111 });
112 assoc_trks = std::move(pruned_trks);
113 }
114
116 if (!m_trkKey.empty()) {
117 auto tracks = std::make_unique<ConstDataVector<xAOD::TrackParticleContainer>>(SG::VIEW_ELEMENTS);
118 for (const TrackPtr& trk : assoc_trks) {
119 const xAOD::TrackParticle* trk_p = trk;
120 tracks->push_back(trk_p);
121 }
122 auto writeHandle = SG::makeHandle(m_trkKey, ctx);
123 ATH_CHECK(writeHandle.record(std::move(tracks)));
124 }
125 if (!m_thinKey.empty()) {
126 SG::ThinningHandle<xAOD::TrackParticleContainer> thinner{m_thinKey, ctx};
127 m_tot_trks += thinner->size();
128 std::vector<bool> thin_dec(thinner->size(), false);
129 for (const TrackPtr& trk : assoc_trks) { thin_dec[trk->index()] = true; }
130 thinner.keep(thin_dec);
131 }
132 return StatusCode::SUCCESS;
133 }
134
135 template <class CONT_TYPE>
136 StatusCode IsoCloseByCorrectionTrkSelAlg::loadTracks(const EventContext& ctx, const SG::ReadHandleKey<CONT_TYPE>& key, TrackSet& tracks,
137 LepContainer& prim_objs) const {
138 if (key.empty()) {
139 ATH_MSG_DEBUG("No key has been defined. Assume that the container is disabled ");
140 return StatusCode::SUCCESS;
141 }
142 SG::ReadHandle<CONT_TYPE> particles{key, ctx};
143 if (!particles.isValid()) {
144 ATH_MSG_FATAL("Failed to retrieve " << key.fullKey());
145 return StatusCode::FAILURE;
146 }
147 for (const auto* p : *particles) {
148 if (!passSelection(ctx, p)) continue;
149 prim_objs.insert(p);
150 TrackSet part_trks = m_closeByCorrTool->getTrackCandidates(ctx, p);
151 tracks.insert(part_trks.begin(), part_trks.end());
152 }
153 return StatusCode::SUCCESS;
154 }
155
156 bool IsoCloseByCorrectionTrkSelAlg::passSelection(const EventContext& ctx, const xAOD::Electron* elec) const {
157 if (!m_elecSelKey.empty()) {
159 if (!decor(*elec)) return false;
160 }
161 return elec->pt() >= m_minElecPt && (m_elecSelTool.empty() || m_elecSelTool->accept(ctx, elec));
162 }
163 bool IsoCloseByCorrectionTrkSelAlg::passSelection(const EventContext& ctx, const xAOD::Photon* phot) const {
164 if (!m_photSelKey.empty()) {
166 if (!decor(*phot)) return false;
167 }
168 return phot->pt() >= m_minPhotPt && (m_photSelTool.empty() || m_photSelTool->accept(phot));
169 }
170 bool IsoCloseByCorrectionTrkSelAlg::passSelection(const EventContext& ctx, const xAOD::Muon* muon) const {
171 if (!m_photSelKey.empty()) {
173 if (!decor(*muon)) return false;
174 }
175 return muon->pt() >= m_minMuonPt && (m_muonSelTool.empty() || m_muonSelTool->accept(*muon));
176 }
177} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
Handle for requesting thinning for a data object.
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_mounSelKey
The keys serve to declare the data dependency on the optional selection decorator properly.
SG::ReadHandleKey< xAOD::PhotonContainer > m_photKey
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Optionally the user can also parse the elec / muon / photon selection tools.
SG::WriteHandleKey< ConstDataVector< xAOD::TrackParticleContainer > > m_trkKey
Optionally the user can also dump a TrackParticleContainer containing all the tracks entring the cone...
ToolHandle< IAsgPhotonIsEMSelector > m_photSelTool
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_photSelKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Input containers to retrieve from the storegate.
ToolHandle< CP::IIsolationCloseByCorrectionTool > m_closeByCorrTool
These tools shall be configured to pick up the same Inner detector tracks as for the isolation buildi...
SG::ReadHandleKey< xAOD::ElectronContainer > m_elecKey
Gaudi::Property< float > m_minElecPt
Kinematic cuts. The selection tools do not support kinematic cut selection unfortunately.
IsoCloseByCorrectionTrkSelAlg(const std::string &name, ISvcLocator *svcLoc)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_thinKey
StatusCode loadTracks(const EventContext &ctx, const SG::ReadHandleKey< CONT_TYPE > &key, TrackSet &tracks, LepContainer &prim_objs) const
std::atomic< Long64_t > m_tot_trks
Total track counter.
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
StatusCode execute(const EventContext &ctx) const override
std::set< const xAOD::IParticle * > LepContainer
bool passSelection(const EventContext &ctx, const xAOD::Electron *elec) const
Gaudi::Property< std::string > m_selDecoration
External selection criteria.
Gaudi::Property< std::string > m_stream
Output stream to be used for the thinning decision.
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_elecSelKey
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition Egamma_v1.cxx:66
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".