Skip to content

Commit

Permalink
Merge pull request #35021 from Dr15Jones/esConsumesRecoEgamma
Browse files Browse the repository at this point in the history
Modernize some EGamma Reco modules
  • Loading branch information
cmsbuild authored Sep 1, 2021
2 parents 729ff10 + d73e61c commit 9dccb35
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 170 deletions.
11 changes: 6 additions & 5 deletions RecoEcal/EgammaClusterProducers/src/EgammaSCCorrectionMaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class EgammaSCCorrectionMaker : public edm::stream::EDProducer<> {
edm::EDGetTokenT<EcalRecHitCollection> rHInputProducer_;
edm::EDGetTokenT<reco::SuperClusterCollection> sCInputProducer_;
edm::InputTag rHTag_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeomToken_;

reco::CaloCluster::AlgoId sCAlgo_;
std::string outputCollection_;
Expand All @@ -88,6 +89,7 @@ EgammaSCCorrectionMaker::EgammaSCCorrectionMaker(const edm::ParameterSet& ps) {
rHTag_ = ps.getParameter<edm::InputTag>("recHitProducer");
rHInputProducer_ = consumes<EcalRecHitCollection>(rHTag_);
sCInputProducer_ = consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("rawSuperClusterProducer"));
caloGeomToken_ = esConsumes();
std::string sCAlgo_str = ps.getParameter<std::string>("superClusterAlgo");

// determine which BasicCluster algo we are correcting for
Expand Down Expand Up @@ -139,11 +141,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<EcalBasicClusterLocalContCorrection>(consumesCollector());
Expand All @@ -165,9 +168,7 @@ void EgammaSCCorrectionMaker::produce(edm::Event& evt, const edm::EventSetup& es
localContCorrectionFunction_->init(es);

// get the collection geometry:
edm::ESHandle<CaloGeometry> geoHandle;
es.get<CaloGeometryRecord>().get(geoHandle);
const CaloGeometry& geometry = *geoHandle;
const CaloGeometry& geometry = es.getData(caloGeomToken_);
const CaloSubdetectorGeometry* geometry_p;

std::string rHInputCollection = rHTag_.instance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace edm {
class Event;
class EventSetup;
class ParameterSet;
class ConsumesCollector;
} // namespace edm

class EcalClusterFunctionBaseClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "FWCore/PluginManager/interface/PluginFactory.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h"
typedef edmplugin::PluginFactory<EcalClusterFunctionBaseClass*(const edm::ParameterSet&)> EcalClusterFunctionFactory;
typedef edmplugin::PluginFactory<EcalClusterFunctionBaseClass*(const edm::ParameterSet&, edm::ConsumesCollector)>
EcalClusterFunctionFactory;

#endif
2 changes: 1 addition & 1 deletion RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down
22 changes: 11 additions & 11 deletions RecoEcal/EgammaCoreTools/plugins/EcalClusterCrackCorrection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -38,15 +41,15 @@ class EcalClusterCrackCorrection : public EcalClusterFunctionBaseClass {
void init(const edm::EventSetup &es) override;

private:
edm::ESHandle<EcalClusterCrackCorrParameters> esParams_;
const EcalClusterCrackCorrParameters *params_;
const edm::EventSetup *es_; //needed to access the ECAL geometry
const edm::ESGetToken<EcalClusterCrackCorrParameters, EcalClusterCrackCorrParametersRcd> paramsToken_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
const EcalClusterCrackCorrParameters *params_ = nullptr;
const CaloGeometry *caloGeom_ = nullptr;
};

void EcalClusterCrackCorrection::init(const edm::EventSetup &es) {
es.get<EcalClusterCrackCorrParametersRcd>().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 {
Expand Down Expand Up @@ -77,10 +80,7 @@ float EcalClusterCrackCorrection::getValue(const reco::CaloCluster &seedbclus) c
if (std::abs(seedbclus.eta()) > 1.4442)
return 1.;

edm::ESHandle<CaloGeometry> pG;
es_->get<CaloGeometryRecord>().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;
Expand Down
12 changes: 5 additions & 7 deletions RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyCorrection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -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<EcalClusterEnergyCorrectionParameters> esParams_;
const EcalClusterEnergyCorrectionParameters *params_;
const edm::ESGetToken<EcalClusterEnergyCorrectionParameters, EcalClusterEnergyCorrectionParametersRcd> paramsToken_;
const EcalClusterEnergyCorrectionParameters *params_ = nullptr;
};

// Shower leakage corrections developed by Jungzhie et al. using TB data
Expand Down Expand Up @@ -240,10 +241,7 @@ float EcalClusterEnergyCorrection::getValue(const reco::SuperCluster &superClust
}
}

void EcalClusterEnergyCorrection::init(const edm::EventSetup &es) {
es.get<EcalClusterEnergyCorrectionParametersRcd>().get(esParams_);
params_ = esParams_.product();
}
void EcalClusterEnergyCorrection::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); }

void EcalClusterEnergyCorrection::checkInit() const {
if (!params_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -35,14 +37,13 @@ class EcalClusterEnergyCorrectionObjectSpecific : public EcalClusterFunctionBase
float fEt(float et, int algorithm) const;
float fEnergy(float e, int algorithm) const;

edm::ESHandle<EcalClusterEnergyCorrectionObjectSpecificParameters> esParams_;
const EcalClusterEnergyCorrectionObjectSpecificParameters *params_;
const edm::ESGetToken<EcalClusterEnergyCorrectionObjectSpecificParameters,
EcalClusterEnergyCorrectionObjectSpecificParametersRcd>
paramsToken_;
const EcalClusterEnergyCorrectionObjectSpecificParameters *params_ = nullptr;
};

void EcalClusterEnergyCorrectionObjectSpecific::init(const edm::EventSetup &es) {
es.get<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>().get(esParams_);
params_ = esParams_.product();
}
void EcalClusterEnergyCorrectionObjectSpecific::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); }

void EcalClusterEnergyCorrectionObjectSpecific::checkInit() const {
if (!params_) {
Expand Down
12 changes: 5 additions & 7 deletions RecoEcal/EgammaCoreTools/plugins/EcalClusterEnergyUncertainty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -31,14 +32,11 @@ class EcalClusterEnergyUncertainty : public EcalClusterFunctionBaseClass {
void init(const edm::EventSetup &es) override;

private:
edm::ESHandle<EcalClusterEnergyUncertaintyParameters> esParams_;
const EcalClusterEnergyUncertaintyParameters *params_;
const edm::ESGetToken<EcalClusterEnergyUncertaintyParameters, EcalClusterEnergyUncertaintyParametersRcd> paramsToken_;
const EcalClusterEnergyUncertaintyParameters *params_ = nullptr;
};

void EcalClusterEnergyUncertainty::init(const edm::EventSetup &es) {
es.get<EcalClusterEnergyUncertaintyParametersRcd>().get(esParams_);
params_ = esParams_.product();
}
void EcalClusterEnergyUncertainty::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); }

void EcalClusterEnergyUncertainty::checkInit() const {
if (!params_) {
Expand Down
3 changes: 2 additions & 1 deletion RecoEcal/EgammaCoreTools/test/testEcalClusterFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Description: <one line class summary>
#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"
Expand All @@ -47,7 +48,7 @@ class testEcalClusterFunctions : public edm::EDAnalyzer {

testEcalClusterFunctions::testEcalClusterFunctions(const edm::ParameterSet& ps) {
std::string functionName = ps.getParameter<std::string>("functionName");
ff_ = EcalClusterFunctionFactory::get()->create(functionName, ps);
ff_ = EcalClusterFunctionFactory::get()->create(functionName, ps, consumesCollector());
std::cout << "got " << functionName << " function at: " << ff_.get() << "\n";
}

Expand Down
2 changes: 1 addition & 1 deletion RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<egamma::conv::TrackTable> ctfTrackTable = std::nullopt;
std::optional<egamma::conv::TrackTable> gsfTrackTable = std::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ GsfElectronProducer::GsfElectronProducer(const edm::ParameterSet& cfg, const Gsf
hcalCfgBc_,
isoCfg,
recHitsCfg,
EcalClusterFunctionFactory::get()->create(cfg.getParameter<std::string>("crackCorrectionFunction"), cfg),
EcalClusterFunctionFactory::get()->create(
cfg.getParameter<std::string>("crackCorrectionFunction"), cfg, consumesCollector()),
regressionCfg,
cfg.getParameter<edm::ParameterSet>("trkIsol03Cfg"),
cfg.getParameter<edm::ParameterSet>("trkIsol04Cfg"),
Expand Down
Loading

0 comments on commit 9dccb35

Please sign in to comment.