CMS 3D CMS Logo

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