CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
< SingleGaussianState1D
VSC
 

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

Definition at line 16 of file MultiGaussianStateCombiner1D.h.

Member Function Documentation

SingleGaussianState1D MultiGaussianStateCombiner1D::combine ( const MultiGaussianState1D theState) const

Definition at line 9 of file MultiGaussianStateCombiner1D.cc.

References MultiGaussianState1D::components().

Referenced by MultiGaussianState1D::checkCombinedState().

10 {
11  return combine(theState.components());
12 }
const SingleState1dContainer & components() const
access to components
SingleGaussianState1D combine(const MultiGaussianState1D &theState) const
SingleGaussianState1D MultiGaussianStateCombiner1D::combine ( const VSC theComponents) const

Definition at line 15 of file MultiGaussianStateCombiner1D.cc.

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

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