[ROOT] Re: Friend tree with TSelector

From: Martin Turner (martin@hep.ph.liv.ac.uk)
Date: Tue May 07 2002 - 19:19:56 MEST


Hi Rene, I didn't doubt that Bernhard's method wouldn't work with
TSelector. The question was how to loop over more than one tree in a file
created by MakeSelector(), as you mentioned to Andre;

The second option is more general as it allows you to:
  - loop on more than one Tree at the same time
  - fill more than one histogram
  - use complex selections

I don't see how I can easily loop over more than one tree without solving
Bernhard's problem. Were you just referring to jumping up and down chains
of trees or something really neat that puts trees in parallel that is
special to TSelector? 

Martin
On Tue, 7 May 2002, Rene Brun wrote:

> Hi Martin,
> 
> Yes, of course, you can use the technique I indicated to Bernhard.
> This technique reading two or more Trees will work if your Trees
> have the same structure.
> 
> Rene Brun
> 
> 
> Martin Turner wrote:
> > 
> > Hi Rene,
> > Thanks for the advice abot using a friend tree but maybe I should have
> > mentioned I need to call TTree::MakeSelector().
> > I saw in rootalk a solution to the problem if I was using makeclass, which
> > I assume would still work, but I also read that I could loop on two trees
> > at the same time in the selector file. This sounds what I want,
> > or is more efficient to just use your reply to Bernhard below? The two
> > trees I am trying to join have the same structure.
> > 
> > Martin.
> > Hi Bernhard,
> > 
> >    Yes, this is possible. Assuming a TTree *T, on which you have
> > generated the class via T->MakeClass("TC");
> > I assume that the first tree is in file tree1.root, the second in
> > tree2.root
> > or subdirectory of tree1.root. You can do
> > 
> > root > .L TC.C
> > root > TC t1;
> > root > TFile f2("tree2.root");
> > root > TTree *tree2 = (TTree*)f2.Get("T");
> > root > TC *t2 = new TC(tree2);
> > 
> >  The file TC.C can be edited to include the declaration of
> >  extern TC *t2;
> > 
> >  In the loop, you can call t2->GetEntry(ientry);
> > 
> >  Rene Brun
> > 
> > On Tue, 7 May 2002, Rene Brun wrote:
> > 
> > > Hi Martin,
> > >
> > > Martin Turner wrote:
> > > >
> > > > Hello! does anyone know the answers to the following:
> > > >
> > > > 1) Open an existing root file containing a tree with a single branch in a
> > > > completely different file to the one it was made(easy). Then add
> > > > additional variables to this branch which are simple doubles and ints
> > > > without overwriting the original branch. If this is possible, are the
> > > > additional variables stored at the entry number where it finished last
> > > > time or start from scratch.
> > > > If (1) is impossible then I may fill the tree with dummy
> > > > leaves so that I simply update vertically.
> > >
> > > The solution is to use Tree Friends.
> > >   See TTree::AddFriend
> > >        http://root.cern.ch/root/htmldoc/TTree.html#TTree:AddFriend
> > >   See example with $ROOTSYS/tutorials/tree3.C
> > >
> > > > 2) Could someone give an example of how to append entry's to a tree.
> > >
> > >   TFile *f = new TFile("myexistingfile.root","update");
> > >   TTree *T = (TTree*)f->Get("myTree");
> > >   T->SetBranchAddress(....
> > >
> > >   your loop with
> > >   T->Fill();
> > >
> > >   T->Write();
> > >
> > > Rene Brun
> > >
> > > >
> > > > Thanks in advance
> > > > Martin.
> > >
> 



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