Hi Brett,
Replace
tree->Branch("abranch","A",&a);
tree->Branch("bbranch","B",&b);
by
tree->Branch("abranch.","A",&a);
tree->Branch("bbranch.","B",&b);
see doc of TTree::Bronch
IMPORTANT NOTE about branch names
In case two or more master branches contain subbranches with
identical names, one must add a "." (dot) character at the end
of the master branch name. This will force the name of the subbranch
to be master.subbranch instead of simply subbranch.
This situation happens when the top level object (say event)
has two or more members referencing the same class.
For example, if a Tree has two branches B1 and B2 corresponding
to objects of the same class MyClass, one can do:
tree.Branch("B1.","MyClass",&b1,8000,1);
tree.Branch("B2.","MyClass",&b2,8000,1);
if MyClass has 3 members a,b,c, the two instructions above will
generate
subbranches called B1.a, B1.b ,B1.c, B2.a, B2.b, B2.c
Rene Brun
On
Thu,
9
Sep 2004, Brett Viren
wrote:
> Hi,
>
> When I run the appended code like:
>
> shell> root -l test.C # generates test.root
> root [0]
> Processing test.C...
> root [1] TFile f("test.root")
> root [2] f.ls()
> TFile** test.root
> TFile* test.root
> KEY: TTree tree;1 test tree
> root [3] tree->Draw("bbranch.a")
> <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>
> Instead of a histogram of "bbranch.a" which should be just one bin at
> zero, I get a histogram of "abranch.a" values. Is it illegal to use
> the same variable names in different branches based on structs, or am
> I doing something else wrong?
>
> CVS root: 4.01/01 25 August 2004, GCC 3.3.3 on x86 Debian.
>
> Thanks,
> -Brett.
>
> //--------------
> // test.C
> void test ()
> {
> struct A : public TObject {
> int a,b,c;
> A() { a=b=c=0; }
> };
> struct B : public TObject {
> int a,b,c;
> B() { a=b=c=0; }
> };
>
> TFile* file = new TFile("test.root","recreate");
> TTree* tree = new TTree("tree", "test tree");
> A* a = new A;
> B* b = new B;
> tree->Branch("abranch","A",&a);
> tree->Branch("bbranch","B",&b);
>
> for (int ind=0; ind<10; ++ind) {
> a->a = ind+1;
> a->b = 10*(ind+1);
> a->c = ind*(ind+1);
>
> b->a = 0;
> b->b = 0;
> b->c = 0;
>
> tree->Fill();
> }
> file->cd();
> tree->Write();
> file->Close();
> }
>
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET