TChains, TEventLists and my position in the chain

Hi, rooters,
how to get the position of an event in a TChain, if I don’t want to count?

I use a chain of files with a tree T. In each file there is additional information I access with (shortened version):

Long64_t allEntries=(Long64_t)(chain->GetEntries());
EntriesTillNow=0;

while(EntriesTillNow < allEntries )
{
chain->GetEntry(EntriesTillNow); // act.Position

TreeEntries=(Long64_t)((TTree*)chain->GetTree())->GetEntries();  // TTree at this position
//... manipulations with the tree..., drawing, etc
LoopFile=(TFile*)chain->GetFile();    // TFile at this position

// Get additional information etc
EntriesTillNow+=TreeEntries;
}

Now, as this works, I want to take subsets of the trees. My cut ist a region of EventNumbers which are a leaf in my TTree and run consecutivly. To get these Events out and not search the whole TChain all the time, I define a TEventList *tempList with a TCut e.g. *tempCut=“EventNumber>1234567 && EventNumber<1234667”, but the chain->GetFile() points to the last file in chain (even after setting chain->SetEventList(“tempList”)), because we searched the whole tree before. But how to set the position to the TTree/TFile my events are in?
Using root4/08 on Suse 8.2.
Thank you

To reset the chain at the first entry, call
chain->LoadTree(0);

Rene

Getting to the beginning is easy, getting to a certain point isn’t, but as my chain is ordered, I helped with counting the events.
But now I have another problem in my compiled program (see function code attached, function MyEventListLoop(…)):
a) I access this function with 2 different Event lists det0 and det1, but having the same range of Events. I draw these events with an additional cut in an tempEventList using the whole chain, which should return the same number of events for both det0 and det1, because I use the whole chain. Using det0 first, I get a reasonable number, det1 gives 0.

b) When I set the chain to the eventLists deto/det1, and fill my histogramm using the same cut as for tempEventList, he draws all Events in the chain.

If I do a and b in a root-session, it works, which let’s me astonished. I could do everything in batch mode, bud a compiled cpp-program where I can use all my other methods would be faster.
MyOwnLoop.cpp (4.13 KB)

I solved it…
a) instead of getting the number of events in the list, I take the return-value of the chain->Draw-Command, which gives the right number.
b) if I have a TCut cut and a stringstream TimeCut, defining a newCut=cut + TimeCut.str().c_str() doesn’t seem to work, if I just use the TimeCut.str().c_str() in my chain->Draw(“hist”,TimeCut.str().c_str()) ; it works…

Thanks!

Can you give an explicit complete example of this failure (be explicit on the difference between what you expect and what you get)?
Also make sure to specify the ROOT version and your platform.

Cheers,
Philippe.

root version 4.0/8 on Suse8.2

shortened:

I call
EventListLoop(outerChain, outerList,"");
thinking an conversion from char* to TCut works (but maybe this is my fault)

void EventListLoop(TChain *ch, TEventList *List,TCut cut)
{
stringstream TimeCut;
TimeCut<<“EventNumber>=”<<FirstEvent<<" && EventNumber<="<<LastEvent";

// I think here is my error
TCut newCut=cut+TimeCut.str().c_str();
cout<<newCut; //output empty

ch->SetEventList(List);
ch->Draw(“GetEnergy()>>hist”,newCut); // draws all in EventList
ch->Draw(“GetEnergy()>>hist”,TimeCut.str().c_str()); // draws just the desired cases
}

So I think it’s a misusage of TCut…

Hi,

There is indeed a problem where CINT does not properly call TCut’s operator const char* (to automatically convert from TCut to a c string).
It works nicely when you compile the code (easy to do using ACLiC). We will try to solve the issue in CINT.

Thanks for reporting this problem.
Philippe.