CMS 3D CMS Logo

FWHGCalMultiClusterProxyBuilder.cc
Go to the documentation of this file.
1 #include "TEveBoxSet.h"
7 
9 
10 class FWHGCalMultiClusterProxyBuilder : public FWHeatmapProxyBuilderTemplate<reco::HGCalMultiCluster> {
11 public:
14 
16 
17  FWHGCalMultiClusterProxyBuilder(const FWHGCalMultiClusterProxyBuilder &) = delete; // stop default
18  const FWHGCalMultiClusterProxyBuilder &operator=(const FWHGCalMultiClusterProxyBuilder &) = delete; // stop default
19 
20 private:
21  void build(const reco::HGCalMultiCluster &iData,
22  unsigned int iIndex,
23  TEveElement &oItemHolder,
24  const FWViewContext *) override;
25 };
26 
28  unsigned int iIndex,
29  TEveElement &oItemHolder,
30  const FWViewContext *) {
31  const long layer = item()->getConfig()->value<long>("Layer");
32  const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
33  const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
34  const bool z_plus = item()->getConfig()->value<bool>("Z+");
35  const bool z_minus = item()->getConfig()->value<bool>("Z-");
36 
37  const auto &clusters = iData.clusters();
38 
39  bool h_hex(false);
40  TEveBoxSet *hex_boxset = new TEveBoxSet("Silicon");
41  if (!heatmap)
42  hex_boxset->UseSingleColor();
43  hex_boxset->SetPickable(true);
44  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
45  hex_boxset->SetAntiFlick(kTRUE);
46 
47  bool h_box(false);
48  TEveBoxSet *boxset = new TEveBoxSet("Scintillator");
49  if (!heatmap)
50  boxset->UseSingleColor();
51  boxset->SetPickable(true);
52  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
53  boxset->SetAntiFlick(kTRUE);
54 
55  for (const auto &c : clusters) {
56  std::vector<std::pair<DetId, float>> clusterDetIds = c->hitsAndFractions();
57 
58  for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
59  it != itEnd;
60  ++it) {
61  if (heatmap && hitmap->find(it->first) == hitmap->end())
62  continue;
63 
64  const bool z = (it->first >> 25) & 0x1;
65 
66  // discard everything thats not at the side that we are intersted in
67  if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
68  continue;
69 
70  const float *corners = item()->getGeom()->getCorners(it->first);
71  const float *parameters = item()->getGeom()->getParameters(it->first);
72  const float *shapes = item()->getGeom()->getShapePars(it->first);
73 
74  if (corners == nullptr || parameters == nullptr || shapes == nullptr) {
75  continue;
76  }
77 
78  const int total_points = parameters[0];
79  const bool isScintillator = (total_points == 4);
80  const uint8_t type = ((it->first >> 28) & 0xF);
81 
82  uint8_t ll = layer;
83  if (layer > 0) {
84  if (layer > 28) {
85  if (type == 8) {
86  continue;
87  }
88  ll -= 28;
89  } else {
90  if (type != 8) {
91  continue;
92  }
93  }
94 
95  if (ll != ((it->first >> (isScintillator ? 17 : 20)) & 0x1F))
96  continue;
97  }
98 
99  // Scintillator
100  if (isScintillator) {
101  const int total_vertices = 3 * total_points;
102 
103  std::vector<float> pnts(24);
104  for (int i = 0; i < total_points; ++i) {
105  pnts[i * 3 + 0] = corners[i * 3];
106  pnts[i * 3 + 1] = corners[i * 3 + 1];
107  pnts[i * 3 + 2] = corners[i * 3 + 2];
108 
109  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
110  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
111  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
112  }
113  boxset->AddBox(&pnts[0]);
114  if (heatmap) {
115  const uint8_t colorFactor =
116  gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
117  boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
118  }
119 
120  h_box = true;
121  }
122  // Silicon
123  else {
124  const int offset = 9;
125 
126  float centerX = (corners[6] + corners[6 + offset]) / 2;
127  float centerY = (corners[7] + corners[7 + offset]) / 2;
128  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
129  hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, 90.0, shapes[3]);
130  if (heatmap) {
131  const uint8_t colorFactor =
132  gradient_steps * (fmin(hitmap->at(it->first)->energy() / saturation_energy, 1.0f));
133  hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
134  }
135 
136  h_hex = true;
137  }
138  }
139  }
140 
141  if (h_hex) {
142  hex_boxset->RefitPlex();
143 
144  hex_boxset->CSCTakeAnyParentAsMaster();
145  if (!heatmap) {
146  hex_boxset->CSCApplyMainColorToMatchingChildren();
147  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
148  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
149  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
150  }
151  oItemHolder.AddElement(hex_boxset);
152  }
153 
154  if (h_box) {
155  boxset->RefitPlex();
156 
157  boxset->CSCTakeAnyParentAsMaster();
158  if (!heatmap) {
159  boxset->CSCApplyMainColorToMatchingChildren();
160  boxset->CSCApplyMainTransparencyToMatchingChildren();
161  boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
162  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
163  }
164  oItemHolder.AddElement(boxset);
165  }
166 }
167 
170  "HGCal MultiCluster",
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
const edm::PtrVector< reco::BasicCluster > & clusters() const
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:461
const FWHGCalMultiClusterProxyBuilder & operator=(const FWHGCalMultiClusterProxyBuilder &)=delete
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:483
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:472
const FWEventItem * item() const
std::unordered_map< DetId, const HGCRecHit *> * hitmap