16 return StatusCode::SUCCESS;
23 if (
bool fail_elec = !elec_input_handle.
isValid(), fail_muon = !muon_input_handle.
isValid(); fail_elec || fail_muon) {
24 ATH_MSG_ERROR( (fail_elec ?
"Could not retrieve Electron container with key " + elec_input_handle.
key() :
"") +
25 (fail_muon ?
"\tCould not retrieve Muon container with key " + muon_input_handle.
key() :
"")
27 return StatusCode::FAILURE;
29 auto elec_container = elec_input_handle.
cptr();
30 auto muon_container = muon_input_handle.
cptr();
34 acc_removed_muons(tau).clear();
35 acc_removed_elecs(tau).clear();
37 auto elec_and_tracks = decltype((
getElecAndTrk)(tau, *elec_container))();
38 auto elec_and_clusters = decltype((
getElecAndCls)(tau, *elec_container))();
39 auto muon_and_tracks = decltype((
getMuonAndTrk)(tau, *muon_container))();
40 auto muon_and_clusters = decltype((
getMuonAndCls)(tau, *muon_container))();
46 if(elec_and_tracks.empty() && elec_and_clusters.empty() && muon_and_tracks.empty() && muon_and_clusters.empty())
return StatusCode::SUCCESS;
50 auto trk_removed_muons =
removeTrks(tau_track_links, muon_and_tracks);
51 auto trk_removed_elecs =
removeTrks(tau_track_links, elec_and_tracks);
52 auto cls_removed_muons =
removeClss(tau_cluster_links, muon_and_clusters);
53 auto cls_removed_elecs =
removeClss(tau_cluster_links, elec_and_clusters);
59 auto removed_muons = std::move(trk_removed_muons);
60 auto removed_elecs = std::move(trk_removed_elecs);
61 removed_muons.insert(removed_muons.end(), cls_removed_muons.begin(), cls_removed_muons.end());
62 removed_elecs.insert(removed_elecs.end(), cls_removed_elecs.begin(), cls_removed_elecs.end());
63 auto removed_muons_set =
std::set(removed_muons.begin(), removed_muons.end());
64 auto removed_elecs_set =
std::set(removed_elecs.begin(), removed_elecs.end());
66 for (
auto muon : removed_muons_set ){
69 acc_removed_muons(tau).push_back(link);
71 for (
auto elec : removed_elecs_set){
74 acc_removed_elecs(tau).push_back(link);
77 if (!acc_removed_elecs(tau).
empty() || !acc_removed_muons(tau).
empty())
80 acc_modified(tau) =
static_cast<char>(
true);
82 return StatusCode::SUCCESS;
88 std::vector< const xAOD::CaloCluster* > orig_cls;
90 auto links = acc_origClusterLinks(*cluster);
91 for (
const auto &link :
links) {
92 if (link.dataID() !=
"CaloCalTopoClusters")
93 ATH_MSG_WARNING(
"the clusters in the lepton cannot be converted to CaloCalTopoClusters, the ID is " << link.dataID());
95 orig_cls.push_back(*link);
105 if (
const auto & orig_link = acc_origTracks(*trk); orig_link.isValid()) {
106 if (orig_link.dataID() !=
"InDetTrackParticles")
107 ATH_MSG_WARNING(
"the tracks in the lepton cannot be converted to InDetTrackParticles, the ID is " << orig_link.dataID());
108 orig_trk = *orig_link;
115 std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Electron*>> ret;
116 std::for_each(elec_container.
cbegin(), elec_container.
cend(),
117 [&](
auto elec) ->
void {
118 if(tau.p4().DeltaR(elec->p4()) < m_lepRemovalConeSize && elec->passSelection(m_elecWpStr)) {
119 auto elec_ID_tracks_links = elec->trackParticleLinks();
120 for (const auto &elec_ID_tracks_link : elec_ID_tracks_links) {
121 if (elec_ID_tracks_link.isValid()) {
122 if(auto orig_ele_trk = getOrignalTrackParticle(*elec_ID_tracks_link); orig_ele_trk)
123 ret.push_back(std::make_pair(orig_ele_trk, elec));
133 std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Electron*>> ret;
134 std::for_each(elec_container.
cbegin(), elec_container.
cend(),
135 [&](
auto elec) ->
void {
136 if(tau.p4().DeltaR(elec->p4()) < m_lepRemovalConeSize && elec->passSelection(m_elecWpStr)) {
137 auto elec_cluster_links = elec->caloClusterLinks();
138 for (const auto & elec_cluster_link : elec_cluster_links) {
139 if (elec_cluster_link.isValid()) {
140 auto orig_elec_clusters = getOrignalTopoClusters(*elec_cluster_link);
141 for (auto cluster : orig_elec_clusters){
142 ret.push_back(std::make_pair(cluster, elec));
153 std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> ret;
154 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
155 [&](
auto muon) ->
void {
156 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
157 if(const auto & muon_ID_tracks_link = muon->inDetTrackParticleLink(); muon_ID_tracks_link.isValid())
158 ret.push_back(std::make_pair(std::move(*muon_ID_tracks_link), muon));
166 std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> ret;
167 std::for_each(muon_container.
cbegin(), muon_container.
cend(),
168 [&](
auto muon) ->
void {
169 if(tau.p4().DeltaR(muon->p4()) < m_lepRemovalConeSize && muon->quality() <= m_muonWpUi) {
170 if(const auto & muon_cluster_link = muon->clusterLink(); muon_cluster_link.isValid()) {
171 auto muon_cluster = std::move(*muon_cluster_link);
172 auto muon_e = muon->e();
173 auto loss_e = muon->floatParameter(xAOD::Muon::ParamEnergyLoss);
174 auto cls_e = muon_cluster->e();
175 auto loss_diff = ((cls_e - loss_e) / (cls_e + loss_e));
176 if (muon_e > cls_e && loss_diff < 0.1 && loss_diff > -0.3) {
177 auto orig_muon_clusters = getOrignalTopoClusters(muon_cluster);
178 for (auto cluster : orig_muon_clusters)
179 ret.push_back(std::make_pair(cluster, muon));
188 template<
typename Tlep,
typename Tlinks> std::vector<Tlep>
TauAODLeptonRemovalTool::removeTrks(Tlinks& tau_trk_links, std::vector<std::pair<const xAOD::TrackParticle*, Tlep>>& tracks_and_leps)
const {
189 std::vector<Tlep> ret;
191 std::remove_if(tau_trk_links.begin(), tau_trk_links.end(),
192 [&](
auto tau_trk_link) ->
bool {
194 if(tau_trk_link.isValid()) {
195 auto tau_trk = (*tau_trk_link)->track();
196 auto where = std::find_if(tracks_and_leps.cbegin(), tracks_and_leps.cend(),
197 [&](auto track_and_lep){ return tau_trk == track_and_lep.first; });
198 if(where != tracks_and_leps.cend()) {
199 ATH_MSG_DEBUG(
"track with pt " << tau_trk->pt()/1000 <<
" GeV removed");
200 ret.push_back(where->second);
212 template<
typename Tlep,
typename Tlinks> std::vector<Tlep>
TauAODLeptonRemovalTool::removeClss(Tlinks& tau_cls_links, std::vector<std::pair<const xAOD::CaloCluster*, Tlep>>& clusters_and_leps)
const {
213 std::vector<Tlep> ret;
215 std::remove_if(tau_cls_links.begin(), tau_cls_links.end(),
216 [&](
auto tau_cls_link) ->
bool {
218 if(tau_cls_link.isValid()) {
219 auto tau_cls = static_cast<const xAOD::CaloCluster*>(*tau_cls_link);
220 auto where = std::find_if(clusters_and_leps.cbegin(), clusters_and_leps.cend(),
221 [&](auto cluster_and_lep){ return tau_cls == cluster_and_lep.first; });
222 if(where != clusters_and_leps.cend()) {
223 ATH_MSG_DEBUG(
"cluster with pt " << tau_cls->pt()/1000 <<
" GeV removed");
224 ret.push_back(where->second);