Issues in cloning TTree extracted from RooDataSet

Dear experts,

I’m sorry if this topic doesn’t belong to the right section, or if the the answer to the question will be excessively trivial (I have little to no experience in RooFit).

What I am trying to do is to obtain a number n of statistically independent distributions (let’s call them pseudo-experiments) starting from an existing histogram.
The basic sequence of commands I implemented to obtain a single pseudo-experiment is the following:

RooRealVar varx("varx",varxName,varxLow,varxHigh);
RooDataHist rooDataHist("rooDataHist", "rooDataHist", RooArgList(varx), h_gen);
RooHistPdf pdfForGen("pdfForGen","pdf",RooArgList(varx), rooDataHist,0) ; 

where h_gen is the original histogram.

Then:

RooRandom::randomGenerator()->SetSeed(); 
RooDataSet *data = pdfForGen.generate(RooArgList(varx), some_vector.size());
TTree* myDataTree = (TTree*)((RooTreeDataStore*)((std::remove_const<TTree*>::type)(data->store())->tree())->CloneTree());

I felt necessary to add the “std::remove_const<TTree*>::type” bit as without it the code wasn’t compiling (I think that CloneTree does not want to act on a const TTree*).
Now it compiles, but the code crashes in trying to execute CloneTree() – I separated the last line in different commands to make sure of that.

What am I doing wrong?

Thank you.

Hi
Probably the internal data storage is not a TTree but a vector and data->store())->tree() returns a null pointer

Lorenzo