I am writing a PyROOT script to create a histogram showing the trigger rate per run.

Since I only have a finite number of runs & they are non-consecutive, I would like the bins in the histogram to exactly correspond to the run numbers. As I understand it, I should be able to do this by creating a histogram using this constructor:

Unfortunately, when I pass the construtor a Python array for the parameter “xbins”, I get the following errors:

[quote]Error in TAxis::TAxis::Set: bins must be in increasing order

Error in TAxis::TAxis::Set: bins must be in increasing order

TCanvas::MakeDefCanvas: created default TCanvas with name c1

Error in TCanvas::Range: illegal world coordinates range: x1=167472.001386, y1=-0.131250, x2=-18608.001386, y2=1.181250

Error in TCanvas::RangeAxis: illegal axis coordinates range: xmin=148864.000000, ymin=0.000000, xmax=0.000000, ymax=1.050000

Error in TGraphPainter::PaintGraphHist: X must be in increasing order[/quote]

What am I doing wrong? How does one correctly pass the xbins parameter from a Python script to ROOT?

Below is a simpler version of my script (with many fewer runs), which I used to produce the exact errors above.

[code]#! /usr/bin/env python

import sys

from ROOT import *

from array import *

gSystem.Load(“libStoppedHSCPAnalysis”)

# Open root file, get TTree

infileName = "hltanalysis.root"

infile = TFile(infileName)

tree = infile.Get(“stoppedHSCPTree/StoppedHSCPTree”)

# Create histogram of trigger rate vs. run#

runArray = array(‘d’,[148864, 149291, 146436, 148822, 149063])

histogram = TH1F(“hist”, “HLT Rate”, len(runArray), runArray)

# Set bin labels to match run numbers

histogram.SetBit(TH1.kCanRebin);

for i in xrange(1,len(runArray)):

histogram.GetXaxis().SetBinLabel(i,str(runArray[i]))

# Draw Histogram

tree.Draw(“events.run>>hist”)

[/code]