CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Fireworks/Muons/plugins/FWRPCDigiProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muon
00004 // Class  :     FWRPCDigiProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author: mccauley
00010 //         Created:  Sun Jan  6 23:57:00 EST 2008
00011 // $Id: FWRPCDigiProxyBuilder.cc,v 1.14 2010/09/07 15:46:48 yana Exp $
00012 //
00013 
00014 #include "TEveStraightLineSet.h"
00015 #include "TEveCompound.h"
00016 #include "TEveGeoNode.h"
00017 
00018 #include "Fireworks/Core/interface/FWProxyBuilderBase.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/RPCDigi/interface/RPCDigiCollection.h"
00024 
00025 class FWRPCDigiProxyBuilder : public FWProxyBuilderBase
00026 {
00027 public:
00028   FWRPCDigiProxyBuilder() {}
00029   virtual ~FWRPCDigiProxyBuilder() {}
00030 
00031   REGISTER_PROXYBUILDER_METHODS();
00032 
00033 private:
00034   virtual void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*);
00035   FWRPCDigiProxyBuilder(const FWRPCDigiProxyBuilder&);    
00036   const FWRPCDigiProxyBuilder& operator=(const FWRPCDigiProxyBuilder&);
00037 };
00038 
00039 void
00040 FWRPCDigiProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*)
00041 {
00042   const RPCDigiCollection* digis = 0;
00043  
00044   iItem->get(digis);
00045 
00046   if ( ! digis ) 
00047   {
00048     fwLog(fwlog::kWarning)<<"Failed to get RPCDigis"<<std::endl;
00049     return;
00050   }
00051   const FWGeometry *geom = iItem->getGeom();
00052 
00053   for ( RPCDigiCollection::DigiRangeIterator dri = digis->begin(), driEnd = digis->end();
00054         dri != driEnd; ++dri )
00055   {
00056     unsigned int rawid = (*dri).first.rawId();
00057     const RPCDigiCollection::Range& range = (*dri).second;
00058 
00059     if( ! geom->contains( rawid ))
00060     {
00061       fwLog( fwlog::kWarning ) << "Failed to get geometry of RPC roll with detid: "
00062                                << rawid << std::endl;
00063       
00064       TEveCompound* compound = createCompound();
00065       setupAddElement( compound, product );
00066       
00067       continue;
00068     }
00069     
00070     const float* parameters = geom->getParameters( rawid );
00071     float nStrips = parameters[0];
00072     float halfStripLength = parameters[1]*0.5;
00073     float pitch = parameters[2];
00074     float offset = -0.5*nStrips*pitch;
00075     
00076     for( RPCDigiCollection::const_iterator dit = range.first;
00077          dit != range.second; ++dit )
00078     {
00079       TEveStraightLineSet* stripDigiSet = new TEveStraightLineSet;
00080       stripDigiSet->SetLineWidth(3);
00081       setupAddElement( stripDigiSet, product );
00082 
00083       int strip = (*dit).strip();
00084       float centreOfStrip = (strip-0.5)*pitch + offset;
00085 
00086       float localPointTop[3] =
00087       {
00088         centreOfStrip, halfStripLength, 0.0
00089       };
00090 
00091       float localPointBottom[3] = 
00092       {
00093         centreOfStrip, -halfStripLength, 0.0
00094       };
00095 
00096       float globalPointTop[3];
00097       float globalPointBottom[3];
00098 
00099       geom->localToGlobal( rawid, localPointTop, globalPointTop, localPointBottom, globalPointBottom );
00100 
00101       stripDigiSet->AddLine(globalPointTop[0], globalPointTop[1], globalPointTop[2],
00102                             globalPointBottom[0], globalPointBottom[1], globalPointBottom[2]);
00103     }
00104   }
00105 }
00106 
00107 REGISTER_FWPROXYBUILDER(FWRPCDigiProxyBuilder, RPCDigiCollection, "RPCDigi", 
00108                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);
00109