124 """Add branches (scalars or arrays) of the current event."""
125 x = np.asarray(x, dtype=float)
128 w = np.broadcast_to(np.asarray(w, dtype=float), x.shape).ravel()
129 bins = self.
_bins(x.ravel())
130 t = np.bincount(bins, w, minlength=len(self.
_current))
133 self.
sum_w2 += np.bincount(bins, w * w, minlength=len(self.
_current))
241 """Write hadd-mergeable objects, identical to the C++ EventHistogram::Write."""
245 edges = np.ascontiguousarray(self.
edges)
248 def hist1(name, sums, sums2):
249 h = ROOT.TH1D(name, self.
title, nb, edges)
250 h.SetDirectory(ROOT.nullptr)
257 def hist2(name, title, values, *yaxis):
258 h = ROOT.TH2D(name, title, nb, edges, *yaxis)
259 h.SetDirectory(ROOT.nullptr)
268 if self.
sum_tt is not None:
269 objects.append(hist2(self.
name +
"_cov",
"sum over events of t_a t_b", self.
sum_tt, nb, edges))
270 if self.
boot is not None:
271 nrep = self.
boot.shape[1]
272 objects.append(hist2(self.
name +
"_boot",
"bootstrap replicas;;replica", self.
boot, nrep, 0.0, float(nrep)))
273 objects.append(ROOT.TParameter(
"Long64_t")(self.
name +
"_nevents", self.
n_events,
"+"))
275 directory.WriteTObject(obj, obj.GetName(),
"Overwrite")
279 """Restore an accumulator written by to_root() or the C++ class (also after hadd)."""
280 h = directory.Get(name)
281 naive = directory.Get(name +
"_naive")
282 nevents = directory.Get(name +
"_nevents")
283 if not h
or not naive
or not nevents:
284 raise KeyError(f
"EventHistogram {name} not found in {directory.GetName()}")
287 edges = [axis.GetBinLowEdge(i)
for i
in range(1, nb + 2)]
288 cov = directory.Get(name +
"_cov")
289 boot = directory.Get(name +
"_boot")
290 n_events = nevents.GetVal()
291 for obj
in (h, naive, cov, boot):
292 if obj
and obj.GetEntries() != n_events:
294 f
"EventHistogram {name}: {obj.GetName()} holds {obj.GetEntries()} events,"
295 f
" {nevents.GetName()} {n_events}; were files with different settings merged?"
297 self = cls(name, edges, title=h.GetTitle(), covariance=bool(cov), n_replicas=boot.GetNbinsY()
if boot
else 0)
300 if self.
sum_tt is not None:
302 if self.
boot is not None: