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
00009
00010
00016 template <unsigned int N>
00017 class GaussianSumUtilities {
00018 public:
00019 typedef SingleGaussianState<N> SingleState;
00020 typedef MultiGaussianState<N> MultiState;
00021
00022 typedef ROOT::Math::SMatrix<double,N,N,ROOT::Math::MatRepStd<double,N> > GenMatrix;
00023
00024 typedef typename SingleState::Vector Vector;
00025 typedef typename SingleState::Matrix Matrix;
00026 typedef typename MultiState::SingleStatePtr SingleStatePtr;
00027 typedef typename MultiState::SingleStateContainer SingleStateContainer;
00028
00029 private:
00030 enum ModeStatus { Valid, NotValid, NotComputed };
00031
00032 public:
00033 GaussianSumUtilities (const MultiState& state) :
00034 theState(state),
00035 theModeStatus(NotComputed) {
00036 #ifdef DRAW_GSND
00037
00038
00039 instance_ = this;
00040 #endif
00041 }
00042 ~GaussianSumUtilities () {
00043 }
00044
00046 inline unsigned int size () const {
00047 return components().size();
00048 }
00050 const SingleStateContainer& components () const {
00051 return theState.components();
00052 }
00054 const MultiState& state () const {
00055 return theState;
00056 }
00058 inline double weight (unsigned int i) const {
00059 return components()[i]->weight();
00060 }
00062 inline const Vector& mean (unsigned int i) const {
00063 return components()[i]->mean();
00064 }
00066 inline const Matrix& covariance (unsigned int i) const {
00067 return components()[i]->covariance();
00068 }
00070 bool modeIsValid () const;
00073 const SingleGaussianState<N>& mode () const;
00075 double pdf (const Vector&) const;
00077 Vector d1Pdf (const Vector&) const;
00079 Matrix d2Pdf (const Vector&) const;
00081 double lnPdf (const Vector&) const;
00083 Vector d1LnPdf (const Vector&) const;
00085 Matrix d2LnPdf (const Vector&) const;
00086
00088 double weight () const {
00089 return theState.weight();
00090 }
00092 const Vector& mean () const {
00093 return theState.mean();
00094 }
00096 const Matrix& covariance () const {
00097 return theState.covariance();
00098 }
00099
00100
00101 protected:
00103 Vector computeModeWithoutTransform () const;
00104
00105 private:
00107 Matrix tensorProduct (const Vector&) const;
00109 double gauss (const double&, const double&, const double&) const;
00111 double gauss (const Vector&,
00112 const Vector&,
00113 const Matrix&) const;
00115 bool findMode (Vector& mode, double& pdfAtMode,
00116 const Vector& xStart) const;
00118 void computeMode () const;
00120 MultiGaussianState1D constrainedState (const Vector& d,
00121 const Vector& x0) const;
00122
00123
00126 Matrix localCovariance (const Vector& x) const;
00128 void setMode (const Vector& mode) const;
00130 void setInvalidMode () const;
00131
00133 std::vector<double> pdfComponents (const Vector&) const;
00135 double pdf (const Vector&, const std::vector<double>&) const;
00137 Vector d1Pdf (const Vector&, const std::vector<double>&) const;
00139 Matrix d2Pdf (const Vector&, const std::vector<double>&) const;
00141 double lnPdf (const Vector&, const std::vector<double>&) const;
00143 Vector d1LnPdf (const Vector&, const std::vector<double>&) const;
00145 Matrix d2LnPdf (const Vector&, const std::vector<double>&) const;
00146
00147
00148 #ifdef DRAW_GSND
00149 public:
00150 void setDraw (int i1, int i2) {v1Draw_=i1; v2Draw_=i2;}
00151 private:
00152 static double fcn2 (double* x, double* p);
00153 static double fcn2mode (double* x, double* p);
00154 #endif
00155
00156 private:
00157 const MultiState& theState;
00158
00159
00160 mutable ModeStatus theModeStatus;
00161
00162 mutable SingleGaussianState<N> theMode;
00163
00164 #ifdef DRAW_GSND
00165 static int v1Draw_;
00166 static int v2Draw_;
00167 static GaussianSumUtilities<N>* instance_;
00168 #endif
00169 };
00170
00171 #include "TrackingTools/GsfTools/interface/GaussianSumUtilities.icc"
00172
00173 #endif