CMS 3D CMS Logo

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
Vector3DBase
Definition: Vector3DBase.h:8
KineDebug3::Count
Definition: KinematicConstrainedVertexUpdatorT.h:16
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
TrackCharge
int TrackCharge
Definition: TrackCharge.h:4
KineDebug3::Count::Count
Count()
Definition: KinematicConstrainedVertexUpdatorT.h:18
KinematicConstrainedVertexUpdatorT::KinematicConstrainedVertexUpdatorT
KinematicConstrainedVertexUpdatorT()
Definition: KinematicConstrainedVertexUpdatorT.h:76
MultiTrackKinematicConstraintT.h
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
KinematicVertexFactory
Definition: KinematicVertexFactory.h:15
cms::cuda::assert
assert(be >=bs)
ReferenceCountingPointer< KinematicVertex >
KinematicConstrainedVertexUpdatorT::vConstraint
VertexKinematicConstraintT vConstraint
Definition: KinematicConstrainedVertexUpdatorT.h:61
KinematicVertexFactory.h
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
VertexKinematicConstraintT.h
GlobalError
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
KinematicConstrainedVertexUpdatorT::v_g_sym
ROOT::Math::SMatrix< double, nConstraint+4, nConstraint+4, ROOT::Math::MatRepSym< double, nConstraint+4 > > v_g_sym
Definition: KinematicConstrainedVertexUpdatorT.h:70
KinematicConstrainedVertexUpdatorT::nCovariance
ROOT::Math::SMatrix< double, 7, 7, ROOT::Math::MatRepSym< double, 7 > > nCovariance
Definition: KinematicConstrainedVertexUpdatorT.h:68
KinematicConstrainedVertexUpdatorT::lambda
ROOT::Math::SVector< double, nConstraint+4 > lambda
Definition: KinematicConstrainedVertexUpdatorT.h:66
MultiTrackKinematicConstraintT
Definition: MultiTrackKinematicConstraintT.h:39
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
KineDebug3::Count::~Count
~Count()
Definition: KinematicConstrainedVertexUpdatorT.h:19
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
Point3DBase< float, GlobalTag >
KineDebug3::Count::n
std::atomic< int > n
Definition: KinematicConstrainedVertexUpdatorT.h:17
edm::LogWarning
Definition: MessageLogger.h:141
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
KineDebug3
Definition: KinematicConstrainedVertexUpdatorT.h:15
thread_safety_macros.h
prod1Switch_cff.prod1
prod1
Definition: prod1Switch_cff.py:9
KinematicConstrainedVertexUpdatorT::g
ROOT::Math::SMatrix< double, nConstraint+4, 3+7 *nTrk > g
Definition: KinematicConstrainedVertexUpdatorT.h:63
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
KinematicParameters
Definition: KinematicParameters.h:15
KinematicConstrainedVertexUpdatorT::vFactory
KinematicVertexFactory vFactory
Definition: KinematicConstrainedVertexUpdatorT.h:60
invertPosDefMatrix
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
Definition: invertPosDefMatrix.h:10
KinematicParametersError
Definition: KinematicParametersError.h:20
AlgebraicVector7
ROOT::Math::SVector< double, 7 > AlgebraicVector7
Definition: Matrices.h:8
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
KinematicConstrainedVertexUpdatorT::pCov
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > pCov
Definition: KinematicConstrainedVertexUpdatorT.h:67
KinematicConstrainedVertexUpdatorT
Definition: KinematicConstrainedVertexUpdatorT.h:34
KinematicConstrainedVertexUpdatorT::delta_alpha
ROOT::Math::SVector< double, 3+7 *nTrk > delta_alpha
Definition: KinematicConstrainedVertexUpdatorT.h:62
KinematicConstrainedVertexUpdatorT::update
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)
Definition: KinematicConstrainedVertexUpdatorT.h:82
VertexKinematicConstraintT
Definition: VertexKinematicConstraintT.h:14
heppy_batch.val
val
Definition: heppy_batch.py:351
VertexState
Definition: VertexState.h:13
KinematicConstrainedVertexUpdatorT::~KinematicConstrainedVertexUpdatorT
~KinematicConstrainedVertexUpdatorT()
Definition: KinematicConstrainedVertexUpdatorT.h:79
KinematicConstrainedVertexUpdatorT::finPar
ROOT::Math::SVector< double, 3+7 *nTrk > finPar
Definition: KinematicConstrainedVertexUpdatorT.h:65
RefCountedKinematicVertex
ReferenceCountingPointer< KinematicVertex > RefCountedKinematicVertex
Definition: RefCountedKinematicVertex.h:7
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MagneticField
Definition: MagneticField.h:19
invertPosDefMatrix.h
KinematicConstrainedVertexUpdatorT::val
ROOT::Math::SVector< double, nConstraint+4 > val
Definition: KinematicConstrainedVertexUpdatorT.h:64
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