CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Geometry/CSCGeometry/src/CSCWireGeometry.cc

Go to the documentation of this file.
00001 #include "Geometry/CSCGeometry/interface/CSCWireGeometry.h"
00002 
00003 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00004 
00005 #include <cmath>
00006 
00007 LocalPoint CSCWireGeometry::intersection( float m1, float c1,
00008                                           float m2, float c2 ) const {
00009 
00010   // Calculate the point of intersection of two straight lines (in 2-dim)
00011   // BEWARE! Do not call with m1 = m2 ! No trapping !
00012 
00013   float x = (c2-c1)/(m1-m2);
00014   float y = (m1*c2-m2*c1)/(m1-m2);
00015   return LocalPoint( x, y );
00016 }
00017 
00018 std::vector<float> CSCWireGeometry::wireValues( float wire ) const {
00019 
00020   // return x and y of mid-point of wire, and length of wire, as 3-dim vector.
00021   // If wire does not intersect active area the returned vector is filled with 0's.
00022 
00023   std::pair< LocalPoint, LocalPoint > ends = wireEnds( wire );
00024 
00025   std::vector<float> buf(3); // note all elem init to 0
00026   
00027   buf[0] = (ends.first.x() + ends.second.x())/2.; // x is first elem of first & second pairs
00028   buf[1] = (ends.first.y() + ends.second.y())/2.; // y is second elem of first & second pairs
00029   float d2 = (ends.first.x() - ends.second.x()) * (ends.first.x() - ends.second.x()) +
00030              (ends.first.y() - ends.second.y()) * (ends.first.y() - ends.second.y());
00031   buf[2] = sqrt(d2) ;
00032   return buf;
00033 }
00034 
00035 std::pair< LocalPoint, LocalPoint > CSCWireGeometry::wireEnds( float wire ) const {
00036 
00037   // return local (x, y) of each end of wire.
00038   // If wire does not intersect active area set all values to 0.
00039   
00040   const float fprec = 1.E-06;
00041 
00042   // slope of wire
00043   float wangle = wireAngle();
00044   float mw = 0;
00045   if ( fabs(wangle) > fprec ) mw = tan( wireAngle() );
00046 
00047   // intercept of wire
00048   float cw = yOfWire( wire );
00049   
00050   LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire=" << wire <<
00051     ", wire angle = " << wangle <<
00052     ", intercept on y axis=" << cw;
00053   
00054   // Find extent of wire plane
00055   double ww = wideWidthOfPlane();
00056   double nw = narrowWidthOfPlane();
00057   double len = lengthOfPlane();
00058   
00059   // slope & intercept of line defining one non-parallel edge of wire-plane trapezoid
00060   float m1 = 2.*len/(ww-nw);
00061   float c1 = 0.;
00062   if ( fabs(wangle) < fprec ) {
00063     c1 = yOfFirstWire() - nw*len/(ww-nw) ; // non-ME11
00064   }
00065   else {
00066     c1 = -len/2. - nw*len/(ww-nw); // ME11
00067   }
00068 
00069   // slope & intercept of other non-parallel edge of wire-plane trapezoid
00070   float m2 = -m1;
00071   float c2 =  c1;
00072 
00073   // wire intersects edge 1 at
00074   LocalPoint pw1 = intersection(mw, cw, m1, c1);
00075   // wire intersects edge 2 at
00076   LocalPoint pw2 = intersection(mw, cw, m2, c2);
00077 
00078   float x1 = pw1.x();
00079   float y1 = pw1.y();
00080 
00081   float x2 = pw2.x();
00082   float y2 = pw2.y();
00083 
00084   LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire intersects edges of plane at " <<
00085     "\n  x1=" << x1 << " y1=" << y1 <<
00086     " x2=" << x2 << " y2=" << y2;
00087   
00088   // WIRES ARE NOT TILTED?
00089 
00090   if ( fabs(wangle) < fprec ) {
00091 
00092     LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wires are not tilted ";
00093     return std::pair< LocalPoint, LocalPoint >( LocalPoint(x1,y1), LocalPoint(x2,y2) );  
00094   }
00095   
00096   // WIRES ARE TILTED
00097 
00098   // ht and hb will be used to check where wire intersects edges of wire plane
00099   float ht = ww/2. ;
00100   float hb = nw/2. ;
00101   float mt = 0.; // slope of top edge
00102   float mb = 0.; //slope of bottom edge
00103   float cb = -len/2.; // intercept bottom edge of wire plane
00104   float ct =  len/2.; // intercept top edge of wire plane
00105   
00106   LogTrace("CSCWireGeometry|CSC") <<  "CSCWireGeometry: slopes & intercepts " <<
00107     "\n  mt=" << mt << " ct=" << ct << " mb=" << mb << " cb=" << cb <<
00108     "\n  m1=" << m1 << " c1=" << c1 << " m2=" << m2 << " c2=" << c2 <<
00109     "\n  mw=" << mw << " cw=" << cw;
00110   
00111   // wire intersects top edge at
00112   LocalPoint pwt = intersection(mw, cw, mt, ct);
00113   // wire intersects bottom edge at
00114   LocalPoint pwb = intersection(mw, cw, mb, cb);
00115   
00116   // get the local coordinates
00117   float xt = pwt.x();
00118   float yt = pwt.y();
00119   
00120   float xb = pwb.x();
00121   float yb = pwb.y();
00122   
00123   LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire intersects top & bottom of wire plane at " <<
00124     "\n  xt=" << xt << " yt=" << yt <<
00125     " xb=" << xb << " yb=" << yb ;
00126   
00127   float xWireEnd[4], yWireEnd[4];
00128   
00129   int i = 0;
00130   if ( fabs(x1) >= hb && fabs(x1) <= ht ) {
00131     // wire does intersect side edge 1 of wire plane
00132     xWireEnd[i] = x1;
00133     yWireEnd[i] = y1;
00134     i++;
00135   }
00136   if ( fabs(xb) <= hb ) {
00137     // wire does intersect bottom edge of wire plane
00138     xWireEnd[i] = xb;
00139     yWireEnd[i] = yb;
00140     i++;
00141   }
00142   if ( fabs(x2) >= hb && fabs(x2) <= ht ) {
00143     // wire does intersect side edge 2 of wire plane
00144     xWireEnd[i] = x2;
00145     yWireEnd[i] = y2;
00146     i++;
00147   }
00148   if ( fabs(xt) <= ht ) {
00149     // wire does intersect top edge of wire plane
00150     xWireEnd[i] = xt;
00151     yWireEnd[i] = yt;
00152     i++;
00153   }
00154   
00155   if ( i != 2 ) {
00156     // the wire does not intersect the wire plane (!)
00157 
00158     LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire does not intersect wire plane!!";
00159     //     throw cms::Exception("BadCSCGeometry") << "the wire has " << i <<
00160     //       " ends!" << "\n";
00161 
00162     return std::pair< LocalPoint, LocalPoint >( LocalPoint(0.,0.), LocalPoint(0.,0.) ); 
00163   }
00164   
00165   LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: ME11 wire ends ";
00166   for ( int j = 0; j<i; j++ ) {
00167     LogTrace("CSCWireGeometry|CSC") << "  x = " << xWireEnd[j] << " y = " << yWireEnd[j];
00168   }
00169 
00170   return std::pair< LocalPoint, LocalPoint >
00171    ( LocalPoint(xWireEnd[0],yWireEnd[0]), LocalPoint(xWireEnd[1],yWireEnd[1]) );  
00172 }
00173 
00174 //@@ COULD/SHOULD BE IMPLEMENTED IN Slanted & Nonslanted DERIVED CLASSES
00175 
00176 std::pair<float, float> CSCWireGeometry::equationOfWire( float wire ) const {
00177   
00178   const float fprec = 1.E-06;
00179 
00180   // slope of wire
00181   float wangle = wireAngle(); 
00182   float mw = 0;
00183   if ( fabs(wangle) > fprec ) mw = tan( wangle );
00184 
00185   // intercept of wire
00186   float cw = yOfWire( wire );
00187 
00188   LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire=" << wire <<
00189     ", wire angle = " << wangle <<
00190     ", intercept on y axis=" << cw;
00191 
00192   return std::pair<float,float>(mw, cw);
00193 }
00194 
00195 //@@ COULD/SHOULD BE IMPLEMENTED IN Slanted & Nonslanted DERIVED CLASSES
00196 
00197 std::pair<float, float> CSCWireGeometry::yLimitsOfWirePlane() const{
00198 
00199   const float fprec = 0.1; // wire angle is either 0 or 29 degrees = 0.506 rads
00200   float ylow = yOfFirstWire(); // non-ME11 chambers
00201   float wangle = wireAngle();  
00202   if ( fabs(wangle) > fprec ) {
00203     ylow += tan( wangle ) * narrowWidthOfPlane()/2.; // correction for ME11
00204   }
00205   float yhigh = ylow + lengthOfPlane(); // add extent of wire plane in y
00206   
00207   return std::pair<float, float>(ylow, yhigh);
00208 }
00209