From 53a03bf8f79b297481b3ca01ff75f370f1f3cf76 Mon Sep 17 00:00:00 2001 From: mcitron Date: Mon, 18 Oct 2021 16:35:46 -0700 Subject: [PATCH 01/19] added producer and filter for jet timing trigger --- .../JetMET/interface/HLTCaloJetTimingFilter.h | 60 ++++++++++ .../interface/HLTCaloJetTimingProducer.h | 59 +++++++++ .../JetMET/src/HLTCaloJetTimingFilter.cc | 66 +++++++++++ .../JetMET/src/HLTCaloJetTimingProducer.cc | 112 ++++++++++++++++++ 4 files changed, 297 insertions(+) create mode 100644 HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h create mode 100644 HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h create mode 100644 HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc create mode 100644 HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h new file mode 100644 index 0000000000000..038d087aafe2a --- /dev/null +++ b/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h @@ -0,0 +1,60 @@ +#ifndef HLTCaloJetTimingFilter_h_ +#define HLTCaloJetTimingFilter_h_ + +/** \class HLTCaloJetTimingFilter + * + * \brief This makes selections on the timing and associated ecal cells + * produced by HLTCaloJetTimingProducer + * \author Matthew Citron + * + * + */ + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "HLTrigger/HLTcore/interface/HLTFilter.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" + +namespace edm { + class ConfigurationDescriptions; +} + +// +// class declaration +// +class HLTCaloJetTimingFilter : public HLTFilter { + public: + explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + bool hltFilter(edm::Event&, const edm::EventSetup&, trigger::TriggerFilterObjectWithRefs& filterproduct) const; + private: + + //Input collections + edm::InputTag jetLabel_; + edm::InputTag jetTimeLabel_; + edm::InputTag jetCellsForTimingLabel_; + edm::InputTag jetEcalEtForTimingLabel_; + //Thresholds for selection + unsigned int minJets_; + double jetTimeThresh_; + double jetEcalEtForTimingThresh_; + unsigned int jetCellsForTimingThresh_; + double minPt_; + + edm::EDGetTokenT jetInputToken; + edm::EDGetTokenT> jetTimesInputToken; + edm::EDGetTokenT> jetCellsForTimingInputToken; + edm::EDGetTokenT> jetEcalEtForTimingInputToken; + +}; +#endif // HLTCaloJetTimingFilter_h_ diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h new file mode 100644 index 0000000000000..b8c7d3c582ad5 --- /dev/null +++ b/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h @@ -0,0 +1,59 @@ +#ifndef HLTCaloJetTimingProducer_h_ +#define HLTCaloJetTimingProducer_h_ + +/** \class HLTCaloJetTimingProducer + * + * \brief This produces timing and associated ecal cell information for calo jets + * \author Matthew Citron + * + * + */ + + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" +#include "DataFormats/Common/interface/ValueMap.h" + +#include "DataFormats/JetReco/interface/CaloJetCollection.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" +#include "TLorentzVector.h" +#include "DataFormats/Math/interface/deltaR.h" + +// +// class declaration +// +class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { +public: + explicit HLTCaloJetTimingProducer(const edm::ParameterSet&); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + + // ----------member data --------------------------- + // Input collections + edm::InputTag jetLabel_; + edm::InputTag ecalEBLabel_; + edm::InputTag ecalEELabel_; + // Include endcap jets or only barrel + bool barrelOnly_; + + edm::EDGetTokenT jetInputToken; + edm::EDGetTokenT>> ecalRecHitsEBToken; + edm::EDGetTokenT>> ecalRecHitsEEToken; +}; +#endif // HLTCaloJetTimingProducer_h_ diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc new file mode 100644 index 0000000000000..6115c8bcdcba7 --- /dev/null +++ b/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc @@ -0,0 +1,66 @@ +/** \class HLTCaloJetTimingFilter + * + * See header file for documentation + * + * \author Matthew Citron + * + */ + +#include "HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h" + +//Constructor +HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig){ + jetLabel_= iConfig.getParameter("jets"); + jetTimeLabel_= iConfig.getParameter("jetTimes"); + jetCellsForTimingLabel_= iConfig.getParameter("jetCellsForTiming"); + jetEcalEtForTimingLabel_= iConfig.getParameter("jetEcalEtForTiming"); + minJets_= iConfig.getParameter("minJets"); + jetTimeThresh_ = iConfig.getParameter("jetTimeThresh"); + jetCellsForTimingThresh_ = iConfig.getParameter("jetCellsForTimingThresh"); + jetEcalEtForTimingThresh_ = iConfig.getParameter("jetEcalEtForTimingThresh"); + minPt_ = iConfig.getParameter("minJetPt"); + jetInputToken = consumes>(jetLabel_); + jetTimesInputToken = consumes>(jetTimeLabel_); + jetCellsForTimingInputToken = consumes>(jetCellsForTimingLabel_); + jetEcalEtForTimingInputToken = consumes>(jetEcalEtForTimingLabel_); + //now do what ever initialization is needed +} + +//Filter +bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup,trigger::TriggerFilterObjectWithRefs& filterproduct) const { + bool accept = false; + int ijet = 0; + edm::Handle jets; + iEvent.getByToken(jetInputToken, jets); + edm::Handle> jetTimes; + iEvent.getByToken(jetTimesInputToken, jetTimes); + edm::Handle> jetCellsForTiming; + iEvent.getByToken(jetCellsForTimingInputToken, jetCellsForTiming); + edm::Handle> jetEcalEtForTiming; + iEvent.getByToken(jetEcalEtForTimingInputToken, jetEcalEtForTiming); + unsigned int njets = 0; + for (auto const& c : *jets) { + reco::CaloJetRef calojetref(jets, ijet); + if((*jetTimes)[calojetref] > jetTimeThresh_ && (*jetEcalEtForTiming)[calojetref] > jetEcalEtForTimingThresh_ && (*jetCellsForTiming)[calojetref] > jetCellsForTimingThresh_ && c.pt() > minPt_) njets++; + ijet ++; + } + accept = njets >= minJets_; + return accept; +} + + +// Fill descriptions +void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + makeHLTFilterDescription(desc); + desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); + desc.add("jetTimes", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming")); + desc.add("jetCellsForTiming", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming","jetCellsForTiming")); + desc.add("jetEcalEtForTiming", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming","jetEcalEtForTiming")); + desc.add("minJets", 1); + desc.add("jetTimeThresh", 1.); + desc.add("jetCellsForTimingThresh", 5); + desc.add("jetEcalEtForTimingThresh", 10.); + desc.add("minJetPt", 40.); + descriptions.add("caloJetTimingFilter", desc); +} diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc new file mode 100644 index 0000000000000..c2829eecc563b --- /dev/null +++ b/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc @@ -0,0 +1,112 @@ +/** \class HLTCaloJetTimingProducer + * + * See header file for documentation + * + * \author Matthew Citron + * + */ + +#include "HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h" + +//Constructor +HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) +{ + produces>(""); + produces>("jetCellsForTiming"); + produces>("jetEcalEtForTiming"); + jetLabel_= iConfig.getParameter("jets"); + ecalEBLabel_= iConfig.getParameter("ebRecHitsColl"); + ecalEELabel_= iConfig.getParameter("eeRecHitsColl"); + barrelOnly_ = iConfig.getParameter("barrelOnly"); + jetInputToken = consumes>(jetLabel_); + ecalRecHitsEBToken = consumes>>(ecalEBLabel_); + ecalRecHitsEEToken = consumes>>(ecalEELabel_); +} + +//Producer +void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + using namespace edm; + std::vector jetTimings; + std::vector jetCellsForTiming; + std::vector jetEcalEtForTiming; + Handle jets; + iEvent.getByToken(jetInputToken, jets); + Handle>> ecalRecHitsEB; + iEvent.getByToken(ecalRecHitsEBToken,ecalRecHitsEB); + Handle>> ecalRecHitsEE; + iEvent.getByToken(ecalRecHitsEEToken,ecalRecHitsEE); + edm::ESHandle pG; + iSetup.get().get(pG); + for (auto const& c : *jets) { + int iCell = -1; + float weightedTimeCell = 0; + float totalEmEnergyCell = 0; + unsigned int nCells = 0; + for (EcalRecHitCollection::const_iterator i=ecalRecHitsEB->begin(); i!=ecalRecHitsEB->end(); i++) { + iCell++; + if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || i->checkFlag(EcalRecHit::kDiWeird))) continue; + if (i->energy() < 0.5) continue; + if (i->timeError() <= 0. || i->timeError() > 100) continue; + if (i->time() < -12.5 || i->time() > 12.5) continue; + GlobalPoint p=pG->getPosition(i->detid()); + if (reco::deltaR(c,p) > 0.4) continue; + weightedTimeCell += i->time()*i->energy()*sin(p.theta()); + totalEmEnergyCell += i->energy()*sin(p.theta()); + nCells++; + } + iCell = -1; + if (!barrelOnly_){ + for (EcalRecHitCollection::const_iterator i=ecalRecHitsEE->begin(); i!=ecalRecHitsEE->end(); i++) { + iCell++; + if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || i->checkFlag(EcalRecHit::kDiWeird))) continue; + if (i->energy() < 0.5) continue; + if (i->timeError() <= 0. || i->timeError() > 100) continue; + if (i->time() < -12.5 || i->time() > 12.5) continue; + GlobalPoint p=pG->getPosition(i->detid()); + if (reco::deltaR(c,p) > 0.4) continue; + weightedTimeCell += i->time()*i->energy()*sin(p.theta()); + totalEmEnergyCell += i->energy()*sin(p.theta()); + nCells++; + } + } + //If there is at least one ecal cell passing selection + // calculate timing + if (totalEmEnergyCell > 0){ + jetTimings.push_back(weightedTimeCell/totalEmEnergyCell); + jetEcalEtForTiming.push_back(totalEmEnergyCell); + jetCellsForTiming.push_back(nCells); + } + else{ + jetTimings.push_back(-50); + jetEcalEtForTiming.push_back(totalEmEnergyCell); + jetCellsForTiming.push_back(nCells); + } + } + std::unique_ptr > jetTimings_out(new edm::ValueMap()); + edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); + jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); + jetTimings_filler.fill(); + iEvent.put(std::move(jetTimings_out), ""); + + std::unique_ptr > jetEcalEtForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out); + jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end()); + jetEcalEtForTiming_filler.fill(); + iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming"); + + std::unique_ptr > jetCellsForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetCellsForTiming_filler(*jetCellsForTiming_out); + jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end()); + jetCellsForTiming_filler.fill(); + iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming"); +} + +// Fill descriptions +void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("jets", edm::InputTag("")); + desc.add("barrelOnly", false); + desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit","EcalRecHitsEB")); + desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit","EcalRecHitsEE")); + descriptions.add("caloJetTimingProducer", desc); +} From 72eb2e11488925dbb0218c2ce494181268f1860b Mon Sep 17 00:00:00 2001 From: mcitron Date: Mon, 18 Oct 2021 20:50:10 -0700 Subject: [PATCH 02/19] apply code-format and code-checks changes --- .../JetMET/interface/HLTCaloJetTimingFilter.h | 51 ++--- .../interface/HLTCaloJetTimingProducer.h | 9 +- .../JetMET/src/HLTCaloJetTimingFilter.cc | 99 ++++----- .../JetMET/src/HLTCaloJetTimingProducer.cc | 190 ++++++++++-------- 4 files changed, 183 insertions(+), 166 deletions(-) diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h index 038d087aafe2a..b9d106fb3eb6f 100644 --- a/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h +++ b/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h @@ -1,5 +1,5 @@ -#ifndef HLTCaloJetTimingFilter_h_ -#define HLTCaloJetTimingFilter_h_ +#ifndef HLTCaloJetTimingFilter_h_ +#define HLTCaloJetTimingFilter_h_ /** \class HLTCaloJetTimingFilter * @@ -33,28 +33,29 @@ namespace edm { // class declaration // class HLTCaloJetTimingFilter : public HLTFilter { - public: - explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - bool hltFilter(edm::Event&, const edm::EventSetup&, trigger::TriggerFilterObjectWithRefs& filterproduct) const; - private: - - //Input collections - edm::InputTag jetLabel_; - edm::InputTag jetTimeLabel_; - edm::InputTag jetCellsForTimingLabel_; - edm::InputTag jetEcalEtForTimingLabel_; - //Thresholds for selection - unsigned int minJets_; - double jetTimeThresh_; - double jetEcalEtForTimingThresh_; - unsigned int jetCellsForTimingThresh_; - double minPt_; - - edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT> jetTimesInputToken; - edm::EDGetTokenT> jetCellsForTimingInputToken; - edm::EDGetTokenT> jetEcalEtForTimingInputToken; - +public: + explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + bool hltFilter(edm::Event&, + const edm::EventSetup&, + trigger::TriggerFilterObjectWithRefs& filterproduct) const override; + +private: + //Input collections + edm::InputTag jetLabel_; + edm::InputTag jetTimeLabel_; + edm::InputTag jetCellsForTimingLabel_; + edm::InputTag jetEcalEtForTimingLabel_; + //Thresholds for selection + unsigned int minJets_; + double jetTimeThresh_; + double jetEcalEtForTimingThresh_; + unsigned int jetCellsForTimingThresh_; + double minPt_; + + edm::EDGetTokenT jetInputToken; + edm::EDGetTokenT> jetTimesInputToken; + edm::EDGetTokenT> jetCellsForTimingInputToken; + edm::EDGetTokenT> jetEcalEtForTimingInputToken; }; #endif // HLTCaloJetTimingFilter_h_ diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h index b8c7d3c582ad5..48284d9e7ed6e 100644 --- a/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h +++ b/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h @@ -1,5 +1,5 @@ -#ifndef HLTCaloJetTimingProducer_h_ -#define HLTCaloJetTimingProducer_h_ +#ifndef HLTCaloJetTimingProducer_h_ +#define HLTCaloJetTimingProducer_h_ /** \class HLTCaloJetTimingProducer * @@ -9,7 +9,6 @@ * */ - // system include files #include @@ -53,7 +52,7 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { bool barrelOnly_; edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT>> ecalRecHitsEBToken; - edm::EDGetTokenT>> ecalRecHitsEEToken; + edm::EDGetTokenT>> ecalRecHitsEBToken; + edm::EDGetTokenT>> ecalRecHitsEEToken; }; #endif // HLTCaloJetTimingProducer_h_ diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc index 6115c8bcdcba7..20fd99d496a89 100644 --- a/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc @@ -9,58 +9,63 @@ #include "HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h" //Constructor -HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig){ - jetLabel_= iConfig.getParameter("jets"); - jetTimeLabel_= iConfig.getParameter("jetTimes"); - jetCellsForTimingLabel_= iConfig.getParameter("jetCellsForTiming"); - jetEcalEtForTimingLabel_= iConfig.getParameter("jetEcalEtForTiming"); - minJets_= iConfig.getParameter("minJets"); - jetTimeThresh_ = iConfig.getParameter("jetTimeThresh"); - jetCellsForTimingThresh_ = iConfig.getParameter("jetCellsForTimingThresh"); - jetEcalEtForTimingThresh_ = iConfig.getParameter("jetEcalEtForTimingThresh"); - minPt_ = iConfig.getParameter("minJetPt"); - jetInputToken = consumes>(jetLabel_); - jetTimesInputToken = consumes>(jetTimeLabel_); - jetCellsForTimingInputToken = consumes>(jetCellsForTimingLabel_); - jetEcalEtForTimingInputToken = consumes>(jetEcalEtForTimingLabel_); - //now do what ever initialization is needed +HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) { + jetLabel_ = iConfig.getParameter("jets"); + jetTimeLabel_ = iConfig.getParameter("jetTimes"); + jetCellsForTimingLabel_ = iConfig.getParameter("jetCellsForTiming"); + jetEcalEtForTimingLabel_ = iConfig.getParameter("jetEcalEtForTiming"); + minJets_ = iConfig.getParameter("minJets"); + jetTimeThresh_ = iConfig.getParameter("jetTimeThresh"); + jetCellsForTimingThresh_ = iConfig.getParameter("jetCellsForTimingThresh"); + jetEcalEtForTimingThresh_ = iConfig.getParameter("jetEcalEtForTimingThresh"); + minPt_ = iConfig.getParameter("minJetPt"); + jetInputToken = consumes>(jetLabel_); + jetTimesInputToken = consumes>(jetTimeLabel_); + jetCellsForTimingInputToken = consumes>(jetCellsForTimingLabel_); + jetEcalEtForTimingInputToken = consumes>(jetEcalEtForTimingLabel_); + //now do what ever initialization is needed } //Filter -bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup,trigger::TriggerFilterObjectWithRefs& filterproduct) const { - bool accept = false; - int ijet = 0; - edm::Handle jets; - iEvent.getByToken(jetInputToken, jets); - edm::Handle> jetTimes; - iEvent.getByToken(jetTimesInputToken, jetTimes); - edm::Handle> jetCellsForTiming; - iEvent.getByToken(jetCellsForTimingInputToken, jetCellsForTiming); - edm::Handle> jetEcalEtForTiming; - iEvent.getByToken(jetEcalEtForTimingInputToken, jetEcalEtForTiming); - unsigned int njets = 0; - for (auto const& c : *jets) { - reco::CaloJetRef calojetref(jets, ijet); - if((*jetTimes)[calojetref] > jetTimeThresh_ && (*jetEcalEtForTiming)[calojetref] > jetEcalEtForTimingThresh_ && (*jetCellsForTiming)[calojetref] > jetCellsForTimingThresh_ && c.pt() > minPt_) njets++; - ijet ++; - } - accept = njets >= minJets_; - return accept; +bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, + const edm::EventSetup& iSetup, + trigger::TriggerFilterObjectWithRefs& filterproduct) const { + bool accept = false; + int ijet = 0; + edm::Handle jets; + iEvent.getByToken(jetInputToken, jets); + edm::Handle> jetTimes; + iEvent.getByToken(jetTimesInputToken, jetTimes); + edm::Handle> jetCellsForTiming; + iEvent.getByToken(jetCellsForTimingInputToken, jetCellsForTiming); + edm::Handle> jetEcalEtForTiming; + iEvent.getByToken(jetEcalEtForTimingInputToken, jetEcalEtForTiming); + unsigned int njets = 0; + for (auto const& c : *jets) { + reco::CaloJetRef calojetref(jets, ijet); + if ((*jetTimes)[calojetref] > jetTimeThresh_ && (*jetEcalEtForTiming)[calojetref] > jetEcalEtForTimingThresh_ && + (*jetCellsForTiming)[calojetref] > jetCellsForTimingThresh_ && c.pt() > minPt_) + njets++; + ijet++; + } + accept = njets >= minJets_; + return accept; } - // Fill descriptions void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - makeHLTFilterDescription(desc); - desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); - desc.add("jetTimes", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming")); - desc.add("jetCellsForTiming", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming","jetCellsForTiming")); - desc.add("jetEcalEtForTiming", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming","jetEcalEtForTiming")); - desc.add("minJets", 1); - desc.add("jetTimeThresh", 1.); - desc.add("jetCellsForTimingThresh", 5); - desc.add("jetEcalEtForTimingThresh", 10.); - desc.add("minJetPt", 40.); - descriptions.add("caloJetTimingFilter", desc); + edm::ParameterSetDescription desc; + makeHLTFilterDescription(desc); + desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); + desc.add("jetTimes", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming")); + desc.add("jetCellsForTiming", + edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetCellsForTiming")); + desc.add("jetEcalEtForTiming", + edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetEcalEtForTiming")); + desc.add("minJets", 1); + desc.add("jetTimeThresh", 1.); + desc.add("jetCellsForTimingThresh", 5); + desc.add("jetEcalEtForTimingThresh", 10.); + desc.add("minJetPt", 40.); + descriptions.add("caloJetTimingFilter", desc); } diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc index c2829eecc563b..34904b038ee60 100644 --- a/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc @@ -9,104 +9,116 @@ #include "HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h" //Constructor -HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) -{ - produces>(""); - produces>("jetCellsForTiming"); - produces>("jetEcalEtForTiming"); - jetLabel_= iConfig.getParameter("jets"); - ecalEBLabel_= iConfig.getParameter("ebRecHitsColl"); - ecalEELabel_= iConfig.getParameter("eeRecHitsColl"); - barrelOnly_ = iConfig.getParameter("barrelOnly"); - jetInputToken = consumes>(jetLabel_); - ecalRecHitsEBToken = consumes>>(ecalEBLabel_); - ecalRecHitsEEToken = consumes>>(ecalEELabel_); +HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) { + produces>(""); + produces>("jetCellsForTiming"); + produces>("jetEcalEtForTiming"); + jetLabel_ = iConfig.getParameter("jets"); + ecalEBLabel_ = iConfig.getParameter("ebRecHitsColl"); + ecalEELabel_ = iConfig.getParameter("eeRecHitsColl"); + barrelOnly_ = iConfig.getParameter("barrelOnly"); + jetInputToken = consumes>(jetLabel_); + ecalRecHitsEBToken = consumes>>(ecalEBLabel_); + ecalRecHitsEEToken = consumes>>(ecalEELabel_); } //Producer void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - using namespace edm; - std::vector jetTimings; - std::vector jetCellsForTiming; - std::vector jetEcalEtForTiming; - Handle jets; - iEvent.getByToken(jetInputToken, jets); - Handle>> ecalRecHitsEB; - iEvent.getByToken(ecalRecHitsEBToken,ecalRecHitsEB); - Handle>> ecalRecHitsEE; - iEvent.getByToken(ecalRecHitsEEToken,ecalRecHitsEE); - edm::ESHandle pG; - iSetup.get().get(pG); - for (auto const& c : *jets) { - int iCell = -1; - float weightedTimeCell = 0; - float totalEmEnergyCell = 0; - unsigned int nCells = 0; - for (EcalRecHitCollection::const_iterator i=ecalRecHitsEB->begin(); i!=ecalRecHitsEB->end(); i++) { - iCell++; - if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || i->checkFlag(EcalRecHit::kDiWeird))) continue; - if (i->energy() < 0.5) continue; - if (i->timeError() <= 0. || i->timeError() > 100) continue; - if (i->time() < -12.5 || i->time() > 12.5) continue; - GlobalPoint p=pG->getPosition(i->detid()); - if (reco::deltaR(c,p) > 0.4) continue; - weightedTimeCell += i->time()*i->energy()*sin(p.theta()); - totalEmEnergyCell += i->energy()*sin(p.theta()); - nCells++; - } - iCell = -1; - if (!barrelOnly_){ - for (EcalRecHitCollection::const_iterator i=ecalRecHitsEE->begin(); i!=ecalRecHitsEE->end(); i++) { - iCell++; - if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || i->checkFlag(EcalRecHit::kDiWeird))) continue; - if (i->energy() < 0.5) continue; - if (i->timeError() <= 0. || i->timeError() > 100) continue; - if (i->time() < -12.5 || i->time() > 12.5) continue; - GlobalPoint p=pG->getPosition(i->detid()); - if (reco::deltaR(c,p) > 0.4) continue; - weightedTimeCell += i->time()*i->energy()*sin(p.theta()); - totalEmEnergyCell += i->energy()*sin(p.theta()); - nCells++; - } - } - //If there is at least one ecal cell passing selection - // calculate timing - if (totalEmEnergyCell > 0){ - jetTimings.push_back(weightedTimeCell/totalEmEnergyCell); - jetEcalEtForTiming.push_back(totalEmEnergyCell); - jetCellsForTiming.push_back(nCells); - } - else{ - jetTimings.push_back(-50); - jetEcalEtForTiming.push_back(totalEmEnergyCell); - jetCellsForTiming.push_back(nCells); - } + using namespace edm; + std::vector jetTimings; + std::vector jetCellsForTiming; + std::vector jetEcalEtForTiming; + Handle jets; + iEvent.getByToken(jetInputToken, jets); + Handle>> ecalRecHitsEB; + iEvent.getByToken(ecalRecHitsEBToken, ecalRecHitsEB); + Handle>> ecalRecHitsEE; + iEvent.getByToken(ecalRecHitsEEToken, ecalRecHitsEE); + edm::ESHandle pG; + iSetup.get().get(pG); + for (auto const& c : *jets) { + int iCell = -1; + float weightedTimeCell = 0; + float totalEmEnergyCell = 0; + unsigned int nCells = 0; + for (EcalRecHitCollection::const_iterator i = ecalRecHitsEB->begin(); i != ecalRecHitsEB->end(); i++) { + iCell++; + if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || + i->checkFlag(EcalRecHit::kDiWeird))) + continue; + if (i->energy() < 0.5) + continue; + if (i->timeError() <= 0. || i->timeError() > 100) + continue; + if (i->time() < -12.5 || i->time() > 12.5) + continue; + GlobalPoint p = pG->getPosition(i->detid()); + if (reco::deltaR(c, p) > 0.4) + continue; + weightedTimeCell += i->time() * i->energy() * sin(p.theta()); + totalEmEnergyCell += i->energy() * sin(p.theta()); + nCells++; } - std::unique_ptr > jetTimings_out(new edm::ValueMap()); - edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); - jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); - jetTimings_filler.fill(); - iEvent.put(std::move(jetTimings_out), ""); + iCell = -1; + if (!barrelOnly_) { + for (EcalRecHitCollection::const_iterator i = ecalRecHitsEE->begin(); i != ecalRecHitsEE->end(); i++) { + iCell++; + if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || + i->checkFlag(EcalRecHit::kDiWeird))) + continue; + if (i->energy() < 0.5) + continue; + if (i->timeError() <= 0. || i->timeError() > 100) + continue; + if (i->time() < -12.5 || i->time() > 12.5) + continue; + GlobalPoint p = pG->getPosition(i->detid()); + if (reco::deltaR(c, p) > 0.4) + continue; + weightedTimeCell += i->time() * i->energy() * sin(p.theta()); + totalEmEnergyCell += i->energy() * sin(p.theta()); + nCells++; + } + } + //If there is at least one ecal cell passing selection + // calculate timing + if (totalEmEnergyCell > 0) { + jetTimings.push_back(weightedTimeCell / totalEmEnergyCell); + jetEcalEtForTiming.push_back(totalEmEnergyCell); + jetCellsForTiming.push_back(nCells); + } else { + jetTimings.push_back(-50); + jetEcalEtForTiming.push_back(totalEmEnergyCell); + jetCellsForTiming.push_back(nCells); + } + } + std::unique_ptr> jetTimings_out(new edm::ValueMap()); + edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); + jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); + jetTimings_filler.fill(); + iEvent.put(std::move(jetTimings_out), ""); - std::unique_ptr > jetEcalEtForTiming_out(new edm::ValueMap()); - edm::ValueMap::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out); - jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end()); - jetEcalEtForTiming_filler.fill(); - iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming"); + std::unique_ptr> jetEcalEtForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out); + jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end()); + jetEcalEtForTiming_filler.fill(); + iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming"); - std::unique_ptr > jetCellsForTiming_out(new edm::ValueMap()); - edm::ValueMap::Filler jetCellsForTiming_filler(*jetCellsForTiming_out); - jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end()); - jetCellsForTiming_filler.fill(); - iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming"); + std::unique_ptr> jetCellsForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetCellsForTiming_filler(*jetCellsForTiming_out); + jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end()); + jetCellsForTiming_filler.fill(); + iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming"); } // Fill descriptions void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - desc.add("jets", edm::InputTag("")); - desc.add("barrelOnly", false); - desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit","EcalRecHitsEB")); - desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit","EcalRecHitsEE")); - descriptions.add("caloJetTimingProducer", desc); + edm::ParameterSetDescription desc; + desc.add("jets", edm::InputTag("")); + desc.add("barrelOnly", false); + desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); + desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); + descriptions.add("caloJetTimingProducer", desc); } From 9f7f0d7d91e8fa160976f4956083bdf007da3cd3 Mon Sep 17 00:00:00 2001 From: mcitron Date: Tue, 19 Oct 2021 17:08:11 -0700 Subject: [PATCH 03/19] moved calojet timing filter and producer to plugins --- .../JetMET/interface/HLTCaloJetTimingFilter.h | 61 ------------------- .../interface/HLTCaloJetTimingProducer.h | 58 ------------------ .../HLTCaloJetTimingFilter.cc | 57 ++++++++++++++++- .../HLTCaloJetTimingProducer.cc | 54 +++++++++++++++- 4 files changed, 105 insertions(+), 125 deletions(-) delete mode 100644 HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h delete mode 100644 HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h rename HLTrigger/JetMET/{src => plugins}/HLTCaloJetTimingFilter.cc (66%) rename HLTrigger/JetMET/{src => plugins}/HLTCaloJetTimingProducer.cc (75%) diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h deleted file mode 100644 index b9d106fb3eb6f..0000000000000 --- a/HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef HLTCaloJetTimingFilter_h_ -#define HLTCaloJetTimingFilter_h_ - -/** \class HLTCaloJetTimingFilter - * - * \brief This makes selections on the timing and associated ecal cells - * produced by HLTCaloJetTimingProducer - * \author Matthew Citron - * - * - */ - -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "HLTrigger/HLTcore/interface/HLTFilter.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" - -namespace edm { - class ConfigurationDescriptions; -} - -// -// class declaration -// -class HLTCaloJetTimingFilter : public HLTFilter { -public: - explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - bool hltFilter(edm::Event&, - const edm::EventSetup&, - trigger::TriggerFilterObjectWithRefs& filterproduct) const override; - -private: - //Input collections - edm::InputTag jetLabel_; - edm::InputTag jetTimeLabel_; - edm::InputTag jetCellsForTimingLabel_; - edm::InputTag jetEcalEtForTimingLabel_; - //Thresholds for selection - unsigned int minJets_; - double jetTimeThresh_; - double jetEcalEtForTimingThresh_; - unsigned int jetCellsForTimingThresh_; - double minPt_; - - edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT> jetTimesInputToken; - edm::EDGetTokenT> jetCellsForTimingInputToken; - edm::EDGetTokenT> jetEcalEtForTimingInputToken; -}; -#endif // HLTCaloJetTimingFilter_h_ diff --git a/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h b/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h deleted file mode 100644 index 48284d9e7ed6e..0000000000000 --- a/HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef HLTCaloJetTimingProducer_h_ -#define HLTCaloJetTimingProducer_h_ - -/** \class HLTCaloJetTimingProducer - * - * \brief This produces timing and associated ecal cell information for calo jets - * \author Matthew Citron - * - * - */ - -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" -#include "DataFormats/Common/interface/ValueMap.h" - -#include "DataFormats/JetReco/interface/CaloJetCollection.h" - -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" -#include "TLorentzVector.h" -#include "DataFormats/Math/interface/deltaR.h" - -// -// class declaration -// -class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { -public: - explicit HLTCaloJetTimingProducer(const edm::ParameterSet&); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void produce(edm::Event&, const edm::EventSetup&) override; - - // ----------member data --------------------------- - // Input collections - edm::InputTag jetLabel_; - edm::InputTag ecalEBLabel_; - edm::InputTag ecalEELabel_; - // Include endcap jets or only barrel - bool barrelOnly_; - - edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT>> ecalRecHitsEBToken; - edm::EDGetTokenT>> ecalRecHitsEEToken; -}; -#endif // HLTCaloJetTimingProducer_h_ diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc similarity index 66% rename from HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc rename to HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 20fd99d496a89..4b194e542b315 100644 --- a/HLTrigger/JetMET/src/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -1,12 +1,60 @@ /** \class HLTCaloJetTimingFilter * - * See header file for documentation - * + * \brief This makes selections on the timing and associated ecal cells + * produced by HLTCaloJetTimingProducer * \author Matthew Citron * + * */ -#include "HLTrigger/JetMET/interface/HLTCaloJetTimingFilter.h" +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "HLTrigger/HLTcore/interface/HLTFilter.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" + +namespace edm { + class ConfigurationDescriptions; +} + +// +// class declaration +// +class HLTCaloJetTimingFilter : public HLTFilter { +public: + explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + bool hltFilter(edm::Event&, + const edm::EventSetup&, + trigger::TriggerFilterObjectWithRefs& filterproduct) const override; + +private: + //Input collections + edm::InputTag jetLabel_; + edm::InputTag jetTimeLabel_; + edm::InputTag jetCellsForTimingLabel_; + edm::InputTag jetEcalEtForTimingLabel_; + //Thresholds for selection + unsigned int minJets_; + double jetTimeThresh_; + double jetEcalEtForTimingThresh_; + unsigned int jetCellsForTimingThresh_; + double minPt_; + + edm::EDGetTokenT jetInputToken; + edm::EDGetTokenT> jetTimesInputToken; + edm::EDGetTokenT> jetCellsForTimingInputToken; + edm::EDGetTokenT> jetEcalEtForTimingInputToken; +}; //Constructor HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) { @@ -69,3 +117,6 @@ void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& de desc.add("minJetPt", 40.); descriptions.add("caloJetTimingFilter", desc); } + +// declare this class as a framework plugin +DEFINE_FWK_MODULE(HLTCaloJetTimingFilter); diff --git a/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc similarity index 75% rename from HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc rename to HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 34904b038ee60..5f632ff67fc6f 100644 --- a/HLTrigger/JetMET/src/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -1,12 +1,57 @@ /** \class HLTCaloJetTimingProducer * - * See header file for documentation - * + * \brief This produces timing and associated ecal cell information for calo jets * \author Matthew Citron * + * */ -#include "HLTrigger/JetMET/interface/HLTCaloJetTimingProducer.h" +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" +#include "DataFormats/Common/interface/ValueMap.h" + +#include "DataFormats/JetReco/interface/CaloJetCollection.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" +#include "TLorentzVector.h" +#include "DataFormats/Math/interface/deltaR.h" + +// +// class declaration +// +class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { +public: + explicit HLTCaloJetTimingProducer(const edm::ParameterSet&); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + + // ----------member data --------------------------- + // Input collections + edm::InputTag jetLabel_; + edm::InputTag ecalEBLabel_; + edm::InputTag ecalEELabel_; + // Include endcap jets or only barrel + bool barrelOnly_; + + edm::EDGetTokenT jetInputToken; + edm::EDGetTokenT>> ecalRecHitsEBToken; + edm::EDGetTokenT>> ecalRecHitsEEToken; +}; //Constructor HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) { @@ -122,3 +167,6 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); descriptions.add("caloJetTimingProducer", desc); } + +// declare this class as a framework plugin +DEFINE_FWK_MODULE(HLTCaloJetTimingProducer); From ba46057ac5ecdf8e6a3d7084acb8386c97711606 Mon Sep 17 00:00:00 2001 From: mcitron Date: Tue, 19 Oct 2021 17:13:03 -0700 Subject: [PATCH 04/19] added test config for hlt calo jet timing --- .../JetMET/test/hltCaloJetTimingFilter_cfg.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py diff --git a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py new file mode 100644 index 0000000000000..d71b92c5ad813 --- /dev/null +++ b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py @@ -0,0 +1,50 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("Demo") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.load("Geometry.CMSCommonData.cmsIdealGeometryXML_cfi"); +process.load("Geometry.CaloEventSetup.CaloGeometry_cfi"); +process.load("Geometry.CaloEventSetup.CaloTopology_cfi"); +process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi") +process.load("Configuration.Geometry.GeometryIdeal_cff") +process.load("Configuration.StandardSequences.MagneticField_cff") +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) + +process.source = cms.Source("PoolSource", + fileNames = cms.untracked.vstring( + '/store/mc/Run3Winter21DRMiniAOD/HTo2LongLivedTo4b_MH-250_MFF-60_CTau-1000mm_TuneCP5_14TeV-pythia8/GEN-SIM-RECO/FlatPU30to80FEVT_112X_mcRun3_2021_realistic_v16-v2/130000/058470ca-8aaa-4727-80d8-f42621bafd39.root' + ) +) +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag.globaltag = '120X_mcRun3_2021_realistic_v2' + +process.hltTimingProducer = cms.EDProducer('HLTCaloJetTimingProducer', + jets = cms.InputTag( "ak4CaloJets" ), + ebRecHitsColl = cms.InputTag( 'ecalRecHit','EcalRecHitsEB' ), + eeRecHitsColl = cms.InputTag( 'ecalRecHit','EcalRecHitsEE' ), + barrelOnly = cms.bool(True), +) + +process.hltTimingFilter = cms.EDFilter('HLTCaloJetTimingFilter', + saveTags = cms.bool( True ), + minJets = cms.uint32(1), + minJetPt = cms.double(40.0), + jetTimeThresh = cms.double(1.), + jetCellsForTimingThresh = cms.uint32(5), + jetEcalEtForTimingThresh = cms.double(10.), + jets = cms.InputTag( "ak4CaloJets" ), + jetTimes = cms.InputTag( "hltTimingProducer" ), + jetEcalEtForTiming = cms.InputTag( "hltTimingProducer" ,"jetEcalEtForTiming"), + jetCellsForTiming = cms.InputTag( "hltTimingProducer" ,"jetCellsForTiming"), +) +process.output = cms.OutputModule( "PoolOutputModule", + fileName = cms.untracked.string( "timingOutput.root" ), + ) + +process.p = cms.Path(process.hltTimingProducer+process.hltTimingFilter) +process.Output = cms.EndPath(process.output) From c75d5abd45d97b3592ae2a0f8d1feca37cf37112 Mon Sep 17 00:00:00 2001 From: mcitron Date: Tue, 26 Oct 2021 11:42:47 -0700 Subject: [PATCH 05/19] Apply suggestions from code review Applying all suggested changes for testing/updating as needed Co-authored-by: Marino Missiroli --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 88 ++++++------- .../plugins/HLTCaloJetTimingProducer.cc | 116 ++++++++---------- .../JetMET/test/hltCaloJetTimingFilter_cfg.py | 4 +- 3 files changed, 86 insertions(+), 122 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 4b194e542b315..8eab52e85764e 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -4,7 +4,6 @@ * produced by HLTCaloJetTimingProducer * \author Matthew Citron * - * */ // system include files @@ -38,66 +37,51 @@ class HLTCaloJetTimingFilter : public HLTFilter { trigger::TriggerFilterObjectWithRefs& filterproduct) const override; private: - //Input collections - edm::InputTag jetLabel_; - edm::InputTag jetTimeLabel_; - edm::InputTag jetCellsForTimingLabel_; - edm::InputTag jetEcalEtForTimingLabel_; - //Thresholds for selection - unsigned int minJets_; - double jetTimeThresh_; - double jetEcalEtForTimingThresh_; - unsigned int jetCellsForTimingThresh_; - double minPt_; + // Input collections + const edm::EDGetTokenT jetInputToken_; + const edm::EDGetTokenT> jetTimesInputToken_; + const edm::EDGetTokenT> jetCellsForTimingInputToken_; + const edm::EDGetTokenT> jetEcalEtForTimingInputToken_; - edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT> jetTimesInputToken; - edm::EDGetTokenT> jetCellsForTimingInputToken; - edm::EDGetTokenT> jetEcalEtForTimingInputToken; + // Thresholds for selection + const unsigned int minJets_; + const double jetTimeThresh_; + const double jetEcalEtForTimingThresh_; + const unsigned int jetCellsForTimingThresh_; + const double minPt_; }; //Constructor -HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) { - jetLabel_ = iConfig.getParameter("jets"); - jetTimeLabel_ = iConfig.getParameter("jetTimes"); - jetCellsForTimingLabel_ = iConfig.getParameter("jetCellsForTiming"); - jetEcalEtForTimingLabel_ = iConfig.getParameter("jetEcalEtForTiming"); - minJets_ = iConfig.getParameter("minJets"); - jetTimeThresh_ = iConfig.getParameter("jetTimeThresh"); - jetCellsForTimingThresh_ = iConfig.getParameter("jetCellsForTimingThresh"); - jetEcalEtForTimingThresh_ = iConfig.getParameter("jetEcalEtForTimingThresh"); - minPt_ = iConfig.getParameter("minJetPt"); - jetInputToken = consumes>(jetLabel_); - jetTimesInputToken = consumes>(jetTimeLabel_); - jetCellsForTimingInputToken = consumes>(jetCellsForTimingLabel_); - jetEcalEtForTimingInputToken = consumes>(jetEcalEtForTimingLabel_); - //now do what ever initialization is needed -} +HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, + jetCellsForTimingInputToken_{consumes>(iConfig.getParameter("jetCellsForTiming"))}, + jetEcalEtForTimingInputToken_{consumes>(iConfig.getParameter("jetEcalEtForTiming"))}, + minJets_{iConfig.getParameter("minJets")}, + jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, + jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, + jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, + minPt_{iConfig.getParameter("minJetPt")} +{} //Filter bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { - bool accept = false; - int ijet = 0; - edm::Handle jets; - iEvent.getByToken(jetInputToken, jets); - edm::Handle> jetTimes; - iEvent.getByToken(jetTimesInputToken, jetTimes); - edm::Handle> jetCellsForTiming; - iEvent.getByToken(jetCellsForTimingInputToken, jetCellsForTiming); - edm::Handle> jetEcalEtForTiming; - iEvent.getByToken(jetEcalEtForTimingInputToken, jetEcalEtForTiming); - unsigned int njets = 0; - for (auto const& c : *jets) { - reco::CaloJetRef calojetref(jets, ijet); - if ((*jetTimes)[calojetref] > jetTimeThresh_ && (*jetEcalEtForTiming)[calojetref] > jetEcalEtForTimingThresh_ && - (*jetCellsForTiming)[calojetref] > jetCellsForTimingThresh_ && c.pt() > minPt_) - njets++; - ijet++; + auto const& jets = iEvent.get(jetInputToken_); + auto const& jetTimes = iEvent.get(jetTimesInputToken_); + auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); + auto const& jetEcalEtForTiming = iEvent.getByToken(jetEcalEtForTimingInputToken_); + + uint njets = 0; + for (size_t ijet=0; ijet minPt_ and jetTimes[calojetref] > jetTimeThresh_ and jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) + ++njets; } - accept = njets >= minJets_; - return accept; + + return njets >= minJets_; } // Fill descriptions @@ -115,7 +99,7 @@ void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& de desc.add("jetCellsForTimingThresh", 5); desc.add("jetEcalEtForTimingThresh", 10.); desc.add("minJetPt", 40.); - descriptions.add("caloJetTimingFilter", desc); + descriptions.addWithDefaultLabel(desc); } // declare this class as a framework plugin diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 5f632ff67fc6f..30210c3cce6e3 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -25,8 +25,6 @@ #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" -#include "TLorentzVector.h" #include "DataFormats/Math/interface/deltaR.h" // @@ -40,105 +38,89 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - // ----------member data --------------------------- // Input collections - edm::InputTag jetLabel_; - edm::InputTag ecalEBLabel_; - edm::InputTag ecalEELabel_; - // Include endcap jets or only barrel - bool barrelOnly_; + const edm::EDGetTokenT jetInputToken_; + const edm::EDGetTokenT>> ecalRecHitsEBToken_; + const edm::EDGetTokenT>> ecalRecHitsEEToken_; - edm::EDGetTokenT jetInputToken; - edm::EDGetTokenT>> ecalRecHitsEBToken; - edm::EDGetTokenT>> ecalRecHitsEEToken; + // Include endcap jets or only barrel + const bool barrelOnly_; }; //Constructor -HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) { +HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) : + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + ecalRecHitsEBToken_{consumes>>(iConfig.getParameter("ebRecHitsColl"))}, + ecalRecHitsEEToken_{consumes>>(iConfig.getParameter("eeRecHitsColl"))}, + barrelOnly_{iConfig.getParameter("barrelOnly")} { produces>(""); produces>("jetCellsForTiming"); produces>("jetEcalEtForTiming"); - jetLabel_ = iConfig.getParameter("jets"); - ecalEBLabel_ = iConfig.getParameter("ebRecHitsColl"); - ecalEELabel_ = iConfig.getParameter("eeRecHitsColl"); - barrelOnly_ = iConfig.getParameter("barrelOnly"); - jetInputToken = consumes>(jetLabel_); - ecalRecHitsEBToken = consumes>>(ecalEBLabel_); - ecalRecHitsEEToken = consumes>>(ecalEELabel_); } //Producer void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - using namespace edm; + auto const& jets = iEvent.get(jetInputToken_); + auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); + auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); + std::vector jetTimings; std::vector jetCellsForTiming; std::vector jetEcalEtForTiming; - Handle jets; - iEvent.getByToken(jetInputToken, jets); - Handle>> ecalRecHitsEB; - iEvent.getByToken(ecalRecHitsEBToken, ecalRecHitsEB); - Handle>> ecalRecHitsEE; - iEvent.getByToken(ecalRecHitsEEToken, ecalRecHitsEE); - edm::ESHandle pG; - iSetup.get().get(pG); - for (auto const& c : *jets) { - int iCell = -1; + + jetTimings.reserve(jets.size()); + jetEcalEtForTiming.reserve(jets.size()); + jetCellsForTiming.reserve(jets.size()); + for (auto const& jet : jets) { float weightedTimeCell = 0; float totalEmEnergyCell = 0; unsigned int nCells = 0; - for (EcalRecHitCollection::const_iterator i = ecalRecHitsEB->begin(); i != ecalRecHitsEB->end(); i++) { - iCell++; - if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || - i->checkFlag(EcalRecHit::kDiWeird))) + for (auto const& ecalRH : ecalRecHitsEB) { + if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || + ecalRH.checkFlag(EcalRecHit::kDiWeird)) continue; - if (i->energy() < 0.5) + if (ecalRH.energy() < 0.5) continue; - if (i->timeError() <= 0. || i->timeError() > 100) + if (ecalRH.timeError() <= 0. || ecalRH.timeError() > 100) continue; - if (i->time() < -12.5 || i->time() > 12.5) + if (ecalRH.time() < -12.5 || ecalRH.time() > 12.5) continue; - GlobalPoint p = pG->getPosition(i->detid()); - if (reco::deltaR(c, p) > 0.4) + auto const pos = pG->getPosition(ecalRH.detid()); + if (reco::deltaR2(jet, pos) > 0.16) continue; - weightedTimeCell += i->time() * i->energy() * sin(p.theta()); - totalEmEnergyCell += i->energy() * sin(p.theta()); + weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(p.theta()); + totalEmEnergyCell += ecalRH.energy() * sin(p.theta()); nCells++; } - iCell = -1; + if (!barrelOnly_) { - for (EcalRecHitCollection::const_iterator i = ecalRecHitsEE->begin(); i != ecalRecHitsEE->end(); i++) { - iCell++; - if ((i->checkFlag(EcalRecHit::kSaturated) || i->checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - i->checkFlag(EcalRecHit::kPoorReco) || i->checkFlag(EcalRecHit::kWeird) || - i->checkFlag(EcalRecHit::kDiWeird))) + for (auto const& ecalRH : ecalRecHitsEE) { + if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || + ecalRH.checkFlag(EcalRecHit::kDiWeird)) continue; - if (i->energy() < 0.5) + if (ecalRH.energy() < 0.5) continue; - if (i->timeError() <= 0. || i->timeError() > 100) + if (ecalRH.timeError() <= 0. || ecalRH.timeError() > 100) continue; - if (i->time() < -12.5 || i->time() > 12.5) + if (ecalRH.time() < -12.5 || ecalRH.time() > 12.5) continue; - GlobalPoint p = pG->getPosition(i->detid()); - if (reco::deltaR(c, p) > 0.4) + auto const pos = pG->getPosition(ecalRH.detid()); + if (reco::deltaR2(jet, pos) > 0.16) continue; - weightedTimeCell += i->time() * i->energy() * sin(p.theta()); - totalEmEnergyCell += i->energy() * sin(p.theta()); + weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(p.theta()); + totalEmEnergyCell += ecalRH.energy() * sin(p.theta()); nCells++; } } - //If there is at least one ecal cell passing selection - // calculate timing - if (totalEmEnergyCell > 0) { - jetTimings.push_back(weightedTimeCell / totalEmEnergyCell); - jetEcalEtForTiming.push_back(totalEmEnergyCell); - jetCellsForTiming.push_back(nCells); - } else { - jetTimings.push_back(-50); - jetEcalEtForTiming.push_back(totalEmEnergyCell); - jetCellsForTiming.push_back(nCells); - } + + // If there is at least one ecal cell passing selection, calculate timing + jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell / totalEmEnergyCell : -50); + jetEcalEtForTiming.emplace_back(totalEmEnergyCell); + jetCellsForTiming.emplace_back(nCells); } + std::unique_ptr> jetTimings_out(new edm::ValueMap()); edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); @@ -165,7 +147,7 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("barrelOnly", false); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); - descriptions.add("caloJetTimingProducer", desc); + descriptions.addWithDefaultLabel(desc); } // declare this class as a framework plugin diff --git a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py index d71b92c5ad813..1ab1e6a024fb2 100644 --- a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py +++ b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py @@ -6,8 +6,6 @@ process.load("Geometry.CMSCommonData.cmsIdealGeometryXML_cfi"); process.load("Geometry.CaloEventSetup.CaloGeometry_cfi"); process.load("Geometry.CaloEventSetup.CaloTopology_cfi"); -process.load("FWCore.MessageLogger.MessageLogger_cfi") -process.load("FWCore.MessageLogger.MessageLogger_cfi") process.load("TrackingTools/TransientTrack/TransientTrackBuilder_cfi") process.load("Configuration.Geometry.GeometryIdeal_cff") process.load("Configuration.StandardSequences.MagneticField_cff") @@ -44,7 +42,7 @@ ) process.output = cms.OutputModule( "PoolOutputModule", fileName = cms.untracked.string( "timingOutput.root" ), - ) +) process.p = cms.Path(process.hltTimingProducer+process.hltTimingFilter) process.Output = cms.EndPath(process.output) From 0e2a454c4b7a828bd05c77999583cf02c282500d Mon Sep 17 00:00:00 2001 From: mcitron Date: Tue, 26 Oct 2021 21:32:16 -0700 Subject: [PATCH 06/19] added correct global tag, fixed bugs, added more configurables for calo timing producer --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 13 ++- .../plugins/HLTCaloJetTimingProducer.cc | 106 ++++++++++-------- .../JetMET/test/hltCaloJetTimingFilter_cfg.py | 9 +- 3 files changed, 73 insertions(+), 55 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 8eab52e85764e..d909156b4e85a 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -53,6 +53,7 @@ class HLTCaloJetTimingFilter : public HLTFilter { //Constructor HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : + HLTFilter(iConfig), jetInputToken_{consumes>(iConfig.getParameter("jets"))}, jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, jetCellsForTimingInputToken_{consumes>(iConfig.getParameter("jetCellsForTiming"))}, @@ -62,20 +63,22 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, minPt_{iConfig.getParameter("minJetPt")} -{} +{ +} //Filter bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { - auto const& jets = iEvent.get(jetInputToken_); + edm::Handle jets; + iEvent.getByToken(jetInputToken_, jets); auto const& jetTimes = iEvent.get(jetTimesInputToken_); auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); - auto const& jetEcalEtForTiming = iEvent.getByToken(jetEcalEtForTimingInputToken_); + auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); uint njets = 0; - for (size_t ijet=0; ijetsize(); ++ijet) { + auto const& jet = jets->at(ijet); reco::CaloJetRef const calojetref(jets, ijet); if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) ++njets; diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 30210c3cce6e3..045346601cdc8 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -37,14 +37,22 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; + void jetTimeFromEcalCells(const reco::CaloJet&, const edm::SortedCollection>&,float& ,float& ,uint& ); // Input collections const edm::EDGetTokenT jetInputToken_; const edm::EDGetTokenT>> ecalRecHitsEBToken_; const edm::EDGetTokenT>> ecalRecHitsEEToken_; - // Include endcap jets or only barrel - const bool barrelOnly_; + // Include barrel, endcap jets or both + const bool barrelJets_; + const bool endcapJets_; + const double ecalCellEnergyThresh_; + const double ecalCellTimeThresh_; + const double ecalCellTimeErrorThresh_; + const double matchingRadius2_; + + edm::ESHandle _pG; }; //Constructor @@ -52,15 +60,44 @@ HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iCon jetInputToken_{consumes>(iConfig.getParameter("jets"))}, ecalRecHitsEBToken_{consumes>>(iConfig.getParameter("ebRecHitsColl"))}, ecalRecHitsEEToken_{consumes>>(iConfig.getParameter("eeRecHitsColl"))}, - barrelOnly_{iConfig.getParameter("barrelOnly")} { + barrelJets_{iConfig.getParameter("barrelJets")}, + endcapJets_{iConfig.getParameter("endcapJets")}, + ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, + ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, + ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, + matchingRadius2_{iConfig.getParameter("matchingRadius2")}{ produces>(""); produces>("jetCellsForTiming"); produces>("jetEcalEtForTiming"); } +//calculateJetTime +void HLTCaloJetTimingProducer::jetTimeFromEcalCells(const reco::CaloJet& jet, const edm::SortedCollection>& ecalRecHits,float& weightedTimeCell,float& totalEmEnergyCell,uint& nCells){ + for (auto const& ecalRH : ecalRecHits) { + if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || + ecalRH.checkFlag(EcalRecHit::kDiWeird)) + continue; + if (ecalRH.energy() < ecalCellEnergyThresh_) + continue; + if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_) + continue; + if (fabs(ecalRH.time()) > ecalCellTimeThresh_) + continue; + auto const pos = _pG->getPosition(ecalRH.detid()); + if (reco::deltaR2(jet, pos) > matchingRadius2_) + continue; + weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); + totalEmEnergyCell += ecalRH.energy() * sin(pos.theta()); + nCells++; + } + if (totalEmEnergyCell > 0){weightedTimeCell /= totalEmEnergyCell;} +} + //Producer void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - auto const& jets = iEvent.get(jetInputToken_); + edm::Handle jets; + iEvent.getByToken(jetInputToken_, jets); auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); @@ -68,55 +105,23 @@ void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup std::vector jetCellsForTiming; std::vector jetEcalEtForTiming; - jetTimings.reserve(jets.size()); - jetEcalEtForTiming.reserve(jets.size()); - jetCellsForTiming.reserve(jets.size()); - for (auto const& jet : jets) { + jetTimings.reserve(jets->size()); + jetEcalEtForTiming.reserve(jets->size()); + jetCellsForTiming.reserve(jets->size()); + + iSetup.get().get(_pG); + for (auto const& jet : *jets) { float weightedTimeCell = 0; float totalEmEnergyCell = 0; unsigned int nCells = 0; - for (auto const& ecalRH : ecalRecHitsEB) { - if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || - ecalRH.checkFlag(EcalRecHit::kDiWeird)) - continue; - if (ecalRH.energy() < 0.5) - continue; - if (ecalRH.timeError() <= 0. || ecalRH.timeError() > 100) - continue; - if (ecalRH.time() < -12.5 || ecalRH.time() > 12.5) - continue; - auto const pos = pG->getPosition(ecalRH.detid()); - if (reco::deltaR2(jet, pos) > 0.16) - continue; - weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(p.theta()); - totalEmEnergyCell += ecalRH.energy() * sin(p.theta()); - nCells++; - } - - if (!barrelOnly_) { - for (auto const& ecalRH : ecalRecHitsEE) { - if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || - ecalRH.checkFlag(EcalRecHit::kDiWeird)) - continue; - if (ecalRH.energy() < 0.5) - continue; - if (ecalRH.timeError() <= 0. || ecalRH.timeError() > 100) - continue; - if (ecalRH.time() < -12.5 || ecalRH.time() > 12.5) - continue; - auto const pos = pG->getPosition(ecalRH.detid()); - if (reco::deltaR2(jet, pos) > 0.16) - continue; - weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(p.theta()); - totalEmEnergyCell += ecalRH.energy() * sin(p.theta()); - nCells++; - } + if (barrelJets_) jetTimeFromEcalCells(jet,ecalRecHitsEB, weightedTimeCell, totalEmEnergyCell, nCells); + if (endcapJets_) { + weightedTimeCell *= totalEmEnergyCell; + jetTimeFromEcalCells(jet,ecalRecHitsEE, weightedTimeCell, totalEmEnergyCell, nCells); } // If there is at least one ecal cell passing selection, calculate timing - jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell / totalEmEnergyCell : -50); + jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell : -50); jetEcalEtForTiming.emplace_back(totalEmEnergyCell); jetCellsForTiming.emplace_back(nCells); } @@ -144,7 +149,12 @@ void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("jets", edm::InputTag("")); - desc.add("barrelOnly", false); + desc.add("barrelJets", false); + desc.add("endcapJets", false); + desc.add("ecalCellEnergyThresh",0.5); + desc.add("ecalCellTimeThresh",12.5); + desc.add("ecalCellTimeErrorThresh",100.); + desc.add("matchingRadius2",0.16); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); descriptions.addWithDefaultLabel(desc); diff --git a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py index 1ab1e6a024fb2..1d56c9c451356 100644 --- a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py +++ b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py @@ -19,13 +19,18 @@ ) ) from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag.globaltag = '120X_mcRun3_2021_realistic_v2' +process.GlobalTag.globaltag = '121X_mcRun3_2021_realistic_v1' process.hltTimingProducer = cms.EDProducer('HLTCaloJetTimingProducer', jets = cms.InputTag( "ak4CaloJets" ), ebRecHitsColl = cms.InputTag( 'ecalRecHit','EcalRecHitsEB' ), eeRecHitsColl = cms.InputTag( 'ecalRecHit','EcalRecHitsEE' ), - barrelOnly = cms.bool(True), + barrelJets = cms.bool(True), + endcapJets = cms.bool(False), + ecalCellEnergyThresh =cms.double(0.5), + ecalCellTimeThresh = cms.double(12.5), + ecalCellTimeErrorThresh = cms.double(100.), + matchingRadius2 = cms.double(0.16), ) process.hltTimingFilter = cms.EDFilter('HLTCaloJetTimingFilter', From 5d65413b5de6eb1e1c8aa39433a9de9bbd0df3db Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 10:18:55 -0700 Subject: [PATCH 07/19] Apply matching radius changes Co-authored-by: Marino Missiroli --- HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 045346601cdc8..b72fd1375cdd1 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -65,7 +65,7 @@ HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iCon ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, - matchingRadius2_{iConfig.getParameter("matchingRadius2")}{ + matchingRadius2_{std::pow(iConfig.getParameter("matchingRadius"), 2)}{ produces>(""); produces>("jetCellsForTiming"); produces>("jetEcalEtForTiming"); @@ -154,7 +154,7 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("ecalCellEnergyThresh",0.5); desc.add("ecalCellTimeThresh",12.5); desc.add("ecalCellTimeErrorThresh",100.); - desc.add("matchingRadius2",0.16); + desc.add("matchingRadius",0.4); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); descriptions.addWithDefaultLabel(desc); From a61f130a05a26d500b5d00d2566bb063222703d1 Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 10:27:41 -0700 Subject: [PATCH 08/19] code checks --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 32 ++++--- .../plugins/HLTCaloJetTimingProducer.cc | 91 +++++++++++-------- .../JetMET/test/hltCaloJetTimingFilter_cfg.py | 2 +- 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index d909156b4e85a..3bc97453a1a5a 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -52,19 +52,19 @@ class HLTCaloJetTimingFilter : public HLTFilter { }; //Constructor -HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : - HLTFilter(iConfig), - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, - jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, - jetCellsForTimingInputToken_{consumes>(iConfig.getParameter("jetCellsForTiming"))}, - jetEcalEtForTimingInputToken_{consumes>(iConfig.getParameter("jetEcalEtForTiming"))}, - minJets_{iConfig.getParameter("minJets")}, - jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, - jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, - jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, - minPt_{iConfig.getParameter("minJetPt")} -{ -} +HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) + : HLTFilter(iConfig), + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, + jetCellsForTimingInputToken_{ + consumes>(iConfig.getParameter("jetCellsForTiming"))}, + jetEcalEtForTimingInputToken_{ + consumes>(iConfig.getParameter("jetEcalEtForTiming"))}, + minJets_{iConfig.getParameter("minJets")}, + jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, + jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, + jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, + minPt_{iConfig.getParameter("minJetPt")} {} //Filter bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, @@ -77,10 +77,12 @@ bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); uint njets = 0; - for (size_t ijet=0; ijetsize(); ++ijet) { + for (size_t ijet = 0; ijet < jets->size(); ++ijet) { auto const& jet = jets->at(ijet); reco::CaloJetRef const calojetref(jets, ijet); - if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) + if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and + jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and + jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) ++njets; } diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 045346601cdc8..9fe7ba960ba3b 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -3,7 +3,6 @@ * \brief This produces timing and associated ecal cell information for calo jets * \author Matthew Citron * - * */ // system include files @@ -37,7 +36,11 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - void jetTimeFromEcalCells(const reco::CaloJet&, const edm::SortedCollection>&,float& ,float& ,uint& ); + void jetTimeFromEcalCells(const reco::CaloJet&, + const edm::SortedCollection>&, + float&, + float&, + uint&); // Input collections const edm::EDGetTokenT jetInputToken_; @@ -56,42 +59,51 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { }; //Constructor -HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) : - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, - ecalRecHitsEBToken_{consumes>>(iConfig.getParameter("ebRecHitsColl"))}, - ecalRecHitsEEToken_{consumes>>(iConfig.getParameter("eeRecHitsColl"))}, - barrelJets_{iConfig.getParameter("barrelJets")}, - endcapJets_{iConfig.getParameter("endcapJets")}, - ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, - ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, - ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, - matchingRadius2_{iConfig.getParameter("matchingRadius2")}{ +HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) + : jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + ecalRecHitsEBToken_{consumes>>( + iConfig.getParameter("ebRecHitsColl"))}, + ecalRecHitsEEToken_{consumes>>( + iConfig.getParameter("eeRecHitsColl"))}, + barrelJets_{iConfig.getParameter("barrelJets")}, + endcapJets_{iConfig.getParameter("endcapJets")}, + ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, + ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, + ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, + matchingRadius2_{iConfig.getParameter("matchingRadius2")} { produces>(""); produces>("jetCellsForTiming"); produces>("jetEcalEtForTiming"); } //calculateJetTime -void HLTCaloJetTimingProducer::jetTimeFromEcalCells(const reco::CaloJet& jet, const edm::SortedCollection>& ecalRecHits,float& weightedTimeCell,float& totalEmEnergyCell,uint& nCells){ - for (auto const& ecalRH : ecalRecHits) { - if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || - ecalRH.checkFlag(EcalRecHit::kDiWeird)) - continue; - if (ecalRH.energy() < ecalCellEnergyThresh_) - continue; - if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_) - continue; - if (fabs(ecalRH.time()) > ecalCellTimeThresh_) - continue; - auto const pos = _pG->getPosition(ecalRH.detid()); - if (reco::deltaR2(jet, pos) > matchingRadius2_) - continue; - weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); - totalEmEnergyCell += ecalRH.energy() * sin(pos.theta()); - nCells++; - } - if (totalEmEnergyCell > 0){weightedTimeCell /= totalEmEnergyCell;} +void HLTCaloJetTimingProducer::jetTimeFromEcalCells( + const reco::CaloJet& jet, + const edm::SortedCollection>& ecalRecHits, + float& weightedTimeCell, + float& totalEmEnergyCell, + uint& nCells) { + for (auto const& ecalRH : ecalRecHits) { + if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || + ecalRH.checkFlag(EcalRecHit::kDiWeird)) + continue; + if (ecalRH.energy() < ecalCellEnergyThresh_) + continue; + if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_) + continue; + if (fabs(ecalRH.time()) > ecalCellTimeThresh_) + continue; + auto const pos = _pG->getPosition(ecalRH.detid()); + if (reco::deltaR2(jet, pos) > matchingRadius2_) + continue; + weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); + totalEmEnergyCell += ecalRH.energy() * sin(pos.theta()); + nCells++; + } + if (totalEmEnergyCell > 0) { + weightedTimeCell /= totalEmEnergyCell; + } } //Producer @@ -114,10 +126,11 @@ void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup float weightedTimeCell = 0; float totalEmEnergyCell = 0; unsigned int nCells = 0; - if (barrelJets_) jetTimeFromEcalCells(jet,ecalRecHitsEB, weightedTimeCell, totalEmEnergyCell, nCells); + if (barrelJets_) + jetTimeFromEcalCells(jet, ecalRecHitsEB, weightedTimeCell, totalEmEnergyCell, nCells); if (endcapJets_) { - weightedTimeCell *= totalEmEnergyCell; - jetTimeFromEcalCells(jet,ecalRecHitsEE, weightedTimeCell, totalEmEnergyCell, nCells); + weightedTimeCell *= totalEmEnergyCell; + jetTimeFromEcalCells(jet, ecalRecHitsEE, weightedTimeCell, totalEmEnergyCell, nCells); } // If there is at least one ecal cell passing selection, calculate timing @@ -151,10 +164,10 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("jets", edm::InputTag("")); desc.add("barrelJets", false); desc.add("endcapJets", false); - desc.add("ecalCellEnergyThresh",0.5); - desc.add("ecalCellTimeThresh",12.5); - desc.add("ecalCellTimeErrorThresh",100.); - desc.add("matchingRadius2",0.16); + desc.add("ecalCellEnergyThresh", 0.5); + desc.add("ecalCellTimeThresh", 12.5); + desc.add("ecalCellTimeErrorThresh", 100.); + desc.add("matchingRadius2", 0.16); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); descriptions.addWithDefaultLabel(desc); diff --git a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py index 1d56c9c451356..6152efbfb9da6 100644 --- a/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py +++ b/HLTrigger/JetMET/test/hltCaloJetTimingFilter_cfg.py @@ -30,7 +30,7 @@ ecalCellEnergyThresh =cms.double(0.5), ecalCellTimeThresh = cms.double(12.5), ecalCellTimeErrorThresh = cms.double(100.), - matchingRadius2 = cms.double(0.16), + matchingRadius = cms.double(0.4), ) process.hltTimingFilter = cms.EDFilter('HLTCaloJetTimingFilter', From 64dc08551ccb86bbf0c1b609afd5d3e848a559f8 Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 13:56:23 -0700 Subject: [PATCH 09/19] added dev for filterproduct --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 3bc97453a1a5a..96cba448275dd 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -38,6 +38,7 @@ class HLTCaloJetTimingFilter : public HLTFilter { private: // Input collections + edm::InputTag jetInput_; const edm::EDGetTokenT jetInputToken_; const edm::EDGetTokenT> jetTimesInputToken_; const edm::EDGetTokenT> jetCellsForTimingInputToken_; @@ -54,7 +55,8 @@ class HLTCaloJetTimingFilter : public HLTFilter { //Constructor HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig), - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + jetInput_{iConfig.getParameter("jets")}, + jetInputToken_{consumes>(jetInput_)}, jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, jetCellsForTimingInputToken_{ consumes>(iConfig.getParameter("jetCellsForTiming"))}, @@ -64,7 +66,8 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, - minPt_{iConfig.getParameter("minJetPt")} {} + minPt_{iConfig.getParameter("minJetPt")} { + } //Filter bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, @@ -75,15 +78,24 @@ bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, auto const& jetTimes = iEvent.get(jetTimesInputToken_); auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); + if (saveTags()) + filterproduct.addCollectionTag(jetInput_); uint njets = 0; - for (size_t ijet = 0; ijet < jets->size(); ++ijet) { + uint ijet = 0; + for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { auto const& jet = jets->at(ijet); reco::CaloJetRef const calojetref(jets, ijet); if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and - jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) + jetCellsForTiming[calojetref] > jetCellsForTimingThresh_){ + // Get a ref to the delayed jet + reco::CaloJetRef ref = reco::CaloJetRef(jets, distance(jets->begin(), iterJet)); + //add ref to event + filterproduct.addObject(trigger::TriggerJet, ref); ++njets; + } + ijet++; } return njets >= minJets_; From 0c751ac15f50b21e7264ee3317d73dc97fcd352a Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 14:20:13 -0700 Subject: [PATCH 10/19] code format --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 5 +-- .../plugins/HLTCaloJetTimingProducer.cc | 45 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 96cba448275dd..39b2bd5945422 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -66,8 +66,7 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, - minPt_{iConfig.getParameter("minJetPt")} { - } + minPt_{iConfig.getParameter("minJetPt")} {} //Filter bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, @@ -88,7 +87,7 @@ bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, reco::CaloJetRef const calojetref(jets, ijet); if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and - jetCellsForTiming[calojetref] > jetCellsForTimingThresh_){ + jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) { // Get a ref to the delayed jet reco::CaloJetRef ref = reco::CaloJetRef(jets, distance(jets->begin(), iterJet)); //add ref to event diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index 992b34ae10b76..bbc43bdc058d0 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -41,10 +41,9 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { float&, float&, uint&); - virtual void beginRun(edm::Run const&, - edm::EventSetup const&) override; + void beginRun(edm::Run const&, edm::EventSetup const&) override; - edm::ESHandle _pG; + edm::ESHandle caloGeometry_; const edm::ESGetToken caloGeometryToken_; // Input collections const edm::EDGetTokenT jetInputToken_; @@ -58,29 +57,29 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { const double ecalCellTimeThresh_; const double ecalCellTimeErrorThresh_; const double matchingRadius2_; - }; //Constructor -HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) : - caloGeometryToken_(esConsumes()), - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, - ecalRecHitsEBToken_{consumes>>(iConfig.getParameter("ebRecHitsColl"))}, - ecalRecHitsEEToken_{consumes>>(iConfig.getParameter("eeRecHitsColl"))}, - barrelJets_{iConfig.getParameter("barrelJets")}, - endcapJets_{iConfig.getParameter("endcapJets")}, - ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, - ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, - ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, - matchingRadius2_{std::pow(iConfig.getParameter("matchingRadius"), 2)}{ +HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) + : caloGeometryToken_(esConsumes()), + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + ecalRecHitsEBToken_{consumes>>( + iConfig.getParameter("ebRecHitsColl"))}, + ecalRecHitsEEToken_{consumes>>( + iConfig.getParameter("eeRecHitsColl"))}, + barrelJets_{iConfig.getParameter("barrelJets")}, + endcapJets_{iConfig.getParameter("endcapJets")}, + ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, + ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, + ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, + matchingRadius2_{std::pow(iConfig.getParameter("matchingRadius"), 2)} { produces>(""); produces>("jetCellsForTiming"); produces>("jetEcalEtForTiming"); } -void HLTCaloJetTimingProducer::beginRun(const edm::Run &run, - const edm::EventSetup &iSetup) { - _pG = iSetup.getHandle(caloGeometryToken_); +void HLTCaloJetTimingProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { + caloGeometry_ = iSetup.getHandle(caloGeometryToken_); } //calculateJetTime @@ -101,7 +100,7 @@ void HLTCaloJetTimingProducer::jetTimeFromEcalCells( continue; if (fabs(ecalRH.time()) > ecalCellTimeThresh_) continue; - auto const pos = _pG->getPosition(ecalRH.detid()); + auto const pos = caloGeometry_->getPosition(ecalRH.detid()); if (reco::deltaR2(jet, pos) > matchingRadius2_) continue; weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); @@ -169,10 +168,10 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("jets", edm::InputTag("")); desc.add("barrelJets", false); desc.add("endcapJets", false); - desc.add("ecalCellEnergyThresh",0.5); - desc.add("ecalCellTimeThresh",12.5); - desc.add("ecalCellTimeErrorThresh",100.); - desc.add("matchingRadius",0.4); + desc.add("ecalCellEnergyThresh", 0.5); + desc.add("ecalCellTimeThresh", 12.5); + desc.add("ecalCellTimeErrorThresh", 100.); + desc.add("matchingRadius", 0.4); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); descriptions.addWithDefaultLabel(desc); From b2005d8ea57d462f79054a775147618207c48d26 Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 14:29:54 -0700 Subject: [PATCH 11/19] Small comment update --- HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc index bbc43bdc058d0..ca94a6a22d9f0 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc @@ -53,6 +53,8 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { // Include barrel, endcap jets or both const bool barrelJets_; const bool endcapJets_; + + // Configurables for timing definition const double ecalCellEnergyThresh_; const double ecalCellTimeThresh_; const double ecalCellTimeErrorThresh_; From 9f1aa4d23d4f9bdfce9f2514c832d407b3caefe0 Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 14:40:09 -0700 Subject: [PATCH 12/19] fix input token for jets in filter --- HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index 39b2bd5945422..afe1e0278347e 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -72,8 +72,7 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { - edm::Handle jets; - iEvent.getByToken(jetInputToken_, jets); + auto const jets = iEvent.getHandle(jetInputToken_); auto const& jetTimes = iEvent.get(jetTimesInputToken_); auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); From 790f2af269d4eb90c86a92b1bfdabc34656a9743 Mon Sep 17 00:00:00 2001 From: mcitron Date: Wed, 27 Oct 2021 15:55:25 -0700 Subject: [PATCH 13/19] small code refactor for filter --- .../JetMET/plugins/HLTCaloJetTimingFilter.cc | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc index afe1e0278347e..fde79a3856b43 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc @@ -38,7 +38,7 @@ class HLTCaloJetTimingFilter : public HLTFilter { private: // Input collections - edm::InputTag jetInput_; + const edm::InputTag jetInput_; const edm::EDGetTokenT jetInputToken_; const edm::EDGetTokenT> jetTimesInputToken_; const edm::EDGetTokenT> jetCellsForTimingInputToken_; @@ -72,30 +72,25 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { + if (saveTags()) + filterproduct.addCollectionTag(jetInput_); + auto const jets = iEvent.getHandle(jetInputToken_); auto const& jetTimes = iEvent.get(jetTimesInputToken_); auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); - if (saveTags()) - filterproduct.addCollectionTag(jetInput_); uint njets = 0; - uint ijet = 0; for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - auto const& jet = jets->at(ijet); - reco::CaloJetRef const calojetref(jets, ijet); - if (jet.pt() > minPt_ and jetTimes[calojetref] > jetTimeThresh_ and - jetEcalEtForTiming[calojetref] > jetEcalEtForTimingThresh_ and - jetCellsForTiming[calojetref] > jetCellsForTimingThresh_) { - // Get a ref to the delayed jet - reco::CaloJetRef ref = reco::CaloJetRef(jets, distance(jets->begin(), iterJet)); - //add ref to event - filterproduct.addObject(trigger::TriggerJet, ref); + reco::CaloJetRef const caloJetRef(jets, std::distance(jets->begin(), iterJet)); + if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and + jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and + jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { + // add caloJetRef to the event + filterproduct.addObject(trigger::TriggerJet, caloJetRef); ++njets; } - ijet++; } - return njets >= minJets_; } From 8504e36c238cf7fe6b828d3248b4662cea191385 Mon Sep 17 00:00:00 2001 From: mcitron Date: Thu, 28 Oct 2021 11:48:47 -0700 Subject: [PATCH 14/19] changed to template and instantiate for calojet and pfjet --- ...tTimingFilter.cc => HLTJetTimingFilter.cc} | 32 ++++++++++------ ...ingProducer.cc => HLTJetTimingProducer.cc} | 37 ++++++++++++------- 2 files changed, 45 insertions(+), 24 deletions(-) rename HLTrigger/JetMET/plugins/{HLTCaloJetTimingFilter.cc => HLTJetTimingFilter.cc} (81%) rename HLTrigger/JetMET/plugins/{HLTCaloJetTimingProducer.cc => HLTJetTimingProducer.cc} (85%) diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc similarity index 81% rename from HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc rename to HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc index fde79a3856b43..4c553546dca78 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc @@ -1,7 +1,7 @@ -/** \class HLTCaloJetTimingFilter +/** \class HLTJetTimingFilter * * \brief This makes selections on the timing and associated ecal cells - * produced by HLTCaloJetTimingProducer + * produced by HLTJetTimingProducer * \author Matthew Citron * */ @@ -28,9 +28,10 @@ namespace edm { // // class declaration // -class HLTCaloJetTimingFilter : public HLTFilter { +template +class HLTJetTimingFilter : public HLTFilter { public: - explicit HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig); + explicit HLTJetTimingFilter(const edm::ParameterSet& iConfig); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); bool hltFilter(edm::Event&, const edm::EventSetup&, @@ -39,7 +40,7 @@ class HLTCaloJetTimingFilter : public HLTFilter { private: // Input collections const edm::InputTag jetInput_; - const edm::EDGetTokenT jetInputToken_; + const edm::EDGetTokenT> jetInputToken_; const edm::EDGetTokenT> jetTimesInputToken_; const edm::EDGetTokenT> jetCellsForTimingInputToken_; const edm::EDGetTokenT> jetEcalEtForTimingInputToken_; @@ -53,10 +54,11 @@ class HLTCaloJetTimingFilter : public HLTFilter { }; //Constructor -HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) +template +HLTJetTimingFilter::HLTJetTimingFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig), jetInput_{iConfig.getParameter("jets")}, - jetInputToken_{consumes>(jetInput_)}, + jetInputToken_{consumes>(jetInput_)}, jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, jetCellsForTimingInputToken_{ consumes>(iConfig.getParameter("jetCellsForTiming"))}, @@ -69,9 +71,12 @@ HLTCaloJetTimingFilter::HLTCaloJetTimingFilter(const edm::ParameterSet& iConfig) minPt_{iConfig.getParameter("minJetPt")} {} //Filter -bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, +template +bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { + typedef vector TCollection; + typedef edm::Ref TRef; if (saveTags()) filterproduct.addCollectionTag(jetInput_); @@ -82,7 +87,7 @@ bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, uint njets = 0; for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - reco::CaloJetRef const caloJetRef(jets, std::distance(jets->begin(), iterJet)); + TRef caloJetRef = TRef(jets, std::distance(jets->begin(), iterJet)); if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { @@ -95,7 +100,8 @@ bool HLTCaloJetTimingFilter::hltFilter(edm::Event& iEvent, } // Fill descriptions -void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +template +void HLTJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; makeHLTFilterDescription(desc); desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); @@ -112,5 +118,9 @@ void HLTCaloJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& de descriptions.addWithDefaultLabel(desc); } -// declare this class as a framework plugin +typedef HLTJetTimingFilter HLTCaloJetTimingFilter; +typedef HLTJetTimingFilter HLTPFJetTimingFilter; + +// declare classes as framework plugins DEFINE_FWK_MODULE(HLTCaloJetTimingFilter); +DEFINE_FWK_MODULE(HLTPFJetTimingFilter); diff --git a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc similarity index 85% rename from HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc rename to HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc index ca94a6a22d9f0..9465b5dcbfa38 100644 --- a/HLTrigger/JetMET/plugins/HLTCaloJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc @@ -1,4 +1,4 @@ -/** \class HLTCaloJetTimingProducer +/** \class HLTJetTimingProducer * * \brief This produces timing and associated ecal cell information for calo jets * \author Matthew Citron @@ -20,6 +20,7 @@ #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/JetReco/interface/CaloJetCollection.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" @@ -29,14 +30,15 @@ // // class declaration // -class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { +template +class HLTJetTimingProducer : public edm::stream::EDProducer<> { public: - explicit HLTCaloJetTimingProducer(const edm::ParameterSet&); + explicit HLTJetTimingProducer(const edm::ParameterSet&); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: void produce(edm::Event&, const edm::EventSetup&) override; - void jetTimeFromEcalCells(const reco::CaloJet&, + void jetTimeFromEcalCells(const T&, const edm::SortedCollection>&, float&, float&, @@ -46,7 +48,7 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { edm::ESHandle caloGeometry_; const edm::ESGetToken caloGeometryToken_; // Input collections - const edm::EDGetTokenT jetInputToken_; + const edm::EDGetTokenT> jetInputToken_; const edm::EDGetTokenT>> ecalRecHitsEBToken_; const edm::EDGetTokenT>> ecalRecHitsEEToken_; @@ -62,9 +64,10 @@ class HLTCaloJetTimingProducer : public edm::stream::EDProducer<> { }; //Constructor -HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iConfig) +template +HLTJetTimingProducer::HLTJetTimingProducer(const edm::ParameterSet& iConfig) : caloGeometryToken_(esConsumes()), - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, ecalRecHitsEBToken_{consumes>>( iConfig.getParameter("ebRecHitsColl"))}, ecalRecHitsEEToken_{consumes>>( @@ -80,13 +83,15 @@ HLTCaloJetTimingProducer::HLTCaloJetTimingProducer(const edm::ParameterSet& iCon produces>("jetEcalEtForTiming"); } -void HLTCaloJetTimingProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { +template +void HLTJetTimingProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { caloGeometry_ = iSetup.getHandle(caloGeometryToken_); } //calculateJetTime -void HLTCaloJetTimingProducer::jetTimeFromEcalCells( - const reco::CaloJet& jet, +template +void HLTJetTimingProducer::jetTimeFromEcalCells( + const T& jet, const edm::SortedCollection>& ecalRecHits, float& weightedTimeCell, float& totalEmEnergyCell, @@ -115,7 +120,8 @@ void HLTCaloJetTimingProducer::jetTimeFromEcalCells( } //Producer -void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +template +void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { auto const jets = iEvent.getHandle(jetInputToken_); auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); @@ -165,7 +171,8 @@ void HLTCaloJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup } // Fill descriptions -void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +template +void HLTJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("jets", edm::InputTag("")); desc.add("barrelJets", false); @@ -179,5 +186,9 @@ void HLTCaloJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions.addWithDefaultLabel(desc); } -// declare this class as a framework plugin +typedef HLTJetTimingProducer HLTCaloJetTimingProducer; +typedef HLTJetTimingProducer HLTPFJetTimingProducer; + +// declare classes as framework plugins DEFINE_FWK_MODULE(HLTCaloJetTimingProducer); +DEFINE_FWK_MODULE(HLTPFJetTimingProducer); From 532309be0952e4c7c837ba8cc7ce3a24be3a8f68 Mon Sep 17 00:00:00 2001 From: mcitron Date: Thu, 28 Oct 2021 11:57:58 -0700 Subject: [PATCH 15/19] format updates --- HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc | 6 +++--- HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc index 4c553546dca78..6edf6151c8173 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc @@ -73,8 +73,8 @@ HLTJetTimingFilter::HLTJetTimingFilter(const edm::ParameterSet& iConfig) //Filter template bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, - const edm::EventSetup& iSetup, - trigger::TriggerFilterObjectWithRefs& filterproduct) const { + const edm::EventSetup& iSetup, + trigger::TriggerFilterObjectWithRefs& filterproduct) const { typedef vector TCollection; typedef edm::Ref TRef; if (saveTags()) @@ -87,7 +87,7 @@ bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, uint njets = 0; for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - TRef caloJetRef = TRef(jets, std::distance(jets->begin(), iterJet)); + TRef caloJetRef = TRef(jets, std::distance(jets->begin(), iterJet)); if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc index 9465b5dcbfa38..a9425dfd365e7 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc @@ -38,11 +38,8 @@ class HLTJetTimingProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - void jetTimeFromEcalCells(const T&, - const edm::SortedCollection>&, - float&, - float&, - uint&); + void jetTimeFromEcalCells( + const T&, const edm::SortedCollection>&, float&, float&, uint&); void beginRun(edm::Run const&, edm::EventSetup const&) override; edm::ESHandle caloGeometry_; From ce81a64faeb2c3ca0e70489548062e9b693762f8 Mon Sep 17 00:00:00 2001 From: mcitron Date: Thu, 28 Oct 2021 15:49:08 -0700 Subject: [PATCH 16/19] split plugins and put template in .cc --- .../JetMET/plugins/HLTJetTimingFilter.cc | 120 +----------- HLTrigger/JetMET/plugins/HLTJetTimingFilter.h | 123 ++++++++++++ .../JetMET/plugins/HLTJetTimingProducer.cc | 185 +----------------- .../JetMET/plugins/HLTJetTimingProducer.h | 183 +++++++++++++++++ 4 files changed, 308 insertions(+), 303 deletions(-) create mode 100644 HLTrigger/JetMET/plugins/HLTJetTimingFilter.h create mode 100644 HLTrigger/JetMET/plugins/HLTJetTimingProducer.h diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc index 6edf6151c8173..4c92f33ad1806 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.cc @@ -1,122 +1,4 @@ -/** \class HLTJetTimingFilter - * - * \brief This makes selections on the timing and associated ecal cells - * produced by HLTJetTimingProducer - * \author Matthew Citron - * - */ - -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "HLTrigger/HLTcore/interface/HLTFilter.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" - -namespace edm { - class ConfigurationDescriptions; -} - -// -// class declaration -// -template -class HLTJetTimingFilter : public HLTFilter { -public: - explicit HLTJetTimingFilter(const edm::ParameterSet& iConfig); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - bool hltFilter(edm::Event&, - const edm::EventSetup&, - trigger::TriggerFilterObjectWithRefs& filterproduct) const override; - -private: - // Input collections - const edm::InputTag jetInput_; - const edm::EDGetTokenT> jetInputToken_; - const edm::EDGetTokenT> jetTimesInputToken_; - const edm::EDGetTokenT> jetCellsForTimingInputToken_; - const edm::EDGetTokenT> jetEcalEtForTimingInputToken_; - - // Thresholds for selection - const unsigned int minJets_; - const double jetTimeThresh_; - const double jetEcalEtForTimingThresh_; - const unsigned int jetCellsForTimingThresh_; - const double minPt_; -}; - -//Constructor -template -HLTJetTimingFilter::HLTJetTimingFilter(const edm::ParameterSet& iConfig) - : HLTFilter(iConfig), - jetInput_{iConfig.getParameter("jets")}, - jetInputToken_{consumes>(jetInput_)}, - jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, - jetCellsForTimingInputToken_{ - consumes>(iConfig.getParameter("jetCellsForTiming"))}, - jetEcalEtForTimingInputToken_{ - consumes>(iConfig.getParameter("jetEcalEtForTiming"))}, - minJets_{iConfig.getParameter("minJets")}, - jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, - jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, - jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, - minPt_{iConfig.getParameter("minJetPt")} {} - -//Filter -template -bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, - const edm::EventSetup& iSetup, - trigger::TriggerFilterObjectWithRefs& filterproduct) const { - typedef vector TCollection; - typedef edm::Ref TRef; - if (saveTags()) - filterproduct.addCollectionTag(jetInput_); - - auto const jets = iEvent.getHandle(jetInputToken_); - auto const& jetTimes = iEvent.get(jetTimesInputToken_); - auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); - auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); - - uint njets = 0; - for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - TRef caloJetRef = TRef(jets, std::distance(jets->begin(), iterJet)); - if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and - jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and - jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { - // add caloJetRef to the event - filterproduct.addObject(trigger::TriggerJet, caloJetRef); - ++njets; - } - } - return njets >= minJets_; -} - -// Fill descriptions -template -void HLTJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - makeHLTFilterDescription(desc); - desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); - desc.add("jetTimes", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming")); - desc.add("jetCellsForTiming", - edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetCellsForTiming")); - desc.add("jetEcalEtForTiming", - edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetEcalEtForTiming")); - desc.add("minJets", 1); - desc.add("jetTimeThresh", 1.); - desc.add("jetCellsForTimingThresh", 5); - desc.add("jetEcalEtForTimingThresh", 10.); - desc.add("minJetPt", 40.); - descriptions.addWithDefaultLabel(desc); -} +#include "HLTJetTimingFilter.h" typedef HLTJetTimingFilter HLTCaloJetTimingFilter; typedef HLTJetTimingFilter HLTPFJetTimingFilter; diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h new file mode 100644 index 0000000000000..fc0adf136cd6b --- /dev/null +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h @@ -0,0 +1,123 @@ +/** \class HLTJetTimingFilter + * + * \brief This makes selections on the timing and associated ecal cells + * produced by HLTJetTimingProducer + * \author Matthew Citron + * + */ +#ifndef HLTrigger_JetMET_plugins_HLTJetTimingFilter_h +#define HLTrigger_JetMET_plugins_HLTJetTimingFilter_h + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "HLTrigger/HLTcore/interface/HLTFilter.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" + +namespace edm { + class ConfigurationDescriptions; +} + +// +// class declaration +// +template +class HLTJetTimingFilter : public HLTFilter { +public: + explicit HLTJetTimingFilter(const edm::ParameterSet& iConfig); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + bool hltFilter(edm::Event&, + const edm::EventSetup&, + trigger::TriggerFilterObjectWithRefs& filterproduct) const override; + +private: + // Input collections + const edm::InputTag jetInput_; + const edm::EDGetTokenT> jetInputToken_; + const edm::EDGetTokenT> jetTimesInputToken_; + const edm::EDGetTokenT> jetCellsForTimingInputToken_; + const edm::EDGetTokenT> jetEcalEtForTimingInputToken_; + + // Thresholds for selection + const unsigned int minJets_; + const double jetTimeThresh_; + const double jetEcalEtForTimingThresh_; + const unsigned int jetCellsForTimingThresh_; + const double minPt_; +}; + +//Constructor +template +HLTJetTimingFilter::HLTJetTimingFilter(const edm::ParameterSet& iConfig) + : HLTFilter(iConfig), + jetInput_{iConfig.getParameter("jets")}, + jetInputToken_{consumes>(jetInput_)}, + jetTimesInputToken_{consumes>(iConfig.getParameter("jetTimes"))}, + jetCellsForTimingInputToken_{ + consumes>(iConfig.getParameter("jetCellsForTiming"))}, + jetEcalEtForTimingInputToken_{ + consumes>(iConfig.getParameter("jetEcalEtForTiming"))}, + minJets_{iConfig.getParameter("minJets")}, + jetTimeThresh_{iConfig.getParameter("jetTimeThresh")}, + jetEcalEtForTimingThresh_{iConfig.getParameter("jetEcalEtForTimingThresh")}, + jetCellsForTimingThresh_{iConfig.getParameter("jetCellsForTimingThresh")}, + minPt_{iConfig.getParameter("minJetPt")} {} + +//Filter +template +bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, + const edm::EventSetup& iSetup, + trigger::TriggerFilterObjectWithRefs& filterproduct) const { + // typedef vector TCollection; + // typedef edm::Ref TRef; + if (saveTags()) + filterproduct.addCollectionTag(jetInput_); + + auto const jets = iEvent.getHandle(jetInputToken_); + auto const& jetTimes = iEvent.get(jetTimesInputToken_); + auto const& jetCellsForTiming = iEvent.get(jetCellsForTimingInputToken_); + auto const& jetEcalEtForTiming = iEvent.get(jetEcalEtForTimingInputToken_); + + uint njets = 0; + for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { + edm::Ref> const caloJetRef(jets, std::distance(jets->begin(), iterJet)); + if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and + jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and + jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { + // add caloJetRef to the event + filterproduct.addObject(trigger::TriggerJet, caloJetRef); + ++njets; + } + } + + return njets >= minJets_; +} + +// Fill descriptions +template +void HLTJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + makeHLTFilterDescription(desc); + desc.add("jets", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPt")); + desc.add("jetTimes", edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming")); + desc.add("jetCellsForTiming", + edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetCellsForTiming")); + desc.add("jetEcalEtForTiming", + edm::InputTag("hltDisplacedHLTCaloJetCollectionProducerMidPtTiming", "jetEcalEtForTiming")); + desc.add("minJets", 1); + desc.add("jetTimeThresh", 1.); + desc.add("jetCellsForTimingThresh", 5); + desc.add("jetEcalEtForTimingThresh", 10.); + desc.add("minJetPt", 40.); + descriptions.addWithDefaultLabel(desc); +} + +#endif // HLTrigger_JetMET_plugins_HLTJetTimingFilter_h diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc index a9425dfd365e7..48fd4e9c7848c 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.cc @@ -1,187 +1,4 @@ -/** \class HLTJetTimingProducer - * - * \brief This produces timing and associated ecal cell information for calo jets - * \author Matthew Citron - * - */ - -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" -#include "DataFormats/Common/interface/ValueMap.h" - -#include "DataFormats/JetReco/interface/CaloJetCollection.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" - -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/Math/interface/deltaR.h" - -// -// class declaration -// -template -class HLTJetTimingProducer : public edm::stream::EDProducer<> { -public: - explicit HLTJetTimingProducer(const edm::ParameterSet&); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void produce(edm::Event&, const edm::EventSetup&) override; - void jetTimeFromEcalCells( - const T&, const edm::SortedCollection>&, float&, float&, uint&); - void beginRun(edm::Run const&, edm::EventSetup const&) override; - - edm::ESHandle caloGeometry_; - const edm::ESGetToken caloGeometryToken_; - // Input collections - const edm::EDGetTokenT> jetInputToken_; - const edm::EDGetTokenT>> ecalRecHitsEBToken_; - const edm::EDGetTokenT>> ecalRecHitsEEToken_; - - // Include barrel, endcap jets or both - const bool barrelJets_; - const bool endcapJets_; - - // Configurables for timing definition - const double ecalCellEnergyThresh_; - const double ecalCellTimeThresh_; - const double ecalCellTimeErrorThresh_; - const double matchingRadius2_; -}; - -//Constructor -template -HLTJetTimingProducer::HLTJetTimingProducer(const edm::ParameterSet& iConfig) - : caloGeometryToken_(esConsumes()), - jetInputToken_{consumes>(iConfig.getParameter("jets"))}, - ecalRecHitsEBToken_{consumes>>( - iConfig.getParameter("ebRecHitsColl"))}, - ecalRecHitsEEToken_{consumes>>( - iConfig.getParameter("eeRecHitsColl"))}, - barrelJets_{iConfig.getParameter("barrelJets")}, - endcapJets_{iConfig.getParameter("endcapJets")}, - ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, - ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, - ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, - matchingRadius2_{std::pow(iConfig.getParameter("matchingRadius"), 2)} { - produces>(""); - produces>("jetCellsForTiming"); - produces>("jetEcalEtForTiming"); -} - -template -void HLTJetTimingProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { - caloGeometry_ = iSetup.getHandle(caloGeometryToken_); -} - -//calculateJetTime -template -void HLTJetTimingProducer::jetTimeFromEcalCells( - const T& jet, - const edm::SortedCollection>& ecalRecHits, - float& weightedTimeCell, - float& totalEmEnergyCell, - uint& nCells) { - for (auto const& ecalRH : ecalRecHits) { - if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || - ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || - ecalRH.checkFlag(EcalRecHit::kDiWeird)) - continue; - if (ecalRH.energy() < ecalCellEnergyThresh_) - continue; - if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_) - continue; - if (fabs(ecalRH.time()) > ecalCellTimeThresh_) - continue; - auto const pos = caloGeometry_->getPosition(ecalRH.detid()); - if (reco::deltaR2(jet, pos) > matchingRadius2_) - continue; - weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); - totalEmEnergyCell += ecalRH.energy() * sin(pos.theta()); - nCells++; - } - if (totalEmEnergyCell > 0) { - weightedTimeCell /= totalEmEnergyCell; - } -} - -//Producer -template -void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - auto const jets = iEvent.getHandle(jetInputToken_); - auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); - auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); - - std::vector jetTimings; - std::vector jetCellsForTiming; - std::vector jetEcalEtForTiming; - - jetTimings.reserve(jets->size()); - jetEcalEtForTiming.reserve(jets->size()); - jetCellsForTiming.reserve(jets->size()); - - for (auto const& jet : *jets) { - float weightedTimeCell = 0; - float totalEmEnergyCell = 0; - unsigned int nCells = 0; - if (barrelJets_) - jetTimeFromEcalCells(jet, ecalRecHitsEB, weightedTimeCell, totalEmEnergyCell, nCells); - if (endcapJets_) { - weightedTimeCell *= totalEmEnergyCell; - jetTimeFromEcalCells(jet, ecalRecHitsEE, weightedTimeCell, totalEmEnergyCell, nCells); - } - - // If there is at least one ecal cell passing selection, calculate timing - jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell : -50); - jetEcalEtForTiming.emplace_back(totalEmEnergyCell); - jetCellsForTiming.emplace_back(nCells); - } - - std::unique_ptr> jetTimings_out(new edm::ValueMap()); - edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); - jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); - jetTimings_filler.fill(); - iEvent.put(std::move(jetTimings_out), ""); - - std::unique_ptr> jetEcalEtForTiming_out(new edm::ValueMap()); - edm::ValueMap::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out); - jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end()); - jetEcalEtForTiming_filler.fill(); - iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming"); - - std::unique_ptr> jetCellsForTiming_out(new edm::ValueMap()); - edm::ValueMap::Filler jetCellsForTiming_filler(*jetCellsForTiming_out); - jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end()); - jetCellsForTiming_filler.fill(); - iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming"); -} - -// Fill descriptions -template -void HLTJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - desc.add("jets", edm::InputTag("")); - desc.add("barrelJets", false); - desc.add("endcapJets", false); - desc.add("ecalCellEnergyThresh", 0.5); - desc.add("ecalCellTimeThresh", 12.5); - desc.add("ecalCellTimeErrorThresh", 100.); - desc.add("matchingRadius", 0.4); - desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); - desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); - descriptions.addWithDefaultLabel(desc); -} +#include "HLTJetTimingProducer.h" typedef HLTJetTimingProducer HLTCaloJetTimingProducer; typedef HLTJetTimingProducer HLTPFJetTimingProducer; diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h new file mode 100644 index 0000000000000..c8525c533999a --- /dev/null +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h @@ -0,0 +1,183 @@ +/** \class HLTJetTimingProducer + * + * \brief This produces timing and associated ecal cell information for calo jets + * \author Matthew Citron + * + */ +#ifndef HLTrigger_JetMET_plugins_HLTJetTimingProducer_h +#define HLTrigger_JetMET_plugins_HLTJetTimingProducer_h + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/ValueMap.h" + +#include "DataFormats/JetReco/interface/CaloJetCollection.h" +#include "DataFormats/JetReco/interface/PFJetCollection.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/Math/interface/deltaR.h" + +// +// class declaration +// +template +class HLTJetTimingProducer : public edm::stream::EDProducer<> { +public: + explicit HLTJetTimingProducer(const edm::ParameterSet&); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::Event&, const edm::EventSetup&) override; + void jetTimeFromEcalCells( + const T&, const edm::SortedCollection>&,const edm::ESHandle&, float&, float&, uint&); + + const edm::ESGetToken caloGeometryToken_; + // Input collections + const edm::EDGetTokenT> jetInputToken_; + const edm::EDGetTokenT>> ecalRecHitsEBToken_; + const edm::EDGetTokenT>> ecalRecHitsEEToken_; + + // Include barrel, endcap jets or both + const bool barrelJets_; + const bool endcapJets_; + + // Configurables for timing definition + const double ecalCellEnergyThresh_; + const double ecalCellTimeThresh_; + const double ecalCellTimeErrorThresh_; + const double matchingRadius2_; +}; + +//Constructor +template +HLTJetTimingProducer::HLTJetTimingProducer(const edm::ParameterSet& iConfig) + : caloGeometryToken_(esConsumes()), + jetInputToken_{consumes>(iConfig.getParameter("jets"))}, + ecalRecHitsEBToken_{consumes>>( + iConfig.getParameter("ebRecHitsColl"))}, + ecalRecHitsEEToken_{consumes>>( + iConfig.getParameter("eeRecHitsColl"))}, + barrelJets_{iConfig.getParameter("barrelJets")}, + endcapJets_{iConfig.getParameter("endcapJets")}, + ecalCellEnergyThresh_{iConfig.getParameter("ecalCellEnergyThresh")}, + ecalCellTimeThresh_{iConfig.getParameter("ecalCellTimeThresh")}, + ecalCellTimeErrorThresh_{iConfig.getParameter("ecalCellTimeErrorThresh")}, + matchingRadius2_{std::pow(iConfig.getParameter("matchingRadius"), 2)} { + produces>(""); + produces>("jetCellsForTiming"); + produces>("jetEcalEtForTiming"); +} + +//calculate jet time +template +void HLTJetTimingProducer::jetTimeFromEcalCells( + const T& jet, + const edm::SortedCollection>& ecalRecHits, + const edm::ESHandle& caloGeometry, + float& weightedTimeCell, + float& totalEmEnergyCell, + uint& nCells) { + for (auto const& ecalRH : ecalRecHits) { + if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) || + ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) || + ecalRH.checkFlag(EcalRecHit::kDiWeird)) + continue; + if (ecalRH.energy() < ecalCellEnergyThresh_) + continue; + if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_) + continue; + if (fabs(ecalRH.time()) > ecalCellTimeThresh_) + continue; + auto const pos = caloGeometry->getPosition(ecalRH.detid()); + if (reco::deltaR2(jet, pos) > matchingRadius2_) + continue; + weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); + totalEmEnergyCell += ecalRH.energy() * sin(pos.theta()); + nCells++; + } + if (totalEmEnergyCell > 0) { + weightedTimeCell /= totalEmEnergyCell; + } +} + +//Producer +template +void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + edm::ESHandle caloGeometry = iSetup.getHandle(caloGeometryToken_); + auto const jets = iEvent.getHandle(jetInputToken_); + auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); + auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); + + std::vector jetTimings; + std::vector jetCellsForTiming; + std::vector jetEcalEtForTiming; + + jetTimings.reserve(jets->size()); + jetEcalEtForTiming.reserve(jets->size()); + jetCellsForTiming.reserve(jets->size()); + + for (auto const& jet : *jets) { + float weightedTimeCell = 0; + float totalEmEnergyCell = 0; + unsigned int nCells = 0; + if (barrelJets_) + jetTimeFromEcalCells(jet, ecalRecHitsEB,caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); + if (endcapJets_) { + weightedTimeCell *= totalEmEnergyCell; + jetTimeFromEcalCells(jet, ecalRecHitsEE,caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); + } + + // If there is at least one ecal cell passing selection, calculate timing + jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell : -50); + jetEcalEtForTiming.emplace_back(totalEmEnergyCell); + jetCellsForTiming.emplace_back(nCells); + } + + std::unique_ptr> jetTimings_out(new edm::ValueMap()); + edm::ValueMap::Filler jetTimings_filler(*jetTimings_out); + jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end()); + jetTimings_filler.fill(); + iEvent.put(std::move(jetTimings_out), ""); + + std::unique_ptr> jetEcalEtForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out); + jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end()); + jetEcalEtForTiming_filler.fill(); + iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming"); + + std::unique_ptr> jetCellsForTiming_out(new edm::ValueMap()); + edm::ValueMap::Filler jetCellsForTiming_filler(*jetCellsForTiming_out); + jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end()); + jetCellsForTiming_filler.fill(); + iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming"); +} + +// Fill descriptions +template +void HLTJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("jets", edm::InputTag("")); + desc.add("barrelJets", false); + desc.add("endcapJets", false); + desc.add("ecalCellEnergyThresh", 0.5); + desc.add("ecalCellTimeThresh", 12.5); + desc.add("ecalCellTimeErrorThresh", 100.); + desc.add("matchingRadius", 0.4); + desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); + desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); + descriptions.addWithDefaultLabel(desc); +} + +#endif // HLTrigger_JetMET_plugins_HLTJetTimingProducer_h From a0e1f130c81ae367028aca6156af30ca797e6d09 Mon Sep 17 00:00:00 2001 From: mcitron Date: Thu, 28 Oct 2021 16:06:10 -0700 Subject: [PATCH 17/19] format --- HLTrigger/JetMET/plugins/HLTJetTimingFilter.h | 2 +- HLTrigger/JetMET/plugins/HLTJetTimingProducer.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h index fc0adf136cd6b..e7b25141ea879 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h @@ -88,7 +88,7 @@ bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, uint njets = 0; for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - edm::Ref> const caloJetRef(jets, std::distance(jets->begin(), iterJet)); + edm::Ref> const caloJetRef(jets, std::distance(jets->begin(), iterJet)); if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h index c8525c533999a..861cc0dd7dbd9 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h @@ -39,8 +39,12 @@ class HLTJetTimingProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - void jetTimeFromEcalCells( - const T&, const edm::SortedCollection>&,const edm::ESHandle&, float&, float&, uint&); + void jetTimeFromEcalCells(const T&, + const edm::SortedCollection>&, + const edm::ESHandle&, + float&, + float&, + uint&); const edm::ESGetToken caloGeometryToken_; // Input collections @@ -114,7 +118,6 @@ void HLTJetTimingProducer::jetTimeFromEcalCells( //Producer template void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::ESHandle caloGeometry = iSetup.getHandle(caloGeometryToken_); auto const jets = iEvent.getHandle(jetInputToken_); auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); @@ -133,10 +136,10 @@ void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& float totalEmEnergyCell = 0; unsigned int nCells = 0; if (barrelJets_) - jetTimeFromEcalCells(jet, ecalRecHitsEB,caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); + jetTimeFromEcalCells(jet, ecalRecHitsEB, caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); if (endcapJets_) { weightedTimeCell *= totalEmEnergyCell; - jetTimeFromEcalCells(jet, ecalRecHitsEE,caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); + jetTimeFromEcalCells(jet, ecalRecHitsEE, caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells); } // If there is at least one ecal cell passing selection, calculate timing From 87a8a123cc6692892f282598ce6d36af8ebeaf71 Mon Sep 17 00:00:00 2001 From: mcitron Date: Fri, 29 Oct 2021 09:53:03 -0700 Subject: [PATCH 18/19] fix geo and trig product --- HLTrigger/JetMET/plugins/HLTJetTimingFilter.h | 7 +++---- HLTrigger/JetMET/plugins/HLTJetTimingProducer.h | 11 ++++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h index e7b25141ea879..6003738eacf1c 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h @@ -21,6 +21,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h" +#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" namespace edm { class ConfigurationDescriptions; @@ -76,8 +77,6 @@ template bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { - // typedef vector TCollection; - // typedef edm::Ref TRef; if (saveTags()) filterproduct.addCollectionTag(jetInput_); @@ -88,7 +87,7 @@ bool HLTJetTimingFilter::hltFilter(edm::Event& iEvent, uint njets = 0; for (auto iterJet = jets->begin(); iterJet != jets->end(); ++iterJet) { - edm::Ref> const caloJetRef(jets, std::distance(jets->begin(), iterJet)); + edm::Ref> const caloJetRef(jets, std::distance(jets->begin(), iterJet)); if (iterJet->pt() > minPt_ and jetTimes[caloJetRef] > jetTimeThresh_ and jetEcalEtForTiming[caloJetRef] > jetEcalEtForTimingThresh_ and jetCellsForTiming[caloJetRef] > jetCellsForTimingThresh_) { @@ -117,7 +116,7 @@ void HLTJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& des desc.add("jetCellsForTimingThresh", 5); desc.add("jetEcalEtForTimingThresh", 10.); desc.add("minJetPt", 40.); - descriptions.addWithDefaultLabel(desc); + descriptions.add(defaultModuleLabel>(),desc); } #endif // HLTrigger_JetMET_plugins_HLTJetTimingFilter_h diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h index 861cc0dd7dbd9..3bb68976c7406 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h @@ -26,6 +26,7 @@ #include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "Geometry/Records/interface/CaloGeometryRecord.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" #include "DataFormats/Math/interface/deltaR.h" // @@ -41,7 +42,7 @@ class HLTJetTimingProducer : public edm::stream::EDProducer<> { void produce(edm::Event&, const edm::EventSetup&) override; void jetTimeFromEcalCells(const T&, const edm::SortedCollection>&, - const edm::ESHandle&, + const CaloGeometry&, float&, float&, uint&); @@ -88,7 +89,7 @@ template void HLTJetTimingProducer::jetTimeFromEcalCells( const T& jet, const edm::SortedCollection>& ecalRecHits, - const edm::ESHandle& caloGeometry, + const CaloGeometry& caloGeometry, float& weightedTimeCell, float& totalEmEnergyCell, uint& nCells) { @@ -103,7 +104,7 @@ void HLTJetTimingProducer::jetTimeFromEcalCells( continue; if (fabs(ecalRH.time()) > ecalCellTimeThresh_) continue; - auto const pos = caloGeometry->getPosition(ecalRH.detid()); + auto const pos = caloGeometry.getPosition(ecalRH.detid()); if (reco::deltaR2(jet, pos) > matchingRadius2_) continue; weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta()); @@ -118,7 +119,7 @@ void HLTJetTimingProducer::jetTimeFromEcalCells( //Producer template void HLTJetTimingProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::ESHandle caloGeometry = iSetup.getHandle(caloGeometryToken_); + auto const& caloGeometry = iSetup.getData(caloGeometryToken_); auto const jets = iEvent.getHandle(jetInputToken_); auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_); auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_); @@ -180,7 +181,7 @@ void HLTJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& d desc.add("matchingRadius", 0.4); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); - descriptions.addWithDefaultLabel(desc); + descriptions.add(defaultModuleLabel>(),desc); } #endif // HLTrigger_JetMET_plugins_HLTJetTimingProducer_h From 188ab90472e81a67abcacfcded2297f1db398ea7 Mon Sep 17 00:00:00 2001 From: mcitron Date: Fri, 29 Oct 2021 10:02:52 -0700 Subject: [PATCH 19/19] format --- HLTrigger/JetMET/plugins/HLTJetTimingFilter.h | 2 +- HLTrigger/JetMET/plugins/HLTJetTimingProducer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h index 6003738eacf1c..009eb40bb1dcb 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingFilter.h @@ -116,7 +116,7 @@ void HLTJetTimingFilter::fillDescriptions(edm::ConfigurationDescriptions& des desc.add("jetCellsForTimingThresh", 5); desc.add("jetEcalEtForTimingThresh", 10.); desc.add("minJetPt", 40.); - descriptions.add(defaultModuleLabel>(),desc); + descriptions.add(defaultModuleLabel>(), desc); } #endif // HLTrigger_JetMET_plugins_HLTJetTimingFilter_h diff --git a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h index 3bb68976c7406..e49b0f2833c11 100644 --- a/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h +++ b/HLTrigger/JetMET/plugins/HLTJetTimingProducer.h @@ -181,7 +181,7 @@ void HLTJetTimingProducer::fillDescriptions(edm::ConfigurationDescriptions& d desc.add("matchingRadius", 0.4); desc.add("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB")); desc.add("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE")); - descriptions.add(defaultModuleLabel>(),desc); + descriptions.add(defaultModuleLabel>(), desc); } #endif // HLTrigger_JetMET_plugins_HLTJetTimingProducer_h