CMS 3D CMS Logo

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