diff --git a/RecoMET/METAlgorithms/interface/CSCHaloAlgo.h b/RecoMET/METAlgorithms/interface/CSCHaloAlgo.h index 2c529837499c5..ca24f28c9bd11 100644 --- a/RecoMET/METAlgorithms/interface/CSCHaloAlgo.h +++ b/RecoMET/METAlgorithms/interface/CSCHaloAlgo.h @@ -89,7 +89,7 @@ namespace edm { class CSCHaloAlgo { public: - CSCHaloAlgo(); + CSCHaloAlgo(edm::ConsumesCollector iC); ~CSCHaloAlgo() {} reco::CSCHaloData Calculate(const CSCGeometry& TheCSCGeometry, edm::Handle& TheCosmicMuons, @@ -170,6 +170,7 @@ class CSCHaloAlgo { float et_thresh_rh_ee, dphi_thresh_segvsrh_ee, dr_lowthresh_segvsrh_ee, dr_highthresh_segvsrh_ee, dt_lowthresh_segvsrh_ee, dt_highthresh_segvsrh_ee; + edm::ESGetToken geoToken_; const CaloGeometry* geo_; const HcalGeometry* hgeo_; math::XYZPoint getPosition(const DetId& id, reco::Vertex::Point vtx); diff --git a/RecoMET/METAlgorithms/src/CSCHaloAlgo.cc b/RecoMET/METAlgorithms/src/CSCHaloAlgo.cc index 8c483c8041aec..0f3e648570c2f 100644 --- a/RecoMET/METAlgorithms/src/CSCHaloAlgo.cc +++ b/RecoMET/METAlgorithms/src/CSCHaloAlgo.cc @@ -14,7 +14,7 @@ using namespace edm; namespace { constexpr float c_cm_per_ns = 29.9792458; }; -CSCHaloAlgo::CSCHaloAlgo() : geo_(nullptr), hgeo_(nullptr) { +CSCHaloAlgo::CSCHaloAlgo(edm::ConsumesCollector iC) : geoToken_(iC.esConsumes()), geo_(nullptr), hgeo_(nullptr) { deta_threshold = 0.; min_inner_radius = 0.; max_inner_radius = 9999.; @@ -84,9 +84,7 @@ reco::CSCHaloData CSCHaloAlgo::Calculate(const CSCGeometry& TheCSCGeometry, bool ECALEmatched = false; bool HCALmatched = false; - edm::ESHandle pGeo; - TheSetup.get().get(pGeo); - geo_ = pGeo.product(); + geo_ = &TheSetup.getData(geoToken_); hgeo_ = dynamic_cast(geo_->getSubdetectorGeometry(DetId::Hcal, 1)); //} diff --git a/RecoMET/METFilters/interface/EcalBoundaryInfoCalculator.h b/RecoMET/METFilters/interface/EcalBoundaryInfoCalculator.h index e1fc9c3729560..9fcf3a8469c31 100644 --- a/RecoMET/METFilters/interface/EcalBoundaryInfoCalculator.h +++ b/RecoMET/METFilters/interface/EcalBoundaryInfoCalculator.h @@ -16,7 +16,6 @@ #include "DataFormats/EcalDetId/interface/EEDetId.h" #include "DataFormats/EcalDetId/interface/ESDetId.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "DataFormats/METReco/interface/BoundaryInformation.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -29,20 +28,20 @@ class EcalBoundaryInfoCalculator { EcalBoundaryInfoCalculator(); ~EcalBoundaryInfoCalculator(); - BoundaryInformation boundaryRecHits(const edm::Handle&, + BoundaryInformation boundaryRecHits(const EcalRecHitCollection&, const EcalRecHit*, - const edm::ESHandle theCaloTopology, - const edm::ESHandle ecalStatus, - const edm::ESHandle geometry) const; + const CaloTopology& theCaloTopology, + const EcalChannelStatus& ecalStatus, + const CaloGeometry& geometry) const; - BoundaryInformation gapRecHits(const edm::Handle&, + BoundaryInformation gapRecHits(const EcalRecHitCollection&, const EcalRecHit*, - const edm::ESHandle theCaloTopology, - const edm::ESHandle ecalStatus, - const edm::ESHandle geometry) const; + const CaloTopology& theCaloTopology, + const EcalChannelStatus& ecalStatus, + const CaloGeometry& geometry) const; bool checkRecHitHasDeadNeighbour(const EcalRecHit& hit, - const edm::ESHandle ecalStatus, + const EcalChannelStatus& ecalStatus, std::vector& stati) const { stati.clear(); EcalDetId hitdetid = EcalDetId(hit.id()); @@ -72,8 +71,8 @@ class EcalBoundaryInfoCalculator { if (EBDetId::validDetId(neighbourIeta, neighbourIphi)) { const EBDetId detid = EBDetId(neighbourIeta, neighbourIphi, EBDetId::ETAPHIMODE); - EcalChannelStatus::const_iterator chit = ecalStatus->find(detid); - int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(detid); + int status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { bool present = false; @@ -106,8 +105,8 @@ class EcalBoundaryInfoCalculator { if (EEDetId::validDetId(neighbourIx, neighbourIy, hitIz)) { const EEDetId detid = EEDetId(neighbourIx, neighbourIy, hitIz, EEDetId::XYMODE); - EcalChannelStatus::const_iterator chit = ecalStatus->find(detid); - int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(detid); + int status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { bool present = false; @@ -133,7 +132,7 @@ class EcalBoundaryInfoCalculator { return false; } - bool checkRecHitHasInvalidNeighbour(const EcalRecHit& hit, const edm::ESHandle ecalStatus) const { + bool checkRecHitHasInvalidNeighbour(const EcalRecHit& hit, const EcalChannelStatus& ecalStatus) const { //// return true, if *direct* neighbour is invalid EcalDetId hitdetid = EcalDetId(hit.id()); @@ -266,15 +265,15 @@ class EcalBoundaryInfoCalculator { } std::unique_ptr> initializeEcalNavigator(DetId startE, - const edm::ESHandle theCaloTopology, + const CaloTopology& theCaloTopology, EcalSubdetector ecalSubDet) const { - std::unique_ptr> theEcalNav(nullptr); + std::unique_ptr> theEcalNav; if (ecalSubDet == EcalBarrel) { - theEcalNav.reset(new CaloNavigator( - (EBDetId)startE, (theCaloTopology->getSubdetectorTopology(DetId::Ecal, ecalSubDet)))); + theEcalNav = std::make_unique>( + (EBDetId)startE, (theCaloTopology.getSubdetectorTopology(DetId::Ecal, ecalSubDet))); } else if (ecalSubDet == EcalEndcap) { - theEcalNav.reset(new CaloNavigator( - (EEDetId)startE, (theCaloTopology->getSubdetectorTopology(DetId::Ecal, ecalSubDet)))); + theEcalNav = std::make_unique>( + (EEDetId)startE, (theCaloTopology.getSubdetectorTopology(DetId::Ecal, ecalSubDet))); } else { edm::LogWarning("EcalBoundaryInfoCalculator") << "initializeEcalNavigator not implemented for subDet: " << ecalSubDet; @@ -315,12 +314,11 @@ template EcalBoundaryInfoCalculator::~EcalBoundaryInfoCalculator() {} template -BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( - const edm::Handle& RecHits, - const EcalRecHit* hit, - const edm::ESHandle theCaloTopology, - edm::ESHandle ecalStatus, - edm::ESHandle geometry) const { +BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits(const EcalRecHitCollection& RecHits, + const EcalRecHit* hit, + const CaloTopology& theCaloTopology, + const EcalChannelStatus& ecalStatus, + const CaloGeometry& geometry) const { //initialize boundary information std::vector boundaryRecHits; std::vector boundaryDetIds; @@ -336,7 +334,7 @@ BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( boundaryEnergy += hit->energy(); EcalDetId hitdetid = (EcalDetId)hit->id(); boundaryDetIds.push_back(hitdetid); - const CaloSubdetectorGeometry* subGeom = geometry->getSubdetectorGeometry(hitdetid); + const CaloSubdetectorGeometry* subGeom = geometry.getSubdetectorGeometry(hitdetid); auto cellGeom = subGeom->getGeometry(hitdetid); double eta = cellGeom->getPosition().eta(); boundaryET += hit->energy() / cosh(eta); @@ -370,8 +368,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( next = makeStepInDirection(currDirection, theEcalNav.get()); theEcalNav->setHome(current); theEcalNav->home(); - EcalChannelStatus::const_iterator chit = ecalStatus->find(next); - int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(next); + int status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { stati.push_back(status); startAlgo = true; @@ -400,8 +398,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( next = makeStepInDirection(currDirection, theEcalNav.get()); theEcalNav->setHome(current); theEcalNav->home(); - EcalChannelStatus::const_iterator chit = ecalStatus->find(next); - status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(next); + status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { // New dead cell found: update status std::vector of dead channels bool present = false; @@ -449,8 +447,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( // save recHits and add energy if on the boundary (and not inside at border) if ((!atBorder || status == 0) && !nextIsStart) { boundaryDetIds.push_back(next); - if (RecHits->find(next) != RecHits->end() && status == 0) { - EcalRecHit nexthit = *RecHits->find(next); + if (RecHits.find(next) != RecHits.end() && status == 0) { + EcalRecHit nexthit = *RecHits.find(next); ++beCellCounter; boundaryRecHits.push_back(nexthit); boundaryEnergy += nexthit.energy(); @@ -510,11 +508,11 @@ BoundaryInformation EcalBoundaryInfoCalculator::boundaryRecHits( } template -BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm::Handle& RecHits, +BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const EcalRecHitCollection& RecHits, const EcalRecHit* hit, - const edm::ESHandle theCaloTopology, - edm::ESHandle ecalStatus, - edm::ESHandle geometry) const { + const CaloTopology& theCaloTopology, + const EcalChannelStatus& ecalStatus, + const CaloGeometry& geometry) const { //initialize boundary information std::vector gapRecHits; std::vector gapDetIds; @@ -529,7 +527,7 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: gapEnergy += hit->energy(); EcalDetId hitdetid = (EcalDetId)hit->id(); gapDetIds.push_back(hitdetid); - const CaloSubdetectorGeometry* subGeom = geometry->getSubdetectorGeometry(hitdetid); + const CaloSubdetectorGeometry* subGeom = geometry.getSubdetectorGeometry(hitdetid); auto cellGeom = subGeom->getGeometry(hitdetid); double eta = cellGeom->getPosition().eta(); gapET += hit->energy() / cosh(eta); @@ -591,8 +589,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: next = makeStepInDirection(currDirection, theEcalNav.get()); theEcalNav->setHome(current); theEcalNav->home(); - EcalChannelStatus::const_iterator chit = ecalStatus->find(next); - status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(next); + status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { // Find dead cell along border -> end of cluster endIsFound = true; @@ -601,7 +599,7 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: // In case the Ecal border -> go along gap currDirection = turnLeft(currDirection, reverseOrientation); } else if (status == 0) { - if (RecHits->find(next) != RecHits->end()) { + if (RecHits.find(next) != RecHits.end()) { nextStepFound = true; } else { endIsFound = true; @@ -636,8 +634,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: // save recHits and add energy if (!endIsFound) { gapDetIds.push_back(next); - if (RecHits->find(next) != RecHits->end()) { - EcalRecHit nexthit = *RecHits->find(next); + if (RecHits.find(next) != RecHits.end()) { + EcalRecHit nexthit = *RecHits.find(next); ++gapCellCounter; gapRecHits.push_back(nexthit); gapEnergy += nexthit.energy(); @@ -670,8 +668,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: next = makeStepInDirection(currDirection, theEcalNav.get()); theEcalNav->setHome(current); theEcalNav->home(); - EcalChannelStatus::const_iterator chit = ecalStatus->find(next); - status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(next); + status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status > 0) { // Find dead cell along border -> end of cluster endIsFound = true; @@ -680,7 +678,7 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: // In case the Ecal border -> go along gap currDirection = turnRight(currDirection, reverseOrientation); } else if (status == 0) { - if (RecHits->find(next) != RecHits->end()) { + if (RecHits.find(next) != RecHits.end()) { nextStepFound = true; } else { endIsFound = true; @@ -708,8 +706,8 @@ BoundaryInformation EcalBoundaryInfoCalculator::gapRecHits(const edm: // save recHits and add energy if (!endIsFound) { gapDetIds.push_back(next); - if (RecHits->find(next) != RecHits->end()) { - EcalRecHit nexthit = *RecHits->find(next); + if (RecHits.find(next) != RecHits.end()) { + EcalRecHit nexthit = *RecHits.find(next); ++gapCellCounter; gapRecHits.push_back(nexthit); gapEnergy += nexthit.energy(); diff --git a/RecoMET/METFilters/plugins/EEBadScFilter.cc b/RecoMET/METFilters/plugins/EEBadScFilter.cc index bee6f89af9d3f..8bb67edebb77b 100644 --- a/RecoMET/METFilters/plugins/EEBadScFilter.cc +++ b/RecoMET/METFilters/plugins/EEBadScFilter.cc @@ -16,7 +16,6 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/global/EDFilter.h" #include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -44,17 +43,19 @@ class EEBadScFilter : public edm::global::EDFilter<> { // function to calculate 5x5 energy and check rechit flags - virtual void scan5x5(const DetId &det, - const edm::Handle &hits, - const edm::ESHandle &caloTopo, - const edm::ESHandle &geometry, - int &nHits, - float &totEt) const; + void scan5x5(const DetId &det, + const EcalRecHitCollection &hits, + const CaloTopology &caloTopo, + const CaloGeometry &geometry, + int &nHits, + float &totEt) const; // input parameters // ee rechit collection (from AOD) const edm::EDGetTokenT eeRHSrcToken_; + const edm::ESGetToken geometryToken_; + const edm::ESGetToken caloTopoToken_; //config parameters (defining the cuts on the bad SCs) const double Emin_; // rechit energy threshold (check for !kGood rechit flags) @@ -70,6 +71,8 @@ class EEBadScFilter : public edm::global::EDFilter<> { // read the parameters from the config file EEBadScFilter::EEBadScFilter(const edm::ParameterSet &iConfig) : eeRHSrcToken_(consumes(iConfig.getParameter("EERecHitSource"))), + geometryToken_(esConsumes()), + caloTopoToken_(esConsumes()), Emin_(iConfig.getParameter("EminHit")), EtminSC_(iConfig.getParameter("EtminSC")), side_(iConfig.getParameter("SCsize")), @@ -81,9 +84,9 @@ EEBadScFilter::EEBadScFilter(const edm::ParameterSet &iConfig) } void EEBadScFilter::scan5x5(const DetId &det, - const edm::Handle &hits, - const edm::ESHandle &caloTopo, - const edm::ESHandle &geometry, + const EcalRecHitCollection &hits, + const CaloTopology &caloTopo, + const CaloGeometry &geometry, int &nHits, float &totEt) const { // function to compute: total transverse energy in a given supercrystal (totEt) @@ -95,8 +98,7 @@ void EEBadScFilter::scan5x5(const DetId &det, // navigator to define a 5x5 region around the input DetId - CaloNavigator cursor = CaloNavigator(det, caloTopo->getSubdetectorTopology(det)); - const CaloGeometry *geo = geometry.product(); + CaloNavigator cursor = CaloNavigator(det, caloTopo.getSubdetectorTopology(det)); // loop over a 5x5 array centered on the input DetId @@ -104,11 +106,11 @@ void EEBadScFilter::scan5x5(const DetId &det, for (int i = -side_ / 2; i <= side_ / 2; ++i) { cursor.home(); cursor.offsetBy(i, j); - if (hits->find(*cursor) != hits->end()) // if hit exists in the rechit collection + if (hits.find(*cursor) != hits.end()) // if hit exists in the rechit collection { - EcalRecHit tmpHit = *hits->find(*cursor); // get rechit with detID at cursor + EcalRecHit tmpHit = *hits.find(*cursor); // get rechit with detID at cursor - const GlobalPoint p(geo->getPosition(*cursor)); // calculate Et of the rechit + const GlobalPoint p(geometry.getPosition(*cursor)); // calculate Et of the rechit TVector3 hitPos(p.x(), p.y(), p.z()); hitPos *= 1.0 / hitPos.Mag(); hitPos *= tmpHit.energy(); @@ -129,16 +131,13 @@ bool EEBadScFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::EventSe // load required collections // EE rechit collection - edm::Handle eeRHs; - iEvent.getByToken(eeRHSrcToken_, eeRHs); + auto const &eeRHs = iEvent.get(eeRHSrcToken_); // Calo Geometry - needed for computing E_t - edm::ESHandle pG; - iSetup.get().get(pG); + auto const &geometry = iSetup.getData(geometryToken_); // Calo Toplology - needed for navigating the 5x5 xtal array around the centre of a SC - edm::ESHandle pTopology; - iSetup.get().get(pTopology); + auto const &caloTopo = iSetup.getData(caloTopoToken_); // by default the event is OK bool pass = true; @@ -169,7 +168,7 @@ bool EEBadScFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::EventSe // loop over the 5x5 SC centered on this DetId and fill discriminating variables - scan5x5(det, eeRHs, pTopology, pG, nhits, totEt); + scan5x5(det, eeRHs, caloTopo, geometry, nhits, totEt); // print some debug info diff --git a/RecoMET/METFilters/plugins/EcalBadCalibFilter.cc b/RecoMET/METFilters/plugins/EcalBadCalibFilter.cc index 9ebccffc315c8..1ac8801e3c0dc 100644 --- a/RecoMET/METFilters/plugins/EcalBadCalibFilter.cc +++ b/RecoMET/METFilters/plugins/EcalBadCalibFilter.cc @@ -19,7 +19,6 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/global/EDFilter.h" #include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -49,6 +48,7 @@ class EcalBadCalibFilter : public edm::global::EDFilter<> { // input parameters // ecal rechit collection (from AOD) const edm::EDGetTokenT ecalRHSrcToken_; + const edm::ESGetToken geoToken_; //config parameters (defining the cuts on the bad SCs) const double ecalMin_; // ecal rechit et threshold @@ -62,6 +62,7 @@ class EcalBadCalibFilter : public edm::global::EDFilter<> { // read the parameters from the config file EcalBadCalibFilter::EcalBadCalibFilter(const edm::ParameterSet& iConfig) : ecalRHSrcToken_(consumes(iConfig.getParameter("EcalRecHitSource"))), + geoToken_(esConsumes()), ecalMin_(iConfig.getParameter("ecalMinEt")), baddetEcal_(iConfig.getParameter >("baddetEcal")), taggingMode_(iConfig.getParameter("taggingMode")), @@ -77,9 +78,7 @@ bool EcalBadCalibFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::Ev iEvent.getByToken(ecalRHSrcToken_, ecalRHs); // Calo Geometry - needed for computing E_t - edm::ESHandle pG; - iSetup.get().get(pG); - const CaloGeometry* geo = pG.product(); + const CaloGeometry& geo = iSetup.getData(geoToken_); // by default the event is OK bool pass = true; @@ -109,7 +108,7 @@ bool EcalBadCalibFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::Ev ene = ecalhit->energy(); // compute transverse energy - const GlobalPoint& posecal = geo->getPosition(ecaldet); + const GlobalPoint& posecal = geo.getPosition(ecaldet); float pf = posecal.perp() / posecal.mag(); et = ene * pf; diff --git a/RecoMET/METFilters/plugins/EcalDeadCellBoundaryEnergyFilter.cc b/RecoMET/METFilters/plugins/EcalDeadCellBoundaryEnergyFilter.cc index 181483c47f9be..895113620c586 100644 --- a/RecoMET/METFilters/plugins/EcalDeadCellBoundaryEnergyFilter.cc +++ b/RecoMET/METFilters/plugins/EcalDeadCellBoundaryEnergyFilter.cc @@ -71,6 +71,9 @@ class EcalDeadCellBoundaryEnergyFilter : public edm::global::EDFilter<> { edm::EDGetTokenT EBRecHitsToken_; edm::EDGetTokenT EERecHitsToken_; + edm::ESGetToken caloTopologyToken_; + edm::ESGetToken ecalStatusToken_; + edm::ESGetToken geometryToken_; const std::string FilterAlgo_; const bool taggingMode_; @@ -105,9 +108,10 @@ EcalDeadCellBoundaryEnergyFilter::EcalDeadCellBoundaryEnergyFilter(const edm::Pa //now do what ever initialization is needed , EBRecHitsToken_(consumes(iConfig.getParameter("recHitsEB"))), - EERecHitsToken_(consumes(iConfig.getParameter("recHitsEE"))) - - , + EERecHitsToken_(consumes(iConfig.getParameter("recHitsEE"))), + caloTopologyToken_(esConsumes()), + ecalStatusToken_(esConsumes()), + geometryToken_(esConsumes()), FilterAlgo_(iConfig.getUntrackedParameter("FilterAlgo", "TuningMode")), taggingMode_(iConfig.getParameter("taggingMode")), skimGap_(iConfig.getUntrackedParameter("skimGap", false)), @@ -163,19 +167,12 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, v_boundaryInfoDeadCells_EE.reserve(50); // Get the Ecal RecHits - Handle EBRecHits; - iEvent.getByToken(EBRecHitsToken_, EBRecHits); - Handle EERecHits; - iEvent.getByToken(EERecHitsToken_, EERecHits); - - edm::ESHandle theCaloTopology; - iSetup.get().get(theCaloTopology); - - edm::ESHandle ecalStatus; - iSetup.get().get(ecalStatus); + auto const& EBRecHits = iEvent.get(EBRecHitsToken_); + auto const& EERecHits = iEvent.get(EERecHitsToken_); - edm::ESHandle geometry; - iSetup.get().get(geometry); + auto const& theCaloTopology = iSetup.getData(caloTopologyToken_); + auto const& ecalStatus = iSetup.getData(ecalStatusToken_); + auto const& geometry = iSetup.getData(geometryToken_); // int DeadChannelsCounterEB = 0; // int DeadChannelsCounterEE = 0; @@ -193,12 +190,12 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, if (debug_) edm::LogInfo("EcalDeadCellBoundaryEnergyFilter") << "process EB"; - for (EcalRecHitCollection::const_iterator hit = EBRecHits->begin(); hit != EBRecHits->end(); ++hit) { + for (EcalRecHitCollection::const_iterator hit = EBRecHits.begin(); hit != EBRecHits.end(); ++hit) { bool detIdAlreadyChecked = false; DetId currDetId = (DetId)hit->id(); //add limitation to channel stati - EcalChannelStatus::const_iterator chit = ecalStatus->find(currDetId); - int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(currDetId); + int status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status != 0) continue; bool passChannelLimitation = false; @@ -226,11 +223,8 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, // RecHit is at EB boundary and should be processed if (!detIdAlreadyChecked && deadNeighbourStati.empty() && ebBoundaryCalc.checkRecHitHasInvalidNeighbour(*hit, ecalStatus)) { - BoundaryInformation gapinfo = ebBoundaryCalc.gapRecHits((const edm::Handle&)EBRecHits, - (const EcalRecHit*)&(*hit), - theCaloTopology, - ecalStatus, - geometry); + BoundaryInformation gapinfo = + ebBoundaryCalc.gapRecHits(EBRecHits, &(*hit), theCaloTopology, ecalStatus, geometry); // get rechits along gap cluster for (std::vector::iterator it = gapinfo.detIds.begin(); it != gapinfo.detIds.end(); it++) { @@ -251,11 +245,7 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, if (!detIdAlreadyChecked && (passChannelLimitation || (limitDeadCellToChannelStatusEB_.empty() && !deadNeighbourStati.empty()))) { BoundaryInformation boundinfo = - ebBoundaryCalc.boundaryRecHits((const edm::Handle&)EBRecHits, - (const EcalRecHit*)&(*hit), - theCaloTopology, - ecalStatus, - geometry); + ebBoundaryCalc.boundaryRecHits(EBRecHits, &(*hit), theCaloTopology, ecalStatus, geometry); // get boundary of !kDead rechits arround the dead cluster for (std::vector::iterator it = boundinfo.detIds.begin(); it != boundinfo.detIds.end(); it++) { @@ -282,12 +272,12 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, if (debug_) edm::LogInfo("EcalDeadCellBoundaryEnergyFilter") << "process EE"; - for (EcalRecHitCollection::const_iterator hit = EERecHits->begin(); hit != EERecHits->end(); ++hit) { + for (EcalRecHitCollection::const_iterator hit = EERecHits.begin(); hit != EERecHits.end(); ++hit) { bool detIdAlreadyChecked = false; DetId currDetId = (DetId)hit->id(); //add limitation to channel stati - EcalChannelStatus::const_iterator chit = ecalStatus->find(currDetId); - int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1; + EcalChannelStatus::const_iterator chit = ecalStatus.find(currDetId); + int status = (chit != ecalStatus.end()) ? chit->getStatusCode() & 0x1F : -1; if (status != 0) continue; bool passChannelLimitation = false; @@ -313,17 +303,14 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, } // RecHit is at EE boundary and should be processed - const CaloSubdetectorGeometry* subGeom = geometry->getSubdetectorGeometry(currDetId); + const CaloSubdetectorGeometry* subGeom = geometry.getSubdetectorGeometry(currDetId); auto cellGeom = subGeom->getGeometry(currDetId); double eta = cellGeom->getPosition().eta(); if (!detIdAlreadyChecked && deadNeighbourStati.empty() && eeBoundaryCalc.checkRecHitHasInvalidNeighbour(*hit, ecalStatus) && std::abs(eta) < 1.6) { - BoundaryInformation gapinfo = eeBoundaryCalc.gapRecHits((const edm::Handle&)EERecHits, - (const EcalRecHit*)&(*hit), - theCaloTopology, - ecalStatus, - geometry); + BoundaryInformation gapinfo = + eeBoundaryCalc.gapRecHits(EERecHits, &(*hit), theCaloTopology, ecalStatus, geometry); // get rechits along gap cluster for (std::vector::iterator it = gapinfo.detIds.begin(); it != gapinfo.detIds.end(); it++) { @@ -344,11 +331,7 @@ bool EcalDeadCellBoundaryEnergyFilter::filter(edm::StreamID, edm::Event& iEvent, if (!detIdAlreadyChecked && (passChannelLimitation || (limitDeadCellToChannelStatusEE_.empty() && !deadNeighbourStati.empty()))) { BoundaryInformation boundinfo = - eeBoundaryCalc.boundaryRecHits((const edm::Handle&)EERecHits, - (const EcalRecHit*)&(*hit), - theCaloTopology, - ecalStatus, - geometry); + eeBoundaryCalc.boundaryRecHits(EERecHits, &(*hit), theCaloTopology, ecalStatus, geometry); // get boundary of !kDead rechits arround the dead cluster for (std::vector::iterator it = boundinfo.detIds.begin(); it != boundinfo.detIds.end(); it++) { diff --git a/RecoMET/METFilters/plugins/EcalLaserCorrFilter.cc b/RecoMET/METFilters/plugins/EcalLaserCorrFilter.cc index 0082305af37af..fbfd4b75db418 100644 --- a/RecoMET/METFilters/plugins/EcalLaserCorrFilter.cc +++ b/RecoMET/METFilters/plugins/EcalLaserCorrFilter.cc @@ -3,7 +3,6 @@ #include "FWCore/Framework/interface/global/EDFilter.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" @@ -37,6 +36,7 @@ class EcalLaserCorrFilter : public edm::global::EDFilter<> { const edm::EDGetTokenT ebRHSrcToken_; const edm::EDGetTokenT eeRHSrcToken_; + const edm::ESGetToken laserToken_; // thresholds to laser corr to set kPoorCalib const double EBLaserMIN_, EELaserMIN_, EBLaserMAX_, EELaserMAX_, EBEnegyMIN_, EEEnegyMIN_; @@ -46,6 +46,7 @@ class EcalLaserCorrFilter : public edm::global::EDFilter<> { EcalLaserCorrFilter::EcalLaserCorrFilter(const edm::ParameterSet& iConfig) : ebRHSrcToken_(consumes(iConfig.getParameter("EBRecHitSource"))), eeRHSrcToken_(consumes(iConfig.getParameter("EERecHitSource"))), + laserToken_(esConsumes()), EBLaserMIN_(iConfig.getParameter("EBLaserMIN")), EELaserMIN_(iConfig.getParameter("EELaserMIN")), EBLaserMAX_(iConfig.getParameter("EBLaserMAX")), @@ -69,8 +70,7 @@ bool EcalLaserCorrFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::E iEvent.getByToken(eeRHSrcToken_, eeRHs); // Laser corrections - edm::ESHandle laser; - iSetup.get().get(laser); + auto const& laser = iSetup.getData(laserToken_); bool goodCalib = true; @@ -85,7 +85,7 @@ bool EcalLaserCorrFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::E int jz = EEDetId((*eerh).id()).zside(); // get laser coefficient - float lasercalib = laser->getLaserCorrection(EEDetId(eeDet), iEvent.time()); + float lasercalib = laser.getLaserCorrection(EEDetId(eeDet), iEvent.time()); if (energy > EEEnegyMIN_ && (lasercalib < EELaserMIN_ || lasercalib > EELaserMAX_)) { goodCalib = false; @@ -111,7 +111,7 @@ bool EcalLaserCorrFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::E int zrec = EBDetId((*ebrh).id()).zside(); // get laser coefficient - float lasercalib = laser->getLaserCorrection(EBDetId(ebDet), iEvent.time()); + float lasercalib = laser.getLaserCorrection(EBDetId(ebDet), iEvent.time()); if (energy > EBEnegyMIN_ && (lasercalib < EBLaserMIN_ || lasercalib > EBLaserMAX_)) { goodCalib = false; diff --git a/RecoMET/METPUSubtraction/interface/PFMETAlgorithmMVA.h b/RecoMET/METPUSubtraction/interface/PFMETAlgorithmMVA.h index 211cac8035348..4a121e780e214 100644 --- a/RecoMET/METPUSubtraction/interface/PFMETAlgorithmMVA.h +++ b/RecoMET/METPUSubtraction/interface/PFMETAlgorithmMVA.h @@ -11,9 +11,11 @@ */ #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "CondFormats/GBRForest/interface/GBRForest.h" +#include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" #include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/METReco/interface/MET.h" @@ -29,7 +31,7 @@ class PFMETAlgorithmMVA { public: - PFMETAlgorithmMVA(const edm::ParameterSet& cfg); + PFMETAlgorithmMVA(const edm::ParameterSet& cfg, edm::ConsumesCollector iC); ~PFMETAlgorithmMVA(); void initialize(const edm::EventSetup&); @@ -56,7 +58,6 @@ class PFMETAlgorithmMVA { private: const std::string updateVariableNames(std::string input); const GBRForest* loadMVAfromFile(const edm::FileInPath& inputFileName, const std::string& mvaName); - const GBRForest* loadMVAfromDB(const edm::EventSetup& es, const std::string& mvaName); const float evaluateU(); const float evaluateDPhi(); @@ -70,6 +71,11 @@ class PFMETAlgorithmMVA { std::string mvaNameCovU1_; std::string mvaNameCovU2_; + edm::ESGetToken mvaTokenU_; + edm::ESGetToken mvaTokenDPhi_; + edm::ESGetToken mvaTokenCovU1_; + edm::ESGetToken mvaTokenCovU2_; + int mvaType_; bool hasPhotons_; diff --git a/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc b/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc index 3a9c3880cff9d..6c6cd067499fe 100644 --- a/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc +++ b/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc @@ -7,7 +7,8 @@ const double dR2Min = 0.01 * 0.01; const double dR2Max = 0.5 * 0.5; const double dPtMatch = 0.1; -PFMETProducerMVA::PFMETProducerMVA(const edm::ParameterSet& cfg) : mvaMEtAlgo_(cfg), mvaMEtAlgo_isInitialized_(false) { +PFMETProducerMVA::PFMETProducerMVA(const edm::ParameterSet& cfg) + : mvaMEtAlgo_(cfg, consumesCollector()), mvaMEtAlgo_isInitialized_(false) { srcCorrJets_ = consumes(cfg.getParameter("srcCorrJets")); srcUncorrJets_ = consumes(cfg.getParameter("srcUncorrJets")); srcJetIds_ = consumes >(cfg.getParameter("srcMVAPileupJetId")); diff --git a/RecoMET/METPUSubtraction/src/PFMETAlgorithmMVA.cc b/RecoMET/METPUSubtraction/src/PFMETAlgorithmMVA.cc index 976b982927bf2..0902c7c8c1aac 100644 --- a/RecoMET/METPUSubtraction/src/PFMETAlgorithmMVA.cc +++ b/RecoMET/METPUSubtraction/src/PFMETAlgorithmMVA.cc @@ -3,10 +3,6 @@ #include "FWCore/ParameterSet/interface/FileInPath.h" #include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" - #include "DataFormats/METReco/interface/CommonMETData.h" #include @@ -112,13 +108,7 @@ const GBRForest* PFMETAlgorithmMVA::loadMVAfromFile(const edm::FileInPath& input return mva; } -const GBRForest* PFMETAlgorithmMVA::loadMVAfromDB(const edm::EventSetup& es, const std::string& mvaName) { - edm::ESHandle mva; - es.get().get(mvaName, mva); - return mva.product(); -} - -PFMETAlgorithmMVA::PFMETAlgorithmMVA(const edm::ParameterSet& cfg) +PFMETAlgorithmMVA::PFMETAlgorithmMVA(const edm::ParameterSet& cfg, edm::ConsumesCollector iC) : utils_(cfg), mvaReaderU_(nullptr), mvaReaderDPhi_(nullptr), @@ -127,7 +117,19 @@ PFMETAlgorithmMVA::PFMETAlgorithmMVA(const edm::ParameterSet& cfg) cfg_(cfg) { mvaType_ = kBaseline; + edm::ParameterSet cfgInputRecords = cfg_.getParameter("inputRecords"); + mvaNameU_ = cfgInputRecords.getParameter("U"); + mvaNameDPhi_ = cfgInputRecords.getParameter("DPhi"); + mvaNameCovU1_ = cfgInputRecords.getParameter("CovU1"); + mvaNameCovU2_ = cfgInputRecords.getParameter("CovU2"); + loadMVAfromDB_ = cfg.getParameter("loadMVAfromDB"); + if (loadMVAfromDB_) { + mvaTokenU_ = iC.esConsumes(edm::ESInputTag("", mvaNameU_)); + mvaTokenDPhi_ = iC.esConsumes(edm::ESInputTag("", mvaNameDPhi_)); + mvaTokenCovU1_ = iC.esConsumes(edm::ESInputTag("", mvaNameCovU1_)); + mvaTokenCovU2_ = iC.esConsumes(edm::ESInputTag("", mvaNameCovU2_)); + } } PFMETAlgorithmMVA::~PFMETAlgorithmMVA() { @@ -141,17 +143,11 @@ PFMETAlgorithmMVA::~PFMETAlgorithmMVA() { //------------------------------------------------------------------------------- void PFMETAlgorithmMVA::initialize(const edm::EventSetup& es) { - edm::ParameterSet cfgInputRecords = cfg_.getParameter("inputRecords"); - mvaNameU_ = cfgInputRecords.getParameter("U"); - mvaNameDPhi_ = cfgInputRecords.getParameter("DPhi"); - mvaNameCovU1_ = cfgInputRecords.getParameter("CovU1"); - mvaNameCovU2_ = cfgInputRecords.getParameter("CovU2"); - if (loadMVAfromDB_) { - mvaReaderU_ = loadMVAfromDB(es, mvaNameU_); - mvaReaderDPhi_ = loadMVAfromDB(es, mvaNameDPhi_); - mvaReaderCovU1_ = loadMVAfromDB(es, mvaNameCovU1_); - mvaReaderCovU2_ = loadMVAfromDB(es, mvaNameCovU2_); + mvaReaderU_ = &es.getData(mvaTokenU_); + mvaReaderDPhi_ = &es.getData(mvaTokenDPhi_); + mvaReaderCovU1_ = &es.getData(mvaTokenCovU1_); + mvaReaderCovU2_ = &es.getData(mvaTokenCovU2_); } else { edm::ParameterSet cfgInputFileNames = cfg_.getParameter("inputFileNames"); diff --git a/RecoMET/METProducers/interface/PFMETProducer.h b/RecoMET/METProducers/interface/PFMETProducer.h index 56560a2bb1c8d..f6a45c3a568d3 100644 --- a/RecoMET/METProducers/interface/PFMETProducer.h +++ b/RecoMET/METProducers/interface/PFMETProducer.h @@ -41,10 +41,10 @@ #include "RecoMET/METAlgorithms/interface/SignPFSpecificAlgo.h" #include "RecoMET/METAlgorithms/interface/METSignificance.h" +#include "CondFormats/DataRecord/interface/JetResolutionRcd.h" +#include "CondFormats/DataRecord/interface/JetResolutionScaleFactorRcd.h" #include "JetMETCorrections/Modules/interface/JetResolution.h" -#include "TVector.h" - #include //____________________________________________________________________________|| @@ -76,9 +76,10 @@ namespace cms { edm::EDGetTokenT> jetToken_; std::vector>> lepTokens_; - std::string jetSFType_; - std::string jetResPtType_; - std::string jetResPhiType_; + + edm::ESGetToken jetSFToken_; + edm::ESGetToken jetResPtToken_; + edm::ESGetToken jetResPhiToken_; edm::EDGetTokenT rhoToken_; bool applyWeight_; edm::EDGetTokenT> weightsToken_; diff --git a/RecoMET/METProducers/src/CSCHaloDataProducer.cc b/RecoMET/METProducers/src/CSCHaloDataProducer.cc index 504b3eee9bb6e..d89ab6efcf155 100644 --- a/RecoMET/METProducers/src/CSCHaloDataProducer.cc +++ b/RecoMET/METProducers/src/CSCHaloDataProducer.cc @@ -13,7 +13,7 @@ using namespace edm; using namespace std; using namespace reco; -CSCHaloDataProducer::CSCHaloDataProducer(const edm::ParameterSet& iConfig) { +CSCHaloDataProducer::CSCHaloDataProducer(const edm::ParameterSet& iConfig) : CSCAlgo(consumesCollector()) { //Digi Level IT_L1MuGMTReadout = iConfig.getParameter("L1MuGMTReadoutLabel"); diff --git a/RecoMET/METProducers/src/PFMETProducer.cc b/RecoMET/METProducers/src/PFMETProducer.cc index 9427e9753fee7..96f2e8d464dff 100644 --- a/RecoMET/METProducers/src/PFMETProducer.cc +++ b/RecoMET/METProducers/src/PFMETProducer.cc @@ -39,9 +39,9 @@ namespace cms { lepTokens_.push_back(mayConsume>(*it)); } - jetSFType_ = iConfig.getParameter("srcJetSF"); - jetResPtType_ = iConfig.getParameter("srcJetResPt"); - jetResPhiType_ = iConfig.getParameter("srcJetResPhi"); + jetSFToken_ = esConsumes(edm::ESInputTag("", iConfig.getParameter("srcJetSF"))); + jetResPtToken_ = esConsumes(edm::ESInputTag("", iConfig.getParameter("srcJetResPt"))); + jetResPhiToken_ = esConsumes(edm::ESInputTag("", iConfig.getParameter("srcJetResPhi"))); rhoToken_ = consumes(iConfig.getParameter("srcRho")); } @@ -106,9 +106,9 @@ namespace cms { edm::Handle> inputJets; event.getByToken(jetToken_, inputJets); - JME::JetResolution resPtObj = JME::JetResolution::get(setup, jetResPtType_); - JME::JetResolution resPhiObj = JME::JetResolution::get(setup, jetResPhiType_); - JME::JetResolutionScaleFactor resSFObj = JME::JetResolutionScaleFactor::get(setup, jetSFType_); + JME::JetResolution resPtObj(setup.getData(jetResPtToken_)); + JME::JetResolution resPhiObj(setup.getData(jetResPhiToken_)); + JME::JetResolutionScaleFactor resSFObj(setup.getData(jetSFToken_)); edm::Handle rho; event.getByToken(rhoToken_, rho);