Bar charts for integers as strings

Hello! I want to create a bar chart like in tutorial example hbars.C, but my branch values are integers (they are PDG codes of particles), and I want the entries of the branch (leaf) to just be enumerated along the Y axis like on the upper bar chart in the example. How do I do that?

See the function tree1r for reading the tree and filling a histogram; in your case, just create and fill a TH1I (an integer histogram, instead of the TH1F “hpx” in the example) with the data and plot it with the “hbar” option.

This just draws a histogram where the axis is plotted as a continuous range of numbers, but I want the numbers to just be enumerated along the axis (like PT, ZZ, GR and so on in the example), as the PDG codes range from 1-digit to 7-digit numbers with huge gaps between them. In principle I want to see how many of each particle (symbolized with its PDG code) appeared in the simulation I’m analyzing. Should I somehow convert those PDG codes to stirings?

You can manually “send” the data to bins 1 to n, and then use ChangeLabel or SetBinLabel for each bin to rename them as you want. See also ROOT: tutorials/tree/cernstaff.C File Reference or search the forum for more examples.

TH1 → Alphanumeric Bin Labels ;

${ROOTSYS}/tutorials/hist/hlabels1.C ;
${ROOTSYS}/tutorials/hist/hlabels2.C ;
${ROOTSYS}/tutorials/graphs/labels1.C ;
${ROOTSYS}/tutorials/graphs/labels2.C

Have found myself a way to do what I wanted with the help of these, thanks!

Ok so I guess I could just just use Fill(entry, weight) with weight set to 1. That solves it!