Confused reading a sub-branch of a splitted object

Dear rooters,

I’ve read a sub-branch of a spliited(99) object of my own MCEvent class inhereted from my Event and found out that the result is different for TChain and TTree.
A short protocol of my session is in the attachment.
Are there any ideas about the difference of results in the 1-st and 2-nd root seesions?

                                         best wishes, Valery.

PS

RHL9 Linux 2.4.20-20.9 #1 Mon Aug 18 11:45:58 EDT 2003 i686 i686 GNU/Linux

confusion.txt (3.69 KB)

I do not understand this problem. Are you running with the binaries from the ROOT web site or did you compile yourself (if yes with which version of the compiler)?

Could you run with the following mods:

root [0] gSystem->Load(“Event_cxx.so”);
root [1] Event event = 0;
root [2] TChain chain(“mctreecoll”);
root [3] chain.Add(“treetest1.root”);
root [4] chain.Add(“treetest2.root”);
root [5] chain.SetBranchAddress(“eventsplit”,&event);
root [6] chain.SetBranchStatus("
",0);
root [7] chain.SetBranchStatus(“fData”,1);
root [8] chain.LoadTree(0);
root [9] cout<<chain.GetEntry(2)<<endl;

Rene

Dear Rene,
The reason for confusion is the different result
when reading a sub-branch of a tree from a file using
TChain or TTree methods. A fData MCEvent class data member
isn’t filled when reading the file added to a TChain, while is correctrly filled,
when the TTree methods are used.
I suspect that the result should be the same in both cases.

I use a distribution from the ROOT site:
root_v4.00.06.Linux.RH9.0.gcc32.tar.gz

I did carried out your suggestion, but the result is the same - the MCEvent object
hasn’t been ceated.

[Event2] > root


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 4.00/06 4 June 2004 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gSystem->Load(“Event_cxx.so”);
root [1] Event event = 0;
root [2] TChain chain(“mctreecoll”);
root [3] chain.Add(“treetest1.root”);
root [4] chain.Add(“treetest2.root”);
root [5] chain.SetBranchAddress(“eventsplit”,&event);
root [6] chain.SetBranchStatus("
",0);
root [7] chain.SetBranchStatus(“fData”,1);
root [8] chain.LoadTree(0);
root [9] cout<<chain.GetEntry(2)<<endl;
0 // <========!!!
root [10] if( event ) cout<<(*event)<<endl; // event == 0 !!!

But if i will try to read the whole branch, then i will get the fData:

[Event2] > root


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 4.00/06 4 June 2004 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gSystem->Load(“Event_cxx.so”);
root [1] Event *event = 0;
root [2] TChain chain(“mctreecoll”);
root [3] chain.Add(“treetest1.root”);
root [4] chain.Add(“treetest2.root”);
root [5] chain.SetBranchAddress(“eventsplit”,&event);
root [6] chain.LoadTree(0);
root [7] cout<<chain.GetEntry(2)<<endl;
36 // <========== !!!
root [8] if( event ) cout<<(*event)<<endl;
Event: “mceventobj” %1 %2 fData: 0.318973 // MCEvent was created and fData was set

If i will try to use a TTree methods to read the fData, then the result will be correct, too.

[Event2] > root


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 4.00/06 4 June 2004 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linux with thread support.

CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gSystem->Load(“Event_cxx.so”);
root [1] Event event = 0;
root [2] TFile f(“treetest1.root”);
root [3] TTree tree = (TTree)f.Get(“mctreecoll”);
root [4] tree->SetBranchAddress(“eventsplit”,&event);
root [5] tree->SetBranchStatus("
",0);
root [6] tree->SetBranchStatus(“fData”,1);
root [7]
root [7] cout<GetEntry(2)<<endl;
8 // <=========== !!!
root [8] if( event ) cout<<(*event)<<endl;
Event: “mceventobj” %0 %0 fData: 0.318973 // fData was set
root [9] .q

                                 Regards, Valery.

Could you send me the SHORTEST possible set of files reproducing the problem?

Rene

Dear Rene,
In the attachment below you will find a file for production of trees(writetree.C)
and Event class description(Event.h,.cxx).
The files treetest1.root and treetest2.root were produced by executing:
.x writetree.C
.x writetree.C(“treetest2.root”,5,2);
Regards, Valery.
confusion.tar.gz (1.44 KB)

Hi Valery,

Invert the calls to TChain::SetBranchAddress and SetBranchStatus. see:

root.cern.ch/root/htmldoc/TChain … nchAddress

Rene

Dear Rene,

It helps. Thanks a lot.

                        Regards, Valery.