Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TauAODMuonRemovalTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 }
10 
14  return StatusCode::SUCCESS;
15 }
16 
18  // Read in muon container
20  if (bool fail_muon = !muon_input_handle.isValid(); fail_muon) {
21  ATH_MSG_ERROR( "Could not retrieve Muon container with key " + muon_input_handle.key() );
22  return StatusCode::FAILURE;
23  }
24  auto muon_container = muon_input_handle.cptr();
25  //Add the Aux element as empty vector
26  const SG::Accessor<std::vector<ElementLink<xAOD::MuonContainer>>> acc_removed_muons("removedMuons");
27  acc_removed_muons(tau).clear();
28  //get the muon tracks and clusters
29  auto muon_and_tracks = decltype((getMuonAndTrk)(tau, *muon_container))();
30  auto muon_and_clusters = decltype((getMuonAndCls)(tau, *muon_container))();
31  if(m_doMuonTrkRm) muon_and_tracks = getMuonAndTrk(tau, *muon_container);
32  if(m_doMuonClsRm) muon_and_clusters = getMuonAndCls(tau, *muon_container);
33  // if nothing found just give up here
34  if(muon_and_tracks.empty() && muon_and_clusters.empty()) return StatusCode::SUCCESS;
35  // remove the links from the tau
36  auto tau_track_links = tau.allTauTrackLinksNonConst();
37  auto tau_cluster_links = tau.clusterLinks();
38  auto trk_removed_muons = removeTrks(tau_track_links, muon_and_tracks);
39  auto cls_removed_muons = removeClss(tau_cluster_links, muon_and_clusters);
40  tau.clearTauTrackLinks();
41  tau.clearClusterLinks();
42  tau.setClusterLinks(tau_cluster_links);
43  tau.setAllTauTrackLinks(tau_track_links);
44  //Merge the resulting vector and add them to sets
45  auto removed_muons = std::move(trk_removed_muons);
46  removed_muons.insert(removed_muons.end(), cls_removed_muons.begin(), cls_removed_muons.end());
47  auto removed_muons_set = std::set(removed_muons.begin(), removed_muons.end());
48  //set link to the removed lepton
49  for (auto muon : removed_muons_set ){
51  link.toContainedElement(*muon_container, muon);
52  acc_removed_muons(tau).push_back(link);
53  }
54  //notify the runner alg that the tau was modified
55  if (!acc_removed_muons(tau).empty())
56  {
57  const SG::Accessor<char> acc_modified("ModifiedInAOD");
58  acc_modified(tau) = static_cast<char>(true);
59  }
60  return StatusCode::SUCCESS;
61 }
62 
63 //helpers
64 std::vector<const xAOD::CaloCluster*> TauAODMuonRemovalTool::getOriginalTopoClusters(const xAOD::CaloCluster *cluster) const {
65  static const SG::Accessor<std::vector<ElementLink<xAOD::CaloClusterContainer>>> acc_origClusterLinks("constituentClusterLinks");
66  std::vector< const xAOD::CaloCluster* > orig_cls;
67  if(acc_origClusterLinks.isAvailable(*cluster)) {
68  auto links = acc_origClusterLinks(*cluster);
69  for (const auto &link : links) {
70  if (link.dataID() != "CaloCalTopoClusters")
71  ATH_MSG_WARNING("the clusters in the lepton cannot be converted to CaloCalTopoClusters, the ID is " << link.dataID());
72  if (link.isValid())
73  orig_cls.push_back(*link);
74  }
75  }
76  return orig_cls;
77 }
78 
79 std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> TauAODMuonRemovalTool::getMuonAndTrk(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const {
80  std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> ret;
81  std::for_each(muon_container.cbegin(), muon_container.cend(),
82  [&](auto muon) -> void {
83  if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
84  if(const auto & muon_ID_tracks_link = muon->inDetTrackParticleLink(); muon_ID_tracks_link.isValid())
85  ret.push_back(std::make_pair(std::move(*muon_ID_tracks_link), muon));
86  }
87  }
88  );
89  return ret;
90 }
91 
92 std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> TauAODMuonRemovalTool::getMuonAndCls(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const {
93  std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> ret;
94  std::for_each(muon_container.cbegin(), muon_container.cend(),
95  [&](auto muon) -> void {
96  if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
97  if(const auto & muon_cluster_link = muon->clusterLink(); muon_cluster_link.isValid()) {
98  auto muon_cluster = std::move(*muon_cluster_link);
99  auto muon_e = muon->e();
100  auto loss_e = muon->floatParameter(xAOD::Muon::ParamEnergyLoss);
101  auto cls_e = muon_cluster->e();
102  auto loss_diff = ((cls_e - loss_e) / (cls_e + loss_e));
103  if (muon_e > cls_e && loss_diff < 0.1 && loss_diff > -0.3) {
104  auto orig_muon_clusters = getOriginalTopoClusters(muon_cluster);
105  for (auto cluster : orig_muon_clusters)
106  ret.push_back(std::make_pair(cluster, muon));
107  }
108  }
109  }
110  }
111  );
112  return ret;
113 }
114 
115 template<typename Tlep, typename Tlinks> std::vector<Tlep> TauAODMuonRemovalTool::removeTrks(Tlinks& tau_trk_links, std::vector<std::pair<const xAOD::TrackParticle*, Tlep>>& tracks_and_leps) const {
116  std::vector<Tlep> ret;
117  tau_trk_links.erase(
118  std::remove_if(tau_trk_links.begin(), tau_trk_links.end(),
119  [&](auto tau_trk_link) -> bool {
120  bool match = false;
121  if(tau_trk_link.isValid()) {
122  auto tau_trk = (*tau_trk_link)->track();
123  auto where = std::find_if(tracks_and_leps.cbegin(), tracks_and_leps.cend(),
124  [&](auto track_and_lep){ return tau_trk == track_and_lep.first; });
125  if(where != tracks_and_leps.cend()) {
126  ATH_MSG_DEBUG("track with pt " << tau_trk->pt()/1000 << " GeV removed");
127  ret.push_back(where->second);
128  match = true;
129  }
130  }
131  return match;
132  }
133  ),
134  tau_trk_links.end()
135  );
136  return ret;
137 }
138 
139 template<typename Tlep, typename Tlinks> std::vector<Tlep> TauAODMuonRemovalTool::removeClss(Tlinks& tau_cls_links, std::vector<std::pair<const xAOD::CaloCluster*, Tlep>>& clusters_and_leps) const {
140  std::vector<Tlep> ret;
141  tau_cls_links.erase(
142  std::remove_if(tau_cls_links.begin(), tau_cls_links.end(),
143  [&](auto tau_cls_link) -> bool {
144  bool match = false;
145  if(tau_cls_link.isValid()) {
146  auto tau_cls = static_cast<const xAOD::CaloCluster*>(*tau_cls_link);
147  auto where = std::find_if(clusters_and_leps.cbegin(), clusters_and_leps.cend(),
148  [&](auto cluster_and_lep){ return tau_cls == cluster_and_lep.first; });
149  if(where != clusters_and_leps.cend()) {
150  ATH_MSG_DEBUG("cluster with pt " << tau_cls->pt()/1000 << " GeV removed");
151  ret.push_back(where->second);
152  match = true;
153  }
154  }
155  return match;
156  }
157  ),
158  tau_cls_links.end()
159  );
160  return ret;
161 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
TauAODMuonRemovalTool::getMuonAndCls
std::vector< std::pair< const xAOD::CaloCluster *, const xAOD::Muon * > > getMuonAndCls(const xAOD::TauJet &tau, const xAOD::MuonContainer &muon_cont) const
Definition: TauAODMuonRemovalTool.cxx:92
xAOD::TauJet_v3::setAllTauTrackLinks
void setAllTauTrackLinks(const TauTrackLinks_t &tauTracks)
Definition: TauJet_v3.cxx:424
xAOD::TauJet_v3::clusterLinks
const IParticleLinks_t & clusterLinks() const
TauAODMuonRemovalTool::TauAODMuonRemovalTool
TauAODMuonRemovalTool(const std::string &type)
Definition: TauAODMuonRemovalTool.cxx:7
TauAODMuonRemovalTool::m_muonInputContainer
SG::ReadHandleKey< xAOD::MuonContainer > m_muonInputContainer
Definition: TauAODMuonRemovalTool.h:30
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TauAODMuonRemovalTool::m_doMuonTrkRm
Gaudi::Property< bool > m_doMuonTrkRm
Definition: TauAODMuonRemovalTool.h:32
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TauAODMuonRemovalTool::getOriginalTopoClusters
std::vector< const xAOD::CaloCluster * > getOriginalTopoClusters(const xAOD::CaloCluster *cluster) const
Definition: TauAODMuonRemovalTool.cxx:64
xAOD::TauJet_v3::clearTauTrackLinks
void clearTauTrackLinks()
Remove all tracks from the tau.
Definition: TauJet_v3.cxx:567
TauAODMuonRemovalTool::m_muonWpUi
uint m_muonWpUi
Definition: TauAODMuonRemovalTool.h:29
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
TauAODMuonRemovalTool::m_doMuonClsRm
Gaudi::Property< bool > m_doMuonClsRm
Definition: TauAODMuonRemovalTool.h:33
xAOD::TauJet_v3::clearClusterLinks
void clearClusterLinks()
Remove all clusters from the tau.
Definition: TauJet_v3.cxx:620
TauAODMuonRemovalTool::removeClss
std::vector< Tlep > removeClss(Tlinks &tau_cls_links, std::vector< std::pair< const xAOD::CaloCluster *, Tlep >> &clusters_and_leps) const
Definition: TauAODMuonRemovalTool.cxx:139
DataVector::cend
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
TauAODMuonRemovalTool::m_strMinMuonIdWp
Gaudi::Property< std::string > m_strMinMuonIdWp
Definition: TauAODMuonRemovalTool.h:34
TauAODMuonRemovalTool::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: TauAODMuonRemovalTool.cxx:11
TauAODMuonRemovalTool::execute
virtual StatusCode execute(xAOD::TauJet &) const override
Execute - called for each tau candidate.
Definition: TauAODMuonRemovalTool.cxx:17
xAOD::TauJet_v3::setClusterLinks
void setClusterLinks(const IParticleLinks_t &clusters)
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::links
links
Definition: CLinks_v1.cxx:22
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
TauAODMuonRemovalTool::getMuonAndTrk
std::vector< std::pair< const xAOD::TrackParticle *, const xAOD::Muon * > > getMuonAndTrk(const xAOD::TauJet &tau, const xAOD::MuonContainer &muon_cont) const
Definition: TauAODMuonRemovalTool.cxx:79
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::TauJet_v3::allTauTrackLinksNonConst
TauTrackLinks_t & allTauTrackLinksNonConst()
In order to sort track links.
Definition: TauJet_v3.cxx:446
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
TauAODMuonRemovalTool.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TauAODMuonRemovalTool::removeTrks
std::vector< Tlep > removeTrks(Tlinks &tau_trk_links, std::vector< std::pair< const xAOD::TrackParticle *, Tlep >> &removings) const
Definition: TauAODMuonRemovalTool.cxx:115
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
DataVector::cbegin
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TauAODMuonRemovalTool::m_mapMuonIdWp
const std::map< std::string, uint > m_mapMuonIdWp
Definition: TauAODMuonRemovalTool.h:28
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356