CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types
MultiGaussianStateCombiner1D Class Reference

#include <MultiGaussianStateCombiner1D.h>

Public Member Functions

SingleGaussianState1D combine (const MultiGaussianState1D &theState) const
 
SingleGaussianState1D combine (const VSC &theComponents) const
 

Private Types

typedef std::vector< SingleGaussianState1DVSC
 

Detailed Description

Class to collapse (combine) a Gaussian mixture of states into one. (c.f. R. Fruewirth et.al., Comp.Phys.Comm 100 (1997) 1

Definition at line 13 of file MultiGaussianStateCombiner1D.h.

Member Typedef Documentation

◆ VSC

Definition at line 15 of file MultiGaussianStateCombiner1D.h.

Member Function Documentation

◆ combine() [1/2]

SingleGaussianState1D MultiGaussianStateCombiner1D::combine ( const MultiGaussianState1D theState) const

Definition at line 7 of file MultiGaussianStateCombiner1D.cc.

References MultiGaussianState1D::components().

7  {
8  return combine(theState.components());
9 }
SingleGaussianState1D combine(const MultiGaussianState1D &theState) const
const SingleState1dContainer & components() const
access to components

◆ combine() [2/2]

SingleGaussianState1D MultiGaussianStateCombiner1D::combine ( const VSC theComponents) const

Definition at line 11 of file MultiGaussianStateCombiner1D.cc.

References gather_cfg::cout, Exception, and mps_merge::weight.

11  {
12  if (theComponents.empty()) {
13  throw cms::Exception("LogicError") << "MultiGaussianStateCombiner1D:: state container to collapse is empty";
14  // return SingleState(SingleState::Vector(),SingleState::Matrix(),0.);
15  // return SingleState(SingleState::Vector(),
16  // SingleState::Matrix(),0.);
17  return SingleGaussianState1D();
18  }
19 
20  const SingleGaussianState1D& firstState(theComponents.front());
21  if (theComponents.size() == 1)
22  return firstState;
23 
24  // int size = firstState.mean().num_row();
25  double meanMean(0.);
26  double weightSum(0.);
27  // double weight;
28  double measCovar1(0.);
29  double measCovar2(0.);
30  for (VSC::const_iterator mixtureIter1 = theComponents.begin(); mixtureIter1 != theComponents.end(); mixtureIter1++) {
31  double weight = mixtureIter1->weight();
32  weightSum += weight;
33 
34  double mean1 = mixtureIter1->mean();
35  meanMean += weight * mean1;
36  measCovar1 += weight * mixtureIter1->variance();
37 
38  for (VSC::const_iterator mixtureIter2 = mixtureIter1 + 1; mixtureIter2 != theComponents.end(); mixtureIter2++) {
39  double posDiff = mean1 - mixtureIter2->mean();
40  // SingleState::Matrix s(1,1); //stupid trick to make CLHEP work decently
41  // measCovar2 +=weight * (*mixtureIter2).weight() *
42  // s.similarity(posDiff.T().T());
43  // SingleState::Matrix mat;
44  // for ( unsigned int i1=0; i1<N; i1++ ) {
45  // for ( unsigned int i2=0; i2<=i1; i2++ ) mat(i1,i2) = posDiff(i1)*posDiff(i2);
46  // }
47  // measCovar2 += weight * (*mixtureIter2).weight() * mat;
48  //
49  // TensorProd yields a general matrix - need to convert to a symm. matrix
50  double covGen = posDiff * posDiff;
51  // double covSym(covGen.LowerBlock());
52  measCovar2 += weight * mixtureIter2->weight() * covGen;
53  }
54  }
55 
56  double measCovar;
57  if (weightSum < DBL_MIN) {
58  std::cout << "MultiGaussianStateCombiner1D:: New state has total weight of 0." << std::endl;
59  // meanMean = SingleState::Vector(size,0);
60  meanMean = 0.;
61  measCovar = 0.;
62  weightSum = 0.;
63  } else {
64  weightSum = 1. / weightSum;
65  meanMean *= weightSum;
66  measCovar1 *= weightSum;
67  measCovar2 *= weightSum * weightSum;
68  measCovar = measCovar1 + measCovar2;
69  // measCovar = measCovar1/weightSum + measCovar2/weightSum/weightSum;
70  }
71 
72  return SingleGaussianState1D(meanMean, measCovar, weightSum);
73 }
Definition: weight.py:1