From 432a7007a57b38b92ff6cff90d2227db5e1ff1b7 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 14:50:52 -0500 Subject: [PATCH 01/12] GsfConstraintAtVertex no longer accesses the EventSetup Users now pass in the required data products to the constructor. --- .../src/GsfElectronAlgo.cc | 2 +- TrackingTools/GsfTracking/BuildFile.xml | 1 - .../interface/GsfConstraintAtVertex.h | 11 ++++--- .../GsfTracking/src/GsfConstraintAtVertex.cc | 31 +++++++++---------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc b/RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc index 694451ad19f3b..1562e13a0a2f5 100644 --- a/RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc +++ b/RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc @@ -629,7 +629,7 @@ reco::GsfElectronCollection GsfElectronAlgo::completeElectrons(edm::Event const& double magneticFieldInTesla = magneticField.inTesla(GlobalPoint(0., 0., 0.)).z(); MultiTrajectoryStateTransform mtsTransform(&trackerGeometry, &magneticField); - GsfConstraintAtVertex constraintAtVtx(eventSetup); + GsfConstraintAtVertex constraintAtVtx(&trackerGeometry, &magneticField); std::optional ctfTrackTable = std::nullopt; std::optional gsfTrackTable = std::nullopt; diff --git a/TrackingTools/GsfTracking/BuildFile.xml b/TrackingTools/GsfTracking/BuildFile.xml index 10774cfe95275..f38545c852ee3 100644 --- a/TrackingTools/GsfTracking/BuildFile.xml +++ b/TrackingTools/GsfTracking/BuildFile.xml @@ -5,7 +5,6 @@ - diff --git a/TrackingTools/GsfTracking/interface/GsfConstraintAtVertex.h b/TrackingTools/GsfTracking/interface/GsfConstraintAtVertex.h index 1f223afbd0c53..c7c5e0c78a5f5 100644 --- a/TrackingTools/GsfTracking/interface/GsfConstraintAtVertex.h +++ b/TrackingTools/GsfTracking/interface/GsfConstraintAtVertex.h @@ -3,7 +3,6 @@ #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" -#include "FWCore/Framework/interface/EventSetup.h" #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "TrackingTools/GsfTools/interface/MultiTrajectoryStateTransform.h" @@ -12,7 +11,10 @@ #include "DataFormats/BeamSpot/interface/BeamSpot.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "RecoTracker/TransientTrackingRecHit/interface/TRecHit2DPosConstraint.h" +#include "TrackingTools/GsfTools/interface/GsfPropagatorAdapter.h" +#include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h" +#include class TrackerGeometry; class MagneticField; class GsfPropagatorAdapter; @@ -20,8 +22,7 @@ class TransverseImpactPointExtrapolator; class GsfConstraintAtVertex { public: - explicit GsfConstraintAtVertex(const edm::EventSetup&); - ~GsfConstraintAtVertex(); + explicit GsfConstraintAtVertex(const TrackerGeometry* geometry, const MagneticField* magField); /// (multi)TSOS after including the beamspot TrajectoryStateOnSurface constrainAtBeamSpot(const reco::GsfTrack&, const reco::BeamSpot&) const; @@ -37,6 +38,6 @@ class GsfConstraintAtVertex { GsfMultiStateUpdator gsfUpdator_; const TrackerGeometry* geometry_; const MagneticField* magField_; - GsfPropagatorAdapter* gsfPropagator_; - TransverseImpactPointExtrapolator* tipExtrapolator_; + GsfPropagatorAdapter gsfPropagator_; + TransverseImpactPointExtrapolator tipExtrapolator_; }; diff --git a/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc b/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc index 8c2a5260d2471..71c341c826c7c 100644 --- a/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc +++ b/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc @@ -2,7 +2,6 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h" @@ -17,25 +16,25 @@ #include "TrackingTools/GsfTracking/interface/GsfMultiStateUpdator.h" #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h" -GsfConstraintAtVertex::GsfConstraintAtVertex(const edm::EventSetup& setup) { - edm::ESHandle geometryHandle; - setup.get().get(geometryHandle); - geometry_ = geometryHandle.product(); +GsfConstraintAtVertex::GsfConstraintAtVertex(const TrackerGeometry* geometry, const MagneticField* magField) + : geometry_(geometry), + magField_(magField), + gsfPropagator_(AnalyticalPropagator(magField, anyDirection)), + tipExtrapolator_(gsfPropagator_) { + //edm::ESHandle geometryHandle; + //setup.get().get(geometryHandle); + geometry_ = geometry; - edm::ESHandle magFieldHandle; - setup.get().get(magFieldHandle); - magField_ = magFieldHandle.product(); + //edm::ESHandle magFieldHandle; + //setup.get().get(magFieldHandle); + //magField_ = magFieldHandle.product(); + magField_ = magField; // edm::ESHandle propagatorHandle; // setup.get().get(propagatorName_,propagatorHandle); // propagator_ = propagatorHandle.product(); - gsfPropagator_ = new GsfPropagatorAdapter(AnalyticalPropagator(magField_, anyDirection)); - tipExtrapolator_ = new TransverseImpactPointExtrapolator(*gsfPropagator_); -} - -GsfConstraintAtVertex::~GsfConstraintAtVertex() { - delete tipExtrapolator_; - delete gsfPropagator_; + //gsfPropagator_ = std::make_unique(AnalyticalPropagator(magField, anyDirection)); + //tipExtrapolator_ = std::make_unique(*gsfPropagator_); } TrajectoryStateOnSurface GsfConstraintAtVertex::constrainAtBeamSpot(const reco::GsfTrack& track, @@ -69,7 +68,7 @@ TrajectoryStateOnSurface GsfConstraintAtVertex::constrainAtPoint(const reco::Gsf TrajectoryStateOnSurface innerState = multiStateTransformer_.innerStateOnSurface(track, *geometry_, magField_); if (!innerState.isValid()) return TrajectoryStateOnSurface(); - TrajectoryStateOnSurface tipState = tipExtrapolator_->extrapolate(innerState, globalPosition); + TrajectoryStateOnSurface tipState = tipExtrapolator_.extrapolate(innerState, globalPosition); if (!tipState.isValid()) return TrajectoryStateOnSurface(); // From 9ceca496a9b22e2d42276b434b44c65928b00a4f Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 15:43:52 -0500 Subject: [PATCH 02/12] EcalClusterFunctionBaseClass classes use esConsumes --- .../src/EgammaSCCorrectionMaker.cc | 5 +++-- .../interface/EcalClusterFunctionBaseClass.h | 1 + .../interface/EcalClusterFunctionFactory.h | 3 ++- .../plugins/EcalClusterCrackCorrection.cc | 22 +++++++++---------- .../plugins/EcalClusterEnergyCorrection.cc | 12 +++++----- ...alClusterEnergyCorrectionObjectSpecific.cc | 15 +++++++------ .../plugins/EcalClusterEnergyUncertainty.cc | 12 +++++----- .../test/testEcalClusterFunctions.cc | 3 ++- .../plugins/GsfElectronProducer.cc | 3 ++- .../src/PhotonEnergyCorrector.cc | 8 +++---- 10 files changed, 43 insertions(+), 41 deletions(-) diff --git a/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc b/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc index fed9687ff7589..5a8d036eaab85 100644 --- a/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc +++ b/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc @@ -139,11 +139,12 @@ EgammaSCCorrectionMaker::EgammaSCCorrectionMaker(const edm::ParameterSet& ps) { // energy correction class if (applyEnergyCorrection_) - energyCorrectionFunction_ = EcalClusterFunctionFactory::get()->create(energyCorrectorName_, ps); + energyCorrectionFunction_ = + EcalClusterFunctionFactory::get()->create(energyCorrectorName_, ps, consumesCollector()); //energyCorrectionFunction_ = EcalClusterFunctionFactory::get()->create("EcalClusterEnergyCorrection", ps); if (applyCrackCorrection_) - crackCorrectionFunction_ = EcalClusterFunctionFactory::get()->create(crackCorrectorName_, ps); + crackCorrectionFunction_ = EcalClusterFunctionFactory::get()->create(crackCorrectorName_, ps, consumesCollector()); if (applyLocalContCorrection_) localContCorrectionFunction_ = std::make_unique(consumesCollector()); diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h b/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h index fae2e5686f193..7d1b9546ecda9 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h @@ -21,6 +21,7 @@ namespace edm { class Event; class EventSetup; class ParameterSet; + class ConsumesCollector; } // namespace edm class EcalClusterFunctionBaseClass { diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h b/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h index 776644a904d89..0d517b905b0b9 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h @@ -12,6 +12,7 @@ #include "FWCore/PluginManager/interface/PluginFactory.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" -typedef edmplugin::PluginFactory EcalClusterFunctionFactory; +typedef edmplugin::PluginFactory + EcalClusterFunctionFactory; #endif diff --git a/RecoEcal/EgammaCoreTools/plugins/EcalClusterCrackCorrection.cc b/RecoEcal/EgammaCoreTools/plugins/EcalClusterCrackCorrection.cc index b119ea72ae7b2..b29889ed6b1a5 100644 --- a/RecoEcal/EgammaCoreTools/plugins/EcalClusterCrackCorrection.cc +++ b/RecoEcal/EgammaCoreTools/plugins/EcalClusterCrackCorrection.cc @@ -16,12 +16,15 @@ #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/Utilities/interface/ESGetToken.h" #include "TVector2.h" class EcalClusterCrackCorrection : public EcalClusterFunctionBaseClass { public: - EcalClusterCrackCorrection(const edm::ParameterSet &){}; + EcalClusterCrackCorrection(const edm::ParameterSet &, edm::ConsumesCollector iC) + : paramsToken_(iC.esConsumes()), geomToken_(iC.esConsumes()) {} // get/set explicit methods for parameters const EcalClusterCrackCorrParameters *getParameters() const { return params_; } @@ -38,15 +41,15 @@ class EcalClusterCrackCorrection : public EcalClusterFunctionBaseClass { void init(const edm::EventSetup &es) override; private: - edm::ESHandle esParams_; - const EcalClusterCrackCorrParameters *params_; - const edm::EventSetup *es_; //needed to access the ECAL geometry + const edm::ESGetToken paramsToken_; + const edm::ESGetToken geomToken_; + const EcalClusterCrackCorrParameters *params_ = nullptr; + const CaloGeometry *caloGeom_ = nullptr; }; void EcalClusterCrackCorrection::init(const edm::EventSetup &es) { - es.get().get(esParams_); - params_ = esParams_.product(); - es_ = &es; //needed to access the ECAL geometry + params_ = &es.getData(paramsToken_); + caloGeom_ = &es.getData(geomToken_); } void EcalClusterCrackCorrection::checkInit() const { @@ -77,10 +80,7 @@ float EcalClusterCrackCorrection::getValue(const reco::CaloCluster &seedbclus) c if (std::abs(seedbclus.eta()) > 1.4442) return 1.; - edm::ESHandle pG; - es_->get().get(pG); - - const CaloSubdetectorGeometry *geom = pG->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); //EcalBarrel = 1 + const CaloSubdetectorGeometry *geom = caloGeom_->getSubdetectorGeometry(DetId::Ecal, EcalBarrel); //EcalBarrel = 1 const math::XYZPoint &position_ = seedbclus.position(); double Theta = -position_.theta() + 0.5 * M_PI; diff --git a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrection.cc b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrection.cc index f515f67b59fd1..e6522c4991b32 100644 --- a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrection.cc +++ b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrection.cc @@ -10,12 +10,13 @@ #include "CondFormats/DataRecord/interface/EcalClusterEnergyCorrectionParametersRcd.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "CondFormats/EcalObjects/interface/EcalClusterEnergyCorrectionParameters.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" class EcalClusterEnergyCorrection : public EcalClusterFunctionBaseClass { public: - EcalClusterEnergyCorrection(const edm::ParameterSet &){}; + EcalClusterEnergyCorrection(const edm::ParameterSet &, edm::ConsumesCollector iC) : paramsToken_(iC.esConsumes()) {} // get/set explicit methods for parameters const EcalClusterEnergyCorrectionParameters *getParameters() const { return params_; } @@ -34,8 +35,8 @@ class EcalClusterEnergyCorrection : public EcalClusterFunctionBaseClass { float fBrem(float e, float eta, int algorithm) const; float fEtEta(float et, float eta, int algorithm) const; - edm::ESHandle esParams_; - const EcalClusterEnergyCorrectionParameters *params_; + const edm::ESGetToken paramsToken_; + const EcalClusterEnergyCorrectionParameters *params_ = nullptr; }; // Shower leakage corrections developed by Jungzhie et al. using TB data @@ -240,10 +241,7 @@ float EcalClusterEnergyCorrection::getValue(const reco::SuperCluster &superClust } } -void EcalClusterEnergyCorrection::init(const edm::EventSetup &es) { - es.get().get(esParams_); - params_ = esParams_.product(); -} +void EcalClusterEnergyCorrection::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); } void EcalClusterEnergyCorrection::checkInit() const { if (!params_) { diff --git a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrectionObjectSpecific.cc b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrectionObjectSpecific.cc index 9ef27199f7057..e0cd6bdfc4105 100644 --- a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrectionObjectSpecific.cc +++ b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrectionObjectSpecific.cc @@ -10,12 +10,14 @@ #include "DataFormats/EcalDetId/interface/EcalSubdetector.h" #include "CondFormats/DataRecord/interface/EcalClusterEnergyCorrectionObjectSpecificParametersRcd.h" #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" #include "CondFormats/EcalObjects/interface/EcalClusterEnergyCorrectionObjectSpecificParameters.h" class EcalClusterEnergyCorrectionObjectSpecific : public EcalClusterFunctionBaseClass { public: - EcalClusterEnergyCorrectionObjectSpecific(const edm::ParameterSet &){}; + EcalClusterEnergyCorrectionObjectSpecific(const edm::ParameterSet &, edm::ConsumesCollector iC) + : paramsToken_(iC.esConsumes()) {} // get/set explicit methods for parameters const EcalClusterEnergyCorrectionObjectSpecificParameters *getParameters() const { return params_; } @@ -35,14 +37,13 @@ class EcalClusterEnergyCorrectionObjectSpecific : public EcalClusterFunctionBase float fEt(float et, int algorithm) const; float fEnergy(float e, int algorithm) const; - edm::ESHandle esParams_; - const EcalClusterEnergyCorrectionObjectSpecificParameters *params_; + const edm::ESGetToken + paramsToken_; + const EcalClusterEnergyCorrectionObjectSpecificParameters *params_ = nullptr; }; -void EcalClusterEnergyCorrectionObjectSpecific::init(const edm::EventSetup &es) { - es.get().get(esParams_); - params_ = esParams_.product(); -} +void EcalClusterEnergyCorrectionObjectSpecific::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); } void EcalClusterEnergyCorrectionObjectSpecific::checkInit() const { if (!params_) { diff --git a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyUncertainty.cc b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyUncertainty.cc index 8bbf5c9d4a508..2a84b5d3a4a7d 100644 --- a/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyUncertainty.cc +++ b/RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyUncertainty.cc @@ -12,11 +12,12 @@ #include "CondFormats/DataRecord/interface/EcalClusterEnergyUncertaintyParametersRcd.h" #include "CondFormats/EcalObjects/interface/EcalClusterEnergyUncertaintyParameters.h" #include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" class EcalClusterEnergyUncertainty : public EcalClusterFunctionBaseClass { public: - EcalClusterEnergyUncertainty(const edm::ParameterSet &){}; + EcalClusterEnergyUncertainty(const edm::ParameterSet &, edm::ConsumesCollector iC) : paramsToken_(iC.esConsumes()) {} // get/set explicit methods for parameters const EcalClusterEnergyUncertaintyParameters *getParameters() const { return params_; } @@ -31,14 +32,11 @@ class EcalClusterEnergyUncertainty : public EcalClusterFunctionBaseClass { void init(const edm::EventSetup &es) override; private: - edm::ESHandle esParams_; - const EcalClusterEnergyUncertaintyParameters *params_; + const edm::ESGetToken paramsToken_; + const EcalClusterEnergyUncertaintyParameters *params_ = nullptr; }; -void EcalClusterEnergyUncertainty::init(const edm::EventSetup &es) { - es.get().get(esParams_); - params_ = esParams_.product(); -} +void EcalClusterEnergyUncertainty::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); } void EcalClusterEnergyUncertainty::checkInit() const { if (!params_) { diff --git a/RecoEcal/EgammaCoreTools/test/testEcalClusterFunctions.cc b/RecoEcal/EgammaCoreTools/test/testEcalClusterFunctions.cc index 362fb22970eaa..07c3208abdd50 100644 --- a/RecoEcal/EgammaCoreTools/test/testEcalClusterFunctions.cc +++ b/RecoEcal/EgammaCoreTools/test/testEcalClusterFunctions.cc @@ -29,6 +29,7 @@ Description: #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h" @@ -47,7 +48,7 @@ class testEcalClusterFunctions : public edm::EDAnalyzer { testEcalClusterFunctions::testEcalClusterFunctions(const edm::ParameterSet& ps) { std::string functionName = ps.getParameter("functionName"); - ff_ = EcalClusterFunctionFactory::get()->create(functionName, ps); + ff_ = EcalClusterFunctionFactory::get()->create(functionName, ps, consumesCollector()); std::cout << "got " << functionName << " function at: " << ff_.get() << "\n"; } diff --git a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronProducer.cc index 28b6bcc789997..ca978e41a11fd 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/GsfElectronProducer.cc @@ -407,7 +407,8 @@ GsfElectronProducer::GsfElectronProducer(const edm::ParameterSet& cfg, const Gsf hcalCfgBc_, isoCfg, recHitsCfg, - EcalClusterFunctionFactory::get()->create(cfg.getParameter("crackCorrectionFunction"), cfg), + EcalClusterFunctionFactory::get()->create( + cfg.getParameter("crackCorrectionFunction"), cfg, consumesCollector()), regressionCfg, cfg.getParameter("trkIsol03Cfg"), cfg.getParameter("trkIsol04Cfg"), diff --git a/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc b/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc index e8d070bac6127..d6547c508c481 100644 --- a/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc +++ b/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc @@ -25,19 +25,19 @@ PhotonEnergyCorrector::PhotonEnergyCorrector(const edm::ParameterSet& config, ed // function to extract f(eta) correction std::string superClusterFunctionName = config.getParameter("superClusterEnergyCorrFunction"); - scEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterFunctionName, config); + scEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterFunctionName, config, iC); // function to extract corrections to cracks std::string superClusterCrackFunctionName = config.getParameter("superClusterCrackEnergyCorrFunction"); - scCrackEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterCrackFunctionName, config); + scCrackEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterCrackFunctionName, config, iC); // function to extract the error on the sc ecal correction std::string superClusterErrorFunctionName = config.getParameter("superClusterEnergyErrorFunction"); - scEnergyErrorFunction_ = EcalClusterFunctionFactory::get()->create(superClusterErrorFunctionName, config); + scEnergyErrorFunction_ = EcalClusterFunctionFactory::get()->create(superClusterErrorFunctionName, config, iC); // function to extract the error on the photon ecal correction std::string photonEnergyFunctionName = config.getParameter("photonEcalEnergyCorrFunction"); - photonEcalEnergyCorrFunction_ = EcalClusterFunctionFactory::get()->create(photonEnergyFunctionName, config); + photonEcalEnergyCorrFunction_ = EcalClusterFunctionFactory::get()->create(photonEnergyFunctionName, config, iC); //ingredient for photon uncertainty photonUncertaintyCalculator_ = std::make_unique(config); From 37d2c89e671ff03c105ed1e724fb2b66d4e4d7c4 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 16:32:13 -0500 Subject: [PATCH 03/12] Improved LowPtGsfElectronIDProducer - used esConsumes - avoid doing large numbers of string constructions and comparisons. --- .../plugins/LowPtGsfElectronIDProducer.cc | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index a4b24b3fd8f0c..ac334f672dd88 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -35,20 +35,24 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { private: double eval( - const std::string& name, const edm::Ptr&, double rho, float unbiased, float field_z) const; + const GBRForest& model, const edm::Ptr&, double rho, float unbiased, float field_z) const; const bool usePAT_; edm::EDGetTokenT electrons_; edm::EDGetTokenT patElectrons_; const edm::EDGetTokenT rho_; edm::EDGetTokenT > unbiased_; + const edm::ESGetToken fieldToken_; + const std::vector names_; const bool passThrough_; const double minPtThreshold_; const double maxPtThreshold_; std::vector > models_; const std::vector thresholds_; - const std::string version_; + const std::string versionName_; + enum class Version { V0, V1 }; + Version version_; }; //////////////////////////////////////////////////////////////////////////////// @@ -59,12 +63,13 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& patElectrons_(), rho_(consumes(conf.getParameter("rho"))), unbiased_(), + fieldToken_(esConsumes()), names_(conf.getParameter >("ModelNames")), passThrough_(conf.getParameter("PassThrough")), minPtThreshold_(conf.getParameter("MinPtThreshold")), maxPtThreshold_(conf.getParameter("MaxPtThreshold")), thresholds_(conf.getParameter >("ModelThresholds")), - version_(conf.getParameter("Version")) { + versionName_(conf.getParameter("Version")) { if (usePAT_) { patElectrons_ = consumes(conf.getParameter("electrons")); } else { @@ -82,8 +87,12 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& throw cms::Exception("Incorrect configuration") << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n"; } - if (version_ != "V0" && version_ != "V1") { - throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n"; + if (versionName_ == "V0") { + version_ = Version::V0; + } else if (versionName_ == "V1") { + version_ = Version::V1; + } else { + throw cms::Exception("Incorrect configuration") << "Unknown Version: " << versionName_ << "\n"; } for (const auto& name : names_) { produces >(name); @@ -94,19 +103,18 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& // void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const { // Get z-component of B field - edm::ESHandle field; - setup.get().get(field); - math::XYZVector zfield(field->inTesla(GlobalPoint(0, 0, 0))); + math::XYZVector zfield(setup.getData(fieldToken_).inTesla(GlobalPoint(0, 0, 0))); // Pileup - edm::Handle rho; - event.getByToken(rho_, rho); - if (!rho.isValid()) { + edm::Handle hRho; + event.getByToken(rho_, hRho); + if (!hRho.isValid()) { std::ostringstream os; os << "Problem accessing rho collection for low-pT electrons" << std::endl; throw cms::Exception("InvalidHandle", os.str()); } + double rho = *hRho; // Retrieve pat::Electrons or reco::GsfElectrons from Event edm::Handle patElectrons; edm::Handle electrons; @@ -124,19 +132,22 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const // Iterate through Electrons, evaluate BDT, and store result std::vector > output; + output.reserve(names_.size()); unsigned int nElectrons = usePAT_ ? patElectrons->size() : electrons->size(); for (unsigned int iname = 0; iname < names_.size(); ++iname) { output.emplace_back(nElectrons, -999.); } if (usePAT_) { + const std::string kUnbiased("unbiased"); for (unsigned int iele = 0; iele < nElectrons; iele++) { edm::Ptr ele(patElectrons, iele); if (!ele->isElectronIDAvailable("unbiased")) { continue; } - for (unsigned int iname = 0; iname < names_.size(); ++iname) { - output[iname][iele] = eval(names_[iname], ele, *rho, ele->electronID("unbiased"), zfield.z()); + float id = ele->electronID(kUnbiased); + for (unsigned int index = 0; index < models_.size(); ++index) { + output[index][iele] = eval(*models_[index], ele, rho, id, zfield.z()); } } } else { @@ -150,8 +161,8 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const continue; } float unbiased = (*unbiasedH)[gsf]; - for (unsigned int iname = 0; iname < names_.size(); ++iname) { - output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z()); + for (unsigned int index = 0; index < models_.size(); ++index) { + output[index][iele] = eval(*models_[index], ele, rho, unbiased, zfield.z()); } } } @@ -173,21 +184,14 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const ////////////////////////////////////////////////////////////////////////////////////////// // double LowPtGsfElectronIDProducer::eval( - const std::string& name, const edm::Ptr& ele, double rho, float unbiased, float field_z) const { - auto iter = std::find(names_.begin(), names_.end(), name); - if (iter != names_.end()) { - int index = std::distance(names_.begin(), iter); - std::vector inputs; - if (version_ == "V0") { - inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); - } else if (version_ == "V1") { - inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z); - } - return models_.at(index)->GetResponse(inputs.data()); - } else { - throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n"; + const GBRForest& model, const edm::Ptr& ele, double rho, float unbiased, float field_z) const { + std::vector inputs; + if (version_ == Version::V0) { + inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); + } else if (version_ == Version::V1) { + inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z); } - return 0.; + return model.GetResponse(inputs.data()); } ////////////////////////////////////////////////////////////////////////////////////////// From 50d6202c50f8e24349427531a475025fc8812881 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 16:53:58 -0500 Subject: [PATCH 04/12] Removed unnecessary use of edm::Ptr --- .../plugins/LowPtGsfElectronIDProducer.cc | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index ac334f672dd88..fd02717cf7dce 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -34,8 +34,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - double eval( - const GBRForest& model, const edm::Ptr&, double rho, float unbiased, float field_z) const; + double eval(const GBRForest& model, const reco::GsfElectron&, double rho, float unbiased, float field_z) const; const bool usePAT_; edm::EDGetTokenT electrons_; @@ -141,22 +140,22 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const if (usePAT_) { const std::string kUnbiased("unbiased"); for (unsigned int iele = 0; iele < nElectrons; iele++) { - edm::Ptr ele(patElectrons, iele); - if (!ele->isElectronIDAvailable("unbiased")) { + pat::Electron const& ele = (*patElectrons)[iele]; + if (!ele.isElectronIDAvailable("unbiased")) { continue; } - float id = ele->electronID(kUnbiased); + float id = ele.electronID(kUnbiased); for (unsigned int index = 0; index < models_.size(); ++index) { output[index][iele] = eval(*models_[index], ele, rho, id, zfield.z()); } } } else { for (unsigned int iele = 0; iele < nElectrons; iele++) { - edm::Ptr ele(electrons, iele); - if (ele->core().isNull()) { + reco::GsfElectron const& ele = (*electrons)[iele]; + if (ele.core().isNull()) { continue; } - const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef + const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNull()) { continue; } @@ -184,12 +183,12 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const ////////////////////////////////////////////////////////////////////////////////////////// // double LowPtGsfElectronIDProducer::eval( - const GBRForest& model, const edm::Ptr& ele, double rho, float unbiased, float field_z) const { + const GBRForest& model, const reco::GsfElectron& ele, double rho, float unbiased, float field_z) const { std::vector inputs; if (version_ == Version::V0) { - inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased); + inputs = lowptgsfeleid::features_V0(ele, rho, unbiased); } else if (version_ == Version::V1) { - inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z); + inputs = lowptgsfeleid::features_V1(ele, rho, unbiased, field_z); } return model.GetResponse(inputs.data()); } From 62840319fabbe655a2b68591f7379eadf2206f7b Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 18:39:44 -0500 Subject: [PATCH 05/12] consolidate common code patterns into a template function --- .../plugins/LowPtGsfElectronIDProducer.cc | 84 ++++++++++--------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index fd02717cf7dce..19d54319292bd 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -36,6 +36,8 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { private: double eval(const GBRForest& model, const reco::GsfElectron&, double rho, float unbiased, float field_z) const; + template + void doWork(double rho, float bz, EL const& electrons, F&& idFunctor, edm::Event&) const; const bool usePAT_; edm::EDGetTokenT electrons_; edm::EDGetTokenT patElectrons_; @@ -118,63 +120,67 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::Handle patElectrons; edm::Handle electrons; if (usePAT_) { - event.getByToken(patElectrons_, patElectrons); - } else { - event.getByToken(electrons_, electrons); - } + auto const& electrons = event.getHandle(patElectrons_); - // ElectronSeed unbiased BDT - edm::Handle > unbiasedH; - if (!unbiased_.isUninitialized()) { - event.getByToken(unbiased_, unbiasedH); + const std::string kUnbiased("unbiased"); + doWork( + rho, + zfield.z(), + electrons, + [&](auto const& ele) { + if (!ele.isElectronIDAvailable(kUnbiased)) { + return std::numeric_limits::max(); + } + return ele.electronID(kUnbiased); + }, + event); + } else { + auto const& electrons = event.getHandle(electrons_); + // ElectronSeed unbiased BDT + edm::ValueMap const& unbiasedH = event.get(unbiased_); + doWork( + rho, + zfield.z(), + electrons, + [&](auto const& ele) { + if (ele.core().isNull()) { + return std::numeric_limits::max(); + } + const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef + if (gsf.isNull()) { + return std::numeric_limits::max(); + } + return unbiasedH[gsf]; + }, + event); } +} +template +void LowPtGsfElectronIDProducer::doWork( + double rho, float bz, EL const& electrons, F&& idFunctor, edm::Event& event) const { // Iterate through Electrons, evaluate BDT, and store result std::vector > output; output.reserve(names_.size()); - unsigned int nElectrons = usePAT_ ? patElectrons->size() : electrons->size(); + auto nElectrons = electrons->size(); for (unsigned int iname = 0; iname < names_.size(); ++iname) { output.emplace_back(nElectrons, -999.); } - if (usePAT_) { - const std::string kUnbiased("unbiased"); - for (unsigned int iele = 0; iele < nElectrons; iele++) { - pat::Electron const& ele = (*patElectrons)[iele]; - if (!ele.isElectronIDAvailable("unbiased")) { - continue; - } - float id = ele.electronID(kUnbiased); + for (unsigned int iele = 0; iele < nElectrons; iele++) { + auto const& ele = (*electrons)[iele]; + float id = idFunctor(ele); + if (id != std::numeric_limits::max()) { for (unsigned int index = 0; index < models_.size(); ++index) { - output[index][iele] = eval(*models_[index], ele, rho, id, zfield.z()); - } - } - } else { - for (unsigned int iele = 0; iele < nElectrons; iele++) { - reco::GsfElectron const& ele = (*electrons)[iele]; - if (ele.core().isNull()) { - continue; - } - const auto& gsf = ele.core()->gsfTrack(); // reco::GsfTrackRef - if (gsf.isNull()) { - continue; - } - float unbiased = (*unbiasedH)[gsf]; - for (unsigned int index = 0; index < models_.size(); ++index) { - output[index][iele] = eval(*models_[index], ele, rho, unbiased, zfield.z()); + output[index][iele] = eval(*models_[index], ele, rho, id, bz); } } } - // Create and put ValueMap in Event for (unsigned int iname = 0; iname < names_.size(); ++iname) { auto ptr = std::make_unique >(edm::ValueMap()); edm::ValueMap::Filler filler(*ptr); - if (usePAT_) { - filler.insert(patElectrons, output[iname].begin(), output[iname].end()); - } else { - filler.insert(electrons, output[iname].begin(), output[iname].end()); - } + filler.insert(electrons, output[iname].begin(), output[iname].end()); filler.fill(); event.put(std::move(ptr), names_[iname]); } From 4a3752c8ceebec17338f409c395f4f0133edea58 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 18:57:42 -0500 Subject: [PATCH 06/12] Changed loop order to model then electrons This avoids having to keep all the model results in memory at one time. --- .../plugins/LowPtGsfElectronIDProducer.cc | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 19d54319292bd..79b1b1788b913 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -159,30 +159,27 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const template void LowPtGsfElectronIDProducer::doWork( double rho, float bz, EL const& electrons, F&& idFunctor, edm::Event& event) const { - // Iterate through Electrons, evaluate BDT, and store result - std::vector > output; - output.reserve(names_.size()); auto nElectrons = electrons->size(); - for (unsigned int iname = 0; iname < names_.size(); ++iname) { - output.emplace_back(nElectrons, -999.); - } - - for (unsigned int iele = 0; iele < nElectrons; iele++) { - auto const& ele = (*electrons)[iele]; - float id = idFunctor(ele); - if (id != std::numeric_limits::max()) { - for (unsigned int index = 0; index < models_.size(); ++index) { - output[index][iele] = eval(*models_[index], ele, rho, id, bz); + std::vector ids; + ids.reserve(nElectrons); + std::transform(electrons->begin(), electrons->end(), std::back_inserter(ids), idFunctor); + + std::vector output(nElectrons); //resused for each model + for (unsigned int index = 0; index < names_.size(); ++index) { + // Iterate through Electrons, evaluate BDT, and store result + for (unsigned int iele = 0; iele < nElectrons; iele++) { + auto const& ele = (*electrons)[iele]; + if (ids[iele] != std::numeric_limits::max()) { + output[iele] = eval(*models_[index], ele, rho, ids[iele], bz); + } else { + output[iele] = -999.; } } - } - - for (unsigned int iname = 0; iname < names_.size(); ++iname) { auto ptr = std::make_unique >(edm::ValueMap()); edm::ValueMap::Filler filler(*ptr); - filler.insert(electrons, output[iname].begin(), output[iname].end()); + filler.insert(electrons, output.begin(), output.end()); filler.fill(); - event.put(std::move(ptr), names_[iname]); + event.put(std::move(ptr), names_[index]); } } From 7d4a23c41aeb0306c5b083c8870e33a7af3abb9d Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 19:10:47 -0500 Subject: [PATCH 07/12] Use EDPutTokenT to avoid making a temporary container on the heap Some code-formatting also snuck in. --- .../plugins/LowPtGsfElectronIDProducer.cc | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 79b1b1788b913..96327668a8fd4 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -42,14 +42,15 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { edm::EDGetTokenT electrons_; edm::EDGetTokenT patElectrons_; const edm::EDGetTokenT rho_; - edm::EDGetTokenT > unbiased_; + edm::EDGetTokenT> unbiased_; const edm::ESGetToken fieldToken_; const std::vector names_; + std::vector>> putTokens_; const bool passThrough_; const double minPtThreshold_; const double maxPtThreshold_; - std::vector > models_; + std::vector> models_; const std::vector thresholds_; const std::string versionName_; enum class Version { V0, V1 }; @@ -65,19 +66,19 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& rho_(consumes(conf.getParameter("rho"))), unbiased_(), fieldToken_(esConsumes()), - names_(conf.getParameter >("ModelNames")), + names_(conf.getParameter>("ModelNames")), passThrough_(conf.getParameter("PassThrough")), minPtThreshold_(conf.getParameter("MinPtThreshold")), maxPtThreshold_(conf.getParameter("MaxPtThreshold")), - thresholds_(conf.getParameter >("ModelThresholds")), + thresholds_(conf.getParameter>("ModelThresholds")), versionName_(conf.getParameter("Version")) { if (usePAT_) { patElectrons_ = consumes(conf.getParameter("electrons")); } else { electrons_ = consumes(conf.getParameter("electrons")); - unbiased_ = consumes >(conf.getParameter("unbiased")); + unbiased_ = consumes>(conf.getParameter("unbiased")); } - for (auto& weights : conf.getParameter >("ModelWeights")) { + for (auto& weights : conf.getParameter>("ModelWeights")) { models_.push_back(createGBRForest(edm::FileInPath(weights))); } if (names_.size() != models_.size()) { @@ -95,8 +96,9 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& } else { throw cms::Exception("Incorrect configuration") << "Unknown Version: " << versionName_ << "\n"; } + putTokens_.reserve(names_.size()); for (const auto& name : names_) { - produces >(name); + putTokens_.emplace_back(produces>(name)); } } @@ -175,11 +177,11 @@ void LowPtGsfElectronIDProducer::doWork( output[iele] = -999.; } } - auto ptr = std::make_unique >(edm::ValueMap()); - edm::ValueMap::Filler filler(*ptr); + edm::ValueMap valueMap; + edm::ValueMap::Filler filler(valueMap); filler.insert(electrons, output.begin(), output.end()); filler.fill(); - event.put(std::move(ptr), names_[index]); + event.emplace(putTokens_[index], std::move(valueMap)); } } @@ -204,10 +206,10 @@ void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); desc.addOptional("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); desc.add("rho", edm::InputTag("fixedGridRhoFastjetAll")); - desc.add >("ModelNames", {""}); - desc.add >( + desc.add>("ModelNames", {""}); + desc.add>( "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root"}); - desc.add >("ModelThresholds", {-99.}); + desc.add>("ModelThresholds", {-99.}); desc.add("PassThrough", false); desc.add("MinPtThreshold", 0.5); desc.add("MaxPtThreshold", 15.); From 18f1955f8ad5f06564be631f785b57b944bf541b Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 25 Aug 2021 19:21:47 -0500 Subject: [PATCH 08/12] Added missing esConsumes to LowPtGsfElectronSeedProducer --- .../plugins/LowPtGsfElectronSeedProducer.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 26d8d7d9d245f..6492ecdd1b94b 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -152,6 +152,7 @@ class LowPtGsfElectronSeedProducer final const edm::ESGetToken trajectoryFitterToken_; const edm::ESGetToken trajectorySmootherToken_; const edm::ESGetToken builderToken_; + const edm::ESGetToken magToken_; const noZS::EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_; const bool passThrough_; @@ -183,6 +184,7 @@ LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer(const edm::ParameterS trajectoryFitterToken_{esConsumes(conf.getParameter("Fitter"))}, trajectorySmootherToken_{esConsumes(conf.getParameter("Smoother"))}, builderToken_{esConsumes(conf.getParameter("TTRHBuilder"))}, + magToken_{esConsumes()}, ecalClusterToolsESGetTokens_{consumesCollector()}, passThrough_(conf.getParameter("PassThrough")), usePfTracks_(conf.getParameter("UsePfTracks")), @@ -203,7 +205,7 @@ LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer(const edm::ParameterS ////////////////////////////////////////////////////////////////////////////////////////// // void LowPtGsfElectronSeedProducer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& setup) { - setup.get().get(field_); + field_ = setup.getHandle(magToken_); } ////////////////////////////////////////////////////////////////////////////////////////// From d7742ff255044951d6176cc0a4ae7fa15e48d737 Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Wed, 25 Aug 2021 21:49:57 +0200 Subject: [PATCH 09/12] Remove redundant PhotonEnergyCorrector::init() call from GEDPhotonProducer::beginRun() It is called unconditionally from GEDPhotonProducer::produce(), I can not see how the call from beginRun() could do anything additional except it would require different set ESGetTokens wihtin PhotonEnergyCorrector etc compared to other users. --- RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc index 8b80e31f244fd..6f953ca768599 100644 --- a/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc +++ b/RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc @@ -51,8 +51,6 @@ class GEDPhotonProducer : public edm::stream::EDProducer<> { public: GEDPhotonProducer(const edm::ParameterSet& ps); - void beginRun(edm::Run const& r, edm::EventSetup const& es) final; - void endRun(edm::Run const&, edm::EventSetup const&) final {} void produce(edm::Event& evt, const edm::EventSetup& es) override; private: @@ -360,12 +358,6 @@ GEDPhotonProducer::GEDPhotonProducer(const edm::ParameterSet& config) } } -void GEDPhotonProducer::beginRun(edm::Run const& r, edm::EventSetup const& eventSetup) { - if (!recoStep_.isFinal()) { - photonEnergyCorrector_->init(eventSetup); - } -} - void GEDPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& eventSetup) { using namespace edm; From b1892a6914b2d6008a8b4b001f9fbec372829e81 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 27 Aug 2021 08:49:55 -0500 Subject: [PATCH 10/12] removed redunadant and commented out code --- .../GsfTracking/src/GsfConstraintAtVertex.cc | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc b/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc index 71c341c826c7c..b0c3cff39518a 100644 --- a/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc +++ b/TrackingTools/GsfTracking/src/GsfConstraintAtVertex.cc @@ -20,22 +20,7 @@ GsfConstraintAtVertex::GsfConstraintAtVertex(const TrackerGeometry* geometry, co : geometry_(geometry), magField_(magField), gsfPropagator_(AnalyticalPropagator(magField, anyDirection)), - tipExtrapolator_(gsfPropagator_) { - //edm::ESHandle geometryHandle; - //setup.get().get(geometryHandle); - geometry_ = geometry; - - //edm::ESHandle magFieldHandle; - //setup.get().get(magFieldHandle); - //magField_ = magFieldHandle.product(); - magField_ = magField; - - // edm::ESHandle propagatorHandle; - // setup.get().get(propagatorName_,propagatorHandle); - // propagator_ = propagatorHandle.product(); - //gsfPropagator_ = std::make_unique(AnalyticalPropagator(magField, anyDirection)); - //tipExtrapolator_ = std::make_unique(*gsfPropagator_); -} + tipExtrapolator_(gsfPropagator_) {} TrajectoryStateOnSurface GsfConstraintAtVertex::constrainAtBeamSpot(const reco::GsfTrack& track, const reco::BeamSpot& beamSpot) const { From a1693428569e90fd7f042b8961e367cd42ca37c1 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 27 Aug 2021 09:33:16 -0500 Subject: [PATCH 11/12] Take ConsumesCollector by value not rvalue reference This is now the recommended way to use the ConsumesCollector as it is trivially copyable. --- RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h b/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h index 4ea5ef11fe96e..4bacd8b340742 100644 --- a/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h +++ b/RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h @@ -54,7 +54,7 @@ class EcalClusterLazyToolsBase { class ESGetTokens { public: - ESGetTokens(edm::ConsumesCollector &&cc) + ESGetTokens(edm::ConsumesCollector cc) : caloGeometryToken_{cc.esConsumes()}, caloTopologyToken_{cc.esConsumes()}, ecalIntercalibConstantsToken_{cc.esConsumes()}, From d73e61c2e90863e8c323067870d87cb9b2dbd5f8 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 27 Aug 2021 09:42:29 -0500 Subject: [PATCH 12/12] Added missing esConsumes --- .../EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc | 6 +++--- .../EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h | 1 + RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc b/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc index 5a8d036eaab85..020f7aa27d5a9 100644 --- a/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc +++ b/RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc @@ -75,6 +75,7 @@ class EgammaSCCorrectionMaker : public edm::stream::EDProducer<> { edm::EDGetTokenT rHInputProducer_; edm::EDGetTokenT sCInputProducer_; edm::InputTag rHTag_; + edm::ESGetToken caloGeomToken_; reco::CaloCluster::AlgoId sCAlgo_; std::string outputCollection_; @@ -88,6 +89,7 @@ EgammaSCCorrectionMaker::EgammaSCCorrectionMaker(const edm::ParameterSet& ps) { rHTag_ = ps.getParameter("recHitProducer"); rHInputProducer_ = consumes(rHTag_); sCInputProducer_ = consumes(ps.getParameter("rawSuperClusterProducer")); + caloGeomToken_ = esConsumes(); std::string sCAlgo_str = ps.getParameter("superClusterAlgo"); // determine which BasicCluster algo we are correcting for @@ -166,9 +168,7 @@ void EgammaSCCorrectionMaker::produce(edm::Event& evt, const edm::EventSetup& es localContCorrectionFunction_->init(es); // get the collection geometry: - edm::ESHandle geoHandle; - es.get().get(geoHandle); - const CaloGeometry& geometry = *geoHandle; + const CaloGeometry& geometry = es.getData(caloGeomToken_); const CaloSubdetectorGeometry* geometry_p; std::string rHInputCollection = rHTag_.instance(); diff --git a/RecoEgamma/EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h b/RecoEgamma/EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h index fc66f5bd5837d..f512f93fd9681 100644 --- a/RecoEgamma/EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h +++ b/RecoEgamma/EgammaPhotonAlgos/interface/PhotonEnergyCorrector.h @@ -52,6 +52,7 @@ class PhotonEnergyCorrector { edm::EDGetTokenT barrelEcalHitsToken_; edm::EDGetTokenT endcapEcalHitsToken_; const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_; + const edm::ESGetToken caloGeomToken_; std::unique_ptr photonUncertaintyCalculator_; }; diff --git a/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc b/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc index d6547c508c481..cf3964dfa3ec0 100644 --- a/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc +++ b/RecoEgamma/EgammaPhotonAlgos/src/PhotonEnergyCorrector.cc @@ -11,7 +11,7 @@ #include "RecoEgamma/EgammaPhotonAlgos/interface/EnergyUncertaintyPhotonSpecific.h" PhotonEnergyCorrector::PhotonEnergyCorrector(const edm::ParameterSet& config, edm::ConsumesCollector&& iC) - : ecalClusterToolsESGetTokens_{std::move(iC)} { + : ecalClusterToolsESGetTokens_{iC}, caloGeomToken_{iC.esConsumes()} { minR9Barrel_ = config.getParameter("minR9Barrel"); minR9Endcap_ = config.getParameter("minR9Endcap"); // get the geometry from the event setup: @@ -58,7 +58,7 @@ PhotonEnergyCorrector::PhotonEnergyCorrector(const edm::ParameterSet& config, ed } void PhotonEnergyCorrector::init(const edm::EventSetup& theEventSetup) { - theEventSetup.get().get(theCaloGeom_); + theCaloGeom_ = theEventSetup.getHandle(caloGeomToken_); scEnergyFunction_->init(theEventSetup); scCrackEnergyFunction_->init(theEventSetup);