CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/Muons/plugins/FWDTSegmentProxyBuilder.cc

Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 //
00004 // Package:     Muons
00005 // Class  :     FWDTSegmentProxyBuilder
00006 //
00007 // Implementation:
00008 //     <Notes on implementation>
00009 //
00010 // Original Author:
00011 //         Created:  Sun Jan  6 23:57:00 EST 2008
00012 //
00013 
00014 #include "TEveGeoNode.h"
00015 #include "TEveStraightLineSet.h"
00016 #include "TEvePointSet.h"
00017 #include "TGeoArb8.h"
00018 
00019 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00020 #include "Fireworks/Core/interface/FWEventItem.h"
00021 #include "Fireworks/Core/interface/FWGeometry.h"
00022 #include "Fireworks/Core/interface/fwLog.h"
00023 
00024 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00025 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00026 
00027 #include <vector>
00028 
00029 class FWDTSegmentProxyBuilder : public FWSimpleProxyBuilderTemplate<DTRecSegment4D>
00030 {
00031 public:
00032    FWDTSegmentProxyBuilder( void ) {}
00033    virtual ~FWDTSegmentProxyBuilder( void ) {}
00034 
00035   virtual bool haveSingleProduct() const { return false; }
00036 
00037    REGISTER_PROXYBUILDER_METHODS();
00038 
00039 private:
00040    FWDTSegmentProxyBuilder( const FWDTSegmentProxyBuilder& );
00041    const FWDTSegmentProxyBuilder& operator=( const FWDTSegmentProxyBuilder& );
00042 
00043    void buildViewType( const DTRecSegment4D& iData, unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* );
00044 };
00045 
00046 void
00047 FWDTSegmentProxyBuilder::buildViewType( const DTRecSegment4D& iData,           
00048                                 unsigned int iIndex, TEveElement& oItemHolder, FWViewType::EType type, const FWViewContext* )
00049 {
00050   unsigned int rawid = iData.chamberId().rawId();
00051   const FWGeometry *geom = item()->getGeom();
00052 
00053   if( ! geom->contains( rawid ))
00054   {
00055     fwLog( fwlog::kError ) << "failed to get geometry of DT chamber with detid: " 
00056                            << rawid << std::endl;
00057     return;
00058   }
00059 
00060   TEveStraightLineSet* segmentSet = new TEveStraightLineSet();
00061   // FIXME: This should be set elsewhere.
00062   segmentSet->SetLineWidth( 3 );
00063   setupAddElement( segmentSet, &oItemHolder );
00064    
00065   TEveGeoShape* shape = item()->getGeom()->getEveShape( rawid );
00066   if( shape ) 
00067   {
00068     if( TGeoBBox* box = dynamic_cast<TGeoBBox*>( shape->GetShape()))
00069     {
00070       LocalPoint pos = iData.localPosition();
00071       LocalVector dir = iData.localDirection();   
00072       LocalVector unit = dir.unit();
00073     
00074       double localPosition[3]     = {  pos.x(),  pos.y(),  pos.z() };
00075       double localDirectionIn[3]  = {  dir.x(),  dir.y(),  dir.z() };
00076       double localDirectionOut[3] = { -dir.x(), -dir.y(), -dir.z() };
00077 
00078       // In RhoZ view, draw segments at the middle of the chamber, otherwise they won't align with 1D rechits, 
00079       // for which only one coordinate is known.
00080       if (type == FWViewType::kRhoZ) { 
00081         localPosition[0]=0;
00082         localDirectionIn[0]=0;
00083         localDirectionOut[0]=0;
00084       }
00085 
00086       Double_t distIn = box->DistFromInside( localPosition, localDirectionIn );
00087       Double_t distOut = box->DistFromInside( localPosition, localDirectionOut );
00088       LocalVector vIn = unit * distIn;
00089       LocalVector vOut = -unit * distOut;
00090       float localSegmentInnerPoint[3] = { static_cast<float>(localPosition[0] + vIn.x()),
00091                                           static_cast<float>(localPosition[1] + vIn.y()),
00092                                           static_cast<float>(localPosition[2] + vIn.z()) 
00093       };
00094       
00095       float localSegmentOuterPoint[3] = { static_cast<float>(localPosition[0] + vOut.x()),
00096                                           static_cast<float>(localPosition[1] + vOut.y()),
00097                                           static_cast<float>(localPosition[2] + vOut.z()) 
00098       };
00099                                    
00100       float globalSegmentInnerPoint[3];
00101       float globalSegmentOuterPoint[3];
00102 
00103       geom->localToGlobal( rawid, localSegmentInnerPoint,  globalSegmentInnerPoint, localSegmentOuterPoint,  globalSegmentOuterPoint );
00104 
00105       segmentSet->AddLine( globalSegmentInnerPoint[0], globalSegmentInnerPoint[1], globalSegmentInnerPoint[2],
00106                            globalSegmentOuterPoint[0], globalSegmentOuterPoint[1], globalSegmentOuterPoint[2] );
00107 
00108       
00109       // Draw hits included in the segment
00110       TEvePointSet* pointSet = new TEvePointSet;
00111       // FIXME: This should be set elsewhere.
00112       pointSet->SetMarkerSize(1.5);
00113       setupAddElement( pointSet, &oItemHolder );
00114 
00115       std::vector<DTRecHit1D> recHits;
00116       const DTChamberRecSegment2D* phiSeg = iData.phiSegment();      
00117       const DTSLRecSegment2D* zSeg = iData.zSegment();
00118       if (type == FWViewType::kRhoPhi && phiSeg) {
00119         recHits = phiSeg->specificRecHits();
00120       }
00121       if (type == FWViewType::kRhoZ && zSeg) {
00122         recHits = zSeg->specificRecHits();
00123       }
00124 
00125       for (std::vector<DTRecHit1D>::const_iterator rh=recHits.begin(); rh!=recHits.end(); ++rh){
00126         DTLayerId layerId = (*rh).wireId().layerId();
00127         LocalPoint hpos = (*rh).localPosition();
00128         float hitLocalPos[3]= {hpos.x(), hpos.y(), hpos.z()};
00129         if (layerId.superLayer()==2 && type == FWViewType::kRhoZ) {
00130           // In RhoZ view, draw theta SL hits at the middle of the chamber, otherwise they won't align with 1D rechits, 
00131           // for which only one coordinate is known.
00132           hitLocalPos[1]=0;
00133         }
00134         float hitGlobalPoint[3];
00135         geom->localToGlobal(layerId, hitLocalPos, hitGlobalPoint);
00136         pointSet->SetNextPoint(hitGlobalPoint[0], hitGlobalPoint[1], hitGlobalPoint[2]);
00137       }
00138     }
00139   }
00140 }
00141 
00142 REGISTER_FWPROXYBUILDER( FWDTSegmentProxyBuilder, DTRecSegment4D, "DT-segments", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );
00143 
00144