CMS 3D CMS Logo

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