Dear rooters, the new class TTreeIter is developed, tested and proposed for the wide usage. This is a kind of iterator for TTree or TChain classes. Functionally it is combination of TTree::Draw() and TTree::MakeClass(). TTreeIter is almost as flexible as TTree::Draw() and allows the same complexity of request as TTree::MakeClass() The user interface is very simple and user friendly. It is based on rather complicated C++ features but all this complexity is hidden from the user. SPEED is same as optimised MakeClass (only needed branches are read) In compiled case (ACLIc) it is faster then TTree::Draw For several histograms (>3) it is faster then TTree::Draw even in CINT case. TTreeIter is not supposed to replace TTree::Draw() or TTree::MakeClass(). But there is rather wide range of applications where it is more convenient then these two. A simple example. ================ TTreeIter iter; iter.AddFile("path1/event*.root"); iter.AddFile("path2/event*.root"); // init of user variables const int &ntrk = iter("fTracks"); const Float_t *&pz = iter("fTracks.fPz"); // Now the user variables ntrk and pz are initialised and according branches // automatically activated. These variables are referenced to internal // hidden buffers, which will be automatically updated during iteration. TH1F *hz = new TH1F("Z","Z distribution",50,-5.,+5.); // Now iterations while (iter.Next()) { for (int itr=0;itr<ntrk;itr++) { hz->Fill( pz[itr]); } } iter.Reset(); //ready for next loop ------------------------------------------------------------------------- For those who is interested, all codes and Makefile are: Those users who have AFS can get it from /afs/rhic/star/packages/.DEV/StRoot/StarRoot/* or http://rhic.rcf.bnl.gov/~perev/StarRoot/ FILEs: TTreeIter.txt - this message TTreeIter.h TTreeIter.cxx TTreeIterLinkDef.h MakeTTreeIter.mk - make file for Linux (easily modification for others) - gmake -f MakeTTreeIter.mk th.C - example to measure speed TTreeIter and Draw mk.C - example to measure speed MakeClass All comments, critics and proposals are welcome. Victor =================================================================== MORE DETAILED =================================================================== TTreeIter does the same job as TTree::Draw() or MakeClassb but it is different. ============================================================================== Comparison with TTree::Draw(): ----------------------------- 1. TTree::Draw() uses special language. TTreeIter uses standard C++ or CINT. 2. Selection in TTree::Draw() must be in one line. It is very convenient for simple case. TTreeIter does not have such limitation. Selection and weight calculation could be as complex as user needs. 3. To fill several histograms, TTree::Draw() must read the file or the chain of files several times. TTreeIter does it in one pass. Comparison with MakeClass: ------------------------- 1. TTreeIter internally uses the same technique as MakeClass. Complexity of selection is the same 2. For each tree MakeClass generates C++ code which user should use. TTreeIter is the same for all trees. No code is generated In this sense TTreeIter is more flexible. 3. If format of tree is changed, MakeClass should be regenerated. TTreeIter is the same. Only additional needed variable could be declared. 4. Usually not all variables of tree are used. To keep MakeClass fast, user must activate/deactivate according branches by hands. In TTreeIter, when user defined and initialised variable (const Float_t &temp = iter("fTemperature");) according branch activated automatically and only activated branches are read. Speed tests: ------------ 1 histogram 10000 events CINT interpreter case: ---------------------------------------------- TTree::Draw : 23.49 seconds TTreeIter : 41.11 seconds MakeClassNonOpt: 162.39 seconds MakeClassOpt : 41.99 seconds So, TTreeIter as fast as optimised MakeClass and both are slower than TTree::Draw 1 histogram 10000 events ACLiC case: ---------------------------------------------- TTree::Draw : 24.09 seconds TTreeIter : 9.32 seconds MakeClassNonOpt : 132.18 seconds MakeClassOpt : 9.40 seconds Again, TTreeIter as fast as optimised MakeClass and both are much faster than TTree::Draw. The last is evident, Draw uses interpretor. 3 histograms 10000 events CINT interpreter case: ---------------------------------------------- TTree::Draw : 35.40 seconds TTreeIter : 46.57 seconds MakeClassNonOpt : 164.27 seconds MakeClassOpt : 47.79 seconds Here, TTreeIter as fast as optimised MakeClass and both are close to TTree::Draw. It is because Draw uses separate pass for each histogram. For the big amount of histograms, TTree::Draw will be slower than TTreeIter and MakeClassOpt 3 histograms 10000 events ACLiC case: ---------------------------------------------- TTree::Draw : 35.77 seconds TTreeIter : 16.44 seconds MakeClassNonOpt : 129.08 seconds MakeClassOpt : 15.92 seconds Again, TTreeIter as fast as optimised MakeClass and both are much faster than TTree::Draw. Any feedback will be very welcome. Victor -- Victor M. Perevoztchikov perev@bnl.gov perev@vxcern.cern.ch Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000 tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690--
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET