Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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