Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Original author: Leonardo Cristella
0002 
0003 // user include files
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Utilities/interface/EDGetToken.h"
0012 #include "FWCore/Utilities/interface/ESGetToken.h"
0013 
0014 #include "SimDataFormats/Associations/interface/TracksterToSimTracksterHitLCAssociator.h"
0015 #include "TSToSimTSHitLCAssociatorByEnergyScoreImpl.h"
0016 
0017 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0018 
0019 class TSToSimTSHitLCAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> {
0020 public:
0021   explicit TSToSimTSHitLCAssociatorByEnergyScoreProducer(const edm::ParameterSet &);
0022   ~TSToSimTSHitLCAssociatorByEnergyScoreProducer() override;
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0025 
0026 private:
0027   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0028   edm::EDGetTokenT<std::unordered_map<DetId, const unsigned int>> hitMap_;
0029   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometry_;
0030   const bool hardScatterOnly_;
0031   std::shared_ptr<hgcal::RecHitTools> rhtools_;
0032   std::vector<edm::InputTag> hits_label_;
0033   std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hits_token_;
0034 };
0035 
0036 TSToSimTSHitLCAssociatorByEnergyScoreProducer::TSToSimTSHitLCAssociatorByEnergyScoreProducer(const edm::ParameterSet &ps)
0037     : hitMap_(consumes<std::unordered_map<DetId, const unsigned int>>(ps.getParameter<edm::InputTag>("hitMapTag"))),
0038       caloGeometry_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0039       hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
0040       hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
0041   rhtools_.reset(new hgcal::RecHitTools());
0042 
0043   for (auto &label : hits_label_) {
0044     hits_token_.push_back(consumes<HGCRecHitCollection>(label));
0045   }
0046 
0047   // Register the product
0048   produces<ticl::TracksterToSimTracksterHitLCAssociator>();
0049 }
0050 
0051 TSToSimTSHitLCAssociatorByEnergyScoreProducer::~TSToSimTSHitLCAssociatorByEnergyScoreProducer() {}
0052 
0053 void TSToSimTSHitLCAssociatorByEnergyScoreProducer::produce(edm::StreamID,
0054                                                             edm::Event &iEvent,
0055                                                             const edm::EventSetup &es) const {
0056   edm::ESHandle<CaloGeometry> geom = es.getHandle(caloGeometry_);
0057   rhtools_->setGeometry(*geom);
0058 
0059   std::vector<const HGCRecHit *> hits;
0060   for (auto &token : hits_token_) {
0061     edm::Handle<HGCRecHitCollection> hits_handle;
0062     iEvent.getByToken(token, hits_handle);
0063     for (const auto &hit : *hits_handle) {
0064       hits.push_back(&hit);
0065     }
0066   }
0067 
0068   const auto hitMap = &iEvent.get(hitMap_);
0069 
0070   auto impl = std::make_unique<TSToSimTSHitLCAssociatorByEnergyScoreImpl>(
0071       iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits);
0072   auto toPut = std::make_unique<ticl::TracksterToSimTracksterHitLCAssociator>(std::move(impl));
0073   iEvent.put(std::move(toPut));
0074 }
0075 
0076 void TSToSimTSHitLCAssociatorByEnergyScoreProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
0077   edm::ParameterSetDescription desc;
0078   desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0079   desc.add<std::vector<edm::InputTag>>("hits",
0080                                        {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0081                                         edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0082                                         edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0083   desc.add<bool>("hardScatterOnly", true);
0084 
0085   cfg.add("simTracksterHitLCAssociatorByEnergyScore", desc);
0086 }
0087 
0088 //define this as a plug-in
0089 DEFINE_FWK_MODULE(TSToSimTSHitLCAssociatorByEnergyScoreProducer);