CMS 3D CMS Logo

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