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 private:
27  long layer;
29  bool heatmap;
30  bool z_plus;
31  bool z_minus;
36 
37  FWTracksterHitsProxyBuilder(const FWTracksterHitsProxyBuilder &) = delete; // stop default
38  const FWTracksterHitsProxyBuilder &operator=(const FWTracksterHitsProxyBuilder &) = delete; // stop default
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  edm::LogWarning("DataNotFound|InvalidData") << "couldn't locate 'timeLayerCluster' ValueMap in root file.";
74  }
75 
77  edm::LogWarning("DataNotFound|InvalidData") << "couldn't locate 'timeLayerCluster' ValueMap in root file.";
78  }
79 
80  layer = item()->getConfig()->value<long>("Layer");
81  saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
82  heatmap = item()->getConfig()->value<bool>("Heatmap");
83  z_plus = item()->getConfig()->value<bool>("Z+");
84  z_minus = item()->getConfig()->value<bool>("Z-");
85  enableTimeFilter = item()->getConfig()->value<bool>("EnableTimeFilter");
86  enableSeedLines = item()->getConfig()->value<bool>("EnableSeedLines");
87  enablePositionLines = item()->getConfig()->value<bool>("EnablePositionLines");
88  enableEdges = item()->getConfig()->value<bool>("EnableEdges");
89 
90  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
91 }
92 
94  unsigned int iIndex,
95  TEveElement &oItemHolder,
96  const FWViewContext *) {
98  const float time = TimeValueMapHandle->get(iIndex).first;
99  if (time < timeLowerBound || time > timeUpperBound)
100  return;
101  }
102 
103  const ticl::Trackster &trackster = iData;
104  const size_t N = trackster.vertices().size();
105  const std::vector<reco::CaloCluster> &layerClusters = *layerClustersHandle;
106 
107  bool h_hex(false);
108  TEveBoxSet *hex_boxset = new TEveBoxSet();
109  if (!heatmap)
110  hex_boxset->UseSingleColor();
111  hex_boxset->SetPickable(true);
112  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
113  hex_boxset->SetAntiFlick(true);
114 
115  bool h_box(false);
116  TEveBoxSet *boxset = new TEveBoxSet();
117  if (!heatmap)
118  boxset->UseSingleColor();
119  boxset->SetPickable(true);
120  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
121  boxset->SetAntiFlick(true);
122 
123  for (size_t i = 0; i < N; ++i) {
124  const reco::CaloCluster layerCluster = layerClusters[trackster.vertices(i)];
125  std::vector<std::pair<DetId, float>> clusterDetIds = layerCluster.hitsAndFractions();
126 
127  for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
128  it != itEnd;
129  ++it) {
130  const uint8_t type = ((it->first >> 28) & 0xF);
131 
132  const float *corners = item()->getGeom()->getCorners(it->first);
133  if (corners == nullptr)
134  continue;
135 
136  if (heatmap && hitmap->find(it->first) == hitmap->end())
137  continue;
138 
139  const bool z = (it->first >> 25) & 0x1;
140 
141  // discard everything thats not at the side that we are intersted in
142  if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
143  continue;
144 
145  const float *parameters = item()->getGeom()->getParameters(it->first);
146  const float *shapes = item()->getGeom()->getShapePars(it->first);
147 
148  if (parameters == nullptr || shapes == nullptr)
149  continue;
150 
151  const int total_points = parameters[0];
152  const bool isScintillator = (total_points == 4);
153 
154  uint8_t ll = layer;
155  if (layer > 0) {
156  if (layer > 28) {
157  if (type == 8) {
158  continue;
159  }
160  ll -= 28;
161  } else {
162  if (type != 8) {
163  continue;
164  }
165  }
166 
167  if (ll != ((it->first >> (isScintillator ? 17 : 20)) & 0x1F))
168  continue;
169  }
170 
171  // seed and cluster position
172  if (layerCluster.seed().rawId() == it->first.rawId()) {
173  const float crossScale = 1.0f + fmin(layerCluster.energy(), 5.0f);
174  if (enableSeedLines) {
175  TEveStraightLineSet *marker = new TEveStraightLineSet;
176  marker->SetLineWidth(1);
177 
178  // center of RecHit
179  const float center[3] = {corners[total_points * 3 + 0],
180  corners[total_points * 3 + 1],
181  corners[total_points * 3 + 2] + shapes[3] * 0.5f};
182 
183  // draw 3D cross
184  marker->AddLine(center[0] - crossScale, center[1], center[2], center[0] + crossScale, center[1], center[2]);
185  marker->AddLine(center[0], center[1] - crossScale, center[2], center[0], center[1] + crossScale, center[2]);
186  marker->AddLine(center[0], center[1], center[2] - crossScale, center[0], center[1], center[2] + crossScale);
187 
188  oItemHolder.AddElement(marker);
189  }
190 
191  if (enablePositionLines) {
192  TEveStraightLineSet *position_marker = new TEveStraightLineSet;
193  position_marker->SetLineWidth(2);
194  position_marker->SetLineColor(kOrange);
195  auto const &pos = layerCluster.position();
196  const float position_crossScale = crossScale * 0.5;
197  position_marker->AddLine(
198  pos.x() - position_crossScale, pos.y(), pos.z(), pos.x() + position_crossScale, pos.y(), pos.z());
199  position_marker->AddLine(
200  pos.x(), pos.y() - position_crossScale, pos.z(), pos.x(), pos.y() + position_crossScale, pos.z());
201 
202  oItemHolder.AddElement(position_marker);
203  }
204  }
205 
206  const float energy =
207  fmin((item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap->at(it->first)->energy()
208  : layerCluster.energy()) /
210  1.0f);
211  const uint8_t colorFactor = gradient_steps * energy;
212 
213  // Scintillator
214  if (isScintillator) {
215  const int total_vertices = 3 * total_points;
216 
217  std::vector<float> pnts(24);
218  for (int i = 0; i < total_points; ++i) {
219  pnts[i * 3 + 0] = corners[i * 3];
220  pnts[i * 3 + 1] = corners[i * 3 + 1];
221  pnts[i * 3 + 2] = corners[i * 3 + 2];
222 
223  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
224  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
225  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
226  }
227  boxset->AddBox(&pnts[0]);
228  if (heatmap) {
229  energy ? boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor])
230  : boxset->DigitColor(64, 64, 64);
231  }
232 
233  h_box = true;
234  }
235  // Silicon
236  else {
237  constexpr int offset = 9;
238 
239  float centerX = (corners[6] + corners[6 + offset]) / 2;
240  float centerY = (corners[7] + corners[7 + offset]) / 2;
241  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
242  hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, 90.0, shapes[3]);
243  if (heatmap) {
244  energy ? hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor])
245  : hex_boxset->DigitColor(64, 64, 64);
246  }
247 
248  h_hex = true;
249  }
250  }
251  }
252 
253  if (enableEdges) {
254  auto &edges = trackster.edges();
255 
256  for (auto edge : edges) {
257  auto doublet = std::make_pair(layerClusters[edge[0]], layerClusters[edge[1]]);
258 
259  const bool isScintillatorIn = doublet.first.seed().det() == DetId::HGCalHSc;
260  const bool isScintillatorOut = doublet.second.seed().det() == DetId::HGCalHSc;
261  int layerIn = (isScintillatorIn) ? (HGCScintillatorDetId(doublet.first.seed()).layer())
262  : (HGCSiliconDetId(doublet.first.seed()).layer());
263  int layerOut = (isScintillatorOut) ? (HGCScintillatorDetId(doublet.second.seed()).layer())
264  : (HGCSiliconDetId(doublet.second.seed()).layer());
265 
266  // Check if offset is needed
267  const int offset = 28;
268  const int offsetIn = offset * (doublet.first.seed().det() != DetId::HGCalEE);
269  const int offsetOut = offset * (doublet.second.seed().det() != DetId::HGCalEE);
270  layerIn += offsetIn;
271  layerOut += offsetOut;
272 
273  const bool isAdjacent = (layerOut - layerIn) == 1;
274 
275  TEveStraightLineSet *marker = new TEveStraightLineSet;
276  marker->SetLineWidth(2);
277  if (isAdjacent) {
278  marker->SetLineColor(kYellow);
279  } else {
280  marker->SetLineColor(kRed);
281  }
282 
283  // draw 3D cross
284  if (layer == 0 || fabs(layerIn - layer) == 0 || fabs(layerOut - layer) == 0) {
285  marker->AddLine(doublet.first.x(),
286  doublet.first.y(),
287  doublet.first.z(),
288  doublet.second.x(),
289  doublet.second.y(),
290  doublet.second.z());
291  }
292 
293  oItemHolder.AddElement(marker);
294  }
295  }
296 
297  if (h_hex) {
298  hex_boxset->RefitPlex();
299 
300  hex_boxset->CSCTakeAnyParentAsMaster();
301  if (!heatmap) {
302  hex_boxset->CSCApplyMainColorToMatchingChildren();
303  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
304  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
305  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
306  }
307  oItemHolder.AddElement(hex_boxset);
308  }
309 
310  if (h_box) {
311  boxset->RefitPlex();
312 
313  boxset->CSCTakeAnyParentAsMaster();
314  if (!heatmap) {
315  boxset->CSCApplyMainColorToMatchingChildren();
316  boxset->CSCApplyMainTransparencyToMatchingChildren();
317  boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
318  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
319  }
320  oItemHolder.AddElement(boxset);
321  }
322 }
323 
FWTracksterHitsProxyBuilder::z_minus
bool z_minus
Definition: FWTracksterHitsProxyBuilder.cc:31
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
FWTracksterHitsProxyBuilder::layer
long layer
Definition: FWTracksterHitsProxyBuilder.cc:27
mps_fire.i
i
Definition: mps_fire.py:428
FWHeatmapProxyBuilderTemplate::setItem
void setItem(const FWEventItem *iItem) override
Definition: FWHeatmapProxyBuilderTemplate.h:82
FWTracksterHitsProxyBuilder::~FWTracksterHitsProxyBuilder
~FWTracksterHitsProxyBuilder(void) override
Definition: FWTracksterHitsProxyBuilder.cc:19
MessageLogger.h
Trackster.h
FWGeometry::getCorners
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:467
HGCScintillatorDetId.h
edm::EventBase::getByLabel
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
FWEventItem::getConfig
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWHeatmapProxyBuilderTemplate< ticl::Trackster >::gradient_steps
static constexpr uint8_t gradient_steps
Definition: FWHeatmapProxyBuilderTemplate.h:49
REGISTER_FWPROXYBUILDER
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
Definition: FWProxyBuilderFactory.h:33
FWTracksterHitsProxyBuilder::enableTimeFilter
bool enableTimeFilter
Definition: FWTracksterHitsProxyBuilder.cc:32
FWTracksterHitsProxyBuilder
Definition: FWTracksterHitsProxyBuilder.cc:16
pos
Definition: PixelAliasList.h:18
HGCSiliconDetId.h
REGISTER_PROXYBUILDER_METHODS
#define REGISTER_PROXYBUILDER_METHODS()
Definition: register_dataproxybuilder_macro.h:27
FWGeometry::getShapePars
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:489
protons_cff.time
time
Definition: protons_cff.py:35
FWTracksterHitsProxyBuilder::enablePositionLines
bool enablePositionLines
Definition: FWTracksterHitsProxyBuilder.cc:34
FWTracksterHitsProxyBuilder::enableSeedLines
bool enableSeedLines
Definition: FWTracksterHitsProxyBuilder.cc:33
BuilderUtils.h
FWTracksterHitsProxyBuilder::heatmap
bool heatmap
Definition: FWTracksterHitsProxyBuilder.cc:29
FWTracksterHitsProxyBuilder::operator=
const FWTracksterHitsProxyBuilder & operator=(const FWTracksterHitsProxyBuilder &)=delete
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HGCSiliconDetId
Definition: HGCSiliconDetId.h:22
FWTracksterHitsProxyBuilder::TimeValueMapHandle
edm::Handle< edm::ValueMap< std::pair< float, float > > > TimeValueMapHandle
Definition: FWTracksterHitsProxyBuilder.cc:24
FWTracksterHitsProxyBuilder::timeLowerBound
double timeLowerBound
Definition: FWTracksterHitsProxyBuilder.cc:26
DetId::HGCalEE
Definition: DetId.h:32
FWGeometry::getParameters
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:478
FWProxyBuilderBase::layer
int layer() const
Definition: FWProxyBuilderBase.cc:414
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
FWTracksterHitsProxyBuilder::layerClustersHandle
edm::Handle< std::vector< reco::CaloCluster > > layerClustersHandle
Definition: FWTracksterHitsProxyBuilder.cc:25
reco::CaloCluster
Definition: CaloCluster.h:31
DDAxes::z
N
#define N
Definition: blowfish.cc:9
ticl::Trackster::edges
std::vector< std::array< unsigned int, 2 > > & edges()
Definition: Trackster.h:58
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HLTEgPhaseIITestSequence_cff.layerClusters
layerClusters
Definition: HLTEgPhaseIITestSequence_cff.py:2506
FWProxyBuilderConfiguration::assertParam
FWGenericParameter< T > * assertParam(const std::string &name, T def)
Definition: FWProxyBuilderConfiguration.cc:83
FWEventItem::getEvent
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:131
FWHeatmapProxyBuilderTemplate< ticl::Trackster >::gradient
static constexpr uint8_t gradient[3][gradient_steps]
Definition: FWHeatmapProxyBuilderTemplate.h:50
FWGeometry.h
FWTracksterHitsProxyBuilder::FWTracksterHitsProxyBuilder
FWTracksterHitsProxyBuilder(void)
Definition: FWTracksterHitsProxyBuilder.cc:18
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
FWTracksterHitsProxyBuilder::z_plus
bool z_plus
Definition: FWTracksterHitsProxyBuilder.cc:30
FWTracksterHitsProxyBuilder::enableEdges
bool enableEdges
Definition: FWTracksterHitsProxyBuilder.cc:35
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
FWProxyBuilderBase::build
void build()
Definition: FWProxyBuilderBase.cc:110
SelectiveReadoutTask_cfi.edges
edges
Definition: SelectiveReadoutTask_cfi.py:107
reco::CaloCluster::seed
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
FWEventItem.h
FWViewContext
Definition: FWViewContext.h:32
reco::CaloCluster::position
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
ValueMap.h
FWEventItem::getGeom
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
FWProxyBuilderBase::item
const FWEventItem * item() const
Definition: FWProxyBuilderBase.h:64
edm::ValueMap::get
const_reference_type get(ProductID id, size_t idx) const
Definition: ValueMap.h:144
FWHeatmapProxyBuilderTemplate
Definition: FWHeatmapProxyBuilderTemplate.h:34
FWEventItem
Definition: FWEventItem.h:56
FWViewType::kISpyBit
Definition: FWViewType.h:54
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
FWProxyBuilderConfiguration::value
T value(const std::string &name)
Definition: FWProxyBuilderConfiguration.cc:123
DetId.h
HGCScintillatorDetId
Definition: HGCScintillatorDetId.h:23
DetId::HGCalHSc
Definition: DetId.h:34
ticl::Trackster::vertices
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
FWTracksterHitsProxyBuilder::timeUpperBound
double timeUpperBound
Definition: FWTracksterHitsProxyBuilder.cc:26
FWTracksterHitsProxyBuilder::saturation_energy
double saturation_energy
Definition: FWTracksterHitsProxyBuilder.cc:28
FWHeatmapProxyBuilderTemplate.h
FWHeatmapProxyBuilderTemplate< ticl::Trackster >::hitmap
std::unordered_map< DetId, const HGCRecHit * > * hitmap
Definition: FWHeatmapProxyBuilderTemplate.h:47
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
edm::InputTag
Definition: InputTag.h:15
ticl::Trackster
Definition: Trackster.h:19
FWTracksterHitsProxyBuilder::setItem
void setItem(const FWEventItem *iItem) override
Definition: FWTracksterHitsProxyBuilder.cc:49
CaloCluster.h