ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RootMacros/setIntegerBinLabels.C
Revision: 1.1
Committed: Wed Mar 18 21:14:28 2009 UTC (16 years, 1 month ago) by klukas
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Give the x-axis bins integer labels; useful for nJets, nHits, etc.

File Contents

# Content
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 }