CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultipleKinematicConstraint.cc
Go to the documentation of this file.
2 
4 {
5  if(newConst == 0)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.size() == 0)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.size() == 0) 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  AlgebraicVector expansion = exPoint;
46  int inSize = exPoint.num_row();
47  if((inSize%7) !=0) throw VertexException("MultipleKinematicConstraint::linearization point has a wrong dimension");
48 
49 
50  AlgebraicVector par = exPoint;
51  int total = 0;
52  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
53  {total += (*i)->numberOfEquations();}
54 
55 //Full derivative matrix: (numberOfConstraints x 7*numberOfStates)
56  AlgebraicMatrix dr(total,inSize);
57 
58  int cr_size = 0;
59  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
60  {
61 //matrix should be (nx7*NumberOfStates)
62  AlgebraicMatrix lConst = (*i)->derivative(par).first;
63  dr.sub(cr_size+1,1,lConst);
64  cr_size += (*i)->numberOfEquations();
65  }
66  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr,par);
67 }
68 
70 {
71  int ne = 0;
72  if(cts.size() == 0) throw VertexException("MultipleKinematicConstraint::number of equations requested for empty constraint");
73  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
74  {ne += (*i)->numberOfEquations();}
75  return ne;
76 }
77 
78 std::pair<AlgebraicVector, AlgebraicVector> MultipleKinematicConstraint::value(const std::vector<RefCountedKinematicParticle> &par) const
79 {
80  if(cts.size() == 0) throw VertexException("MultipleKinematicConstraint::derivative requested for empty constraint");
81  int nStates = par.size();
82  AlgebraicVector param(7*nStates,0);
83  int count = 1;
84  for(std::vector<RefCountedKinematicParticle>::const_iterator i = par.begin(); i!=par.end(); i++)
85  {
86  for(int j = 1; j<8; j++){param((count -1)*7+j) = (*i)->currentState().kinematicParameters().vector()(j-1);}
87  count++;
88  }
89 
90 //looking for total number of equations
91  int total = 0;
92  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
93  {total += (*i)->numberOfEquations();}
94  AlgebraicVector vl(total,0);
95 
96  int cr_size = 0;
97  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
98  {
99  AlgebraicVector vlc = (*i)->value(par).first;
100  int sz = vlc.num_row();
101  for(int j = 1; j <= sz; j++)
102  {vl(cr_size+j) = vlc(j);}
103  cr_size += sz;
104  }
105  return std::pair<AlgebraicVector, AlgebraicVector>(vl,param);
106 }
107 
108 std::pair<AlgebraicMatrix, AlgebraicVector> MultipleKinematicConstraint::derivative(const std::vector<RefCountedKinematicParticle> &par) const
109 {
110  if(cts.size() == 0) throw VertexException("MultipleKinematicConstraint::derivative requested for empty constraint");
111  int nStates = par.size();
112  AlgebraicVector param(7*nStates,0);
113 
114  int count = 1;
115  for(std::vector<RefCountedKinematicParticle>::const_iterator i = par.begin(); i!=par.end(); i++)
116  {
117  for(int j = 1; j<8; j++){param((count -1)*7+j) = (*i)->currentState().kinematicParameters().vector()(j-1);}
118  count++;
119  }
120  int total = 0;
121  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
122  {total += (*i)->numberOfEquations();}
123  AlgebraicMatrix dr(total,7*nStates);
124 
125  int cr_size = 0;
126  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
127  {
128 
129 //matrix should be (TotalNumberOfEquations x 7* TotalNumberOfStates)
130 //Derivative matrix for given constraint
131  AlgebraicMatrix lConst = (*i)->derivative(param).first;
132 
133 //putting it into the appropriate line
134  dr.sub(cr_size+1,1,lConst);
135  cr_size += (*i)->numberOfEquations();
136  }
137  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr,param);
138 }
139 
141 {
142  AlgebraicVector dev(nStates*7,0);
143  if(cts.size() == 0) throw VertexException("MultipleKinematicConstraint::deviations requested for empty constraint");
144  for(std::vector<KinematicConstraint *>::const_iterator i = cts.begin(); i != cts.end(); i++)
145  {
146  AlgebraicVector dev_loc =(*i)->deviations(nStates);
147  for(int j = 1; j < nStates*7+1; j++){dev(j) = dev(j) + dev_loc(j);}
148  }
149  return dev;
150 }
151 
int i
Definition: DBlmapReader.cc:9
void addConstraint(KinematicConstraint *newConst) const
Common base class.
std::pair< AlgebraicVector, AlgebraicVector > value(const AlgebraicVector &exPoint) const
std::vector< KinematicConstraint * > cts
std::pair< AlgebraicMatrix, AlgebraicVector > derivative(const AlgebraicVector &exPoint) const
CLHEP::HepMatrix AlgebraicMatrix
int j
Definition: DBlmapReader.cc:9
CLHEP::HepVector AlgebraicVector
AlgebraicVector deviations(int nStates) const