Using a predefined TH2D in RDataframe to compute new quantiy

Maybe this can be helpful
There are shorter and clever tricks than the one posted here, for example you can simply make a struct implementing a member being your 2D histo to read and one operator() implementation, or even better maybe and simple to use lambda capturing the histogram as argument

 auto reweight=[& inputHist]( double X, double y){
....
};
node = node.Define( "w", reweight,{ "col1","col2"})

( Personally I prefer to declare a functor class to do this since then I can compile and make dictionary for it and use in pyROOT for other cases I need it)

. The only thing to be careful is that you use only const methods on the TH2D object in the operator() implementation.
(E.g FindFixBin, GetBinContent, check out the doxygen if the methods you use are marked const for your Root version.

1 Like