CMS 3D CMS Logo

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

#include <PosteriorWeightsCalculator.h>

Public Member Functions

 PosteriorWeightsCalculator (const std::vector< TSOS > &mixture)
 
std::vector< double > weights (const TrackingRecHit &tsos) const
 Create random state. More...
 
template<unsigned int D>
std::vector< double > weights (const TrackingRecHit &tsos) const
 
 ~PosteriorWeightsCalculator ()
 

Private Types

typedef TrajectoryStateOnSurface TSOS
 

Private Attributes

std::vector< TSOSpredictedComponents
 

Detailed Description

Helper class which calculates the posterior weights of a Gaussian mixture given a prior (predicted) mixture and a RecHit. The prior is specified during construction time in the form of a vector of trajectory states.

Definition at line 13 of file PosteriorWeightsCalculator.h.

Member Typedef Documentation

Definition at line 16 of file PosteriorWeightsCalculator.h.

Constructor & Destructor Documentation

PosteriorWeightsCalculator::PosteriorWeightsCalculator ( const std::vector< TSOS > &  mixture)
inline

Definition at line 19 of file PosteriorWeightsCalculator.h.

19  :
PosteriorWeightsCalculator::~PosteriorWeightsCalculator ( )
inline

Definition at line 22 of file PosteriorWeightsCalculator.h.

References weights().

22 {}

Member Function Documentation

std::vector< double > PosteriorWeightsCalculator::weights ( const TrackingRecHit tsos) const

Create random state.

Definition at line 11 of file PosteriorWeightsCalculator.cc.

References TrackingRecHit::dimension(), Exception, and rpcPointValidation_cfi::recHit.

Referenced by GsfChi2MeasurementEstimator::estimate(), GsfMultiStateUpdator::update(), weights(), and ~PosteriorWeightsCalculator().

11  {
12  switch (recHit.dimension()) {
13  case 1: return weights<1>(recHit);
14  case 2: return weights<2>(recHit);
15  case 3: return weights<3>(recHit);
16  case 4: return weights<4>(recHit);
17  case 5: return weights<5>(recHit);
18  }
19  throw cms::Exception("Error: rechit of size not 1,2,3,4,5");
20 }
template<unsigned int D>
std::vector< double > PosteriorWeightsCalculator::weights ( const TrackingRecHit tsos) const

Definition at line 23 of file PosteriorWeightsCalculator.cc.

References vertices_cff::chi2, muonBadTrackFilter_cfi::chi2Min, JetChargeProducer_cfi::exp, TrackingRecHit::getKfComponents(), mps_fire::i, invertPosDefMatrix(), LogDebug, convertSQLiteXML::ok, AlCaHLTBitMon_ParallelJobs::p, predictedComponents, dttmaxenums::R, alignCSCRings::r, mathSSE::sqrt(), w, weights(), and x.

23  {
24  typedef typename AlgebraicROOTObject<D,5>::Matrix MatD5;
25  typedef typename AlgebraicROOTObject<5,D>::Matrix Mat5D;
26  typedef typename AlgebraicROOTObject<D,D>::SymMatrix SMatDD;
27  typedef typename AlgebraicROOTObject<D>::Vector VecD;
28  using ROOT::Math::SMatrixNoInit;
29 
30  std::vector<double> weights;
31  if ( predictedComponents.empty() ) {
32  edm::LogError("EmptyPredictedComponents")<<"a multi state is empty. cannot compute any weight.";
33  return weights;
34  }
35  weights.reserve(predictedComponents.size());
36 
37  std::vector<double> detRs;
38  detRs.reserve(predictedComponents.size());
39  std::vector<double> chi2s;
40  chi2s.reserve(predictedComponents.size());
41 
42  VecD r, rMeas;
43  SMatDD V(SMatrixNoInit{}), R(SMatrixNoInit{});
45  //
46  // calculate chi2 and determinant / component and find
47  // minimum / maximum of chi2
48  //
49  double chi2Min(DBL_MAX);
50  for ( unsigned int i=0; i<predictedComponents.size(); i++ ) {
51 
52  KfComponentsHolder holder;
53  auto const & x = predictedComponents[i].localParameters().vector();
54  holder.template setup<D>(&r, &V, &p, &rMeas, &R,
55  x, predictedComponents[i].localError().matrix());
56  recHit.getKfComponents(holder);
57 
58  r -= rMeas;
59  R += V;
60 
61  double detR;
62  if (! R.Det2(detR) ) {
63  edm::LogError("PosteriorWeightsCalculator") << "PosteriorWeightsCalculator: determinant failed";
64  return std::vector<double>();
65  }
66  detRs.push_back(detR);
67 
68  bool ok = invertPosDefMatrix(R);
69  if ( !ok ) {
70  edm::LogError("PosteriorWeightsCalculator")
71  << "PosteriorWeightsCalculator: inversion failed";
72  return std::vector<double>();
73  }
74  double chi2 = ROOT::Math::Similarity(r,R);
75  chi2s.push_back(chi2);
76  if ( chi2<chi2Min ) chi2Min = chi2;
77  }
78 
79  if ( detRs.size()!=predictedComponents.size() ||
80  chi2s.size()!=predictedComponents.size() ) {
81  edm::LogError("PosteriorWeightsCalculator") << "Problem in vector sizes";
82  return std::vector<double>();
83  }
84 
85  //
86  // calculate weights (extracting a common factor
87  // exp(-0.5*chi2Min) to avoid numerical problems
88  // during exponentation
89  //
90  double sumWeights(0.);
91  for ( unsigned int i=0; i<predictedComponents.size(); i++ ) {
92  double priorWeight = predictedComponents[i].weight();
93 
94  double chi2 = chi2s[i] - chi2Min;
95 
96  double tempWeight(0.);
97  if ( detRs[i]>FLT_MIN ) {
98  //
99  // Calculation of (non-normalised) weight. Common factors exp(-chi2Norm/2.) and
100  // 1./sqrt(2*pi*recHit.dimension()) have been omitted
101  //
102  tempWeight = priorWeight * std::sqrt(1./detRs[i]) * std::exp(-0.5 * chi2);
103  }
104  else {
105  LogDebug("GsfTrackFitters") << "PosteriorWeightsCalculator: detR < FLT_MIN !!";
106  }
107  weights.push_back(tempWeight);
108  sumWeights += tempWeight;
109  }
110 
111  if ( sumWeights<DBL_MIN ) {
112  LogDebug("GsfTrackFitters") << "PosteriorWeightsCalculator: sumWeight < DBL_MIN";
113  edm::LogError("PosteriorWeightsCalculator") << "PosteriorWeightsCalculator: sumWeight < DBL_MIN";
114  return std::vector<double>();
115  }
116 
117  if ( weights.size()!=predictedComponents.size() ) {
118  edm::LogError("PosteriorWeightsCalculator") << "Problem in vector sizes (2)";
119  return std::vector<double>();
120  }
121  sumWeights = 1./sumWeights;
122  for (auto & w : weights) w *= sumWeights;
123  return weights;
124 }
#define LogDebug(id)
ROOT::Math::SMatrix< double, D1, D1, ROOT::Math::MatRepSym< double, D1 > > SymMatrix
const double w
Definition: UKUtility.cc:23
std::vector< double > weights(const TrackingRecHit &tsos) const
Create random state.
ROOT::Math::SMatrix< double, D1, D2, ROOT::Math::MatRepStd< double, D1, D2 > > Matrix
T sqrt(T t)
Definition: SSEVec.h:18
bool invertPosDefMatrix(ROOT::Math::SMatrix< T, N, N, ROOT::Math::MatRepSym< T, N > > &m)
ROOT::Math::SVector< double, D1 > Vector

Member Data Documentation

std::vector<TSOS> PosteriorWeightsCalculator::predictedComponents
private

Definition at line 29 of file PosteriorWeightsCalculator.h.

Referenced by weights().