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 ( )

Definition at line 10 of file KinematicConstrainedVertexUpdator.cc.

References vConstraint, and vFactory.

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

Member Function Documentation

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 g, mps_fire::i, edm::isNotFinite(), dqmiolumiharvest::j, LogDebug, MultiTrackKinematicConstraint::numberOfEquations(), VertexKinematicConstraint::parametersDerivative(), MultiTrackKinematicConstraint::parametersDerivative(), VertexKinematicConstraint::positionDerivative(), MultiTrackKinematicConstraint::positionDerivative(), heppy_batch::val, VertexKinematicConstraint::value(), MultiTrackKinematicConstraint::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__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), KinematicConstrainedVertexFitter::fit(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

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 }
#define LogDebug(id)
virtual int numberOfEquations() const =0
virtual AlgebraicMatrix parametersDerivative(const std::vector< KinematicState > &, const GlobalPoint &) const =0
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
T y() const
Definition: PV3DBase.h:60
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
AlgebraicMatrix parametersDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
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
AlgebraicVector value(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
int TrackCharge
Definition: TrackCharge.h:4
CLHEP::HepMatrix AlgebraicMatrix
T z() const
Definition: PV3DBase.h:61
CLHEP::HepVector AlgebraicVector
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
virtual AlgebraicMatrix positionDerivative(const std::vector< KinematicState > &, const GlobalPoint &) const =0
virtual AlgebraicVector value(const std::vector< KinematicState > &, const GlobalPoint &) const =0
CLHEP::HepSymMatrix AlgebraicSymMatrix
static RefCountedKinematicVertex vertex(const VertexState &state, float totalChiSq, float degreesOfFr)
T x() const
Definition: PV3DBase.h:59
AlgebraicMatrix positionDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override

Member Data Documentation

VertexKinematicConstraint* KinematicConstrainedVertexUpdator::vConstraint
private
KinematicVertexFactory* KinematicConstrainedVertexUpdator::vFactory
private