Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:27

0001 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0002 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0003 #include "Fireworks/Core/interface/FWEventItem.h"
0004 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0005 #include "Fireworks/Core/interface/FWGeometry.h"
0006 
0007 #include "TEveBoxSet.h"
0008 
0009 class FWHGCRecHitProxyBuilder : public FWSimpleProxyBuilderTemplate<HGCRecHit> {
0010 public:
0011   FWHGCRecHitProxyBuilder() {}
0012   ~FWHGCRecHitProxyBuilder(void) override {}
0013 
0014   REGISTER_PROXYBUILDER_METHODS();
0015 
0016   FWHGCRecHitProxyBuilder(const FWHGCRecHitProxyBuilder &) = delete;
0017   const FWHGCRecHitProxyBuilder &operator=(const FWHGCRecHitProxyBuilder &) = delete;
0018 
0019 private:
0020   static constexpr uint8_t gradient_steps = 9;
0021   static constexpr float gradient[3][gradient_steps] = {{0.2082 * 255,
0022                                                          0.0592 * 255,
0023                                                          0.0780 * 255,
0024                                                          0.0232 * 255,
0025                                                          0.1802 * 255,
0026                                                          0.5301 * 255,
0027                                                          0.8186 * 255,
0028                                                          0.9956 * 255,
0029                                                          0.9764 * 255},
0030                                                         {0.1664 * 255,
0031                                                          0.3599 * 255,
0032                                                          0.5041 * 255,
0033                                                          0.6419 * 255,
0034                                                          0.7178 * 255,
0035                                                          0.7492 * 255,
0036                                                          0.7328 * 255,
0037                                                          0.7862 * 255,
0038                                                          0.9832 * 255},
0039                                                         {0.5293 * 255,
0040                                                          0.8684 * 255,
0041                                                          0.8385 * 255,
0042                                                          0.7914 * 255,
0043                                                          0.6425 * 255,
0044                                                          0.4662 * 255,
0045                                                          0.3499 * 255,
0046                                                          0.1968 * 255,
0047                                                          0.0539 * 255}};
0048 
0049   void setItem(const FWEventItem *iItem) override;
0050   void build(const HGCRecHit &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *) override;
0051 };
0052 
0053 void FWHGCRecHitProxyBuilder::setItem(const FWEventItem *iItem) {
0054   FWProxyBuilderBase::setItem(iItem);
0055   if (iItem) {
0056     iItem->getConfig()->keepEntries(true);
0057     iItem->getConfig()->assertParam("Layer", 0L, 0L, 52L);
0058     iItem->getConfig()->assertParam("EnergyCutOff", 0.5, 0.2, 5.0);
0059     iItem->getConfig()->assertParam("Heatmap", true);
0060     iItem->getConfig()->assertParam("Z+", true);
0061     iItem->getConfig()->assertParam("Z-", true);
0062   }
0063 }
0064 
0065 void FWHGCRecHitProxyBuilder::build(const HGCRecHit &iData,
0066                                     unsigned int iIndex,
0067                                     TEveElement &oItemHolder,
0068                                     const FWViewContext *) {
0069   const long layer = item()->getConfig()->value<long>("Layer");
0070   const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
0071   const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
0072   const bool z_plus = item()->getConfig()->value<bool>("Z+");
0073   const bool z_minus = item()->getConfig()->value<bool>("Z-");
0074 
0075   TEveBoxSet *boxset = new TEveBoxSet();
0076   if (!heatmap)
0077     boxset->UseSingleColor();
0078   boxset->SetPickable(true);
0079   boxset->SetAntiFlick(true);
0080 
0081   unsigned int ID = iData.id();
0082 
0083   const bool z = (ID >> 25) & 0x1;
0084 
0085   // discard everything thats not at the side that we are intersted in
0086   if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
0087     return;
0088 
0089   const float *corners = item()->getGeom()->getCorners(ID);
0090   const float *parameters = item()->getGeom()->getParameters(ID);
0091   const float *shapes = item()->getGeom()->getShapePars(ID);
0092 
0093   if (corners == nullptr || parameters == nullptr || shapes == nullptr)
0094     return;
0095 
0096   const int total_points = parameters[0];
0097   const bool isScintillator = (total_points == 4);
0098   const uint8_t type = ((ID >> 28) & 0xF);
0099 
0100   uint8_t ll = layer;
0101   if (layer > 0) {
0102     if (layer > 28) {
0103       if (type == 8) {
0104         return;
0105       }
0106       ll -= 28;
0107     } else {
0108       if (type != 8) {
0109         return;
0110       }
0111     }
0112 
0113     if (ll != ((ID >> (isScintillator ? 17 : 20)) & 0x1F))
0114       return;
0115   }
0116 
0117   boxset->Reset(isScintillator ? TEveBoxSet::kBT_FreeBox : TEveBoxSet::kBT_Hex, true, 64);
0118 
0119   // Scintillator
0120   if (isScintillator) {
0121     const int total_vertices = 3 * total_points;
0122 
0123     std::vector<float> pnts(24);
0124     for (int i = 0; i < total_points; ++i) {
0125       pnts[i * 3 + 0] = corners[i * 3];
0126       pnts[i * 3 + 1] = corners[i * 3 + 1];
0127       pnts[i * 3 + 2] = corners[i * 3 + 2];
0128 
0129       pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
0130       pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
0131       pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
0132     }
0133     boxset->AddBox(&pnts[0]);
0134   }
0135   // Silicon
0136   else {
0137     const int offset = 9;
0138 
0139     float centerX = (corners[6] + corners[6 + offset]) / 2;
0140     float centerY = (corners[7] + corners[7 + offset]) / 2;
0141     float radius = fabs(corners[6] - corners[6 + offset]) / 2;
0142     boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, shapes[2], shapes[3]);
0143   }
0144 
0145   if (heatmap) {
0146     const uint8_t colorFactor = gradient_steps * (fmin(iData.energy() / saturation_energy, 1.0f));
0147     boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
0148   }
0149 
0150   boxset->RefitPlex();
0151 
0152   boxset->CSCTakeAnyParentAsMaster();
0153   if (!heatmap) {
0154     boxset->CSCApplyMainColorToMatchingChildren();
0155     boxset->CSCApplyMainTransparencyToMatchingChildren();
0156     boxset->SetMainColor(item()->defaultDisplayProperties().color());
0157     boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0158   }
0159   oItemHolder.AddElement(boxset);
0160 }
0161 
0162 REGISTER_FWPROXYBUILDER(FWHGCRecHitProxyBuilder, HGCRecHit, "HGC RecHit", FWViewType::kISpyBit);