16 return StatusCode::SUCCESS;
20 const EventContext& ctx)
const {
24 if (
bool fail_muon = !muon_input_handle.
isValid(); fail_muon) {
25 ATH_MSG_ERROR(
"Could not retrieve Muon container with key " + muon_input_handle.
key() );
26 return StatusCode::FAILURE;
28 auto muon_container = muon_input_handle.
cptr();
31 acc_removed_muons(tau).clear();
33 auto muon_and_tracks =
decltype((
getMuonAndTrk)(tau, *muon_container))();
34 auto muon_and_clusters =
decltype((
getMuonAndCls)(tau, *muon_container))();
38 if(muon_and_tracks.empty() && muon_and_clusters.empty())
return StatusCode::SUCCESS;
40 auto tau_track_links = tau.allTauTrackLinksNonConst();
41 auto tau_cluster_links = tau.clusterLinks();
42 auto trk_removed_muons =
removeTrks(tau_track_links, muon_and_tracks);
43 auto cls_removed_muons =
removeClss(tau_cluster_links, muon_and_clusters);
44 tau.clearTauTrackLinks();
45 tau.clearClusterLinks();
46 tau.setClusterLinks(tau_cluster_links);
47 tau.setAllTauTrackLinks(tau_track_links);
49 auto removed_muons = std::move(trk_removed_muons);
50 removed_muons.insert(removed_muons.end(), cls_removed_muons.begin(), cls_removed_muons.end());
51 auto removed_muons_set = std::set(removed_muons.begin(), removed_muons.end());
53 for (
auto muon : removed_muons_set ){
55 link.toContainedElement(*muon_container, muon);
56 acc_removed_muons(tau).push_back(link);
59 if (!acc_removed_muons(tau).
empty())
62 acc_modified(tau) =
static_cast<char>(
true);
64 return StatusCode::SUCCESS;
70 std::vector< const xAOD::CaloCluster* > orig_cls;
72 auto links = acc_origClusterLinks(*cluster);
73 for (
const auto &link : links) {
74 if (link.dataID() !=
"CaloCalTopoClusters")
75 ATH_MSG_WARNING(
"the clusters in the lepton cannot be converted to CaloCalTopoClusters, the ID is " << link.dataID());
77 orig_cls.push_back(*link);
84 std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> ret;
85 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
86 [&](
auto muon) ->
void {
87 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && static_cast<unsigned>(muon->quality()) <= m_muonWpUi) {
88 if(const xAOD::TrackParticle* idTrk = muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle); idTrk != nullptr)
89 ret.push_back(std::make_pair(idTrk, muon));
97 std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> ret;
98 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
100 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize &&
101 static_cast<unsigned>(muon->quality()) <= m_muonWpUi) {
102 if( const xAOD::CaloCluster* muon_cluster = muon->cluster(); muon_cluster != nullptr) {
103 auto muon_e = muon->e();
104 auto loss_e = muon->floatParameter(xAOD::Muon::ParamDef::ParamEnergyLoss);
105 auto cls_e = muon_cluster->e();
106 auto loss_diff = ((cls_e - loss_e) / (cls_e + loss_e));
107 if (muon_e > cls_e && loss_diff < 0.1 && loss_diff > -0.3) {
108 auto orig_muon_clusters = getOriginalTopoClusters(muon_cluster);
109 for (auto cluster : orig_muon_clusters)
110 ret.push_back(std::make_pair(cluster, muon));
119template<
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 {
120 std::vector<Tlep> ret;
123 [&](
auto tau_trk_link) ->
bool {
125 if(tau_trk_link.isValid()) {
126 auto tau_trk = (*tau_trk_link)->track();
127 auto where = std::find_if(tracks_and_leps.cbegin(), tracks_and_leps.cend(),
128 [&](auto track_and_lep){ return tau_trk == track_and_lep.first; });
129 if(where != tracks_and_leps.cend()) {
130 ATH_MSG_DEBUG(
"track with pt " << tau_trk->pt()/GeV <<
" GeV removed");
131 ret.push_back(where->second);
143template<
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 {
144 std::vector<Tlep> ret;
147 [&](
auto tau_cls_link) ->
bool {
149 if(tau_cls_link.isValid()) {
150 auto tau_cls = static_cast<const xAOD::CaloCluster*>(*tau_cls_link);
151 auto where = std::find_if(clusters_and_leps.cbegin(), clusters_and_leps.cend(),
152 [&](auto cluster_and_lep){ return tau_cls == cluster_and_lep.first; });
153 if(where != clusters_and_leps.cend()) {
154 ATH_MSG_DEBUG(
"cluster with pt " << tau_cls->pt()/GeV <<
" GeV removed");
155 ret.push_back(where->second);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
static const Attributes_t empty
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
ElementLink implementation for ROOT usage.
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
bool match(std::string s1, std::string s2)
match the individual directories of two strings
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TauJet_v3 TauJet
Definition of the current "tau version".
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".