Accessing leaves with RooDataSet

Hi,

I’ve been trying to import a variable from a TTree into a RooDataSet. As far as I understand, it is simple enough to import a TBranch from a TTree, where the branch contains the relevant variable. For a TBranch with the name “Mass” from the TTree “tree” I would do:

RooRealVar mass(“Mass”, “Mass”, 0, 5);
RooDataSet data(“data”, “data”, RooArgSet(mass), Import(*tree));

However, how do I import a leaf from a branch? What if I have a branch “Child1” with the leaf “Mass”? The following does not work (as I would expect it to):

RooRealVar mass(“Child1.Mass”, “Child1.Mass”, 0, 5);
RooDataSet data(“data”, “data”, RooArgSet(mass), Import(*tree));

Is this even possible to do, or can only branches be imported as variables? Thanks for any pointers on this.

Hello,

if all the variables you want to import are part of the same branch in the tree I believe you can use:

TTree* tree = (TTree*) file.Get(“tree/Child1”);

and then import “Mass”. If you want to import also other variables from other branches: you can import the variables of Child1 in a dataset1 and Child2 in dataset2 and then merge the datasets (if that’s what you want to do).

You can also create an empty dataset:

RooRealVar mass(“Mass”, “Mass”, 0, 5);
RooArgSet row(mass);
RooDataSet data(“data”, “data”, row);

and then loop over the tree(s) entries and add each row one by one with in the loop:

mass->setVal(…);
data.add(row);

Regards,

– Gregory