Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit b2dcab4

Browse files
committed
also the add methods
1 parent 4eaeb04 commit b2dcab4

File tree

2 files changed

+0
-165
lines changed

2 files changed

+0
-165
lines changed

uproot_methods/classes/TH1.py

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -140,76 +140,6 @@ def index(self, data):
140140
elif not math.isnan(data):
141141
return int(math.floor(self._fXaxis._fNbins * (data - low) / (high - low))) + 1
142142

143-
def fill(self, datum):
144-
numbins = self._fXaxis._fNbins
145-
low = self._fXaxis._fXmin
146-
high = self._fXaxis._fXmax
147-
if datum < low:
148-
self[0] += 1
149-
elif datum >= high:
150-
self[-1] += 1
151-
else:
152-
self[int(math.floor(numbins * (datum - low) / (high - low))) + 1] += 1
153-
154-
def fillw(self, datum, weight):
155-
numbins = self._fXaxis._fNbins
156-
low = self._fXaxis._fXmin
157-
high = self._fXaxis._fXmax
158-
if datum < low:
159-
self[0] += weight
160-
elif datum >= high:
161-
self[-1] += weight
162-
else:
163-
self[int(math.floor(numbins * (datum - low) / (high - low))) + 1] += weight
164-
165-
def fillall(self, data):
166-
numbins = self._fXaxis._fNbins
167-
low = self._fXaxis._fXmin
168-
high = self._fXaxis._fXmax
169-
170-
if not isinstance(data, numpy.ndarray):
171-
data = numpy.array(data)
172-
173-
freq, edges = numpy.histogram(data, bins=numbins, range=(low, high), density=False)
174-
for i, x in enumerate(freq):
175-
self[i + 1] += x
176-
177-
self[0] += (data < low).sum()
178-
self[-1] += (data >= high).sum()
179-
180-
def fillallw(self, data, weights):
181-
numbins = self._fXaxis._fNbins
182-
low = self._fXaxis._fXmin
183-
high = self._fXaxis._fXmax
184-
185-
if not isinstance(data, numpy.ndarray):
186-
data = numpy.array(data)
187-
188-
if isinstance(weights, numbers.Real):
189-
weights = numpy.full(data.shape, weights)
190-
191-
freq, edges = numpy.histogram(data, bins=numbins, range=(low, high), weights=weights, density=False)
192-
for i, x in enumerate(freq):
193-
self[i + 1] += x
194-
195-
self[0] += weights[data < low].sum()
196-
self[-1] += weights[data >= high].sum()
197-
198-
def __add__(self, other):
199-
if not isinstance(other, TH1Methods) or self.numbins != other.numbins or self.low != other.low or self.high != other.high:
200-
raise TypeError("TH1 histograms can only be combined with other TH1 histograms with the same binning")
201-
return hist(self.numbins, self.low, self.high, name=(self.name if self.name is not None else other.name), title=(self.title if self.title is not None else other.title), allvalues=(numpy.array(self) + numpy.array(other)))
202-
203-
def __radd__(self, other):
204-
return self.__add__(other)
205-
206-
def __iadd__(self, other):
207-
if not isinstance(other, TH1Methods) or self.numbins != other.numbins or self.low != other.low or self.high != other.high:
208-
raise TypeError("TH1 histograms can only be combined with other TH1 histograms with the same binning")
209-
for i in range(len(self)):
210-
self[i] = other[i]
211-
return self
212-
213143
@property
214144
def xlabels(self):
215145
if self._fXaxis._fLabels is None:

uproot_methods/classes/TH2.py

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -199,101 +199,6 @@ def xindex(self, data):
199199
def yindex(self, data):
200200
return self.index(data, "y")
201201

202-
def fill(self, datumx, datumy):
203-
self.fillw(datumx,datumy, 1.0)
204-
205-
def fillw(self, datumx, datumy, weight):
206-
xnumbins = self.xnumbins
207-
xlow = self.xlow
208-
xhigh = self.xhigh
209-
ynumbins = self.ynumbins
210-
ylow = self.ylow
211-
yhigh = self.yhigh
212-
213-
binx = self.index(datumx, "x") # get the x bin
214-
biny = self.index(datumy, "y") # get the y bin
215-
216-
# translate biny,binx into index for self[index]
217-
bin = biny*(xnumbins + 2) + binx
218-
self[bin] += weight
219-
220-
def fillall(self, datax, datay):
221-
self.fillallw(datax, datay, weights=None)
222-
223-
def fillallw(self, datax, datay, weights):
224-
xbins = self._fXaxis._fXbins
225-
xlow = self.xlow
226-
xhigh = self.xhigh
227-
ybins = self._fYaxis._fXbins
228-
ylow = self.ylow
229-
yhigh = self.yhigh
230-
231-
if not xbins: xbins = self.xnumbins
232-
if not ybins: ybins = self.ynumbins
233-
234-
if not isinstance(datax, numpy.ndarray):
235-
datax = numpy.array(datax)
236-
if not isinstance(datay, numpy.ndarray):
237-
datay = numpy.array(datay)
238-
239-
if isinstance(weights, numbers.Real):
240-
weights = numpy.full(datax.shape, weights)
241-
242-
freq, xedges, yedges = numpy.histogram2d(datax,
243-
datay,
244-
bins=[xbins, ybins],
245-
range=[[xlow, xhigh], [ylow, yhigh]],
246-
weights=weights,
247-
normed=False)
248-
freq = freq.flatten().tolist()
249-
for i, x in enumerate(freq):
250-
self[i+1] += x
251-
252-
# get all values for underflow
253-
data_xlow = numpy.where(datax<xlow)
254-
data_ylow = numpy.where(datay<ylow)
255-
data_low = numpy.unique(numpy.concatenate((data_xlow,data_ylow),0)) # indices for underflow
256-
257-
# get all values for overflow
258-
data_xhigh = numpy.where(datax>xhigh)
259-
data_yhigh = numpy.where(datax>yhigh)
260-
data_high = numpy.unique(numpy.concatenate((data_xhigh,data_yhigh),0)) # indices for overflow
261-
262-
# put all (unique) underflow and overflow values into an area
263-
data_uo = numpy.unique(numpy.concatenate((data_low,data_high),0)) # indices for under/overflow
264-
265-
if weights is None:
266-
for d in data_uo:
267-
binx = self.index(datax[d],'x') # get the x bin
268-
biny = self.index(datay[d],'y') # get the y bin
269-
270-
# translate biny,binx into index for self[index]
271-
bin = biny*(xnumbins+2) + binx
272-
self[bin] += 1
273-
else:
274-
for d in data_uo:
275-
binx = self.index(datax[d],'x') # get the x bin
276-
biny = self.index(datay[d],'y') # get the y bin
277-
278-
# translate biny,binx into index for self[index]
279-
bin = biny*(xnumbins+2) + binx
280-
self[bin] += weights[d]
281-
282-
def __add__(self, other):
283-
if not isinstance(other, TH2Methods) or self.numbins != other.numbins or self.low != other.low or self.high != other.high:
284-
raise TypeError("TH2 histograms can only be combined with other TH2 histograms with the same binning")
285-
return hist2d(self.xnumbins, self.xlow, self.xhigh, self.ynumbins, self.ylow, self.yhigh, name=(self.name if self.name is not None else other.name), title=(self.title if self.title is not None else other.title), allvalues=(numpy.array(self) + numpy.array(other)))
286-
287-
def __radd__(self, other):
288-
return self.__add__(other)
289-
290-
def __iadd__(self, other):
291-
if not isinstance(other, TH2Methods) or self.numbins != other.numbins or self.low != other.low or self.high != other.high:
292-
raise TypeError("TH2 histograms can only be combined with other TH2 histograms with the same binning")
293-
for i in range(len(self)):
294-
self[i] = other[i]
295-
return self
296-
297202
@property
298203
def ylabels(self):
299204
if self._fYaxis._fLabels is None:

0 commit comments

Comments
 (0)