Hi Martin, Let's take a concrete example, the one in $ROOTSYS/tutorials/h1analysis.C. Make the following few mods: -at the top of h1analysis.C, add TH1F *hdmd; TH2F *h2; h1analysis bis; //NEW LINE. create a new h1analysis object -in h1analysis::Begin, add the following lines: TFile *f = new TFile("$H1/dstarp1a.root"); //NEWLINE TTree *h42 = (TTree*)f->Get("h42");//NEW LINE bis.Init(h42);//NEW LINE //initialize the Tree branch addresses Init(tree); -in h1analysis::ProcessFill, add this line if (entry < 100) bis.fChain->Show(entry+1000); Now, do, eg root > .x h1chain.C root > chain.Process("h1analysis.C++) In h1analysis::Begin, the second selector (bis) will be initialized with the Tree named "h42" in one of the $H1 files. In h1analysis::ProcessFill, we simply read and dump an entry of the second Tree. You can replace fChain->Show by fChain->GetEntry and use the data members of the object bis. You could add more selectors acting on other Trees in the same way. Rene Brun On Tue, 7 May 2002, Martin Turner wrote: > 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