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