Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-20 03:14:12

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