Serious problems adding a class to a TTree

Hi all,
I’m continuing to torture the TTree beacusa I need to create for various reason a TTree with many variables.

Assuming that that using a C structure I cannot have dynamic leaves now I’m trying to use classes, but as results I have many problems (code in attachments):

  1. I created a simple code that store data in a class, non dynamic leaves. Little example work.

  2. I extend this example creating 2 instance for the same class, added in branches with different names. Now two instance, in the TTree but no during creation, contains the same values. bad

root [1] tree->Scan()
************************************************************
*    Row   *      val1 *      val2 *      val1 *      val2 *
************************************************************
*        0 * 0.0194094 *         0 * 0.0194094 *         0 *
*        1 * -1.107838 *         2 * -1.107838 *         2 *
*        2 * 0.7634595 *         0 * 0.7634595 *         0 *
*        3 * -0.627032 *         2 * -0.627032 *         2 *
  1. I try to create the code to loop in the TTree with two objects using MakeClass. The code generated have many errors:

a. the two sets of variables have the same names, no prefix with the name of the branch is added, from make_complextree.h

   // Declaration of leave types
 //myClass         *data0;
   Double_t        val1;
   Float_t         val2;
 //myClass         *data1;
   Double_t        val1;
   Float_t         val2;

b. the name of the TBranches in the declaration are different respect name used in the Init() methods:

declaration:

   // List of branches
   TBranch        *b_data0_val1;   //!
   TBranch        *b_data0_val2;   //!
   TBranch        *b_data1_val1;   //!
   TBranch        *b_data1_val2;   //!

in Init method became:

   fChain->SetBranchAddress("val1", &val1, &b_val1);
   fChain->SetBranchAddress("val2", &val2, &b_val2);
   fChain->SetBranchAddress("val1", &val1, &b_val1);
   fChain->SetBranchAddress("val2", &val2, &b_val2);

In my opinion only the section of TBranch declaration make sense the other seems an error.

Guido
make_complextree.h (3.92 KB)
complextree3b.C (981 Bytes)
complextree3.C (803 Bytes)

Hi Guido,

  1. you have small typo in complextree3b.C: obj1->SetVal2 instead SetVal1
  2. add this lines in your myClass:

Double_t GetVal1() { return val1; } Float_t GetVal2() { return val2; } 3) after run complextree3b() try this:

[code]myClass *obj0;
myClass *obj1;
tree->SetBranchAddress(“data0”, &obj0);
tree->SetBranchAddress(“data1”, &obj1);

tree->GetEntry(0);
Printf("%g, %g", obj0->GetVal1(), obj1->GetVal1());
tree->GetEntry(1);
Printf("%g, %g", obj0->GetVal1(), obj1->GetVal1());
[/code]all is OK, values are different, but really, tree->Scan() show same values (maybe Philippe can explanation ?)

Jan

[quote]all is OK, values are different, but really, tree->Scan() show same values (maybe Philippe can explanation ?)
[/quote]Indeed, this is somewhat of an issue restricted to TTree::Scan.
The issue is that you have 2 top level branches containing the same object and you requested (implictly) the short version of branchname which make avoiding ‘ambiguities’ difficult (does val1 mans data0.val1 or data1.val1?) (and TTree::Scan fails because of this ambiguity).

To solve the problem, simply request the long version of the branchname by adding a ‘.’ at the end of the branch name: tree->Branch("data0.",&obj0,8000,1); tree->Branch("data1.",&obj1,8000,1);

[quote]3. a. the two sets of variables have the same names, no prefix with the name of the branch is added, from make_complextree.h
[/quote]This issues always goes away when requesting the long version of the branchname.

[quote]3. b. the name of the TBranches in the declaration are different respect name used in the Init() methods:
[/quote]This has been fixed (in the last few hours) in the CVS repository.

Cheers,
Philippe.

Great, the adding a dot to the branch name works?

************************************************************
*    Row   * data0.val * data0.val * data1.val * data1.val *
************************************************************
*        0 * 0.0194094 *         0 *         2 * 0.3271895 *
*        1 * -1.107838 *         2 *         0 * -0.081343 *
*        2 * 0.7634595 *         0 *         0 * 0.3330836 *
*        3 * -0.627032 *         2 *         0 * -0.438629 *

for musinsky, this was not a typo but to have a quick test I want exange the distributions contained in val1 and val2 in the 2 objects, a little trick.

A question: I need to know if the error in MakeClass is only in the latest stable version or in the old version, to know the problem that other people of my group can have running my code.

Many Thanks Philippe.

[quote]A question: I need to know if the error in MakeClass is only in the latest stable version or in the old version, to know the problem that other people of my group can have running my code.
[/quote]This was only in 5.12/00.

Cheers,
Philippe