CMS 3D CMS Logo

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