File indexing completed on 2024-05-29 23:13:09
0001 #include "LCToSCAssociatorByEnergyScoreProducer.h"
0002
0003 template <typename HIT>
0004 LCToSCAssociatorByEnergyScoreProducer<HIT>::LCToSCAssociatorByEnergyScoreProducer(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
0019 produces<ticl::LayerClusterToSimClusterAssociator>();
0020 }
0021
0022 template <typename HIT>
0023 LCToSCAssociatorByEnergyScoreProducer<HIT>::~LCToSCAssociatorByEnergyScoreProducer() {}
0024
0025 template <typename HIT>
0026 void LCToSCAssociatorByEnergyScoreProducer<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 const auto hitMap = &iEvent.get(hitMap_);
0051
0052 auto impl = std::make_unique<LCToSCAssociatorByEnergyScoreImpl<HIT>>(
0053 iEvent.productGetter(), hardScatterOnly_, rhtools_, hitMap, hits);
0054 auto toPut = std::make_unique<ticl::LayerClusterToSimClusterAssociator>(std::move(impl));
0055 iEvent.put(std::move(toPut));
0056 }
0057
0058 template <typename HIT>
0059 void LCToSCAssociatorByEnergyScoreProducer<HIT>::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
0060 edm::ParameterSetDescription desc;
0061 desc.add<bool>("hardScatterOnly", true);
0062 if constexpr (std::is_same_v<HIT, HGCRecHit>) {
0063 desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0064 desc.add<std::vector<edm::InputTag>>("hits",
0065 {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0066 edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0067 edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0068 } else {
0069 desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "barrelRecHitMap"));
0070 desc.add<std::vector<edm::InputTag>>("hits",
0071 {edm::InputTag("particleFlowRecHitECAL", ""),
0072 edm::InputTag("particleFlowRecHitHBHE", ""),
0073 edm::InputTag("particleFlowRecHitHO", "")});
0074 }
0075 cfg.addWithDefaultLabel(desc);
0076 }