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/TracksterToSimClusterAssociator.h"
0017 #include "TSToSCAssociatorByEnergyScoreImpl.h"
0018 
0019 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0020 
0021 class TSToSCAssociatorByEnergyScoreProducer : public edm::global::EDProducer<> {
0022 public:
0023   explicit TSToSCAssociatorByEnergyScoreProducer(const edm::ParameterSet &);
0024   ~TSToSCAssociatorByEnergyScoreProducer() 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 TSToSCAssociatorByEnergyScoreProducer::TSToSCAssociatorByEnergyScoreProducer(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   // Register the product
0049   produces<ticl::TracksterToSimClusterAssociator>();
0050 }
0051 
0052 TSToSCAssociatorByEnergyScoreProducer::~TSToSCAssociatorByEnergyScoreProducer() {}
0053 
0054 void TSToSCAssociatorByEnergyScoreProducer::produce(edm::StreamID,
0055                                                     edm::Event &iEvent,
0056                                                     const edm::EventSetup &es) const {
0057   edm::ESHandle<CaloGeometry> geom = es.getHandle(caloGeometry_);
0058   rhtools_->setGeometry(*geom);
0059 
0060   std::vector<const HGCRecHit *> hits;
0061   for (auto &token : hits_token_) {
0062     edm::Handle<HGCRecHitCollection> hits_handle;
0063     iEvent.getByToken(token, hits_handle);
0064     for (const auto &hit : *hits_handle) {
0065       hits.push_back(&hit);
0066     }
0067   }
0068 
0069   const auto hitMap = &iEvent.get(hitMap_);
0070 
0071   auto impl = std::make_unique<TSToSCAssociatorByEnergyScoreImpl>(
0072       iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits);
0073   auto toPut = std::make_unique<ticl::TracksterToSimClusterAssociator>(std::move(impl));
0074   iEvent.put(std::move(toPut));
0075 }
0076 
0077 void TSToSCAssociatorByEnergyScoreProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
0078   edm::ParameterSetDescription desc;
0079   desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0080   desc.add<std::vector<edm::InputTag>>("hits",
0081                                        {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0082                                         edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0083                                         edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0084   desc.add<bool>("hardScatterOnly", true);
0085 
0086   cfg.add("tracksterAssociatorByEnergyScore", desc);
0087 }
0088 
0089 //define this as a plug-in
0090 DEFINE_FWK_MODULE(TSToSCAssociatorByEnergyScoreProducer);