CMS 3D CMS Logo

FWTracksterHitsProxyBuilder.cc
Go to the documentation of this file.
12 
13 #include "TEveBoxSet.h"
14 #include "TEveStraightLineSet.h"
15 
17 public:
19  ~FWTracksterHitsProxyBuilder(void) override {}
20 
22 
23  FWTracksterHitsProxyBuilder(const FWTracksterHitsProxyBuilder &) = delete; // stop default
24  const FWTracksterHitsProxyBuilder &operator=(const FWTracksterHitsProxyBuilder &) = delete; // stop default
25 
26 private:
30  long layer_;
32  bool heatmap_;
33  bool z_plus_;
34  bool z_minus_;
39 
40  void setItem(const FWEventItem *iItem) override;
41 
42  void build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) override;
43  void build(const ticl::Trackster &iData,
44  unsigned int iIndex,
45  TEveElement &oItemHolder,
46  const FWViewContext *) override;
47 };
48 
51  if (iItem) {
52  iItem->getConfig()->assertParam("Cluster(0)/RecHit(1)", false);
53  iItem->getConfig()->assertParam("EnableSeedLines", false);
54  iItem->getConfig()->assertParam("EnablePositionLines", false);
55  iItem->getConfig()->assertParam("EnableEdges", false);
56  iItem->getConfig()->assertParam("EnableTimeFilter", false);
57  iItem->getConfig()->assertParam("TimeLowerBound(ns)", 0.01, 0.0, 75.0);
58  iItem->getConfig()->assertParam("TimeUpperBound(ns)", 0.01, 0.0, 75.0);
59  }
60 }
61 
62 void FWTracksterHitsProxyBuilder::build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) {
63  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
64  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters"), layerClustersHandle_);
66  timeLowerBound_ = item()->getConfig()->value<double>("TimeLowerBound(ns)");
67  timeUpperBound_ = item()->getConfig()->value<double>("TimeUpperBound(ns)");
69  edm::LogWarning("InvalidParameters")
70  << "lower time bound is larger than upper time bound. Maybe opposite is desired?";
71  }
72  } else {
73  iItem->getEvent()->getByLabel(edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
74  edm::LogWarning("DataNotFound|InvalidData")
75  << __FILE__ << ":" << __LINE__
76  << " couldn't locate 'hgcalLayerClusters:timeLayerCluster' ValueMap in input file. Trying to access "
77  "'hgcalMergeLayerClusters:timeLayerClusters' ValueMap";
79  edm::LogWarning("DataNotFound|InvalidData")
80  << __FILE__ << ":" << __LINE__
81  << " couldn't locate 'hgcalMergeLayerClusters:timeLayerCluster' ValueMap in input file.";
82  }
83  }
84 
86  iItem->getEvent()->getByLabel(edm::InputTag("hgcalMergeLayerClusters"), layerClustersHandle_);
87  edm::LogWarning("DataNotFound|InvalidData")
88  << __FILE__ << ":" << __LINE__
89  << " couldn't locate 'hgcalLayerClusters' collection "
90  "in input file. Trying to access 'hgcalMergeLayerClusters' collection.";
92  edm::LogWarning("DataNotFound|InvalidData")
93  << __FILE__ << ":" << __LINE__ << " couldn't locate 'hgcalMergeLayerClusters' collection in input file.";
94  }
95  }
96 
97  layer_ = item()->getConfig()->value<long>("Layer");
98  saturation_energy_ = item()->getConfig()->value<double>("EnergyCutOff");
99  heatmap_ = item()->getConfig()->value<bool>("Heatmap");
100  z_plus_ = item()->getConfig()->value<bool>("Z+");
101  z_minus_ = item()->getConfig()->value<bool>("Z-");
102  enableTimeFilter_ = item()->getConfig()->value<bool>("EnableTimeFilter");
103  enableSeedLines_ = item()->getConfig()->value<bool>("EnableSeedLines");
104  enablePositionLines_ = item()->getConfig()->value<bool>("EnablePositionLines");
105  enableEdges_ = item()->getConfig()->value<bool>("EnableEdges");
106 
107  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
108 }
109 
111  unsigned int iIndex,
112  TEveElement &oItemHolder,
113  const FWViewContext *) {
115  const float time = TimeValueMapHandle_->get(iIndex).first;
116  if (time < timeLowerBound_ || time > timeUpperBound_)
117  return;
118  }
119 
120  const ticl::Trackster &trackster = iData;
121  const size_t N = trackster.vertices().size();
122  const std::vector<reco::CaloCluster> &layerClusters = *layerClustersHandle_;
123 
124  TEveBoxSet *hex_boxset = new TEveBoxSet();
125  if (!heatmap_)
126  hex_boxset->UseSingleColor();
127  hex_boxset->SetPickable(true);
128  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
129 
130  TEveBoxSet *boxset = new TEveBoxSet();
131  if (!heatmap_)
132  boxset->UseSingleColor();
133  boxset->SetPickable(true);
134  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
135 
136  TEveStraightLineSet *seed_marker = nullptr;
137  if (enableSeedLines_) {
138  seed_marker = new TEveStraightLineSet("seeds");
139  seed_marker->SetLineWidth(2);
140  seed_marker->SetLineColor(kOrange + 10);
141  seed_marker->GetLinePlex().Reset(sizeof(TEveStraightLineSet::Line_t), 2 * N);
142  }
143 
144  TEveStraightLineSet *position_marker = nullptr;
145  if (enablePositionLines_) {
146  position_marker = new TEveStraightLineSet("positions");
147  position_marker->SetLineWidth(2);
148  position_marker->SetLineColor(kOrange);
149  position_marker->GetLinePlex().Reset(sizeof(TEveStraightLineSet::Line_t), 2 * N);
150  }
151 
152  for (size_t i = 0; i < N; ++i) {
153  const reco::CaloCluster layerCluster = layerClusters[trackster.vertices(i)];
154  std::vector<std::pair<DetId, float>> clusterDetIds = layerCluster.hitsAndFractions();
155 
156  for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
157  it != itEnd;
158  ++it) {
159  const float *corners = item()->getGeom()->getCorners(it->first);
160  if (corners == nullptr)
161  continue;
162 
163  if (heatmap_ && hitmap->find(it->first) == hitmap->end())
164  continue;
165 
166  const float *parameters = item()->getGeom()->getParameters(it->first);
167  const float *shapes = item()->getGeom()->getShapePars(it->first);
168 
169  if (parameters == nullptr || shapes == nullptr)
170  continue;
171 
172  const int total_points = parameters[0];
173  const int layer = parameters[1];
174  const int zside = parameters[2];
175  const bool isSilicon = parameters[3];
176 
177  // discard everything that's not at the side that we are intersted in
178  auto const z_selection_is_on = z_plus_ ^ z_minus_;
179  auto const z_plus_selection_ok = z_plus_ && (zside == 1);
180  auto const z_minus_selection_ok = z_minus_ && (zside == -1);
181  if (!z_minus_ && !z_plus_)
182  break;
183  if (z_selection_is_on && !(z_plus_selection_ok || z_minus_selection_ok))
184  break;
185 
186  if (layer_ > 0 && layer != layer_)
187  break;
188 
189  // seed and cluster position
190  if (layerCluster.seed().rawId() == it->first.rawId()) {
191  const float crossScale = 0.2f + fmin(layerCluster.energy(), 5.0f);
192  if (enableSeedLines_) {
193  // center of RecHit
194  const float center[3] = {corners[total_points * 3 + 0],
195  corners[total_points * 3 + 1],
196  corners[total_points * 3 + 2] + shapes[3] * 0.5f};
197 
198  // draw 3D cross
199  seed_marker->AddLine(
200  center[0] - crossScale, center[1], center[2], center[0] + crossScale, center[1], center[2]);
201  seed_marker->AddLine(
202  center[0], center[1] - crossScale, center[2], center[0], center[1] + crossScale, center[2]);
203  }
204 
205  if (enablePositionLines_) {
206  auto const &pos = layerCluster.position();
207  const float position_crossScale = crossScale * 0.5;
208  position_marker->AddLine(
209  pos.x() - position_crossScale, pos.y(), pos.z(), pos.x() + position_crossScale, pos.y(), pos.z());
210  position_marker->AddLine(
211  pos.x(), pos.y() - position_crossScale, pos.z(), pos.x(), pos.y() + position_crossScale, pos.z());
212  }
213  }
214 
215  const float energy =
216  fmin((item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap->at(it->first)->energy()
217  : layerCluster.energy()) /
219  1.0f);
220  const uint8_t colorFactor = gradient_steps * energy;
221  auto transparency = item()->modelInfo(iIndex).displayProperties().transparency();
222  UChar_t alpha = (255 * (100 - transparency)) / 100;
223 
224  // Scintillator
225  if (!isSilicon) {
226  const int total_vertices = 3 * total_points;
227 
228  std::vector<float> pnts(24);
229  for (int i = 0; i < total_points; ++i) {
230  pnts[i * 3 + 0] = corners[i * 3];
231  pnts[i * 3 + 1] = corners[i * 3 + 1];
232  pnts[i * 3 + 2] = corners[i * 3 + 2];
233 
234  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
235  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
236  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
237  }
238  boxset->AddBox(&pnts[0]);
239  if (heatmap_) {
240  energy
241  ? boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor], alpha)
242  : boxset->DigitColor(64, 64, 64, alpha);
243  }
244  }
245  // Silicon
246  else {
247  constexpr int offset = 9;
248 
249  float centerX = (corners[6] + corners[6 + offset]) / 2;
250  float centerY = (corners[7] + corners[7 + offset]) / 2;
251  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
252  hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, shapes[2], shapes[3]);
253  if (heatmap_) {
254  energy ? hex_boxset->DigitColor(
255  gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor], alpha)
256  : hex_boxset->DigitColor(64, 64, 64, alpha);
257  } else {
258  hex_boxset->CSCApplyMainColorToMatchingChildren();
259  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
260  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
261  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
262  }
263  }
264  } // End of loop over rechits of a single layercluster
265  } // End loop over the layerclusters of the trackster
266 
267  hex_boxset->RefitPlex();
268  boxset->RefitPlex();
269  setupAddElement(hex_boxset, &oItemHolder);
270  setupAddElement(boxset, &oItemHolder);
271 
272  if (enableSeedLines_)
273  oItemHolder.AddElement(seed_marker);
274 
276  oItemHolder.AddElement(position_marker);
277 
278  if (enableEdges_) {
279  auto &edges = trackster.edges();
280 
281  TEveStraightLineSet *adjacent_marker = new TEveStraightLineSet("adj_edges");
282  adjacent_marker->SetLineWidth(2);
283  adjacent_marker->SetLineColor(kYellow);
284  adjacent_marker->GetLinePlex().Reset(sizeof(TEveStraightLineSet::Line_t), edges.size());
285 
286  TEveStraightLineSet *non_adjacent_marker = new TEveStraightLineSet("non_adj_edges");
287  non_adjacent_marker->SetLineWidth(2);
288  non_adjacent_marker->SetLineColor(kRed);
289  non_adjacent_marker->GetLinePlex().Reset(sizeof(TEveStraightLineSet::Line_t), edges.size());
290 
291  for (auto edge : edges) {
292  auto doublet = std::make_pair(layerClusters[edge[0]], layerClusters[edge[1]]);
293 
294  int layerIn = item()->getGeom()->getParameters(doublet.first.seed())[1];
295  int layerOut = item()->getGeom()->getParameters(doublet.second.seed())[1];
296 
297  const bool isAdjacent = std::abs(layerOut - layerIn) == 1;
298 
299  // draw 3D cross
300  if (layer_ == 0 || std::abs(layerIn - layer_) == 0 || std::abs(layerOut - layer_) == 0) {
301  if (isAdjacent)
302  adjacent_marker->AddLine(doublet.first.x(),
303  doublet.first.y(),
304  doublet.first.z(),
305  doublet.second.x(),
306  doublet.second.y(),
307  doublet.second.z());
308  else
309  non_adjacent_marker->AddLine(doublet.first.x(),
310  doublet.first.y(),
311  doublet.first.z(),
312  doublet.second.x(),
313  doublet.second.y(),
314  doublet.second.z());
315  }
316  } // End of loop over all edges of the trackster
317  oItemHolder.AddElement(adjacent_marker);
318  oItemHolder.AddElement(non_adjacent_marker);
319  }
320 }
321 
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
void setItem(const FWEventItem *iItem) override
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
const_reference_type get(ProductID id, size_t idx) const
Definition: ValueMap.h:138
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:218
Char_t transparency() const
edm::Handle< edm::ValueMap< std::pair< float, float > > > TimeValueMapHandle_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:97
int zside(DetId const &)
std::vector< std::array< unsigned int, 2 > > & edges()
Definition: Trackster.h:58
edm::Handle< std::vector< reco::CaloCluster > > layerClustersHandle_
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:64
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:439
void setItem(const FWEventItem *iItem) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
#define N
Definition: blowfish.cc:9
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:461
bool isValid() const
Definition: HandleBase.h:70
const FWTracksterHitsProxyBuilder & operator=(const FWTracksterHitsProxyBuilder &)=delete
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:450
Log< level::Warning, false > LogWarning
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
const FWEventItem * item() const
std::unordered_map< DetId, const HGCRecHit *> * hitmap