CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Fireworks/Muons/plugins/FWDTSegmentProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muons
00004 // Class  :     FWDTSegmentProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:
00010 //         Created:  Sun Jan  6 23:57:00 EST 2008
00011 // $Id: FWDTSegmentProxyBuilder.cc,v 1.14 2010/11/11 20:25:28 amraktad Exp $
00012 //
00013 
00014 #include "TEveGeoNode.h"
00015 #include "TEveStraightLineSet.h"
00016 #include "TGeoArb8.h"
00017 
00018 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00019 #include "Fireworks/Core/interface/FWEventItem.h"
00020 #include "Fireworks/Core/interface/FWGeometry.h"
00021 #include "Fireworks/Core/interface/fwLog.h"
00022 
00023 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00024 
00025 class FWDTSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<DTRecSegment4D>
00026 {
00027 public:
00028    FWDTSegmentProxyBuilder( void ) {}
00029    virtual ~FWDTSegmentProxyBuilder( void ) {}
00030 
00031    REGISTER_PROXYBUILDER_METHODS();
00032 
00033 private:
00034    FWDTSegmentProxyBuilder( const FWDTSegmentProxyBuilder& );
00035    const FWDTSegmentProxyBuilder& operator=( const FWDTSegmentProxyBuilder& );
00036 
00037    void build( const DTRecSegment4D& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* );
00038 };
00039 
00040 void
00041 FWDTSegmentProxyBuilder::build( const DTRecSegment4D& iData,           
00042                                 unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* )
00043 {
00044   unsigned int rawid = iData.chamberId().rawId();
00045   const FWGeometry *geom = item()->getGeom();
00046 
00047   if( ! geom->contains( rawid ))
00048   {
00049     fwLog( fwlog::kError ) << "failed to get geometry of DT chamber with detid: " 
00050                            << rawid << std::endl;
00051     return;
00052   }
00053 
00054   TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
00055   // FIXME: This should be set elsewhere.
00056   segmentSet->SetLineWidth( 3 );
00057   setupAddElement( segmentSet, &oItemHolder );
00058    
00059   TEveGeoShape* shape = item()->getGeom()->getEveShape( rawid );
00060   if( shape ) 
00061   {
00062     if( TGeoBBox* box = dynamic_cast<TGeoBBox*>( shape->GetShape()))
00063     {
00064       LocalPoint pos = iData.localPosition();
00065       LocalVector dir = iData.localDirection();   
00066       LocalVector unit = dir.unit();
00067     
00068       double localPosition[3]     = {  pos.x(),  pos.y(),  pos.z() };
00069       double localDirectionIn[3]  = {  dir.x(),  dir.y(),  dir.z() };
00070       double localDirectionOut[3] = { -dir.x(), -dir.y(), -dir.z() };
00071 
00072       Double_t distIn = box->DistFromInside( localPosition, localDirectionIn );
00073       Double_t distOut = box->DistFromInside( localPosition, localDirectionOut );
00074       LocalVector vIn = unit * distIn;
00075       LocalVector vOut = -unit * distOut;
00076       float localSegmentInnerPoint[3] = { static_cast<float>(localPosition[0] + vIn.x()),
00077                                           static_cast<float>(localPosition[1] + vIn.y()),
00078                                           static_cast<float>(localPosition[2] + vIn.z()) 
00079       };
00080       
00081       float localSegmentOuterPoint[3] = { static_cast<float>(localPosition[0] + vOut.x()),
00082                                           static_cast<float>(localPosition[1] + vOut.y()),
00083                                           static_cast<float>(localPosition[2] + vOut.z()) 
00084       };
00085                                    
00086       float globalSegmentInnerPoint[3];
00087       float globalSegmentOuterPoint[3];
00088 
00089       geom->localToGlobal( rawid, localSegmentInnerPoint,  globalSegmentInnerPoint, localSegmentOuterPoint,  globalSegmentOuterPoint );
00090 
00091       segmentSet->AddLine( globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2],
00092                            globalSegmentOuterPoint[0], globalSegmentOuterPoint[1], globalSegmentOuterPoint[2] );
00093     }
00094   }
00095 }
00096 
00097 REGISTER_FWPROXYBUILDER( FWDTSegmentProxyBuilder, DTRecSegment4D, "DT-segments", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );
00098 
00099