CMS 3D CMS Logo

TangentCircle.cc
Go to the documentation of this file.
3 
4 #define PI 3.1415926
5 
6 // TODO: is not valid don't do any calculations and return init values
8  : theInnerPoint(inner), theOuterPoint(outer), theVertexPoint(inner) {
10  valid = false;
11  } else
12  valid = true;
13 
14  double x1 = inner.x();
15  double y1 = inner.y();
16  double x2 = outer.x();
17  double y2 = outer.y();
18  double alpha1 = (direction.y() != 0) ? atan(-direction.x() / direction.y()) : PI / 2;
19  double denominator = 2 * ((x1 - x2) * cos(alpha1) + (y1 - y2) * sin(alpha1));
20  theRho = (denominator != 0) ? ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) / denominator : 1E12;
21 
22  // TODO : variable not yet calculated look in nucl.C
23  theX0 = 1E10;
24  theY0 = 1E10;
25 
28 
29  //theCharge = (theRho>0) ? -1 : 1;
30 
31  theCharge = 0;
32  theRho = fabs(theRho);
33 
35 }
36 
38  const GlobalPoint& innerPoint,
39  const GlobalPoint& vertexPoint)
40  : theInnerPoint(innerPoint), theOuterPoint(outerPoint), theVertexPoint(vertexPoint) {
42  theX0 = circle.x0();
43  theY0 = circle.y0();
44  theRho = circle.rho();
45  theVertexError = 0;
46  theCharge = 0;
47  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
48  if (theInnerPoint.perp2() > theOuterPoint.perp2() || !circle.isValid()) {
49  valid = false;
50  } else
51  valid = true;
52 }
53 
55  const GlobalPoint& outerPoint,
56  const GlobalPoint& innerPoint) {
58  valid = false;
59  } else
60  valid = true;
61 
62  int NITER = 10;
63 
64  // Initial vertex used = outerPoint of the primary circle (should be the first estimation of the nuclear interaction position)
65  GlobalPoint InitialVertex(primCircle.outerPoint().x(), primCircle.outerPoint().y(), 0);
66  GlobalPoint SecInnerPoint(innerPoint.x(), innerPoint.y(), 0);
67  GlobalPoint SecOuterPoint(outerPoint.x(), outerPoint.y(), 0);
68 
69  // distance between the initial vertex and the inner point of the secondary circle
70  double s = (SecInnerPoint - InitialVertex).mag();
71  double deltaTheta = s / primCircle.rho();
72 
73  double minTangentCondition = 1E12;
74  TangentCircle theCorrectSecCircle;
75  GlobalPoint vertex = InitialVertex;
76  int dir = 1;
77  double theta = deltaTheta / (NITER - 1);
78 
79  for (int i = 0; i < NITER; i++) {
80  // get the circle which pass through outerPoint, innerPoint and the vertex
81  TangentCircle secCircle(SecOuterPoint, SecInnerPoint, vertex);
82 
83  // get a value relative to the tangentness of the 2 circles
84  double minCond = isTangent(primCircle, secCircle);
85 
86  // double dirDiff = (primCircle.direction(vertex) - secCircle.direction(vertex)).mag();
87  // if( dirDiff > 1) dirDiff = 2-dirDiff;
88 
89  if (minCond < minTangentCondition) {
90  minTangentCondition = minCond;
91  theCorrectSecCircle = secCircle;
92  vertex = getPosition(primCircle, secCircle.vertexPoint(), theta, dir);
93  if (i == 0 && ((vertex - SecInnerPoint).mag() > (InitialVertex - SecInnerPoint).mag())) {
94  dir = -1;
95  vertex = getPosition(primCircle, InitialVertex, theta, dir);
96  LogDebug("NuclearSeedGenerator") << "Change direction to look for vertex"
97  << "\n";
98  }
99  } else
100  break;
101  }
102  theInnerPoint = theCorrectSecCircle.innerPoint();
103  theOuterPoint = theCorrectSecCircle.outerPoint();
104  theVertexPoint = theCorrectSecCircle.vertexPoint();
105  theX0 = theCorrectSecCircle.x0();
106  theY0 = theCorrectSecCircle.y0();
107  theRho = theCorrectSecCircle.rho();
108  theCharge = 0;
109  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
110 
111  theVertexError = s / NITER;
112 }
113 
114 double TangentCircle::isTangent(const TangentCircle& primCircle, const TangentCircle& secCircle) const {
115  // return a value that should be equal to 0 if primCircle and secCircle are tangent
116 
117  double distanceBetweenCircle = (primCircle.x0() - secCircle.x0()) * (primCircle.x0() - secCircle.x0()) +
118  (primCircle.y0() - secCircle.y0()) * (primCircle.y0() - secCircle.y0());
119  double RadiusSum = (primCircle.rho() + secCircle.rho()) * (primCircle.rho() + secCircle.rho());
120  double RadiusDifference = (primCircle.rho() - secCircle.rho()) * (primCircle.rho() - secCircle.rho());
121 
122  return std::min(fabs(RadiusSum - distanceBetweenCircle), fabs(RadiusDifference - distanceBetweenCircle));
123 }
124 
126  if (theY0 > 1E9 || theX0 > 1E9) {
127  LogDebug("NuclearSeedGenerator") << "Center of TangentCircle not calculated but used !!!"
128  << "\n";
129  }
130 
131  // calculate the direction perpendicular to the vector v = point - center_of_circle
132  GlobalVector dir(point.y() - theY0, theX0 - point.x(), 0);
133 
134  dir /= dir.mag();
135 
136  // Check the sign :
138  double diff = (dir - fastDir).mag();
139  double sum = (dir + fastDir).mag();
140 
141  if (sum < diff)
142  dir = (-1) * dir;
143 
144  return dir;
145 }
146 
148  if (theDirectionAtVertex.x() > 999)
150  return theDirectionAtVertex;
151 }
152 
154  const GlobalPoint& initalPosition,
155  double theta,
156  int dir) const {
157  int sign[3];
158  double x2 = initalPosition.x();
159  double y2 = initalPosition.y();
160 
161  if ((x2 > circle.x0()) && dir > 0) {
162  sign[0] = 1;
163  sign[1] = -1;
164  sign[2] = -1;
165  }
166  if ((x2 > circle.x0()) && dir < 0) {
167  sign[0] = 1;
168  sign[1] = 1;
169  sign[2] = 1;
170  }
171  if ((x2 < circle.x0()) && dir > 0) {
172  sign[0] = -1;
173  sign[1] = 1;
174  sign[2] = -1;
175  }
176  if ((x2 < circle.x0()) && dir < 0) {
177  sign[0] = -1;
178  sign[1] = -1;
179  sign[2] = 1;
180  }
181 
182  double l = 2 * circle.rho() * sin(theta / 2);
183  double alpha = atan((y2 - circle.y0()) / (x2 - circle.x0()));
184  double beta = PI / 2 - theta / 2;
185  double gamma = PI + sign[2] * alpha - beta;
186 
187  double xnew = x2 + sign[0] * l * cos(gamma);
188  double ynew = y2 + sign[1] * l * sin(gamma);
189 
190  return GlobalPoint(xnew, ynew, 0);
191 }
192 
197  return fabs(1 / circle1.rho() - 1 / circle2.rho());
198  } else {
201  return fabs(1 / circle1.rho() - 1 / circle2.rho());
202  }
203 }
204 
205 int TangentCircle::charge(float magz) {
206  if (theCharge != 0)
207  return theCharge;
208 
209  if (theX0 > 1E9 || theY0 > 1E9)
211  else {
212  GlobalPoint center(theX0, theY0, 0);
213  GlobalVector u = center - theVertexPoint;
215 
216  // F = force vector
217  GlobalVector F(v.y() * magz, -v.x() * magz, 0);
218  if (u.x() * F.x() + u.y() * F.y() > 0)
219  theCharge = -1;
220  else
221  theCharge = 1;
222 
223  if (theCharge != chargeLocally(magz, v)) {
224  LogDebug("NuclearSeedGenerator") << "Inconsistency in calculation of the charge"
225  << "\n";
226  }
227  }
228  return theCharge;
229 }
230 
233  double tz = v.x() * u.y() - v.y() * u.x();
234 
235  if (tz * magz > 0)
236  return 1;
237  else
238  return -1;
239 }
double curvatureError()
GlobalPoint getPosition(const TangentCircle &circle, const GlobalPoint &initalPosition, double theta, int direction) const
int chargeLocally(float magz, GlobalVector v) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint vertexPoint() const
Definition: TangentCircle.h:48
GlobalPoint outerPoint() const
Definition: TangentCircle.h:44
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
bool isValid() const
Definition: FastCircle.h:49
GlobalPoint theVertexPoint
Definition: TangentCircle.h:59
GlobalPoint theOuterPoint
Definition: TangentCircle.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
T mag() const
Definition: PV3DBase.h:64
double isTangent(const TangentCircle &primCircle, const TangentCircle &secCircle) const
double rho() const
Definition: TangentCircle.h:42
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalPoint innerPoint() const
Definition: TangentCircle.h:46
GlobalVector directionAtVertex()
Return the direction at the vertex.
double y0() const
Definition: FastCircle.h:45
T perp2() const
Definition: PV3DBase.h:68
GlobalPoint theInnerPoint
Definition: TangentCircle.h:57
double rho() const
Definition: FastCircle.h:47
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:61
double x0() const
Definition: TangentCircle.h:38
double y0() const
Definition: TangentCircle.h:40
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
double theVertexError
Definition: TangentCircle.h:67
int charge(float magz)
GlobalVector direction(const GlobalPoint &point) const
Geom::Theta< T > theta() const
double x0() const
Definition: FastCircle.h:43
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
Global3DVector GlobalVector
Definition: GlobalVector.h:10
#define LogDebug(id)