RooDataSet::tree() function now working?


I have a mac with OSX 10.10.4 and ROOT 6.05/01. I am trying to extract the tree representation of a RooDataSet. In the code below:

[code] RooRealVar x(“x”,"",0,10);
RooRealVar p(“p”,"",0,10);

RooGenericPdf pdf("pdf","","TMath::Exp(-p*x)",RooArgList(x,p) );
RooDataSet *data = pdf.generate(x, 5000);

TTree *tree_data = (TTree*)data->tree();

RooAbsDataStore *ds = (RooAbsDataStore*)data->store();

TTree *tree = (TTree*)ds->tree();


you can see that I try to call RooDataSet::tree() but I get a null pointer. Here RooDataSet::tree() in RooFit version 3.00 it says that I should be able to get a RooAbsDataStore object with RooDataSet::store() and then from it I should call RooAbsDataStore::tree(), which I did above, but the pointer is still null. Am I making a mistake in the code above? Any of these tree() functions are supposed to work?

Also, if anyone else needs this and its not available I wrote this function:

[code]TTree* GetDataTree(TString name, RooDataSet *data)
TTree *tree = new TTree(name,"");

std::map<TString, float> m_map;

for (int i_entry = 0; ; i_entry++)
    RooArgSet *mset = (RooArgSet*)data->get(i_entry);
    TIterator *iter = mset->createIterator();
    while(TObject *obj = iter->Next())
        RooRealVar *var = dynamic_cast<RooRealVar*>(obj);
        TString name( var->GetName() );
        m_map[name] = var->getValV();
        if(i_entry != 0)
        tree->Branch(name.Data(), &m_map[name]);

return tree;


It only makes branches with floats as types, however I have never needed anything else.



By default the storage type for a RooAbsData is a simple vector. In order to have the method tree() working you would need to do call first the static function RooAbsData::setDefaultStorageType(RooAbsData::Tree).

If you have an existing data you just need to do something like

 RooDataSet * dataNew = new RooDataSet("dataNew","dataNew",oldDataSet, *oldDataSet->get()); 
 TTree * tree = dataNew->tree();  // this would return a valid pointer 

Best Regards



I tried it and yes, it did work, however this is a pretty useful piece of information that is not documented anywhere. Could you please add that to the entry in: … 72b17b58d9

So that people can find it easily?