Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:35

0001 #ifndef MultiGaussianState_H
0002 #define MultiGaussianState_H
0003 
0004 #include "TrackingTools/GsfTools/interface/SingleGaussianState.h"
0005 #include <memory>
0006 
0007 #include <vector>
0008 
0009 // #include <iostream>
0010 // #include <signal.h>
0011 /// Mixture of multi-variate gaussian states
0012 
0013 /** Multi-dimensional multi-Gaussian mixture: weighted sum of single
0014  *  Gaussian components.
0015  */
0016 
0017 template <unsigned int N>
0018 class MultiGaussianState {
0019 public:
0020   typedef typename SingleGaussianState<N>::Vector Vector;
0021   typedef typename SingleGaussianState<N>::Matrix Matrix;
0022   typedef SingleGaussianState<N> SingleState;
0023   typedef std::shared_ptr<SingleState> SingleStatePtr;
0024   //   typedef std::vector< std::shared_ptr<const SingleState> > SingleStateContainer;
0025   typedef std::vector<SingleStatePtr> SingleStateContainer;
0026 
0027 public:
0028   MultiGaussianState() : theCombinedStateUp2Date(false) {
0029     //     ++instances_;++maxInstances_;
0030     //     std::cout << "MultiGaussianState() " << N << " " << instances_ << std::endl;
0031   }
0032 
0033   MultiGaussianState(const SingleStateContainer& stateV) : theComponents(stateV), theCombinedStateUp2Date(false) {
0034     //     theComponents[0]->rescaleWeight(1.);
0035     //     ++instances_;++maxInstances_;
0036     //     std::cout << "MultiGaussianState(const SingleStateContainer&) " << N << " "
0037     //        << instances_ << std::endl;
0038   }
0039 
0040   //   MultiGaussianState(const MultiGaussianState<N>& rhs) :
0041   //     theComponents(rhs.theComponents), theCombinedState(rhs.theCombinedState),
0042   //     theCombinedStateUp2Date(rhs.theCombinedStateUp2Date) {
0043   //     ++instances_;++maxInstances_;
0044   //     std::cout << "MultiGaussianState(const MultiGaussianState<N>&) " << N << " "
0045   //          << instances_ << std::endl;
0046   //   }
0047 
0048   ~MultiGaussianState() {
0049     //     --instances_;
0050     //     std::cout << "~MultiGaussianState " << N << " " << instances_ << std::endl;
0051   }
0052 
0053   //   /**
0054   //    * Creates a new multi-state with the given components.
0055   //    * For this base class, no information is passed from the initial
0056   //    * instance.
0057   //    */
0058   //   virtual MultiGaussianState createState(
0059   //    const std::vector<SingleGaussianState> & stateV) const {
0060   //     return MultiGaussianState(stateV);
0061   //   }
0062 
0063   //   /**
0064   //    * Creates a new single-state with the given information.
0065   //    * For this base class, no information is passed from the initial
0066   //    * instance.
0067   //    */
0068   //   virtual SingleGaussianState createSingleState (
0069   //    const AlgebraicVector & aMean, const AlgebraicSymMatrix & aCovariance,
0070   //    double aWeight = 1.) const {
0071   //     return SingleGaussianState(aMean, aCovariance, aWeight);
0072   //   }
0073 
0074   /// combined weight
0075   double weight() const;
0076   /// combined mean
0077   const Vector& mean() const;
0078   /// combined covariance matrix
0079   const Matrix& covariance() const;
0080   /// combined weight matrix
0081   const Matrix& weightMatrix() const;
0082   /// access to components (single Gaussian states)
0083   inline const SingleStateContainer& components() const { return theComponents; }
0084   /// dimension of parameter vector
0085   int dimension() const { return N; }
0086   /// renormalize weight
0087   void setWeight(double newWeight);
0088   /// rescale weight
0089   void rescaleWeight(double scale);
0090 
0091   // protected:
0092 private:
0093   /// calculation of the combined state (on demand)
0094   void checkCombinedState() const;
0095 
0096   //   std::vector<SingleState> theComponents;
0097   // should become a vector of pointers to const SingleState ...
0098   const SingleStateContainer theComponents;
0099   mutable SingleStatePtr theCombinedState;
0100   mutable bool theCombinedStateUp2Date;
0101 
0102   // public:
0103   //   static int instances_;
0104   //   static int maxInstances_;
0105   //   static int constructsCombinedState_;
0106 };
0107 
0108 /**
0109  * Class to collapse (combine) a Gaussian mixture of states
0110  * into one.
0111  * (c.f. R. Fruewirth et.al., Comp.Phys.Comm 100 (1997) 1
0112  */
0113 
0114 //NOTE: Circular dependency between MultiGaussianState and
0115 // MultiGaussianStateCombiner requires they be in the same
0116 // headerfile
0117 
0118 template <unsigned int N>
0119 class MultiGaussianStateCombiner {
0120 private:
0121   typedef SingleGaussianState<N> SingleState;
0122   typedef MultiGaussianState<N> MultiState;
0123   typedef typename MultiGaussianState<N>::SingleStatePtr SingleStatePtr;
0124   typedef typename MultiGaussianState<N>::SingleStateContainer VSC;
0125 
0126 public:
0127   //   typedef std::vector<SingleState> VSC;
0128 
0129   SingleStatePtr combine(const MultiState& theState) const;
0130   SingleStatePtr combine(const VSC& theComponents) const;
0131 };
0132 
0133 #include "TrackingTools/GsfTools/interface/MultiGaussianStateCombiner.icc"
0134 #include "TrackingTools/GsfTools/interface/MultiGaussianState.icc"
0135 
0136 //   template <unsigned int N> int MultiGaussianState<N>::instances_ = 0;
0137 //   template <unsigned int N> int MultiGaussianState<N>::maxInstances_ = 0;
0138 //   template <unsigned int N> int MultiGaussianState<N>::constructsCombinedState_ = 0;
0139 
0140 #endif