CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TangentApproachInRPhi.cc
Go to the documentation of this file.
5 
6 using namespace std;
7 
9  const TrajectoryStateOnSurface & stb)
10 {
11  TrackCharge chargeA = sta.charge(); TrackCharge chargeB = stb.charge();
12  GlobalVector momentumA = sta.globalMomentum();
13  GlobalVector momentumB = stb.globalMomentum();
14  GlobalPoint positionA = sta.globalPosition();
15  GlobalPoint positionB = stb.globalPosition();
16  paramA = sta.globalParameters();
17  paramB = stb.globalParameters();
18 
19  return calculate(chargeA, momentumA, positionA, chargeB, momentumB, positionB,
21 }
22 
23 
25  const FreeTrajectoryState & stb)
26 {
27  TrackCharge chargeA = sta.charge(); TrackCharge chargeB = stb.charge();
28  GlobalVector momentumA = sta.momentum();
29  GlobalVector momentumB = stb.momentum();
30  GlobalPoint positionA = sta.position();
31  GlobalPoint positionB = stb.position();
32  paramA = sta.parameters();
33  paramB = stb.parameters();
34 
35  return calculate(chargeA, momentumA, positionA, chargeB, momentumB, positionB,
36  sta.parameters().magneticField());
37 }
38 
39 pair<GlobalPoint, GlobalPoint> TangentApproachInRPhi::points() const
40 {
41  if (!status_)
42  throw cms::Exception("TrackingTools/PatternTools","TangentApproachInRPhi::could not compute track crossing. Check status before calling this method!");
43  return pair<GlobalPoint, GlobalPoint> (posA, posB);
44 }
45 
46 
49 {
50  if (!status_)
51  throw cms::Exception("TrackingTools/PatternTools","TangentApproachInRPhi::could not compute track crossing. Check status before calling this method!");
52  return GlobalPoint((posA.x() + posB.x())/2.,
53  (posA.y() + posB.y())/2.,
54  (posA.z() + posB.z())/2.);
55 }
56 
57 
59 {
60  if (!status_)
61  throw cms::Exception("TrackingTools/PatternTools","TangentApproachInRPhi::could not compute track crossing. Check status before calling this method!");
62  return (posB - posA).mag();
63 }
64 
66 {
67  if (!status_)
68  throw cms::Exception("TrackingTools/PatternTools","TangentApproachInRPhi::could not compute track crossing. Check status before calling this method!");
69 
70  float perpdist = (posB - posA).perp();
71 
72  if (intersection_) {
73  perpdist = -perpdist;
74  }
75 
76  return perpdist;
77 
78 }
79 
80 
82  const GlobalVector & momentumA,
83  const GlobalPoint & positionA,
84  const TrackCharge & chargeB,
85  const GlobalVector & momentumB,
86  const GlobalPoint & positionB,
87  const MagneticField& magField)
88 {
89 
90  // centres and radii of track circles
91  double xca, yca, ra;
92  circleParameters(chargeA, momentumA, positionA, xca, yca, ra, magField);
93  double xcb, ycb, rb;
94  circleParameters(chargeB, momentumB, positionB, xcb, ycb, rb, magField);
95 
96  // points of closest approach in transverse plane
97  double xg1, yg1, xg2, yg2;
98  int flag = transverseCoord(xca, yca, ra, xcb, ycb, rb, xg1, yg1, xg2, yg2);
99  if (flag == 0) {
100  status_ = false;
101  return false;
102  }
103 
104  double xga, yga, zga, xgb, ygb, zgb;
105 
106  if (flag == 1) {
107  intersection_ = true;
108  }
109  else {
110  intersection_ = false;
111  }
112 
113  // one point of closest approach on each track in transverse plane
114  xga = xg1; yga = yg1;
115  zga = zCoord(momentumA, positionA, ra, xca, yca, xga, yga);
116  xgb = xg2; ygb = yg2;
117  zgb = zCoord(momentumB, positionB, rb, xcb, ycb, xgb, ygb);
118 
119 
120  posA = GlobalPoint(xga, yga, zga);
121  posB = GlobalPoint(xgb, ygb, zgb);
122  status_ = true;
123  return true;
124 }
125 
126 pair <GlobalTrajectoryParameters, GlobalTrajectoryParameters>
128 {
129  if (!status_)
130  throw cms::Exception("TrackingTools/PatternTools","TangentApproachInRPhi::could not compute track crossing. Check status before calling this method!");
131  pair <GlobalTrajectoryParameters, GlobalTrajectoryParameters>
132  ret ( trajectoryParameters ( posA, paramA ),
133  trajectoryParameters ( posB, paramB ) );
134  return ret;
135 }
136 
138  const GlobalPoint & newpt, const GlobalTrajectoryParameters & oldgtp ) const
139 {
140  // First we need the centers of the circles.
141  double xc, yc, r;
142  circleParameters( oldgtp.charge(), oldgtp.momentum(),
143  oldgtp.position(), xc, yc, r, oldgtp.magneticField() );
144 
145  // now we do a translation, move the center of circle to (0,0,0).
146  double dx1 = oldgtp.position().x() - xc;
147  double dy1 = oldgtp.position().y() - yc;
148  double dx2 = newpt.x() - xc;
149  double dy2 = newpt.y() - yc;
150 
151  // now for the angles:
152  double cosphi = ( dx1 * dx2 + dy1 * dy2 ) /
153  ( sqrt ( dx1 * dx1 + dy1 * dy1 ) * sqrt ( dx2 * dx2 + dy2 * dy2 ));
154  double sinphi = - oldgtp.charge() * sqrt ( 1 - cosphi * cosphi );
155 
156  // Finally, the new momenta:
157  double px = cosphi * oldgtp.momentum().x() - sinphi * oldgtp.momentum().y();
158  double py = sinphi * oldgtp.momentum().x() + cosphi * oldgtp.momentum().y();
159 
160  GlobalVector vta ( px, py, oldgtp.momentum().z() );
161  GlobalTrajectoryParameters gta( newpt , vta , oldgtp.charge(), &(oldgtp.magneticField()) );
162  return gta;
163 }
164 
165 void
167  const GlobalVector& momentum,
168  const GlobalPoint& position,
169  double& xc, double& yc, double& r,
170  const MagneticField& magField)
171 const
172 {
173 
174  // compute radius of circle
178 // double bz = MagneticField::inInverseGeV(position).z();
179  double bz = magField.inTesla(position).z() * 2.99792458e-3;
180 
181  // signed_r directed towards circle center, along F_Lorentz = q*v X B
182  double signed_r = charge*momentum.transverse() / bz;
183  r = abs(signed_r);
187  // compute centre of circle
188  double phi = momentum.phi();
189  xc = signed_r*sin(phi) + position.x();
190  yc = -signed_r*cos(phi) + position.y();
191 
192 }
193 
194 
195 int
196 TangentApproachInRPhi::transverseCoord(double cxa, double cya, double ra,
197  double cxb, double cyb, double rb,
198  double & xg1, double & yg1,
199  double & xg2, double & yg2) const
200 {
201  int flag = 0;
202  double x1, y1, x2, y2;
203 
204  // new reference frame with origin in (cxa, cya) and x-axis
205  // directed from (cxa, cya) to (cxb, cyb)
206 
207  double d_ab = sqrt((cxb - cxa)*(cxb - cxa) + (cyb - cya)*(cyb - cya));
208  if (d_ab == 0) { // concentric circles
209  return 0;
210  }
211  // elements of rotation matrix
212  double u = (cxb - cxa) / d_ab;
213  double v = (cyb - cya) / d_ab;
214 
215  // conditions for circle intersection
216  if (d_ab <= ra + rb && d_ab >= abs(rb - ra)) {
217 
218  // circles cross each other
219 // flag = 1;
220 //
221 // // triangle (ra, rb, d_ab)
222 // double cosphi = (ra*ra - rb*rb + d_ab*d_ab) / (2*ra*d_ab);
223 // double sinphi2 = 1. - cosphi*cosphi;
224 // if (sinphi2 < 0.) { sinphi2 = 0.; cosphi = 1.; }
225 //
226 // // intersection points in new frame
227 // double sinphi = sqrt(sinphi2);
228 // x1 = ra*cosphi; y1 = ra*sinphi; x2 = x1; y2 = -y1;
229 
230  //circles cross each other, but take tangent points anyway
231  flag = 1;
232 
233  // points of closest approach in new frame
234  // are on line between 2 centers
235  x1 = ra; y1 = 0; x2 = d_ab - rb; y2 = 0;
236 
237 
238  }
239  else if (d_ab > ra + rb) {
240 
241  // circles are external to each other
242  flag = 2;
243 
244  // points of closest approach in new frame
245  // are on line between 2 centers
246  x1 = ra; y1 = 0; x2 = d_ab - rb; y2 = 0;
247  }
248  else if (d_ab < abs(rb - ra)) {
249 
250  // circles are inside each other
251  flag = 2;
252 
253  // points of closest approach in new frame are on line between 2 centers
254  // choose 2 closest points
255  double sign = 1.;
256  if (ra <= rb) sign = -1.;
257  x1 = sign*ra; y1 = 0; x2 = d_ab + sign*rb; y2 = 0;
258  }
259  else {
260  return 0;
261  }
262 
263  // intersection points in global frame, transverse plane
264  xg1 = u*x1 - v*y1 + cxa; yg1 = v*x1 + u*y1 + cya;
265  xg2 = u*x2 - v*y2 + cxa; yg2 = v*x2 + u*y2 + cya;
266 
267  return flag;
268 }
269 
270 
271 double
273  const GlobalPoint& pos,
274  double r, double xc, double yc,
275  double xg, double yg) const
276 {
277 
278  // starting point
279  double x = pos.x(); double y = pos.y(); double z = pos.z();
280 
281  double px = mom.x(); double py = mom.y(); double pz = mom.z();
282 
283  // rotation angle phi from starting point to crossing point (absolute value)
284  // -- compute sin(phi/2) if phi smaller than pi/4,
285  // -- cos(phi) if phi larger than pi/4
286  double phi = 0.;
287  double sinHalfPhi = sqrt((x-xg)*(x-xg) + (y-yg)*(y-yg))/(2*r);
288  if (sinHalfPhi < 0.383) { // sin(pi/8)
289  phi = 2*asin(sinHalfPhi);
290  }
291  else {
292  double cosPhi = ((x-xc)*(xg-xc) + (y-yc)*(yg-yc))/(r*r);
293  if (std::abs(cosPhi) > 1) cosPhi = (cosPhi > 0 ? 1 : -1);
294  phi = abs(acos(cosPhi));
295  }
296  // -- sign of phi
297  double signPhi = ((x - xc)*(yg - yc) - (xg - xc)*(y - yc) > 0) ? 1. : -1.;
298 
299  // sign of track angular momentum
300  // if rotation is along angular momentum, delta z is along pz
301  double signOmega = ((x - xc)*py - (y - yc)*px > 0) ? 1. : -1.;
302 
303  // delta z
304  // -- |dz| = |cos(theta) * path along helix|
305  // = |cos(theta) * arc length along circle / sin(theta)|
306  double dz = signPhi*signOmega*(pz/mom.transverse())*phi*r;
307 
308  return z + dz;
309 }
virtual std::pair< GlobalPoint, GlobalPoint > points() const
long int flag
Definition: mlp_lapack.h:47
std::pair< GlobalTrajectoryParameters, GlobalTrajectoryParameters > trajectoryParameters() const
const GlobalTrajectoryParameters & parameters() const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
T perp() const
Magnitude of transverse component.
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:57
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
TrackCharge charge() const
double zCoord(const GlobalVector &mom, const GlobalPoint &pos, double r, double xc, double yc, double xg, double yg) const
double charge(const std::vector< uint8_t > &Ampls)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
virtual GlobalPoint crossingPoint() const
T transverse() const
Definition: PV3DBase.h:67
int TrackCharge
Definition: TrackCharge.h:4
Definition: DDAxes.h:10
FreeTrajectoryState * freeState(bool withErrors=true) const
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int transverseCoord(double cxa, double cya, double ra, double cxb, double cyb, double rb, double &xg1, double &yg1, double &xg2, double &yg2) const
GlobalVector momentum() const
GlobalPoint position() const
const GlobalTrajectoryParameters & globalParameters() const
virtual float distance() const
GlobalVector globalMomentum() const
const MagneticField & magneticField() const
void circleParameters(const TrackCharge &charge, const GlobalVector &momemtum, const GlobalPoint &position, double &xc, double &yc, double &r, const MagneticField &magField) const
T x() const
Definition: PV3DBase.h:56
virtual bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb)
mathSSE::Vec4< T > v
Definition: DDAxes.h:10