CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Fireworks/Muons/plugins/FWGEMRecHitProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muons
00004 // Class  :     FWGEMRecHitProxyBuilder
00005 //
00006 //
00007 // Original Author:
00008 //         Created:  Sun Jan  6 23:42:33 EST 2008
00009 // $Id: FWRPCRecHitProxyBuilder.cc,v 1.16 2010/11/11 20:25:28 amraktad Exp $
00010 // $Id: FWGEMRecHitProxyBuilder.cc,v 1.17 2013/10/10 21:57:00 Yusang Kim   $
00011 //
00012 
00013 #include "TEveGeoNode.h"
00014 #include "TEveStraightLineSet.h"
00015 
00016 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00017 #include "Fireworks/Core/interface/FWEventItem.h"
00018 #include "Fireworks/Core/interface/FWGeometry.h"
00019 #include "Fireworks/Core/interface/fwLog.h"
00020 
00021 #include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h"
00022 
00023 class FWGEMRecHitProxyBuilder : public FWSimpleProxyBuilderTemplate<GEMRecHit>
00024 {
00025 public:
00026    FWGEMRecHitProxyBuilder() {}
00027    virtual ~FWGEMRecHitProxyBuilder() {}
00028   
00029    virtual bool haveSingleProduct() const 
00030     { 
00031       return false; 
00032     }
00033 
00034    REGISTER_PROXYBUILDER_METHODS();
00035 
00036 private:
00037   FWGEMRecHitProxyBuilder(const FWGEMRecHitProxyBuilder&);
00038   const FWGEMRecHitProxyBuilder& operator=(const FWGEMRecHitProxyBuilder&); 
00039  
00040   virtual void buildViewType(const GEMRecHit& iData, 
00041                              unsigned int iIndex, 
00042                              TEveElement& oItemHolder, 
00043                              FWViewType::EType type, 
00044                              const FWViewContext*);
00045 };
00046 
00047 
00048 void
00049 FWGEMRecHitProxyBuilder::buildViewType(const GEMRecHit& iData,
00050                                        unsigned int iIndex, 
00051                                        TEveElement& oItemHolder, 
00052                                        FWViewType::EType type,
00053                                        const FWViewContext*)
00054 {
00055   GEMDetId gemId = iData.gemId();
00056   unsigned int rawid = gemId.rawId();
00057   
00058   const FWGeometry *geom = item()->getGeom();
00059 
00060   if( ! geom->contains( rawid ))
00061   {
00062     fwLog( fwlog::kError ) << "failed to get geometry of GEM roll with detid: " 
00063                            << rawid <<std::endl;
00064     return;
00065   }
00066 
00067   TEveStraightLineSet* recHitSet = new TEveStraightLineSet;
00068   recHitSet->SetLineWidth(3);
00069 
00070   if( type == FWViewType::k3D || type == FWViewType::kISpy ) 
00071   {
00072     TEveGeoShape* shape = geom->getEveShape( rawid );
00073     shape->SetMainTransparency( 75 );
00074     shape->SetMainColor( item()->defaultDisplayProperties().color());
00075     recHitSet->AddElement( shape );
00076   }
00077 
00078   float localX = iData.localPosition().x();
00079   float localY = iData.localPosition().y();
00080   float localZ = iData.localPosition().z();
00081   
00082   float localXerr = sqrt(iData.localPositionError().xx());
00083   float localYerr = sqrt(iData.localPositionError().yy());
00084 
00085   float localU1[3] = 
00086     {
00087       localX - localXerr, localY, localZ 
00088     };
00089   
00090   float localU2[3] = 
00091     {
00092       localX + localXerr, localY, localZ 
00093     };
00094   
00095   float localV1[3] = 
00096     {
00097       localX, localY - localYerr, localZ
00098     };
00099   
00100   float localV2[3] = 
00101     {
00102       localX, localY + localYerr, localZ
00103     };
00104 
00105   float globalU1[3];
00106   float globalU2[3];
00107   float globalV1[3];
00108   float globalV2[3];
00109 
00110   FWGeometry::IdToInfoItr det = geom->find( rawid );
00111  
00112   geom->localToGlobal( *det, localU1, globalU1 );
00113   geom->localToGlobal( *det, localU2, globalU2 );
00114   geom->localToGlobal( *det, localV1, globalV1 );
00115   geom->localToGlobal( *det, localV2, globalV2 );
00116  
00117   recHitSet->AddLine( globalU1[0], globalU1[1], globalU1[2],
00118                       globalU2[0], globalU2[1], globalU2[2] );
00119 
00120   recHitSet->AddLine( globalV1[0], globalV1[1], globalV1[2],
00121                       globalV2[0], globalV2[1], globalV2[2] );
00122 
00123   setupAddElement( recHitSet, &oItemHolder );
00124 }
00125 
00126 REGISTER_FWPROXYBUILDER( FWGEMRecHitProxyBuilder, GEMRecHit, "GEM RecHits", 
00127                          FWViewType::kAll3DBits | FWViewType::kAllRPZBits);