From b5e1c2eb3e78f57a7832942a1879efc80ebfd252 Mon Sep 17 00:00:00 2001 From: mmusich Date: Fri, 5 Mar 2021 14:23:53 +0100 Subject: [PATCH] migrate RecoPixelVertexing/PixelLowPtUtilities to esConsumes --- .../bin/PixelClusterShapeExtractor.cc | 26 ++++++++----------- .../interface/PixelTripletLowPtGenerator.h | 8 ++++++ .../StripSubClusterShapeTrajectoryFilter.h | 8 ++++++ .../plugins/PixelVertexProducerClusters.cc | 15 +++-------- .../plugins/PixelVertexProducerClusters.h | 5 +++- .../plugins/PixelVertexProducerMedian.cc | 5 ++-- .../plugins/PixelVertexProducerMedian.h | 6 ++--- .../SiPixelClusterShapeCacheProducer.cc | 6 ++--- .../plugins/TrackFitterProducer.cc | 21 +++++++-------- .../src/PixelTripletLowPtGenerator.cc | 16 +++--------- .../StripSubClusterShapeTrajectoryFilter.cc | 20 +++++++------- 11 files changed, 66 insertions(+), 70 deletions(-) diff --git a/RecoPixelVertexing/PixelLowPtUtilities/bin/PixelClusterShapeExtractor.cc b/RecoPixelVertexing/PixelLowPtUtilities/bin/PixelClusterShapeExtractor.cc index 4a71ff6428798..1ebfd5a365ea6 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/bin/PixelClusterShapeExtractor.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/bin/PixelClusterShapeExtractor.cc @@ -91,6 +91,10 @@ class PixelClusterShapeExtractor final : public edm::global::EDAnalyzer<> { void analyzeSimHits(const edm::Event& ev, const edm::EventSetup& es) const; void analyzeRecTracks(const edm::Event& ev, const edm::EventSetup& es) const; + /// Tokens for ESconsumes + const edm::ESGetToken topoToken_; + const edm::ESGetToken csfToken_; + TFile* file; const bool hasSimHits; @@ -143,7 +147,9 @@ void PixelClusterShapeExtractor::init() { /*****************************************************************************/ PixelClusterShapeExtractor::PixelClusterShapeExtractor(const edm::ParameterSet& pset) - : hasSimHits(pset.getParameter("hasSimHits")), + : topoToken_(esConsumes()), + csfToken_(esConsumes(edm::ESInputTag("", "ClusterShapeHitFilter"))), + hasSimHits(pset.getParameter("hasSimHits")), hasRecTracks(pset.getParameter("hasRecTracks")), noBPIX1(pset.getParameter("noBPIX1")), tracks_token(hasRecTracks ? consumes(pset.getParameter("tracks")) @@ -300,13 +306,8 @@ void PixelClusterShapeExtractor::processPixelRecHits(const SiPixelRecHitCollecti /*****************************************************************************/ void PixelClusterShapeExtractor::analyzeSimHits(const edm::Event& ev, const edm::EventSetup& es) const { - edm::ESHandle shape; - es.get().get("ClusterShapeHitFilter", shape); - auto const& theClusterShape = *shape.product(); - - edm::ESHandle tTopoHandle; - es.get().get(tTopoHandle); - auto const& tkTpl = *tTopoHandle; + auto const& theClusterShape = es.getData(csfToken_); + auto const& tkTpl = es.getData(topoToken_); edm::Handle clusterShapeCache; ev.getByToken(clusterShapeCache_token, clusterShapeCache); @@ -329,13 +330,8 @@ void PixelClusterShapeExtractor::analyzeSimHits(const edm::Event& ev, const edm: /*****************************************************************************/ void PixelClusterShapeExtractor::analyzeRecTracks(const edm::Event& ev, const edm::EventSetup& es) const { - edm::ESHandle shape; - es.get().get("ClusterShapeHitFilter", shape); - auto const& theClusterShape = *shape.product(); - - edm::ESHandle tTopoHandle; - es.get().get(tTopoHandle); - auto const& tkTpl = *tTopoHandle; + auto const& theClusterShape = es.getData(csfToken_); + auto const& tkTpl = es.getData(topoToken_); // Get tracks edm::Handle tracks; diff --git a/RecoPixelVertexing/PixelLowPtUtilities/interface/PixelTripletLowPtGenerator.h b/RecoPixelVertexing/PixelLowPtUtilities/interface/PixelTripletLowPtGenerator.h index 96f654937295e..1793db0b5129f 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/interface/PixelTripletLowPtGenerator.h +++ b/RecoPixelVertexing/PixelLowPtUtilities/interface/PixelTripletLowPtGenerator.h @@ -7,6 +7,11 @@ provided Layers */ +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "Geometry/Records/interface/TrackerTopologyRcd.h" + #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/EDGetToken.h" @@ -41,6 +46,9 @@ class PixelTripletLowPtGenerator : public HitTripletGeneratorFromPairAndLayers { const int nThirdLayers) override; private: + edm::ESGetToken m_geomToken; + edm::ESGetToken m_topoToken; + void getTracker(const edm::EventSetup& es); GlobalPoint getGlobalPosition(const TrackingRecHit* recHit); diff --git a/RecoPixelVertexing/PixelLowPtUtilities/interface/StripSubClusterShapeTrajectoryFilter.h b/RecoPixelVertexing/PixelLowPtUtilities/interface/StripSubClusterShapeTrajectoryFilter.h index 17c154b8b10d4..56126fba88500 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/interface/StripSubClusterShapeTrajectoryFilter.h +++ b/RecoPixelVertexing/PixelLowPtUtilities/interface/StripSubClusterShapeTrajectoryFilter.h @@ -9,6 +9,8 @@ #include "FWCore/Utilities/interface/EDGetToken.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h" +#include "CondFormats/SiStripObjects/interface/SiStripNoises.h" +#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h" class ClusterShapeHitFilter; class TrackerTopology; @@ -40,6 +42,12 @@ class StripSubClusterShapeFilterBase { const GlobalVector &gdir, bool mustProject = false) const; + // esConsumes tokens + edm::ESGetToken m_topoToken; + edm::ESGetToken m_csfToken; + edm::ESGetToken m_geomToken; + edm::ESGetToken m_stripNoiseToken; + // who am i std::string label_; diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.cc b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.cc index 22dced0f36975..78f66a1d4c1d8 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.cc @@ -11,15 +11,12 @@ #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h" #include "Geometry/CommonTopologies/interface/PixelTopology.h" -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" + #include "Geometry/CommonDetUnit/interface/GeomDet.h" #include "DataFormats/GeometryVector/interface/LocalPoint.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "Geometry/Records/interface/TrackerTopologyRcd.h" - #include "SimDataFormats/Vertex/interface/SimVertexContainer.h" #include @@ -56,7 +53,7 @@ namespace { /*****************************************************************************/ PixelVertexProducerClusters::PixelVertexProducerClusters(const edm::ParameterSet& ps) - : pixelToken_(consumes(edm::InputTag("siPixelRecHits"))) { + : geomToken_(esConsumes()), pixelToken_(consumes(edm::InputTag("siPixelRecHits"))) { // Product produces(); } @@ -66,14 +63,8 @@ PixelVertexProducerClusters::~PixelVertexProducerClusters() {} /*****************************************************************************/ void PixelVertexProducerClusters::produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const { - //Retrieve tracker topology from geometry - edm::ESHandle tTopo; - es.get().get(tTopo); - // Get tracker geometry - edm::ESHandle trackerHandle; - es.get().get(trackerHandle); - const TrackerGeometry* theTracker = trackerHandle.product(); + const TrackerGeometry* theTracker = &es.getData(geomToken_); // Get pixel hit collections edm::Handle pixelColl; diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.h b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.h index 6515d65d04494..8a1b42cee8b3e 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.h +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerClusters.h @@ -1,11 +1,13 @@ #ifndef PixelVertexProducerClusters_H #define PixelVertexProducerClusters_H +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" #include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" - #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" +class TrackerGeometry; + namespace edm { class Run; class Event; @@ -21,6 +23,7 @@ class PixelVertexProducerClusters : public edm::global::EDProducer<> { void produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const override; private: + const edm::ESGetToken geomToken_; edm::EDGetTokenT pixelToken_; }; #endif diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.cc b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.cc index 54ee5d283606d..dd6f21b6da70e 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.cc @@ -27,6 +27,7 @@ struct ComparePairs { /*****************************************************************************/ PixelVertexProducerMedian::PixelVertexProducerMedian(const edm::ParameterSet& ps) : theConfig(ps) { + thePtMin = theConfig.getParameter("PtMin"); produces(); } @@ -34,15 +35,13 @@ PixelVertexProducerMedian::PixelVertexProducerMedian(const edm::ParameterSet& ps PixelVertexProducerMedian::~PixelVertexProducerMedian() {} /*****************************************************************************/ -void PixelVertexProducerMedian::produce(edm::Event& ev, const edm::EventSetup& es) { +void PixelVertexProducerMedian::produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const { // Get pixel tracks edm::Handle trackCollection; std::string trackCollectionName = theConfig.getParameter("TrackCollection"); ev.getByLabel(trackCollectionName, trackCollection); const reco::TrackCollection tracks_ = *(trackCollection.product()); - thePtMin = theConfig.getParameter("PtMin"); - // Select tracks std::vector tracks; for (unsigned int i = 0; i < tracks_.size(); i++) { diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.h b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.h index 3ab5228c079fe..1be2a44604a50 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.h +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/PixelVertexProducerMedian.h @@ -1,7 +1,7 @@ #ifndef PixelVertexProducerMedian_H #define PixelVertexProducerMedian_H -#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" namespace edm { @@ -9,11 +9,11 @@ namespace edm { class EventSetup; } // namespace edm -class PixelVertexProducerMedian : public edm::EDProducer { +class PixelVertexProducerMedian : public edm::global::EDProducer<> { public: explicit PixelVertexProducerMedian(const edm::ParameterSet& ps); ~PixelVertexProducerMedian() override; - void produce(edm::Event& ev, const edm::EventSetup& es) override; + void produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const override; private: edm::ParameterSet theConfig; diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/SiPixelClusterShapeCacheProducer.cc b/RecoPixelVertexing/PixelLowPtUtilities/plugins/SiPixelClusterShapeCacheProducer.cc index 373636d129ab5..dba9894b23c72 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/SiPixelClusterShapeCacheProducer.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/SiPixelClusterShapeCacheProducer.cc @@ -36,10 +36,11 @@ class SiPixelClusterShapeCacheProducer : public edm::global::EDProducer<> { using InputCollection = edmNew::DetSetVector; const edm::EDGetTokenT token_; + const edm::ESGetToken geomToken_; }; SiPixelClusterShapeCacheProducer::SiPixelClusterShapeCacheProducer(const edm::ParameterSet& iConfig) - : token_(consumes(iConfig.getParameter("src"))) { + : token_(consumes(iConfig.getParameter("src"))), geomToken_(esConsumes()) { if (iConfig.getParameter("onDemand")) { throw cms::Exception("OnDemandNotAllowed") << "Use of the `onDemand` feature of SiPixelClusterShapeCacheProducer is no longer supported"; @@ -60,8 +61,7 @@ void SiPixelClusterShapeCacheProducer::produce(edm::StreamID, edm::Event& iEvent edm::Handle input; iEvent.getByToken(token_, input); - edm::ESHandle geom; - iSetup.get().get(geom); + const auto& geom = &iSetup.getData(geomToken_); auto output = std::make_unique(input); output->resize(input->data().size()); diff --git a/RecoPixelVertexing/PixelLowPtUtilities/plugins/TrackFitterProducer.cc b/RecoPixelVertexing/PixelLowPtUtilities/plugins/TrackFitterProducer.cc index 5a240083547cd..73d61351507da 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/plugins/TrackFitterProducer.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/plugins/TrackFitterProducer.cc @@ -30,12 +30,16 @@ class TrackFitterProducer : public edm::global::EDProducer<> { private: void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override; - std::string theTTRHBuilderName; + const edm::ESGetToken geomToken_; + const edm::ESGetToken magFieldToken_; + const edm::ESGetToken ttrhToken_; edm::EDGetTokenT theBeamSpotToken; }; TrackFitterProducer::TrackFitterProducer(const edm::ParameterSet& iConfig) - : theTTRHBuilderName(iConfig.getParameter("TTRHBuilder")) { + : geomToken_(esConsumes()), + magFieldToken_(esConsumes()), + ttrhToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter("TTRHBuilder")))) { produces(); } @@ -48,16 +52,11 @@ void TrackFitterProducer::fillDescriptions(edm::ConfigurationDescriptions& descr } void TrackFitterProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { - edm::ESHandle trackerESH; - iSetup.get().get(trackerESH); + const auto& tracker = &iSetup.getData(geomToken_); + const auto& field = &iSetup.getData(magFieldToken_); + const auto& ttrh = &iSetup.getData(ttrhToken_); - edm::ESHandle fieldESH; - iSetup.get().get(fieldESH); - - edm::ESHandle ttrhbESH; - iSetup.get().get(theTTRHBuilderName, ttrhbESH); - - auto impl = std::make_unique(trackerESH.product(), fieldESH.product(), ttrhbESH.product()); + auto impl = std::make_unique(tracker, field, ttrh); auto prod = std::make_unique(std::move(impl)); iEvent.put(std::move(prod)); } diff --git a/RecoPixelVertexing/PixelLowPtUtilities/src/PixelTripletLowPtGenerator.cc b/RecoPixelVertexing/PixelLowPtUtilities/src/PixelTripletLowPtGenerator.cc index 0c499fad958a2..f5bf4ed86d4d9 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/src/PixelTripletLowPtGenerator.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/src/PixelTripletLowPtGenerator.cc @@ -6,14 +6,9 @@ #include "RecoTracker/TkMSParametrization/interface/PixelRecoPointRZ.h" #include "RecoTracker/TkHitPairs/interface/HitPairGeneratorFromLayerPair.h" -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "Geometry/Records/interface/TrackerTopologyRcd.h" - #include "FWCore/Framework/interface/Event.h" #include "DataFormats/SiPixelCluster/interface/SiPixelClusterShapeCache.h" @@ -24,6 +19,8 @@ using namespace std; /*****************************************************************************/ PixelTripletLowPtGenerator::PixelTripletLowPtGenerator(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC) : HitTripletGeneratorFromPairAndLayers(), // no theMaxElement used in this class + m_geomToken(iC.esConsumes()), + m_topoToken(iC.esConsumes()), theTracker(nullptr), theClusterShapeCacheToken( iC.consumes(cfg.getParameter("clusterShapeCacheSrc"))) { @@ -44,10 +41,7 @@ PixelTripletLowPtGenerator::~PixelTripletLowPtGenerator() {} void PixelTripletLowPtGenerator::getTracker(const edm::EventSetup& es) { if (theTracker == nullptr) { // Get tracker geometry - edm::ESHandle tracker; - es.get().get(tracker); - - theTracker = tracker.product(); + theTracker = &es.getData(m_geomToken); } if (!theFilter) { @@ -70,9 +64,7 @@ void PixelTripletLowPtGenerator::hitTriplets(const TrackingRegion& region, const SeedingLayerSetsHits::SeedingLayerSet& pairLayers, const std::vector& thirdLayers) { //Retrieve tracker topology from geometry - edm::ESHandle tTopoHand; - es.get().get(tTopoHand); - const TrackerTopology* tTopo = tTopoHand.product(); + const TrackerTopology* tTopo = &es.getData(m_topoToken); edm::Handle clusterShapeCache; ev.getByToken(theClusterShapeCacheToken, clusterShapeCache); diff --git a/RecoPixelVertexing/PixelLowPtUtilities/src/StripSubClusterShapeTrajectoryFilter.cc b/RecoPixelVertexing/PixelLowPtUtilities/src/StripSubClusterShapeTrajectoryFilter.cc index 2423dc6a880e1..da3ec788c7879 100644 --- a/RecoPixelVertexing/PixelLowPtUtilities/src/StripSubClusterShapeTrajectoryFilter.cc +++ b/RecoPixelVertexing/PixelLowPtUtilities/src/StripSubClusterShapeTrajectoryFilter.cc @@ -31,9 +31,6 @@ #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h" #include "DataFormats/SiStripDetId/interface/SiStripDetId.h" -#include "CondFormats/SiStripObjects/interface/SiStripNoises.h" -#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h" - #ifdef StripSubClusterShapeFilterBase_COUNTERS #define INC_COUNTER(X) X++; #else @@ -137,7 +134,12 @@ namespace { /*****************************************************************************/ StripSubClusterShapeFilterBase::StripSubClusterShapeFilterBase(const edm::ParameterSet &iCfg, edm::ConsumesCollector &iC) - : label_(iCfg.getUntrackedParameter("label", "")), + : m_topoToken(iC.esConsumes()), + m_csfToken( + iC.esConsumes(edm::ESInputTag("", "ClusterShapeHitFilter"))), + m_geomToken(iC.esConsumes()), + m_stripNoiseToken(iC.esConsumes()), + label_(iCfg.getUntrackedParameter("label", "")), maxNSat_(iCfg.getParameter("maxNSat")), trimMaxADC_(iCfg.getParameter("trimMaxADC")), trimMaxFracTotal_(iCfg.getParameter("trimMaxFracTotal")), @@ -322,14 +324,12 @@ bool StripSubClusterShapeFilterBase::testLastHit(const TrackingRecHit *hit, void StripSubClusterShapeFilterBase::setEventBase(const edm::Event &event, const edm::EventSetup &es) { // Get tracker geometry - es.get().get(theTracker); - - es.get().get("ClusterShapeHitFilter", theFilter); + theTracker = es.getHandle(m_geomToken); + theFilter = es.getHandle(m_csfToken); //Retrieve tracker topology from geometry - es.get().get(theTopology); - - es.get().get(theNoise); + theTopology = es.getHandle(m_topoToken); + theNoise = es.getHandle(m_stripNoiseToken); } /*****************************************************************************/