Root version : 6.12/06
OS platform : CentOS 7.3
Compiler : gcc6.2
Dear co-rooters,
I am trying to do a rather simple task.
I am reading a file with numbers and from these number I want to fill a symmetric boos matrix.
My code is the following
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include "TROOT.h"
#include "TGraph.h"
#include "TH1.h"
#include "TH2.h"
#include "TMath.h"
#include "TMatrixF.h"
#include "TMatrixFSym.h"
#include "TMatrixFSparse.h"
#include "TVector.h"
#include "TMatrixTSym.h"
#include "TString.h"
#include "TRandom.h"
#include </usr/include/boost/numeric/ublas/matrix.hpp>
#include </usr/include/boost/numeric/ublas/matrix_sparse.hpp>
#include </usr/include/boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/banded.hpp>
#include </usr/include/boost/numeric/ublas/io.hpp>
//#include "covariance_lib.cc"
using namespace std;
using namespace boost::numeric::ublas;
boost::numeric::ublas::symmetric_matrix<float> fill_symmetric (boost::numeric::ublas::symmetric_matrix<float> m_sym, float* filler, int size_FILLER){
float* in = filler;
for (size_t i=0; i<m_sym.size1(); ++ i)
for (size_t j = 0; j <= i && in != &filler[size_FILLER+1]; ++ j)
m_sym (i, j) = *in++;
return m_sym;
}//___fill_symmetric()
void test(){
// () Read the correlation Matrix
float covariance;
float *covariance_EVAL = new float[6];
int index=0;
std::ifstream myfile;
myfile.open("TEST_MT18_CorMat.dat");
while(1){
myfile >> covariance;
if (!myfile.good()) break;
covariance_EVAL[index] = covariance;
index++;
cout << covariance << "\t" << covariance_EVAL[index] << endl;
}
myfile.close();
// (4) Define the types of T-objects that will be used
symmetric_matrix<float, upper> COV_EVAL (3, 3);
COV_EVAL = fill_symmetric( COV_EVAL, covariance_EVAL, 3);
std::cout << COV_EVAL << std::endl;
}
The output of my code is the following
1 0
0.46 1.83475e-32
1 0
0.4 4.48416e-44
0.46 0
1 1.35926e-43
[3,3]((1,0.46,0.4),(0.46,1,4.48416e-44),(0.4,4.48416e-44,0))
The problem is that the matrix is supposed to be filled in a different way so as to have the following values
[3,3]((1,0.46,0.4),(0.46,1,0.46),(0.4,0.46,1))
Although the values are parsed correctly, they are stored strangely in the array.
Any idea on how to solve this issue?
Thank you very much in advance!
A sample file is the following
1.00
0.46
1.00
0.40
0.46
1.00