TEntryList and TChain

Hi,

I’m trying to use a TEntryList on a TChain to select a subset of events, but i’m having problem grabbing the correct entries when the event loop processes the 2nd tree.

Basically, the chain does not change to the 2nd tree when all the entries of the 1st sublist have been processed, so the
entry = elist->GetEntry(ev); //_evt is just the loop counter
returns the local entry number of the 2nd tree
and therefore
ntEntry = _chain->LoadTree(entry);
grab the local entry in the 1st tree, instead of the 2nd.

I must be forgetting some steps somewhere… hopefully somebody can help…

Cheers
-a

Here’s a bit more details on what i do:

The TEntryList is,I believe, filled correctly, since if 2 TTree are processed, the elist printout show the name of the 1st TTree file followed by the local entry numbers selected, then the name of the 2nd TTree file followed by the local entry numbers selected. I also see the 2 sublist for each TTree.
The TEntryList is filled using:

To read back the chain using the elist, prior to the event loop:

In the event loop:

int nEvts = _chain->GetEntries(); if(useList) nEvts = _elist->GetN();

[code]for(int ev=0; ev<nEvts; ev++) { // loop over the events

if(elist && useList){
int treeNum;
int entry = _elist->GetEntryAndTree(ev,treeNum);
ntEntry = _chain->LoadTree(entry);
std::cout << " TList process entry " << entry << " for local entry " << ntEntry << " tree# " << treeNum << std::endl;
if(_chain->GetTreeNumber() != _fTreeCurrent){
getNtupleBranches(); //update branch pointers
}
}

b_evt->GetEntry(ntEntry);

}[/code]

see example below showing how to loop on a TreeEntryList in case of a TChain.
The example is in the TEntryList doc at root.cern.ch/root/html/TEntryList.html

Rene

void loopChain() { TFile *fe = TFile::Open("myelist.root"); TEntryList *myelist=(TEntryList*)fe->Get("myelist"); TChain *ch = new TChain("ntuple"); ch->Add("hsimple.root"); ch->Add("hsimple2.root"); Long64_t listEntries=myelist->GetN(); Long64_t chainEntries = ch->GetEntries(); Int_t treenum=0; ch->SetEntryList(myelist); for (Long64_t el =0;el<listEntries;el++) { Long64_t treeEntry = myelist->GetEntryAndTree(el,treenum); Long64_t chainEntry = treeEntry+ch->GetTreeOffset()[treenum]; printf("el=%lld, treeEntry=%lld, chainEntry=%lld, treenum=%d\n",el,treeEntry,chainEntry,treenum); } }