ZetaPixel.cc
Go to the documentation of this file.
1 #include "ZetaPixel.h"
2 #include <utl/MathConstants.h>
3 #include <utl/AugerUnits.h>
4 #include <vector>
5 #include <cmath>
6 #include <algorithm>
7 #include <utl/TabulatedFunction.h>
8 
9 using namespace std;
10 using namespace utl;
11 using namespace FdEnergyDepositFinderKG;
12 
13 
14 //---------------------------------------------------
15 ZetaPixel::ZetaPixel(const unsigned int pixelId,
16  const double xPos, const double yPos,
17  const double sideLength, const double tiltAngle) :
18  fLightFraction(-1),
19  fPixelId(pixelId),
20  fCenterX(xPos),
21  fCenterY(yPos),
22  fSideLength(sideLength),
23  fTiltAngle(tiltAngle),
24  fCosTiltAngle(cos(tiltAngle)),
25  fSinTiltAngle(sin(tiltAngle))
26 {
28 }
29 
30 
31 //---------------------------------------------------
32 double
34  const double circleY,
35  const double circleRadius)
36  const
37 {
38  vector<double> phiVec = CircleIntersections(circleX, circleY, circleRadius);
39 
40  // if there is no intercept it is either all in or all out
41  if (phiVec.empty())
42  return IsInside(circleX, circleY+circleRadius) ? 1 : 0;
43 
44  phiVec.push_back(phiVec.front() + 2*kPi);
45 
46  double arcLength = 0.;
47  for (unsigned int i = 0, n = phiVec.size()-1; i < n; ++i) {
48  const double phi1 = phiVec[i];
49  const double phi2 = phiVec[i+1];
50  const double meanPhi = 0.5*(phi1 + phi2);
51  // check for inside or outside at middle of arc
52  if (IsInside(circleX + circleRadius*cos(meanPhi),
53  circleY + circleRadius*sin(meanPhi)))
54  arcLength += phi2 - phi1;
55  }
56  return 0.5*arcLength/kPi;
57 }
58 
59 
60 //---------------------------------------------------
61 vector<double>
62 ZetaPixel::CircleIntersections(const double circleX,
63  const double circleY,
64  const double circleRadius)
65  const
66 {
67  vector<double> intersectionPhi;
68 
69  const double r = circleRadius;
70  const double r2 = r*r;
71 
72  // loop over all sides, calculate circle-line intersections
73  // (see mathworld.wolfram.com/Circle-LineIntersection.html)
74  // and pick the ones that are on the hexagon
75 
76  for (unsigned int iSide = 0; iSide < 6; ++iSide) {
77 
78  const double x1 = fXCoordinates[iSide] - circleX;
79  const double y1 = fYCoordinates[iSide] - circleY;
80  const double x2 = fXCoordinates[iSide+1] - circleX;
81  const double y2 = fYCoordinates[iSide+1] - circleY;
82  const double dx = x2 - x1;
83  const double dy = y2 - y1;
84  const double dr2 = dx*dx + dy*dy;
85  const double D = x1*y2 - x2*y1;
86  const double D2 = D*D;
87  const double Delta = r2*dr2 - D2;
88  if (Delta > 0) {
89  const double signdy = (dy < 0 ? -1 : 1);
90  const double sqrtDelta = sqrt(Delta);
91  const double tx1 = D*dy;
92  const double tx2 = signdy*dx*sqrtDelta;
93  const double ty1 = -D*dx;
94  const double ty2 = fabs(dy)*sqrtDelta;
95 
96  const double xInter1 = (tx1 + tx2)/dr2 + circleX;
97  const double xInter2 = (tx1 - tx2)/dr2 + circleX;
98  const double yInter1 = (ty1 + ty2)/dr2 + circleY;
99  const double yInter2 = (ty1 - ty2)/dr2 + circleY;
100  if (IsInside(xInter1, yInter1)) {
101  double phi = atan2(yInter1-circleY, xInter1-circleX);
102  if (phi < 0)
103  phi += 2*kPi;
104  intersectionPhi.push_back(phi);
105  }
106  if (IsInside(xInter2, yInter2)) {
107  double phi = atan2(yInter2-circleY, xInter2-circleX);
108  if (phi < 0)
109  phi += 2*kPi;
110  intersectionPhi.push_back(phi);
111  }
112  }
113  }
114 
115  sort(intersectionPhi.begin(), intersectionPhi.end());
116 
117  return intersectionPhi;
118 }
119 
120 
121 //---------------------------------------------------
122 bool
123 ZetaPixel::IsInside(const double x, const double y)
124  const
125 {
126  const double safety = 1e-10;
127  const double cos30 = 0.5*kSqrt3;
128  const double tan30 = 1/kSqrt3;
129 
130  const double r = (1+safety)*fSideLength;
131  const double xx = x-fCenterX;
132  const double yy = y-fCenterY;
133  const double xxRot = fabs(fCosTiltAngle*xx +fSinTiltAngle*yy);
134  const double yyRot = fabs(-fSinTiltAngle*xx+fCosTiltAngle*yy);
135  const double xMax = cos30*r;
136 
137  // inside hexagon check
138  return (xxRot <= xMax && yyRot <= r-tan30*xxRot);
139 }
140 
141 
142 //---------------------------------------------------
143 void
145 {
146  double phi = 30.*degree + fTiltAngle;
147  for (unsigned int i = 0; i < 7; ++i) {
148  const double x = cos(phi)*fSideLength + fCenterX;
149  const double y = sin(phi)*fSideLength + fCenterY;
150  fXCoordinates.push_back(x);
151  fYCoordinates.push_back(y);
152  phi += 60*degree;
153  }
154 }
const double degree
bool IsInside(const double x, double y) const
check if point (x,y) is inside the hexagon
Definition: ZetaPixel.cc:123
constexpr double kPi
Definition: MathConstants.h:24
constexpr double kSqrt3
Definition: MathConstants.h:31
std::vector< double > CircleIntersections(const double circleX, const double circleY, const double circleRadius) const
get vector of intersections (phi angle) with a circle with
Definition: ZetaPixel.cc:62
double CalculateInsideArcLength(const double circleX, const double circleY, const double circleRadius) const
calculate arc length of a circle inside hexagon in units of r*2*pi
Definition: ZetaPixel.cc:33
std::vector< double > fXCoordinates
Definition: ZetaPixel.h:92
std::vector< double > fYCoordinates
Definition: ZetaPixel.h:93

, generated on Tue Sep 26 2023.