How to access to branch informations

HI all,
I don’t understand what is the way to access the information in a branch.
I have I root file, see the picture, with some variables and two branch, Met and Header.
Now to take info for the variable I use the method:

TFile *file = new TFile("mini-ntuple.root"); TTree *tree = (TTree*)file->Get("Jet"); tree->SetBranchAddress("E", &E); for (int i=0; i<entries; i++) { tree->GetEntry(i); cout << E[i] << endl; }

and everything works.
Now if I want to take info from the branch “Met”, for example the variable MetSig, what is the way?
I tried to write:

  TBranch *Met = tree->GetBranch("Met");
  Met->SetBranchAddress("MetSig", &MetSig);

but it’s wrong…
Do you have some hints?
Ciccio


Hi,

You best bet is to use the result of tree->MakeSelector(“mysel”); which will set properly the branch addresses (or possibly better yet the result of TTree::MakeProxy).

The short answer is that you need to do:tree->SetMakeClass(1); // Use the decomposed object mode. tree->SetBranchAddress("Met.MetSig",&MetSig);

Cheers,
Philippe.

Hi,

thank you much for the answer.
I tried to use:

tree->SetMakeClass(1); // Use the decomposed object mode. tree->SetBranchAddress("Met.MetSig",&MetSig);

but I obtain this error:

so I tried to use: tree->MakeSelector(“mysel”); and I obtain the 2 files: mysel.C, mysel.h
what is the way to use information in these files?
Thank you
Ciccio

[quote]Error in TTree::SetBranchAddress: unknown branch -> Met.MetSig [/quote]Well I was guessing on the name of the branch … :slight_smile:

[quote]what is the way to use information in these files?
[/quote]See the User’s guide and the documentation in the reference’s guide for MakeSelector and TSelector.

You will need to look at the content of mysel.h to see the name used for your variable the you should edit the file mysel.C to create your histogram in the routine mysel::SlaveBegin, fill then in the routine mysel::Process and draw then in the routine mysel::Terminate.

Then you can use as:mytree->Process("mysel.C+");

Cheers,
Philippe.

but the name of the branch is correct, see picture, and the MetSig is not empty.
and in mysel.h about MetSig I have only this:

Float_t         Met_MetSig;

nothing else.
Ciccio




[quote]and in mysel.h about MetSig I have only this: [/quote]There should also a SetBranchAddress … If not this is strange and I would need your file to investigate further.

Cheers,
Philippe.