MnUserCovariance.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: MnUserCovariance.h 20880 2007-11-19 11:23:41Z rdm $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef ROOT_Minuit2_MnUserCovariance
00011 #define ROOT_Minuit2_MnUserCovariance
00012 
00013 #ifndef ROOT_Minuit2_MnConfig
00014 #include "Minuit2/MnConfig.h"
00015 #endif
00016 #include <vector>
00017 #include <cassert>
00018 
00019 namespace ROOT {
00020 
00021    namespace Minuit2 {
00022 
00023 
00024 /**
00025    Class containing the covariance matrix data represented as a vector of 
00026    size n*(n+1)/2
00027    Used to hide internal matrix representation to user
00028  */
00029 class MnUserCovariance {
00030 
00031 public:
00032 
00033   MnUserCovariance() : fData(std::vector<double>()), fNRow(0) {}
00034 
00035   MnUserCovariance(const std::vector<double>& data, unsigned int nrow) :
00036     fData(data), fNRow(nrow) {
00037     assert(data.size() == nrow*(nrow+1)/2);
00038   }
00039 
00040   MnUserCovariance(unsigned int n) : 
00041     fData(std::vector<double>(n*(n+1)/2, 0.)), fNRow(n) {}
00042 
00043   ~MnUserCovariance() {}
00044 
00045   MnUserCovariance(const MnUserCovariance& cov) : fData(cov.fData), fNRow(cov.fNRow) {}
00046 
00047   MnUserCovariance& operator=(const MnUserCovariance& cov) {
00048     fData = cov.fData;
00049     fNRow = cov.fNRow;
00050     return *this;
00051   }
00052 
00053   double operator()(unsigned int row, unsigned int col) const {
00054     assert(row < fNRow && col < fNRow);
00055     if(row > col) 
00056       return fData[col+row*(row+1)/2];
00057     else
00058       return fData[row+col*(col+1)/2];
00059   }
00060 
00061   double& operator()(unsigned int row, unsigned int col) {
00062     assert(row < fNRow && col < fNRow);
00063     if(row > col) 
00064       return fData[col+row*(row+1)/2];
00065     else
00066       return fData[row+col*(col+1)/2];
00067   }
00068 
00069   void Scale(double f) {
00070     for(unsigned int i = 0; i < fData.size(); i++) fData[i] *= f;
00071   }
00072 
00073   const std::vector<double>& Data() const {return fData;}
00074 
00075   unsigned int Nrow() const {return fNRow;}
00076 
00077 // VC 7.1 warning: conversion from size_t to unsigned int
00078   unsigned int size() const 
00079   { return static_cast < unsigned int > ( fData.size() );
00080   }
00081 
00082 private:
00083 
00084   std::vector<double> fData;
00085   unsigned int fNRow;
00086 };
00087 
00088   }  // namespace Minuit2
00089 
00090 }  // namespace ROOT
00091 
00092 #endif  // ROOT_Minuit2_MnUserCovariance

Generated on Tue Jul 5 14:25:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1