Custom binning with TProfile1DModel

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


Hi,

thanks for the report and the diagnosis: this is most useful to us!
I acknowledge the issue which will be fixed - I opened a ticket on our bug-tracker https://sft.its.cern.ch/jira/browse/ROOT-9476
I’ll notify also this thread once the issue is closed.

Best,
D

Hi again,

I opened a PR to fix this: https://github.com/root-project/root/pull/2666
Once we can verify that the fix is ok on all supported platforms, the change will be available in ROOT master and will be available in the ROOT 6.16 release.
One day after the change is made available in master, it will be backported to the 6.14 branch and will be available in release 6.14/06.

Best and thanks again for the report and fix suggestion,
Danilo

Hi,

if you want to try the fix out, it has been just merged.

Cheers,
D

Hi Danilo,

thank you for your prompt reply and the quick fix!
I’ve tried it out and the custom binning seems to work now.

Cheers,
Daniel

Hi Daniel,

Great! Thanks for confirming.
There are glitches with the profiles2d at the moment, the fix is coming.

Cheers,
D

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