CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muon
00004 // Class  :     FWCSCStripDigiProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author: mccauley
00010 //         Created:  Sun Jan  6 23:57:00 EST 2008
00011 // $Id: FWCSCStripDigiProxyBuilder.cc,v 1.14 2010/09/07 15:46:48 yana Exp $
00012 //
00013 
00014 #include "TEveStraightLineSet.h"
00015 #include "TEveCompound.h"
00016 
00017 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
00018 #include "Fireworks/Core/interface/FWEventItem.h"
00019 #include "Fireworks/Core/interface/FWGeometry.h"
00020 #include "Fireworks/Core/interface/fwLog.h"
00021 
00022 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
00023 
00024 class FWCSCStripDigiProxyBuilder : public FWProxyBuilderBase
00025 {
00026 public:
00027   FWCSCStripDigiProxyBuilder() {}
00028   virtual ~FWCSCStripDigiProxyBuilder() {}
00029 
00030   REGISTER_PROXYBUILDER_METHODS();
00031 
00032 private:
00033   virtual void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*);
00034   FWCSCStripDigiProxyBuilder(const FWCSCStripDigiProxyBuilder&);    
00035   const FWCSCStripDigiProxyBuilder& operator=(const FWCSCStripDigiProxyBuilder&);
00036 };
00037 
00038 void
00039 FWCSCStripDigiProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*)
00040 {
00041    const CSCStripDigiCollection* digis = 0;
00042   
00043    iItem->get(digis);
00044 
00045    if( ! digis ) 
00046    {
00047       fwLog( fwlog::kWarning ) << "failed to get CSCStripDigis"<<std::endl;
00048       return;
00049    }
00050    const FWGeometry *geom = iItem->getGeom();
00051 
00052    int thresholdOffset = 9;       
00053 
00054    for ( CSCStripDigiCollection::DigiRangeIterator dri = digis->begin(), driEnd = digis->end();
00055          dri != driEnd; ++dri )
00056    {    
00057       unsigned int rawid = (*dri).first.rawId();
00058       const CSCStripDigiCollection::Range& range = (*dri).second;
00059 
00060       if( ! geom->contains( rawid ))
00061       {
00062          fwLog( fwlog::kWarning ) << "failed to get geometry of CSC with detid: "
00063                                   << rawid << std::endl;
00064 
00065          TEveCompound* compound = createCompound();
00066          setupAddElement( compound, product );
00067 
00068          continue;
00069       }
00070      
00071       const float* shape = geom->getShapePars( rawid );
00072       float length = shape[4];
00073 
00074       const float* parameters = geom->getParameters( rawid );
00075 
00076       float yAxisOrientation = parameters[0];
00077       float centreToIntersection = parameters[1];
00078       float yCentre = parameters[2];
00079       float phiOfOneEdge = parameters[3];
00080       float stripOffset = parameters[4];
00081       float angularWidth = parameters[5];
00082 
00083       for( CSCStripDigiCollection::const_iterator dit = range.first;
00084            dit != range.second; ++dit )
00085       {
00086          std::vector<int> adcCounts = (*dit).getADCCounts();
00087       
00088          int signalThreshold = (adcCounts[0] + adcCounts[1])/2 + thresholdOffset;  
00089         
00090          TEveStraightLineSet* stripDigiSet = new TEveStraightLineSet();
00091          setupAddElement(stripDigiSet, product);
00092              
00093          if( std::find_if( adcCounts.begin(), adcCounts.end(), bind2nd( std::greater<int>(), signalThreshold )) != adcCounts.end()) 
00094          {
00095             stripDigiSet->SetLineWidth(3);
00096             int stripId = (*dit).getStrip();  
00097 
00098             float yOrigin = centreToIntersection-yCentre;      
00099             float stripAngle = phiOfOneEdge + yAxisOrientation*(stripId-(0.5-stripOffset))*angularWidth;
00100             float tanStripAngle = tan(stripAngle);
00101             //float xOfStrip = yAxisOrientation*yOrigin*tanStripAngle; this is x of strip at origin
00102              
00103             float localPointTop[3] = 
00104               {
00105                 yAxisOrientation*(yOrigin+length)*tanStripAngle, length, 0.0
00106               };
00107 
00108             float localPointBottom[3] = 
00109               {
00110                 yAxisOrientation*(yOrigin-length)*tanStripAngle, -length, 0.0
00111               };
00112       
00113             float globalPointTop[3];
00114             float globalPointBottom[3];
00115         
00116             geom->localToGlobal( rawid, localPointTop, globalPointTop, localPointBottom, globalPointBottom);
00117         
00118             stripDigiSet->AddLine( globalPointBottom[0], globalPointBottom[1], globalPointBottom[2],
00119                                    globalPointTop[0], globalPointTop[1], globalPointTop[2] );
00120          }
00121       }       
00122    }   
00123 }
00124 
00125 REGISTER_FWPROXYBUILDER(FWCSCStripDigiProxyBuilder, CSCStripDigiCollection, "CSCStripDigi", 
00126                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);
00127