This repository was archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhistogram.py
More file actions
86 lines (68 loc) · 2.44 KB
/
Copy pathhistogram.py
File metadata and controls
86 lines (68 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Histogram configuration objects
These histogram objects are passed to the HistogramPool to be
created for processors that they are grouped with.
"""
def uniform_binning( nbins , minedge , maxedge ) :
"""Create a list of bin edges uniformly separated
Parameters
----------
nbins : int
Number of bins
minedge : float
Lower edge of binning
maxedge : float
Upper edge of binning
"""
bin_width = float(maxedge-minedge)/float(nbins)
#range does not include upper limit, so we need to add an extra bin at end
return [ bin_width*ibin+minedge for ibin in range(nbins+1) ]
class histogram:
"""Object to hold parameters for a one-dimensional root histogram
This histogram object will be passed to the HistogramPool and created,
so that it is available to the processor who created it.
If the ybins member is empty, then the histogram is assumed to be a 1D
histogram.
Parameters
----------
name : str
pointer name of histogram (like you are defining a variable)
xlabel : str
title of x-axis that this histogram represents
xbins : list of floats
bin edges along x-axis
ylabel : str
title of y-axis that this histogram represents
ybins : list of floats
bin edges along y-axis
"""
def __init__(self, name, xlabel, xbins, ylabel='', ybins=[]) :
self.name = name
self.xlabel = xlabel
self.xbins = xbins
self.ylabel = ylabel
self.ybins = ybins
def __repr__(self):
"""Represent this object to the human user
Returns
-------
A string representation of the histogram displaying its properties.
"""
if len(self.ybins) > 0 :
return "Name: %s x Label: %s y Label: %s" % (self.name,
self.xlabel, self.ylabel)
else :
return "Name: %s x Label: %s" % (self.name,self.xlabel)
def __str__(self):
"""Stringify this object.
Helpful for printing it in python to make sure the passed variables are what you want.
Returns
-------
A string representation of the histogram displaying its properties.
Example
-------
This function allows you to do things like:
print(myHistogram)
or
"The histogram in my processor is %s" % ( myHistogram )
"""
return self.__repr__()