Skip to content

Commit 0db87c6

Browse files
committed
Revert "use a PSet to wrap the list of hits to use in RecHitMapProducer"
This reverts commit 0c8751e.
1 parent f2d1970 commit 0db87c6

File tree

3 files changed

+56
-68
lines changed

3 files changed

+56
-68
lines changed
Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// user include files
12
#include <unordered_map>
23

34
#include "FWCore/Framework/interface/Frameworkfwd.h"
@@ -9,7 +10,6 @@
910
#include "FWCore/Framework/interface/MakerMacros.h"
1011
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
1112
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
12-
#include "FWCore/ParameterSet/interface/ParameterSet.h"
1313

1414
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
1515
#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
@@ -19,88 +19,81 @@ class RecHitMapProducer : public edm::global::EDProducer<> {
1919
public:
2020
RecHitMapProducer(const edm::ParameterSet&);
2121
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22+
2223
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
2324

2425
private:
25-
using DetIdRecHitMap = std::unordered_map<DetId, const unsigned int>;
26-
27-
std::unordered_map<std::string, edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_tokens_;
28-
std::unordered_map<std::string, edm::EDGetTokenT<reco::PFRecHitCollection>> barrel_hits_tokens_;
26+
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
27+
std::vector<edm::EDGetTokenT<reco::PFRecHitCollection>> barrel_hits_token_;
2928

3029
bool hgcalOnly_;
3130
};
3231

3332
DEFINE_FWK_MODULE(RecHitMapProducer);
3433

34+
using DetIdRecHitMap = std::unordered_map<DetId, const unsigned int>;
35+
3536
RecHitMapProducer::RecHitMapProducer(const edm::ParameterSet& ps) : hgcalOnly_(ps.getParameter<bool>("hgcalOnly")) {
36-
const edm::ParameterSet& hitPSet = ps.getParameter<edm::ParameterSet>("hits");
37-
for (const auto& entry : hitPSet.getParameterNamesForType<edm::InputTag>()) {
38-
edm::InputTag tag = hitPSet.getParameter<edm::InputTag>(entry);
37+
std::vector<edm::InputTag> tags = ps.getParameter<std::vector<edm::InputTag>>("hits");
38+
for (auto& tag : tags) {
3939
if (tag.label().find("HGCalRecHit") != std::string::npos) {
40-
hgcal_hits_tokens_.emplace(entry, consumes<HGCRecHitCollection>(tag));
40+
hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(tag));
4141
} else {
42-
barrel_hits_tokens_.emplace(entry, consumes<reco::PFRecHitCollection>(tag));
42+
barrel_hits_token_.push_back(consumes<reco::PFRecHitCollection>(tag));
4343
}
4444
}
4545

4646
produces<DetIdRecHitMap>("hgcalRecHitMap");
47-
if (!hgcalOnly_) {
47+
if (!hgcalOnly_)
4848
produces<DetIdRecHitMap>("barrelRecHitMap");
49-
}
5049
}
5150

5251
void RecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
53-
edm::ParameterSetDescription hitDesc;
54-
hitDesc.add<edm::InputTag>("HGCEE", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
55-
hitDesc.add<edm::InputTag>("HGCHEF", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
56-
hitDesc.add<edm::InputTag>("HGCHEB", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
57-
// Optionally allow barrel collections to be defined
58-
hitDesc.addOptional<edm::InputTag>("ECAL", edm::InputTag("particleFlowRecHitECAL"));
59-
hitDesc.addOptional<edm::InputTag>("HCAL", edm::InputTag("particleFlowRecHitHBHE"));
60-
6152
edm::ParameterSetDescription desc;
62-
desc.add<edm::ParameterSetDescription>("hits", hitDesc);
53+
desc.add<std::vector<edm::InputTag>>("hits",
54+
{edm::InputTag("HGCalRecHit", "HGCEERecHits"),
55+
edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
56+
edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
6357
desc.add<bool>("hgcalOnly", true);
6458
descriptions.add("recHitMapProducer", desc);
6559
}
6660

67-
void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const {
61+
void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
6862
auto hitMapHGCal = std::make_unique<DetIdRecHitMap>();
69-
MultiVectorManager<HGCRecHit> rechitManager;
7063

71-
for (const auto& [name, token] : hgcal_hits_tokens_) {
72-
const auto& handle = evt.getHandle(token);
73-
if (handle.isValid()) {
74-
rechitManager.addVector(*handle);
75-
} else {
76-
edm::LogWarning("RecHitMapProducer") << "HGCal collection \"" << name << "\" is invalid.";
77-
}
64+
// Retrieve collections
65+
const auto& ee_hits = evt.getHandle(hgcal_hits_token_[0]);
66+
const auto& fh_hits = evt.getHandle(hgcal_hits_token_[1]);
67+
const auto& bh_hits = evt.getHandle(hgcal_hits_token_[2]);
68+
69+
// Check validity of all handles
70+
if (!ee_hits.isValid() || !fh_hits.isValid() || !bh_hits.isValid()) {
71+
edm::LogWarning("HGCalRecHitMapProducer") << "One or more hit collections are unavailable. Returning an empty map.";
72+
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
73+
return;
7874
}
7975

76+
MultiVectorManager<HGCRecHit> rechitManager;
77+
rechitManager.addVector(*ee_hits);
78+
rechitManager.addVector(*fh_hits);
79+
rechitManager.addVector(*bh_hits);
80+
8081
for (unsigned int i = 0; i < rechitManager.size(); ++i) {
81-
hitMapHGCal->emplace(rechitManager[i].detid(), i);
82+
const auto recHitDetId = rechitManager[i].detid();
83+
hitMapHGCal->emplace(recHitDetId, i);
8284
}
8385

8486
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
8587

86-
if (hgcalOnly_)
87-
return;
88-
89-
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
90-
MultiVectorManager<reco::PFRecHit> barrelManager;
91-
92-
for (const auto& [name, token] : barrel_hits_tokens_) {
93-
const auto& handle = evt.getHandle(token);
94-
if (handle.isValid()) {
95-
barrelManager.addVector(*handle);
96-
} else {
97-
edm::LogWarning("RecHitMapProducer") << "Barrel collection \"" << name << "\" is invalid.";
88+
if (!hgcalOnly_) {
89+
auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
90+
MultiVectorManager<reco::PFRecHit> barrelRechitManager;
91+
barrelRechitManager.addVector(evt.get(barrel_hits_token_[0]));
92+
barrelRechitManager.addVector(evt.get(barrel_hits_token_[1]));
93+
for (unsigned int i = 0; i < barrelRechitManager.size(); ++i) {
94+
const auto recHitDetId = barrelRechitManager[i].detId();
95+
hitMapBarrel->emplace(recHitDetId, i);
9896
}
97+
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
9998
}
100-
101-
for (unsigned int i = 0; i < barrelManager.size(); ++i) {
102-
hitMapBarrel->emplace(barrelManager[i].detId(), i);
103-
}
104-
105-
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
10699
}
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import FWCore.ParameterSet.Config as cms
22

3-
from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cfi import recHitMapProducer as _recHitMapProducer
3+
from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cfi import recHitMapProducer as recHitMapProducer_
44

5-
recHitMapProducer = _recHitMapProducer.clone(
6-
hits = dict(HGCEE = ("HGCalRecHit", "HGCEERecHits"),
7-
HGCHEF = ("HGCalRecHit", "HGCHEFRecHits"),
8-
HGCHEB = ("HGCalRecHit", "HGCHEBRecHits"))
9-
)
5+
recHitMapProducer = recHitMapProducer_.clone()
6+
7+
hits = ["HGCalRecHit:HGCEERecHits",
8+
"HGCalRecHit:HGCHEFRecHits",
9+
"HGCalRecHit:HGCHEBRecHits",
10+
"particleFlowRecHitECAL",
11+
"particleFlowRecHitHBHE"]
1012

1113
from Configuration.ProcessModifiers.ticl_barrel_cff import ticl_barrel
12-
ticl_barrel.toModify(recHitMapProducer,
13-
hits = dict(HGCEE = ("HGCalRecHit", "HGCEERecHits"),
14-
HGCHEF = ("HGCalRecHit", "HGCHEFRecHits"),
15-
HGCHEB = ("HGCalRecHit", "HGCHEBRecHits"),
16-
ECAL = "particleFlowRecHitECAL",
17-
HBHE = "particleFlowRecHitHBHE"),
18-
hgcalOnly = False
19-
)
14+
ticl_barrel.toModify(recHitMapProducer, hits = hits, hgcalOnly = cms.bool(False))

Validation/Configuration/python/hltHGCalSimValid_cff.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
from Validation.HGCalValidation.HLT_TICLIterLabels_cff import hltTiclIterLabels as _hltTiclIterLabels
1313

14-
from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cfi import recHitMapProducer as _recHitMapProducer
14+
from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cff import recHitMapProducer as _recHitMapProducer
15+
16+
hits = ["hltHGCalRecHit:HGCEERecHits", "hltHGCalRecHit:HGCHEFRecHits", "hltHGCalRecHit:HGCHEBRecHits"]
1517
hltRecHitMapProducer = _recHitMapProducer.clone(
16-
hits = dict(HGCEE = ("hltHGCalRecHit", "HGCEERecHits"),
17-
HGCHEF = ("hltHGCalRecHit", "HGCHEFRecHits"),
18-
HGCHEB = ("hltHGCalRecHit", "HGCHEBRecHits")),
19-
hgcalOnly = True,
18+
hits = hits,
19+
hgcalOnly = cms.bool(True),
2020
)
2121

2222
hltLcAssocByEnergyScoreProducer = _lcAssocByEnergyScoreProducer.clone(

0 commit comments

Comments
 (0)