CMS 3D CMS Logo

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