1 from __future__
import division
2 from __future__
import print_function
3 from builtins
import map
4 from builtins
import range
6 from array
import array
8 import progressbar
as pb
11 precision =
max(
int(-math.log10(err)), 0)+1
12 form =
"{0:.%if} #pm {1:.%if}" % (precision, precision)
13 return form.format(val, err)
17 rows, columns = os.popen(
'stty size',
'r').read().split() 18 maxw = max(list(map(len,mylist))) 19 ncols = int(columns)//(maxw+1) 23 print(word.ljust(maxw),
" ", end=
' ')
32 prims = list(c1.GetListOfPrimitives())
33 return [x
for x
in prims
if x.InheritsFrom(
"TH1")]
36 def VerticalRange(hists, xrange=(0,0), ratio=
False, forceOne=
True, ignoreError=
False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05):
39 maxbin = hists[0].GetNbinsX()
41 minbin = hists[0].
FindBin(xrange[0])
42 maxbin = hists[0].
FindBin(xrange[1])
48 for b
in range(minbin, maxbin+1):
49 denom = hist.GetBinContent(b)
50 if denom == 0: denom = 0.00001
51 errratio =
abs(hist.GetBinError(b) / denom)
54 lowval = hist.GetBinContent(b)
55 highval = hist.GetBinContent(b)
57 lowval = hist.GetBinContent(b) - hist.GetBinError(b)
58 highval = hist.GetBinContent(b) + hist.GetBinError(b)
62 if (errratio < maxerr)
or ignoreError:
63 if lowval < min
and not (hist.GetBinContent(b) == 0
and ratio):
72 adjust = (max - min)*buffer/2.
100 low =
min(low, mean-2*rms)
101 high =
max(high, mean+2*rms)
103 for m
in mustinclude:
108 adjust = (high-low)*0.05
113 hist.GetXaxis().SetRangeUser(low,high)
122 for bin
in range(1, h1.GetNbinsX()+1):
123 sum1 += h1.GetBinContent(bin)
124 sum2 += h2.GetBinContent(bin)
125 ew1 = h1.GetBinError(bin)
126 ew2 = h2.GetBinError(bin)
133 chi2 = delta*delta / sigmasq
134 prob = TMath.Prob(chi2, 1)
139 from ROOT
import TColor
154 for i
in range(nsteps):
158 color = TColor.GetColor(r, g, b)
160 gradient.append(color)
166 for xb
in range(1,hist.GetNbinsX()):
167 x1 = hist.GetXaxis().GetBinLowEdge(xb)
168 y1 = hist.GetBinContent(xb)
169 x2 = hist.GetXaxis().GetBinLowEdge(xb+1)
170 y2 = hist.GetBinContent(xb+1)
171 x3 = hist.GetXaxis().GetBinLowEdge(xb+2)
172 lowleft = (y1 < value
and y2 > value)
173 lowright = (y1 > value
and y2 < value)
175 if lowleft
or lowright:
177 intersections += [
Interpolate(x1, y1, x2, y2, value) ]
179 intersections += [ x3 ]
181 intersections += [ x2 ]
189 xstp = (xmax - xmin)//(nsteps - 1)
191 for xi
in range(nsteps-1):
192 x1 = xmin + (xi+0)*xstp
193 x2 = xmin + (xi+1)*xstp
196 lowleft = (y1 < value
and y2 > value)
197 lowright = (y1 > value
and y2 < value)
199 if lowleft
or lowright:
200 intersections += [
Interpolate(x1, y1, x2, y2, value) ]
206 return x1 + (yvalue-y1)/m
210 widgets = [ name+
': ',pb.Value(),
'/', pb.Total(),
' ', pb.Percentage(),
' ',
211 pb.Bar(marker=
'=',left=
'[',right=
']'),
213 pbar = pb.ProgressBar(widgets=widgets, maxval=len(iterable), term_width=100)
224 width = h.GetBinWidth(1)
226 for i
in range(1, h.GetNbinsX()+1):
227 wi = h.GetBinWidth(i)
229 c = h.GetBinContent(i)
231 h.SetBinContent(i, c/w)
232 h.SetBinError(i, e/w)
241 bins = [ x*(bmax-bmin)/(nbins - 1.) + bmin
for x
in range(nbins) ]
243 bins = [10.**x
for x
in bins]
244 return array(
'd',bins)
251 ldiv = TLine(x, c1.GetUymin(), x, c1.GetUymax())
260 ldiv = TLine(c1.GetUxmin(), val, c1.GetUxmax(), val)
267 return sum(lst)/len(lst)
271 return sqrt( sum([(x-m)**2
for x
in lst]) / (len(lst)-1.) )
274 return sqrt( sum([(x)**2
for x
in lst]) / len(lst) )
278 axis = hist.GetXaxis()
279 axisother = hist.GetYaxis()
281 prof = TH1D(hist.GetName()+
"_profX", hist.GetTitle(), axis.GetNbins(), axis.GetBinLowEdge(1), axis.GetBinLowEdge(axis.GetNbins()+1))
282 prof.SetXTitle(axis.GetTitle())
284 for nb
in range(1, axis.GetNbins()+1):
286 for nbo
in range(1, axisother.GetNbins()+1):
287 val =
min(val, hist.GetBinContent(nb, nbo))
288 prof.SetBinContent(nb, val)
294 axis = hist.GetYaxis()
295 axisother = hist.GetXaxis()
297 prof = TH1D(hist.GetName()+
"_profX", hist.GetTitle(), axis.GetNbins(), axis.GetBinLowEdge(1), axis.GetBinLowEdge(axis.GetNbins()+1))
298 prof.SetXTitle(axis.GetTitle())
300 for nb
in range(1, axis.GetNbins()+1):
302 for nbo
in range(1, axisother.GetNbins()+1):
303 val =
min(val, hist.GetBinContent(nbo, nb))
304 prof.SetBinContent(nb, val)
int FindBin(double value, std::vector< double > binning)
def HorizontalRange(hists, mustinclude=[])
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def MakeGradient(nsteps, start, end)
def VerticalRange(hists, xrange=(0, 0), ratio=False, forceOne=True, ignoreError=False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05)
def MakeBins(bmin, bmax, nbins, log=False)
def Interpolate(x1, y1, x2, y2, yvalue)
static int max(int a, int b)
def BinWidthNormalize(h, width=-1)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
def gIntersections(graph, value, xrng, nsteps=1000)
def Intersections(hist, value, interp=False)
def pbloop(iterable, name="Entries")