CMS 3D CMS Logo

FWHGCRecHitProxyBuilder.cc
Go to the documentation of this file.
6 
7 #include "TEveBoxSet.h"
8 
10 {
11 public:
13  ~FWHGCRecHitProxyBuilder( void ) override {}
14 
16 private:
19 
20  static constexpr uint8_t gradient_steps = 9;
21  static constexpr float gradient[3][gradient_steps] = {
22  {0.2082*255, 0.0592*255, 0.0780*255, 0.0232*255, 0.1802*255, 0.5301*255, 0.8186*255, 0.9956*255, 0.9764*255},
23  {0.1664*255, 0.3599*255, 0.5041*255, 0.6419*255, 0.7178*255, 0.7492*255, 0.7328*255, 0.7862*255, 0.9832*255},
24  {0.5293*255, 0.8684*255, 0.8385*255, 0.7914*255, 0.6425*255, 0.4662*255, 0.3499*255, 0.1968*255, 0.0539*255}
25  };
26 
27  void setItem(const FWEventItem *iItem) override;
28  void build(const HGCRecHit &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *) override;
29 };
30 
32 {
34  if (iItem)
35  {
36  iItem->getConfig()->keepEntries(true);
37  iItem->getConfig()->assertParam("Layer", 0L, 0L, 52L);
38  iItem->getConfig()->assertParam("EnergyCutOff", 0.5, 0.2, 5.0);
39  iItem->getConfig()->assertParam("Heatmap", true);
40  iItem->getConfig()->assertParam("Z+", true);
41  iItem->getConfig()->assertParam("Z-", true);
42  }
43 }
44 
45 void FWHGCRecHitProxyBuilder::build(const HGCRecHit &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *)
46 {
47  const long layer = item()->getConfig()->value<long>("Layer");
48  const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
49  const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
50  const bool z_plus = item()->getConfig()->value<bool>("Z+");
51  const bool z_minus = item()->getConfig()->value<bool>("Z-");
52 
53  TEveBoxSet* boxset = new TEveBoxSet();
54  if(!heatmap)
55  boxset->UseSingleColor();
56  boxset->SetPickable(true);
57  boxset->SetAntiFlick(true);
58 
59  unsigned int ID = iData.id();
60 
61  const bool z = (ID >> 25) & 0x1;
62 
63  // discard everything thats not at the side that we are intersted in
64  if (
65  ((z_plus & z_minus) != 1) &&
66  (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
67  return;
68 
69  const float *corners = item()->getGeom()->getCorners(ID);
70  const float *parameters = item()->getGeom()->getParameters(ID);
71  const float *shapes = item()->getGeom()->getShapePars(ID);
72 
73  if (corners == nullptr || parameters == nullptr || shapes == nullptr)
74  return;
75 
76  const int total_points = parameters[0];
77  const bool isScintillator = (total_points == 4);
78  const uint8_t type = ((ID >> 28) & 0xF);
79 
80  uint8_t ll = layer;
81  if (layer > 0)
82  {
83  if (layer > 28)
84  {
85  if (type == 8)
86  {
87  return;
88  }
89  ll -= 28;
90  }
91  else
92  {
93  if (type != 8)
94  {
95  return;
96  }
97  }
98 
99  if (ll != ((ID >> (isScintillator ? 17 : 20)) & 0x1F))
100  return;
101  }
102 
103  boxset->Reset(isScintillator ? TEveBoxSet::kBT_FreeBox : TEveBoxSet::kBT_Hex, true, 64);
104 
105  // Scintillator
106  if (isScintillator)
107  {
108  const int total_vertices = 3 * total_points;
109 
110  std::vector<float> pnts(24);
111  for (int i = 0; i < total_points; ++i)
112  {
113  pnts[i * 3 + 0] = corners[i * 3];
114  pnts[i * 3 + 1] = corners[i * 3 + 1];
115  pnts[i * 3 + 2] = corners[i * 3 + 2];
116 
117  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
118  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
119  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
120  }
121  boxset->AddBox(&pnts[0]);
122  }
123  // Silicon
124  else
125  {
126  const int offset = 9;
127 
128  float centerX = (corners[6] + corners[6 + offset]) / 2;
129  float centerY = (corners[7] + corners[7 + offset]) / 2;
130  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
131  boxset->AddHex(TEveVector(centerX, centerY, corners[2]),
132  radius, 90.0, shapes[3]);
133  }
134 
135  if(heatmap) {
136  const uint8_t colorFactor = gradient_steps*(fmin(iData.energy()/saturation_energy, 1.0f));
137  boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
138  }
139 
140  boxset->RefitPlex();
141 
142  boxset->CSCTakeAnyParentAsMaster();
143  if (!heatmap)
144  {
145  boxset->CSCApplyMainColorToMatchingChildren();
146  boxset->CSCApplyMainTransparencyToMatchingChildren();
147  boxset->SetMainColor(item()->defaultDisplayProperties().color());
148  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
149  }
150  oItemHolder.AddElement(boxset);
151 }
152 
constexpr float energy() const
Definition: CaloRecHit.h:31
type
Definition: HCALResponse.h:21
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:169
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:446
uint32_t ID
Definition: Definitions.h:26
const FWEventItem * item() const
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:462
virtual void setItem(const FWEventItem *iItem)
const FWHGCRecHitProxyBuilder & operator=(const FWHGCRecHitProxyBuilder &)=delete
DetId id() const
get the id
Definition: HGCRecHit.h:69
FWGenericParameter< T > * assertParam(const std::string &name, T def)
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:430
static float gradient[3][gradient_steps]
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:686
#define constexpr
void setItem(const FWEventItem *iItem) override