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 
2 // -*- C++ -*-
3 //
4 // Package: Muons
5 // Class : FWDTSegmentProxyBuilder
6 //
7 // Implementation:
8 // <Notes on implementation>
9 //
10 // Original Author:
11 // Created: Sun Jan 6 23:57:00 EST 2008
12 //
13 
14 #include "TEveGeoNode.h"
15 #include "TEveStraightLineSet.h"
16 #include "TEvePointSet.h"
17 #include "TGeoArb8.h"
18 
23 
26 
27 #include <vector>
28 
30 {
31 public:
33  virtual ~FWDTSegmentProxyBuilder( void ) {}
34 
35  virtual bool haveSingleProduct() const { return false; }
36 
38 
39 private:
42 
43  void buildViewType( const DTRecSegment4D& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* );
44 };
45 
46 void
48  unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* )
49 {
50  unsigned int rawid = iData.chamberId().rawId();
51  const FWGeometry *geom = item()->getGeom();
52 
53  if( ! geom->contains( rawid ))
54  {
55  fwLog( fwlog::kError ) << "failed to get geometry of DT chamber with detid: "
56  << rawid << std::endl;
57  return;
58  }
59 
60  TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
61  // FIXME: This should be set elsewhere.
62  segmentSet->SetLineWidth( 3 );
63  setupAddElement( segmentSet, &oItemHolder );
64 
65  TEveGeoShape* shape = item()->getGeom()->getEveShape( rawid );
66  if( shape )
67  {
68  if( TGeoBBox* box = dynamic_cast<TGeoBBox*>( shape->GetShape()))
69  {
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 
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 
100  float globalSegmentInnerPoint[3];
101  float globalSegmentOuterPoint[3];
102 
103  geom->localToGlobal( rawid, localSegmentInnerPoint, globalSegmentInnerPoint, localSegmentOuterPoint, globalSegmentOuterPoint );
104 
105  segmentSet->AddLine( globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2],
106  globalSegmentOuterPoint[0], globalSegmentOuterPoint[1], globalSegmentOuterPoint[2] );
107 
108 
109  // Draw hits included in the segment
110  TEvePointSet* pointSet = new TEvePointSet;
111  // FIXME: This should be set elsewhere.
112  pointSet->SetMarkerSize(1.5);
113  setupAddElement( pointSet, &oItemHolder );
114 
115  std::vector<DTRecHit1D> recHits;
116  const DTChamberRecSegment2D* phiSeg = iData.phiSegment();
117  const DTSLRecSegment2D* zSeg = iData.zSegment();
118  if (type == FWViewType::kRhoPhi && phiSeg) {
119  recHits = phiSeg->specificRecHits();
120  }
121  if (type == FWViewType::kRhoZ && zSeg) {
122  recHits = zSeg->specificRecHits();
123  }
124 
125  for (std::vector<DTRecHit1D>::const_iterator rh=recHits.begin(); rh!=recHits.end(); ++rh){
126  DTLayerId layerId = (*rh).wireId().layerId();
127  LocalPoint hpos = (*rh).localPosition();
128  float hitLocalPos[3]= {hpos.x(), hpos.y(), hpos.z()};
129  if (layerId.superLayer()==2 && type == FWViewType::kRhoZ) {
130  // In RhoZ view, draw theta SL hits at the middle of the chamber, otherwise they won't align with 1D rechits,
131  // for which only one coordinate is known.
132  hitLocalPos[1]=0;
133  }
134  float hitGlobalPoint[3];
135  geom->localToGlobal(layerId, hitLocalPos, hitGlobalPoint);
136  pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
137  }
138  }
139  }
140 }
141 
143 
144 
type
Definition: HCALResponse.h:22
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
static const int kAllRPZBits
Definition: FWViewType.h:59
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:62
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void localToGlobal(unsigned int id, const float *local, float *global) const
Definition: FWGeometry.cc:325
const FWEventItem * item() const
virtual bool haveSingleProduct() const
static const int kAll3DBits
Definition: FWViewType.h:60
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual LocalVector localDirection() const
Local direction in Chamber frame.
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:250
string unit
Definition: csvLumiCalc.py:46
T z() const
Definition: PV3DBase.h:63
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
void buildViewType(const DTRecSegment4D &iData, unsigned int iIndex, TEveElement &oItemHolder, FWViewType::EType type, const FWViewContext *)
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
#define fwLog(_level_)
Definition: fwLog.h:51
dbl *** dir
Definition: mlp_gen.cc:35
T x() const
Definition: PV3DBase.h:61
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:681