TVector* problem in ROOT 5.32/01

Hi all,

I am having some trouble reading elements out of a TVector* in compiled code, as Print() gives the correct result but operator[] doesn’t. It’s most likely my fault, but I can’t quite see what I’m doing wrong. The following snippet

  //read the shifts 
  TFile* f=TFile::Open("PEMaterial/JES_WeightsAndOffsets_13.root","READ");
  TVector* vShifts = (TVector*)f->Get("offsets");
  unsigned int nOffsets = vShifts->GetNrows();
  std::cout << "Shifts:" << std::endl;
  vShifts->Print();
  for (unsigned int iPE=0; iPE<nOffsets; iPE++) {
    std::cout << "JES shift: "<< (vShifts->operator[](iPE)) << std::endl;
  }

produces the following output:

Shifts:   

Vector (13)  is as follows

     |        1  |
------------------
   0 |0   
   1 |-3  
   2 |-2.5
   3 |-2  
   4 |-1.5
   5 |-1  
   6 |-0.5
   7 |0.5
   8 |1
   9 |1.5
  10 |2
  11 |2.5
  12 |3

JES shift: 0
JES shift: 0
JES shift: 0
JES shift: -2.125
JES shift: 0
JES shift: -2.0625
JES shift: 0
JES shift: -2
JES shift: 0
JES shift: -1.9375
JES shift: 0
JES shift: -1.875
JES shift: 0

Could anyone tell me what I’m doing wrong/how to access the elements of the vector correctly?

Thanks a lot,
Caterina

Hi,

Try code[iPE][/code]or code(iPE)[/code]

Cheers,
Philippe.