Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize some EGamma Reco modules #35021

Merged
merged 12 commits into from
Sep 1, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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<EcalBasicClusterLocalContCorrection>(consumesCollector());
Dr15Jones marked this conversation as resolved.
Show resolved Hide resolved
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
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