CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/Tracks/plugins/FWSiStripClusterProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: FWSiStripClusterProxyBuilder.cc,v 1.20 2012/06/01 04:02:45 amraktad Exp $
00003 //
00004 
00005 #include "TEveGeoNode.h"
00006 #include "TEveStraightLineSet.h"
00007 #include "TEveCompound.h"
00008 
00009 #include "Fireworks/Core/interface/fwLog.h"
00010 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012 #include "Fireworks/Core/interface/FWGeometry.h"
00013 #include "Fireworks/Tracks/interface/TrackUtils.h"
00014 
00015 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00016 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00017 
00018 class FWSiStripClusterProxyBuilder : public FWProxyBuilderBase
00019 {
00020 public:
00021    FWSiStripClusterProxyBuilder( void ) {}
00022    virtual ~FWSiStripClusterProxyBuilder( void ) {}
00023 
00024    REGISTER_PROXYBUILDER_METHODS();
00025 
00026    virtual void clean();
00027 
00028 protected:
00029    virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext*);
00030    virtual void localModelChanges( const FWModelId& iId, TEveElement* iCompound,
00031                                    FWViewType::EType viewType, const FWViewContext* vc );
00032 private:
00033    FWSiStripClusterProxyBuilder( const FWSiStripClusterProxyBuilder& );
00034    const FWSiStripClusterProxyBuilder& operator=( const FWSiStripClusterProxyBuilder& );              
00035 };
00036 
00037 
00038 void
00039 FWSiStripClusterProxyBuilder::clean()
00040 {
00041    // keep itemholders to restore configuration
00042 
00043    for (FWProxyBuilderBase::Product_it i = m_products.begin(); i != m_products.end(); ++i)
00044    {
00045       if ((*i)->m_elements)
00046       {
00047          TEveElement* elms = (*i)->m_elements;
00048          for (TEveElement::List_i it = elms->BeginChildren(); it != elms->EndChildren(); ++it)
00049             (*it)->DestroyElements();
00050       }
00051    }
00052 
00053    cleanLocal();
00054 }
00055 void
00056 FWSiStripClusterProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* )
00057 {
00058    const edmNew::DetSetVector<SiStripCluster>* clusters = 0;
00059    iItem->get( clusters );
00060    if( 0 == clusters ) return;
00061    int cnt = 0;
00062 
00063    for( edmNew::DetSetVector<SiStripCluster>::const_iterator set = clusters->begin(), setEnd = clusters->end();
00064         set != setEnd; ++set) {
00065       unsigned int id = set->detId();
00066 
00067       
00068       TEveGeoShape* shape = item()->getGeom()->getEveShape( id );
00069       if (shape) 
00070       {
00071          shape->SetMainTransparency( 75 );    
00072          shape->SetElementName( "Det" );
00073       }
00074       else      
00075       {
00076          fwLog( fwlog::kWarning ) 
00077             << "failed to get shape of SiStripCluster with detid: "
00078             << id << std::endl;
00079       }  
00080 
00081       for( edmNew::DetSet<SiStripCluster>::const_iterator ic = set->begin (), icEnd = set->end (); ic != icEnd; ++ic ) 
00082       {
00083          TEveCompound* itemHolder = 0;
00084          if (cnt < product->NumChildren())
00085          {
00086             TEveElement::List_i pit = product->BeginChildren();
00087             std::advance(pit, cnt);
00088             itemHolder = (TEveCompound*)*pit;
00089             itemHolder->SetRnrSelfChildren(true, true);
00090          }
00091          else {
00092             itemHolder = createCompound(); 
00093             setupAddElement( itemHolder, product );
00094          }
00095 
00096          // add common shape
00097          if (shape) 
00098          {
00099             setupAddElement( shape, itemHolder );
00100             increaseComponentTransparency( cnt, itemHolder, "Det", 60 );
00101          }
00102 
00103          // add line        
00104          if( ! item()->getGeom()->contains( id ))
00105          {
00106             fwLog( fwlog::kError )
00107                << "failed to geometry of SiStripCluster with detid: " 
00108                << id << std::endl;
00109             continue;
00110          }
00111 
00112          TEveStraightLineSet *lineSet = new TEveStraightLineSet( "strip" );
00113          setupAddElement( lineSet, itemHolder ); 
00114          float localTop[3] = { 0.0, 0.0, 0.0 };
00115          float localBottom[3] = { 0.0, 0.0, 0.0 };
00116 
00117          fireworks::localSiStrip( (*ic).firstStrip(), localTop, localBottom, iItem->getGeom()->getParameters( id ), id );
00118 
00119          float globalTop[3];
00120          float globalBottom[3];
00121          iItem->getGeom()->localToGlobal( id, localTop, globalTop, localBottom, globalBottom );
00122   
00123          lineSet->AddLine( globalTop[0], globalTop[1], globalTop[2],
00124                            globalBottom[0], globalBottom[1], globalBottom[2] ); 
00125 
00126          cnt++;
00127       }
00128    }
00129 }
00130 void
00131 FWSiStripClusterProxyBuilder::localModelChanges( const FWModelId& iId, TEveElement* iCompound,
00132                                                  FWViewType::EType viewType, const FWViewContext* vc )
00133 {
00134   increaseComponentTransparency( iId.index(), iCompound, "Det", 60 );
00135 }
00136 
00137 REGISTER_FWPROXYBUILDER( FWSiStripClusterProxyBuilder, edmNew::DetSetVector<SiStripCluster>, "SiStripCluster", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );