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/HcalDetId/interface/HcalDetId.h"
0008 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0009 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0010 #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
0011 // #include "L1Trigger/L1THGCal/plugins/geometries/HGCalTriggerGeometryV9Imp2.cc"
0012 
0013 #include "TEveBoxSet.h"
0014 
0015 class FWHGCalTriggerCellProxyBuilder : public FWL1THGCalProxyTemplate<l1t::HGCalTriggerCell> {
0016 public:
0017   FWHGCalTriggerCellProxyBuilder(void) {}
0018   ~FWHGCalTriggerCellProxyBuilder(void) override {}
0019 
0020   REGISTER_PROXYBUILDER_METHODS();
0021 
0022   FWHGCalTriggerCellProxyBuilder(const FWHGCalTriggerCellProxyBuilder &) = delete;                   // stop default
0023   const FWHGCalTriggerCellProxyBuilder &operator=(const FWHGCalTriggerCellProxyBuilder &) = delete;  // stop default
0024 
0025 private:
0026   void build(const l1t::HGCalTriggerCell &iData,
0027              unsigned int iIndex,
0028              TEveElement &oItemHolder,
0029              const FWViewContext *) override;
0030 };
0031 
0032 void FWHGCalTriggerCellProxyBuilder::build(const l1t::HGCalTriggerCell &iData,
0033                                            unsigned int iIndex,
0034                                            TEveElement &oItemHolder,
0035                                            const FWViewContext *) {
0036   const long layer = item()->getConfig()->value<long>("Layer");
0037   const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
0038   const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
0039 
0040   const bool z_plus = item()->getConfig()->value<bool>("Z+");
0041   const bool z_minus = item()->getConfig()->value<bool>("Z-");
0042 
0043   bool h_hex(false);
0044   TEveBoxSet *hex_boxset = new TEveBoxSet();
0045   if (!heatmap)
0046     hex_boxset->UseSingleColor();
0047   hex_boxset->SetPickable(true);
0048   hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
0049   hex_boxset->SetAntiFlick(true);
0050 
0051   bool h_box(false);
0052   TEveBoxSet *boxset = new TEveBoxSet();
0053   if (!heatmap)
0054     boxset->UseSingleColor();
0055   boxset->SetPickable(true);
0056   boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
0057   boxset->SetAntiFlick(true);
0058 
0059   const float energy = fmin(10 * iData.energy() / saturation_energy, 1.0);
0060 
0061   std::unordered_set<unsigned> cells = getCellsFromTriggerCell(iData.detId());
0062 
0063   for (std::unordered_set<unsigned>::const_iterator it = cells.begin(), itEnd = cells.end(); it != itEnd; ++it) {
0064     const bool z = (*it >> 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);
0071     const float *parameters = item()->getGeom()->getParameters(*it);
0072     const float *shapes = item()->getGeom()->getShapePars(*it);
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 >> 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 >> (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       boxset->DigitColor(energy * 255, 0, 255 - energy * 255);
0115 
0116       h_box = true;
0117     }
0118     // Silicon
0119     else {
0120       const int offset = 9;
0121 
0122       float centerX = (corners[6] + corners[6 + offset]) / 2;
0123       float centerY = (corners[7] + corners[7 + offset]) / 2;
0124       float radius = fabs(corners[6] - corners[6 + offset]) / 2;
0125       hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, shapes[2], shapes[3]);
0126       hex_boxset->DigitColor(energy * 255, 0, 255 - energy * 255);
0127 
0128       h_hex = true;
0129     }
0130   }
0131 
0132   if (h_hex) {
0133     hex_boxset->RefitPlex();
0134 
0135     hex_boxset->CSCTakeAnyParentAsMaster();
0136     if (!heatmap) {
0137       hex_boxset->CSCApplyMainColorToMatchingChildren();
0138       hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
0139       hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0140       hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0141     }
0142     oItemHolder.AddElement(hex_boxset);
0143   }
0144 
0145   if (h_box) {
0146     boxset->RefitPlex();
0147 
0148     boxset->CSCTakeAnyParentAsMaster();
0149     if (!heatmap) {
0150       boxset->CSCApplyMainColorToMatchingChildren();
0151       boxset->CSCApplyMainTransparencyToMatchingChildren();
0152       boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
0153       boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
0154     }
0155     oItemHolder.AddElement(boxset);
0156   }
0157 }
0158 
0159 REGISTER_FWPROXYBUILDER(FWHGCalTriggerCellProxyBuilder,
0160                         l1t::HGCalTriggerCell,
0161                         "HGCal Trigger Cell",
0162                         FWViewType::kAll3DBits);