CMS 3D CMS Logo

FWCaloClusterProxyBuilder.cc
Go to the documentation of this file.
7 
8 #include "TEveBoxSet.h"
9 #include "TEveStraightLineSet.h"
10 
12 {
13  public:
15  ~FWCaloClusterProxyBuilder(void) override {}
16 
18 
19  private:
22  long layer;
24  bool heatmap;
25  bool z_plus;
26  bool z_minus;
28 
29  FWCaloClusterProxyBuilder(const FWCaloClusterProxyBuilder &) = delete; // stop default
30  const FWCaloClusterProxyBuilder &operator=(const FWCaloClusterProxyBuilder &) = delete; // stop default
31 
32  void setItem(const FWEventItem *iItem) override;
33 
34  void build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) override;
35  void build(const reco::CaloCluster &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *) override;
36 };
37 
39 {
41  if (iItem)
42  {
43  iItem->getConfig()->assertParam("Cluster(0)/RecHit(1)", false);
44  iItem->getConfig()->assertParam("EnableTimeFilter", false);
45  iItem->getConfig()->assertParam("TimeLowerBound(ns)", 0.01, 0.0, 75.0);
46  iItem->getConfig()->assertParam("TimeUpperBound(ns)", 0.01, 0.0, 75.0);
47  }
48 }
49 
50 void FWCaloClusterProxyBuilder::build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc)
51 {
52  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters", "timeLayerCluster"), TimeValueMapHandle);
54  timeLowerBound = std::min(item()->getConfig()->value<double>("TimeLowerBound(ns)"), item()->getConfig()->value<double>("TimeUpperBound(ns)"));
55  timeUpperBound = std::max(item()->getConfig()->value<double>("TimeLowerBound(ns)"), item()->getConfig()->value<double>("TimeUpperBound(ns)"));
56  }
57  else {
58  std::cerr << "Warning: couldn't locate 'timeLayerCluster' ValueMap in root file." << std::endl;
59  }
60 
61  layer = item()->getConfig()->value<long>("Layer");
62  saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
63  heatmap = item()->getConfig()->value<bool>("Heatmap");
64  z_plus = item()->getConfig()->value<bool>("Z+");
65  z_minus = item()->getConfig()->value<bool>("Z-");
66  enableTimeFilter = item()->getConfig()->value<bool>("EnableTimeFilter");
67 
68  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
69 }
70 
71 void FWCaloClusterProxyBuilder::build(const reco::CaloCluster &iData, unsigned int iIndex, TEveElement &oItemHolder, const FWViewContext *)
72 {
74  {
75  const float time = TimeValueMapHandle->get(iIndex);
76  if (time < timeLowerBound || time > timeUpperBound)
77  return;
78  }
79 
80  std::vector<std::pair<DetId, float>> clusterDetIds = iData.hitsAndFractions();
81 
82  bool h_hex(false);
83  TEveBoxSet *hex_boxset = new TEveBoxSet();
84  if (!heatmap)
85  hex_boxset->UseSingleColor();
86  hex_boxset->SetPickable(true);
87  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
88  hex_boxset->SetAntiFlick(true);
89 
90  bool h_box(false);
91  TEveBoxSet *boxset = new TEveBoxSet();
92  if (!heatmap)
93  boxset->UseSingleColor();
94  boxset->SetPickable(true);
95  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
96  boxset->SetAntiFlick(true);
97 
98  for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
99  it != itEnd; ++it)
100  {
101  const uint8_t type = ((it->first >> 28) & 0xF);
102 
103  const float *corners = item()->getGeom()->getCorners(it->first);
104  if (corners == nullptr)
105  continue;
106 
107  // HGCal
108  if (iData.algo() == 8 || (type >= 8 && type <= 10))
109  {
110 
111  if (heatmap && hitmap.find(it->first) == hitmap.end())
112  continue;
113 
114  const bool z = (it->first >> 25) & 0x1;
115 
116  // discard everything thats not at the side that we are intersted in
117  if (
118  ((z_plus & z_minus) != 1) &&
119  (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
120  continue;
121 
122  const float *parameters = item()->getGeom()->getParameters(it->first);
123  const float *shapes = item()->getGeom()->getShapePars(it->first);
124 
125  if (parameters == nullptr || shapes == nullptr)
126  continue;
127 
128  const int total_points = parameters[0];
129  const bool isScintillator = (total_points == 4);
130 
131  uint8_t ll = layer;
132  if (layer > 0)
133  {
134  if (layer > 28)
135  {
136  if (type == 8)
137  {
138  continue;
139  }
140  ll -= 28;
141  }
142  else
143  {
144  if (type != 8)
145  {
146  continue;
147  }
148  }
149 
150  if (ll != ((it->first >> (isScintillator ? 17 : 20)) & 0x1F))
151  continue;
152  }
153 
154  // seed
155  if (iData.seed().rawId() == it->first.rawId())
156  {
157  TEveStraightLineSet *marker = new TEveStraightLineSet;
158  marker->SetLineWidth(1);
159 
160  // center of RecHit
161  const float center[3] = { corners[total_points*3 + 0], corners[total_points*3+ 1], corners[total_points*3 + 2] + shapes[3] * 0.5f };
162 
163  // draw 3D cross
164  const float crossScale = 1.0f + fmin(iData.energy(), 5.0f);
165  marker->AddLine(
166  center[0] - crossScale, center[1], center[2],
167  center[0] + crossScale, center[1], center[2]);
168  marker->AddLine(
169  center[0], center[1] - crossScale, center[2],
170  center[0], center[1] + crossScale, center[2]);
171  marker->AddLine(
172  center[0], center[1], center[2] - crossScale,
173  center[0], center[1], center[2] + crossScale);
174 
175  oItemHolder.AddElement(marker);
176  }
177 
178  const float energy = fmin((item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap[it->first]->energy() : iData.energy()) / saturation_energy, 1.0f);
179  const uint8_t colorFactor = gradient_steps*energy;
180 
181  // Scintillator
182  if (isScintillator)
183  {
184  const int total_vertices = 3 * total_points;
185 
186  std::vector<float> pnts(24);
187  for (int i = 0; i < total_points; ++i)
188  {
189  pnts[i * 3 + 0] = corners[i * 3];
190  pnts[i * 3 + 1] = corners[i * 3 + 1];
191  pnts[i * 3 + 2] = corners[i * 3 + 2];
192 
193  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
194  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
195  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
196  }
197  boxset->AddBox(&pnts[0]);
198  if (heatmap)
199  {
200  energy ?
201  boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]) :
202  boxset->DigitColor(64, 64, 64);
203  }
204 
205  h_box = true;
206  }
207  // Silicon
208  else
209  {
210  constexpr int offset = 9;
211 
212  float centerX = (corners[6] + corners[6 + offset]) / 2;
213  float centerY = (corners[7] + corners[7 + offset]) / 2;
214  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
215  hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]),
216  radius, 90.0, shapes[3]);
217  if (heatmap)
218  {
219  energy ?
220  hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]) :
221  hex_boxset->DigitColor(64, 64, 64);
222  }
223 
224  h_hex = true;
225  }
226  }
227  // Not HGCal
228  else
229  {
230  h_box = true;
231 
232  std::vector<float> pnts(24);
233  fireworks::energyTower3DCorners(corners, (*it).second, pnts);
234  boxset->AddBox(&pnts[0]);
235  }
236  }
237 
238  if (h_hex)
239  {
240  hex_boxset->RefitPlex();
241 
242  hex_boxset->CSCTakeAnyParentAsMaster();
243  if (!heatmap)
244  {
245  hex_boxset->CSCApplyMainColorToMatchingChildren();
246  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
247  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
248  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
249  }
250  oItemHolder.AddElement(hex_boxset);
251  }
252 
253  if (h_box)
254  {
255  boxset->RefitPlex();
256 
257  boxset->CSCTakeAnyParentAsMaster();
258  if (!heatmap)
259  {
260  boxset->CSCApplyMainColorToMatchingChildren();
261  boxset->CSCApplyMainTransparencyToMatchingChildren();
262  boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
263  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
264  }
265  oItemHolder.AddElement(boxset);
266  }
267 }
268 
edm::Handle< edm::ValueMap< float > > TimeValueMapHandle
type
Definition: HCALResponse.h:21
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:169
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
void setItem(const FWEventItem *iItem) override
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:446
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:197
void setItem(const FWEventItem *iItem) override
const FWEventItem * item() const
AlgoId algo() const
algorithm identifier
Definition: CaloCluster.h:177
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:462
double f[11][100]
double energy() const
cluster energy
Definition: CaloCluster.h:126
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:74
const_reference_type get(ProductID id, size_t idx) const
Definition: ValueMap.h:140
FWGenericParameter< T > * assertParam(const std::string &name, T def)
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:148
void energyTower3DCorners(const float *corners, float scale, std::vector< float > &, bool reflect=false)
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:430
const FWCaloClusterProxyBuilder & operator=(const FWCaloClusterProxyBuilder &)=delete
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:686
#define constexpr