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

Change EGM code to be able to read HCAL PF thresholds from DB #43164

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
etThresHB = cms.vdouble( 0.0, 0.0, 0.0, 0.0 ),
eThresHE = cms.vdouble( 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 ),
etThresHE = cms.vdouble( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ),
usePFThresholdsFromDB = cms.bool(True),
rappoccio marked this conversation as resolved.
Show resolved Hide resolved
maxSeverityHB = cms.int32( 9 ),
maxSeverityHE = cms.int32( 9 )
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
etThresHB = cms.vdouble( 0.0, 0.0, 0.0, 0.0 ),
eThresHE = cms.vdouble( 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 ),
etThresHE = cms.vdouble( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ),
usePFThresholdsFromDB = cms.bool(True),
rappoccio marked this conversation as resolved.
Show resolved Hide resolved
maxSeverityHB = cms.int32( 9 ),
maxSeverityHE = cms.int32( 9 )
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h"
#include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
#include "Geometry/CaloTopology/interface/CaloTowerConstituentsMap.h"
#include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
#include "CondTools/Hcal/interface/HcalPFCutsHandler.h"

class ConsumesCollector;
class EgammaHadTower;
Expand Down Expand Up @@ -43,7 +45,7 @@ class ElectronHcalHelper {
void beginEvent(const edm::Event &evt, const edm::EventSetup &eventSetup);

inline auto hcalTowersBehindClusters(const reco::SuperCluster &sc) const { return egamma::towersOf(sc, *towerMap_); }
double hcalESum(const reco::SuperCluster &, int depth) const;
double hcalESum(const reco::SuperCluster &, int depth, const HcalPFCuts *hcalCuts) const;
double hOverEConeSize() const { return cfg_.hOverEConeSize; }
int maxSeverityHB() const { return cfg_.maxSeverityHB; }
int maxSeverityHE() const { return cfg_.maxSeverityHE; }
Expand Down
9 changes: 6 additions & 3 deletions RecoEgamma/EgammaElectronAlgos/interface/GsfElectronAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class GsfElectronAlgo {
// main methods
reco::GsfElectronCollection completeElectrons(edm::Event const& event,
edm::EventSetup const& eventSetup,
const HeavyObjectCache* hoc);
const HeavyObjectCache* hoc,
const HcalPFCuts* hcalCuts);

private:
// internal structures
Expand Down Expand Up @@ -258,7 +259,8 @@ class GsfElectronAlgo {
const HeavyObjectCache*,
egamma::conv::TrackTableView ctfTable,
egamma::conv::TrackTableView gsfTable,
EcalPFRecHitThresholds const& thresholds);
EcalPFRecHitThresholds const& thresholds,
const HcalPFCuts* hcalCuts);

void setCutBasedPreselectionFlag(reco::GsfElectron& ele, const reco::BeamSpot&) const;

Expand All @@ -269,7 +271,8 @@ class GsfElectronAlgo {
EventData const& eventData,
CaloTopology const& topology,
CaloGeometry const& geometry,
EcalPFRecHitThresholds const& thresholds) const;
EcalPFRecHitThresholds const& thresholds,
const HcalPFCuts* hcalCuts) const;
reco::GsfElectron::SaturationInfo calculateSaturationInfo(const reco::SuperClusterRef&,
EventData const& eventData) const;

Expand Down
6 changes: 3 additions & 3 deletions RecoEgamma/EgammaElectronAlgos/src/ElectronHcalHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ bool ElectronHcalHelper::hasActiveHcal(const reco::SuperCluster& sc) const {
: true;
}

double ElectronHcalHelper::hcalESum(const SuperCluster& sc, int depth) const {
return (cfg_.onlyBehindCluster) ? hcalIso_->getHcalESumBc(&sc, depth)
: (cfg_.hOverEConeSize > 0.) ? hcalIso_->getHcalESum(&sc, depth)
double ElectronHcalHelper::hcalESum(const SuperCluster& sc, int depth, const HcalPFCuts* hcalCuts) const {
return (cfg_.onlyBehindCluster) ? hcalIso_->getHcalESumBc(&sc, depth, hcalCuts)
: (cfg_.hOverEConeSize > 0.) ? hcalIso_->getHcalESum(&sc, depth, hcalCuts)
: 0.;
}
47 changes: 33 additions & 14 deletions RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "RecoEgamma/EgammaElectronAlgos/interface/ecalClusterEnergyUncertaintyElectronSpecific.h"
#include "CommonTools/Egamma/interface/ConversionTools.h"
#include "RecoEcal/EgammaCoreTools/interface/EgammaLocalCovParamDefaults.h"
#include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
#include "CondTools/Hcal/interface/HcalPFCutsHandler.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

#include <Math/Point3D.h>
#include <memory>
Expand Down Expand Up @@ -311,7 +314,8 @@ reco::GsfElectron::ShowerShape GsfElectronAlgo::calculateShowerShape(const reco:
EventData const& eventData,
CaloTopology const& topology,
CaloGeometry const& geometry,
EcalPFRecHitThresholds const& thresholds) const {
EcalPFRecHitThresholds const& thresholds,
const HcalPFCuts* hcalCuts) const {
using ClusterTools = EcalClusterToolsT<full5x5>;
reco::GsfElectron::ShowerShape showerShape;

Expand Down Expand Up @@ -358,8 +362,8 @@ reco::GsfElectron::ShowerShape GsfElectronAlgo::calculateShowerShape(const reco:
const float scale = full5x5 ? showerShape.e5x5 : theClus->energy();

for (uint id = 0; id < showerShape.hcalOverEcal.size(); ++id) {
showerShape.hcalOverEcal[id] = hcalHelperCone.hcalESum(*theClus, id + 1) / scale;
showerShape.hcalOverEcalBc[id] = hcalHelperBc.hcalESum(*theClus, id + 1) / scale;
showerShape.hcalOverEcal[id] = hcalHelperCone.hcalESum(*theClus, id + 1, hcalCuts) / scale;
showerShape.hcalOverEcalBc[id] = hcalHelperBc.hcalESum(*theClus, id + 1, hcalCuts) / scale;
}
showerShape.invalidHcal = !hcalHelperBc.hasActiveHcal(*theClus);
showerShape.hcalTowersBehindClusters = hcalHelperBc.hcalTowersBehindClusters(*theClus);
Expand Down Expand Up @@ -662,7 +666,8 @@ GsfElectronAlgo::EventData GsfElectronAlgo::beginEvent(edm::Event const& event,

reco::GsfElectronCollection GsfElectronAlgo::completeElectrons(edm::Event const& event,
edm::EventSetup const& eventSetup,
const GsfElectronAlgo::HeavyObjectCache* hoc) {
const GsfElectronAlgo::HeavyObjectCache* hoc,
const HcalPFCuts* hcalCuts) {
reco::GsfElectronCollection electrons;

auto const& magneticField = eventSetup.getData(magneticFieldToken_);
Expand Down Expand Up @@ -725,7 +730,8 @@ reco::GsfElectronCollection GsfElectronAlgo::completeElectrons(edm::Event const&
hoc,
ctfTrackTable.value(),
gsfTrackTable.value(),
thresholds);
thresholds,
hcalCuts);

} // loop over tracks
return electrons;
Expand Down Expand Up @@ -859,7 +865,8 @@ void GsfElectronAlgo::createElectron(reco::GsfElectronCollection& electrons,
const GsfElectronAlgo::HeavyObjectCache* hoc,
egamma::conv::TrackTableView ctfTable,
egamma::conv::TrackTableView gsfTable,
EcalPFRecHitThresholds const& thresholds) {
EcalPFRecHitThresholds const& thresholds,
const HcalPFCuts* hcalCuts) {
// charge ID
int eleCharge;
GsfElectron::ChargeInfo eleChargeInfo;
Expand Down Expand Up @@ -988,10 +995,22 @@ void GsfElectronAlgo::createElectron(reco::GsfElectronCollection& electrons,
reco::GsfElectron::ShowerShape showerShape;
reco::GsfElectron::ShowerShape full5x5_showerShape;
if (!EcalTools::isHGCalDet((DetId::Detector)region)) {
showerShape = calculateShowerShape<false>(
electronData.superClusterRef, hcalHelperCone_, hcalHelperBc_, eventData, topology, geometry, thresholds);
full5x5_showerShape = calculateShowerShape<true>(
electronData.superClusterRef, hcalHelperCone_, hcalHelperBc_, eventData, topology, geometry, thresholds);
showerShape = calculateShowerShape<false>(electronData.superClusterRef,
hcalHelperCone_,
hcalHelperBc_,
eventData,
topology,
geometry,
thresholds,
hcalCuts);
full5x5_showerShape = calculateShowerShape<true>(electronData.superClusterRef,
hcalHelperCone_,
hcalHelperBc_,
eventData,
topology,
geometry,
thresholds,
hcalCuts);
}

//====================================================
Expand Down Expand Up @@ -1155,11 +1174,11 @@ void GsfElectronAlgo::createElectron(reco::GsfElectronCollection& electrons,

if (!EcalTools::isHGCalDet((DetId::Detector)region)) {
for (uint id = 0; id < dr03.hcalRecHitSumEt.size(); ++id) {
dr03.hcalRecHitSumEt[id] = eventData.hadIsolation03.getHcalEtSum(&ele, id + 1);
dr03.hcalRecHitSumEtBc[id] = eventData.hadIsolation03Bc.getHcalEtSumBc(&ele, id + 1);
dr03.hcalRecHitSumEt[id] = eventData.hadIsolation03.getHcalEtSum(&ele, id + 1, hcalCuts);
dr03.hcalRecHitSumEtBc[id] = eventData.hadIsolation03Bc.getHcalEtSumBc(&ele, id + 1, hcalCuts);

dr04.hcalRecHitSumEt[id] = eventData.hadIsolation04.getHcalEtSum(&ele, id + 1);
dr04.hcalRecHitSumEtBc[id] = eventData.hadIsolation04Bc.getHcalEtSumBc(&ele, id + 1);
dr04.hcalRecHitSumEt[id] = eventData.hadIsolation04.getHcalEtSum(&ele, id + 1, hcalCuts);
dr04.hcalRecHitSumEtBc[id] = eventData.hadIsolation04Bc.getHcalEtSumBc(&ele, id + 1, hcalCuts);
}

dr03.ecalRecHitSumEt = eventData.ecalBarrelIsol03.getEtSum(&ele);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@
#include "FWCore/Framework/interface/Event.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/ClusterTools.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalTools.h"
#include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
#include "CondTools/Hcal/interface/HcalPFCutsHandler.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

class ElectronSeedProducer : public edm::stream::EDProducer<> {
public:
explicit ElectronSeedProducer(const edm::ParameterSet&);

void beginRun(const edm::Run&, const edm::EventSetup&) override;
void produce(edm::Event&, const edm::EventSetup&) final;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
Expand All @@ -56,6 +60,10 @@ class ElectronSeedProducer : public edm::stream::EDProducer<> {

bool allowHGCal_;
std::unique_ptr<hgcal::ClusterTools> hgcClusterTools_;

edm::ESGetToken<HcalPFCuts, HcalPFCutsRcd> hcalCutsToken_;
bool cutsFromDB;
HcalPFCuts const* hcalCuts = nullptr;
};

using namespace reco;
Expand Down Expand Up @@ -102,6 +110,12 @@ ElectronSeedProducer::ElectronSeedProducer(const edm::ParameterSet& conf)
maxHOverEEndcaps_ = conf.getParameter<double>("maxHOverEEndcaps");
}

//Retrieve HCAL PF thresholds - from config or from DB
cutsFromDB = conf.getParameter<bool>("usePFThresholdsFromDB");
if (cutsFromDB) {
hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd, edm::Transition::BeginRun>(edm::ESInputTag("", "withTopo"));
}

ElectronSeedGenerator::Tokens esg_tokens;
esg_tokens.token_bs = beamSpotTag_;
esg_tokens.token_vtx = mayConsume<reco::VertexCollection>(conf.getParameter<edm::InputTag>("vertices"));
Expand All @@ -115,6 +129,12 @@ ElectronSeedProducer::ElectronSeedProducer(const edm::ParameterSet& conf)
produces<ElectronSeedCollection>();
}

void ElectronSeedProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
if (cutsFromDB) {
hcalCuts = &iSetup.getData(hcalCutsToken_);
}
}

void ElectronSeedProducer::produce(edm::Event& e, const edm::EventSetup& iSetup) {
LogDebug("ElectronSeedProducer") << "[ElectronSeedProducer::produce] entering ";

Expand Down Expand Up @@ -174,7 +194,7 @@ SuperClusterRefVector ElectronSeedProducer::filterClusters(
if (scl.energy() / cosh(sclEta) > SCEtCut_) {
if (applyHOverECut_) {
bool hoeVeto = false;
double had = hcalHelper_->hcalESum(scl, 0);
double had = hcalHelper_->hcalESum(scl, 0, hcalCuts);
double scle = scl.energy();
int det_group = scl.seed()->hitsAndFractions()[0].first.det();
int detector = scl.seed()->hitsAndFractions()[0].first.subdetId();
Expand Down Expand Up @@ -222,6 +242,7 @@ void ElectronSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& desc
desc.add<std::vector<double>>("recHitEThresholdHB", {0., 0., 0., 0.});
desc.add<std::vector<double>>("recHitEThresholdHE", {0., 0., 0., 0., 0., 0., 0.});
desc.add<int>("maxHcalRecHitSeverity", 999999);
desc.add<bool>("usePFThresholdsFromDB", false);

// H/E equivalent for HGCal
desc.add<bool>("allowHGCal", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class GsfElectronProducer : public edm::stream::EDProducer<edm::GlobalCache<GsfE
static void globalEndJob(GsfElectronAlgo::HeavyObjectCache const*){};

// ------------ method called to produce the data ------------
void beginRun(const edm::Run&, const edm::EventSetup&) override;
void produce(edm::Event& event, const edm::EventSetup& setup) override;

private:
Expand Down Expand Up @@ -166,6 +167,10 @@ class GsfElectronProducer : public edm::stream::EDProducer<edm::GlobalCache<GsfE
float extetaboundary_;

std::vector<tensorflow::Session*> tfSessions_;

edm::ESGetToken<HcalPFCuts, HcalPFCutsRcd> hcalCutsToken_;
bool cutsFromDB;
HcalPFCuts const* hcalCuts = nullptr;
};

void GsfElectronProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down Expand Up @@ -210,6 +215,7 @@ void GsfElectronProducer::fillDescriptions(edm::ConfigurationDescriptions& descr
desc.add<std::vector<double>>("recHitEThresholdHE", {0., 0., 0., 0., 0., 0., 0.});
desc.add<int>("maxHcalRecHitSeverity", 999999);
desc.add<bool>("hcalRun2EffDepth", false);
desc.add<bool>("usePFThresholdsFromDB", false);

// Isolation algos configuration
desc.add("trkIsol03Cfg", EleTkIsolFromCands::pSetDescript());
Expand Down Expand Up @@ -400,6 +406,12 @@ namespace {
}
}; // namespace

void GsfElectronProducer::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
if (cutsFromDB) {
hcalCuts = &setup.getData(hcalCutsToken_);
}
}

GsfElectronProducer::GsfElectronProducer(const edm::ParameterSet& cfg, const GsfElectronAlgo::HeavyObjectCache* gcache)
: cutsCfg_{makeCutsConfiguration(cfg.getParameter<edm::ParameterSet>("preselection"))},
ecalSeedingParametersChecked_(false),
Expand All @@ -411,6 +423,12 @@ GsfElectronProducer::GsfElectronProducer(const edm::ParameterSet& cfg, const Gsf
egmPFCandidateCollection_ = consumes(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag"));
}

//Retrieve HCAL PF thresholds - from config or from DB
cutsFromDB = cfg.getParameter<bool>("usePFThresholdsFromDB");
if (cutsFromDB) {
hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd, edm::Transition::BeginRun>(edm::ESInputTag("", "withTopo"));
}

inputCfg_.gsfElectronCores = consumes(cfg.getParameter<edm::InputTag>("gsfElectronCoresTag"));
inputCfg_.hbheRecHitsTag = consumes(cfg.getParameter<edm::InputTag>("hbheRecHits"));
inputCfg_.barrelRecHitCollection = consumes(cfg.getParameter<edm::InputTag>("barrelRecHitCollectionTag"));
Expand Down Expand Up @@ -740,7 +758,7 @@ void GsfElectronProducer::produce(edm::Event& event, const edm::EventSetup& setu
}
}

auto electrons = algo_->completeElectrons(event, setup, globalCache());
auto electrons = algo_->completeElectrons(event, setup, globalCache(), hcalCuts);
if (resetMvaValuesUsingPFCandidates_) {
const auto gsfMVAInputMap = matchWithPFCandidates(event.get(egmPFCandidateCollection_));
for (auto& el : electrons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
hbheRecHits = egammaHBHERecHit.hbheRecHits,
recHitEThresholdHB = egammaHBHERecHit.recHitEThresholdHB,
recHitEThresholdHE = egammaHBHERecHit.recHitEThresholdHE,
usePFThresholdsFromDB = egammaHBHERecHit.usePFThresholdsFromDB,
maxHcalRecHitSeverity = egammaHBHERecHit.maxHcalRecHitSeverity
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
hbheRecHits = egammaHBHERecHit.hbheRecHits,
recHitEThresholdHB = egammaHBHERecHit.recHitEThresholdHB,
recHitEThresholdHE = egammaHBHERecHit.recHitEThresholdHE,
usePFThresholdsFromDB = egammaHBHERecHit.usePFThresholdsFromDB,
maxHcalRecHitSeverity = egammaHBHERecHit.maxHcalRecHitSeverity,

pfECALClusIsolCfg = cms.PSet(
Expand Down
Loading