CMS 3D CMS Logo

FWTracksterLayersProxyBuilder.cc
Go to the documentation of this file.
12 
13 #include "TEveBoxSet.h"
14 #include "TGeoSphere.h"
15 #include "TGeoTube.h"
16 #include "TEveGeoShape.h"
17 #include "TEveStraightLineSet.h"
18 
19 #include <cmath>
20 
22 public:
25 
27 
28  FWTracksterLayersProxyBuilder(const FWTracksterLayersProxyBuilder &) = delete; // stop default
29  const FWTracksterLayersProxyBuilder &operator=(const FWTracksterLayersProxyBuilder &) = delete; // stop default
30 
31 private:
35  long layer_;
37  bool heatmap_;
38  bool z_plus_;
39  bool z_minus_;
43  double displayMode_;
45 
46  void setItem(const FWEventItem *iItem) override;
47 
48  void build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) override;
49  void build(const ticl::Trackster &iData,
50  unsigned int iIndex,
51  TEveElement &oItemHolder,
52  const FWViewContext *) override;
53 };
54 
57  if (iItem) {
58  iItem->getConfig()->assertParam("EnablePositionLines", false);
59  iItem->getConfig()->assertParam("EnableEdges", false);
60  iItem->getConfig()->assertParam("EnableTimeFilter", false);
61  iItem->getConfig()->assertParam("TimeLowerBound(ns)", 0.01, 0.0, 75.0);
62  iItem->getConfig()->assertParam("TimeUpperBound(ns)", 0.01, 0.0, 75.0);
63  iItem->getConfig()->assertParam("DisplayMode", 0.0, 0.0, 5.0);
64  iItem->getConfig()->assertParam("ProportionalityFactor", 1.0, 0.0, 1.0);
65  }
66 }
67 
68 void FWTracksterLayersProxyBuilder::build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) {
69  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
70  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters"), layerClustersHandle_);
72  timeLowerBound_ = item()->getConfig()->value<double>("TimeLowerBound(ns)");
73  timeUpperBound_ = item()->getConfig()->value<double>("TimeUpperBound(ns)");
75  edm::LogWarning("InvalidParameters")
76  << "lower time bound is larger than upper time bound. Maybe opposite is desired?";
77  }
78  } else {
79  edm::LogWarning("DataNotFound|InvalidData") << "couldn't locate 'timeLayerCluster' ValueMap in root file.";
80  }
81 
83  edm::LogWarning("DataNotFound|InvalidData") << "couldn't locate 'timeLayerCluster' ValueMap in root file.";
84  }
85 
86  layer_ = item()->getConfig()->value<long>("Layer");
87  saturation_energy_ = item()->getConfig()->value<double>("EnergyCutOff");
88  heatmap_ = item()->getConfig()->value<bool>("Heatmap");
89  z_plus_ = item()->getConfig()->value<bool>("Z+");
90  z_minus_ = item()->getConfig()->value<bool>("Z-");
91  enableTimeFilter_ = item()->getConfig()->value<bool>("EnableTimeFilter");
92  enablePositionLines_ = item()->getConfig()->value<bool>("EnablePositionLines");
93  enableEdges_ = item()->getConfig()->value<bool>("EnableEdges");
94  displayMode_ = item()->getConfig()->value<double>("DisplayMode");
95  proportionalityFactor_ = item()->getConfig()->value<double>("ProportionalityFactor");
96 
97  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
98 }
99 
101  unsigned int iIndex,
102  TEveElement &oItemHolder,
103  const FWViewContext *) {
105  const float time = TimeValueMapHandle_->get(iIndex).first;
106  if (time < timeLowerBound_ || time > timeUpperBound_)
107  return;
108  }
109 
110  const ticl::Trackster &trackster = iData;
111  const size_t N = trackster.vertices().size();
112  const std::vector<reco::CaloCluster> &layerClusters = *layerClustersHandle_;
113  TEveStraightLineSet *position_marker = nullptr;
114 
115  if (enablePositionLines_) {
116  position_marker = new TEveStraightLineSet;
117  position_marker->SetLineWidth(2);
118  position_marker->SetLineColor(kWhite);
119  }
120 
121  for (size_t i = 0; i < N; ++i) {
122  const reco::CaloCluster layerCluster = layerClusters[trackster.vertices(i)];
123  const math::XYZPoint &position = layerCluster.position();
124  const size_t nHits = layerCluster.size();
125  const double energy = layerCluster.energy();
126  float radius = 0;
127  auto detIdOnLayer = layerCluster.seed();
128 
129  const auto *parameters = item()->getGeom()->getParameters(detIdOnLayer);
130  const int layer = parameters[1];
131  const int zside = parameters[2];
132  const bool isSilicon = parameters[3];
133 
134  auto const z_selection_is_on = z_plus_ ^ z_minus_;
135  auto const z_plus_selection_ok = z_plus_ && (zside == 1);
136  auto const z_minus_selection_ok = z_minus_ && (zside == -1);
137  if (!z_minus_ && !z_plus_)
138  continue;
139  if (z_selection_is_on && !(z_plus_selection_ok || z_minus_selection_ok))
140  continue;
141 
142  if (layer_ > 0 && (layer != layer_))
143  continue;
144 
145  if (displayMode_ == 0) {
146  radius = sqrt(nHits);
147  } else if (displayMode_ == 1) {
148  radius = nHits;
149  } else if (displayMode_ == 2) {
150  radius = energy;
151  } else if (displayMode_ == 3) {
152  radius = energy / nHits;
153  } else if (displayMode_ == 4) {
154  float area = 0;
155  if (!isSilicon) {
156  const bool isFine = (HGCScintillatorDetId(layerCluster.seed()).type() == 0);
157  float dphi = (isFine) ? 1.0 * M_PI / 180. : 1.25 * M_PI / 180.;
158  int ir = HGCScintillatorDetId(layerCluster.seed()).iradiusAbs();
159  float dr = (isFine) ? (0.0484 * static_cast<float>(ir) + 2.1) : (0.075 * static_cast<float>(ir) + 2.0);
160  float r = (isFine) ? (0.0239 * static_cast<float>(pow(ir, 2)) + 2.02 * static_cast<float>(ir) + 119.6)
161  : (0.0367 * static_cast<float>(pow(ir, 2)) + 1.7 * static_cast<float>(ir) + 90.7);
162  area = r * dr * dphi;
163  } else {
164  const bool isFine = (HGCSiliconDetId(layerCluster.seed()).type() == 0);
165  float side = (isFine) ? 0.465 : 0.698;
166  area = pow(side, 2) * 3 * sqrt(3) / 2;
167  }
168  radius = sqrt(nHits * area) / M_PI;
169  }
170 
171  auto *eveCircle = new TEveGeoShape("Circle");
172  auto tube = new TGeoTube(0., proportionalityFactor_ * radius, 0.1);
173  eveCircle->SetShape(tube);
174  eveCircle->InitMainTrans();
175  eveCircle->RefMainTrans().Move3PF(position.x(), position.y(), position.z());
176  setupAddElement(eveCircle, &oItemHolder);
177  // Apply heatmap color coding **after** the call to setupAddElement, that will internally setup the color.
178  if (heatmap_) {
179  const float normalized_energy = fmin(energy / saturation_energy_, 1.0f);
180  const uint8_t colorFactor = gradient_steps * normalized_energy;
181  eveCircle->SetFillColor(
182  TColor::GetColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]));
183  } else {
184  eveCircle->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
185  eveCircle->SetMainTransparency(item()->defaultDisplayProperties().transparency());
186  }
187 
188  // seed and cluster position
189  const float crossScale = 1.0f + fmin(energy, 5.0f);
190  if (enablePositionLines_) {
191  auto const &pos = layerCluster.position();
192  const float position_crossScale = crossScale * 0.5;
193  position_marker->AddLine(
194  pos.x() - position_crossScale, pos.y(), pos.z(), pos.x() + position_crossScale, pos.y(), pos.z());
195  position_marker->AddLine(
196  pos.x(), pos.y() - position_crossScale, pos.z(), pos.x(), pos.y() + position_crossScale, pos.z());
197  }
198  }
199 
201  oItemHolder.AddElement(position_marker);
202 
203  if (enableEdges_) {
204  auto &edges = trackster.edges();
205 
206  TEveStraightLineSet *adjacent_marker = new TEveStraightLineSet;
207  adjacent_marker->SetLineWidth(2);
208  adjacent_marker->SetLineColor(kYellow);
209 
210  TEveStraightLineSet *non_adjacent_marker = new TEveStraightLineSet;
211  non_adjacent_marker->SetLineWidth(2);
212  non_adjacent_marker->SetLineColor(kRed);
213 
214  for (auto edge : edges) {
215  auto doublet = std::make_pair(layerClusters[edge[0]], layerClusters[edge[1]]);
216 
217  int layerIn = item()->getGeom()->getParameters(doublet.first.seed())[1];
218  int layerOut = item()->getGeom()->getParameters(doublet.second.seed())[1];
219 
220  const bool isAdjacent = std::abs(layerOut - layerIn) == 1;
221 
222  // draw 3D cross
223  if (layer_ == 0 || fabs(layerIn - layer_) == 0 || fabs(layerOut - layer_) == 0) {
224  if (isAdjacent)
225  adjacent_marker->AddLine(doublet.first.x(),
226  doublet.first.y(),
227  doublet.first.z(),
228  doublet.second.x(),
229  doublet.second.y(),
230  doublet.second.z());
231  else
232  non_adjacent_marker->AddLine(doublet.first.x(),
233  doublet.first.y(),
234  doublet.first.z(),
235  doublet.second.x(),
236  doublet.second.y(),
237  doublet.second.z());
238  }
239  }
240  oItemHolder.AddElement(adjacent_marker);
241  oItemHolder.AddElement(non_adjacent_marker);
242  }
243 }
244 
edm::Handle< std::vector< reco::CaloCluster > > layerClustersHandle_
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
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:144
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
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:59
void setItem(const FWEventItem *iItem) override
const FWTracksterLayersProxyBuilder & operator=(const FWTracksterLayersProxyBuilder &)=delete
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:187
static constexpr uint8_t gradient[3][gradient_steps]
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:131
#define M_PI
FWGenericParameter< T > * assertParam(const std::string &name, T def)
double energy() const
cluster energy
Definition: CaloCluster.h:149
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
#define N
Definition: blowfish.cc:9
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
bool isValid() const
Definition: HandleBase.h:70
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:450
static int position[264][3]
Definition: ReadPGInfo.cc:289
Log< level::Warning, false > LogWarning
edm::Handle< edm::ValueMap< std::pair< float, float > > > TimeValueMapHandle_
const FWEventItem * item() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29