Re: [ROOT] Cloning/filtering more complicated trees

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Dec 02 2002 - 18:15:38 MET


Hi Rick,

Below an example of a script that I introduced last week in the CVS
version in $ROOTSYS/tutorials/copytree3.C
This script uses a file produced by $ROOTSYS/test/Event with
Event 200 0 99 1

Rene Brun

{
   gSystem->Load("$ROOTSYS/test/libEvent.so");

   //Get old file, old tree and set top branch address
   TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
   TTree *oldtree = (TTree*)oldfile->Get("T");
   Int_t nentries = (Int_t)oldtree->GetEntries();
   Event *event   = 0;
   oldtree->SetBranchAddress("event",&event);

   //Create a new file + a clone of old tree in new file
   TFile *newfile = new TFile("small.root","recreate");
   TTree *newtree = oldtree->CloneTree(0);

   for (Int_t i=0;i<nentries; i++) {
      oldtree->GetEntry(i);
      if (event->GetNtrack() > 605) newtree->Fill();
      event->Clear();
   }
   newtree->Print();
   newtree->AutoSave();
   delete oldfile;
   delete newfile;
}


On Mon, 2 Dec 2002, Rick Van Kooten wrote:

> 
>   I was filtering trees, i.e., using selection criteria inside of a
> looping macro in root and then writing out a subset of the original
> tree.
> 
>   However, I am having trouble (and have tried other experts already)
> cloning a tree where some of the branches are not basic types, i.e.,
> arrays, and there are links between members of the different arrays. 
> The documentation does state:
> 
>  IMPORTANT: Before invoking this function, the branch addresses
>             of this TTree must have been set if one or more branches
>             is not a basic type.
> 
> and there is a member function CopyAddresses, but how does one use it
> to set the addresses _before_ one has created the new tree using
> CloneTree? All my efforts so far has resulted in a correctly filtered
> tree for the basic branches, but not for the branches that are arrays.
> An example would be nice....
> 
> 				Thanks,
> 						Rick
> -- 
> Rick Van Kooten  \    Telephone: (812) 855-2650  FNAL: (630) 840-3859
> Dept. of Physics  \   FAX:       (812) 855-0440 
> Indiana University \  e-mail:    rvankoot@indiana.edu
> Swain Hall West 117 \            rickv@fnal.gov
> Bloomington, IN 47405\ http://physics.indiana.edu/~rickv/aboutme.html
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:22 MET