Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:09:55

0001 #include "TEveBoxSet.h"
0002 #include "Fireworks/Calo/interface/FWHeatmapProxyBuilderTemplate.h"
0003 #include "Fireworks/Core/interface/FWEventItem.h"
0004 #include "Fireworks/Core/interface/FWGeometry.h"
0005 #include "Fireworks/Core/interface/BuilderUtils.h"
0006 #include "DataFormats/ParticleFlowReco/interface/HGCalMultiCluster.h"
0007 
0008 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0009 
0010 class FWHGCalMultiClusterProxyBuilder : public FWHeatmapProxyBuilderTemplate<reco::HGCalMultiCluster> {
0011 public:
0012   FWHGCalMultiClusterProxyBuilder(void) {}
0013   ~FWHGCalMultiClusterProxyBuilder(void) override {}
0014 
0015   REGISTER_PROXYBUILDER_METHODS();
0016 
0017   FWHGCalMultiClusterProxyBuilder(const FWHGCalMultiClusterProxyBuilder &) = delete;                   // stop default
0018   const FWHGCalMultiClusterProxyBuilder &operator=(const FWHGCalMultiClusterProxyBuilder &) = delete;  // stop default
0019 
0020 private:
0021   void build(const reco::HGCalMultiCluster &iData,
0022              unsigned int iIndex,
0023              TEveElement &oItemHolder,
0024              const FWViewContext *) override;
0025 };
0026 
0027 void FWHGCalMultiClusterProxyBuilder::build(const reco::HGCalMultiCluster &iData,
0028                                             unsigned int iIndex,
0029                                             TEveElement &oItemHolder,
0030                                             const FWViewContext *) {
0031   const long layer = item()->getConfig()->value<long>("Layer");
0032   const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
0033   const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
0034   const bool z_plus = item()->getConfig()->value<bool>("Z+");
0035   const bool z_minus = item()->getConfig()->value<bool>("Z-");
0036 
0037   const auto &clusters = iData.clusters();
0038 
0039   bool h_hex(false);
0040   TEveBoxSet *hex_boxset = new TEveBoxSet("Silicon");
0041   if (!heatmap)
0042     hex_boxset->UseSingleColor();
0043   hex_boxset->SetPickable(true);
0044   hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
0045   hex_boxset->SetAntiFlick(kTRUE);
0046 
0047   bool h_box(false);
0048   TEveBoxSet *boxset = new TEveBoxSet("Scintillator");
0049   if (!heatmap)
0050     boxset->UseSingleColor();
0051   boxset->SetPickable(true);
0052   boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
0053   boxset->SetAntiFlick(kTRUE);
0054 
0055   for (const auto &c : clusters) {
0056     std::vector<std::pair<DetId, float>> clusterDetIds = c->hitsAndFractions();
0057 
0058     for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
0059          it != itEnd;
0060          ++it) {
0061       if (heatmap && hitmap->find(it->first) == hitmap->end())
0062         continue;
0063 
0064       const bool z = (it->first >> 25) & 0x1;
0065 
0066       // discard everything thats not at the side that we are intersted in
0067       if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
0068         continue;
0069 
0070       const float *corners = item()->getGeom()->getCorners(it->first);
0071       const float *parameters = item()->getGeom()->getParameters(it->first);
0072       const float *shapes = item()->getGeom()->getShapePars(it->first);
0073 
0074       if (corners == nullptr || parameters == nullptr || shapes == nullptr) {
0075         continue;
0076       }
0077 
0078       const int total_points = parameters[0];
0079       const bool isScintillator = (total_points == 4);
0080       const uint8_t type = ((it->first >> 28) & 0xF);
0081 
0082       uint8_t ll = layer;
0083       if (layer > 0) {
0084         if (layer > 28) {
0085           if (type == 8) {
0086             continue;
0087           }
0088           ll -= 28;
0089         } else {
0090           if (type != 8) {
0091             continue;
0092           }
0093         }
0094 
0095         if (ll != ((it->first >> (isScintillator ? 17 : 20)) & 0x1F))
0096           continue;
0097       }
0098 
0099       // Scintillator
0100       if (isScintillator) {
0101         const int total_vertices = 3 * total_points;
0102 
0103         std::vector<float> pnts(24);
0104         for (int i = 0; i < total_points; ++i) {
0105           pnts[i * 3 + 0] = corners[i * 3];
0106           pnts[i * 3 + 1] = corners[i * 3 + 1];
0107           pnts[i * 3 + 2] = corners[i * 3 + 2];
0108 
0109           pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
0110           pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
0111           pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
0112         }
0113         boxset->AddBox(&pnts[0]);
0114         if (heatmap) {
0115           const uint8_t colorFactor =
0116               gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
0117           boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
0118         }
0119 
0120         h_box = true;
0121       }
0122       // Silicon
0123       else {
0124         const int offset = 9;
0125 
0126         float centerX = (corners[6] + corners[6 + offset]) / 2;
0127         float centerY = (corners[7] + corners[7 + offset]) / 2;
0128         float radius = fabs(corners[6] - corners[6 + offset]) / 2;
0129         hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, 90.0, shapes[3]);
0130         if (heatmap) {
0131           const uint8_t colorFactor =
0132               gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
0133           hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
0134         }
0135 
0136         h_hex = true;
0137       }
0138     }
0139   }
0140 
0141   if (h_hex) {
0142     hex_boxset->RefitPlex();
0143 
0144     hex_boxset->CSCTakeAnyParentAsMaster();
0145     if (!heatmap) {
0146       hex_boxset->CSCApplyMainColorToMatchingChildren();
0147       hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
0148       hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0149       hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0150     }
0151     oItemHolder.AddElement(hex_boxset);
0152   }
0153 
0154   if (h_box) {
0155     boxset->RefitPlex();
0156 
0157     boxset->CSCTakeAnyParentAsMaster();
0158     if (!heatmap) {
0159       boxset->CSCApplyMainColorToMatchingChildren();
0160       boxset->CSCApplyMainTransparencyToMatchingChildren();
0161       boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0162       boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0163     }
0164     oItemHolder.AddElement(boxset);
0165   }
0166 }
0167 
0168 REGISTER_FWPROXYBUILDER(FWHGCalMultiClusterProxyBuilder,
0169                         reco::HGCalMultiCluster,
0170                         "HGCal MultiCluster",
0171                         FWViewType::kISpyBit);