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) {
9 
10  if(theInnerPoint.perp2() > theOuterPoint.perp2()) { valid = false; }
11  else valid=true;
12 
13  double x1 = inner.x();
14  double y1 = inner.y();
15  double x2 = outer.x();
16  double y2 = outer.y();
17  double alpha1 = (direction.y() != 0) ? atan(-direction.x()/direction.y()) : PI/2 ;
18  double denominator = 2*((x1-x2)*cos(alpha1)+(y1-y2)*sin(alpha1));
19  theRho = (denominator != 0) ? ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))/denominator : 1E12;
20 
21  // TODO : variable not yet calculated look in nucl.C
22  theX0 = 1E10;
23  theY0 = 1E10;
24 
27 
28  //theCharge = (theRho>0) ? -1 : 1;
29 
30  theCharge = 0;
31  theRho = fabs(theRho);
32 
34 }
35 
37  theInnerPoint(innerPoint), theOuterPoint(outerPoint), theVertexPoint(vertexPoint) {
38  FastCircle circle(outerPoint, innerPoint, vertexPoint);
39  theX0 = circle.x0();
40  theY0 = circle.y0();
41  theRho = circle.rho();
42  theVertexError = 0;
43  theCharge = 0;
44  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
45  if(theInnerPoint.perp2() > theOuterPoint.perp2() || !circle.isValid()) { valid = false; }
46  else valid=true;
47 }
48 
50 
51  if(theInnerPoint.perp2() > theOuterPoint.perp2()) { valid = false; }
52  else valid = true;
53 
54  int NITER = 10;
55 
56  // Initial vertex used = outerPoint of the primary circle (should be the first estimation of the nuclear interaction position)
57  GlobalPoint InitialVertex( primCircle.outerPoint().x() , primCircle.outerPoint().y(), 0);
58  GlobalPoint SecInnerPoint( innerPoint.x(), innerPoint.y(), 0);
59  GlobalPoint SecOuterPoint( outerPoint.x(), outerPoint.y(), 0);
60 
61  // distance between the initial vertex and the inner point of the secondary circle
62  double s = (SecInnerPoint - InitialVertex).mag();
63  double deltaTheta = s/primCircle.rho();
64 
65  double minTangentCondition = 1E12;
66  TangentCircle theCorrectSecCircle;
67  GlobalPoint vertex = InitialVertex;
68  int dir = 1;
69  double theta = deltaTheta/(NITER-1);
70 
71  for(int i=0; i<NITER; i++) {
72 
73  // get the circle which pass through outerPoint, innerPoint and the vertex
74  TangentCircle secCircle( SecOuterPoint, SecInnerPoint, vertex );
75 
76  // get a value relative to the tangentness of the 2 circles
77  double minCond = isTangent(primCircle, secCircle);
78 
79  // double dirDiff = (primCircle.direction(vertex) - secCircle.direction(vertex)).mag();
80  // if( dirDiff > 1) dirDiff = 2-dirDiff;
81 
82  if(minCond < minTangentCondition) {
83  minTangentCondition = minCond;
84  theCorrectSecCircle = secCircle;
85  vertex = getPosition( primCircle, secCircle.vertexPoint(), theta, dir );
86  if( i==0 && ((vertex-SecInnerPoint).mag() > (InitialVertex-SecInnerPoint).mag()) ) {
87  dir=-1;
88  vertex = getPosition( primCircle, InitialVertex, theta, dir );
89  LogDebug("NuclearSeedGenerator") << "Change direction to look for vertex" << "\n";
90  }
91  }
92  else break;
93 
94  }
95  theInnerPoint = theCorrectSecCircle.innerPoint();
96  theOuterPoint = theCorrectSecCircle.outerPoint();
97  theVertexPoint = theCorrectSecCircle.vertexPoint();
98  theX0 = theCorrectSecCircle.x0();
99  theY0 = theCorrectSecCircle.y0();
100  theRho = theCorrectSecCircle.rho();
101  theCharge = 0;
102  theDirectionAtVertex = GlobalVector(1000, 1000, 1000);
103 
104  theVertexError = s/NITER;
105 }
106 
107 double TangentCircle::isTangent(const TangentCircle& primCircle, const TangentCircle& secCircle) const {
108  // return a value that should be equal to 0 if primCircle and secCircle are tangent
109 
110  double distanceBetweenCircle = (primCircle.x0() - secCircle.x0())*(primCircle.x0() - secCircle.x0())
111  + (primCircle.y0() - secCircle.y0())*(primCircle.y0() - secCircle.y0());
112  double RadiusSum = (primCircle.rho() + secCircle.rho())*(primCircle.rho() + secCircle.rho());
113  double RadiusDifference = (primCircle.rho() - secCircle.rho())*(primCircle.rho() - secCircle.rho());
114 
115  return std::min( fabs(RadiusSum-distanceBetweenCircle), fabs(RadiusDifference-distanceBetweenCircle) );
116 }
117 
119 
120  if(theY0 > 1E9 || theX0 > 1E9) {
121  LogDebug("NuclearSeedGenerator") << "Center of TangentCircle not calculated but used !!!" << "\n";
122  }
123 
124  // calculate the direction perpendicular to the vector v = point - center_of_circle
125  GlobalVector dir(point.y() - theY0, theX0 - point.x(), 0);
126 
127  dir/=dir.mag();
128 
129  // Check the sign :
131  double diff = (dir - fastDir).mag();
132  double sum = (dir + fastDir).mag();
133 
134  if( sum < diff ) dir = (-1)*dir;
135 
136  return dir;
137 }
138 
140  if(theDirectionAtVertex.x() > 999)
142  return theDirectionAtVertex;
143 }
144 
145 GlobalPoint TangentCircle::getPosition(const TangentCircle& circle, const GlobalPoint& initalPosition, double theta, int dir) const {
146 
147  int sign[3];
148  double x2 = initalPosition.x();
149  double y2 = initalPosition.y();
150 
151  if( (x2>circle.x0()) && dir >0) { sign[0] = 1; sign[1] = -1; sign[2] = -1; }
152  if( (x2>circle.x0()) && dir <0) { sign[0] = 1; sign[1] = 1; sign[2] = 1; }
153  if( (x2<circle.x0()) && dir >0) { sign[0] = -1; sign[1] = 1; sign[2] = -1; }
154  if( (x2<circle.x0()) && dir <0) { sign[0] = -1; sign[1] = -1; sign[2] = 1; }
155 
156  double l = 2*circle.rho()*sin(theta/2);
157  double alpha = atan((y2-circle.y0())/(x2-circle.x0()));
158  double beta = PI/2-theta/2;
159  double gamma = PI + sign[2]* alpha - beta;
160 
161  double xnew = x2 + sign[0]*l*cos(gamma);
162  double ynew = y2 + sign[1]*l*sin(gamma);
163 
164  return GlobalPoint( xnew, ynew, 0 );
165 }
166 
171  return fabs(1/circle1.rho() - 1/circle2.rho());
172  }
173  else {
176  return fabs(1/circle1.rho() - 1/circle2.rho());
177  }
178 }
179 
180 int TangentCircle::charge(float magz) {
181 
182  if(theCharge != 0) return theCharge;
183 
184  if(theX0 > 1E9 || theY0 > 1E9) theCharge = chargeLocally(magz, directionAtVertex());
185  else {
186  GlobalPoint center(theX0, theY0, 0);
187  GlobalVector u = center - theVertexPoint;
189 
190  // F = force vector
191  GlobalVector F( v.y() * magz, -v.x() * magz, 0);
192  if( u.x() * F.x() + u.y() * F.y() > 0) theCharge=-1;
193  else theCharge=1;
194 
195  if(theCharge != chargeLocally(magz, v)) {
196  LogDebug("NuclearSeedGenerator") << "Inconsistency in calculation of the charge" << "\n";
197  }
198 
199  }
200  return theCharge;
201 }
202 
205  double tz = v.x() * u.y() - v.y() * u.x() ;
206 
207  if(tz * magz > 0) return 1; else return -1;
208 }
#define LogDebug(id)
const double beta
float alpha
Definition: AMPTWrapper.h:95
double curvatureError()
double y0() const
Definition: TangentCircle.h:34
double x0() const
Definition: FastCircle.h:50
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double x0() const
Definition: TangentCircle.h:32
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
GlobalPoint innerPoint() const
Definition: TangentCircle.h:40
T perp2() const
Definition: PV3DBase.h:71
double rho() const
Definition: FastCircle.h:54
#define PI
Definition: TangentCircle.cc:4
bool isValid() const
Definition: FastCircle.h:56
GlobalPoint getPosition(const TangentCircle &circle, const GlobalPoint &initalPosition, double theta, int direction) const
T mag() const
Definition: PV3DBase.h:67
double rho() const
Definition: TangentCircle.h:36
GlobalPoint theVertexPoint
Definition: TangentCircle.h:54
GlobalPoint outerPoint() const
Definition: TangentCircle.h:38
GlobalPoint theOuterPoint
Definition: TangentCircle.h:53
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
T min(T a, T b)
Definition: MathUtil.h:58
GlobalVector directionAtVertex()
Return the direction at the vertex.
int chargeLocally(float magz, GlobalVector v) const
GlobalVector direction(const GlobalPoint &point) const
double y0() const
Definition: FastCircle.h:52
GlobalPoint theInnerPoint
Definition: TangentCircle.h:52
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:56
dbl *** dir
Definition: mlp_gen.cc:35
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
double theVertexError
Definition: TangentCircle.h:62
int charge(float magz)
double isTangent(const TangentCircle &primCircle, const TangentCircle &secCircle) const
T x() const
Definition: PV3DBase.h:62
GlobalPoint vertexPoint() const
Definition: TangentCircle.h:42
*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