Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15#include <ROOT/RSpan.hxx>
16
17#include <vector>
18#include <cassert>
19
20namespace ROOT {
21
22namespace Minuit2 {
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
31public:
32 MnUserCovariance() = default;
33
34 // safe constructor using std::vector
35 MnUserCovariance(std::span<const double> data, unsigned int nrow) : fData(data.begin(), data.end()), fNRow(nrow)
36 {
37 assert(data.size() == nrow * (nrow + 1) / 2);
38 }
39
40 // unsafe constructor using just a pointer
41 MnUserCovariance(const double *data, unsigned int nrow)
42 : fData(std::vector<double>(data, data + nrow * (nrow + 1) / 2)), fNRow(nrow)
43 {
44 }
45
46 MnUserCovariance(unsigned int n) : fData(std::vector<double>(n * (n + 1) / 2, 0.)), fNRow(n) {}
47
48 double operator()(unsigned int row, unsigned int col) const
49 {
50 assert(row < fNRow && col < fNRow);
51 if (row > col)
52 return fData[col + row * (row + 1) / 2];
53 else
54 return fData[row + col * (col + 1) / 2];
55 }
56
57 double &operator()(unsigned int row, unsigned int col)
58 {
59 assert(row < fNRow && col < fNRow);
60 if (row > col)
61 return fData[col + row * (row + 1) / 2];
62 else
63 return fData[row + col * (col + 1) / 2];
64 }
65
66 void Scale(double f)
67 {
68 for (unsigned int i = 0; i < fData.size(); i++)
69 fData[i] *= f;
70 }
71
72 const std::vector<double> &Data() const { return fData; }
73
74 unsigned int Nrow() const { return fNRow; }
75
76 // VC 7.1 warning: conversion from size_t to unsigned int
77 unsigned int size() const { return static_cast<unsigned int>(fData.size()); }
78
79private:
80 std::vector<double> fData;
81 unsigned int fNRow = 0;
82};
83
84} // namespace Minuit2
85
86} // namespace ROOT
87
88#endif // ROOT_Minuit2_MnUserCovariance
#define f(i)
Definition RSha256.hxx:104
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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(std::span< const double > data, unsigned int nrow)
MnUserCovariance(const double *data, unsigned int nrow)
double operator()(unsigned int row, unsigned int col) const
const Int_t n
Definition legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...