Skip to content

Commit f2d1970

Browse files
mmusichbrusale
authored andcommitted
use a PSet to wrap the list of hits to use in RecHitMapProducer
1 parent 1e39341 commit f2d1970

File tree

3 files changed

+68
-56
lines changed

3 files changed

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

43
#include "FWCore/Framework/interface/Frameworkfwd.h"
@@ -10,6 +9,7 @@
109
#include "FWCore/Framework/interface/MakerMacros.h"
1110
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
1211
#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,81 +19,88 @@ class RecHitMapProducer : public edm::global::EDProducer<> {
1919
public:
2020
RecHitMapProducer(const edm::ParameterSet&);
2121
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22-
2322
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
2423

2524
private:
26-
std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hgcal_hits_token_;
27-
std::vector<edm::EDGetTokenT<reco::PFRecHitCollection>> barrel_hits_token_;
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_;
2829

2930
bool hgcalOnly_;
3031
};
3132

3233
DEFINE_FWK_MODULE(RecHitMapProducer);
3334

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

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

5152
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+
5261
edm::ParameterSetDescription desc;
53-
desc.add<std::vector<edm::InputTag>>("hits",
54-
{edm::InputTag("HGCalRecHit", "HGCEERecHits"),
55-
edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
56-
edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
62+
desc.add<edm::ParameterSetDescription>("hits", hitDesc);
5763
desc.add<bool>("hgcalOnly", true);
5864
descriptions.add("recHitMapProducer", desc);
5965
}
6066

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

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;
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+
}
7478
}
7579

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

8684
evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
8785

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);
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.";
9698
}
97-
evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
9899
}
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");
99106
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
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-
7-
hits = ["HGCalRecHit:HGCEERecHits",
8-
"HGCalRecHit:HGCHEFRecHits",
9-
"HGCalRecHit:HGCHEBRecHits",
10-
"particleFlowRecHitECAL",
11-
"particleFlowRecHitHBHE"]
5+
recHitMapProducer = _recHitMapProducer.clone(
6+
hits = dict(HGCEE = ("HGCalRecHit", "HGCEERecHits"),
7+
HGCHEF = ("HGCalRecHit", "HGCHEFRecHits"),
8+
HGCHEB = ("HGCalRecHit", "HGCHEBRecHits"))
9+
)
1210

1311
from Configuration.ProcessModifiers.ticl_barrel_cff import ticl_barrel
14-
ticl_barrel.toModify(recHitMapProducer, hits = hits, hgcalOnly = cms.bool(False))
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+
)

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_cff import recHitMapProducer as _recHitMapProducer
15-
16-
hits = ["hltHGCalRecHit:HGCEERecHits", "hltHGCalRecHit:HGCHEFRecHits", "hltHGCalRecHit:HGCHEBRecHits"]
14+
from RecoLocalCalo.HGCalRecProducers.recHitMapProducer_cfi import recHitMapProducer as _recHitMapProducer
1715
hltRecHitMapProducer = _recHitMapProducer.clone(
18-
hits = hits,
19-
hgcalOnly = cms.bool(True),
16+
hits = dict(HGCEE = ("hltHGCalRecHit", "HGCEERecHits"),
17+
HGCHEF = ("hltHGCalRecHit", "HGCHEFRecHits"),
18+
HGCHEB = ("hltHGCalRecHit", "HGCHEBRecHits")),
19+
hgcalOnly = True,
2020
)
2121

2222
hltLcAssocByEnergyScoreProducer = _lcAssocByEnergyScoreProducer.clone(

0 commit comments

Comments
 (0)