CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/Fireworks/Muons/plugins/FWDTDigiProxyBuilder.cc

Go to the documentation of this file.
00001 /*
00002  *  FWDTDigiProxyBuilder.cc
00003  *  FWorks
00004  *
00005  *  Created by Ianna Osborne on 6/7/10.
00006  *
00007  */
00008 
00009 #include "TEveGeoNode.h"
00010 #include "TEvePointSet.h"
00011 #include "TEveCompound.h"
00012 #include "TGeoArb8.h"
00013 #include "TEveBox.h"
00014 
00015 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
00016 #include "Fireworks/Core/interface/FWEventItem.h"
00017 #include "Fireworks/Core/interface/FWGeometry.h"
00018 #include "Fireworks/Core/interface/fwLog.h"
00019 
00020 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
00021 
00022 namespace 
00023 {
00024   void
00025   addTube( TEveBox* shape, const FWGeometry::GeomDetInfo& info, float localPos[3],  const float* pars )
00026   {
00027     const Float_t width = pars[0] / 2.;
00028     const Float_t thickness = pars[1] / 2.;
00029     const Float_t length = pars[2] / 2.;
00030     
00031     const Float_t vtx[24] = { localPos[0] - width, -length, -thickness,
00032                               localPos[0] - width,  length, -thickness,
00033                               localPos[0] + width,  length, -thickness,
00034                               localPos[0] + width, -length, -thickness,
00035                               localPos[0] - width, -length,  thickness,
00036                               localPos[0] - width,  length,  thickness,
00037                               localPos[0] + width,  length,  thickness,
00038                               localPos[0] + width, -length,  thickness };
00039     
00040     double array[16] = { info.matrix[0], info.matrix[3], info.matrix[6], 0.,
00041                          info.matrix[1], info.matrix[4], info.matrix[7], 0.,
00042                          info.matrix[2], info.matrix[5], info.matrix[8], 0.,
00043                          info.translation[0], info.translation[1], info.translation[2], 1.
00044     };
00045     
00046     shape->SetVertices( vtx );
00047     shape->SetTransMatrix( array );
00048     shape->SetDrawFrame(false);
00049     shape->SetMainTransparency( 75 );
00050   }
00051 }
00052 
00053 class FWDTDigiProxyBuilder : public FWProxyBuilderBase
00054 {
00055 public:
00056   FWDTDigiProxyBuilder( void ) {}
00057   virtual ~FWDTDigiProxyBuilder( void ) {}
00058 
00059   virtual bool haveSingleProduct( void ) const { return false; }
00060            
00061   REGISTER_PROXYBUILDER_METHODS();
00062         
00063 private:
00064   // Disable default copy constructor
00065   FWDTDigiProxyBuilder( const FWDTDigiProxyBuilder& );
00066   // Disable default assignment operator
00067   const FWDTDigiProxyBuilder& operator=( const FWDTDigiProxyBuilder& );
00068         
00069   virtual void buildViewType( const FWEventItem* iItem, TEveElementList* product, FWViewType::EType, const FWViewContext* );
00070 };
00071 
00072 void
00073 FWDTDigiProxyBuilder::buildViewType( const FWEventItem* iItem, TEveElementList* product, FWViewType::EType type, const FWViewContext* )
00074 {
00075    const DTDigiCollection* digis = 0;
00076    iItem->get( digis );
00077         
00078    if( ! digis )
00079    {
00080       return;
00081    }
00082    const FWGeometry *geom = iItem->getGeom();
00083         
00084    for( DTDigiCollection::DigiRangeIterator dri = digis->begin(), dre = digis->end(); dri != dre; ++dri )
00085    {
00086       const DTLayerId& layerId = (*dri).first;
00087       unsigned int rawid = layerId.rawId();
00088       const DTDigiCollection::Range &range = (*dri).second;
00089 
00090       if( ! geom->contains( rawid ))
00091       {
00092          fwLog( fwlog::kWarning ) << "failed to get geometry of DT with detid: "
00093                                   << rawid << std::endl;
00094 
00095          TEveCompound* compound = createCompound();
00096          setupAddElement( compound, product );
00097 
00098          continue;
00099       }
00100 
00101       const float* pars = geom->getParameters( rawid );
00102       FWGeometry::IdToInfoItr det = geom->find( rawid );
00103 
00104       int superLayer = layerId.superlayerId().superLayer();
00105 
00106       float localPos[3] = { 0.0, 0.0, 0.0 };
00107                 
00108       // Loop over the digis of this DetUnit
00109       for( DTDigiCollection::const_iterator it = range.first;
00110            it != range.second; ++it )
00111       {
00112          // The x wire position in the layer, starting from its wire number.
00113          float firstChannel = pars[3];
00114          float nChannels = pars[5];
00115          localPos[0] = ((*it).wire() - ( firstChannel - 1 ) - 0.5 ) * pars[0] - nChannels / 2.0 * pars[0];
00116 
00117          if( type == FWViewType::k3D || type == FWViewType::kISpy )
00118          {
00119             TEveBox* box = new TEveBox;
00120             setupAddElement( box, product );
00121             ::addTube( box, *det, localPos, pars );
00122          }
00123          else if(( ( type == FWViewType::kRhoPhi ||  type == FWViewType::kRhoPhiPF ) && superLayer != 2 ) ||
00124                  ( type == FWViewType::kRhoZ && superLayer == 2 ))
00125          {
00126             TEvePointSet* pointSet = new TEvePointSet;
00127             pointSet->SetMarkerStyle( 24 );
00128             setupAddElement( pointSet, product);        
00129 
00130             float globalPos[3];                 
00131             geom->localToGlobal( *det, localPos, globalPos );
00132             pointSet->SetNextPoint( globalPos[0],  globalPos[1],  globalPos[2] );
00133 
00134             TEveBox* box = new TEveBox;
00135             setupAddElement( box, product );
00136             ::addTube( box, *det, localPos, pars );
00137          }
00138          else
00139          {
00140             TEveCompound* compound = createCompound();
00141             setupAddElement( compound, product );
00142 
00143          }
00144       }         
00145    }
00146 }
00147 
00148 REGISTER_FWPROXYBUILDER( FWDTDigiProxyBuilder, DTDigiCollection, "DT Digis", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );