diff --git a/Reconstruction/tauRec/python/TauToolHolder.py b/Reconstruction/tauRec/python/TauToolHolder.py index 2ebcef1c2b4add38d4f86ee461e9fab4c02ee05e..ecc08ac4067d34c6f5ba20e11616d64a7a38bc08 100644 --- a/Reconstruction/tauRec/python/TauToolHolder.py +++ b/Reconstruction/tauRec/python/TauToolHolder.py @@ -937,8 +937,8 @@ def TauCombinedTESCfg(flags): def TauAODMuonRemovalCfg(flags): result = ComponentAccumulator() _name = flags.Tau.ActiveConfig.prefix + 'MuonRemoval' - TauAODLeptonRemovalTool = CompFactory.getComp("TauAODLeptonRemovalTool") - myMuonRemoval = TauAODLeptonRemovalTool( name = _name, + TauAODMuonRemovalTool = CompFactory.getComp("TauAODMuonRemovalTool") + myMuonRemoval = TauAODMuonRemovalTool( name = _name, Key_MuonInputContainer = 'Muons', doMuonTrkRm = True, doMuonClsRm = True, diff --git a/Reconstruction/tauRecTools/Root/TauAODLeptonRemovalTool.cxx b/Reconstruction/tauRecTools/Root/TauAODMuonRemovalTool.cxx similarity index 58% rename from Reconstruction/tauRecTools/Root/TauAODLeptonRemovalTool.cxx rename to Reconstruction/tauRecTools/Root/TauAODMuonRemovalTool.cxx index 795eb8af13e03db1d72aca940a48788be0a3ad94..3beed3c9f8747cff4a447a679c071f63c8b86c92 100644 --- a/Reconstruction/tauRecTools/Root/TauAODLeptonRemovalTool.cxx +++ b/Reconstruction/tauRecTools/Root/TauAODMuonRemovalTool.cxx @@ -1,80 +1,58 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ -#include "tauRecTools/TauAODLeptonRemovalTool.h" +#include "tauRecTools/TauAODMuonRemovalTool.h" -TauAODLeptonRemovalTool::TauAODLeptonRemovalTool(const std::string& name): +TauAODMuonRemovalTool::TauAODMuonRemovalTool(const std::string& name): TauRecToolBase(name) { } -StatusCode TauAODLeptonRemovalTool::initialize() { - ATH_CHECK(m_elecInputContainer.initialize()); +StatusCode TauAODMuonRemovalTool::initialize() { ATH_CHECK(m_muonInputContainer.initialize()); - m_elecWpStr = m_strElecIdWpPrefix.value() + m_strMinElecIdWp.value(); m_muonWpUi = m_mapMuonIdWp.at(m_strMinMuonIdWp); return StatusCode::SUCCESS; } -StatusCode TauAODLeptonRemovalTool::execute(xAOD::TauJet& tau) const { - // Read in elec and muon container - SG::ReadHandle<xAOD::ElectronContainer> elec_input_handle(m_elecInputContainer); +StatusCode TauAODMuonRemovalTool::execute(xAOD::TauJet& tau) const { + // Read in muon container SG::ReadHandle<xAOD::MuonContainer> muon_input_handle(m_muonInputContainer); - if (bool fail_elec = !elec_input_handle.isValid(), fail_muon = !muon_input_handle.isValid(); fail_elec || fail_muon) { - ATH_MSG_ERROR( (fail_elec ? "Could not retrieve Electron container with key " + elec_input_handle.key() : "") + - (fail_muon ? "\tCould not retrieve Muon container with key " + muon_input_handle.key() : "") - ); + if (bool fail_muon = !muon_input_handle.isValid(); fail_muon) { + ATH_MSG_ERROR( "Could not retrieve Muon container with key " + muon_input_handle.key() ); return StatusCode::FAILURE; } - auto elec_container = elec_input_handle.cptr(); auto muon_container = muon_input_handle.cptr(); //Add the Aux element as empty vector const SG::AuxElement::Accessor<std::vector<ElementLink<xAOD::MuonContainer>>> acc_removed_muons("removedMuons"); - const SG::AuxElement::Accessor<std::vector<ElementLink<xAOD::ElectronContainer>>> acc_removed_elecs("removedElecs"); acc_removed_muons(tau).clear(); - acc_removed_elecs(tau).clear(); - //get the muon and electron tracks and clusters - auto elec_and_tracks = decltype((getElecAndTrk)(tau, *elec_container))(); - auto elec_and_clusters = decltype((getElecAndCls)(tau, *elec_container))(); + //get the muon tracks and clusters auto muon_and_tracks = decltype((getMuonAndTrk)(tau, *muon_container))(); auto muon_and_clusters = decltype((getMuonAndCls)(tau, *muon_container))(); - if(m_doElecTrkRm) elec_and_tracks = getElecAndTrk(tau, *elec_container); - if(m_doElecClsRm) elec_and_clusters = getElecAndCls(tau, *elec_container); if(m_doMuonTrkRm) muon_and_tracks = getMuonAndTrk(tau, *muon_container); if(m_doMuonClsRm) muon_and_clusters = getMuonAndCls(tau, *muon_container); // if nothing found just give up here - if(elec_and_tracks.empty() && elec_and_clusters.empty() && muon_and_tracks.empty() && muon_and_clusters.empty()) return StatusCode::SUCCESS; + if(muon_and_tracks.empty() && muon_and_clusters.empty()) return StatusCode::SUCCESS; // remove the links from the tau auto tau_track_links = tau.allTauTrackLinksNonConst(); auto tau_cluster_links = tau.clusterLinks(); auto trk_removed_muons = removeTrks(tau_track_links, muon_and_tracks); - auto trk_removed_elecs = removeTrks(tau_track_links, elec_and_tracks); auto cls_removed_muons = removeClss(tau_cluster_links, muon_and_clusters); - auto cls_removed_elecs = removeClss(tau_cluster_links, elec_and_clusters); tau.clearTauTrackLinks(); tau.clearClusterLinks(); tau.setClusterLinks(tau_cluster_links); tau.setAllTauTrackLinks(tau_track_links); //Merge the resulting vector and add them to sets auto removed_muons = std::move(trk_removed_muons); - auto removed_elecs = std::move(trk_removed_elecs); removed_muons.insert(removed_muons.end(), cls_removed_muons.begin(), cls_removed_muons.end()); - removed_elecs.insert(removed_elecs.end(), cls_removed_elecs.begin(), cls_removed_elecs.end()); auto removed_muons_set = std::set(removed_muons.begin(), removed_muons.end()); - auto removed_elecs_set = std::set(removed_elecs.begin(), removed_elecs.end()); //set link to the removed lepton for (auto muon : removed_muons_set ){ ElementLink<xAOD::MuonContainer> link; link.toContainedElement(*muon_container, muon); acc_removed_muons(tau).push_back(link); } - for (auto elec : removed_elecs_set){ - ElementLink<xAOD::ElectronContainer> link; - link.toContainedElement(*elec_container, elec); - acc_removed_elecs(tau).push_back(link); - } //notify the runner alg that the tau was modified - if (!acc_removed_elecs(tau).empty() || !acc_removed_muons(tau).empty()) + if (!acc_removed_muons(tau).empty()) { const SG::AuxElement::Accessor<char> acc_modified("ModifiedInAOD"); acc_modified(tau) = static_cast<char>(true); @@ -83,7 +61,7 @@ StatusCode TauAODLeptonRemovalTool::execute(xAOD::TauJet& tau) const { } //helpers -std::vector<const xAOD::CaloCluster*> TauAODLeptonRemovalTool::getOrignalTopoClusters(const xAOD::CaloCluster *cluster) const { +std::vector<const xAOD::CaloCluster*> TauAODMuonRemovalTool::getOrignalTopoClusters(const xAOD::CaloCluster *cluster) const { static const SG::AuxElement::Accessor<std::vector<ElementLink<xAOD::CaloClusterContainer>>> acc_origClusterLinks("constituentClusterLinks"); std::vector< const xAOD::CaloCluster* > orig_cls; if(acc_origClusterLinks.isAvailable(*cluster)) { @@ -98,7 +76,7 @@ std::vector<const xAOD::CaloCluster*> TauAODLeptonRemovalTool::getOrignalTopoClu return orig_cls; } -const xAOD::TrackParticle* TauAODLeptonRemovalTool::getOrignalTrackParticle(const xAOD::TrackParticle* trk) const { +const xAOD::TrackParticle* TauAODMuonRemovalTool::getOrignalTrackParticle(const xAOD::TrackParticle* trk) const { static const SG::AuxElement::Accessor<ElementLink<xAOD::TrackParticleContainer>> acc_origTracks ("originalTrackParticle"); const xAOD::TrackParticle* orig_trk = nullptr; if(acc_origTracks.isAvailable(*trk)) { @@ -111,45 +89,7 @@ const xAOD::TrackParticle* TauAODLeptonRemovalTool::getOrignalTrackParticle(cons return orig_trk; } -std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Electron*>> TauAODLeptonRemovalTool::getElecAndTrk(const xAOD::TauJet& tau, const xAOD::ElectronContainer& elec_container) const { - std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Electron*>> ret; - std::for_each(elec_container.cbegin(), elec_container.cend(), - [&](auto elec) -> void { - if(tau.p4().DeltaR(elec->p4()) < m_lepRemovalConeSize && elec->passSelection(m_elecWpStr)) { - auto elec_ID_tracks_links = elec->trackParticleLinks(); - for (const auto &elec_ID_tracks_link : elec_ID_tracks_links) { - if (elec_ID_tracks_link.isValid()) { - if(auto orig_ele_trk = getOrignalTrackParticle(*elec_ID_tracks_link); orig_ele_trk) - ret.push_back(std::make_pair(orig_ele_trk, elec)); - } - } - } - } - ); - return ret; -} - -std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Electron*>> TauAODLeptonRemovalTool::getElecAndCls(const xAOD::TauJet& tau, const xAOD::ElectronContainer& elec_container) const { - std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Electron*>> ret; - std::for_each(elec_container.cbegin(), elec_container.cend(), - [&](auto elec) -> void { - if(tau.p4().DeltaR(elec->p4()) < m_lepRemovalConeSize && elec->passSelection(m_elecWpStr)) { - auto elec_cluster_links = elec->caloClusterLinks(); - for (const auto & elec_cluster_link : elec_cluster_links) { - if (elec_cluster_link.isValid()) { - auto orig_elec_clusters = getOrignalTopoClusters(*elec_cluster_link); - for (auto cluster : orig_elec_clusters){ - ret.push_back(std::make_pair(cluster, elec)); - } - } - } - } - } - ); - return ret; -} - -std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> TauAODLeptonRemovalTool::getMuonAndTrk(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const { +std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> TauAODMuonRemovalTool::getMuonAndTrk(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const { std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> ret; std::for_each(muon_container.cbegin(), muon_container.cend(), [&](auto muon) -> void { @@ -162,7 +102,7 @@ std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> TauAODLept return ret; } -std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> TauAODLeptonRemovalTool::getMuonAndCls(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const { +std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> TauAODMuonRemovalTool::getMuonAndCls(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_container) const { std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> ret; std::for_each(muon_container.cbegin(), muon_container.cend(), [&](auto muon) -> void { @@ -185,7 +125,7 @@ std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> TauAODLepton return ret; } -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 { +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 { std::vector<Tlep> ret; tau_trk_links.erase( std::remove_if(tau_trk_links.begin(), tau_trk_links.end(), @@ -209,7 +149,7 @@ template<typename Tlep, typename Tlinks> std::vector<Tlep> TauAODLeptonRemovalTo return ret; } -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 { +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 { std::vector<Tlep> ret; tau_cls_links.erase( std::remove_if(tau_cls_links.begin(), tau_cls_links.end(), diff --git a/Reconstruction/tauRecTools/src/components/tauRecTools_entries.cxx b/Reconstruction/tauRecTools/src/components/tauRecTools_entries.cxx index 0e78bf7d357e50f2de792c78d4ffb30d5469dab2..890f2145bd0333b46c087e4ea4ed15be2ffadc5d 100644 --- a/Reconstruction/tauRecTools/src/components/tauRecTools_entries.cxx +++ b/Reconstruction/tauRecTools/src/components/tauRecTools_entries.cxx @@ -29,7 +29,7 @@ #include "tauRecTools/TauDecayModeNNClassifier.h" #include "tauRecTools/TauVertexedClusterDecorator.h" #include "tauRecTools/TauAODSelector.h" -#include "tauRecTools/TauAODLeptonRemovalTool.h" +#include "tauRecTools/TauAODMuonRemovalTool.h" #include "tauRecTools/TauEleOverlapChecker.h" #ifndef XAOD_ANALYSIS @@ -64,5 +64,5 @@ DECLARE_COMPONENT( TauGNNEvaluator ) DECLARE_COMPONENT( TauDecayModeNNClassifier ) DECLARE_COMPONENT( TauVertexedClusterDecorator ) DECLARE_COMPONENT( TauAODSelector ) -DECLARE_COMPONENT( TauAODLeptonRemovalTool ) +DECLARE_COMPONENT( TauAODMuonRemovalTool ) DECLARE_COMPONENT( TauEleOverlapChecker ) diff --git a/Reconstruction/tauRecTools/tauRecTools/TauAODLeptonRemovalTool.h b/Reconstruction/tauRecTools/tauRecTools/TauAODMuonRemovalTool.h similarity index 58% rename from Reconstruction/tauRecTools/tauRecTools/TauAODLeptonRemovalTool.h rename to Reconstruction/tauRecTools/tauRecTools/TauAODMuonRemovalTool.h index afda9cea44791f022606b9b2045241c7342693ba..c2745b82d91a0f2c1908bb50db4a1320c385ef02 100644 --- a/Reconstruction/tauRecTools/tauRecTools/TauAODLeptonRemovalTool.h +++ b/Reconstruction/tauRecTools/tauRecTools/TauAODMuonRemovalTool.h @@ -1,13 +1,13 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** - * @brief the tool meant to run at AOD level, to remove the lepton found inside the TauJet. + * @brief the tool meant to run at AOD level, to remove the muon found inside the TauJet. */ -#ifndef TAURECTOOLS_TAUAODLEPTONREMOVALTOOL_H -#define TAURECTOOLS_TAUAODLEPTONREMOVALTOOL_H +#ifndef TAURECTOOLS_TAUAODMUONREMOVALTOOL_H +#define TAURECTOOLS_TAUAODMUONREMOVALTOOL_H #include "tauRecTools/TauRecToolBase.h" #include "xAODTau/TauJet.h" @@ -17,37 +17,29 @@ #include "AsgDataHandles/ReadHandleKey.h" #include "AsgTools/PropertyWrapper.h" -class TauAODLeptonRemovalTool : public TauRecToolBase +class TauAODMuonRemovalTool : public TauRecToolBase { public: - ASG_TOOL_CLASS2( TauAODLeptonRemovalTool, TauRecToolBase, ITauToolBase ) - TauAODLeptonRemovalTool(const std::string& type); + ASG_TOOL_CLASS2( TauAODMuonRemovalTool, TauRecToolBase, ITauToolBase ) + TauAODMuonRemovalTool(const std::string& type); virtual StatusCode initialize() override; virtual StatusCode execute(xAOD::TauJet&) const override; private: const std::map<std::string, uint> m_mapMuonIdWp = {{"Tight", 0}, {"Medium", 1}, {"Loose", 2}, {"VeryLoose",3}}; - std::string m_elecWpStr = "DFCommonElectronsLHMedium"; uint m_muonWpUi = 1; SG::ReadHandleKey<xAOD::MuonContainer> m_muonInputContainer{this, "Key_MuonInputContainer", "Muons", "input xAOD muons"}; - SG::ReadHandleKey<xAOD::ElectronContainer> m_elecInputContainer{this, "Key_ElecInputContainer", "Electrons", "input xAOD electrons"}; //properties Gaudi::Property<bool> m_doMuonTrkRm {this, "doMuonTrkRm", false, "Whether to remove the muon tracks from the tau candidate" }; - Gaudi::Property<bool> m_doElecTrkRm {this, "doElecTrkRm", false, "Whether to remove the electron tracks from the tau candidate" }; Gaudi::Property<bool> m_doMuonClsRm {this, "doMuonClsRm", false, "Whether to remove the muon clusters from the tau candidate" }; - Gaudi::Property<bool> m_doElecClsRm {this, "doElecClsRm", false, "Whether to remove the electron clusters from the tau candidate" }; - Gaudi::Property<std::string> m_strMinElecIdWp {this, "elecIDWP", "Medium", "minimum electron identification WP, [VeryLoose, Loose, Medium, Tight]"}; Gaudi::Property<std::string> m_strMinMuonIdWp {this, "muonIDWP", "Medium", "minimum muon identification WP, [VeryLoose, Loose, Medium, Tight]" }; - Gaudi::Property<std::string> m_strElecIdWpPrefix {this, "eleIDWPPrefix", "DFCommonElectronsLH", "The prefix of the electron ID WP, leave to default if in confusion" }; Gaudi::Property<double> m_lepRemovalConeSize{this, "lepRemovalConeSize", 0.6, "The maximum dR between the lepton and the tau" }; //helpers std::vector<const xAOD::CaloCluster*> getOrignalTopoClusters (const xAOD::CaloCluster *cluster) const; const xAOD::TrackParticle* getOrignalTrackParticle(const xAOD::TrackParticle *trk ) const; - std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Electron*>> getElecAndTrk(const xAOD::TauJet& tau, const xAOD::ElectronContainer& elec_cont) const; - std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Electron*>> getElecAndCls(const xAOD::TauJet& tau, const xAOD::ElectronContainer& elec_cont) const; std::vector<std::pair<const xAOD::TrackParticle*, const xAOD::Muon*>> getMuonAndTrk(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_cont) const; std::vector<std::pair<const xAOD::CaloCluster*, const xAOD::Muon*>> getMuonAndCls(const xAOD::TauJet& tau, const xAOD::MuonContainer& muon_cont) const; template<typename Tlep, typename Tlinks> std::vector<Tlep> removeTrks(Tlinks& tau_trk_links, std::vector<std::pair<const xAOD::TrackParticle*, Tlep>>& removings) const; template<typename Tlep, typename Tlinks> std::vector<Tlep> removeClss(Tlinks& tau_cls_links, std::vector<std::pair<const xAOD::CaloCluster*, Tlep>>& clusters_and_leps) const; }; -#endif// TAURECTOOLS_TAUAODLEPTONREMOVALTOOL_H +#endif// TAURECTOOLS_TAUAODMUONREMOVALTOOL_H diff --git a/Reconstruction/tauRecTools/tauRecTools/selection.xml b/Reconstruction/tauRecTools/tauRecTools/selection.xml index 68046cccab35d85a858c475868c3a9a46493fa51..c0f33d6bff8755073a6948bd99d73c32b0626155 100644 --- a/Reconstruction/tauRecTools/tauRecTools/selection.xml +++ b/Reconstruction/tauRecTools/tauRecTools/selection.xml @@ -1,4 +1,4 @@ -<!-- Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration --> +<!-- Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration --> <lcgdict> <class name="TauVertexedClusterDecorator" /> @@ -17,6 +17,6 @@ <class name="TauJetRNNEvaluator" /> <class name="TauDecayModeNNClassifier" /> <class name="TauAODSelector" /> - <class name="TauAODLeptonRemovalTool" /> + <class name="TauAODMuonRemovalTool" /> </lcgdict> diff --git a/Reconstruction/tauRecTools/tauRecTools/tauRecToolsDict.h b/Reconstruction/tauRecTools/tauRecTools/tauRecToolsDict.h index 19d447fb7f8b60445fdaa093fc42acb1523e3a27..0854b2bb0d747508717a915bac17431adb30942b 100644 --- a/Reconstruction/tauRecTools/tauRecTools/tauRecToolsDict.h +++ b/Reconstruction/tauRecTools/tauRecTools/tauRecToolsDict.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration // #ifndef TAURECTOOLS_TAURECTOOLSDICT_H #define TAURECTOOLS_TAURECTOOLSDICT_H @@ -20,6 +20,6 @@ #include "tauRecTools/TauJetRNNEvaluator.h" #include "tauRecTools/TauDecayModeNNClassifier.h" #include "tauRecTools/TauAODSelector.h" -#include "tauRecTools/TauAODLeptonRemovalTool.h" +#include "tauRecTools/TauAODMuonRemovalTool.h" #endif // TAURECTOOLS_TAURECTOOLSDICT_H