CMS 3D CMS Logo

FourMomentumKinematicConstraint.cc
Go to the documentation of this file.
3 
5  const AlgebraicVector& deviation) {
6  if ((momentum.num_row() != 4) || (deviation.num_row() != 4))
7  throw VertexException("FourMomentumKinematicConstraint::vector of wrong size passed as 4-Momentum or Deviations");
8  mm = momentum;
9  AlgebraicVector deviation_l(7, 0);
10  deviation_l(6) = momentum(3);
11  deviation_l(5) = momentum(2);
12  deviation_l(4) = momentum(1);
13 
14  double mass_sq =
15  momentum(4) * momentum(4) - momentum(3) * momentum(3) - momentum(2) * momentum(2) - momentum(1) * momentum(1);
16 
17  if (mass_sq == 0.)
18  throw VertexException("FourMomentumKinematicConstraint::the constraint vector passed corresponds to 0 mass");
19  //deviation for mass calculated from deviations
20  //of momentum
21  deviation_l(7) =
22  momentum(4) * momentum(4) * deviation(4) / mass_sq + momentum(3) * momentum(3) * deviation(3) / mass_sq +
23  momentum(2) * momentum(2) * deviation(2) / mass_sq + momentum(1) * momentum(1) * deviation(1) / mass_sq;
24  //mass sigma because of the energy
25 
26  dd = deviation_l;
27 }
28 
29 std::pair<AlgebraicVector, AlgebraicVector> FourMomentumKinematicConstraint::value(
30  const AlgebraicVector& exPoint) const {
31  if (exPoint.num_row() == 0)
32  throw VertexException("FourMomentumKinematicConstraint::value requested for zero Linearization point");
33 
34  //security check for extended cartesian parametrization
35  int inSize = exPoint.num_row();
36  if ((inSize % 7) != 0)
37  throw VertexException("FourMomentumKinematicConstraint::linearization point has a wrong dimension");
38  int nStates = inSize / 7;
39  if (nStates != 1)
40  throw VertexException("FourMomentumKinematicConstraint::Multi particle refit is not supported in this version");
41  AlgebraicVector pr = exPoint;
42  AlgebraicVector vl(4, 0);
43  vl(1) += (pr(4) - mm(1));
44  vl(2) += (pr(5) - mm(2));
45  vl(3) += (pr(6) - mm(3));
46  vl(7) += (sqrt(pr(4) * pr(4) + pr(5) * pr(5) + pr(6) * pr(6) + pr(7) * pr(7)) - mm(4));
47 
48  return std::pair<AlgebraicVector, AlgebraicVector>(vl, pr);
49 }
50 
51 std::pair<AlgebraicMatrix, AlgebraicVector> FourMomentumKinematicConstraint::derivative(
52  const AlgebraicVector& exPoint) const {
53  if (exPoint.num_row() == 0)
54  throw VertexException("FourMomentumKinematicConstraint::value requested for zero Linearization point");
55 
56  //security check for extended cartesian parametrization
57  int inSize = exPoint.num_row();
58  if ((inSize % 7) != 0)
59  throw VertexException("FourMomentumKinematicConstraint::linearization point has a wrong dimension");
60  int nStates = inSize / 7;
61  if (nStates != 1)
62  throw VertexException("FourMomentumKinematicConstraint::Multi particle refit is not supported in this version");
63  AlgebraicVector pr = exPoint;
64  AlgebraicMatrix dr(4, 7, 0);
65 
66  dr(1, 4) = 1.;
67  dr(2, 5) = 1.;
68  dr(3, 6) = 1.;
69  dr(4, 7) = pr(7) / sqrt(pr(4) * pr(4) + pr(5) * pr(5) + pr(6) * pr(6) + pr(7) * pr(7));
70 
71  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr, pr);
72 }
73 
74 std::pair<AlgebraicVector, AlgebraicVector> FourMomentumKinematicConstraint::value(
75  const std::vector<RefCountedKinematicParticle>& par) const {
76  int nStates = par.size();
77  if (nStates == 0)
78  throw VertexException("FourMomentumKinematicConstraint::Empty vector of particles passed");
79  if (nStates != 1)
80  throw VertexException("FourMomentumKinematicConstraint::Multi particle refit is not supported in this version");
81  AlgebraicVector pr = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
82  AlgebraicVector vl(4, 0);
83 
84  vl(1) = pr(4) - mm(1);
85  vl(2) = pr(5) - mm(2);
86  vl(3) = pr(6) - mm(3);
87  vl(7) = sqrt(pr(4) * pr(4) + pr(5) * pr(5) + pr(6) * pr(6) + pr(7) * pr(7)) - mm(4);
88 
89  return std::pair<AlgebraicVector, AlgebraicVector>(vl, pr);
90 }
91 
92 std::pair<AlgebraicMatrix, AlgebraicVector> FourMomentumKinematicConstraint::derivative(
93  const std::vector<RefCountedKinematicParticle>& par) const {
94  int nStates = par.size();
95  if (nStates == 0)
96  throw VertexException("FourMomentumKinematicConstraint::Empty vector of particles passed");
97  if (nStates != 1)
98  throw VertexException("FourMomentumKinematicConstraint::Multi particle refit is not supported in this version");
99  AlgebraicMatrix dr(4, 7, 0);
100 
101  AlgebraicVector pr = asHepVector<7>(par.front()->currentState().kinematicParameters().vector());
102  dr(1, 4) = 1.;
103  dr(2, 5) = 1.;
104  dr(3, 6) = 1.;
105  dr(4, 7) = -pr(7) / sqrt(pr(4) * pr(4) + pr(5) * pr(5) + pr(6) * pr(6) + pr(7) * pr(7));
106 
107  return std::pair<AlgebraicMatrix, AlgebraicVector>(dr, pr);
108 }
109 
111  if (nStates == 0)
112  throw VertexException("FourMomentumKinematicConstraint::Empty vector of particles passed");
113  if (nStates != 1)
114  throw VertexException("FourMomentumKinematicConstraint::Multi particle refit is not supported in this version");
116  return res;
117 }
118 
std::pair< AlgebraicVector, AlgebraicVector > value(const AlgebraicVector &exPoint) const override
Common base class.
Definition: Electron.h:6
std::pair< AlgebraicMatrix, AlgebraicVector > derivative(const AlgebraicVector &exPoint) const override
CLHEP::HepMatrix AlgebraicMatrix
AlgebraicVector deviations(int nStates) const override
T sqrt(T t)
Definition: SSEVec.h:19
CLHEP::HepVector AlgebraicVector
FourMomentumKinematicConstraint(const AlgebraicVector &momentum, const AlgebraicVector &deviation)