From ae012fc13ccb9237002d126f13e0937ede06579e Mon Sep 17 00:00:00 2001 From: Teng Jian Khoo <khoo@cern.ch> Date: Mon, 2 Jul 2018 22:01:31 +0200 Subject: [PATCH] Make OverlapRemovalGenUseAlg more configurable * Allow setting of input collections * Allow disabling of selection flags (in the event that the input containers are preselected) * Allow setting default (fail) value to false rather than true Former-commit-id: b21c562982b870d4433501046af5e91843914491 --- .../OverlapRemovalGenUseAlg.h | 6 + .../Root/OverlapRemovalGenUseAlg.cxx | 169 ++++++++++-------- 2 files changed, 100 insertions(+), 75 deletions(-) diff --git a/PhysicsAnalysis/AnalysisCommon/AssociationUtils/AssociationUtils/OverlapRemovalGenUseAlg.h b/PhysicsAnalysis/AnalysisCommon/AssociationUtils/AssociationUtils/OverlapRemovalGenUseAlg.h index 350e4a41a5c..cabafffe2a6 100644 --- a/PhysicsAnalysis/AnalysisCommon/AssociationUtils/AssociationUtils/OverlapRemovalGenUseAlg.h +++ b/PhysicsAnalysis/AnalysisCommon/AssociationUtils/AssociationUtils/OverlapRemovalGenUseAlg.h @@ -57,11 +57,17 @@ class OverlapRemovalGenUseAlg : public EL::AnaAlgorithm /// Configuration std::string m_selectionLabel; std::string m_overlapLabel; + std::string m_jetKey; std::string m_bJetLabel; + std::string m_electronKey; std::string m_electronLabel; + std::string m_photonKey; std::string m_photonLabel; + std::string m_muonKey; std::string m_muonLabel; + std::string m_tauKey; std::string m_tauLabel; + bool m_defaultValue; double m_ptCut; double m_etaCut; diff --git a/PhysicsAnalysis/AnalysisCommon/AssociationUtils/Root/OverlapRemovalGenUseAlg.cxx b/PhysicsAnalysis/AnalysisCommon/AssociationUtils/Root/OverlapRemovalGenUseAlg.cxx index 7eafdfb3616..b60460a5a9b 100644 --- a/PhysicsAnalysis/AnalysisCommon/AssociationUtils/Root/OverlapRemovalGenUseAlg.cxx +++ b/PhysicsAnalysis/AnalysisCommon/AssociationUtils/Root/OverlapRemovalGenUseAlg.cxx @@ -23,25 +23,37 @@ OverlapRemovalGenUseAlg::OverlapRemovalGenUseAlg(const std::string& name, : EL::AnaAlgorithm(name, svcLoc), m_orTool("OverlapRemovalTool", this) { - declareProperty("OverlapRemovalTool", m_orTool); - declareProperty("SelectionLabel", m_selectionLabel="selected", - "Input label for the OverlapRemovalTool"); - declareProperty("OverlapLabel", m_overlapLabel="overlaps", - "Output label for the OverlapRemovalTool"); - declareProperty("BJetLabel", m_bJetLabel="", - "Input label for b-tagged jets"); - declareProperty("ElectronLabel", m_electronLabel="DFCommonElectronsLHLoose", - "Input label for passing electrons"); - declareProperty("PhotonLabel", m_photonLabel="DFCommonPhotonsIsEMLoose", - "Input label for passing photons"); - declareProperty("MuonLabel", m_muonLabel="DFCommonGoodMuon", - "Input label for passing muons"); - declareProperty("TauLabel", m_tauLabel="DFCommonTausLoose", - "Input label for passing taus"); - declareProperty("PtCut", m_ptCut = 20.0, - "Minimum pt for consideration"); - declareProperty("EtaCut", m_etaCut = 4.5, - "Maximum eta for consideration"); + declareProperty("OverlapRemovalTool", m_orTool); + declareProperty("SelectionLabel", m_selectionLabel="selected", + "Input label for the OverlapRemovalTool"); + declareProperty("OverlapLabel", m_overlapLabel="overlaps", + "Output label for the OverlapRemovalTool"); + declareProperty("DefaultValue", m_defaultValue=true, + "Default value for objects failing OR"); + declareProperty("JetKey", m_jetKey="AntiKt4EMTopoJets", + "StoreGate/TEvent key for jets"); + declareProperty("BJetLabel", m_bJetLabel="", + "Input label for b-tagged jets"); + declareProperty("ElectronKey", m_electronKey="Electrons", + "StoreGate/TEvent key for electrons"); + declareProperty("ElectronLabel", m_electronLabel="DFCommonElectronsLHLoose", + "Input label for passing electrons"); + declareProperty("PhotonKey", m_photonKey="Photons", + "StoreGate/TEvent key for photons"); + declareProperty("PhotonLabel", m_photonLabel="DFCommonPhotonsIsEMLoose", + "Input label for passing photons"); + declareProperty("MuonKey", m_muonKey="Muons", + "StoreGate/TEvent key for muons"); + declareProperty("MuonLabel", m_muonLabel="DFCommonGoodMuon", + "Input label for passing muons"); + declareProperty("TauKey", m_tauKey="TauJets", + "StoreGate/TEvent key for taus"); + declareProperty("TauLabel", m_tauLabel="DFCommonTausLoose", + "Input label for passing taus"); + declareProperty("PtCut", m_ptCut = 20.0, + "Minimum pt for consideration"); + declareProperty("EtaCut", m_etaCut = 4.5, + "Maximum eta for consideration"); } @@ -64,65 +76,70 @@ StatusCode OverlapRemovalGenUseAlg::initialize() //----------------------------------------------------------------------------- StatusCode OverlapRemovalGenUseAlg::execute() { - // Electrons - const xAOD::ElectronContainer* electrons = 0; - ATH_CHECK( evtStore()->retrieve(electrons, "Electrons") ); - applySelection(*electrons); - // Muons - const xAOD::MuonContainer* muons = 0; - ATH_CHECK( evtStore()->retrieve(muons, "Muons") ); - applySelection(*muons); - // Taus - const xAOD::TauJetContainer* taus = 0; - ATH_CHECK( evtStore()->retrieve(taus, "TauJets") ); - applySelection(*taus); - // Jets - const xAOD::JetContainer* jets = 0; - ATH_CHECK( evtStore()->retrieve(jets, "AntiKt4EMTopoJets") ); - applySelection(*jets); - // Photons - const xAOD::PhotonContainer* photons = 0; - ATH_CHECK( evtStore()->retrieve(photons, "Photons") ); - applySelection(*photons); - - // Primary Vertices - const xAOD::VertexContainer* vertices = nullptr; - int checkVtx = 0; - if(evtStore()->retrieve(vertices, "PrimaryVertices").isSuccess()) { - for(auto vtx : *vertices) { - if(vtx->vertexType() == xAOD::VxType::PriVtx) + // Electrons + const xAOD::ElectronContainer* electrons = 0; + ATH_CHECK( evtStore()->retrieve(electrons, m_electronKey) ); + applySelection(*electrons); + // Muons + const xAOD::MuonContainer* muons = 0; + ATH_CHECK( evtStore()->retrieve(muons, m_muonKey) ); + applySelection(*muons); + // Jets + const xAOD::JetContainer* jets = 0; + ATH_CHECK( evtStore()->retrieve(jets, m_jetKey) ); + applySelection(*jets); + // Taus + const xAOD::TauJetContainer* taus = 0; + if(!m_tauKey.empty()) { + ATH_CHECK( evtStore()->retrieve(taus, m_tauKey) ); + applySelection(*taus); + } + // Photons + const xAOD::PhotonContainer* photons = 0; + if(!m_photonKey.empty()) { + ATH_CHECK( evtStore()->retrieve(photons, m_photonKey) ); + applySelection(*photons); + } + + // Primary Vertices + const xAOD::VertexContainer* vertices = nullptr; + int checkVtx = 0; + if(evtStore()->retrieve(vertices, "PrimaryVertices").isSuccess()) { + for(auto vtx : *vertices) { + if(vtx->vertexType() == xAOD::VxType::PriVtx) checkVtx = 1; - } - } + } + } - if(checkVtx==1){ - // Apply the overlap removal - ATH_CHECK( m_orTool->removeOverlaps(electrons, muons, jets, taus, photons) );} - else{ - // Reset all decorations to failing - ATH_MSG_DEBUG("No primary vertices found, cannot do overlap removal! Will return all fails."); - if(electrons) setDefaultDecorations(*electrons); - if(muons) setDefaultDecorations(*muons); - if(jets) setDefaultDecorations(*jets); - if(taus) setDefaultDecorations(*taus); - if(photons) setDefaultDecorations(*photons); - } + if(checkVtx==1){ + // Apply the overlap removal + ATH_CHECK( m_orTool->removeOverlaps(electrons, muons, jets, taus, photons) );} + else{ + // Reset all decorations to failing + ATH_MSG_DEBUG("No primary vertices found, cannot do overlap removal! Will return all fails."); + setDefaultDecorations(*jets); + setDefaultDecorations(*electrons); + setDefaultDecorations(*muons); + if(taus) setDefaultDecorations(*taus); + if(photons) setDefaultDecorations(*photons); + } - // Dump the objects - ATH_MSG_VERBOSE("Dumping results"); + // Dump the objects + ATH_MSG_VERBOSE("Dumping results"); #ifdef XAOD_STANDALONE auto msglvl = msg().level(); #else auto msglvl = msgLevel(); #endif - if(msglvl >= MSG::VERBOSE){ - printObjects(*electrons, "ele"); - printObjects(*muons, "muo"); - printObjects(*taus, "tau"); - printObjects(*jets, "jet"); - printObjects(*photons, "pho");} - - return StatusCode::SUCCESS; + if(msglvl >= MSG::VERBOSE){ + printObjects(*electrons, "ele"); + printObjects(*muons, "muo"); + printObjects(*jets, "jet"); + if(taus) printObjects(*taus, "tau"); + if(photons) printObjects(*photons, "pho"); + } + + return StatusCode::SUCCESS; } //--------------------------------------------------------------------------- @@ -133,7 +150,7 @@ void OverlapRemovalGenUseAlg::setDefaultDecorations(const ContainerType& contain { static ort::inputDecorator_t defaultDec(m_overlapLabel); for(auto obj : container){ - defaultDec(*obj) = 1; //default to all objects being overlaps if we can't get primary vertices. Ensures the event cleaning decision fails. + defaultDec(*obj) = m_defaultValue; //default to all objects being overlaps if we can't get primary vertices. Ensures the event cleaning decision fails. } } @@ -147,6 +164,8 @@ void OverlapRemovalGenUseAlg::applySelection(const ContainerType& container) static ort::inputDecorator_t selDec(m_selectionLabel); for(auto obj : container){ selDec(*obj) = selectObject(*obj); + ATH_MSG_VERBOSE(" Obj " << obj->index() << " of type " << obj->type() + << " selected? " << int(selDec(*obj))); } } //----------------------------------------------------------------------------- @@ -174,7 +193,7 @@ template<> bool OverlapRemovalGenUseAlg::selectObject<xAOD::Electron>(const xAOD::Electron& obj) { const static SG::AuxElement::ConstAccessor<char> acc_ElectronPass(m_electronLabel); - if(m_electronLabel=="") return false; //disable objects with empty labels + if(m_electronLabel.empty()) return true; //disable selection for objects with empty labels if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false; if(!acc_ElectronPass(obj)) return false; return true; @@ -185,7 +204,7 @@ template<> bool OverlapRemovalGenUseAlg::selectObject<xAOD::Photon>(const xAOD::Photon& obj) { const static SG::AuxElement::ConstAccessor<char> acc_PhotonPass(m_photonLabel); - if(m_photonLabel=="") return false; //disable objects with empty labels + if(m_photonLabel.empty()) return true; //disable selection for objects with empty labels if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false; if(!acc_PhotonPass(obj)) return false; return true; @@ -196,7 +215,7 @@ template<> bool OverlapRemovalGenUseAlg::selectObject<xAOD::Muon>(const xAOD::Muon& obj) { const static SG::AuxElement::ConstAccessor<char> acc_MuonPass(m_muonLabel); - if(m_muonLabel=="") return false; //disable objects with empty labels + if(m_muonLabel.empty()) return true; //disable selection for objects with empty labels if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false; if(!acc_MuonPass(obj)) return false; return true; @@ -207,7 +226,7 @@ template<> bool OverlapRemovalGenUseAlg::selectObject<xAOD::TauJet>(const xAOD::TauJet& obj) { const static SG::AuxElement::ConstAccessor<char> acc_TauPass(m_tauLabel); - if(m_tauLabel=="") return false; //disable objects with empty labels + if(m_tauLabel.empty()) return true; //disable selection for objects with empty labels if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false; if(!acc_TauPass(obj)) return false; return true; -- GitLab