1+ // user include files
12#include < unordered_map>
23
34#include " FWCore/Framework/interface/Frameworkfwd.h"
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<> {
1919public:
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
2425private:
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
3332DEFINE_FWK_MODULE (RecHitMapProducer);
3433
34+ using DetIdRecHitMap = std::unordered_map<DetId, const unsigned int >;
35+
3536RecHitMapProducer::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
5251void 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}
0 commit comments