Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 22:39:30

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