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