CMS 3D CMS Logo

FWDTSegmentProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Muons
4 // Class : FWDTSegmentProxyBuilder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Sun Jan 6 23:57:00 EST 2008
11 //
12 
13 #include "TEveGeoNode.h"
14 #include "TEveStraightLineSet.h"
15 #include "TEvePointSet.h"
16 #include "TGeoArb8.h"
17 
22 
25 
26 #include <vector>
27 
28 class FWDTSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<DTRecSegment4D> {
29 public:
31  ~FWDTSegmentProxyBuilder(void) override {}
32 
33  bool haveSingleProduct() const override { return false; }
34 
36 
37 private:
40 
42  void buildViewType(const DTRecSegment4D& iData,
43  unsigned int iIndex,
44  TEveElement& oItemHolder,
46  const FWViewContext*) override;
47 };
48 
50  unsigned int iIndex,
51  TEveElement& oItemHolder,
53  const FWViewContext*) {
54  unsigned int rawid = iData.chamberId().rawId();
55  const FWGeometry* geom = item()->getGeom();
56 
57  if (!geom->contains(rawid)) {
58  fwLog(fwlog::kError) << "failed to get geometry of DT chamber with detid: " << rawid << std::endl;
59  return;
60  }
61 
62  TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
63  // FIXME: This should be set elsewhere.
64  segmentSet->SetLineWidth(3);
65  setupAddElement(segmentSet, &oItemHolder);
66 
67  TEveGeoShape* shape = item()->getGeom()->getEveShape(rawid);
68  if (shape) {
69  if (TGeoBBox* box = dynamic_cast<TGeoBBox*>(shape->GetShape())) {
70  LocalPoint pos = iData.localPosition();
71  LocalVector dir = iData.localDirection();
72  LocalVector unit = dir.unit();
73 
74  double localPosition[3] = {pos.x(), pos.y(), pos.z()};
75  double localDirectionIn[3] = {dir.x(), dir.y(), dir.z()};
76  double localDirectionOut[3] = {-dir.x(), -dir.y(), -dir.z()};
77 
78  // In RhoZ view, draw segments at the middle of the chamber, otherwise they won't align with 1D rechits,
79  // for which only one coordinate is known.
80  if (type == FWViewType::kRhoZ) {
81  localPosition[0] = 0;
82  localDirectionIn[0] = 0;
83  localDirectionOut[0] = 0;
84  }
85 
86  Double_t distIn = box->DistFromInside(localPosition, localDirectionIn);
87  Double_t distOut = box->DistFromInside(localPosition, localDirectionOut);
88  LocalVector vIn = unit * distIn;
89  LocalVector vOut = -unit * distOut;
90  float localSegmentInnerPoint[3] = {static_cast<float>(localPosition[0] + vIn.x()),
91  static_cast<float>(localPosition[1] + vIn.y()),
92  static_cast<float>(localPosition[2] + vIn.z())};
93 
94  float localSegmentOuterPoint[3] = {static_cast<float>(localPosition[0] + vOut.x()),
95  static_cast<float>(localPosition[1] + vOut.y()),
96  static_cast<float>(localPosition[2] + vOut.z())};
97 
98  float globalSegmentInnerPoint[3];
99  float globalSegmentOuterPoint[3];
100 
101  geom->localToGlobal(
102  rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint);
103 
104  segmentSet->AddLine(globalSegmentInnerPoint[0],
105  globalSegmentInnerPoint[1],
106  globalSegmentInnerPoint[2],
107  globalSegmentOuterPoint[0],
108  globalSegmentOuterPoint[1],
109  globalSegmentOuterPoint[2]);
110 
111  // Draw hits included in the segment
112  TEvePointSet* pointSet = new TEvePointSet;
113  // FIXME: This should be set elsewhere.
114  pointSet->SetMarkerSize(1.5);
115  setupAddElement(pointSet, &oItemHolder);
116 
117  std::vector<DTRecHit1D> recHits;
118  const DTChamberRecSegment2D* phiSeg = iData.phiSegment();
119  const DTSLRecSegment2D* zSeg = iData.zSegment();
120  if (phiSeg) {
121  std::vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
122  copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits));
123  }
124  if (zSeg) {
125  std::vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
126  copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits));
127  }
128 
129  for (std::vector<DTRecHit1D>::const_iterator rh = recHits.begin(); rh != recHits.end(); ++rh) {
130  DTLayerId layerId = (*rh).wireId().layerId();
131  LocalPoint hpos = (*rh).localPosition();
132  float hitLocalPos[3] = {hpos.x(), hpos.y(), hpos.z()};
133  if (type == FWViewType::kRhoZ) {
134  // In RhoZ view, draw hits at the middle of the layer in the global Z coordinate,
135  // otherwise they won't align with 1D rechits, for which only one coordinate is known.
136  if (layerId.superLayer() == 2) {
137  hitLocalPos[1] = 0;
138  } else {
139  hitLocalPos[0] = 0;
140  }
141  }
142  float hitGlobalPoint[3];
143  geom->localToGlobal(layerId, hitLocalPos, hitGlobalPoint);
144  pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
145  }
146  }
147  }
148 }
149 
152  "DT-segments",
type
Definition: HCALResponse.h:21
bool haveSingleProduct() const override
LocalPoint localPosition() const override
Local position in Chamber frame.
static const int kAllRPZBits
Definition: FWViewType.h:67
LocalVector localDirection() const override
Local direction in Chamber frame.
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
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
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
const FWEventItem * item() const
static const int kAll3DBits
Definition: FWViewType.h:68
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:262
void buildViewType(const DTRecSegment4D &iData, unsigned int iIndex, TEveElement &oItemHolder, FWViewType::EType type, const FWViewContext *) override
T z() const
Definition: PV3DBase.h:61
void localToGlobal(unsigned int id, const float *local, float *global, bool translatep=true) const
Definition: FWGeometry.cc:438
int superLayer() const
Return the superlayer number.
bool contains(unsigned int id) const
Definition: FWGeometry.h:139
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
Vector3DBase unit() const
Definition: Vector3DBase.h:54
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
#define fwLog(_level_)
Definition: fwLog.h:45
#define REGISTER_PROXYBUILDER_METHODS()
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
const FWDTSegmentProxyBuilder & operator=(const FWDTSegmentProxyBuilder &)=delete
T x() const
Definition: PV3DBase.h:59
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
Basic3DVector unit() const