Skip to content

Commit

Permalink
more ESGetTokens in EgammaTools
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Nov 2, 2020
1 parent dde811b commit e600e2f
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 190 deletions.
26 changes: 15 additions & 11 deletions RecoEgamma/EgammaTools/interface/EgammaRegressionContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@
// currently e/gamma also can optionally force saturated electrons
// to always be in the high et training

#include "CondFormats/DataRecord/interface/GBRDWrapperRcd.h"
#include "CondFormats/EgammaObjects/interface/GBRForestD.h"
#include "RecoEgamma/EgammaTools/interface/EgammaBDTOutputTransformer.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include <string>

namespace edm {
class ParameterSet;
class ParameterSetDescription;
class EventSetup;
class ConsumesCollector;
} // namespace edm
class GBRForestD;

class EgammaRegressionContainer {
public:
EgammaRegressionContainer(const edm::ParameterSet& iConfig);
EgammaRegressionContainer(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc);
~EgammaRegressionContainer() {}

static edm::ParameterSetDescription makePSetDescription();
Expand All @@ -40,15 +43,16 @@ class EgammaRegressionContainer {

bool forceHighEnergyTrainingIfSaturated_;
const float lowEtHighEtBoundary_;
const std::string ebLowEtForestName_;
const std::string ebHighEtForestName_;
const std::string eeLowEtForestName_;
const std::string eeHighEtForestName_;

const GBRForestD* ebLowEtForest_; //not owned
const GBRForestD* ebHighEtForest_; //not owned
const GBRForestD* eeLowEtForest_; //not owned
const GBRForestD* eeHighEtForest_; //not owned

const edm::ESGetToken<GBRForestD, GBRDWrapperRcd> ebLowEtForestToken_;
const edm::ESGetToken<GBRForestD, GBRDWrapperRcd> ebHighEtForestToken_;
const edm::ESGetToken<GBRForestD, GBRDWrapperRcd> eeLowEtForestToken_;
const edm::ESGetToken<GBRForestD, GBRDWrapperRcd> eeHighEtForestToken_;

const GBRForestD* ebLowEtForest_ = nullptr; //not owned
const GBRForestD* ebHighEtForest_ = nullptr; //not owned
const GBRForestD* eeLowEtForest_ = nullptr; //not owned
const GBRForestD* eeHighEtForest_ = nullptr; //not owned
};

#endif
3 changes: 2 additions & 1 deletion RecoEgamma/EgammaTools/interface/EpCombinationTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ namespace edm {
class ParameterSet;
class ParameterSetDescription;
class EventSetup;
class ConsumesCollector;
} // namespace edm
namespace reco {
class GsfElectron;
}

class EpCombinationTool {
public:
EpCombinationTool(const edm::ParameterSet& iConfig);
EpCombinationTool(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& cc);
~EpCombinationTool() {}

static edm::ParameterSetDescription makePSetDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ namespace {
template <typename T>
CalibratedElectronProducerT<T>::CalibratedElectronProducerT(const edm::ParameterSet& conf)
: electronToken_(consumes<edm::View<T>>(conf.getParameter<edm::InputTag>("src"))),
epCombinationTool_(conf.getParameter<edm::ParameterSet>("epCombConfig")),
epCombinationTool_{conf.getParameter<edm::ParameterSet>("epCombConfig"), consumesCollector()},
energyCorrector_(epCombinationTool_, conf.getParameter<std::string>("correctionFile")),
recHitCollectionEBToken_(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitCollectionEB"))),
recHitCollectionEEToken_(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitCollectionEE"))),
Expand Down
40 changes: 21 additions & 19 deletions RecoEgamma/EgammaTools/plugins/EG8XObjectUpdateModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,46 @@ class EG8XObjectUpdateModifier : public ModifyObjectValueBase {
private:
std::pair<int, bool> getSaturationInfo(const reco::SuperCluster& superClus) const;

edm::ESHandle<CaloTopology> caloTopoHandle_;
edm::Handle<EcalRecHitCollection> ecalRecHitsEBHandle_;
edm::Handle<EcalRecHitCollection> ecalRecHitsEEHandle_;
CaloTopology const* caloTopo_ = nullptr;
EcalRecHitCollection const* ecalRecHitsEB_ = nullptr;
EcalRecHitCollection const* ecalRecHitsEE_ = nullptr;

edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopoToken_;
edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEBToken_;
edm::EDGetTokenT<EcalRecHitCollection> ecalRecHitsEEToken_;
};

EG8XObjectUpdateModifier::EG8XObjectUpdateModifier(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
: ModifyObjectValueBase(conf),
ecalRecHitsEBToken_(cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("ecalRecHitsEB"))),
ecalRecHitsEEToken_(cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("ecalRecHitsEE"))) {}
caloTopoToken_{cc.esConsumes()},
ecalRecHitsEBToken_(cc.consumes(conf.getParameter<edm::InputTag>("ecalRecHitsEB"))),
ecalRecHitsEEToken_(cc.consumes(conf.getParameter<edm::InputTag>("ecalRecHitsEE"))) {}

void EG8XObjectUpdateModifier::setEvent(const edm::Event& iEvent) {
iEvent.getByToken(ecalRecHitsEBToken_, ecalRecHitsEBHandle_);
iEvent.getByToken(ecalRecHitsEEToken_, ecalRecHitsEEHandle_);
ecalRecHitsEB_ = &iEvent.get(ecalRecHitsEBToken_);
ecalRecHitsEE_ = &iEvent.get(ecalRecHitsEEToken_);
}

void EG8XObjectUpdateModifier::setEventContent(const edm::EventSetup& iSetup) {
iSetup.get<CaloTopologyRecord>().get(caloTopoHandle_);
caloTopo_ = &iSetup.getData<CaloTopology, CaloTopologyRecord>(caloTopoToken_);
}

void EG8XObjectUpdateModifier::modifyObject(reco::GsfElectron& ele) const {
const reco::CaloCluster& seedClus = *(ele.superCluster()->seed());
const EcalRecHitCollection* ecalRecHits = ele.isEB() ? &*ecalRecHitsEBHandle_ : &*ecalRecHitsEEHandle_;
const auto* caloTopo = caloTopoHandle_.product();
const EcalRecHitCollection* ecalRecHits = ele.isEB() ? ecalRecHitsEB_ : ecalRecHitsEE_;

auto full5x5ShowerShapes = ele.full5x5_showerShape();
full5x5ShowerShapes.e2x5Left = noZS::EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo);
full5x5ShowerShapes.e2x5Right = noZS::EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo);
full5x5ShowerShapes.e2x5Top = noZS::EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo);
full5x5ShowerShapes.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo);
full5x5ShowerShapes.e2x5Left = noZS::EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo_);
full5x5ShowerShapes.e2x5Right = noZS::EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo_);
full5x5ShowerShapes.e2x5Top = noZS::EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo_);
full5x5ShowerShapes.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo_);
ele.full5x5_setShowerShape(full5x5ShowerShapes);

auto showerShapes = ele.showerShape();
showerShapes.e2x5Left = EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo);
showerShapes.e2x5Right = EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo);
showerShapes.e2x5Top = EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo);
showerShapes.e2x5Bottom = EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo);
showerShapes.e2x5Left = EcalClusterTools::e2x5Left(seedClus, ecalRecHits, caloTopo_);
showerShapes.e2x5Right = EcalClusterTools::e2x5Right(seedClus, ecalRecHits, caloTopo_);
showerShapes.e2x5Top = EcalClusterTools::e2x5Top(seedClus, ecalRecHits, caloTopo_);
showerShapes.e2x5Bottom = EcalClusterTools::e2x5Bottom(seedClus, ecalRecHits, caloTopo_);
ele.setShowerShape(showerShapes);

reco::GsfElectron::SaturationInfo eleSatInfo;
Expand All @@ -91,7 +93,7 @@ void EG8XObjectUpdateModifier::modifyObject(reco::Photon& pho) const {

std::pair<int, bool> EG8XObjectUpdateModifier::getSaturationInfo(const reco::SuperCluster& superClus) const {
bool isEB = superClus.seed()->seed().subdetId() == EcalBarrel;
const auto& ecalRecHits = isEB ? *ecalRecHitsEBHandle_ : *ecalRecHitsEEHandle_;
const auto& ecalRecHits = isEB ? *ecalRecHitsEB_ : *ecalRecHitsEE_;

int nrSatCrys = 0;
bool seedSaturated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class EG9X105XObjectUpdateModifier : public ModifyObjectValueBase {
~EG9X105XObjectUpdateModifier() override {}

void setEvent(const edm::Event&) final;
void setEventContent(const edm::EventSetup&) final;

void modifyObject(reco::GsfElectron& ele) const final;
void modifyObject(reco::Photon& pho) const final;
Expand Down Expand Up @@ -120,8 +119,6 @@ void EG9X105XObjectUpdateModifier::setEvent(const edm::Event& iEvent) {
phoChargedHadPFPVIso_.setHandle(iEvent);
}

void EG9X105XObjectUpdateModifier::setEventContent(const edm::EventSetup& iSetup) {}

void EG9X105XObjectUpdateModifier::modifyObject(reco::GsfElectron& ele) const {
edm::Ptr<reco::GsfElectron> ptrForVM = getPtrForValueMap(ele, eleCollVMsAreKeyedTo_.handle());
if (ptrForVM.isNull()) {
Expand Down
4 changes: 2 additions & 2 deletions RecoEgamma/EgammaTools/plugins/EGEtScaleSysModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class EGEtScaleSysModifier : public ModifyObjectValueBase {
std::unique_ptr<UncertFuncBase> uncertFunc_;
};

EGEtScaleSysModifier::EGEtScaleSysModifier(const edm::ParameterSet& conf, edm::ConsumesCollector&)
: ModifyObjectValueBase(conf), epCombTool_(conf.getParameter<edm::ParameterSet>("epCombConfig")) {
EGEtScaleSysModifier::EGEtScaleSysModifier(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
: ModifyObjectValueBase(conf), epCombTool_{conf.getParameter<edm::ParameterSet>("epCombConfig"), std::move(cc)} {
const edm::ParameterSet funcPSet = conf.getParameter<edm::ParameterSet>("uncertFunc");
const std::string& funcName = funcPSet.getParameter<std::string>("name");
if (funcName == "UncertFuncV1") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class EGFull5x5ShowerShapeModifierFromValueMaps : public ModifyObjectValueBase {
EGFull5x5ShowerShapeModifierFromValueMaps(const edm::ParameterSet& conf, edm::ConsumesCollector& cc);

void setEvent(const edm::Event&) final;
void setEventContent(const edm::EventSetup&) final;

void modifyObject(pat::Electron&) const final;
void modifyObject(pat::Photon&) const final;
Expand Down Expand Up @@ -192,8 +191,6 @@ void EGFull5x5ShowerShapeModifierFromValueMaps::setEvent(const edm::Event& evt)
get_product(evt, ph_conf.tok_hcalDepth2OverEcalBc, pho_vmaps);
}

void EGFull5x5ShowerShapeModifierFromValueMaps::setEventContent(const edm::EventSetup& evs) {}

namespace {
template <typename T, typename U, typename V>
inline void assignValue(const T& ptr, const U& tok, const V& map, float& value) {
Expand Down
22 changes: 17 additions & 5 deletions RecoEgamma/EgammaTools/plugins/EGRegressionModifierHelpers.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#include "RecoEgamma/EgammaTools/plugins/EGRegressionModifierHelpers.h"

std::vector<const GBRForestD*> retrieveGBRForests(edm::EventSetup const& evs, std::vector<std::string> const& names) {
EGRegressionModifierCondTokens::EGRegressionModifierCondTokens(edm::ParameterSet const& config,
std::string const& regressionKey,
std::string const& uncertaintyKey,
edm::ConsumesCollector& cc) {
for (auto const& name : config.getParameter<std::vector<std::string>>(regressionKey)) {
mean.push_back(cc.esConsumes<GBRForestD, GBRDWrapperRcd>(edm::ESInputTag("", name)));
}
for (auto const& name : config.getParameter<std::vector<std::string>>(uncertaintyKey)) {
sigma.push_back(cc.esConsumes<GBRForestD, GBRDWrapperRcd>(edm::ESInputTag("", name)));
}
}

std::vector<const GBRForestD*> retrieveGBRForests(
edm::EventSetup const& evs, std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd>> const& tokens) {
std::vector<const GBRForestD*> items;
edm::ESHandle<GBRForestD> handle;

for (auto const& name : names) {
evs.get<GBRDWrapperRcd>().get(name, handle);
items.push_back(handle.product());
items.reserve(tokens.size());
for (auto const& token : tokens) {
items.push_back(&evs.getData(token));
}

return items;
Expand Down
17 changes: 14 additions & 3 deletions RecoEgamma/EgammaTools/plugins/EGRegressionModifierHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@

#include "CondFormats/DataRecord/interface/GBRDWrapperRcd.h"
#include "CondFormats/EgammaObjects/interface/GBRForestD.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <string>
#include <vector>

std::vector<const GBRForestD*> retrieveGBRForests(edm::EventSetup const& evs, std::vector<std::string> const& names);
struct EGRegressionModifierCondTokens {
EGRegressionModifierCondTokens(edm::ParameterSet const& config,
std::string const& regressionKey,
std::string const& uncertaintyKey,
edm::ConsumesCollector& cc);
std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd>> mean;
std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd>> sigma;
};

std::vector<const GBRForestD*> retrieveGBRForests(
edm::EventSetup const& evs, std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd>> const& tokens);

#endif
43 changes: 19 additions & 24 deletions RecoEgamma/EgammaTools/plugins/EGRegressionModifierV1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ class EGRegressionModifierV1 : public ModifyObjectValueBase {
void modifyObject(pat::Photon& pho) const final { modifyObject(static_cast<reco::Photon&>(pho)); }

private:
struct CondNames {
std::vector<std::string> mean50ns;
std::vector<std::string> sigma50ns;
std::vector<std::string> mean25ns;
std::vector<std::string> sigma25ns;
};

CondNames eleCondNames_;
CondNames phoCondNames_;
EGRegressionModifierCondTokens eleCond50nsTokens_;
EGRegressionModifierCondTokens phoCond50nsTokens_;
EGRegressionModifierCondTokens eleCond25nsTokens_;
EGRegressionModifierCondTokens phoCond25nsTokens_;

std::string condNamesWeight50ns_;
std::string condNamesWeight25ns_;
Expand All @@ -65,6 +60,14 @@ DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, EGRegressionModifierV1, "EGRegressio

EGRegressionModifierV1::EGRegressionModifierV1(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
: ModifyObjectValueBase(conf),
eleCond50nsTokens_{
conf.getParameter<edm::ParameterSet>("electron_config"), "regressionKey_50ns", "uncertaintyKey_50ns", cc},
phoCond50nsTokens_{
conf.getParameter<edm::ParameterSet>("photon_config"), "regressionKey_50ns", "uncertaintyKey_50ns", cc},
eleCond25nsTokens_{
conf.getParameter<edm::ParameterSet>("electron_config"), "regressionKey_25ns", "uncertaintyKey_25ns", cc},
phoCond25nsTokens_{
conf.getParameter<edm::ParameterSet>("photon_config"), "regressionKey_25ns", "uncertaintyKey_25ns", cc},
autoDetectBunchSpacing_(conf.getParameter<bool>("autoDetectBunchSpacing")),
bunchspacing_(autoDetectBunchSpacing_ ? 450 : conf.getParameter<int>("manualBunchSpacing")),
rhoToken_(cc.consumes<double>(conf.getParameter<edm::InputTag>("rhoCollection"))),
Expand All @@ -73,19 +76,9 @@ EGRegressionModifierV1::EGRegressionModifierV1(const edm::ParameterSet& conf, ed
if (autoDetectBunchSpacing_)
bunchSpacingToken_ = cc.consumes<unsigned int>(conf.getParameter<edm::InputTag>("bunchSpacingTag"));

const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
eleCondNames_ = CondNames{.mean50ns = electrons.getParameter<std::vector<std::string>>("regressionKey_50ns"),
.sigma50ns = electrons.getParameter<std::vector<std::string>>("uncertaintyKey_50ns"),
.mean25ns = electrons.getParameter<std::vector<std::string>>("regressionKey_25ns"),
.sigma25ns = electrons.getParameter<std::vector<std::string>>("uncertaintyKey_25ns")};
auto const& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
condNamesWeight50ns_ = electrons.getParameter<std::string>("combinationKey_50ns");
condNamesWeight25ns_ = electrons.getParameter<std::string>("combinationKey_25ns");

const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
phoCondNames_ = CondNames{.mean50ns = photons.getParameter<std::vector<std::string>>("regressionKey_50ns"),
.sigma50ns = photons.getParameter<std::vector<std::string>>("uncertaintyKey_50ns"),
.mean25ns = photons.getParameter<std::vector<std::string>>("regressionKey_25ns"),
.sigma25ns = photons.getParameter<std::vector<std::string>>("uncertaintyKey_25ns")};
}

void EGRegressionModifierV1::setEvent(const edm::Event& evt) {
Expand All @@ -106,11 +99,13 @@ void EGRegressionModifierV1::setEvent(const edm::Event& evt) {
void EGRegressionModifierV1::setEventContent(const edm::EventSetup& evs) {
evs.get<CaloGeometryRecord>().get(caloGeomH_);

phoForestsMean_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? phoCondNames_.mean25ns : phoCondNames_.mean50ns);
phoForestsSigma_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? phoCondNames_.sigma25ns : phoCondNames_.sigma50ns);
phoForestsMean_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? phoCond25nsTokens_.mean : phoCond50nsTokens_.mean);
phoForestsSigma_ =
retrieveGBRForests(evs, (bunchspacing_ == 25) ? phoCond25nsTokens_.sigma : phoCond50nsTokens_.sigma);

eleForestsMean_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? eleCondNames_.mean25ns : eleCondNames_.mean50ns);
eleForestsSigma_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? eleCondNames_.sigma25ns : eleCondNames_.sigma50ns);
eleForestsMean_ = retrieveGBRForests(evs, (bunchspacing_ == 25) ? eleCond25nsTokens_.mean : eleCond50nsTokens_.mean);
eleForestsSigma_ =
retrieveGBRForests(evs, (bunchspacing_ == 25) ? eleCond25nsTokens_.sigma : eleCond50nsTokens_.sigma);

edm::ESHandle<GBRForest> forestEH;
const std::string ep_condnames_weight = (bunchspacing_ == 25) ? condNamesWeight25ns_ : condNamesWeight50ns_;
Expand Down
Loading

0 comments on commit e600e2f

Please sign in to comment.