How to show branch/ histogram entries from the command line

Is there any command line tool to get the entries that show in a branch’s histogram?

I want to get the ‘Entries’ shown when viewing the histogram for a branch in TBrowser, e.g. the number circled here for the `llll_tlv_pt` branch:

However, using:

root -l my.output.root

llllTree->GetBranch("llll_tlv_pt")->GetEntries()

Just prints 60,000 which is the total number of events from the dataset.

Is there any command line function to get the right entries value, or is my best bet to write a script to draw this histogram from the tree and then get the entries?

Kind regards, Matt

Hi Matt,

Thanks for the question. You can use RDataFrame:

ROOT::RDataFrame("llllTree", "my.output.root").Count().GetValue()

There is potential in using RDF, since it is powerful and can be used to do much more than counting events (see e.g. ROOT: ROOT::RDataFrame Class Reference)

Cheers,
D

1 Like

Hi,

an old-style one-liner:

root -b my.output.root -e "llllTree->Draw(\"llll_tlv_pt\"); TH1* myH {static_cast<TH1*>(gPad->GetPrimitive(\"htemp\"))}; myH->GetEntries()" -q
1 Like

Hi @yus ,

Thank you, this worked great! (The tree was actually inside another folder so I used

root -b test_ZdZd13TeV_20251007_02/my.output.root -e "Nominal->cd(); llllTree->Draw(\"llll_tlv_pt\"); TH1* myH {static_cast<TH1*>(gPad->GetPrimitive(\"htemp\"))}; myH->GetEntries()" -q

)

@Danilo the RDataFrame command printed 60,000 so it seems it’s getting total events too. However, I can see from the page that there are a lof of things I will use it for in future so thank you for the suggestion!

Cheers, Matt

Matt, sorry for the misunderstanding. I did not understand you wanted to count collection elements “inside” the events.
Just for completeness, here is what I should have suggested in the first place:

ROOT::RDataFrame("llllTree", "my.output.root").Histo1D("llll_tlv_pt")->GetEntries()

And as a one liner (thanks @yus for making TTreeDraw a oneliner!)

root -b -e "ROOT::RDataFrame(\"llllTree\", \"my.output.root\").Histo1D(\"llll_tlv_pt\")->GetEntries()"

Cheers,
D