CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCWireGeometry.cc
Go to the documentation of this file.
2 
4 
5 #include <cmath>
6 
8  float m2, float c2 ) const {
9 
10  // Calculate the point of intersection of two straight lines (in 2-dim)
11  // BEWARE! Do not call with m1 = m2 ! No trapping !
12 
13  float x = (c2-c1)/(m1-m2);
14  float y = (m1*c2-m2*c1)/(m1-m2);
15  return LocalPoint( x, y );
16 }
17 
18 std::vector<float> CSCWireGeometry::wireValues( float wire ) const {
19 
20  // return x and y of mid-point of wire, and length of wire, as 3-dim vector.
21  // If wire does not intersect active area the returned vector is filled with 0's.
22 
23  std::pair< LocalPoint, LocalPoint > ends = wireEnds( wire );
24 
25  std::vector<float> buf(3); // note all elem init to 0
26 
27  buf[0] = (ends.first.x() + ends.second.x())/2.; // x is first elem of first & second pairs
28  buf[1] = (ends.first.y() + ends.second.y())/2.; // y is second elem of first & second pairs
29  float d2 = (ends.first.x() - ends.second.x()) * (ends.first.x() - ends.second.x()) +
30  (ends.first.y() - ends.second.y()) * (ends.first.y() - ends.second.y());
31  buf[2] = sqrt(d2) ;
32  return buf;
33 }
34 
35 std::pair< LocalPoint, LocalPoint > CSCWireGeometry::wireEnds( float wire ) const {
36 
37  // return local (x, y) of each end of wire.
38  // If wire does not intersect active area set all values to 0.
39 
40  const float fprec = 1.E-06;
41 
42  // slope of wire
43  float wangle = wireAngle();
44  float mw = 0;
45  if ( fabs(wangle) > fprec ) mw = tan( wireAngle() );
46 
47  // intercept of wire
48  float cw = yOfWire( wire );
49 
50  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire=" << wire <<
51  ", wire angle = " << wangle <<
52  ", intercept on y axis=" << cw;
53 
54  // Find extent of wire plane
55  double ww = wideWidthOfPlane();
56  double nw = narrowWidthOfPlane();
57  double len = lengthOfPlane();
58 
59  // slope & intercept of line defining one non-parallel edge of wire-plane trapezoid
60  float m1 = 2.*len/(ww-nw);
61  float c1 = 0.;
62  if ( fabs(wangle) < fprec ) {
63  c1 = yOfFirstWire() - nw*len/(ww-nw) ; // non-ME11
64  }
65  else {
66  c1 = -len/2. - nw*len/(ww-nw); // ME11
67  }
68 
69  // slope & intercept of other non-parallel edge of wire-plane trapezoid
70  float m2 = -m1;
71  float c2 = c1;
72 
73  // wire intersects edge 1 at
74  LocalPoint pw1 = intersection(mw, cw, m1, c1);
75  // wire intersects edge 2 at
76  LocalPoint pw2 = intersection(mw, cw, m2, c2);
77 
78  float x1 = pw1.x();
79  float y1 = pw1.y();
80 
81  float x2 = pw2.x();
82  float y2 = pw2.y();
83 
84  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire intersects edges of plane at " <<
85  "\n x1=" << x1 << " y1=" << y1 <<
86  " x2=" << x2 << " y2=" << y2;
87 
88  // WIRES ARE NOT TILTED?
89 
90  if ( fabs(wangle) < fprec ) {
91 
92  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wires are not tilted ";
93  return std::pair< LocalPoint, LocalPoint >( LocalPoint(x1,y1), LocalPoint(x2,y2) );
94  }
95 
96  // WIRES ARE TILTED
97 
98  // ht and hb will be used to check where wire intersects edges of wire plane
99  float ht = ww/2. ;
100  float hb = nw/2. ;
101  float mt = 0.; // slope of top edge
102  float mb = 0.; //slope of bottom edge
103  float cb = -len/2.; // intercept bottom edge of wire plane
104  float ct = len/2.; // intercept top edge of wire plane
105 
106  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: slopes & intercepts " <<
107  "\n mt=" << mt << " ct=" << ct << " mb=" << mb << " cb=" << cb <<
108  "\n m1=" << m1 << " c1=" << c1 << " m2=" << m2 << " c2=" << c2 <<
109  "\n mw=" << mw << " cw=" << cw;
110 
111  // wire intersects top edge at
112  LocalPoint pwt = intersection(mw, cw, mt, ct);
113  // wire intersects bottom edge at
114  LocalPoint pwb = intersection(mw, cw, mb, cb);
115 
116  // get the local coordinates
117  float xt = pwt.x();
118  float yt = pwt.y();
119 
120  float xb = pwb.x();
121  float yb = pwb.y();
122 
123  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire intersects top & bottom of wire plane at " <<
124  "\n xt=" << xt << " yt=" << yt <<
125  " xb=" << xb << " yb=" << yb ;
126 
127  float xWireEnd[4], yWireEnd[4];
128 
129  int i = 0;
130  if ( fabs(x1) >= hb && fabs(x1) <= ht ) {
131  // wire does intersect side edge 1 of wire plane
132  xWireEnd[i] = x1;
133  yWireEnd[i] = y1;
134  i++;
135  }
136  if ( fabs(xb) <= hb ) {
137  // wire does intersect bottom edge of wire plane
138  xWireEnd[i] = xb;
139  yWireEnd[i] = yb;
140  i++;
141  }
142  if ( fabs(x2) >= hb && fabs(x2) <= ht ) {
143  // wire does intersect side edge 2 of wire plane
144  xWireEnd[i] = x2;
145  yWireEnd[i] = y2;
146  i++;
147  }
148  if ( fabs(xt) <= ht ) {
149  // wire does intersect top edge of wire plane
150  xWireEnd[i] = xt;
151  yWireEnd[i] = yt;
152  i++;
153  }
154 
155  if ( i != 2 ) {
156  // the wire does not intersect the wire plane (!)
157 
158  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire does not intersect wire plane!!";
159  // throw cms::Exception("BadCSCGeometry") << "the wire has " << i <<
160  // " ends!" << "\n";
161 
162  return std::pair< LocalPoint, LocalPoint >( LocalPoint(0.,0.), LocalPoint(0.,0.) );
163  }
164 
165  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: ME11 wire ends ";
166  for ( int j = 0; j<i; j++ ) {
167  LogTrace("CSCWireGeometry|CSC") << " x = " << xWireEnd[j] << " y = " << yWireEnd[j];
168  }
169 
170  return std::pair< LocalPoint, LocalPoint >
171  ( LocalPoint(xWireEnd[0],yWireEnd[0]), LocalPoint(xWireEnd[1],yWireEnd[1]) );
172 }
173 
174 //@@ COULD/SHOULD BE IMPLEMENTED IN Slanted & Nonslanted DERIVED CLASSES
175 
176 std::pair<float, float> CSCWireGeometry::equationOfWire( float wire ) const {
177 
178  const float fprec = 1.E-06;
179 
180  // slope of wire
181  float wangle = wireAngle();
182  float mw = 0;
183  if ( fabs(wangle) > fprec ) mw = tan( wangle );
184 
185  // intercept of wire
186  float cw = yOfWire( wire );
187 
188  LogTrace("CSCWireGeometry|CSC") << "CSCWireGeometry: wire=" << wire <<
189  ", wire angle = " << wangle <<
190  ", intercept on y axis=" << cw;
191 
192  return std::pair<float,float>(mw, cw);
193 }
194 
195 //@@ COULD/SHOULD BE IMPLEMENTED IN Slanted & Nonslanted DERIVED CLASSES
196 
197 std::pair<float, float> CSCWireGeometry::yLimitsOfWirePlane() const{
198 
199  const float fprec = 0.1; // wire angle is either 0 or 29 degrees = 0.506 rads
200  float ylow = yOfFirstWire(); // non-ME11 chambers
201  float wangle = wireAngle();
202  if ( fabs(wangle) > fprec ) {
203  ylow += tan( std::abs(wangle) ) * narrowWidthOfPlane()/2.; // correction for ME11
204  }
205  float yhigh = ylow + lengthOfPlane(); // add extent of wire plane in y
206 
207  return std::pair<float, float>(ylow, yhigh);
208 }
209 
int i
Definition: DBlmapReader.cc:9
double narrowWidthOfPlane() const
double wideWidthOfPlane() const
T y() const
Definition: PV3DBase.h:63
std::vector< float > wireValues(float wire) const
virtual float yOfWire(float wire, float x=0.) const =0
tuple c2
Definition: counter.py:145
std::pair< float, float > yLimitsOfWirePlane() const
T sqrt(T t)
Definition: SSEVec.h:48
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< LocalPoint, LocalPoint > wireEnds(float wire) const
int j
Definition: DBlmapReader.cc:9
double lengthOfPlane() const
#define LogTrace(id)
LocalPoint intersection(float m1, float c1, float m2, float c2) const
double yOfFirstWire() const
std::pair< float, float > equationOfWire(float wire) const
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:62
virtual float wireAngle() const =0