Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:13

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_MnUserCovariance
0011 #define ROOT_Minuit2_MnUserCovariance
0012 
0013 #include "Minuit2/MnConfig.h"
0014 #include <vector>
0015 #include <cassert>
0016 
0017 namespace ROOT {
0018 
0019 namespace Minuit2 {
0020 
0021 /**
0022    Class containing the covariance matrix data represented as a vector of
0023    size n*(n+1)/2
0024    Used to hide internal matrix representation to user
0025  */
0026 class MnUserCovariance {
0027 
0028 public:
0029    MnUserCovariance() : fData(std::vector<double>()), fNRow(0) {}
0030 
0031    // safe constructor using std::vector
0032    MnUserCovariance(const std::vector<double> &data, unsigned int nrow) : fData(data), fNRow(nrow)
0033    {
0034       assert(data.size() == nrow * (nrow + 1) / 2);
0035    }
0036 
0037    // unsafe constructor using just a pointer
0038    MnUserCovariance(const double *data, unsigned int nrow)
0039       : fData(std::vector<double>(data, data + nrow * (nrow + 1) / 2)), fNRow(nrow)
0040    {
0041    }
0042 
0043    MnUserCovariance(unsigned int n) : fData(std::vector<double>(n * (n + 1) / 2, 0.)), fNRow(n) {}
0044 
0045    ~MnUserCovariance() {}
0046 
0047    MnUserCovariance(const MnUserCovariance &cov) : fData(cov.fData), fNRow(cov.fNRow) {}
0048 
0049    MnUserCovariance &operator=(const MnUserCovariance &cov)
0050    {
0051       if (this != &cov) {
0052          fData = cov.fData;
0053          fNRow = cov.fNRow;
0054       }
0055       return *this;
0056    }
0057 
0058    double operator()(unsigned int row, unsigned int col) const
0059    {
0060       assert(row < fNRow && col < fNRow);
0061       if (row > col)
0062          return fData[col + row * (row + 1) / 2];
0063       else
0064          return fData[row + col * (col + 1) / 2];
0065    }
0066 
0067    double &operator()(unsigned int row, unsigned int col)
0068    {
0069       assert(row < fNRow && col < fNRow);
0070       if (row > col)
0071          return fData[col + row * (row + 1) / 2];
0072       else
0073          return fData[row + col * (col + 1) / 2];
0074    }
0075 
0076    void Scale(double f)
0077    {
0078       for (unsigned int i = 0; i < fData.size(); i++)
0079          fData[i] *= f;
0080    }
0081 
0082    const std::vector<double> &Data() const { return fData; }
0083 
0084    unsigned int Nrow() const { return fNRow; }
0085 
0086    // VC 7.1 warning: conversion from size_t to unsigned int
0087    unsigned int size() const { return static_cast<unsigned int>(fData.size()); }
0088 
0089 private:
0090    std::vector<double> fData;
0091    unsigned int fNRow;
0092 };
0093 
0094 } // namespace Minuit2
0095 
0096 } // namespace ROOT
0097 
0098 #endif // ROOT_Minuit2_MnUserCovariance