From 2c72a0fd995d4b993a68014b61bc3b9bed0e6daf Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Tue, 24 Aug 2021 16:24:03 +0200 Subject: [PATCH] Migrate classes deriving from IsoDepositExtractor to esConsumes() --- .../EgammaHcalExtractor.cc | 8 +++---- .../EgammaRecHitExtractor.cc | 14 +++++------ .../MuonIsolation/plugins/CaloExtractor.cc | 1 - .../plugins/CaloExtractorByAssociator.cc | 24 +++++++++---------- .../plugins/CaloExtractorByAssociator.h | 8 +++++++ .../MuonIsolation/plugins/JetExtractor.cc | 1 - .../plugins/PixelTrackExtractor.cc | 2 -- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaHcalExtractor.cc b/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaHcalExtractor.cc index dc3b4f2732593..57d0e0923c719 100644 --- a/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaHcalExtractor.cc +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaHcalExtractor.cc @@ -63,6 +63,7 @@ namespace egammaisolation { double etLow_; edm::EDGetTokenT hcalRecHitProducerToken_; + edm::ESGetToken geometryToken_; }; } // namespace egammaisolation @@ -79,7 +80,8 @@ EgammaHcalExtractor::EgammaHcalExtractor(const edm::ParameterSet& par, edm::Cons : extRadius_(par.getParameter("extRadius")), intRadius_(par.getParameter("intRadius")), etLow_(par.getParameter("etMin")), - hcalRecHitProducerToken_(iC.consumes(par.getParameter("hcalRecHits"))) {} + hcalRecHitProducerToken_(iC.consumes(par.getParameter("hcalRecHits"))), + geometryToken_(iC.esConsumes()) {} EgammaHcalExtractor::~EgammaHcalExtractor() {} @@ -90,9 +92,7 @@ reco::IsoDeposit EgammaHcalExtractor::deposit(const edm::Event& iEvent, auto const& hcalRecHits = iEvent.get(hcalRecHitProducerToken_); //Get Calo Geometry - edm::ESHandle pG; - iSetup.get().get(pG); - const CaloGeometry* caloGeom = pG.product(); + const CaloGeometry* caloGeom = &iSetup.getData(geometryToken_); CaloDualConeSelector coneSel(intRadius_, extRadius_, caloGeom, DetId::Hcal); //Take the SC position diff --git a/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaRecHitExtractor.cc b/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaRecHitExtractor.cc index 364e6c2d74984..91f1e6057623c 100644 --- a/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaRecHitExtractor.cc +++ b/RecoEgamma/EgammaIsolationAlgos/plugins/iso_deposit_extractors/EgammaRecHitExtractor.cc @@ -20,7 +20,6 @@ #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -77,6 +76,8 @@ namespace egammaisolation { edm::InputTag endcapEcalHitsTag_; edm::EDGetTokenT barrelEcalHitsToken_; edm::EDGetTokenT endcapEcalHitsToken_; + edm::ESGetToken geometryToken_; + edm::ESGetToken sevlvToken_; bool fakeNegativeDeposit_; bool tryBoth_; bool useEt_; @@ -113,6 +114,8 @@ EgammaRecHitExtractor::EgammaRecHitExtractor(const edm::ParameterSet& par, edm:: endcapEcalHitsTag_(par.getParameter("endcapEcalHits")), barrelEcalHitsToken_(iC.consumes(barrelEcalHitsTag_)), endcapEcalHitsToken_(iC.consumes(endcapEcalHitsTag_)), + geometryToken_(iC.esConsumes()), + sevlvToken_(iC.esConsumes()), fakeNegativeDeposit_(par.getParameter("subtractSuperClusterEnergy")), tryBoth_(par.getParameter("tryBoth")), vetoClustered_(par.getParameter("vetoClustered")), @@ -170,18 +173,13 @@ EgammaRecHitExtractor::~EgammaRecHitExtractor() {} reco::IsoDeposit EgammaRecHitExtractor::deposit(const edm::Event& iEvent, const edm::EventSetup& iSetup, const reco::Candidate& emObject) const { - edm::ESHandle pG; - iSetup.get().get(pG); - //Get the channel status from the db //edm::ESHandle chStatus; //iSetup.get().get(chStatus); - edm::ESHandle sevlv; - iSetup.get().get(sevlv); - const EcalSeverityLevelAlgo* sevLevel = sevlv.product(); + const EcalSeverityLevelAlgo* sevLevel = &iSetup.getData(sevlvToken_); - const CaloGeometry* caloGeom = pG.product(); + const CaloGeometry* caloGeom = &iSetup.getData(geometryToken_); const CaloSubdetectorGeometry* barrelgeom = caloGeom->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); const CaloSubdetectorGeometry* endcapgeom = caloGeom->getSubdetectorGeometry(DetId::Ecal, EcalEndcap); diff --git a/RecoMuon/MuonIsolation/plugins/CaloExtractor.cc b/RecoMuon/MuonIsolation/plugins/CaloExtractor.cc index cdcee543e6da3..e31ae87a7f2ab 100644 --- a/RecoMuon/MuonIsolation/plugins/CaloExtractor.cc +++ b/RecoMuon/MuonIsolation/plugins/CaloExtractor.cc @@ -1,7 +1,6 @@ #include "CaloExtractor.h" #include "DataFormats/Common/interface/Handle.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" diff --git a/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.cc b/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.cc index 0ae95b8fa251d..8fbf37a61b254 100644 --- a/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.cc +++ b/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.cc @@ -1,18 +1,13 @@ #include "CaloExtractorByAssociator.h" #include "DataFormats/Common/interface/Handle.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" #include "DataFormats/HcalDetId/interface/HcalSubdetector.h" -#include "MagneticField/Engine/interface/MagneticField.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h" @@ -55,6 +50,7 @@ CaloExtractorByAssociator::CaloExtractorByAssociator(const ParameterSet& par, ed theNoiseTow_EE(par.getParameter("NoiseTow_EE")), theService(nullptr), theAssociator(nullptr), + bFieldToken_(iC.esConsumes()), thePrintTimeReport(par.getUntrackedParameter("PrintTimeReport")) { ParameterSet serviceParameters = par.getParameter("ServiceParameters"); theService = new MuonServiceProxy(serviceParameters, edm::ConsumesCollector(iC)); @@ -63,6 +59,10 @@ CaloExtractorByAssociator::CaloExtractorByAssociator(const ParameterSet& par, ed theAssociatorParameters = new TrackAssociatorParameters(); theAssociatorParameters->loadParameters(par.getParameter("TrackAssociatorParameters"), iC); theAssociator = new TrackDetectorAssociator(); + + if (theUseRecHitsFlag) { + caloGeomToken_ = iC.esConsumes(); + } } CaloExtractorByAssociator::~CaloExtractorByAssociator() { @@ -124,10 +124,9 @@ std::vector CaloExtractorByAssociator::deposits(const Event& event, IsoDeposit depHcal(muonDir); IsoDeposit depHOcal(muonDir); - edm::ESHandle bField; - eventSetup.get().get(bField); + auto const& bField = eventSetup.getData(bFieldToken_); - reco::TransientTrack tMuon(muon, &*bField); + reco::TransientTrack tMuon(muon, &bField); FreeTrajectoryState iFTS = tMuon.initialFreeState(); TrackDetMatchInfo mInfo = theAssociator->associate(event, eventSetup, iFTS, *theAssociatorParameters); @@ -159,14 +158,13 @@ std::vector CaloExtractorByAssociator::deposits(const Event& event, if (theUseRecHitsFlag) { //! do things based on rec-hits here //! too much copy-pasting now (refactor later?) - edm::ESHandle caloGeom; - eventSetup.get().get(caloGeom); + auto const& caloGeom = eventSetup.getData(caloGeomToken_); //Ecal std::vector::const_iterator eHitCI = mInfo.ecalRecHits.begin(); for (; eHitCI != mInfo.ecalRecHits.end(); ++eHitCI) { const EcalRecHit* eHitCPtr = *eHitCI; - GlobalPoint eHitPos = caloGeom->getPosition(eHitCPtr->detid()); + GlobalPoint eHitPos = caloGeom.getPosition(eHitCPtr->detid()); double deltar0 = reco::deltaR(muon, eHitPos); double cosTheta = 1. / cosh(eHitPos.eta()); double energy = eHitCPtr->energy(); @@ -207,7 +205,7 @@ std::vector CaloExtractorByAssociator::deposits(const Event& event, std::vector::const_iterator hHitCI = mInfo.hcalRecHits.begin(); for (; hHitCI != mInfo.hcalRecHits.end(); ++hHitCI) { const HBHERecHit* hHitCPtr = *hHitCI; - GlobalPoint hHitPos = caloGeom->getPosition(hHitCPtr->detid()); + GlobalPoint hHitPos = caloGeom.getPosition(hHitCPtr->detid()); double deltar0 = reco::deltaR(muon, hHitPos); double cosTheta = 1. / cosh(hHitPos.eta()); double energy = hHitCPtr->energy(); @@ -248,7 +246,7 @@ std::vector CaloExtractorByAssociator::deposits(const Event& event, std::vector::const_iterator hoHitCI = mInfo.hoRecHits.begin(); for (; hoHitCI != mInfo.hoRecHits.end(); ++hoHitCI) { const HORecHit* hoHitCPtr = *hoHitCI; - GlobalPoint hoHitPos = caloGeom->getPosition(hoHitCPtr->detid()); + GlobalPoint hoHitPos = caloGeom.getPosition(hoHitCPtr->detid()); double deltar0 = reco::deltaR(muon, hoHitPos); double cosTheta = 1. / cosh(hoHitPos.eta()); double energy = hoHitCPtr->energy(); diff --git a/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.h b/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.h index c8ef48fbe2a41..bffbddd717d7e 100644 --- a/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.h +++ b/RecoMuon/MuonIsolation/plugins/CaloExtractorByAssociator.h @@ -25,6 +25,11 @@ #include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" + class TrackAssociatorParameters; class TrackDetectorAssociator; class MuonServiceProxy; @@ -100,6 +105,9 @@ namespace muonisolation { TrackAssociatorParameters* theAssociatorParameters; TrackDetectorAssociator* theAssociator; + edm::ESGetToken bFieldToken_; + edm::ESGetToken caloGeomToken_; + //! flag to turn on/off printing of a time report bool thePrintTimeReport; diff --git a/RecoMuon/MuonIsolation/plugins/JetExtractor.cc b/RecoMuon/MuonIsolation/plugins/JetExtractor.cc index 432e8a5880e6b..2c77fd49b0d1b 100644 --- a/RecoMuon/MuonIsolation/plugins/JetExtractor.cc +++ b/RecoMuon/MuonIsolation/plugins/JetExtractor.cc @@ -1,7 +1,6 @@ #include "JetExtractor.h" #include "DataFormats/Common/interface/Handle.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" diff --git a/RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc b/RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc index 9a194dd08b522..15799955ba2f4 100644 --- a/RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc +++ b/RecoMuon/MuonIsolation/plugins/PixelTrackExtractor.cc @@ -8,8 +8,6 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/BeamSpot/interface/BeamSpot.h" -#include "FWCore/Framework/interface/ESHandle.h" - using namespace edm; using namespace std; using namespace reco;