CMS 3D CMS Logo

KinematicConstrainedVertexUpdator.cc
Go to the documentation of this file.
4 
8 }
9 
11  delete vFactory;
12  delete vConstraint;
13 }
14 
15 std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex>
17  const AlgebraicMatrix& inCov,
18  const std::vector<KinematicState>& lStates,
19  const GlobalPoint& lPoint,
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 }
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
TrackCharge
int TrackCharge
Definition: TrackCharge.h:4
VertexKinematicConstraint::value
AlgebraicVector value(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
Definition: VertexKinematicConstraint.cc:9
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:45
KinematicState
Definition: KinematicState.h:17
KinematicConstrainedVertexUpdator::vFactory
KinematicVertexFactory * vFactory
Definition: KinematicConstrainedVertexUpdator.h:38
KinematicVertexFactory
Definition: KinematicVertexFactory.h:15
KinematicConstrainedVertexUpdator::KinematicConstrainedVertexUpdator
KinematicConstrainedVertexUpdator()
Definition: KinematicConstrainedVertexUpdator.cc:5
MultiTrackKinematicConstraint
Definition: MultiTrackKinematicConstraint.h:23
KinematicConstrainedVertexUpdator::vConstraint
VertexKinematicConstraint * vConstraint
Definition: KinematicConstrainedVertexUpdator.h:39
ReferenceCountingPointer< KinematicVertex >
VertexKinematicConstraint::parametersDerivative
AlgebraicMatrix parametersDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
Definition: VertexKinematicConstraint.cc:50
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
GlobalError
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
Point3DBase< float, GlobalTag >
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
VertexKinematicConstraint::positionDerivative
AlgebraicMatrix positionDerivative(const std::vector< KinematicState > &states, const GlobalPoint &point) const override
Definition: VertexKinematicConstraint.cc:112
KinematicConstrainedVertexUpdator::~KinematicConstrainedVertexUpdator
~KinematicConstrainedVertexUpdator()
Definition: KinematicConstrainedVertexUpdator.cc:10
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
KinematicParameters
Definition: KinematicParameters.h:15
VertexKinematicConstraint
Definition: VertexKinematicConstraint.h:14
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
KinematicParametersError
Definition: KinematicParametersError.h:20
AlgebraicVector7
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
KinematicConstrainedVertexUpdator::update
std::pair< std::pair< std::vector< KinematicState >, AlgebraicMatrix >, RefCountedKinematicVertex > update(const AlgebraicVector &inState, const AlgebraicMatrix &inCov, const std::vector< KinematicState > &lStates, const GlobalPoint &lPoint, MultiTrackKinematicConstraint *cs) const
Definition: KinematicConstrainedVertexUpdator.cc:16
heppy_batch.val
val
Definition: heppy_batch.py:351
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
isFinite.h
VertexState
Definition: VertexState.h:13
RefCountedKinematicVertex
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
Definition: RefCountedKinematicVertex.h:7
KinematicConstrainedVertexUpdator.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
KinematicVertexFactory::vertex
static RefCountedKinematicVertex vertex(const VertexState &state, float totalChiSq, float degreesOfFr)
Definition: KinematicVertexFactory.h:23
MagneticField
Definition: MagneticField.h:19
g
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