Hi ROOT'ers,
I have a question on how to do mixed event analysis using TChains.
The point of it all is, that given that you're in some event, you'd
like to read another event too, be it a previous or a later event. So
in terms of (meta-) code, it be something like:
DO WHILE there are more events to read
read next event into memory
read a previous or later event into memory too
process the two events
END
or in a more ROOT like way:
TChain* chain = ...
chain->Add(...
chain->SetBranchAddress("Event", &event);
...
while (chain->GetEntry(i++)) {
...
chain->SetBranchAddress("Event", &other);
chain->GetEntry(j);
mix_events->(event, other);
chain->SetBranchAddress("Event", &event);
}
I think the problem is, that TChains are a bit particular on how you
access the data in them - they want you to read the files that make up
the chain sequentially - that is, you can not cross file boundaries.
I made an (simple) example, which is available at
http://cholm.home.cern.ch/cholm/root/mixevent.tar.gz
Take a look at that code. Try it as follows:
> tar -xzvf mixevent.tar.gz
> cd mixevent
> make check
As it is now, it will fail, as it's reading two events ahead, hence
crossing file boundaries. Now, try running it skipping only one event
ahead
> ./Read 1
That should work. Now, try running it again, reading some events
backward:
> ./Read <any negative number>
No matter what the absolute value of <any negative number> is, as long
as it's negative, it will always fail when you're reading back over a
file boundary.
I can think of 3 ways of working around this:
1) Make the user set a flag that caches the current event, and they
can then call it back from memory storage later on. This obviously
doesn't work if you want to read events ahead of the current one.
2) Always keep say 5 events in memory, and let the `current' point to
the middle one. Hence the user can use up to 2 events
forward/backward - this behaviour could be dependable one a runtime
flag of course.
3) Allow unlimited access to previous or next events, as long as they
are within the same file as the current event. I believe there's a
method to get the index in the current tree rather than in the
chain (I think it's used when you do TChain::MakeClass).
I personally prefer option 3.
Now my question: What am I doing wrong here? Have I missed something
in the documentation? Is there anyway to do this kind of thing more
naturally, than the 3 work-a-rounds? If not, could there be?
Thank you.
Yours,
___ | Christian Holm Christensen
|_| | -------------------------------------------------------------
| | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
_| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
_| Denmark Office: (+45) 353 25 305
____| Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
| |
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET