Logo ROOT   6.16/01
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#include "Minuit2/MnConfig.h"
14#include <vector>
15#include <cassert>
16
17namespace ROOT {
18
19 namespace Minuit2 {
20
21
22/**
23 Class containing the covariance matrix data represented as a vector of
24 size n*(n+1)/2
25 Used to hide internal matrix representation to user
26 */
28
29public:
30
31 MnUserCovariance() : fData(std::vector<double>()), fNRow(0) {}
32
33 // safe constructor using std::vector
34 MnUserCovariance(const std::vector<double>& data, unsigned int nrow) :
35 fData(data), fNRow(nrow) {
36 assert(data.size() == nrow*(nrow+1)/2);
37 }
38
39 // unsafe constructor using just a pointer
40 MnUserCovariance(const double * data, unsigned int nrow) :
41 fData(std::vector<double>(data,data+nrow*(nrow+1)/2)),
42 fNRow(nrow) {
43 }
44
45 MnUserCovariance(unsigned int n) :
46 fData(std::vector<double>(n*(n+1)/2, 0.)), fNRow(n) {}
47
49
51
53 if(this != &cov) {
54 fData = cov.fData;
55 fNRow = cov.fNRow;
56 }
57 return *this;
58 }
59
60 double operator()(unsigned int row, unsigned int col) const {
61 assert(row < fNRow && col < fNRow);
62 if(row > col)
63 return fData[col+row*(row+1)/2];
64 else
65 return fData[row+col*(col+1)/2];
66 }
67
68 double& operator()(unsigned int row, unsigned int col) {
69 assert(row < fNRow && col < fNRow);
70 if(row > col)
71 return fData[col+row*(row+1)/2];
72 else
73 return fData[row+col*(col+1)/2];
74 }
75
76 void Scale(double f) {
77 for(unsigned int i = 0; i < fData.size(); i++) fData[i] *= f;
78 }
79
80 const std::vector<double>& Data() const {return fData;}
81
82 unsigned int Nrow() const {return fNRow;}
83
84// VC 7.1 warning: conversion from size_t to unsigned int
85 unsigned int size() const
86 { return static_cast < unsigned int > ( fData.size() );
87 }
88
89private:
90
91 std::vector<double> fData;
92 unsigned int fNRow;
93};
94
95 } // namespace Minuit2
96
97} // namespace ROOT
98
99#endif // ROOT_Minuit2_MnUserCovariance
#define f(i)
Definition: RSha256.hxx:104
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
const std::vector< double > & Data() const
double & operator()(unsigned int row, unsigned int col)
MnUserCovariance(const MnUserCovariance &cov)
MnUserCovariance(const double *data, unsigned int nrow)
double operator()(unsigned int row, unsigned int col) const
MnUserCovariance & operator=(const MnUserCovariance &cov)
MnUserCovariance(const std::vector< double > &data, unsigned int nrow)
const Int_t n
Definition: legend1.C:16
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
STL namespace.