File indexing completed on 2024-04-06 12:11:27
0001 #ifndef Fireworks_Core_FWHeatmapProxyBuilderTemplate_h
0002 #define Fireworks_Core_FWHeatmapProxyBuilderTemplate_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <cmath>
0023
0024
0025 #include "Fireworks/Core/interface/FWSimpleProxyBuilder.h"
0026 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0027 #include "Fireworks/Core/interface/FWEventItem.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0030
0031
0032
0033 template <typename T>
0034 class FWHeatmapProxyBuilderTemplate : public FWSimpleProxyBuilder {
0035 public:
0036 FWHeatmapProxyBuilderTemplate() : FWSimpleProxyBuilder(typeid(T)) {}
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 protected:
0047 std::unordered_map<DetId, const HGCRecHit*>* hitmap = new std::unordered_map<DetId, const HGCRecHit*>;
0048
0049 static constexpr uint8_t gradient_steps = 9;
0050 static constexpr uint8_t gradient[3][gradient_steps] = {{static_cast<uint8_t>(0.2082 * 255),
0051 static_cast<uint8_t>(0.0592 * 255),
0052 static_cast<uint8_t>(0.0780 * 255),
0053 static_cast<uint8_t>(0.0232 * 255),
0054 static_cast<uint8_t>(0.1802 * 255),
0055 static_cast<uint8_t>(0.5301 * 255),
0056 static_cast<uint8_t>(0.8186 * 255),
0057 static_cast<uint8_t>(0.9956 * 255),
0058 static_cast<uint8_t>(0.9764 * 255)},
0059
0060 {static_cast<uint8_t>(0.1664 * 255),
0061 static_cast<uint8_t>(0.3599 * 255),
0062 static_cast<uint8_t>(0.5041 * 255),
0063 static_cast<uint8_t>(0.6419 * 255),
0064 static_cast<uint8_t>(0.7178 * 255),
0065 static_cast<uint8_t>(0.7492 * 255),
0066 static_cast<uint8_t>(0.7328 * 255),
0067 static_cast<uint8_t>(0.7862 * 255),
0068 static_cast<uint8_t>(0.9832 * 255)},
0069
0070 {static_cast<uint8_t>(0.5293 * 255),
0071 static_cast<uint8_t>(0.8684 * 255),
0072 static_cast<uint8_t>(0.8385 * 255),
0073 static_cast<uint8_t>(0.7914 * 255),
0074 static_cast<uint8_t>(0.6425 * 255),
0075 static_cast<uint8_t>(0.4662 * 255),
0076 static_cast<uint8_t>(0.3499 * 255),
0077 static_cast<uint8_t>(0.1968 * 255),
0078 static_cast<uint8_t>(0.0539 * 255)}};
0079
0080 const T& modelData(int index) { return *reinterpret_cast<const T*>(m_helper.offsetObject(item()->modelData(index))); }
0081
0082 void setItem(const FWEventItem* iItem) override {
0083 FWProxyBuilderBase::setItem(iItem);
0084 if (iItem) {
0085 iItem->getConfig()->keepEntries(true);
0086 iItem->getConfig()->assertParam("Layer", 0L, 0L, 52L);
0087 iItem->getConfig()->assertParam("EnergyCutOff", 0.5, 0.2, 5.0);
0088 iItem->getConfig()->assertParam("Heatmap", true);
0089 iItem->getConfig()->assertParam("Z+", true);
0090 iItem->getConfig()->assertParam("Z-", true);
0091 }
0092 }
0093
0094 void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc) override {
0095 if (item()->getConfig()->template value<bool>("Heatmap")) {
0096 hitmap->clear();
0097
0098 edm::Handle<HGCRecHitCollection> recHitHandleEE;
0099 edm::Handle<HGCRecHitCollection> recHitHandleFH;
0100 edm::Handle<HGCRecHitCollection> recHitHandleBH;
0101
0102 const edm::EventBase* event = iItem->getEvent();
0103
0104 event->getByLabel(edm::InputTag("HGCalRecHit", "HGCEERecHits"), recHitHandleEE);
0105 event->getByLabel(edm::InputTag("HGCalRecHit", "HGCHEFRecHits"), recHitHandleFH);
0106 event->getByLabel(edm::InputTag("HGCalRecHit", "HGCHEBRecHits"), recHitHandleBH);
0107
0108 if (recHitHandleEE.isValid()) {
0109 const auto& rechitsEE = *recHitHandleEE;
0110
0111 for (unsigned int i = 0; i < rechitsEE.size(); ++i) {
0112 (*hitmap)[rechitsEE[i].detid().rawId()] = &rechitsEE[i];
0113 }
0114 }
0115
0116 if (recHitHandleFH.isValid()) {
0117 const auto& rechitsFH = *recHitHandleFH;
0118
0119 for (unsigned int i = 0; i < rechitsFH.size(); ++i) {
0120 (*hitmap)[rechitsFH[i].detid().rawId()] = &rechitsFH[i];
0121 }
0122 }
0123
0124 if (recHitHandleBH.isValid()) {
0125 const auto& rechitsBH = *recHitHandleBH;
0126
0127 for (unsigned int i = 0; i < rechitsBH.size(); ++i) {
0128 (*hitmap)[rechitsBH[i].detid().rawId()] = &rechitsBH[i];
0129 }
0130 }
0131 }
0132
0133 FWSimpleProxyBuilder::build(iItem, product, vc);
0134 }
0135
0136 using FWSimpleProxyBuilder::build;
0137 void build(const void* iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* context) override {
0138 if (nullptr != iData) {
0139 build(*reinterpret_cast<const T*>(iData), iIndex, oItemHolder, context);
0140 }
0141 }
0142
0143 using FWSimpleProxyBuilder::buildViewType;
0144 void buildViewType(const void* iData,
0145 unsigned int iIndex,
0146 TEveElement& oItemHolder,
0147 FWViewType::EType viewType,
0148 const FWViewContext* context) override {
0149 if (nullptr != iData) {
0150 buildViewType(*reinterpret_cast<const T*>(iData), iIndex, oItemHolder, viewType, context);
0151 }
0152 }
0153
0154
0155
0156 virtual void build(const T& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) {
0157 throw std::runtime_error(
0158 "virtual build(const T&, unsigned int, TEveElement&, const FWViewContext*) not implemented by inherited "
0159 "class.");
0160 }
0161
0162 virtual void buildViewType(
0163 const T& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType viewType, const FWViewContext*) {
0164 throw std::runtime_error(
0165 "virtual buildViewType(const T&, unsigned int, TEveElement&, FWViewType::EType, const FWViewContext*) not "
0166 "implemented by inherited class");
0167 };
0168
0169 public:
0170 FWHeatmapProxyBuilderTemplate(const FWHeatmapProxyBuilderTemplate&) = delete;
0171
0172 const FWHeatmapProxyBuilderTemplate& operator=(const FWHeatmapProxyBuilderTemplate&) = delete;
0173 private:
0174
0175 };
0176
0177 #endif