From 4f67362574545c745d917c4b0bc944e62ed01445 Mon Sep 17 00:00:00 2001 From: pinchun Date: Thu, 18 Apr 2024 19:37:32 +0200 Subject: [PATCH] store the hltobjects for Mass50 triggers Add back a comment that I accidentally removed Fix code-format Fix per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1571187288 Fix per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1571187288 Only store the trigger objects which pass the mass cut, fix per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1571189315 code format Change the default value of InputTag l1EGCand to hltEgammaCandidates, per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1642253760 Fix l1EGCand customisation for HIon HLT menu using HLTEgammaCombMassFilter, per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1645066715 fix Fix per https://github.com/cms-sw/cmssw/pull/44746#discussion_r1647687130 --- .../python/customizeHLTforCMSSW.py | 8 +++ .../Egamma/plugins/HLTEgammaCombMassFilter.cc | 71 +++++++++++++++---- .../Egamma/plugins/HLTEgammaCombMassFilter.h | 10 +++ 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py index d000a4520b165..a42739b7b8067 100644 --- a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py +++ b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py @@ -399,6 +399,13 @@ def customizeHLTfor45063(process): return process +def customizeHLTfor44778(process): + for modLabel in ['hltDoubleEle10Mass50PPOnAAFilter', 'hltDoubleEle15Mass50PPOnAAFilter']: + if hasattr(process, modLabel): + mod = getattr(process, modLabel) + mod.l1EGCand = cms.InputTag('hltEgammaCandidatesPPOnAA') + return process + # CMSSW version specific customizations def customizeHLTforCMSSW(process, menuType="GRun"): @@ -411,5 +418,6 @@ def customizeHLTforCMSSW(process, menuType="GRun"): process = customizeHLTfor44576(process) process = customizeHLTfor45063(process) process = customizeHLTfor45206(process) + process = customizeHLTfor44778(process) return process diff --git a/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.cc b/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.cc index c1407cee16e7d..a7049ecbbfb5c 100644 --- a/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.cc +++ b/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.cc @@ -24,6 +24,7 @@ HLTEgammaCombMassFilter::HLTEgammaCombMassFilter(const edm::ParameterSet& iConfi firstLegLastFilterTag_ = iConfig.getParameter("firstLegLastFilter"); secondLegLastFilterTag_ = iConfig.getParameter("secondLegLastFilter"); minMass_ = iConfig.getParameter("minMass"); + l1EGTag_ = iConfig.getParameter("l1EGCand"); firstLegLastFilterToken_ = consumes(firstLegLastFilterTag_); secondLegLastFilterToken_ = consumes(secondLegLastFilterTag_); } @@ -35,6 +36,7 @@ void HLTEgammaCombMassFilter::fillDescriptions(edm::ConfigurationDescriptions& d makeHLTFilterDescription(desc); desc.add("firstLegLastFilter", edm::InputTag("firstFilter")); desc.add("secondLegLastFilter", edm::InputTag("secondFilter")); + desc.add("l1EGCand", edm::InputTag("hltEgammaCandidates")); desc.add("minMass", -1.0); descriptions.add("hltEgammaCombMassFilter", desc); } @@ -43,32 +45,75 @@ void HLTEgammaCombMassFilter::fillDescriptions(edm::ConfigurationDescriptions& d bool HLTEgammaCombMassFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { - //right, issue 1, we dont know if this is a TriggerElectron, TriggerPhoton, TriggerCluster (should never be a TriggerCluster btw as that implies the 4-vectors are not stored in AOD) + using namespace trigger; + if (saveTags()) { + filterproduct.addCollectionTag(l1EGTag_); + } - //trigger::TriggerObjectType firstLegTrigType; std::vector firstLegP4s; - - //trigger::TriggerObjectType secondLegTrigType; std::vector secondLegP4s; - math::XYZTLorentzVector pairP4; - getP4OfLegCands(iEvent, firstLegLastFilterToken_, firstLegP4s); getP4OfLegCands(iEvent, secondLegLastFilterToken_, secondLegP4s); bool accept = false; - for (auto& firstLegP4 : firstLegP4s) { - for (auto& secondLegP4 : secondLegP4s) { - math::XYZTLorentzVector pairP4 = firstLegP4 + secondLegP4; + std::set addedLegP4s; + + for (size_t i = 0; i < firstLegP4s.size(); i++) { + for (size_t j = 0; j < secondLegP4s.size(); j++) { + // Skip if it's the same object + if (firstLegP4s[i] == secondLegP4s[j]) + continue; + + math::XYZTLorentzVector pairP4 = firstLegP4s[i] + secondLegP4s[j]; double mass = pairP4.M(); - if (mass >= minMass_) + if (mass >= minMass_) { accept = true; + + // Add first leg object if not already added + if (addedLegP4s.insert(firstLegP4s[i]).second) { + addObjectToFilterProduct(iEvent, filterproduct, firstLegLastFilterToken_, i); + } + + // Add second leg object if not already added + if (addedLegP4s.insert(secondLegP4s[j]).second) { + addObjectToFilterProduct(iEvent, filterproduct, secondLegLastFilterToken_, j); + } + } } } return accept; } +void HLTEgammaCombMassFilter::addObjectToFilterProduct( + const edm::Event& iEvent, + trigger::TriggerFilterObjectWithRefs& filterproduct, + const edm::EDGetTokenT& token, + size_t index) { + edm::Handle PrevFilterOutput; + iEvent.getByToken(token, PrevFilterOutput); + + // Get all types of objects + std::vector > phoCandsPrev; + PrevFilterOutput->getObjects(trigger::TriggerPhoton, phoCandsPrev); + std::vector > clusCandsPrev; + PrevFilterOutput->getObjects(trigger::TriggerCluster, clusCandsPrev); + std::vector > eleCandsPrev; + PrevFilterOutput->getObjects(trigger::TriggerElectron, eleCandsPrev); + + // Check which type of object corresponds to the given index + if (index < phoCandsPrev.size()) { + filterproduct.addObject(trigger::TriggerPhoton, phoCandsPrev[index]); + } else if (index < phoCandsPrev.size() + clusCandsPrev.size()) { + filterproduct.addObject(trigger::TriggerCluster, clusCandsPrev[index - phoCandsPrev.size()]); + } else if (index < phoCandsPrev.size() + clusCandsPrev.size() + eleCandsPrev.size()) { + filterproduct.addObject(trigger::TriggerElectron, eleCandsPrev[index - phoCandsPrev.size() - clusCandsPrev.size()]); + } else { + edm::LogWarning("HLTEgammaCombMassFilter") << "Could not find object at index " << index; + } +} + void HLTEgammaCombMassFilter::getP4OfLegCands(const edm::Event& iEvent, const edm::EDGetTokenT& filterToken, std::vector& p4s) { @@ -84,16 +129,16 @@ void HLTEgammaCombMassFilter::getP4OfLegCands(const edm::Event& iEvent, filterOutput->getObjects(trigger::TriggerElectron, eleCands); if (!phoCands.empty()) { //its photons - for (auto& phoCand : phoCands) { + for (auto const& phoCand : phoCands) { p4s.push_back(phoCand->p4()); } } else if (!clusCands.empty()) { //try trigger cluster (should never be this, at the time of writing (17/1/11) this would indicate an error) - for (auto& clusCand : clusCands) { + for (auto const& clusCand : clusCands) { p4s.push_back(clusCand->p4()); } } else if (!eleCands.empty()) { - for (auto& eleCand : eleCands) { + for (auto const& eleCand : eleCands) { p4s.push_back(eleCand->p4()); } } diff --git a/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.h b/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.h index 6a113655d425f..1d8ce651cb662 100644 --- a/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.h +++ b/HLTrigger/Egamma/plugins/HLTEgammaCombMassFilter.h @@ -26,6 +26,10 @@ class HLTEgammaCombMassFilter : public HLTFilter { const edm::EDGetTokenT& filterToken, std::vector& p4s); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void addObjectToFilterProduct(const edm::Event& iEvent, + trigger::TriggerFilterObjectWithRefs& filterproduct, + const edm::EDGetTokenT& token, + size_t index); private: edm::InputTag firstLegLastFilterTag_; @@ -33,6 +37,12 @@ class HLTEgammaCombMassFilter : public HLTFilter { edm::EDGetTokenT firstLegLastFilterToken_; edm::EDGetTokenT secondLegLastFilterToken_; double minMass_; + edm::InputTag l1EGTag_; + struct LorentzVectorComparator { + bool operator()(const math::XYZTLorentzVector& lhs, const math::XYZTLorentzVector& rhs) const { + return lhs.pt() < rhs.pt(); + } + }; }; #endif