Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] RDataFrame to RooDataSet/RooDataHist conversion #7223

Closed
hageboeck opened this issue Feb 16, 2021 · 5 comments · Fixed by #16091
Closed

[RF] RDataFrame to RooDataSet/RooDataHist conversion #7223

hageboeck opened this issue Feb 16, 2021 · 5 comments · Fixed by #16091

Comments

@hageboeck
Copy link
Member

hageboeck commented Feb 16, 2021

Is your feature request related to a problem? Please describe.

You could call it a "problem", yes.

What we want basically is to drop out an RooDataSet directly from RDataFrame. There's two ways to do it:

Easy way:

   // Fill d with dummy values
   Int_t i;
   for (i = 0; i < 1000; i++) {
      x = i / 50 - 10;
      y = sqrt(1.0 * i);
      c.setLabel((i % 2) ? "Plus" : "Minus");
 
      // We must explicitly refer to x,y,c here to pass the values because
      // d is not linked to them (as explained above)
      d.add(RooArgSet(x, y, c));
   }

This is going to be slow, and not so elegant.

Requires more development, but better:

  • RooDataSet should accept collections when you construct it
  • Since data is stored in a std::vector internally, it could even std::swap with an external vector!
  • RDataFrame should directly spit out such a collection or it should be easy to connect the two.
    • It is clear that MT runs are not trivial, but maybe not a priority.
    • @eguiraud what is the easiest to spit out from RDF, which is loopable, maybe even adopt the memory?
@hageboeck hageboeck changed the title RDataFrame to RooDataSet conversion [RF] RDataFrame to RooDataSet/RooDataHist conversion Feb 16, 2021
@eguiraud
Copy link
Member

I think you want a dedicated custom action that users can Book.

In general you can also just Take std::vectors (or other collections) out of a RDataFrame.

@hageboeck
Copy link
Member Author

Book is good-ish, it would fill the dataset one-by-one, but RF can do better.

I think Take is exactly what's needed!

Eventually, this could look like:

auto rooDataSet = rdf.RooDataSet("datasetname", {"x", "y", "z"});
pdf.fitTo(*rooDataSet);

Internally, this would do something like:

RooRealVar x(...);
RooRealVar y(...);
RooRealVar z(...);

auto xData = rdf.Take("x");
auto yData = rdf.Take("y");
auto zData = rdf.Take("z");

return RooDataSet(datasetname, RooArgSet(x, y, z), {std::move(*xData), std::move(*yData), std::move(*zData)}); // This constructor doesn't exist

There is lots of details missing, but that's what it could do eventually. Maybe the RooRealVars have to be passed into whatever it is I wrote above, because they have ranges and binnings and labels ...
In general, the thing is just supposed to connect those RooRealVar objects with the data that's taken from RDF.

Possible?

@eguiraud
Copy link
Member

Book is good-ish, it would fill the dataset one-by-one, but RF can do better.

Uhm, Book exposes the exact same mechanics that RDF uses for its own actions like rdf.RooDataSet, so anything you would like to do in there, you can do in the helper type you pass to Book.

Then it's a small step to go from df.Book(RooDataSetMaker(...), {"x", "y", "z"}) to df.MakeRooDataSet, basically just syntactic sugar.

@hageboeck
Copy link
Member Author

Ok, for single value filling, this may be achievable in a few days, nice.

hageboeck added a commit to hageboeck/root that referenced this issue Mar 4, 2021
To facilitate the creation of RooFit datasets from RDataFrame, an
ActionHelper is added to RooFit.
It lives in its own micro library, since it depends on RDataFrame, which
RooFit does not.

Fix root-project#7223.
hageboeck added a commit to hageboeck/root that referenced this issue Mar 4, 2021
To facilitate the creation of RooFit datasets from RDataFrame, an
ActionHelper is added to RooFit.
It lives in its own micro library, since it depends on RDataFrame, which
RooFit does not.

Fix root-project#7223.

Co-authored by Enrico Guiraud.
hageboeck added a commit to hageboeck/root that referenced this issue Mar 4, 2021
To facilitate the creation of RooFit datasets from RDataFrame, an
ActionHelper is added to RooFit.
It lives in its own micro library, since it depends on RDataFrame, which
RooFit does not.

Fix root-project#7223.

Co-authored by Enrico Guiraud.
@hageboeck
Copy link
Member Author

Reopening, because weights should be tested (and supported). What's needed:

  • Creating and filling bare dataset / datahist
  • A way to select the a weight column in RDataFrame, and tell the RooDataHist/RooDataSet instances about what's the weight.
  • Passing of the weight in the add call.
  • Test of weighted filling.

@hageboeck hageboeck reopened this Mar 5, 2021
nicknagi pushed a commit to nicknagi/root that referenced this issue Mar 30, 2021
To facilitate the creation of RooFit datasets from RDataFrame, an
ActionHelper is added to RooFit.
It lives in its own micro library, since it depends on RDataFrame, which
RooFit does not.

Fix root-project#7223.

Co-authored by Enrico Guiraud.
guitargeek added a commit to guitargeek/root that referenced this issue Jul 23, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes root-project#7223.
guitargeek added a commit to guitargeek/root that referenced this issue Jul 23, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes root-project#7223.
guitargeek added a commit to guitargeek/root that referenced this issue Jul 23, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes root-project#7223.
guitargeek added a commit that referenced this issue Jul 23, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes #7223.
guitargeek added a commit that referenced this issue Jul 23, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes #7223.
silverweed pushed a commit to silverweed/root that referenced this issue Aug 19, 2024
Support weighted filling from RDF to RooFit in RooAbsDataHelper and also
implement a test for it.

Closes root-project#7223.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants