Fill and draw a bar chart from a categorical column with RDataFrame.
RDataFrame has no dedicated action for categorical/string columns, but the generic RDataFrame::Fill() action can fill any user-provided object that exposes Fill() and Merge() methods. This shows how to use it to build and draw a bar chart from a string column.
{
}
void Fill(
const std::string &s) { histo.
Fill(s.c_str(), 1.); }
void Merge(
const std::vector<AlphaNumHist *> &
others)
{
}
};
{
std::uniform_int_distribution<int>
distrib{0, 2};
const std::vector<std::string>
colours{
"RED",
"GREEN",
"BLUE"};
}
auto canvas = std::make_unique<TCanvas>("c");
{
writeData(
"tree",
"df041_alphanumericHistograms.root");
AlphaNumHist model(
"hColour",
"Entries by colour;Colour;Count");
auto result = df.Fill<std::string>(model, {
"colour"});
result->histo.LabelsDeflate(
"X");
result->histo.SetFillColor(45);
result->histo.DrawCopy(
"bar2");
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
1-D histogram with a double per channel (see TH1 documentation)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
virtual UInt_t SetCanExtend(UInt_t extendBitMask)
Make the histogram axes extendable / not extendable according to the bit mask returns the previous bi...
virtual Long64_t Merge(TCollection *list)
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
- Date
- July 2026
- Author
- Mehkaan Khan
Definition in file df041_alphanumericHistograms.C.