Can't read more than one tree with TChain

Hi,
I am using version 3.05/00 of root under linux

I don’t manage to read several trees with a TChain. I try to with this piece of macro :

TChain t1(“Global”);

t1.Add(“189227_001_p160100.root”);
t1.Add(“189227_002_p160100.root”);

t1.SetBranchStatus("*",0);
t1.SetBranchStatus(“L3MuoPR”,1);
TBranch *_B1PR = t1.GetBranch(“L3MuoPR”);

_h1_MUON_chisq = new TH1F("_h1_MUON_chisq","",50,0,500);

Int_t _i1_NMUON;
TLeaf *_L1_NMUON = _B1PR->GetLeaf(“L3Muon_01_off_NMUON”);
_L1_NMUON->SetAddress(&_i1_NMUON);

Float_t _f1_MUON_chisq[200];
TLeaf *_L1_MUON_chisq = _B1PR->GetLeaf(“L3Muon_01_off_MUON_chisq”);
_L1_MUON_chisq->SetAddress(&_f1_MUON_chisq[0]);

for (Int_t i=0; i<N; i++)
//for (Int_t i=0; i<t1.GetEntries(); i++)
{
t1.GetEntry(i);
_h1_NMUON->Fill(_i1_NMUON);

for (Int_t j=0; j<_i1_NMUON; j++)
{
if (_f1_MUON_chisq[j] != -1) _h1_MUON_chisq->Fill(_f1_MUON_chisq[j];
}
}

Then my problems :

1)The call of t1.GetEntries() in the program produces a strange results, the trees are not read! _i1_NMUON variable is always 0 and
_h1_MUON_chisq is empty.

2)I replaced t1.GetEntries() by Int_t N = X and this time the first tree is read correctly but for the second I have the same problem encountered in 1) (X>number of entries of first tree of course)

3)I keep the use of N in my loop and I just add a
cout <<t1.GetEntries() before the loop. The result is same as 1). The call of GetEntries() seems to be responsible for this. I also try to add the cout <<t1.GetEntries() in the loop when i>3 for instance and the result is that the first 3 entries are read correctly and for the others, still the 1) problem.

So, does anyone sees a mistake or have any idea?

thanks, vincent

Hi,

When using a TChain you should not set the ‘branch and leaf address’ directly. The address set directly into the branch will not be transfered from one file to the other.
Instead using t1.SetBranchAddress(“name”,where).

TChain::GetEntries opens all the files (in sequence) and has the side effect of wiping the address set directly into the branches.

Cheers,
Philippe.

I’m sorry but I don’t understand how to replace
TBranch *_B1PR = t1.GetBranch(“L3MuoPR”)
Float_t _f1_MUON_chisq[200];
TLeaf *_L1_MUON_chisq = _B1PR->GetLeaf(“L3Muon_01_off_MUON_chisq”);
_L1_MUON_chisq->SetAddress(&_f1_MUON_chisq[0]);

with something like
t1.SetBranchAddress(“name”,where)

“name” is “_B1PR” or “L3MuoPR” ?
where is &_B1PR ?
how do I access the leave “L3Muon_01_off_MUON_chisq” from branch “L3MuoPR” ?

I’m a new root user and I have to confess it’s not clear for me.

Thanks, vincent

[quote=“pcanal”]Hi,

When using a TChain you should not set the ‘branch and leaf address’ directly. The address set directly into the branch will not be transfered from one file to the other.
Instead using t1.SetBranchAddress(“name”,where).

TChain::GetEntries opens all the files (in sequence) and has the side effect of wiping the address set directly into the branches.

Cheers,
Philippe.[/quote]

Hi,

Uset1.SetBranchAddress("L3MuoPR",&something);
where ‘something’ described the full content of the branch. It might actually be easier for your to use the skeleton produced by TTree::MakeSelector or TTree::MakeClass.

You should read The ROOT User’s Guide, it will be very helpfull to you.

Cheers,
Philippe.