Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "LCToCPAssociatorByEnergyScoreProducer.h"
0002 
0003 template <typename HIT>
0004 LCToCPAssociatorByEnergyScoreProducer<HIT>::LCToCPAssociatorByEnergyScoreProducer(const edm::ParameterSet &ps)
0005     : hitMap_(consumes<std::unordered_map<DetId, const unsigned int>>(ps.getParameter<edm::InputTag>("hitMapTag"))),
0006       caloGeometry_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
0007       hardScatterOnly_(ps.getParameter<bool>("hardScatterOnly")),
0008       hits_label_(ps.getParameter<std::vector<edm::InputTag>>("hits")) {
0009   for (auto &label : hits_label_) {
0010     if constexpr (std::is_same_v<HIT, HGCRecHit>)
0011       hgcal_hits_token_.push_back(consumes<HGCRecHitCollection>(label));
0012     else
0013       hits_token_.push_back(consumes<std::vector<HIT>>(label));
0014   }
0015 
0016   rhtools_.reset(new hgcal::RecHitTools());
0017 
0018   // Register the product
0019   produces<ticl::LayerClusterToCaloParticleAssociator>();
0020 }
0021 
0022 template <typename HIT>
0023 LCToCPAssociatorByEnergyScoreProducer<HIT>::~LCToCPAssociatorByEnergyScoreProducer() {}
0024 
0025 template <typename HIT>
0026 void LCToCPAssociatorByEnergyScoreProducer<HIT>::produce(edm::StreamID,
0027                                                          edm::Event &iEvent,
0028                                                          const edm::EventSetup &es) const {
0029   edm::ESHandle<CaloGeometry> geom = es.getHandle(caloGeometry_);
0030   rhtools_->setGeometry(*geom);
0031 
0032   std::vector<const HIT *> hits;
0033   if constexpr (std::is_same_v<HIT, HGCRecHit>) {
0034     for (auto &token : hgcal_hits_token_) {
0035       edm::Handle<HGCRecHitCollection> hits_handle;
0036       iEvent.getByToken(token, hits_handle);
0037       for (const auto &hit : *hits_handle) {
0038         hits.push_back(&hit);
0039       }
0040     }
0041   } else {
0042     for (auto &token : hits_token_) {
0043       edm::Handle<std::vector<HIT>> hits_handle;
0044       iEvent.getByToken(token, hits_handle);
0045       for (const auto &hit : *hits_handle) {
0046         hits.push_back(&hit);
0047       }
0048     }
0049   }
0050 
0051   const auto hitMap = &iEvent.get(hitMap_);
0052 
0053   auto impl = std::make_unique<LCToCPAssociatorByEnergyScoreImpl<HIT>>(
0054       iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits);
0055   auto toPut = std::make_unique<ticl::LayerClusterToCaloParticleAssociator>(std::move(impl));
0056   iEvent.put(std::move(toPut));
0057 }
0058 
0059 template <typename HIT>
0060 void LCToCPAssociatorByEnergyScoreProducer<HIT>::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
0061   edm::ParameterSetDescription desc;
0062   desc.add<bool>("hardScatterOnly", true);
0063   if constexpr (std::is_same_v<HIT, HGCRecHit>) {
0064     desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0065     desc.add<std::vector<edm::InputTag>>("hits",
0066                                          {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0067                                           edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0068                                           edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0069   } else {
0070     desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "barrelRecHitMap"));
0071     desc.add<std::vector<edm::InputTag>>("hits",
0072                                          {edm::InputTag("particleFlowRecHitECAL", ""),
0073                                           edm::InputTag("particleFlowRecHitHBHE", ""),
0074                                           edm::InputTag("particleFlowRecHitHO", "")});
0075   }
0076   cfg.addWithDefaultLabel(desc);
0077 }