ATLAS Offline Software
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 
13 #include "StoreGate/ReadHandle.h"
16 #include "StoreGate/WriteHandle.h"
18 
19 namespace CP {
20 
21  IsoCloseByCorrectionTrkSelAlg::IsoCloseByCorrectionTrkSelAlg(const std::string& name, ISvcLocator* svcLoc) :
22  AthReentrantAlgorithm(name, svcLoc) {}
24  ATH_CHECK(m_muonKey.initialize(!m_muonKey.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());
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  }
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  }
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()) {
165  SG::ReadDecorHandle<xAOD::PhotonContainer, char> decor{m_photSelKey, ctx};
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()) {
172  SG::ReadDecorHandle<xAOD::MuonContainer, char> decor{m_mounSelKey, ctx};
173  if (!decor(*muon)) return false;
174  }
175  return muon->pt() >= m_minMuonPt && (m_muonSelTool.empty() || m_muonSelTool->accept(*muon));
176  }
177 } // namespace CP
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CP::IsoCloseByCorrectionTrkSelAlg::finalize
StatusCode finalize() override
Definition: IsoCloseByCorrectionTrkSelAlg.cxx:54
CP::IsoCloseByCorrectionTrkSelAlg::m_photSelTool
ToolHandle< IAsgPhotonIsEMSelector > m_photSelTool
Definition: IsoCloseByCorrectionTrkSelAlg.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::IsoCloseByCorrectionTrkSelAlg::m_photKey
SG::ReadHandleKey< xAOD::PhotonContainer > m_photKey
Definition: IsoCloseByCorrectionTrkSelAlg.h:54
CP::IsoCloseByCorrectionTrkSelAlg::m_closeByCorrTool
ToolHandle< CP::IIsolationCloseByCorrectionTool > m_closeByCorrTool
These tools shall be configured to pick up the same Inner detector tracks as for the isolation buildi...
Definition: IsoCloseByCorrectionTrkSelAlg.h:70
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
CP::IsoCloseByCorrectionTrkSelAlg::m_elecSelKey
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_elecSelKey
Definition: IsoCloseByCorrectionTrkSelAlg.h:62
CP::IsoCloseByCorrectionTrkSelAlg::m_thinKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_thinKey
Definition: IsoCloseByCorrectionTrkSelAlg.h:85
CP::TrackSet
std::set< TrackPtr > TrackSet
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:72
CP::IsoCloseByCorrectionTrkSelAlg::m_tot_trks
std::atomic< Long64_t > m_tot_trks
Total track counter.
Definition: IsoCloseByCorrectionTrkSelAlg.h:96
CP::SortedObjPtr
Small helper struct to have sets of particle pointers sorted by pt.
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:40
CP::IsoCloseByCorrectionTrkSelAlg::m_stream
Gaudi::Property< std::string > m_stream
Output stream to be used for the thinning decision.
Definition: IsoCloseByCorrectionTrkSelAlg.h:84
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::IsoCloseByCorrectionTrkSelAlg::m_muonSelTool
ToolHandle< CP::IMuonSelectionTool > m_muonSelTool
Optionally the user can also parse the elec / muon / photon selection tools.
Definition: IsoCloseByCorrectionTrkSelAlg.h:65
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
CP::IsoCloseByCorrectionTrkSelAlg::m_elecSelTool
ToolHandle< IAsgElectronLikelihoodTool > m_elecSelTool
Definition: IsoCloseByCorrectionTrkSelAlg.h:66
CP::IsoCloseByCorrectionTrkSelAlg::initialize
StatusCode initialize() override
Definition: IsoCloseByCorrectionTrkSelAlg.cxx:23
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CP::IsoCloseByCorrectionTrkSelAlg::LepContainer
std::set< const xAOD::IParticle * > LepContainer
Definition: IsoCloseByCorrectionTrkSelAlg.h:46
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
WriteHandle.h
Handle class for recording to StoreGate.
CP::IsoCloseByCorrectionTrkSelAlg::m_muonKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonKey
Input containers to retrieve from the storegate.
Definition: IsoCloseByCorrectionTrkSelAlg.h:52
EgammaxAODHelpers.h
IsoCloseByCorrectionTrkSelAlg.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
CP::IsoCloseByCorrectionTrkSelAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: IsoCloseByCorrectionTrkSelAlg.cxx:68
xAOD::P4Helpers::deltaR
double deltaR(double rapidity1, double phi1, double rapidity2, double phi2)
from bare bare rapidity,phi
Definition: xAODP4Helpers.h:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
CP::IsoCloseByCorrectionTrkSelAlg::IsoCloseByCorrectionTrkSelAlg
IsoCloseByCorrectionTrkSelAlg(const std::string &name, ISvcLocator *svcLoc)
Definition: IsoCloseByCorrectionTrkSelAlg.cxx:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::IsoCloseByCorrectionTrkSelAlg::loadTracks
StatusCode loadTracks(const EventContext &ctx, const SG::ReadHandleKey< CONT_TYPE > &key, TrackSet &tracks, LepContainer &prim_objs) const
Definition: IsoCloseByCorrectionTrkSelAlg.cxx:136
CP::IsoCloseByCorrectionTrkSelAlg::m_trkKey
SG::WriteHandleKey< ConstDataVector< xAOD::TrackParticleContainer > > m_trkKey
Optionally the user can also dump a TrackParticleContainer containing all the tracks entring the cone...
Definition: IsoCloseByCorrectionTrkSelAlg.h:88
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::IsoCloseByCorrectionTrkSelAlg::m_photSelKey
SG::ReadDecorHandleKey< xAOD::PhotonContainer > m_photSelKey
Definition: IsoCloseByCorrectionTrkSelAlg.h:63
CP::IsoCloseByCorrectionTrkSelAlg::m_elecKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_elecKey
Definition: IsoCloseByCorrectionTrkSelAlg.h:53
IsolationCloseByCorrectionTool.h
xAOD::Photon_v1
Definition: Photon_v1.h:37
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
xAOD::Egamma_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: Egamma_v1.cxx:65
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ReadHandle.h
Handle class for reading from StoreGate.
CP::IsoCloseByCorrectionTrkSelAlg::m_mounSelKey
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_mounSelKey
The keys serve to declare the data dependency on the optional selection decorator properly.
Definition: IsoCloseByCorrectionTrkSelAlg.h:61
CP::IsoCloseByCorrectionTrkSelAlg::m_selDecoration
Gaudi::Property< std::string > m_selDecoration
External selection criteria.
Definition: IsoCloseByCorrectionTrkSelAlg.h:57
CP::IsoCloseByCorrectionTrkSelAlg::m_maxConeSize
Gaudi::Property< float > m_maxConeSize
Definition: IsoCloseByCorrectionTrkSelAlg.h:81
CP::TrackPtr
SortedObjPtr< xAOD::TrackParticle > TrackPtr
Definition: PhysicsAnalysis/AnalysisCommon/IsolationSelection/IsolationSelection/Defs.h:70
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37