File indexing completed on 2025-09-13 09:10:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef ROOT_Minuit2_MnUserCovariance
0011 #define ROOT_Minuit2_MnUserCovariance
0012
0013 #include "Minuit2/MnConfig.h"
0014
0015 #include <ROOT/RSpan.hxx>
0016
0017 #include <vector>
0018 #include <cassert>
0019
0020 namespace ROOT {
0021
0022 namespace Minuit2 {
0023
0024
0025
0026
0027
0028
0029 class MnUserCovariance {
0030
0031 public:
0032 MnUserCovariance() = default;
0033
0034
0035 MnUserCovariance(std::span<const double> data, unsigned int nrow) : fData(data.begin(), data.end()), fNRow(nrow)
0036 {
0037 assert(data.size() == nrow * (nrow + 1) / 2);
0038 }
0039
0040
0041 MnUserCovariance(const double *data, unsigned int nrow)
0042 : fData(std::vector<double>(data, data + nrow * (nrow + 1) / 2)), fNRow(nrow)
0043 {
0044 }
0045
0046 MnUserCovariance(unsigned int n) : fData(std::vector<double>(n * (n + 1) / 2, 0.)), fNRow(n) {}
0047
0048 double operator()(unsigned int row, unsigned int col) const
0049 {
0050 assert(row < fNRow && col < fNRow);
0051 if (row > col)
0052 return fData[col + row * (row + 1) / 2];
0053 else
0054 return fData[row + col * (col + 1) / 2];
0055 }
0056
0057 double &operator()(unsigned int row, unsigned int col)
0058 {
0059 assert(row < fNRow && col < fNRow);
0060 if (row > col)
0061 return fData[col + row * (row + 1) / 2];
0062 else
0063 return fData[row + col * (col + 1) / 2];
0064 }
0065
0066 void Scale(double f)
0067 {
0068 for (unsigned int i = 0; i < fData.size(); i++)
0069 fData[i] *= f;
0070 }
0071
0072 const std::vector<double> &Data() const { return fData; }
0073
0074 unsigned int Nrow() const { return fNRow; }
0075
0076
0077 unsigned int size() const { return static_cast<unsigned int>(fData.size()); }
0078
0079 private:
0080 std::vector<double> fData;
0081 unsigned int fNRow = 0;
0082 };
0083
0084 }
0085
0086 }
0087
0088 #endif