Hi Christian, What I normally use is the following : 1) Use GetEntry(ient) to get a certain entry in memory. 2) Then do something like Event* evtold=new Event(*event) to store the current event into the evtold structure. 3) Then do again GetEntry(ient2) to obtain a different event in memory. 4) Now you have 2 structures filled, namely "event" and "evtold" and you can have fun with your mixing :). Cheers, Nick. -- Dr. Nick van Eijndhoven mailto:nick@phys.uu.nl http://www.phys.uu.nl/~nick -------------------------------------------------------------------------- Org.: Utrecht University, Faculty of Physics and Astronomy Address: Princetonplein 5, NL-3584 CC Utrecht, The Netherlands Phone: +31-30-2532331(direct) +31-30-2531492(secr.) Fax: +31-30-2518689 CERN: +41-22-7679751(direct) +41-22-7675857(secr.) Fax: +41-22-7679480 Offices: Buys Ballot laboratory Room 710 (Utrecht) B23 1-020 (CERN) -------------------------------------------------------------------------- Christian Holm Christensen wrote: > > 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