[ROOT] TTree problems, using same variable names in different structs.

From: Brett Viren (bv@bnl.gov)
Date: Thu Sep 09 2004 - 20:11:04 MEST


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