CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KinematicConstrainedVertexUpdatorT.h
Go to the documentation of this file.
1 #ifndef KinematicConstrainedVertexUpdatorT_H
2 #define KinematicConstrainedVertexUpdatorT_H
3 
4 #include <atomic>
5 #include <cassert>
6 #include <iostream>
7 
13 
14 // the usual stupid counter
15 namespace KineDebug3 {
16  struct Count {
17  std::atomic<int> n;
18  Count() : n(0) {}
19  ~Count() {}
20  };
21  inline void count() {
22  CMS_THREAD_SAFE static Count c;
23  ++c.n;
24  }
25 
26 } // namespace KineDebug3
27 
33 template <int nTrk, int nConstraint>
35 public:
40 
42 
52  const ROOT::Math::SVector<double, 3 + 7 * nTrk>& inState,
53  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> >& inCov,
54  std::vector<KinematicState>& lStates,
55  const GlobalPoint& lPoint,
56  GlobalVector const& fieldValue,
58 
59 private:
62  ROOT::Math::SVector<double, 3 + 7 * nTrk> delta_alpha;
63  ROOT::Math::SMatrix<double, nConstraint + 4, 3 + 7 * nTrk> g;
64  ROOT::Math::SVector<double, nConstraint + 4> val;
65  ROOT::Math::SVector<double, 3 + 7 * nTrk> finPar;
66  ROOT::Math::SVector<double, nConstraint + 4> lambda;
67  ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > pCov = ROOT::Math::SMatrixNoInit();
68  ROOT::Math::SMatrix<double, 7, 7, ROOT::Math::MatRepSym<double, 7> > nCovariance = ROOT::Math::SMatrixNoInit();
69  ROOT::Math::SMatrix<double, nConstraint + 4, nConstraint + 4, ROOT::Math::MatRepSym<double, nConstraint + 4> >
70  v_g_sym = ROOT::Math::SMatrixNoInit();
71 };
72 
74 
75 template <int nTrk, int nConstraint>
77 
78 template <int nTrk, int nConstraint>
80 
81 template <int nTrk, int nConstraint>
83  const ROOT::Math::SVector<double, 3 + 7 * nTrk>& inPar,
84  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> >& inCov,
85  std::vector<KinematicState>& lStates,
86  const GlobalPoint& lPoint,
87  GlobalVector const& fieldValue,
90 
91  int vSize = lStates.size();
92 
93  assert(nConstraint == 0 || cs != nullptr);
94  assert(vSize == nConstraint);
95 
96  const MagneticField* field = lStates.front().magneticField();
97 
98  delta_alpha = inPar;
99  delta_alpha(0) -= lPoint.x();
100  delta_alpha(1) -= lPoint.y();
101  delta_alpha(2) -= lPoint.z();
102  int cst = 3;
103  for (std::vector<KinematicState>::const_iterator i = lStates.begin(); i != lStates.end(); i++)
104  for (int j = 0; j < 7; j++) {
105  delta_alpha(cst) -= i->kinematicParameters()(j);
106  cst++;
107  }
108 
109  // cout<<"delta_alpha"<<delta_alpha<<endl;
110  //resulting matrix of derivatives and vector of values.
111  //their size depends of number of tracks to analyze and number of
112  //additional constraints to apply
113 
114  if (nConstraint != 0) {
115  cs->init(lStates, lPoint, fieldValue);
116  val.Place_at(cs->value(), 0);
117  g.Place_at(cs->positionDerivative(), 0, 0);
118  g.Place_at(cs->parametersDerivative(), 0, 3);
119  }
120 
121  vConstraint.init(lStates, lPoint, fieldValue);
122  val.Place_at(vConstraint.value(), nConstraint);
123  g.Place_at(vConstraint.positionDerivative(), nConstraint, 0);
124  g.Place_at(vConstraint.parametersDerivative(), nConstraint, 3);
125 
126  //debug code
127  v_g_sym = ROOT::Math::Similarity(g, inCov);
128 
129  // bool ifl1 = v_g_sym.Invert();
130  bool ifl1 = invertPosDefMatrix(v_g_sym);
131  if (!ifl1) {
132  edm::LogWarning("KinematicConstrainedVertexUpdatorFailed") << "invert failed\n" << v_g_sym;
133  LogDebug("KinematicConstrainedVertexFitter3") << "Fit failed: unable to invert SYM gain matrix\n";
134  return RefCountedKinematicVertex();
135  }
136 
137  // delta alpha is now valid!
138  //full math case now!
139  val += g * delta_alpha;
140  lambda = v_g_sym * val;
141 
142  //final parameters
143  finPar = inPar - inCov * (ROOT::Math::Transpose(g) * lambda);
144 
145  //refitted covariance
146  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > prod =
147  ROOT::Math::SimilarityT(g, v_g_sym);
148  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > prod1;
149  ROOT::Math::AssignSym::Evaluate(prod1, inCov * prod * inCov);
150  // ROOT::Math::AssignSym::Evaluate(prod, prod1 * inCov);
151  inCov -= prod1;
152 
153  pCov = inCov.template Sub<ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > >(0, 0);
154 
155  // chi2
156  double chi = ROOT::Math::Dot(lambda, val); //??
157 
158  //this is ndf without significant prior
159  //vertex so -3 factor exists here
160  float ndf = 2 * vSize - 3;
161  ndf += nConstraint;
162 
163  //making resulting vertex
164  GlobalPoint vPos(finPar(0), finPar(1), finPar(2));
165  VertexState st(vPos, GlobalError(pCov));
166  RefCountedKinematicVertex rVtx = vFactory.vertex(st, chi, ndf);
167 
168  //making refitted states of Kinematic Particles
169  AlgebraicVector7 newPar;
170  int i_int = 0;
171  for (std::vector<KinematicState>::iterator i_st = lStates.begin(); i_st != lStates.end(); i_st++) {
172  for (int i = 0; i < 7; i++) {
173  newPar(i) = finPar(3 + i_int * 7 + i);
174  }
175 
176  nCovariance = inCov.template Sub<ROOT::Math::SMatrix<double, 7, 7, ROOT::Math::MatRepSym<double, 7> > >(
177  3 + i_int * 7, 3 + i_int * 7);
178  TrackCharge chl = i_st->particleCharge();
179  KinematicParameters nrPar(newPar);
180  KinematicParametersError nrEr(nCovariance);
181  KinematicState newState(nrPar, nrEr, chl, field);
182  (*i_st) = newState;
183  i_int++;
184  }
185  return rVtx;
186 }
187 
188 #endif
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > pCov
const edm::EventSetup & c
RefCountedKinematicVertex update(const ROOT::Math::SVector< double, 3+7 *nTrk > &inState, ROOT::Math::SMatrix< double, 3+7 *nTrk, 3+7 *nTrk, ROOT::Math::MatRepSym< double, 3+7 *nTrk > > &inCov, std::vector< KinematicState > &lStates, const GlobalPoint &lPoint, GlobalVector const &fieldValue, MultiTrackKinematicConstraintT< nTrk, nConstraint > *cs)
ROOT::Math::SMatrix< double, nConstraint+4, nConstraint+4, ROOT::Math::MatRepSym< double, nConstraint+4 > > v_g_sym
unique_ptr< ClusterSequence > cs
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
ROOT::Math::SVector< double, nConstraint+4 > val
assert(be >=bs)
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 z() const
Definition: PV3DBase.h:61
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
#define CMS_THREAD_SAFE
ROOT::Math::SVector< double, 3+7 *nTrk > finPar
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepSym< double, 7 > > nCovariance
parametersDerivativeType const & parametersDerivative() const
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
positionDerivativeType const & positionDerivative() const
ROOT::Math::SVector< double, nConstraint+4 > lambda
virtual void init(const std::vector< KinematicState > &states, const GlobalPoint &point, const GlobalVector &mf)=0
Log< level::Warning, false > LogWarning
T x() const
Definition: PV3DBase.h:59
ROOT::Math::SMatrix< double, nConstraint+4, 3+7 *nTrk > g
#define LogDebug(id)
ROOT::Math::SVector< double, 3+7 *nTrk > delta_alpha