from __future__ import absolute_import from __future__ import division from __future__ import print_function from ratproc.base import Processor from rat import ratiter, ROOT class Hist(Processor): ''' Creates and draws a histogram of a certain quantity as the RAT job progresses. Requires specification of a ROOT-style selector string for the quantity. ''' def __init__(self, selector, xbin, xmin, xmax, title=None, interval=10, wait=False): Processor.__init__(self) self.selector = selector if title is None: title = selector self.count = 0 self.interval = interval self.canvas = ROOT.TCanvas('c' + ROOT.TUUID().AsString(), self.selector, 800, 600) self.hist = ROOT.TH1D('', title, xbin, xmin, xmax) self.hist.Draw() self.canvas.Update() self.wait = wait def dsevent(self, run, ds): self.count += 1 for v in ratiter(ds, self.selector): self.hist.Fill(v) if self.count % self.interval == 0: self.canvas.cd() self.hist.Draw() self.canvas.Update() return Processor.OK def finish(self): if self.wait: input('Press enter to close window')