Filling of TMatrixD works in CINT but does not in my class

Hi there,

I am currently working on a fitting algorithm and want to use ROOT’s matrix abilities, but I have some trouble with TMatrixD.
Basically, I have a class that shall be used in a macro later on with a constructor like this:


unsigned int NData = _data->size(); //# of data points
unsigned int lSx = _CSP->_M.size(); //# of knots - 4
_mData = TArrayD(lSx*NData);

//Building the matrix:
for(int r=0; r<NData; r++) {
double x_r = _data->at®->at(0); //coordinate is the 0. entry

for(int i=0; i<lSx; i++) {
  std::cout<<_mData[i]<<"  ";


_matrix = new TMatrixD(NData, lSx);
// does not work for some reason

// for(int i=0; i<NData; i++) {
// for(int j=0; j<lSx; j++)
// _matrix[i][j] = _mData[i*lSx + j];
// }



When compiling and running the macro, I get a matrix that consists almost entirely of zeros, where it should have band structure. It looks like the last lSx (column dimension) entries of the array have been filled to the first row of the matrix, and the rest wasn’t touched.
For bugfixing purposes I print out the array (_mData) as well, which looks perfectly fine. When I try to set the entries of _matrix manually (commented out lines at the end of the code), the class compiles but running the associated macro in CINT crashes:

I guess this happens because using [] on a pointer isn’t really a good thing to do, but I wanted to give it a try since it compiles…

BOTH ways work perfectly fine when I try them on CINT command line level.

What am I doing wrong?

Hi Felix,

Exactly. Dereference the _matrix pointer first, i.e. (*_matrix)[i][j].

Cheers, Axel.