CMS 3D CMS Logo

PointingKinematicConstraint.cc
Go to the documentation of this file.
3 
4 std::pair<AlgebraicVector, AlgebraicVector> PointingKinematicConstraint::value(const AlgebraicVector& exPoint) const {
5  if (exPoint.num_row() == 0)
6  throw VertexException("PointingKinematicConstraint::value requested for zero Linearization point");
7 
8  //security check for extended cartesian parametrization
9  int inSize = exPoint.num_row();
10  if ((inSize % 7) != 0)
11  throw VertexException("PointingKinematicConstraint::linearization point has a wrong dimension");
12  int nStates = inSize / 7;
13  if (nStates != 1)
14  throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
15 
16  AlgebraicVector lPar = exPoint;
17  AlgebraicVector vl(2, 0);
18 
19  //vector of values 1x2 for given particle
20  AlgebraicVector lValue = makeValue(lPar).first;
21  vl(1) = lValue(1);
22  vl(2) = lValue(2);
23  return std::pair<AlgebraicVector, AlgebraicVector>(vl, lPar);
24 }
25 
26 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint::derivative(
27  const AlgebraicVector& exPoint) const {
28  if (exPoint.num_row() == 0)
29  throw VertexException("PointingKinematicConstraint::value requested for zero Linearization point");
30 
31  //security check for extended cartesian parametrization
32  int inSize = exPoint.num_row();
33  if ((inSize % 7) != 0)
34  throw VertexException("PointingKinematicConstraint::linearization point has a wrong dimension");
35  int nStates = inSize / 7;
36  if (nStates != 1)
37  throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
38  AlgebraicVector lPar = exPoint;
39 
40  //2x7 derivative matrix for given particle
41  AlgebraicMatrix lDeriv = makeDerivative(lPar).first;
42  AlgebraicMatrix dr(2, 7, 0);
43  dr.sub(1, 1, lDeriv);
44  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr, lPar);
45 }
46 
47 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint::derivative(
48  const std::vector<RefCountedKinematicParticle>& par) const {
49  int nStates = par.size();
50  if (nStates == 0)
51  throw VertexException("PointingKinematicConstraint::Empty vector of particles passed");
52  if (nStates != 1)
53  throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
54 
55  AlgebraicMatrix dr(2, 7, 0);
56  AlgebraicVector lPoint = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
57 
58  //2x7 derivative matrix for given state
59  AlgebraicMatrix lDeriv = makeDerivative(lPoint).first;
60  dr.sub(1, 1, lDeriv);
61  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr, lPoint);
62 }
63 
64 std::pair<AlgebraicVector, AlgebraicVector> PointingKinematicConstraint::value(
65  const std::vector<RefCountedKinematicParticle>& par) const {
66  int nStates = par.size();
67  if (nStates == 0)
68  throw VertexException("PointingKinematicConstraint::Empty vector of particles passed");
69  if (nStates != 1)
70  throw VertexException("PointingKinematicConstraint::Current version does not support the multistate refit");
71  AlgebraicVector vl(2, 0);
72  AlgebraicVector lPoint = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
73  vl(1) = makeValue(lPoint).first(1);
74  vl(2) = makeValue(lPoint).first(2);
75  return std::pair<AlgebraicVector, AlgebraicVector>(vl, lPoint);
76 }
77 
78 std::pair<AlgebraicVector, AlgebraicVector> PointingKinematicConstraint::makeValue(
79  const AlgebraicVector& exPoint) const {
80  AlgebraicVector vl(2, 0);
81  AlgebraicVector point = exPoint;
82  double dx = point(1) - refPoint.x();
83  double dy = point(2) - refPoint.y();
84  double dz = point(3) - refPoint.z();
85  double px = point(4);
86  double py = point(5);
87  double pz = point(6);
88 
89  // tangent solution
90  // vl(1) = dy/dx - py/px;
91  // vl(2) = dz/sqrt(dx*dx + dy*dy) - pz/sqrt(px*px + py*py);
92 
93  //half angle solution
94  double sin_p = py / sqrt(px * px + py * py);
95  double cos_p = px / sqrt(px * px + py * py);
96  double sin_x = dy / sqrt(dx * dx + dy * dy);
97  double cos_x = dx / sqrt(dx * dx + dy * dy);
98 
99  double sin_pt = pz / sqrt(px * px + py * py + pz * pz);
100  double cos_pt = sqrt(px * px + py * py) / sqrt(px * px + py * py + pz * pz);
101  double sin_xt = dz / sqrt(dx * dx + dy * dy + dz * dz);
102  double cos_xt = sqrt(dx * dx + dy * dy) / sqrt(dx * dx + dy * dy + dz * dz);
103 
104  vl(1) = (1 - cos_x) / sin_x - (1 - cos_p) / sin_p;
105  vl(2) = (1 - cos_xt) / sin_xt - (1 - cos_pt) / sin_pt;
106 
107  //half angle corrected
108  // vl(1) = (sin_x/(1+cos_x)) - (sin_p/(1+cos_p));
109  // vl(2) = (sin_xt/(1+cos_xt)) - (sin_pt/(1+cos_pt));
110  return std::pair<AlgebraicVector, AlgebraicVector>(vl, point);
111 }
112 
113 std::pair<AlgebraicMatrix, AlgebraicVector> PointingKinematicConstraint::makeDerivative(
114  const AlgebraicVector& exPoint) const {
115  AlgebraicMatrix dr(2, 7, 0);
116  AlgebraicVector point = exPoint;
117  double dx = point(1) - refPoint.x();
118  double dy = point(2) - refPoint.y();
119  double dz = point(3) - refPoint.z();
120  double px = point(4);
121  double py = point(5);
122  double pz = point(6);
123 
124  // double tr = px*px + py*py;
125  // double trd = dx*dx + dy*dy;
126  // double pr =1.5;
127  // double p_factor = pow(tr,pr);
128  // double x_factor = pow(trd,pr);
129 
130  //tangent solution
131  /*
132  dr(1,1) = -dy/(dx*dx);
133  dr(1,2) = 1/dx;
134  dr(1,3) = 0;
135  dr(1,4) = py/(px*px);
136  dr(1,5) = -1/px;
137  dr(1,6) = 0;
138  dr(1,7) = 0;
139 
140  dr(2,1) = -(dx*dz)/x_factor;
141  dr(2,2) = -(dy*dz)/x_factor;
142  dr(2,3) = 1/sqrt(dx*dx + dy*dy);
143  dr(2,4) = (px*pz)/p_factor;
144  dr(2,5) = (py*pz)/p_factor;
145  dr(2,6) = -1/sqrt(px*px + py*py);
146  dr(2,7) = 0.;
147 */
148  //half angle solution corrected
149  /*
150  dr(1,1) = - dy/(dx*dx+dy*dy+dx*sqrt(dx*dx+dy*dy));
151  dr(1,2) = dx/(dx*dx+dy*dy+dx*sqrt(dx*dx+dy*dy));
152  dr(1,3) = 0;
153  dr(1,4) = py/(px*px+py*py+px*sqrt(px*px+py*py));
154  dr(1,5) = -px/(px*px+py*py+px*sqrt(px*px+py*py));
155  dr(1,6) = 0;
156  dr(1,7) = 0;
157 */
158 
159  //half angle solution
160  dr(1, 1) = dx / (dy * sqrt(dx * dx + dy * dy)) - 1 / dy;
161  dr(1, 2) = 1 / sqrt(dx * dx + dy * dy) - sqrt(dx * dx + dy * dy) / (dy * dy) + dx / (dy * dy);
162  dr(1, 3) = 0;
163  dr(1, 4) = -(px / (py * sqrt(px * px + py * py)) - 1 / py);
164  dr(1, 5) = -(1 / sqrt(px * px + py * py) - sqrt(px * px + py * py) / (py * py) + px / (py * py));
165  dr(1, 6) = 0;
166  dr(1, 7) = 0;
167 
168  //half angle solution
169  dr(2, 1) = (dx / dz) * (1 / sqrt(dx * dx + dy * dy + dz * dz) - 1 / sqrt(dx * dx + dy * dy));
170  dr(2, 2) = (dy / dz) * (1 / sqrt(dx * dx + dy * dy + dz * dz) - 1 / sqrt(dx * dx + dy * dy));
171  dr(2, 3) = (1 / (dz * dz)) * (sqrt(dx * dx + dy * dy) - sqrt(dx * dx + dy * dy + dz * dz)) +
172  1 / sqrt(dx * dx + dy * dy + dz * dz);
173  dr(2, 4) = -(px / pz) * (1 / sqrt(px * px + py * py + pz * pz) - 1 / sqrt(px * px + py * py));
174  dr(2, 5) = -(py / pz) * (1 / sqrt(px * px + py * py + pz * pz) - 1 / sqrt(px * px + py * py));
175  dr(2, 6) = -((1 / (pz * pz)) * (sqrt(px * px + py * py) - sqrt(px * px + py * py + pz * pz)) +
176  1 / sqrt(px * px + py * py + pz * pz));
177  dr(2, 7) = 0;
178 
179  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr, point);
180 }
181 
182 AlgebraicVector PointingKinematicConstraint::deviations(int nStates) const { return AlgebraicVector(7 * nStates, 0); }
183 
VertexException
Common base class.
Definition: VertexException.h:12
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
PointingKinematicConstraint::makeValue
std::pair< AlgebraicVector, AlgebraicVector > makeValue(const AlgebraicVector &exPoint) const
Definition: PointingKinematicConstraint.cc:78
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
PointingKinematicConstraint::value
std::pair< AlgebraicVector, AlgebraicVector > value(const AlgebraicVector &exPoint) const override
Definition: PointingKinematicConstraint.cc:4
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
PointingKinematicConstraint.h
PointingKinematicConstraint::numberOfEquations
int numberOfEquations() const override
Definition: PointingKinematicConstraint.cc:184
PointingKinematicConstraint::derivative
std::pair< AlgebraicMatrix, AlgebraicVector > derivative(const AlgebraicVector &exPoint) const override
Definition: PointingKinematicConstraint.cc:26
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
PointingKinematicConstraint::makeDerivative
std::pair< AlgebraicMatrix, AlgebraicVector > makeDerivative(const AlgebraicVector &exPoint) const
Definition: PointingKinematicConstraint.cc:113
PointingKinematicConstraint::refPoint
GlobalPoint refPoint
Definition: PointingKinematicConstraint.h:55
PVValHelper::dy
Definition: PVValidationHelpers.h:50
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
PVValHelper::dz
Definition: PVValidationHelpers.h:51
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
VertexException.h
PointingKinematicConstraint::deviations
AlgebraicVector deviations(int nStates) const override
Definition: PointingKinematicConstraint.cc:182
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
PVValHelper::dx
Definition: PVValidationHelpers.h:49