CMS 3D CMS Logo

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