Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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