CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
KinematicConstrainedVertexUpdator Class Reference

#include <KinematicConstrainedVertexUpdator.h>

Public Member Functions

 KinematicConstrainedVertexUpdator ()
 
std::pair< std::pair< std::vector< KinematicState >, AlgebraicMatrix >, RefCountedKinematicVertexupdate (const AlgebraicVector &inState, const AlgebraicMatrix &inCov, const std::vector< KinematicState > &lStates, const GlobalPoint &lPoint, MultiTrackKinematicConstraint *cs) const
 
 ~KinematicConstrainedVertexUpdator ()
 

Private Attributes

VertexKinematicConstraintvConstraint
 
KinematicVertexFactoryvFactory
 

Detailed Description

Class caching the math part for KinematicConstrainedVertexFitter

Definition at line 13 of file KinematicConstrainedVertexUpdator.h.

Constructor & Destructor Documentation

◆ KinematicConstrainedVertexUpdator()

KinematicConstrainedVertexUpdator::KinematicConstrainedVertexUpdator ( )

◆ ~KinematicConstrainedVertexUpdator()

KinematicConstrainedVertexUpdator::~KinematicConstrainedVertexUpdator ( )

Definition at line 10 of file KinematicConstrainedVertexUpdator.cc.

References vConstraint, and vFactory.

10  {
11  delete vFactory;
12  delete vConstraint;
13 }

Member Function Documentation

◆ update()

std::pair< std::pair< std::vector< KinematicState >, AlgebraicMatrix >, RefCountedKinematicVertex > KinematicConstrainedVertexUpdator::update ( const AlgebraicVector inState,
const AlgebraicMatrix inCov,
const std::vector< KinematicState > &  lStates,
const GlobalPoint lPoint,
MultiTrackKinematicConstraint cs 
) const

Method updating the states. Takes a vector of full parameters: (x,y,z,particle_1,...,particle_n), corresponding linearization point: vector of states and GlobalPoint, and constraint to be applied during the vertex fit. Returns refitted vector of 7n+3 parameters and corresponding covariance matrix, where n - number of tracks.

Definition at line 16 of file KinematicConstrainedVertexUpdator.cc.

References callgraph::cs, g, mps_fire::i, edm::isNotFinite(), dqmiolumiharvest::j, LogDebug, VertexKinematicConstraint::parametersDerivative(), VertexKinematicConstraint::positionDerivative(), heppy_batch::val, VertexKinematicConstraint::value(), vConstraint, KinematicVertexFactory::vertex(), vFactory, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), KinematicConstrainedVertexFitter::fit(), and MatrixUtil.Steps::overwrite().

20  {
21  const MagneticField* field = lStates.front().magneticField();
22  AlgebraicMatrix d_matrix = vConstraint->parametersDerivative(lStates, lPoint);
23  AlgebraicMatrix e_matrix = vConstraint->positionDerivative(lStates, lPoint);
24  AlgebraicVector val_s = vConstraint->value(lStates, lPoint);
25  int vSize = lStates.size();
26 
27  //delta alpha
28  AlgebraicVector d_a(7 * vSize + 3);
29  d_a(1) = lPoint.x();
30  d_a(2) = lPoint.y();
31  d_a(3) = lPoint.z();
32 
33  int cst = 0;
34  for (std::vector<KinematicState>::const_iterator i = lStates.begin(); i != lStates.end(); i++) {
35  AlgebraicVector lst_par = asHepVector<7>(i->kinematicParameters().vector());
36  for (int j = 1; j < lst_par.num_row() + 1; j++) {
37  d_a(3 + 7 * cst + j) = lst_par(j);
38  }
39  cst++;
40  }
41 
42  AlgebraicVector delta_alpha = inPar - d_a;
43 
44  // cout<<"delta_alpha"<<delta_alpha<<endl;
45  //resulting matrix of derivatives and vector of values.
46  //their size depends of number of tracks to analyze and number of
47  //additional constraints to apply
50  if (cs == nullptr) {
51  //unconstrained vertex fitter case
52  g = AlgebraicMatrix(2 * vSize, 7 * vSize + 3, 0);
53  val = AlgebraicVector(2 * vSize);
54 
55  //filling the derivative matrix
56  g.sub(1, 1, e_matrix);
57  g.sub(1, 4, d_matrix);
58 
59  //filling the vector of values
60  val = val_s;
61  } else {
62  //constrained vertex fitter case
63  int n_eq = cs->numberOfEquations();
64  g = AlgebraicMatrix(n_eq + 2 * vSize, 7 * vSize + 3, 0);
65  val = AlgebraicVector(n_eq + 2 * vSize);
66  AlgebraicMatrix n_x = cs->positionDerivative(lStates, lPoint);
67  AlgebraicMatrix n_alpha = cs->parametersDerivative(lStates, lPoint);
68  AlgebraicVector c_val = cs->value(lStates, lPoint);
69 
70  //filling the derivative matrix
71  // cout<<"n_x:"<<n_x<<endl;
72  // cout<<"n_alpha"<<n_alpha<<endl;
73 
74  g.sub(1, 1, n_x);
75  g.sub(1, 4, n_alpha);
76  g.sub(n_eq + 1, 1, e_matrix);
77  g.sub(n_eq + 1, 4, d_matrix);
78 
79  //filling the vector of values
80  for (int i = 1; i < n_eq + 1; i++) {
81  val(i) = c_val(i);
82  }
83  for (int i = 1; i < (2 * vSize + 1); i++) {
84  val(i + n_eq) = val_s(i);
85  }
86  }
87 
88  //check for NaN
89  for (int i = 1; i <= val.num_row(); ++i) {
90  if (edm::isNotFinite(val(i))) {
91  LogDebug("KinematicConstrainedVertexUpdator") << "catched NaN.\n";
92  return std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex>(
93  std::pair<std::vector<KinematicState>, AlgebraicMatrix>(std::vector<KinematicState>(), AlgebraicMatrix(1, 0)),
95  }
96  }
97 
98  //debug feature
99  AlgebraicSymMatrix in_cov_sym(7 * vSize + 3, 0);
100 
101  for (int i = 1; i < 7 * vSize + 4; ++i) {
102  for (int j = 1; j < 7 * vSize + 4; ++j) {
103  if (i <= j)
104  in_cov_sym(i, j) = inCov(i, j);
105  }
106  }
107 
108  //debug code
109  AlgebraicSymMatrix v_g_sym = in_cov_sym.similarity(g);
110 
111  int ifl1 = 0;
112  v_g_sym.invert(ifl1);
113  if (ifl1 != 0) {
114  LogDebug("KinematicConstrainedVertexFitter") << "Fit failed: unable to invert SYM gain matrix\n";
115  return std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex>(
116  std::pair<std::vector<KinematicState>, AlgebraicMatrix>(std::vector<KinematicState>(), AlgebraicMatrix(1, 0)),
118  }
119 
120  // delta alpha is now valid!
121  //full math case now!
122  AlgebraicVector lambda = v_g_sym * (g * delta_alpha + val);
123 
124  //final parameters
125  AlgebraicVector finPar = inPar - in_cov_sym * g.T() * lambda;
126 
127  //covariance matrix business:
128  AlgebraicMatrix mFactor = in_cov_sym * (v_g_sym.similarityT(g)) * in_cov_sym;
129 
130  //refitted covariance
131  AlgebraicMatrix rCov = in_cov_sym - mFactor;
132 
133  //symmetric covariance:
134  AlgebraicSymMatrix r_cov_sym(7 * vSize + 3, 0);
135  for (int i = 1; i < 7 * vSize + 4; ++i) {
136  for (int j = 1; j < 7 * vSize + 4; ++j) {
137  if (i <= j)
138  r_cov_sym(i, j) = rCov(i, j);
139  }
140  }
141 
142  AlgebraicSymMatrix pCov = r_cov_sym.sub(1, 3);
143 
144  // chi2
145  AlgebraicVector chi = lambda.T() * (g * delta_alpha + val);
146 
147  //this is ndf without significant prior
148  //vertex so -3 factor exists here
149  float ndf = 2 * vSize - 3;
150  if (cs != nullptr) {
151  ndf += cs->numberOfEquations();
152  }
153 
154  //making resulting vertex
155  GlobalPoint vPos(finPar(1), finPar(2), finPar(3));
156  VertexState st(vPos, GlobalError(asSMatrix<3>(pCov)));
157  RefCountedKinematicVertex rVtx = vFactory->vertex(st, chi(1), ndf);
158 
159  //making refitted states of Kinematic Particles
160  int i_int = 0;
161  std::vector<KinematicState> ns;
162  for (std::vector<KinematicState>::const_iterator i_st = lStates.begin(); i_st != lStates.end(); i_st++) {
163  AlgebraicVector7 newPar;
164  for (int i = 0; i < 7; i++) {
165  newPar(i) = finPar(4 + i_int * 7 + i);
166  }
167 
168  AlgebraicSymMatrix nCovariance = r_cov_sym.sub(4 + i_int * 7, 10 + i_int * 7);
169  TrackCharge chl = i_st->particleCharge();
170  KinematicParameters nrPar(newPar);
171  KinematicParametersError nrEr(asSMatrix<7>(nCovariance));
172  KinematicState newState(nrPar, nrEr, chl, field);
173  ns.push_back(newState);
174  i_int++;
175  }
176  std::pair<std::vector<KinematicState>, AlgebraicMatrix> ns_m(ns, rCov);
177  return std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex>(ns_m, rVtx);
178 }
AlgebraicMatrix positionDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
AlgebraicMatrix parametersDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
T z() const
Definition: PV3DBase.h:61
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
int TrackCharge
Definition: TrackCharge.h:4
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
AlgebraicVector value(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
CLHEP::HepMatrix AlgebraicMatrix
CLHEP::HepVector AlgebraicVector
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
CLHEP::HepSymMatrix AlgebraicSymMatrix
static RefCountedKinematicVertex vertex(const VertexState &state, float totalChiSq, float degreesOfFr)
#define LogDebug(id)

Member Data Documentation

◆ vConstraint

VertexKinematicConstraint* KinematicConstrainedVertexUpdator::vConstraint
private

◆ vFactory

KinematicVertexFactory* KinematicConstrainedVertexUpdator::vFactory
private