Re: [ROOT] TChain misuderstandings

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Aug 18 2003 - 09:04:53 MEST


Hi,

You must provide more information when sending mail to this list.
Simplify the life of thousands of people reading your mail.
Please read: http://root.cern.ch/root/roottalk/RoottalkRules.html

TTree and TChain behave in the same way when setting the branch addresses.
  TTree* tree;  TChain* chain
  tree->SetBranchAddress("branchname",&fdisk01_wedge01_n);

  chain->SetBranchAddress("branchname",&fdisk01_wedge01_n);

when doing tree->GetEntry(i) or chain->GetEntry(i)
the variable/object at the specified address should be filled.

Rene Brun

Justace Clutter wrote:
> 
> Well,
> 
>         I understand that I can do this, and I have.  What I find as strange is the
> differences in the data access between the TChain and the TTree. If I open
> the file with TFile I can access the data by creating a variable placeholder,
> telling the TTree the address of the placeholder and then pulling the right
> entry.  Now, if I open the data through the TChain, there are some more
> detail to take care of.  I am reading about them but do not follow them.  I
> understand that the TChain is based off of TTree, so, intuitivly I would
> assume that it would work transparently as a tree also, such is not the case.
> 
>         The main thing that bothers me is that in the class header that was created
> with makeclass, it declares a lot of variables, all the information that I am
> looking for and it seems to make sence.  Then, instead of calling
> SetBranchAddress over and over it just calles this on a few of the variables
> in the TTree.  After makeing the call to GetEntry all the data seems filled
> even though it seems that the TTree was never passed references to the
> declared placeholders.
> 
> Justace
> 
> On Sunday 17 August 2003 03:34 pm, zaldy wrote:
> > Hi,
> >
> > If I understood it correctly; you want to chain 4 root files, say
> > file1.root, file2.root, file3.root, and file4.root, then you want to
> > produce a code using the MakeClass Functionality.
> >
> > If this is the case, one possibility is:
> >
> > At the directory where all these root files are located do:
> >  root[] TChain ch("SMT");
> >  root[] ch.Add("file*.root");
> >  root[] SMT->MakeClass("myClass");
> >
> > Assuming the root files are of same tree structure, the above lines should
> > result to the creatioin of myClass.C and myClass.h.
> > Then you can edit/modify the files according the nature of your
> > application.
> >
> > I you want to understand the meaning of the codes and functions in the
> > TChain class I suggest you go to the site:
> >
> > http://root.cern.ch/root/html/TChain.html
> >
> > Hope it helps...keep trying.
> >
> > On Sun, 17 Aug 2003, Justace Clutter wrote:
> > > I am a very new root user and have been trying to understand how the
> > > TChain works.  There is a TTree, called SMT, spread out among four
> > > different root files.  If I load the first file up using just a straight
> > > TFile I can access the data directly like the following:
> > >
> > >     Int_t fdisk01_wedge01_n[768];
> > >
> > >     SMT->SetBranchAddress("fdisk01_wedge01_n", &fdisk01_wedge01_n);
> > >     SMT->GetEntry(0);
> > >
> > > However when I try to load all the data at once with TChain I get very
> > > confused.
> > >
> > >     TChain *data_chain = new TChain("SMT");
> > >
> > >     data_chain->Add("file1");
> > >     data_chain->Add("file2");
> > >     data_chain->Add("file3");
> > >     data_chain->Add("file4");
> > >
> > > At this point I can not just run the same code as I did above.  Now I ran
> > > the makeclass utilities and generated the class files, but now I am even
> > > more confused.  The variables are declared in the class but only a few
> > > are set through the SetBranchAddress functions.  But they are all
> > > available somehow.
> > >
> > > I know that this post is very confusing, but I am confused.  I have went
> > > through the ROOT Users Guide and the examples but they did not help my
> > > understanding of this.  Any help on this matter would be greatly
> > > appreciated. I guess that I just want to know how it works, I could just
> > > use the makeclass and close my eyes but that does not put a smile on my
> > > face.
> > >
> > > Justace Clutter



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET