Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:34

0001 // user include files
0002 #include <unordered_map>
0003 
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 
0014 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0015 
0016 class HGCalRecHitMapProducer : public edm::global::EDProducer<> {
0017 public:
0018   HGCalRecHitMapProducer(const edm::ParameterSet&);
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0022 
0023 private:
0024   const edm::EDGetTokenT<HGCRecHitCollection> hits_ee_token_;
0025   const edm::EDGetTokenT<HGCRecHitCollection> hits_fh_token_;
0026   const edm::EDGetTokenT<HGCRecHitCollection> hits_bh_token_;
0027 };
0028 
0029 DEFINE_FWK_MODULE(HGCalRecHitMapProducer);
0030 
0031 using DetIdRecHitMap = std::unordered_map<DetId, const HGCRecHit*>;
0032 
0033 HGCalRecHitMapProducer::HGCalRecHitMapProducer(const edm::ParameterSet& ps)
0034     : hits_ee_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("EEInput"))),
0035       hits_fh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("FHInput"))),
0036       hits_bh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("BHInput"))) {
0037   produces<DetIdRecHitMap>();
0038 }
0039 
0040 void HGCalRecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0041   edm::ParameterSetDescription desc;
0042   desc.add<edm::InputTag>("EEInput", {"HGCalRecHit", "HGCEERecHits"});
0043   desc.add<edm::InputTag>("FHInput", {"HGCalRecHit", "HGCHEFRecHits"});
0044   desc.add<edm::InputTag>("BHInput", {"HGCalRecHit", "HGCHEBRecHits"});
0045   descriptions.add("hgcalRecHitMapProducer", desc);
0046 }
0047 
0048 void HGCalRecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0049   auto hitMap = std::make_unique<DetIdRecHitMap>();
0050   const auto& ee_hits = evt.get(hits_ee_token_);
0051   const auto& fh_hits = evt.get(hits_fh_token_);
0052   const auto& bh_hits = evt.get(hits_bh_token_);
0053 
0054   for (const auto& hit : ee_hits) {
0055     hitMap->emplace(hit.detid(), &hit);
0056   }
0057 
0058   for (const auto& hit : fh_hits) {
0059     hitMap->emplace(hit.detid(), &hit);
0060   }
0061 
0062   for (const auto& hit : bh_hits) {
0063     hitMap->emplace(hit.detid(), &hit);
0064   }
0065   evt.put(std::move(hitMap));
0066 }