GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
FixedDiskLayoutBase.cc
1 #include "gearimpl/FixedDiskLayoutBase.h"
2 
3 #include <cmath>
4 #include <iostream>
5 #include <sstream>
6 #include <stdexcept>
7 
8 namespace gear {
9 
10 
12 {
13 // std::cerr << "FixedDiskLayoutBase::getPadLayoutType() : Warning: " <<std::endl
14 // << " This is deprecated (ambiguous for polar coordinate systems)"<< std::endl
15 // << " Please use getCoordinateType() or getPadLayoutImplType() "<< std::endl;
16  return getCoordinateType();
17 }
18 
19 
20 double FixedDiskLayoutBase::getDistanceToPad(double r, double phi, int padIndex) const
21 {
22  // calculate the outer coordinates of the pad (for code readability)
23  Vector2D padCenter = getPadCenter( padIndex);
24 
25  double r_min = padCenter[0] - getRowHeight( getRowNumber(padIndex) ) /2.;
26  double r_max = padCenter[0] + getRowHeight( getRowNumber(padIndex) ) /2.;
27  double phi_min = padCenter[1]- getPadPitch( padIndex ) /2.;
28  double phi_max = padCenter[1]+ getPadPitch( padIndex ) /2.;
29 
30 // if( (r < padCenter[0] - _rowHeight/2.) || (r > padCenter[0] + _rowHeight/2.) ||
31 // (phi < padCenter[1]- _padAngle/2.) || (phi < padCenter[1]+_padAngle/2. ) )
32  if ( (phi >= phi_min) && (phi <= phi_max ) )
33  {
34  // this is the easy part, it's just distances in r
35  if( (r >= r_min) && (r <= r_max) )
36  // we are inside the pad
37  return 0.;
38  else
39  {
40  if (r < r_min)
41  return r_min - r;
42  else
43  return r - r_max;
44  }
45  }
46  else // this is more complicated
47  {
48  // calculate pca to straight line along radius with phi_min;
49 
50  // determine r_intersect for x = r_intersect * cos(_phiMin) = r* cos(phi) - m * sin(_phiMin)
51  // y = r_intersect * sin(_phiMin) = r*sin(phi) + m * cos(_phiMin)
52  // solve this to r_intersect and m
53  double r_intersect_phiMin = r * (cos(phi)*cos(phi_min) + sin(phi)*sin(phi_min));
54  double m_phiMin = r * (cos(phi)*sin(phi_min) - sin(phi)*cos(phi_min));
55 
56  double distance_phiMin;
57  if ( r_intersect_phiMin < r_min )
58  {
59  // you can check this formula by calculaing sqrt( (x-x_min)^2 - (y-y_min)^2 )
60  // where x_min = r_min cos(phi_min) etc.
61  distance_phiMin = sqrt( r*r + r_min*r_min -2 * r_min * r_intersect_phiMin );
62  }
63  else
64  if ( r_intersect_phiMin > r_max )
65  {
66  distance_phiMin = sqrt( r*r + r_max*r_max -2 * r_max * r_intersect_phiMin );
67  }
68  else
69  distance_phiMin = fabs( m_phiMin );
70 
71 
72  // now the same for _phiMax
73  double r_intersect_phiMax = r * (cos(phi)*cos(phi_max) + sin(phi)*sin(phi_max));
74  double m_phiMax = r * (cos(phi)*sin(phi_max) - sin(phi)*cos(phi_max));
75 
76  double distance_phiMax;
77  if ( r_intersect_phiMax < r_min )
78  {
79  // you can check this formula by calculaing sqrt( (x-x_max)^2 - (y-y_max)^2 )
80  // where x_max = r_min cos(phi_max) etc.
81  distance_phiMax = sqrt( r*r + r_min*r_min -2 * r_min * r_intersect_phiMax );
82  }
83  else
84  if ( r_intersect_phiMax > r_max )
85  {
86  distance_phiMax = sqrt( r*r + r_max*r_max -2 * r_max * r_intersect_phiMax );
87  }
88  else
89  distance_phiMax = fabs( m_phiMax );
90 
91  return (distance_phiMin < distance_phiMax ? distance_phiMin : distance_phiMax);
92 
93  } //else within phi range
94 
95 
96 }
97 
98 } // namespace
99 
virtual double getDistanceToPad(double c0, double c1, int padIndex) const
Returns the closest distance to the edge (outer border) of the pad.
virtual double getRowHeight(int rowNumber) const =0
The row height in mm.
virtual int getPadLayoutType() const
virtual int getCoordinateType() const
The type of the row layouts coordinate system: PadRowLayout2D.POLAR.
virtual double getPadPitch(int padIndex) const =0
The pitch (i.
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex.
virtual Vector2D getPadCenter(int padIndex) const =0
The center of the pad in 2d coordinates, (x,y) or (r,phi).