Logo ROOT   6.08/07
Reference Guide
MnUserCovariance.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #ifndef ROOT_Minuit2_MnUserCovariance
11 #define ROOT_Minuit2_MnUserCovariance
12 
13 #ifndef ROOT_Minuit2_MnConfig
14 #include "Minuit2/MnConfig.h"
15 #endif
16 #include <vector>
17 #include <cassert>
18 
19 namespace ROOT {
20 
21  namespace Minuit2 {
22 
23 
24 /**
25  Class containing the covariance matrix data represented as a vector of
26  size n*(n+1)/2
27  Used to hide internal matrix representation to user
28  */
30 
31 public:
32 
33  MnUserCovariance() : fData(std::vector<double>()), fNRow(0) {}
34 
35  // safe constructor using std::vector
36  MnUserCovariance(const std::vector<double>& data, unsigned int nrow) :
37  fData(data), fNRow(nrow) {
38  assert(data.size() == nrow*(nrow+1)/2);
39  }
40 
41  // unsafe constructor using just a pointer
42  MnUserCovariance(const double * data, unsigned int nrow) :
43  fData(std::vector<double>(data,data+nrow*(nrow+1)/2)),
44  fNRow(nrow) {
45  }
46 
47  MnUserCovariance(unsigned int n) :
48  fData(std::vector<double>(n*(n+1)/2, 0.)), fNRow(n) {}
49 
51 
53 
55  if(this != &cov) {
56  fData = cov.fData;
57  fNRow = cov.fNRow;
58  }
59  return *this;
60  }
61 
62  double operator()(unsigned int row, unsigned int col) const {
63  assert(row < fNRow && col < fNRow);
64  if(row > col)
65  return fData[col+row*(row+1)/2];
66  else
67  return fData[row+col*(col+1)/2];
68  }
69 
70  double& operator()(unsigned int row, unsigned int col) {
71  assert(row < fNRow && col < fNRow);
72  if(row > col)
73  return fData[col+row*(row+1)/2];
74  else
75  return fData[row+col*(col+1)/2];
76  }
77 
78  void Scale(double f) {
79  for(unsigned int i = 0; i < fData.size(); i++) fData[i] *= f;
80  }
81 
82  const std::vector<double>& Data() const {return fData;}
83 
84  unsigned int Nrow() const {return fNRow;}
85 
86 // VC 7.1 warning: conversion from size_t to unsigned int
87  unsigned int size() const
88  { return static_cast < unsigned int > ( fData.size() );
89  }
90 
91 private:
92 
93  std::vector<double> fData;
94  unsigned int fNRow;
95 };
96 
97  } // namespace Minuit2
98 
99 } // namespace ROOT
100 
101 #endif // ROOT_Minuit2_MnUserCovariance
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
const std::vector< double > & Data() const
MnUserCovariance(const MnUserCovariance &cov)
MnUserCovariance(const std::vector< double > &data, unsigned int nrow)
STL namespace.
double operator()(unsigned int row, unsigned int col) const
MnUserCovariance & operator=(const MnUserCovariance &cov)
MnUserCovariance(const double *data, unsigned int nrow)
double f(double x)
double & operator()(unsigned int row, unsigned int col)
const Int_t n
Definition: legend1.C:16
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...