CMS 3D CMS Logo

FWCaloParticleProxyBuilder.cc
Go to the documentation of this file.
1 /*
2  * FWCaloParticleProxyBuilder.cc
3  * FWorks
4  *
5  * Created by Marco Rovere 13/09/2018
6  *
7  */
8 
15 
16 #include "TEveBoxSet.h"
17 
19 public:
21  ~FWCaloParticleProxyBuilder(void) override {}
22 
24 
25  // Disable default copy constructor
27  // Disable default assignment operator
29 
30 private:
31  void build(const CaloParticle &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *) override;
32 };
33 
35  unsigned int iIndex,
36  TEveElement &oItemHolder,
37  const FWViewContext *) {
38  const long layer = item()->getConfig()->value<long>("Layer");
39  const double saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
40  const bool heatmap = item()->getConfig()->value<bool>("Heatmap");
41  const bool z_plus = item()->getConfig()->value<bool>("Z+");
42  const bool z_minus = item()->getConfig()->value<bool>("Z-");
43 
44  bool h_hex(false);
45  TEveBoxSet *hex_boxset = new TEveBoxSet();
46  if (!heatmap)
47  hex_boxset->UseSingleColor();
48  hex_boxset->SetPickable(true);
49  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
50  hex_boxset->SetAntiFlick(true);
51 
52  bool h_box(false);
53  TEveBoxSet *boxset = new TEveBoxSet();
54  if (!heatmap)
55  boxset->UseSingleColor();
56  boxset->SetPickable(true);
57  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
58  boxset->SetAntiFlick(true);
59 
60  for (const auto &c : iData.simClusters()) {
61  for (const auto &it : (*c).hits_and_fractions()) {
62  if (heatmap && hitmap->find(it.first) == hitmap->end())
63  continue;
64 
65  const bool z = (it.first >> 25) & 0x1;
66 
67  // discard everything thats not at the side that we are intersted in
68  if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
69  continue;
70 
71  const float *corners = item()->getGeom()->getCorners(it.first);
72  const float *parameters = item()->getGeom()->getParameters(it.first);
73  const float *shapes = item()->getGeom()->getShapePars(it.first);
74 
75  if (corners == nullptr || parameters == nullptr || shapes == nullptr) {
76  continue;
77  }
78 
79  const int total_points = parameters[0];
80  const bool isScintillator = (total_points == 4);
81  const uint8_t type = ((it.first >> 28) & 0xF);
82 
83  uint8_t ll = layer;
84  if (layer > 0) {
85  if (layer > 28) {
86  if (type == 8) {
87  continue;
88  }
89  ll -= 28;
90  } else {
91  if (type != 8) {
92  continue;
93  }
94  }
95 
96  if (ll != ((it.first >> (isScintillator ? 17 : 20)) & 0x1F))
97  continue;
98  }
99 
100  // Scintillator
101  if (isScintillator) {
102  const int total_vertices = 3 * total_points;
103 
104  std::vector<float> pnts(24);
105  for (int i = 0; i < total_points; ++i) {
106  pnts[i * 3 + 0] = corners[i * 3];
107  pnts[i * 3 + 1] = corners[i * 3 + 1];
108  pnts[i * 3 + 2] = corners[i * 3 + 2];
109 
110  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
111  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
112  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
113  }
114  boxset->AddBox(&pnts[0]);
115  if (heatmap) {
116  const uint8_t colorFactor = 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, shapes[2], shapes[3]);
130  if (heatmap) {
131  const uint8_t colorFactor = gradient_steps * (fmin(hitmap->at(it.first)->energy() / saturation_energy, 1.0f));
132  hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]);
133  }
134 
135  h_hex = true;
136  }
137  }
138  }
139 
140  if (h_hex) {
141  hex_boxset->RefitPlex();
142 
143  hex_boxset->CSCTakeAnyParentAsMaster();
144  if (!heatmap) {
145  hex_boxset->CSCApplyMainColorToMatchingChildren();
146  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
147  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
148  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
149  }
150  oItemHolder.AddElement(hex_boxset);
151  }
152 
153  if (h_box) {
154  boxset->RefitPlex();
155 
156  boxset->CSCTakeAnyParentAsMaster();
157  if (!heatmap) {
158  boxset->CSCApplyMainColorToMatchingChildren();
159  boxset->CSCApplyMainTransparencyToMatchingChildren();
160  boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
161  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
162  }
163  oItemHolder.AddElement(boxset);
164  }
165 }
166 
168  CaloParticle,
169  "CaloParticle",
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:67
const SimClusterRefVector & simClusters() const
Definition: CaloParticle.h:72
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
const FWCaloParticleProxyBuilder & operator=(const FWCaloParticleProxyBuilder &)=delete
static const int kAll3DBits
Definition: FWViewType.h:68
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:439
static constexpr uint8_t gradient[3][gradient_steps]
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:461
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:450
const FWEventItem * item() const
std::unordered_map< DetId, const HGCRecHit *> * hitmap