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 add(const LeastSquares &other, double weight = 1.0); 00023 void calculate(); 00024 00025 std::vector<double> getWeights() const; 00026 std::vector<double> getMeans() const; 00027 double getConstant() const; 00028 00029 inline unsigned int getSize() const { return n; } 00030 inline const TMatrixDSym &getCoefficients() const { return coeffs; } 00031 inline const TMatrixDSym &getCovariance() const { return covar; } 00032 inline const TMatrixDSym &getCorrelations() const { return corr; } 00033 inline const TMatrixD &getRotation() { return rotation; } 00034 00035 void load(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *elem); 00036 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *save( 00037 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc) const; 00038 00039 static TVectorD solveFisher(const TMatrixDSym &coeffs); 00040 static TMatrixD solveRotation(const TMatrixDSym &covar, 00041 TVectorD &trace); 00042 00043 private: 00044 TMatrixDSym coeffs; 00045 TMatrixDSym covar; 00046 TMatrixDSym corr; 00047 TMatrixD rotation; 00048 TVectorD weights; 00049 TVectorD variance; 00050 TVectorD trace; 00051 const unsigned int n; 00052 }; 00053 00054 } // namespace PhysicsTools 00055 00056 #endif // PhysicsTools_MVATrainer_LeastSquares_h