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  iItem->getEvent()->getByLabel(edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
80  edm::LogWarning("DataNotFound|InvalidData")
81  << __FILE__ << ":" << __LINE__
82  << " couldn't locate 'hgcalLayerClusters:timeLayerCluster' ValueMap in input file. Trying to access "
83  "'hgcalMergeLayerClusters:timeLayerClusters' ValueMap";
85  edm::LogWarning("DataNotFound|InvalidData")
86  << __FILE__ << ":" << __LINE__
87  << " couldn't locate 'hgcalMergeLayerClusters:timeLayerCluster' ValueMap in input file.";
88  }
89  }
90 
92  iItem->getEvent()->getByLabel(edm::InputTag("hgcalMergeLayerClusters"), layerClustersHandle_);
93  edm::LogWarning("DataNotFound|InvalidData")
94  << __FILE__ << ":" << __LINE__
95  << " couldn't locate 'hgcalLayerClusters' collection "
96  "in input file. Trying to access 'hgcalMergeLayerClusters' collection.";
98  edm::LogWarning("DataNotFound|InvalidData")
99  << __FILE__ << ":" << __LINE__ << " couldn't locate 'hgcalMergeLayerClusters' collection in input file.";
100  }
101  }
102 
103  layer_ = item()->getConfig()->value<long>("Layer");
104  saturation_energy_ = item()->getConfig()->value<double>("EnergyCutOff");
105  heatmap_ = item()->getConfig()->value<bool>("Heatmap");
106  z_plus_ = item()->getConfig()->value<bool>("Z+");
107  z_minus_ = item()->getConfig()->value<bool>("Z-");
108  enableTimeFilter_ = item()->getConfig()->value<bool>("EnableTimeFilter");
109  enablePositionLines_ = item()->getConfig()->value<bool>("EnablePositionLines");
110  enableEdges_ = item()->getConfig()->value<bool>("EnableEdges");
111  displayMode_ = item()->getConfig()->value<double>("DisplayMode");
112  proportionalityFactor_ = item()->getConfig()->value<double>("ProportionalityFactor");
113 
114  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
115 }
116 
118  unsigned int iIndex,
119  TEveElement &oItemHolder,
120  const FWViewContext *) {
122  const float time = TimeValueMapHandle_->get(iIndex).first;
123  if (time < timeLowerBound_ || time > timeUpperBound_)
124  return;
125  }
126 
127  const ticl::Trackster &trackster = iData;
128  const size_t N = trackster.vertices().size();
129  const std::vector<reco::CaloCluster> &layerClusters = *layerClustersHandle_;
130  TEveStraightLineSet *position_marker = nullptr;
131 
132  if (enablePositionLines_) {
133  position_marker = new TEveStraightLineSet;
134  position_marker->SetLineWidth(2);
135  position_marker->SetLineColor(kWhite);
136  }
137 
138  for (size_t i = 0; i < N; ++i) {
139  const reco::CaloCluster layerCluster = layerClusters[trackster.vertices(i)];
140  const math::XYZPoint &position = layerCluster.position();
141  const size_t nHits = layerCluster.size();
142  const double energy = layerCluster.energy();
143  float radius = 0;
144  auto detIdOnLayer = layerCluster.seed();
145 
146  const auto *parameters = item()->getGeom()->getParameters(detIdOnLayer);
147  const int layer = parameters[1];
148  const int zside = parameters[2];
149  const bool isSilicon = parameters[3];
150 
151  auto const z_selection_is_on = z_plus_ ^ z_minus_;
152  auto const z_plus_selection_ok = z_plus_ && (zside == 1);
153  auto const z_minus_selection_ok = z_minus_ && (zside == -1);
154  if (!z_minus_ && !z_plus_)
155  continue;
156  if (z_selection_is_on && !(z_plus_selection_ok || z_minus_selection_ok))
157  continue;
158 
159  if (layer_ > 0 && (layer != layer_))
160  continue;
161 
162  if (displayMode_ == 0) {
163  radius = sqrt(nHits);
164  } else if (displayMode_ == 1) {
165  radius = nHits;
166  } else if (displayMode_ == 2) {
167  radius = energy;
168  } else if (displayMode_ == 3) {
169  radius = energy / nHits;
170  } else if (displayMode_ == 4) {
171  float area = 0;
172  if (!isSilicon) {
173  const bool isFine = (HGCScintillatorDetId(layerCluster.seed()).type() == 0);
174  float dphi = (isFine) ? 1.0 * M_PI / 180. : 1.25 * M_PI / 180.;
175  int ir = HGCScintillatorDetId(layerCluster.seed()).iradiusAbs();
176  float dr = (isFine) ? (0.0484 * static_cast<float>(ir) + 2.1) : (0.075 * static_cast<float>(ir) + 2.0);
177  float r = (isFine) ? (0.0239 * static_cast<float>(pow(ir, 2)) + 2.02 * static_cast<float>(ir) + 119.6)
178  : (0.0367 * static_cast<float>(pow(ir, 2)) + 1.7 * static_cast<float>(ir) + 90.7);
179  area = r * dr * dphi;
180  } else {
181  const bool isFine = (HGCSiliconDetId(layerCluster.seed()).type() == 0);
182  float side = (isFine) ? 0.465 : 0.698;
183  area = pow(side, 2) * 3 * sqrt(3) / 2;
184  }
185  radius = sqrt(nHits * area) / M_PI;
186  }
187 
188  auto *eveCircle = new TEveGeoShape("Circle");
189  auto tube = new TGeoTube(0., proportionalityFactor_ * radius, 0.1);
190  eveCircle->SetShape(tube);
191  eveCircle->InitMainTrans();
192  eveCircle->RefMainTrans().Move3PF(position.x(), position.y(), position.z());
193  setupAddElement(eveCircle, &oItemHolder);
194  // Apply heatmap color coding **after** the call to setupAddElement, that will internally setup the color.
195  if (heatmap_) {
196  const float normalized_energy = fmin(energy / saturation_energy_, 1.0f);
197  const uint8_t colorFactor = gradient_steps * normalized_energy;
198  eveCircle->SetFillColor(
199  TColor::GetColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor]));
200  } else {
201  eveCircle->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
202  eveCircle->SetMainTransparency(item()->defaultDisplayProperties().transparency());
203  }
204 
205  // seed and cluster position
206  const float crossScale = 1.0f + fmin(energy, 5.0f);
207  if (enablePositionLines_) {
208  auto const &pos = layerCluster.position();
209  const float position_crossScale = crossScale * 0.5;
210  position_marker->AddLine(
211  pos.x() - position_crossScale, pos.y(), pos.z(), pos.x() + position_crossScale, pos.y(), pos.z());
212  position_marker->AddLine(
213  pos.x(), pos.y() - position_crossScale, pos.z(), pos.x(), pos.y() + position_crossScale, pos.z());
214  }
215  }
216 
218  oItemHolder.AddElement(position_marker);
219 
220  if (enableEdges_) {
221  auto &edges = trackster.edges();
222 
223  TEveStraightLineSet *adjacent_marker = new TEveStraightLineSet;
224  adjacent_marker->SetLineWidth(2);
225  adjacent_marker->SetLineColor(kYellow);
226 
227  TEveStraightLineSet *non_adjacent_marker = new TEveStraightLineSet;
228  non_adjacent_marker->SetLineWidth(2);
229  non_adjacent_marker->SetLineColor(kRed);
230 
231  for (auto edge : edges) {
232  auto doublet = std::make_pair(layerClusters[edge[0]], layerClusters[edge[1]]);
233 
234  int layerIn = item()->getGeom()->getParameters(doublet.first.seed())[1];
235  int layerOut = item()->getGeom()->getParameters(doublet.second.seed())[1];
236 
237  const bool isAdjacent = std::abs(layerOut - layerIn) == 1;
238 
239  // draw 3D cross
240  if (layer_ == 0 || fabs(layerIn - layer_) == 0 || fabs(layerOut - layer_) == 0) {
241  if (isAdjacent)
242  adjacent_marker->AddLine(doublet.first.x(),
243  doublet.first.y(),
244  doublet.first.z(),
245  doublet.second.x(),
246  doublet.second.y(),
247  doublet.second.z());
248  else
249  non_adjacent_marker->AddLine(doublet.first.x(),
250  doublet.first.y(),
251  doublet.first.z(),
252  doublet.second.x(),
253  doublet.second.y(),
254  doublet.second.z());
255  }
256  }
257  oItemHolder.AddElement(adjacent_marker);
258  oItemHolder.AddElement(non_adjacent_marker);
259  }
260 }
261 
edm::Handle< std::vector< reco::CaloCluster > > layerClustersHandle_
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
#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:218
constexpr int pow(int x)
Definition: conifer.h:24
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:186
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:148
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
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
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
edm::Handle< edm::ValueMap< std::pair< float, float > > > TimeValueMapHandle_
const FWEventItem * item() const