How to store variables of type RooRealVar as a branch in a tree?

Is there a way to store RooRealVar as a branch in a tree? My aim is to get the distribution of v1 in a range of v0 variable. I tried such a way that first created and filled a histogram as below

TFile f(“tree.root”,“recreate”);
TTree *T = new TTree(“Sig”,“test”);

RooRealVar v0(“v0”,v0", 0.02, 5.);
RooRealVar v1(“v1”,v1", 1.0, 99.);
RooDataSet * dataSetS= (RooDataSet::read(FileName,RooArgSet(v0,v1),“Q”);
TH1 * h1 = dataSetS->createHistogram(“v1”);

T->Branch(“myv1”,&h1); // I try this line but tree has no branch with the distribution of v1 variable. I get it in the root file but not in the branch.

Any suggestion?

Hi,

Do you want to store in the TTree the histograms or all the variable values ?

For transforming a RooDataSet in a TTree there is a function in RooStats,

RooStats::GetAsATree

see

root.cern.ch/doc/v606/namespace … 211cf09d3b

Lorenzo

I need to store the histograms in a TTree branch. I can build the histos as

TH1F* myh = v1.createHistogram(“v1”,“myh”);
TH1* myh2 = dataset->fillHistogram(myh,v1);

and can save the TH1F to a root file but could not find a way of storing it in a Tree branch.

${ROOTSYS}/tutorials/tree/htest.C

yes I definitely tried that but the thing is I need to have “This is the px distribution” - TH1F - in the Tree. I obtain it outside it wrt this code.