Filling RooDataSet with vectors?

Hello everyone!

I have a very naive question regarding the import of the data to RooDataSet in C++

I know that the traditional way to proceed is via using the TTree. However, I have to perform the fit on several slices of it and I don’t want the RooFit to slice the initial TTree every time (at the same time I don’t want to store the preselected trees neither). The workaround would be to pre-define the data and store it in e.g. vectors. If there’s a way to import data to RooDataSet from a vector? (I’m wondering since there’s an option to convert the NumPy arrays to RooDataSet).

The alternative methods to avoid the slicing at each step are very welcome.

Many thanks in advance.

Hi @Mykhailo_Ieresko ,
In Python you can create directly a RooDataSet from a Numpy array, see the tutorial
rf409_NumPyPandasToRooFit.py .

Cheers,
Monica

Hello @mdessole !

Many thanks for your answer.
Precisely, I know that it’s possible for python, hence I’m seeking the equivalent in C++

Cheers,
Mike.

Sorry, I misread your question!
Then maybe you can try to fill first a RDF and then export it to RooDataSet like it is shown here.

Yes, you can use RDF to to open the TTree and get your slices, or you can also just create your RooDataSets from e.g. vectors like this:

// Create original varialbles
RooRealVar x{"x", "x", 0.0};
RooRealVar y{"y", "y", 0.0};

// Define a RooArgSet with the variables outside the loop, to avoid the
// overhead of creating a RooArgSet every time (which is a mistake I often see)
RooArgSet dataVars{x, y};

// Create dataset
RooDataSet dataSet{"dataSet", "dataSet", dataVars};

// The vectors to fill the data with
std::size_t nEntries = 3;
std::vector<double> xVals{1., 2., 3.};
std::vector<double> yVals{4., 5., 6.};

// Now let's fill the dataset
for(std::size_t i = 0; i < nEntries; ++i) {
   x.setVal(xVals[i]);
   y.setVal(yVals[i]);
   dataSet.add(dataVars);
}

Or you could also import your original TTree to a RooDataSet, and the do the slicing with RooFit using the RooAbsData::reduce() method that is further showcased in the rf402_datahandling.C tutorial.

I hope this gives you some ideas!

Cheers,
Jonas

@jonas @mdessole

Many thanks for such rapid answers. Going to try the suggested options!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.