CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiVertexStateCombiner.cc
Go to the documentation of this file.
3 
4 
6 MultiVertexStateCombiner::combine(const VSC & theMixture) const
7 {
8 
9  if (theMixture.empty()) {
10  throw VertexException
11  ("MultiVertexStateCombiner:: VertexState container to collapse is empty");
12  }
13 
14  if (theMixture.size()==1) {
15 // #ifndef CMS_NO_COMPLEX_RETURNS
16  return VertexState(theMixture.front().position(), theMixture.front().error(), 1.0);
17 // #else
18 // VertexState theFinalVM(theMixture.front().position(), theMixture.front().error(), 1.0);
19 // return theFinalVM;
20 // #endif
21  }
22 
23 
24  AlgebraicVector meanPosition(3,0);
25  double weightSum = 0.;
26  double vtxWeight;
27  AlgebraicSymMatrix measCovar1(3,0), measCovar2(3,0);
28  for (VSC::const_iterator mixtureIter1 = theMixture.begin();
29  mixtureIter1 != theMixture.end(); mixtureIter1++ ) {
30  vtxWeight = mixtureIter1->weightInMixture();
31 
32  GlobalPoint vertexPosition = mixtureIter1->position();
33  AlgebraicVector vertexCoord1(3);
34  vertexCoord1[0] = vertexPosition.x();
35  vertexCoord1[1] = vertexPosition.y();
36  vertexCoord1[2] = vertexPosition.z();
37 
38 // AlgebraicVector position = mixtureIter1->position().vector(); //???
39  weightSum += vtxWeight;
40  meanPosition += vtxWeight * vertexCoord1;
41 
42  measCovar1 += vtxWeight * mixtureIter1->error().matrix();
43  for (VSC::const_iterator mixtureIter2 = mixtureIter1+1;
44  mixtureIter2 != theMixture.end(); mixtureIter2++ ) {
45  GlobalPoint vertexPosition2 = mixtureIter2->position();
46  AlgebraicVector vertexCoord2(3);
47  vertexCoord2[0] = vertexPosition2.x();
48  vertexCoord2[1] = vertexPosition2.y();
49  vertexCoord2[2] = vertexPosition2.z();
50  AlgebraicVector posDiff = vertexCoord1 - vertexCoord2;
51  AlgebraicSymMatrix s(1,1); //stupid trick to make CLHEP work decently
52  measCovar2 +=vtxWeight * mixtureIter2->weightInMixture() *
53  s.similarity(posDiff.T().T());
54  }
55  }
56  meanPosition /= weightSum;
57  AlgebraicSymMatrix measCovar = measCovar1/weightSum + measCovar2/weightSum/weightSum;
58 
59  GlobalPoint newPos(meanPosition[0], meanPosition[1], meanPosition[2]);
60 
61 // #ifndef CMS_NO_COMPLEX_RETURNS
62  return VertexState(newPos, GlobalError(measCovar), weightSum);
63 // #else
64 // VertexState theFinalVS(newPos, GlobalError(measCovar), weightSum);
65 // return theFinalVS;
66 // #endif
67 }
VertexState combine(const VSC &theMixture) const
Common base class.
T y() const
Definition: PV3DBase.h:57
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:11
T z() const
Definition: PV3DBase.h:58
std::vector< VertexState > VSC
CLHEP::HepVector AlgebraicVector
CLHEP::HepSymMatrix AlgebraicSymMatrix
string s
Definition: asciidump.py:422
T x() const
Definition: PV3DBase.h:56