Skip to content

Commit 5b5a4da

Browse files
committed
modernize ElectronHcalHelper
1 parent d57cec7 commit 5b5a4da

File tree

4 files changed

+28
-63
lines changed

4 files changed

+28
-63
lines changed

RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include "FWCore/Framework/interface/ESHandle.h"
99
#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
1010
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
11+
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
12+
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
1113

12-
class EgammaHcalIsolation;
13-
class EgammaTowerIsolation;
1414
class EgammaHadTower;
1515
class HcalTopology;
1616
class HcalChannelQuality;
@@ -35,10 +35,9 @@ class ElectronHcalHelper {
3535
double hOverEHFMinE;
3636
};
3737

38-
ElectronHcalHelper(const Configuration &);
39-
void checkSetup(const edm::EventSetup &);
40-
void readEvent(const edm::Event &);
41-
~ElectronHcalHelper();
38+
ElectronHcalHelper(const Configuration &cfg) : cfg_(cfg) {}
39+
40+
void beginEvent(const edm::Event &, const edm::EventSetup &);
4241

4342
double hcalESum(const reco::SuperCluster &, const std::vector<CaloTowerDetId> *excludeTowers = nullptr) const;
4443
double hcalESumDepth1(const reco::SuperCluster &, const std::vector<CaloTowerDetId> *excludeTowers = nullptr) const;
@@ -58,15 +57,15 @@ class ElectronHcalHelper {
5857
const Configuration cfg_;
5958

6059
// event setup data (rechits strategy)
61-
unsigned long long caloGeomCacheId_;
60+
unsigned long long caloGeomCacheId_ = 0;
6261
edm::ESHandle<CaloGeometry> caloGeom_;
6362

6463
// event data (rechits strategy)
65-
EgammaHcalIsolation *hcalIso_;
64+
std::unique_ptr<EgammaHcalIsolation> hcalIso_ = nullptr;
6665

6766
// event data (towers strategy)
68-
EgammaTowerIsolation *towerIso1_;
69-
EgammaTowerIsolation *towerIso2_;
67+
std::unique_ptr<EgammaTowerIsolation> towerIso1_ = nullptr;
68+
std::unique_ptr<EgammaTowerIsolation> towerIso2_ = nullptr;
7069
CaloTowerCollection const *towersFromCollection_ = nullptr;
7170
CaloTowerConstituentsMap const *towerMap_ = nullptr;
7271
HcalChannelQuality const *hcalQuality_ = nullptr;

RecoEgamma/EgammaElectronAlgos/src/ElectronHcalHelper.cc

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronHcalHelper.h"
2-
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHcalIsolation.h"
3-
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
42
#include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaHadTower.h"
53
#include "Geometry/Records/interface/CaloGeometryRecord.h"
64
#include "FWCore/MessageLogger/interface/MessageLogger.h"
@@ -9,15 +7,18 @@
97

108
using namespace reco;
119

12-
ElectronHcalHelper::ElectronHcalHelper(const Configuration& cfg)
13-
: cfg_(cfg), caloGeomCacheId_(0), hcalIso_(nullptr), towerIso1_(nullptr), towerIso2_(nullptr) {}
14-
15-
void ElectronHcalHelper::checkSetup(const edm::EventSetup& es) {
10+
void ElectronHcalHelper::beginEvent(const edm::Event& evt, const edm::EventSetup& es) {
1611
if (cfg_.hOverEConeSize == 0) {
1712
return;
1813
}
1914

2015
if (cfg_.useTowers) {
16+
towersFromCollection_ = &evt.get(cfg_.hcalTowers);
17+
towerIso1_ =
18+
std::make_unique<EgammaTowerIsolation>(cfg_.hOverEConeSize, 0., cfg_.hOverEPtMin, 1, towersFromCollection_);
19+
towerIso2_ =
20+
std::make_unique<EgammaTowerIsolation>(cfg_.hOverEConeSize, 0., cfg_.hOverEPtMin, 2, towersFromCollection_);
21+
2122
edm::ESHandle<CaloTowerConstituentsMap> ctmaph;
2223
es.get<CaloGeometryRecord>().get(ctmaph);
2324
towerMap_ = ctmaph.product();
@@ -28,41 +29,20 @@ void ElectronHcalHelper::checkSetup(const edm::EventSetup& es) {
2829
edm::ESHandle<HcalTopology> hcalTopology;
2930
es.get<HcalRecNumberingRecord>().get(hcalTopology);
3031
hcalTopology_ = hcalTopology.product();
31-
3232
} else {
33-
unsigned long long newCaloGeomCacheId_ = es.get<CaloGeometryRecord>().cacheIdentifier();
34-
if (caloGeomCacheId_ != newCaloGeomCacheId_) {
35-
caloGeomCacheId_ = newCaloGeomCacheId_;
36-
es.get<CaloGeometryRecord>().get(caloGeom_);
37-
}
38-
}
39-
}
40-
41-
void ElectronHcalHelper::readEvent(const edm::Event& evt) {
42-
if (cfg_.hOverEConeSize == 0) {
43-
return;
44-
}
45-
46-
if (cfg_.useTowers) {
47-
delete towerIso1_;
48-
towerIso1_ = nullptr;
49-
delete towerIso2_;
50-
towerIso2_ = nullptr;
51-
52-
towersFromCollection_ = &evt.get(cfg_.hcalTowers);
53-
towerIso1_ = new EgammaTowerIsolation(cfg_.hOverEConeSize, 0., cfg_.hOverEPtMin, 1, towersFromCollection_);
54-
towerIso2_ = new EgammaTowerIsolation(cfg_.hOverEConeSize, 0., cfg_.hOverEPtMin, 2, towersFromCollection_);
55-
} else {
56-
delete hcalIso_;
57-
hcalIso_ = nullptr;
58-
5933
edm::Handle<HBHERecHitCollection> hbhe_;
6034
if (!evt.getByToken(cfg_.hcalRecHits, hbhe_)) {
6135
edm::LogError("ElectronHcalHelper::readEvent") << "failed to get the rechits";
6236
}
6337

64-
hcalIso_ = new EgammaHcalIsolation(
38+
hcalIso_ = std::make_unique<EgammaHcalIsolation>(
6539
cfg_.hOverEConeSize, 0., cfg_.hOverEHBMinE, cfg_.hOverEHFMinE, 0., 0., caloGeom_, *hbhe_);
40+
41+
unsigned long long newCaloGeomCacheId_ = es.get<CaloGeometryRecord>().cacheIdentifier();
42+
if (caloGeomCacheId_ != newCaloGeomCacheId_) {
43+
caloGeomCacheId_ = newCaloGeomCacheId_;
44+
es.get<CaloGeometryRecord>().get(caloGeom_);
45+
}
6646
}
6747
}
6848

@@ -121,15 +101,3 @@ bool ElectronHcalHelper::hasActiveHcal(const reco::SuperCluster& sc) const {
121101
return true;
122102
}
123103
}
124-
125-
ElectronHcalHelper::~ElectronHcalHelper() {
126-
if (cfg_.hOverEConeSize == 0) {
127-
return;
128-
}
129-
if (cfg_.useTowers) {
130-
delete towerIso1_;
131-
delete towerIso2_;
132-
} else {
133-
delete hcalIso_;
134-
}
135-
}

RecoEgamma/EgammaElectronAlgos/src/GsfElectronAlgo.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ GsfElectronAlgo::GsfElectronAlgo(const Tokens& input,
397397
{}
398398

399399
void GsfElectronAlgo::checkSetup(const edm::EventSetup& es) {
400-
hcalHelper_.checkSetup(es);
401400
if (cfg_.strategy.useEcalRegression || cfg_.strategy.useCombinationRegression)
402401
regHelper_.checkSetup(es);
403402

@@ -412,9 +411,6 @@ void GsfElectronAlgo::checkSetup(const edm::EventSetup& es) {
412411
GsfElectronAlgo::EventData GsfElectronAlgo::beginEvent(edm::Event const& event,
413412
CaloGeometry const& caloGeometry,
414413
EcalSeverityLevelAlgo const& ecalSeveretyLevelAlgo) {
415-
// prepare access to hcal data
416-
hcalHelper_.readEvent(event);
417-
418414
auto const& towers = event.get(cfg_.tokens.hcalTowersTag);
419415

420416
// Isolation algos
@@ -538,6 +534,9 @@ reco::GsfElectronCollection GsfElectronAlgo::completeElectrons(edm::Event const&
538534
auto const& trackerGeometry = eventSetup.getData(trackerGeometryToken_);
539535
auto const& ecalSeveretyLevelAlgo = eventSetup.getData(ecalSeveretyLevelAlgoToken_);
540536

537+
// prepare access to hcal data
538+
hcalHelper_.beginEvent(event, eventSetup);
539+
541540
checkSetup(eventSetup);
542541
auto eventData = beginEvent(event, caloGeometry, ecalSeveretyLevelAlgo);
543542
double magneticFieldInTesla = magneticField.inTesla(GlobalPoint(0., 0., 0.)).z();

RecoEgamma/EgammaElectronProducers/plugins/ElectronSeedProducer.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ElectronSeedProducer::ElectronSeedProducer(const edm::ParameterSet& conf)
7777
// for H/E
7878
applyHOverECut_ = conf.getParameter<bool>("applyHOverECut");
7979
if (applyHOverECut_) {
80-
ElectronHcalHelper::Configuration hcalCfg;
80+
ElectronHcalHelper::Configuration hcalCfg{};
8181
hcalCfg.hOverEConeSize = conf.getParameter<double>("hOverEConeSize");
8282
if (hcalCfg.hOverEConeSize > 0) {
8383
hcalCfg.useTowers = true;
@@ -116,8 +116,7 @@ void ElectronSeedProducer::produce(edm::Event& e, const edm::EventSetup& iSetup)
116116
std::unique_ptr<TrajectorySeedCollection> initialSeedCollectionPtr = nullptr; //created on the fly
117117

118118
if (hcalHelper_) {
119-
hcalHelper_->checkSetup(iSetup);
120-
hcalHelper_->readEvent(e);
119+
hcalHelper_->beginEvent(e, iSetup);
121120
if (allowHGCal_) {
122121
hgcClusterTools_->getEventSetup(iSetup);
123122
hgcClusterTools_->getEvent(e);

0 commit comments

Comments
 (0)