test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TwoTrackMinimumDistanceHelixLine.cc
Go to the documentation of this file.
5 #include <iostream>
6 #include <iomanip>
7 
8 using namespace std;
9 
11 {
12  bool isFirstALine = firstGTP->charge() == 0. || firstGTP->magneticField().inTesla(firstGTP->position()).z() == 0.;
13  bool isSecondALine = secondGTP->charge() == 0. || secondGTP->magneticField().inTesla(secondGTP->position()).z() == 0.;
14  if (isFirstALine && !isSecondALine ) {
15  theL= firstGTP;
16  theH= secondGTP;
17  } else if (!isFirstALine && isSecondALine) {
18  theH= firstGTP;
19  theL= secondGTP;
20  } else {
21  edm::LogWarning ("TwoTrackMinimumDistanceHelixLine")
22  << "Error in track charge: "
23  << "One of the tracks has to be charged, and the other not." << endl
24  << "Track Charges: "<<firstGTP->charge() << " and " <<secondGTP->charge();
25  return true;
26  }
27 
28  Hn = theH->momentum().mag();
29  Ln = theL->momentum().mag();
30 
31  if ( Hn == 0. || Ln == 0. )
32  {
33  edm::LogWarning ("TwoTrackMinimumDistanceHelixLine")
34  << "Momentum of input trajectory is zero.";
35  return true;
36  };
37 
38  GlobalPoint lOrig = theL->position();
39  GlobalPoint hOrig = theH->position();
40  posDiff = GlobalVector((lOrig - hOrig).basicVector());
41  X = posDiff.x();
42  Y = posDiff.y();
43  Z = posDiff.z();
44  theLp = theL->momentum();
45  px = theLp.x(); px2 = px*px;
46  py = theLp.y(); py2 = py*py;
47  pz = theLp.z(); pz2 = pz*pz;
48 
49  const double Bc2kH = theH->magneticField().inTesla(hOrig).z() * 2.99792458e-3;
50 // MagneticField::inInverseGeV ( hOrig ).z();
51 
52  if ( Bc2kH == 0. )
53  {
54  edm::LogWarning ("TwoTrackMinimumDistanceHelixLine")
55  << "Magnetic field at point " << hOrig << " is zero.";
56  return true;
57  };
58 
59  theh= - Hn / (theH->charge() * Bc2kH ) *
60  sqrt( 1 - ( ( (theH->momentum().z()*theH->momentum().z()) / (Hn*Hn) )));
61 
62  thetanlambdaH = - theH->momentum().z() / ( theH->charge() * Bc2kH * theh);
63 
64  thePhiH0 = theH->momentum().phi();
65  thesinPhiH0= sin(thePhiH0);
66  thecosPhiH0= cos(thePhiH0);
67 
68  aa = (X + theh*thesinPhiH0)*(py2 + pz2) - px*(py*Y + pz*Z);
69  bb = (Y - theh*thecosPhiH0)*(px2 + pz2) - py*(px*X + pz*Z);
70  cc = pz*theh*thetanlambdaH;
71  dd = theh* px *py;
72  ee = theh*(px2 - py2);
73  ff = (px2 + py2)*theh*thetanlambdaH*thetanlambdaH;
74 
75  baseFct = thetanlambdaH * (Z*(px2+py2) - pz*(px*X + py*Y));
76  baseDer = - ff;
77  return false;
78 }
79 
81  double & thePhiH, double & fct, double & derivative ) const
82 {
83 
84  double thesinPhiH = sin(thePhiH);
85  double thecosPhiH = cos(thePhiH);
86 
87  // Fonction of which the root is to be found:
88 
89  fct = baseFct;
90  fct -= ff*(thePhiH - thePhiH0);
91  fct += thecosPhiH * aa;
92  fct += thesinPhiH * bb;
93  fct += cc*(thePhiH - thePhiH0)*(px * thecosPhiH + py * thesinPhiH);
94  fct += cc * (px * (thesinPhiH - thesinPhiH0) - py * (thecosPhiH - thecosPhiH0));
95  fct += dd * (thesinPhiH* (thesinPhiH - thesinPhiH0) -
96  thecosPhiH*(thecosPhiH - thecosPhiH0));
97  fct += ee * thecosPhiH * thesinPhiH;
98 
99  // Its derivative:
100 
101  derivative = baseDer;
102  derivative += - thesinPhiH * aa;
103  derivative += thecosPhiH * bb;
104  derivative += cc*(thePhiH - thePhiH0)*(py * thecosPhiH - px * thesinPhiH);
105  derivative += 2* cc*(px * thecosPhiH + py * thesinPhiH);
106  derivative += dd *(4 * thecosPhiH * thesinPhiH - thecosPhiH * thesinPhiH0 -
107  thesinPhiH * thecosPhiH0);
108  derivative += ee * (thecosPhiH*thecosPhiH-thesinPhiH*thesinPhiH);
109 
110  return false;
111 }
112 
114  const GlobalTrajectoryParameters & theFirstGTP,
115  const GlobalTrajectoryParameters & theSecondGTP, const float qual )
116 {
117  pointsUpdated = false;
118  firstGTP = (GlobalTrajectoryParameters *) &theFirstGTP;
119  secondGTP = (GlobalTrajectoryParameters *) &theSecondGTP;
120 
121  if ( updateCoeffs () )
122  {
123  return true;
124  };
125 
126  double fctVal, derVal, dPhiH;
127  thePhiH = thePhiH0;
128 
129  double x1=thePhiH0-M_PI, x2=thePhiH0+M_PI;
130  for (int j=1; j<=themaxiter; ++j) {
131  oneIteration(thePhiH, fctVal, derVal);
132  dPhiH=fctVal/derVal;
133  thePhiH -= dPhiH;
134  if ((x1-thePhiH)*(thePhiH-x2) < 0.0) {
135  LogDebug ("TwoTrackMinimumDistanceHelixLine")
136  << "Jumped out of brackets in root finding. Will be moved closer.";
137  thePhiH += (dPhiH*0.8);
138  }
139  if (fabs(dPhiH) < qual) {return false;}
140  }
141  LogDebug ("TwoTrackMinimumDistanceHelixLine")
142  <<"Number of steps exceeded. Has not converged.";
143  return true;
144 }
145 
147 {
148  if (firstGTP==theL) return theL->momentum().phi();
149  else return thePhiH;
150 }
151 
153 {
154  if (secondGTP==theL) return theL->momentum().phi();
155  else return thePhiH;
156 }
157 
158 pair <GlobalPoint, GlobalPoint> TwoTrackMinimumDistanceHelixLine::points()
159  const
160 {
161  if (!pointsUpdated)finalPoints();
162  if (firstGTP==theL)
163  return pair<GlobalPoint, GlobalPoint> (linePoint, helixPoint);
164  else return pair<GlobalPoint, GlobalPoint> (helixPoint, linePoint);
165 }
166 
167 pair <double, double> TwoTrackMinimumDistanceHelixLine::pathLength() const
168 {
169  if (!pointsUpdated)finalPoints();
170  if (firstGTP==theL)
171  return pair<double, double> (linePath, helixPath);
172  else return pair<double, double> (helixPath, linePath);
173 }
174 
176 {
177  helixPoint = GlobalPoint (
178  theH->position().x() + theh * ( sin ( thePhiH) - thesinPhiH0 ),
179  theH->position().y() + theh * ( - cos ( thePhiH) + thecosPhiH0 ),
180  theH->position().z() + theh * ( thetanlambdaH * ( thePhiH- thePhiH0 ))
181  );
182  helixPath = ( thePhiH- thePhiH0 ) * (theh*sqrt(1+thetanlambdaH*thetanlambdaH)) ;
183 
184  GlobalVector diff((theL->position() -helixPoint).basicVector());
185  tL = ( - diff.dot(theLp)) / (Ln*Ln);
186  linePoint = GlobalPoint (
187  theL->position().x() + tL * px,
188  theL->position().y() + tL * py,
189  theL->position().z() + tL * pz );
190  linePath = tL * theLp.mag();
191  pointsUpdated = true;
192 }
#define LogDebug(id)
const double Z[kNumberCalorimeter]
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
bool oneIteration(double &thePhiH, double &fct, double &derivative) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
#define X(str)
Definition: MuonsGrabber.cc:48
list diff
Definition: mps_update.py:85
T mag() const
Definition: PV3DBase.h:67
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
std::pair< double, double > pathLength() const
#define M_PI
std::pair< GlobalPoint, GlobalPoint > points() const
bool calculate(const GlobalTrajectoryParameters &, const GlobalTrajectoryParameters &, const float qual=.0001)
Global3DVector GlobalVector
Definition: GlobalVector.h:10