compute_weights is a C++ function where I will read the muon eta and pt values (potentially more than one per event, but it’s irrelevant here) and a 2D histogram. How can I do this?
Hi @ceballos ,
and welcome to the ROOT forum.
is histo2D a variable defined outside of RDF? If so, you need a lambda that captures it (or equivalentely a functor class that has it as a data member):
yes, histo2D indeed a variable member outside RDF. I’ve tried to use the struct, and I think it’s “almost” working. I am trying to use pyroot. I have a C++ external struct as you write, but then the Define doesn’t work well.
I am not allowed to write:
df.Define(“weights”, ROOT.WeightsComputer(&histo2D), {“mu_pt”, “mu_eta”})
I tried (without &)
df.Define(“weights”, ROOT.WeightsComputer(histo2D), {“mu_pt”, “mu_eta”})
But then, it says:
Error sample: Template method resolution failed:
TypeError: takes at most 2 arguments (3 given)
Failed to instantiate “Define(std::string,WeightsComputer&,set)”
Failed to instantiate “Define(std::string,WeightsComputer*,set)”
Failed to instantiate “Define(std::string,WeightsComputer,set)”
Not sure what the problem is, maybe the curly braces instead of the parens for the last argument of Define. This works (at least with the master branch):
thanks a lot for your help! It works now. It seems the issue was that I was using {“pt”, “eta”} in Define, while it should be (“pt”, “eta”). After making this change, I am able to get the proper information from the histogram in the function.