Restricting number of events in TChain TTrees

Hello,

I want to restrict the number of entries in each TTree added to TChain, through which TChain will go. For example, tree A in TChain has in reality 200 entries, but I want TChain::GetEntry() only go through 20 entries, and then GetEntry(21) should already point to the entry 0 of tree B. What is the best way to do this?

I tried setting number of entries when invoking TChain::Add(), but it seems that as soon as I do a GetEntry(), the number of entries for the read tree in TChain is reset to the max number of entries in this tree… I am using ROOT 5.34.

Hi,

perhaps jumping to the right entry could be the solution for you?
You could also make small “thumbnails” of your files with the rooteventselector routine - ROOT 6 only (I am aware you use ROOT5, just mentioning this)

Danilo

Hi,

Another solution might be to use a TEntryList and chain->GetEntry(chain->GetEntryNumber(entry))

Cheers,
Philippe.

The idea with entrylist crossed my mind. However, this would force me to change all the GetEntry() command in my code, and there are many of them. I just hoped that maybe there is a transparent method for GetEntry(), like for Draw() and Scan(), which respect the entrylist set by SetEntryList().

How about SetEntries()? The documentation tells it is for a different purpose, but maybe it could be done for that one?

[quote=“dpiparo”]perhaps jumping to the right entry could be the solution for you?
You could also make small “thumbnails” of your files with the rooteventselector routine - ROOT 6 only (I am aware you use ROOT5, just mentioning this)
[/quote]

That unfortunately would be quite slow and require lot’s of space on the HD… :frowning:

I just hoped that maybe there is a transparent method for GetEntry(),

For better or worse, GetEntry is indeed always getting the request entry … [Note: it would be impossible (albeit either even more typing or ‘delicate’ to setup) to use a class derived from TTree to overload GetEntry and do what you need …

How about SetEntries()? The documentation tells it is for a different purpose, but maybe it could be done for that one?

It would indeed achieve your goal if there was a way to call it between the time the TChain open the file and the time it records the length of the TTree …

hummm

There might be a way … You might be able to setup one empty TTree per file of the TChain and call SetEntries on this empty tree and then make the TTrees from the files friends of the empty tree. i.e.

   emptytree1->SetEntries(lowNumber1);
   emptytree1->AddFriend(treename,filename1);
   emptytree1->SetEntries(lowNumber2);
   emptytree2->AddFriend(treename,filename2);

and then make a new chain out of the set of empty trees … When looping throught the chain of empty tree, the friend (with the real data) will be accessible and the GetEntry will be limited to the (fake) size of the empty tree.

Cheers,
Philippe.

I may try your solution, although it is complicated :slight_smile:

I understand, that the whole point is, that the TChain reads the whole number of entries from the tree and there is no access to this value later, nor a way to force TChain to get number of entries again from the tree (after I modify it with SetEntries()). So, I guess, that could be a feature request.