1 |
// For histograms plotting discrete numbers (nJets, nHits, etc.), it makes
|
2 |
// more sense to have discrete bin labels rather than letting ROOT set up
|
3 |
// an axis with intermediate values, tick marks, etc.
|
4 |
|
5 |
// This script will set integers as the bin labels, assigning startingValue
|
6 |
// to the first bin (which will usually be either 0 or 1).
|
7 |
|
8 |
void setIntegerBinLabels( TH1F* h, int startingValue = 0 )
|
9 |
{
|
10 |
// Draw with graphics off to make sure X axis exists
|
11 |
h->Draw("goff");
|
12 |
int nBins = h->GetNbinsX();
|
13 |
for ( int i = 0; i < nBins; i++ )
|
14 |
h->GetXaxis()->SetBinLabel( i + 1, Form( "%i", i + startingValue ) );
|
15 |
}
|