Dear ROOT developers,
I would like to use the brilliant new RDataFrames (thanks for that!) for analyzing data stored in TTrees, but I am having a small issue creating TProfiles using a custom (i.e. unequally spaced)
binning for the X variable.
Here’s some dummy code that illustrates the problem: (using PyROOT for simplicity)
import ROOT
from array import array
# create a RDataFrame to read out the TTree
df = ROOT.ROOT.RDataFrame("MyTree", "my_tree.root")
# use custom binning for 'x' variable
x_bin_edges = (50, 100, 200, 450, 4000)
profile_model = ROOT.RDF.TProfile1DModel(
"myProfile", "myProfile", len(x_bin_edges)-1, array('f', x_bin_edges), "")
# create profile of TTree branch 'varY' in bins of 'varX'
profile = df.Profile1D(profile_model, "varX", "varY");
# write to file
output_file = ROOT.TFile("my_output.root", "RECREATE")
output_file.cd()
profile.Write()
output_file.Close()
The above, unfortunately, completely ignores the custom binning and results in a TProfile with 128 equally spaced bins from 0 to 64, which seem to be the default values…
I had a look at the ROOT code on master
, and it looks like this should be supported by the TProfile1DModel
, but this isn’t being taken into consideration when actually creating the Profile (i.e. in TProfile1DModel::GetProfile()
):
In contrast, the TH1DModel
code seems to handle this correctly:
Shouldn’t TProfile1DModel::GetProfile()
also check for fBinXEdges
and do something like:
auto prof = std::make_shared<::TProfile>(fName, fTitle, fNbinsX, fBinXEdges.data(), fOption);
Or am I maybe missing something? I can do without custom binning for Profiles at the moment, but it would be great to get this feature to work.
Cheers!
ROOT Version: 6.14/05
Platform: x86_64-slc6
Compiler: gcc62