CMS 3D CMS Logo

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