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