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 }
Vector3DBase
Definition: Vector3DBase.h:8
PI
Definition: PayloadInspector.h:19
change_name.diff
diff
Definition: change_name.py:13
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
min
T min(T a, T b)
Definition: MathUtil.h:58
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
zMuMuMuonUserData.beta
beta
Definition: zMuMuMuonUserData.py:10
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
TangentCircle::theOuterPoint
GlobalPoint theOuterPoint
Definition: TangentCircle.h:58
TangentCircle::curvatureError
double curvatureError()
Definition: TangentCircle.cc:193
FastCircle::y0
double y0() const
Definition: FastCircle.h:45
CustomPhysics_cfi.gamma
gamma
Definition: CustomPhysics_cfi.py:17
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
findQualityFiles.v
v
Definition: findQualityFiles.py:179
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
FastCircle::rho
double rho() const
Definition: FastCircle.h:47
TangentCircle::isTangent
double isTangent(const TangentCircle &primCircle, const TangentCircle &secCircle) const
Definition: TangentCircle.cc:114
TangentCircle::getPosition
GlobalPoint getPosition(const TangentCircle &circle, const GlobalPoint &initalPosition, double theta, int direction) const
Definition: TangentCircle.cc:153
TangentCircle::theCharge
int theCharge
Definition: TangentCircle.h:70
SurfaceOrientation::inner
Definition: Surface.h:19
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
TangentCircle::valid
bool valid
Definition: TangentCircle.h:69
FastCircle::x0
double x0() const
Definition: FastCircle.h:43
TangentCircle::TangentCircle
TangentCircle()
Definition: TangentCircle.h:13
TangentCircle.h
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
TangentCircle::x0
double x0() const
Definition: TangentCircle.h:38
TangentCircle
Definition: TangentCircle.h:7
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
TangentCircle::theX0
double theX0
Definition: TangentCircle.h:63
TangentCircle::y0
double y0() const
Definition: TangentCircle.h:40
TangentCircle::direction
GlobalVector direction(const GlobalPoint &point) const
Definition: TangentCircle.cc:125
TangentCircle::theRho
double theRho
Definition: TangentCircle.h:65
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
TangentCircle::vertexPoint
GlobalPoint vertexPoint() const
Definition: TangentCircle.h:48
FastCircle
Definition: FastCircle.h:33
TangentCircle::charge
int charge(float magz)
Definition: TangentCircle.cc:205
TangentCircle::theDirectionAtVertex
GlobalVector theDirectionAtVertex
Definition: TangentCircle.h:61
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
TangentCircle::innerPoint
GlobalPoint innerPoint() const
Definition: TangentCircle.h:46
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
HLTTauDQMOffline_cfi.denominator
denominator
Definition: HLTTauDQMOffline_cfi.py:195
TangentCircle::rho
double rho() const
Definition: TangentCircle.h:42
TangentCircle::outerPoint
GlobalPoint outerPoint() const
Definition: TangentCircle.h:44
TangentCircle::directionAtVertex
GlobalVector directionAtVertex()
Return the direction at the vertex.
Definition: TangentCircle.cc:147
FastCircle::isValid
bool isValid() const
Definition: FastCircle.h:49
TangentCircle::theY0
double theY0
Definition: TangentCircle.h:64
TangentCircle::theInnerPoint
GlobalPoint theInnerPoint
Definition: TangentCircle.h:57
SurfaceOrientation::outer
Definition: Surface.h:19
point
*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
TangentCircle::theVertexPoint
GlobalPoint theVertexPoint
Definition: TangentCircle.h:59
TangentCircle::theVertexError
double theVertexError
Definition: TangentCircle.h:67
TangentCircle::chargeLocally
int chargeLocally(float magz, GlobalVector v) const
Definition: TangentCircle.cc:231
PV3DBase::perp2
T perp2() const
Definition: PV3DBase.h:68
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23