Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 23:13:04

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 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0016 
0017 class RecHitMapProducer : public edm::global::EDProducer<> {
0018 public:
0019   RecHitMapProducer(const edm::ParameterSet&);
0020   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0021 
0022   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0023 
0024 private:
0025   const edm::EDGetTokenT<HGCRecHitCollection> hits_ee_token_;
0026   const edm::EDGetTokenT<HGCRecHitCollection> hits_fh_token_;
0027   const edm::EDGetTokenT<HGCRecHitCollection> hits_bh_token_;
0028   const edm::EDGetTokenT<reco::PFRecHitCollection> hits_eb_token_;
0029   const edm::EDGetTokenT<reco::PFRecHitCollection> hits_hb_token_;
0030   const edm::EDGetTokenT<reco::PFRecHitCollection> hits_ho_token_;
0031   bool hgcalOnly_;
0032 };
0033 
0034 DEFINE_FWK_MODULE(RecHitMapProducer);
0035 
0036 using DetIdRecHitMap = std::unordered_map<DetId, const unsigned int>;
0037 
0038 RecHitMapProducer::RecHitMapProducer(const edm::ParameterSet& ps)
0039     : hits_ee_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("EEInput"))),
0040       hits_fh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("FHInput"))),
0041       hits_bh_token_(consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("BHInput"))),
0042       hits_eb_token_(consumes<reco::PFRecHitCollection>(ps.getParameter<edm::InputTag>("EBInput"))),
0043       hits_hb_token_(consumes<reco::PFRecHitCollection>(ps.getParameter<edm::InputTag>("HBInput"))),
0044       hits_ho_token_(consumes<reco::PFRecHitCollection>(ps.getParameter<edm::InputTag>("HOInput"))),
0045       hgcalOnly_(ps.getParameter<bool>("hgcalOnly")) {
0046   produces<DetIdRecHitMap>("hgcalRecHitMap");
0047   if (!hgcalOnly_)
0048     produces<DetIdRecHitMap>("barrelRecHitMap");
0049 }
0050 
0051 void RecHitMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0052   edm::ParameterSetDescription desc;
0053   desc.add<edm::InputTag>("EEInput", {"HGCalRecHit", "HGCEERecHits"});
0054   desc.add<edm::InputTag>("FHInput", {"HGCalRecHit", "HGCHEFRecHits"});
0055   desc.add<edm::InputTag>("BHInput", {"HGCalRecHit", "HGCHEBRecHits"});
0056   desc.add<edm::InputTag>("EBInput", {"particleFlowRecHitECAL", ""});
0057   desc.add<edm::InputTag>("HBInput", {"particleFlowRecHitHBHE", ""});
0058   desc.add<edm::InputTag>("HOInput", {"particleFlowRecHitHO", ""});
0059   desc.add<bool>("hgcalOnly", true);
0060   descriptions.add("recHitMapProducer", desc);
0061 }
0062 
0063 void RecHitMapProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0064   auto hitMapHGCal = std::make_unique<DetIdRecHitMap>();
0065   const auto& ee_hits = evt.get(hits_ee_token_);
0066   const auto& fh_hits = evt.get(hits_fh_token_);
0067   const auto& bh_hits = evt.get(hits_bh_token_);
0068 
0069   for (unsigned int i = 0; i < ee_hits.size(); ++i) {
0070     hitMapHGCal->emplace(ee_hits[i].detid(), i);
0071   }
0072   auto size = ee_hits.size();
0073 
0074   for (unsigned int i = 0; i < fh_hits.size(); ++i) {
0075     hitMapHGCal->emplace(fh_hits[i].detid(), i + size);
0076   }
0077   size += fh_hits.size();
0078 
0079   for (unsigned int i = 0; i < bh_hits.size(); ++i) {
0080     hitMapHGCal->emplace(bh_hits[i].detid(), i + size);
0081   }
0082 
0083   evt.put(std::move(hitMapHGCal), "hgcalRecHitMap");
0084 
0085   if (!hgcalOnly_) {
0086     auto hitMapBarrel = std::make_unique<DetIdRecHitMap>();
0087     const auto& eb_hits = evt.get(hits_eb_token_);
0088     const auto& hb_hits = evt.get(hits_hb_token_);
0089     const auto& ho_hits = evt.get(hits_ho_token_);
0090     size = 0;
0091 
0092     for (unsigned int i = 0; i < eb_hits.size(); ++i) {
0093       hitMapBarrel->emplace(eb_hits[i].detId(), i);
0094     }
0095     size += eb_hits.size();
0096 
0097     for (unsigned int i = 0; i < hb_hits.size(); ++i) {
0098       hitMapBarrel->emplace(hb_hits[i].detId(), i + size);
0099     }
0100     size += hb_hits.size();
0101 
0102     for (unsigned int i = 0; i < ho_hits.size(); ++i) {
0103       hitMapBarrel->emplace(ho_hits[i].detId(), i + size);
0104     }
0105     evt.put(std::move(hitMapBarrel), "barrelRecHitMap");
0106   }
0107 }