CMS 3D CMS Logo

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