CMS 3D CMS Logo

MultipleKinematicConstraint.cc
Go to the documentation of this file.
2 
4 {
5  if(newConst == nullptr)throw VertexException("MultipleKinematicConstraint::zero constraint pointer passed");
6  cts.push_back(newConst);
7  em = false;
8 }
9 
10 std::pair<AlgebraicVector,AlgebraicVector> MultipleKinematicConstraint::value(const AlgebraicVector& exPoint) const
11 {
12  if(cts.empty())throw VertexException("MultipleKinematicConstraint::value requested for empty constraint");
13  if(exPoint.num_row() ==0 ) throw VertexException("MultipleKinematicConstraint::value requested for zero Linearization point");
14 
15 //looking for total number of states, represented by this point.
16 //Since this version only works with extended cartesian parametrization,
17 //we check whether the dimensionof he point is n*7
18  AlgebraicVector expansion = exPoint;
19  int inSize = exPoint.num_row();
20  if((inSize%7) !=0) throw VertexException("MultipleKinematicConstraint::linearization point has a wrong dimension");
21 
22  int total = 0;
23  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
24  {total += (*i)->numberOfEquations();}
25  AlgebraicVector vl(total,0);
26 
27  int cr_size = 0;
28  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
29  {
30  AlgebraicVector vlc = (*i)->value(expansion).first;
31  int sz = vlc.num_row();
32  for(int j = 1; j < sz+1; j++)
33  {vl(cr_size+j) = vlc(j);}
34  cr_size += sz;
35  }
36  return std::pair<AlgebraicVector, AlgebraicVector>(vl,expansion);
37 }
38 
39 std::pair<AlgebraicMatrix, AlgebraicVector> MultipleKinematicConstraint::derivative(const AlgebraicVector& exPoint) const
40 {
41  if(cts.empty()) throw VertexException("MultipleKinematicConstraint::derivative requested for empty constraint");
42  if(exPoint.num_row() ==0 ) throw VertexException("MultipleKinematicConstraint::value requested for zero Linearization point");
43 
44 //security check for extended cartesian parametrization
45  int inSize = exPoint.num_row();
46  if((inSize%7) !=0) throw VertexException("MultipleKinematicConstraint::linearization point has a wrong dimension");
47 
48 
49  AlgebraicVector par = exPoint;
50  int total = 0;
51  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
52  {total += (*i)->numberOfEquations();}
53 
54 //Full derivative matrix: (numberOfConstraints x 7*numberOfStates)
55  AlgebraicMatrix dr(total,inSize);
56 
57  int cr_size = 0;
58  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
59  {
60 //matrix should be (nx7*NumberOfStates)
61  AlgebraicMatrix lConst = (*i)->derivative(par).first;
62  dr.sub(cr_size+1,1,lConst);
63  cr_size += (*i)->numberOfEquations();
64  }
65  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr,par);
66 }
67 
69 {
70  int ne = 0;
71  if(cts.empty()) throw VertexException("MultipleKinematicConstraint::number of equations requested for empty constraint");
72  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
73  {ne += (*i)->numberOfEquations();}
74  return ne;
75 }
76 
77 std::pair<AlgebraicVector, AlgebraicVector> MultipleKinematicConstraint::value(const std::vector<RefCountedKinematicParticle> &par) const
78 {
79  if(cts.empty()) throw VertexException("MultipleKinematicConstraint::derivative requested for empty constraint");
80  int nStates = par.size();
81  AlgebraicVector param(7*nStates,0);
82  int count = 1;
83  for(std::vector<RefCountedKinematicParticle>::const_iterator i = par.begin(); i!=par.end(); i++)
84  {
85  for(int j = 1; j<8; j++){param((count -1)*7+j) = (*i)->currentState().kinematicParameters().vector()(j-1);}
86  count++;
87  }
88 
89 //looking for total number of equations
90  int total = 0;
91  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
92  {total += (*i)->numberOfEquations();}
93  AlgebraicVector vl(total,0);
94 
95  int cr_size = 0;
96  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
97  {
98  AlgebraicVector vlc = (*i)->value(par).first;
99  int sz = vlc.num_row();
100  for(int j = 1; j <= sz; j++)
101  {vl(cr_size+j) = vlc(j);}
102  cr_size += sz;
103  }
104  return std::pair<AlgebraicVector, AlgebraicVector>(vl,param);
105 }
106 
107 std::pair<AlgebraicMatrix, AlgebraicVector> MultipleKinematicConstraint::derivative(const std::vector<RefCountedKinematicParticle> &par) const
108 {
109  if(cts.empty()) throw VertexException("MultipleKinematicConstraint::derivative requested for empty constraint");
110  int nStates = par.size();
111  AlgebraicVector param(7*nStates,0);
112 
113  int count = 1;
114  for(std::vector<RefCountedKinematicParticle>::const_iterator i = par.begin(); i!=par.end(); i++)
115  {
116  for(int j = 1; j<8; j++){param((count -1)*7+j) = (*i)->currentState().kinematicParameters().vector()(j-1);}
117  count++;
118  }
119  int total = 0;
120  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
121  {total += (*i)->numberOfEquations();}
122  AlgebraicMatrix dr(total,7*nStates);
123 
124  int cr_size = 0;
125  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
126  {
127 
128 //matrix should be (TotalNumberOfEquations x 7* TotalNumberOfStates)
129 //Derivative matrix for given constraint
130  AlgebraicMatrix lConst = (*i)->derivative(param).first;
131 
132 //putting it into the appropriate line
133  dr.sub(cr_size+1,1,lConst);
134  cr_size += (*i)->numberOfEquations();
135  }
136  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr,param);
137 }
138 
140 {
141  AlgebraicVector dev(nStates*7,0);
142  if(cts.empty()) throw VertexException("MultipleKinematicConstraint::deviations requested for empty constraint");
143  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
144  {
145  AlgebraicVector dev_loc =(*i)->deviations(nStates);
146  for(int j = 1; j < nStates*7+1; j++){dev(j) = dev(j) + dev_loc(j);}
147  }
148  return dev;
149 }
150 
void addConstraint(KinematicConstraint *newConst) const
Common base class.
std::pair< AlgebraicVector, AlgebraicVector > value(const AlgebraicVector &exPoint) const override
std::vector< KinematicConstraint * > cts
CLHEP::HepMatrix AlgebraicMatrix
CLHEP::HepVector AlgebraicVector
AlgebraicVector deviations(int nStates) const override
std::pair< AlgebraicMatrix, AlgebraicVector > derivative(const AlgebraicVector &exPoint) const override