CMS 3D CMS Logo

FWME0SegmentProxyBuilder.cc
Go to the documentation of this file.
1 #include "TEveGeoNode.h"
2 #include "TEveStraightLineSet.h"
3 #include "TGeoArb8.h"
4 #include "TEvePointSet.h"
5 
10 
12 
14 public:
16  ~FWME0SegmentProxyBuilder(void) override {}
17 
19 
20 private:
23 
24  void build(const ME0Segment& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext*) override;
25 };
26 
28  unsigned int iIndex,
29  TEveElement& oItemHolder,
30  const FWViewContext*) {
31  const FWGeometry* geom = item()->getGeom();
32  unsigned int rawid = iData.me0DetId().rawId();
33 
34  if (!geom->contains(rawid)) {
35  fwLog(fwlog::kError) << "failed to get geometry of ME0 chamber with rawid: " << rawid << std::endl;
36  return;
37  }
38 
39  TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
40  // FIXME: This should be set elsewhere.
41  segmentSet->SetLineWidth(5);
42  setupAddElement(segmentSet, &oItemHolder);
43 
44  TEveGeoShape* shape = item()->getGeom()->getEveShape(rawid);
45  if (shape) {
46  if (TGeoBBox* box = dynamic_cast<TGeoBBox*>(shape->GetShape())) {
47  LocalPoint pos = iData.localPosition();
48  LocalVector dir = iData.localDirection();
49  LocalVector unit = dir.unit();
50 
51  double localPosition[3] = {pos.x(), pos.y(), pos.z()};
52  double localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
53  double localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
54 
55  Double_t distIn = box->DistFromInside(localPosition, localDirectionIn);
56  Double_t distOut = box->DistFromInside(localPosition, localDirectionOut);
57  LocalVector vIn = unit * distIn;
58  LocalVector vOut = -unit * distOut;
59  float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
60  static_cast<float>(localPosition[1] + vIn.y()),
61  static_cast<float>(localPosition[2] + vIn.z())};
62 
63  float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
64  static_cast<float>(localPosition[1] + vOut.y()),
65  static_cast<float>(localPosition[2] + vOut.z())};
66 
67  float globalSegmentInnerPoint[3];
68  float globalSegmentOuterPoint[3];
69 
70  geom->localToGlobal(
71  rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
72 
73  segmentSet->AddLine(globalSegmentInnerPoint[0],
74  globalSegmentInnerPoint[1],
75  globalSegmentInnerPoint[2],
76  globalSegmentOuterPoint[0],
77  globalSegmentOuterPoint[1],
78  globalSegmentOuterPoint[2]);
79 
80  // Draw hits included in the segment
81  TEvePointSet* pointSet = new TEvePointSet;
82  // FIXME: This should be set elsewhere.
83  pointSet->SetMarkerSize(0.5);
84  pointSet->SetMarkerColor(1);
85  setupAddElement(pointSet, &oItemHolder);
86  auto recHits = iData.specificRecHits();
87  for (auto rh = recHits.begin(); rh != recHits.end(); rh++) {
88  auto me0id = rh->me0Id();
89  LocalPoint hpos = rh->localPosition();
90  float hitLocalPos[3] = {hpos.x(), hpos.y(), hpos.z()};
91  float hitGlobalPoint[3];
92  geom->localToGlobal(me0id, hitLocalPos, hitGlobalPoint);
93  pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
94  }
95  }
96  }
97 }
98 
100  ME0Segment,
101  "ME0-segments",
const FWME0SegmentProxyBuilder & operator=(const FWME0SegmentProxyBuilder &)=delete
const std::vector< ME0RecHit > & specificRecHits() const
Definition: ME0Segment.h:74
static const int kAllRPZBits
Definition: FWViewType.h:67
ME0DetId me0DetId() const
Definition: ME0Segment.h:78
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
const FWEventItem * item() const
static const int kAll3DBits
Definition: FWViewType.h:68
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:320
T z() const
Definition: PV3DBase.h:61
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:496
bool contains(unsigned int id) const
Definition: FWGeometry.h:139
LocalVector localDirection() const override
Local direction.
Definition: ME0Segment.h:50
LocalPoint localPosition() const override
Definition: ME0Segment.h:47
Vector3DBase unit() const
Definition: Vector3DBase.h:54
#define fwLog(_level_)
Definition: fwLog.h:45
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
T x() const
Definition: PV3DBase.h:59
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
Basic3DVector unit() const