2 from array
import array
7 precision =
max(
int(-math.log10(err)), 0)+1
8 form =
"{0:.%if} #pm {1:.%if}" % (precision, precision)
9 return form.format(val, err)
13 rows, columns = os.popen(
'stty size',
'r').read().split() 14 maxw = max(map(len,mylist)) 15 ncols = int(columns)/(maxw+1) 19 print word.ljust(maxw),
" ",
28 histo.GetXaxis().CenterTitle()
29 histo.GetYaxis().CenterTitle()
30 histo.GetZaxis().CenterTitle()
34 prims =
list(c1.GetListOfPrimitives())
35 return filter(
lambda x: x.InheritsFrom(
"TH1"), prims)
38 def VerticalRange(hists, xrange=(0,0), ratio=
False, forceOne=
True, ignoreError=
False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05, verbose=0, log=
False):
41 maxbin = hists[0].GetNbinsX()
43 minbin = hists[0].FindBin(xrange[0])
44 maxbin = hists[0].FindBin(xrange[1])
49 if verbose:
print "Running VerticalRange between", minbin, maxbin,
"for", len(hists),
"histograms" 52 for b
in range(minbin, maxbin+1):
53 denom = hist.GetBinContent(b)
54 if denom == 0: denom = 0.00001
55 errratio =
abs(hist.GetBinError(b) / denom)
58 lowval = hist.GetBinContent(b)
59 highval = hist.GetBinContent(b)
61 lowval = hist.GetBinContent(b) - hist.GetBinError(b)
62 highval = hist.GetBinContent(b) + hist.GetBinError(b)
65 if (errratio < maxerr)
or ignoreError:
66 if lowval < min
and not (hist.GetBinContent(b) == 0
and (ratio
or log) ):
68 if verbose:
print " ",hist.GetName(),
":",
"new min", min
71 if verbose:
print " ",hist.GetName(),
":",
"new max", max
77 adjust = (max - min)*buffer/2.
83 adjust = (max - min)*buffer/2.
101 if verbose:
print "Final Min = %f, Max = %f" %(min, max)
112 mean = hist.GetMean()
114 low =
min(low, mean-2*rms)
115 high =
max(high, mean+2*rms)
117 for m
in mustinclude:
122 adjust = (high-low)*0.05
127 hist.GetXaxis().SetRangeUser(low,high)
136 for bin
in range(1, h1.GetNbinsX()+1):
137 sum1 += h1.GetBinContent(bin)
138 sum2 += h2.GetBinContent(bin)
139 ew1 = h1.GetBinError(bin)
140 ew2 = h2.GetBinError(bin)
147 chi2 = delta*delta / sigmasq
148 prob = TMath.Prob(chi2, 1)
153 from ROOT
import TColor
168 for i
in range(nsteps):
172 color = TColor.GetColor(r, g, b)
174 gradient.append(color)
180 for xb
in range(1,hist.GetNbinsX()):
181 x1 = hist.GetXaxis().GetBinLowEdge(xb)
182 y1 = hist.GetBinContent(xb)
183 x2 = hist.GetXaxis().GetBinLowEdge(xb+1)
184 y2 = hist.GetBinContent(xb+1)
185 x3 = hist.GetXaxis().GetBinLowEdge(xb+2)
186 lowleft = (y1 < value
and y2 > value)
187 lowright = (y1 > value
and y2 < value)
189 if lowleft
or lowright:
191 intersections += [
Interpolate(x1, y1, x2, y2, value) ]
193 intersections += [ x3 ]
195 intersections += [ x2 ]
203 xstp = (xmax - xmin)/(nsteps - 1)
205 for xi
in range(nsteps-1):
206 x1 = xmin + (xi+0)*xstp
207 x2 = xmin + (xi+1)*xstp
210 lowleft = (y1 < value
and y2 > value)
211 lowright = (y1 > value
and y2 < value)
213 if lowleft
or lowright:
214 intersections += [
Interpolate(x1, y1, x2, y2, value) ]
220 return x1 + (yvalue-y1)/m
224 # Very handy, but you need to install the ProgressBar package 225 def pbloop(iterable, name = "Entries"): 226 widgets = [ name+': ',pb.Value(), '/', pb.Total(), ' ', pb.Percentage(), ' ', 227 pb.Bar(marker='=',left='[',right=']'), 229 pbar = pb.ProgressBar(widgets=widgets, maxval=len(iterable), term_width=100) 231 for i, val in enumerate(iterable): 241 width = h.GetBinWidth(1)
243 for i
in range(1, h.GetNbinsX()+1):
244 wi = h.GetBinWidth(i)
246 c = h.GetBinContent(i)
248 h.SetBinContent(i, c/w)
249 h.SetBinError(i, e/w)
258 bins = [ x*(bmax-bmin)/(nbins - 1.) + bmin
for x
in range(nbins) ]
260 bins = map(
lambda x: 10.**x, bins)
261 return array(
'd',bins)
268 ldiv = TLine(x, c1.GetUymin(), x, c1.GetUymax())
277 ldiv = TLine(c1.GetUxmin(), val, c1.GetUxmax(), val)
284 return sum(lst)/len(lst)
288 return sqrt(
sum(map(
lambda x: (x-m)**2, lst)) / (len(lst)-1.) )
291 return sqrt(
sum(map(
lambda x: (x)**2, lst)) / len(lst) )
295 axis = hist.GetXaxis()
296 axisother = hist.GetYaxis()
298 prof = TH1D(hist.GetName()+
"_profX", hist.GetTitle(), axis.GetNbins(), axis.GetBinLowEdge(1), axis.GetBinLowEdge(axis.GetNbins()+1))
299 prof.SetXTitle(axis.GetTitle())
301 for nb
in range(1, axis.GetNbins()+1):
303 for nbo
in range(1, axisother.GetNbins()+1):
304 val =
min(val, hist.GetBinContent(nb, nbo))
305 prof.SetBinContent(nb, val)
311 axis = hist.GetYaxis()
312 axisother = hist.GetXaxis()
314 prof = TH1D(hist.GetName()+
"_profX", hist.GetTitle(), axis.GetNbins(), axis.GetBinLowEdge(1), axis.GetBinLowEdge(axis.GetNbins()+1))
315 prof.SetXTitle(axis.GetTitle())
317 for nb
in range(1, axis.GetNbins()+1):
319 for nbo
in range(1, axisother.GetNbins()+1):
320 val =
min(val, hist.GetBinContent(nbo, nb))
321 prof.SetBinContent(nb, val)
def HorizontalRange(hists, mustinclude=[])
Module that kips a configurable number of events between each that it allows through. Note that this module really skips (N-1) events, it uses a simple modular division as its critera. This module will cut down the data sample to 1/N of its original size.
def MakeGradient(nsteps, start, end)
def MakeBins(bmin, bmax, nbins, log=False)
def Interpolate(x1, y1, x2, y2, yvalue)
def BinWidthNormalize(h, width=-1)
static float min(const float a, const float b, const float c)
def VerticalRange(hists, xrange=(0, 0), ratio=False, forceOne=True, ignoreError=False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05, verbose=0, log=False)
def gIntersections(graph, value, xrng, nsteps=1000)
def Intersections(hist, value, interp=False)
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)