00001 #ifndef PhysicsTools_MVATrainer_LeastSquares_h 00002 #define PhysicsTools_MVATrainer_LeastSquares_h 00003 00004 #include <string> 00005 #include <vector> 00006 00007 #include <TMatrixD.h> 00008 #include <TVectorD.h> 00009 00010 #include <xercesc/dom/DOM.hpp> 00011 00012 namespace PhysicsTools { 00013 00014 class LeastSquares 00015 { 00016 public: 00017 LeastSquares(unsigned int n); 00018 virtual ~LeastSquares(); 00019 00020 void add(const std::vector<double> &values, double dest, 00021 double weight = 1.0); 00022 void calculate(); 00023 00024 std::vector<double> getWeights() const; 00025 std::vector<double> getMeans() const; 00026 double getConstant() const; 00027 00028 inline unsigned int getSize() const { return n; } 00029 inline const TMatrixDSym &getCorrelations() const { return corr; } 00030 inline const TMatrixD &getRotation() { return rotation; } 00031 00032 void load(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem); 00033 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *save( 00034 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc) const; 00035 00036 private: 00037 TMatrixDSym coeffs; 00038 TMatrixDSym covar; 00039 TMatrixDSym corr; 00040 TMatrixD rotation; 00041 TVectorD sums; 00042 TVectorD weights; 00043 TVectorD variance; 00044 TVectorD trace; 00045 const unsigned int n; 00046 }; 00047 00048 } // namespace PhysicsTools 00049 00050 #endif // PhysicsTools_MVATrainer_LeastSquares_h