Wrong reading from a tree branch

Hello.

I’m reading some branches of a tree using SetBranchAddress(). The problem appears while reading branches of array type. Below a function to reproduce the problem and the tree is enclosed.

void readchain(){
TGaxis::SetMaxDigits(4);

  TChain* T02= new TChain("USR1");

  T02->Add("output1.root");

  T02->SetMakeClass(1);

  Long64_t nentries = T02->GetEntriesFast();

  Double_t        kQ2;
  Double_t        kXbj;
  Double_t        hPt[2];   //[hNmax]
  Double_t        hP[2];   //[hNmax]

  T02->SetBranchAddress("kXbj",&kXbj);
  T02->SetBranchAddress("kQ2", &kQ2);
  T02->SetBranchAddress("hPt", hPt);
  T02->SetBranchAddress("hP" , hP);

  for (Long64_t jentry=0; jentry<10;jentry++) {

    T02->GetEntry(jentry);

    cout<<"Read row "<<jentry<<" from Chain: "<<kXbj<<" "<<kQ2<<" "<<hPt[0]<<" "<<hPt[1]<<" "<<hP[0]<<" "<<hP[1]<<endl;
    cout<<endl;

       }
}

Below the output of the above piece of code:

Processing readchain.cc...
Warning in <TClass::TClass>: no dictionary for class HptEventOld is available
Read row 0 from Chain: 0.0348501 2.75173 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 1 from Chain: 0.0153456 1.54705 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 2 from Chain: 0.013265 1.8284 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 3 from Chain: 0.0165183 1.44515 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 4 from Chain: 0.00680253 1.33924 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 5 from Chain: 0.0240417 2.46013 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 6 from Chain: 0.0202946 3.53747 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 7 from Chain: 0.0299103 1.28759 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 8 from Chain: 0.011892 1.22897 3.50977e-86 9.65138e-315 1.72062e-296 0

Read row 9 from Chain: 0.00540148 1.33851 3.50977e-86 9.65138e-315 1.72062e-296 0

It is clearly seen that the ‘hPt[0]’, ‘hPt[1]’, ‘hP[0]’, ‘hP[1]’ variables does not coincide with the output from TTree:Scan() function (applied to the tree) reproduce below:

root [1] USR1->Scan("kXbj:kQ2:hPt[0]:hPt[1]:hP[0]:hP[1]")
************************************************************************************
*    Row   *      kXbj *       kQ2 *    hPt[0] *    hPt[1] *     hP[0] *     hP[1] *
************************************************************************************
*        0 * 0.0348500 * 2.7517287 * 0.7111801 * 0.5863552 * 7.2409171 * 8.1636112 *
*        1 * 0.0153456 * 1.5470487 * 0.7453713 * 0.6901956 * 9.0663965 * 6.4435734 *
*        2 * 0.0132650 * 1.8283980 * 0.8001557 * 0.5511284 * 18.748506 * 19.670350 *
*        3 * 0.0165182 * 1.4451511 * 0.8864401 * 0.5320145 * 17.667616 * 11.853742 *
*        4 * 0.0068025 * 1.3392354 * 0.7378976 * 0.6585607 * 10.936812 * 19.765998 *
*        5 * 0.0240416 * 2.4601339 * 0.9340921 * 0.4327372 * 22.210562 * 7.3547232 *
*        6 * 0.0202945 * 3.5374680 * 0.9960351 * 0.4747660 * 16.424522 * 12.626769 *
*        7 * 0.0299102 * 1.2875945 * 0.7050240 * 0.6726329 * 6.0001275 * 8.3194515 *
*        8 * 0.0118920 * 1.2289742 * 0.7655789 * 0.4069784 * 10.260727 * 4.0911505 *
*        9 * 0.0054014 * 1.3385143 * 0.7422751 * 0.5129567 * 42.640021 * 17.716547 *

Am I missing something?

Thanks in advance.

Cheers,
Luis.
output1.root (22.9 KB)

[code]#include

#include “TChain.h”
#include “TGaxis.h”

void readchain(){
TGaxis::SetMaxDigits(4);

TChain* T02= new TChain(“USR1”);

T02->Add(“output1.root”);

T02->SetMakeClass(1);

// Long64_t nentries = T02->GetEntriesFast();

Double_t kQ2;
Double_t kXbj;
Int_t hNmax;
Double_t hPt[2]; //[hNmax]
Double_t hP[2]; //[hNmax]

T02->SetBranchStatus("*", 0);

T02->SetBranchAddress(“kXbj”,&kXbj);
T02->SetBranchAddress(“kQ2”, &kQ2);
T02->SetBranchAddress(“hNmax”, &hNmax);
T02->SetBranchAddress(“hPt”, hPt);
T02->SetBranchAddress(“hP” , hP);

for (Long64_t jentry=0; jentry<10;jentry++) {

T02->GetEntry(jentry);

std::cout<<"Read row "<<jentry<<" from Chain: "<<kXbj<<" "<<kQ2<<" "<<hPt[0]<<" "<<hPt[1]<<" "<<hP[0]<<" "<<hP[1]<<std::endl;
std::cout<<std::endl;

   }

}[/code]

Thanks Pepe!

Cheers,
Luís.