14 return StatusCode::SUCCESS;
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;
24 auto muon_container = muon_input_handle.
cptr();
27 acc_removed_muons(tau).clear();
29 auto muon_and_tracks = decltype((
getMuonAndTrk)(tau, *muon_container))();
30 auto muon_and_clusters = decltype((
getMuonAndCls)(tau, *muon_container))();
34 if(muon_and_tracks.empty() && muon_and_clusters.empty())
return StatusCode::SUCCESS;
38 auto trk_removed_muons =
removeTrks(tau_track_links, muon_and_tracks);
39 auto cls_removed_muons =
removeClss(tau_cluster_links, muon_and_clusters);
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());
49 for (
auto muon : removed_muons_set ){
52 acc_removed_muons(tau).push_back(link);
55 if (!acc_removed_muons(tau).empty())
58 acc_modified(tau) =
static_cast<char>(
true);
60 return StatusCode::SUCCESS;
66 std::vector< const xAOD::CaloCluster* > orig_cls;
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());
73 orig_cls.push_back(*link);
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));
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));
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;
118 std::remove_if(tau_trk_links.begin(), tau_trk_links.end(),
119 [&](
auto tau_trk_link) ->
bool {
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);
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;
142 std::remove_if(tau_cls_links.begin(), tau_cls_links.end(),
143 [&](
auto tau_cls_link) ->
bool {
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);