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
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
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
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.