[tutorial] Add example filling a bar chart from a categorical column#22802
[tutorial] Add example filling a bar chart from a categorical column#22802MehkaanKhan wants to merge 4 commits into
Conversation
Histo1D only supports numeric columns; there was no way to fill a histogram from a string/categorical column (e.g. particle type, detector region labels) without manual workarounds. This adds a BarChart() lazy action that fills a label-binned, auto-extending TH1D from either std::string columns or classic C-style char[] tree branches (inferred as RVec<char> by RDataFrame). - ActionTags::BarChart + a dedicated BuildAction overload - BarChartHelper, since FillHelper<TH1D> cannot compile against either std::string or RVec<char> (no implicit conversion to the const char* Fill overload) - RInterface::BarChart(vName, name, title) - Test coverage in dataframe_histomodels.cxx (bin ordering/counts) and dataframe_simple.cxx (auto name/title derivation) Closes root-project#17057
|
Dear @MehkaanKhan , Thank you for opening this PR and for your effort in helping the ROOT project fix an existing issue! I have been looking at your changes and I believe that, while the overall implementation is not wrong, there is some fundamental design thinking to be done on the ROOT RDataFrame side. Considering that the new ROOT histograms are being integrated also in the RDataFrame API (e.g. see https://root.cern/doc/master/classROOT_1_1RDataFrame.html#a93f03fe55586502a608844d18c7334ce), including a new method in RInterface that returns a Bottom line, I think the implementation in this PR should not be merged as part of the RDataFrame API, and I think a good alternative would be to actually promote it to a public-facing tutorial, along the lines of https://root-forum.cern.ch/t/support-for-filling-histograms-with-alphanumeric-bins-in-rdataframe/48741/2 . If you don't find that a good alternative effort, I could also redirect you to another "good first issue" in RDataFrame that would be easier to maintain and support in the future #22794. Let me reinforce that without your proposal it wouldn't have been so clear what should be the right path forward for this feature request, so thanks again for your effort! |
This reverts commit 34ad3b3.
Per @vepadulano's review on root-project#22802, a new BarChart() RDataFrame method tied to TH1D would risk deprecation once ROOT's new histogram system (RCategoricalAxis in hist/histv7) gains plotting support and becomes the preferred way to handle alphanumeric bins. This tutorial instead shows the same result using RDataFrame's existing generic Fill() action with a small adapter class, requiring no core API changes. Verified against the same cernstaff.root/Nation dataset used in hist006_TH1_bar_charts.C: 15 bins, labels and counts match TTree::Draw("Nation","","hbar2").
|
@vepadulano Updated per your feedback. I reverted the BarChart() API changes and replaced them with a tutorial (df041_alphanumericHistograms.C) showing the same result via the existing Fill() action, no core changes needed. PR title/description updated to match. Ready whenever you have time to take a look. |
This Pull request:
Changes or fixes:
Updated per @vepadulano's review: this PR no longer adds a new
BarChart()RDataFrame method. That approach has been reverted (see commit history) since it would tie a new permanent API toTH1Dright as ROOT migrates to a new histogram system with a native categorical axis (RCategoricalAxisinhist/histv7).Instead, this adds a tutorial (
tutorials/analysis/dataframe/df041_alphanumericHistograms.C) showing how to fill and draw a bar chart from a categorical/string column using RDataFrame's existing genericFill()action with a small adapter class. No core API changes required.Verified against the same
cernstaff.root/Nationdataset used inhist006_TH1_bar_charts.C: 15 bins, labels and counts matchTTree::Draw("Nation","","hbar2").Checklist:
This PR fixes #17057