CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/TrackingTools/GsfTools/interface/GaussianSumUtilities.h

Go to the documentation of this file.
00001 #ifndef GaussianSumUtilities_h_
00002 #define GaussianSumUtilities_h_
00003 
00004 #include "TrackingTools/GsfTools/interface/MultiGaussianState1D.h"
00005 #include "TrackingTools/GsfTools/interface/SingleGaussianState.h"
00006 #include "TrackingTools/GsfTools/interface/MultiGaussianState.h"
00007 #include <vector>
00008 
00014 template <unsigned int N>
00015 class GaussianSumUtilities {
00016 public:
00017   typedef SingleGaussianState<N> SingleState;
00018   typedef MultiGaussianState<N> MultiState; 
00019 //   typedef ROOT::Math::SVector<double, N> Vector;
00020   typedef ROOT::Math::SMatrix<double,N,N,ROOT::Math::MatRepStd<double,N> > GenMatrix;
00021 
00022   typedef typename SingleState::Vector Vector;
00023   typedef typename SingleState::Matrix Matrix;
00024   typedef typename MultiState::SingleStatePtr SingleStatePtr;
00025   typedef typename MultiState::SingleStateContainer SingleStateContainer;
00026 
00027 private:
00028   enum ModeStatus { Valid, NotValid, NotComputed };
00029 
00030 public:
00031   GaussianSumUtilities (const MultiState& state) :
00032     theState(state), 
00033     theModeStatus(NotComputed) {
00034   } 
00035   ~GaussianSumUtilities () {
00036   }
00037 
00039   inline unsigned int size () const {
00040     return components().size();
00041   }
00043   const SingleStateContainer& components () const {
00044     return theState.components();
00045   }
00047   const MultiState& state () const {
00048     return theState;
00049   }
00051   inline double weight (unsigned int i) const {
00052     return components()[i]->weight();
00053   }
00055   inline const Vector& mean (unsigned int i) const {
00056     return components()[i]->mean();
00057   }
00059   inline const Matrix& covariance (unsigned int i) const {
00060     return components()[i]->covariance();
00061   }
00063   bool modeIsValid () const;
00066   const SingleGaussianState<N>& mode () const;
00068   double pdf (const Vector&) const;
00070   Vector d1Pdf (const Vector&) const;
00072   Matrix d2Pdf (const Vector&) const;
00074   double lnPdf (const Vector&) const;
00076   Vector d1LnPdf (const Vector&) const;
00078   Matrix d2LnPdf (const Vector&) const;
00079 
00081   double weight () const {
00082     return theState.weight();
00083   }
00085   const Vector& mean () const {
00086     return theState.mean();
00087   }
00089   const Matrix& covariance () const {
00090     return theState.covariance();
00091   }
00092 
00093 
00094 protected:
00096   Vector computeModeWithoutTransform () const;
00097 
00098 private:
00100   Matrix tensorProduct (const Vector&) const;
00102   double gauss (const double&, const double&, const double&) const;
00104   double gauss (const Vector&, 
00105                 const Vector&,
00106                 const Matrix&) const;
00108   bool findMode (Vector& mode, double& pdfAtMode,
00109                  const Vector& xStart) const;
00111   void computeMode () const;
00113   MultiGaussianState1D constrainedState (const Vector& d,
00114                                          const Vector& x0) const;
00115 //   /// replacement of CLHEP determinant (which rounds off small values)
00116 //   double determinant (const Matrix& matrix) const;
00119   Matrix localCovariance (const Vector& x) const;
00121   void setMode (const Vector& mode) const;
00123   void setInvalidMode () const;
00124 
00126   std::vector<double> pdfComponents (const Vector&) const;
00128   double pdf (const Vector&, const std::vector<double>&) const;
00130   Vector d1Pdf (const Vector&, const std::vector<double>&) const;
00132   Matrix d2Pdf (const Vector&, const std::vector<double>&) const;
00134   double lnPdf (const Vector&, const std::vector<double>&) const;
00136   Vector d1LnPdf (const Vector&, const std::vector<double>&) const;
00138   Matrix d2LnPdf (const Vector&, const std::vector<double>&) const;
00139 
00140 
00141 
00142 private:
00143   const MultiState& theState;
00144 //   int theDimension;
00145 
00146   mutable ModeStatus theModeStatus;
00147 //   mutable Vector theMode;
00148   mutable SingleGaussianState<N> theMode;
00149 
00150 };
00151 
00152 #include "TrackingTools/GsfTools/interface/GaussianSumUtilities.icc"
00153 
00154 #endif