CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Fireworks/Muons/plugins/FWCSCWireDigiProxyBuilder.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Muon
00004 // Class  :     FWCSCWireDigiProxyBuilder
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author: mccauley
00010 //         Created:  Sun Jan  6 23:57:00 EST 2008
00011 // $Id: FWCSCWireDigiProxyBuilder.cc,v 1.20 2010/10/19 09:00:59 chrjones 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/CSCWireDigiCollection.h"
00023 
00024 #include <cmath>
00025 
00026 class FWCSCWireDigiProxyBuilder : public FWProxyBuilderBase
00027 {
00028 public:
00029   FWCSCWireDigiProxyBuilder() {}
00030   virtual ~FWCSCWireDigiProxyBuilder() {}
00031 
00032   REGISTER_PROXYBUILDER_METHODS();
00033 
00034 private:
00035   virtual void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*);
00036   FWCSCWireDigiProxyBuilder(const FWCSCWireDigiProxyBuilder&);    
00037   const FWCSCWireDigiProxyBuilder& operator=(const FWCSCWireDigiProxyBuilder&);
00038 
00039   // NOTE: these parameters are not available via a public interface
00040   // from the geometry or topology so must be hard-coded.
00041   double getYOfFirstWire(const int station, const int ring, const double length);
00042   double getAverageWireSpacing(const int station, const int ring);
00043 };
00044        
00045 double
00046 FWCSCWireDigiProxyBuilder::getYOfFirstWire(const int station, const int ring, const double length)                             
00047 {
00048   double yAlignmentFrame = 3.49;
00049   double alignmentPinToFirstWire;
00050 
00051   if ( station == 1 ) 
00052   { 
00053     if ( ring == 1 || ring == 4 )
00054     {
00055       alignmentPinToFirstWire = 1.065;
00056       yAlignmentFrame = 0.0;
00057     }
00058         
00059     else // ME12, ME 13 
00060       alignmentPinToFirstWire = 2.85;
00061   }
00062   
00063   else if ( station == 4 && ring == 1 )
00064     alignmentPinToFirstWire = 3.04;
00065       
00066   else if ( station == 3 && ring == 1 )
00067     alignmentPinToFirstWire =  2.84;
00068       
00069   else  // ME21, ME22, ME32, ME42 
00070     alignmentPinToFirstWire = 2.87;
00071   
00072   return (yAlignmentFrame-length) + alignmentPinToFirstWire;
00073 }
00074 
00075 double 
00076 FWCSCWireDigiProxyBuilder::getAverageWireSpacing(const int station, const int ring)
00077 {
00078   // return radialExtentOfTheWirePlane / numOfWireGroups
00079   // These numbers come from cscSpec.xml
00080 
00081   if ( ring == 2 )
00082   {
00083     if ( station == 1 )
00084       return 174.81/64;
00085     else
00086       return 323.38/64;
00087   }
00088   
00089   if ( station == 1 && (ring == 1 || ring == 4))
00090     return 150.5/48;
00091   if ( station == 1 && ring == 3 )
00092     return 164.47/32;
00093   if ( station == 2 && ring == 1 )
00094     return 189.97/112;
00095   if ( station == 3 && ring == 1 )
00096     return 170.01/96;
00097   if ( station == 4 && ring == 1 )
00098     return 149.73/96;
00099 
00100   return 0.0;
00101 }
00102 
00103 void
00104 FWCSCWireDigiProxyBuilder::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*)
00105 {
00106   const CSCWireDigiCollection* digis = 0;
00107  
00108   iItem->get(digis);
00109 
00110   if ( ! digis ) 
00111   {
00112     fwLog( fwlog::kWarning ) << "Failed to get CSCWireDigis" << std::endl;
00113     return;
00114   }
00115   const FWGeometry *geom = iItem->getGeom();
00116 
00117   for ( CSCWireDigiCollection::DigiRangeIterator dri = digis->begin(), driEnd = digis->end(); 
00118         dri != driEnd; ++dri )
00119   {
00120     const CSCDetId& cscDetId = (*dri).first;
00121     unsigned int rawid = cscDetId.rawId();
00122     const CSCWireDigiCollection::Range& range = (*dri).second;
00123  
00124     if( ! geom->contains( rawid ))
00125     {
00126       fwLog( fwlog::kWarning ) << "Failed to get geometry of CSC chamber with detid: "
00127                                << rawid << std::endl;
00128       
00129       TEveCompound* compound = createCompound();
00130       setupAddElement( compound, product );
00131 
00132       continue;
00133     }
00134 
00135     const float* shape = geom->getShapePars( rawid );
00136 
00137     float length = shape[4];
00138     float topWidth = shape[2];
00139     float bottomWidth = shape[1];
00140     
00141     // NOTE: do not use parameters right now: need to sort out what is finally needed 
00142     //const float* parameters = iItem->getGeom()->getParameters( rawid );
00143     //float wireSpacing  = parameters[6];
00144     double wireSpacing = getAverageWireSpacing(cscDetId.station(), cscDetId.ring());
00145     //float wireAngle    = parameters[7];
00146     //float cosWireAngle = cos(wireAngle);
00147 
00148     double yOfFirstWire = getYOfFirstWire( cscDetId.station(), cscDetId.ring(), length ); 
00149   
00150     for ( CSCWireDigiCollection::const_iterator dit = range.first;
00151           dit != range.second; ++dit )        
00152     { 
00153       TEveStraightLineSet* wireDigiSet = new TEveStraightLineSet();
00154       wireDigiSet->SetLineWidth(3);
00155       setupAddElement(wireDigiSet, product);
00156 
00157       int wireGroup = (*dit).getWireGroup();
00158       float yOfWire = yOfFirstWire + ((wireGroup-1)*wireSpacing);
00159       float wireLength = yOfWire*(topWidth-bottomWidth) / length;
00160       wireLength += bottomWidth*2.0;
00161      
00162       float localPointLeft[3] = 
00163       {
00164         static_cast<float>(-wireLength*0.5), yOfWire, static_cast<float>(0.0)
00165       };
00166 
00167       // NOTE: This is only an approximation for slanted wires.
00168       // Need to improve the determination of the x coordinate.
00169       float localPointRight[3] = 
00170       {
00171         static_cast<float>(wireLength*0.5), yOfWire, static_cast<float>(0.0)
00172         //wireLength*0.5, yOfWire + wireLength*tan(wireAngle), 0.0
00173       };
00174 
00175       float globalPointLeft[3];     
00176       float globalPointRight[3];
00177 
00178       geom->localToGlobal( rawid, localPointLeft, globalPointLeft, localPointRight, globalPointRight ); 
00179 
00180       wireDigiSet->AddLine( globalPointLeft[0],  globalPointLeft[1],  globalPointLeft[2],
00181                             globalPointRight[0], globalPointRight[1], globalPointRight[2] );
00182     }
00183   }
00184 }
00185 
00186 REGISTER_FWPROXYBUILDER(FWCSCWireDigiProxyBuilder, CSCWireDigiCollection, "CSCWireDigi", 
00187                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);
00188 
00189