CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Fireworks/Muons/plugins/FWCSCSegmentProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muons
00004 // Class  :     FWCSCSegmentProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:
00010 //         Created:  Sun Jan  6 23:57:00 EST 2008
00011 // $Id: FWCSCSegmentProxyBuilder.cc,v 1.18 2010/10/19 09:00:59 chrjones 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/CSCRecHit/interface/CSCSegmentCollection.h"
00024 
00025 class FWCSCSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<CSCSegment>
00026 {
00027 public:
00028   FWCSCSegmentProxyBuilder( void ) {}
00029   virtual ~FWCSCSegmentProxyBuilder( void ) {}
00030   
00031   REGISTER_PROXYBUILDER_METHODS();
00032 
00033 private:
00034   FWCSCSegmentProxyBuilder( const FWCSCSegmentProxyBuilder& );   
00035   const FWCSCSegmentProxyBuilder& operator=( const FWCSCSegmentProxyBuilder& );
00036 
00037   void build( const CSCSegment& iData, unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* );
00038 };
00039 
00040 void
00041 FWCSCSegmentProxyBuilder::build( const CSCSegment& iData,           
00042                                  unsigned int iIndex, TEveElement& oItemHolder, const FWViewContext* )
00043 {
00044   const FWGeometry *geom = item()->getGeom();
00045   unsigned int rawid = iData.cscDetId().rawId();
00046   
00047   if( ! geom->contains( rawid ))
00048   {
00049     fwLog(fwlog::kError) << "failed to get geometry of CSC chamber with rawid: " 
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   float length    = 0.0;
00060   float thickness = 0.0;
00061 
00062   TEveGeoShape* shape = item()->getGeom()->getEveShape( rawid );
00063   if( TGeoTrap* trap = dynamic_cast<TGeoTrap*>( shape->GetShape())) // Trapezoidal
00064   {
00065      length = trap->GetDz();
00066      thickness = trap->GetH1();
00067 
00068      LocalPoint pos = iData.localPosition();
00069      LocalVector dir = iData.localDirection();   
00070      LocalVector unit = dir.unit();
00071     
00072      Double_t localPosition[3]     = {  pos.x(),  pos.y(),  pos.z() };
00073      Double_t localDirectionIn[3]  = {  dir.x(),  dir.y(),  dir.z() };
00074      Double_t localDirectionOut[3] = { -dir.x(), -dir.y(), -dir.z() };
00075   
00076      float distIn = trap->DistFromInside( localPosition, localDirectionIn );
00077      float distOut = trap->DistFromInside( localPosition, localDirectionOut );
00078      LocalVector vIn = unit * distIn;
00079      LocalVector vOut = -unit * distOut;
00080      float localSegmentInnerPoint[3] = { static_cast<float>(localPosition[0] + vIn.x()),
00081                                          static_cast<float>(localPosition[1] + vIn.y()),
00082                                          static_cast<float>(localPosition[2] + vIn.z()) 
00083      };
00084       
00085      float localSegmentOuterPoint[3] = { static_cast<float>(localPosition[0] + vOut.x()),
00086                                          static_cast<float>(localPosition[1] + vOut.y()),
00087                                          static_cast<float>(localPosition[2] + vOut.z()) 
00088      };
00089 
00090      float globalSegmentInnerPoint[3];
00091      float globalSegmentOuterPoint[3];
00092      
00093      geom->localToGlobal( rawid, localSegmentInnerPoint,  globalSegmentInnerPoint, localSegmentOuterPoint,  globalSegmentOuterPoint );
00094 
00095      segmentSet->AddLine( globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2],
00096                           globalSegmentOuterPoint[0], globalSegmentOuterPoint[1], globalSegmentOuterPoint[2] ); 
00097   }
00098 }
00099 
00100 REGISTER_FWPROXYBUILDER( FWCSCSegmentProxyBuilder, CSCSegment, "CSC-segments", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );
00101 
00102