16 return StatusCode::SUCCESS;
22 if (
bool fail_muon = !muon_input_handle.
isValid(); fail_muon) {
23 ATH_MSG_ERROR(
"Could not retrieve Muon container with key " + muon_input_handle.
key() );
24 return StatusCode::FAILURE;
26 auto muon_container = muon_input_handle.
cptr();
29 acc_removed_muons(tau).clear();
31 auto muon_and_tracks = decltype((
getMuonAndTrk)(tau, *muon_container))();
32 auto muon_and_clusters = decltype((
getMuonAndCls)(tau, *muon_container))();
36 if(muon_and_tracks.empty() && muon_and_clusters.empty())
return StatusCode::SUCCESS;
40 auto trk_removed_muons =
removeTrks(tau_track_links, muon_and_tracks);
41 auto cls_removed_muons =
removeClss(tau_cluster_links, muon_and_clusters);
47 auto removed_muons = std::move(trk_removed_muons);
48 removed_muons.insert(removed_muons.end(), cls_removed_muons.begin(), cls_removed_muons.end());
49 auto removed_muons_set =
std::set(removed_muons.begin(), removed_muons.end());
51 for (
auto muon : removed_muons_set ){
54 acc_removed_muons(tau).push_back(link);
57 if (!acc_removed_muons(tau).empty())
60 acc_modified(tau) =
static_cast<char>(
true);
62 return StatusCode::SUCCESS;
68 std::vector< const xAOD::CaloCluster* > orig_cls;
70 auto links = acc_origClusterLinks(*cluster);
71 for (
const auto &link :
links) {
72 if (link.dataID() !=
"CaloCalTopoClusters")
73 ATH_MSG_WARNING(
"the clusters in the lepton cannot be converted to CaloCalTopoClusters, the ID is " << link.dataID());
75 orig_cls.push_back(*link);
82 std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> ret;
83 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
84 [&](
auto muon) ->
void {
85 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
86 if(const auto & muon_ID_tracks_link = muon->inDetTrackParticleLink(); muon_ID_tracks_link.isValid())
87 ret.push_back(std::make_pair(std::move(*muon_ID_tracks_link), muon));
95 std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> ret;
96 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
97 [&](
auto muon) ->
void {
98 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
99 if(const auto & muon_cluster_link = muon->clusterLink(); muon_cluster_link.isValid()) {
100 auto muon_cluster = std::move(*muon_cluster_link);
101 auto muon_e = muon->e();
102 auto loss_e = muon->floatParameter(xAOD::Muon::ParamEnergyLoss);
103 auto cls_e = muon_cluster->e();
104 auto loss_diff = ((cls_e - loss_e) / (cls_e + loss_e));
105 if (muon_e > cls_e && loss_diff < 0.1 && loss_diff > -0.3) {
106 auto orig_muon_clusters = getOriginalTopoClusters(muon_cluster);
107 for (auto cluster : orig_muon_clusters)
108 ret.push_back(std::make_pair(cluster, muon));
117 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 {
118 std::vector<Tlep> ret;
120 std::remove_if(tau_trk_links.begin(), tau_trk_links.end(),
121 [&](
auto tau_trk_link) ->
bool {
123 if(tau_trk_link.isValid()) {
124 auto tau_trk = (*tau_trk_link)->track();
125 auto where = std::find_if(tracks_and_leps.cbegin(), tracks_and_leps.cend(),
126 [&](auto track_and_lep){ return tau_trk == track_and_lep.first; });
127 if(where != tracks_and_leps.cend()) {
128 ATH_MSG_DEBUG(
"track with pt " << tau_trk->pt()/GeV <<
" GeV removed");
129 ret.push_back(where->second);
141 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 {
142 std::vector<Tlep> ret;
144 std::remove_if(tau_cls_links.begin(), tau_cls_links.end(),
145 [&](
auto tau_cls_link) ->
bool {
147 if(tau_cls_link.isValid()) {
148 auto tau_cls = static_cast<const xAOD::CaloCluster*>(*tau_cls_link);
149 auto where = std::find_if(clusters_and_leps.cbegin(), clusters_and_leps.cend(),
150 [&](auto cluster_and_lep){ return tau_cls == cluster_and_lep.first; });
151 if(where != clusters_and_leps.cend()) {
152 ATH_MSG_DEBUG(
"cluster with pt " << tau_cls->pt()/GeV <<
" GeV removed");
153 ret.push_back(where->second);