def build(self): file = R.TFile(self.cfg.filename, 'READ') if file.IsZombie(): raise Exception('Can not read ROOT file ' + file.GetName()) print('Read input file {}:'.format(file.GetName())) normalize = self.cfg.get('normalize', False) for it in self.nidx.iterate(): if it.ndim() > 0: subst, = it.current_values() else: subst = '' hname = self.groups.format(subst, self.cfg.format) h = file.Get(hname) if not h: raise Exception('Can not read {hist} from {file}'.format( hist=hname, file=file.GetName())) print(' read{}: {}'.format(' ' + subst, hname), end=' ') edges = get_bin_edges_axis(h.GetXaxis()) data = get_buffer_hist1(h) data = N.ascontiguousarray(data, dtype='d') if isinstance(normalize, slice): print('[normalized]', end=' ') data = data / data[normalize].sum() elif normalize: print('[normalized]', end=' ') data = data / data.sum() else: print() xscale = self.cfg.get('xscale', None) yscale = self.cfg.get('yscale', None) if xscale is not None: print('[xscale]', end=' ') edges *= xscale if yscale is not None: print('[yscale]', end=' ') data *= yscale print() fmt = self.cfg.get('label', 'hist {name}\n{autoindex}') hist = Histogram(edges, data, labels=it.current_format(fmt, name=self.cfg.name)) self.set_output(self.cfg.name, it, hist.single()) self.context.objects[('hist', subst)] = hist file.Close()
def init_data(self): dtype_spower = [('e', 'd'), ('temp1', 'd'), ('temp2', 'd'), ('dedx', 'd')] self.stopping_power = N.loadtxt(self.cfg.stopping_power, dtype=dtype_spower) from mpl_tools.root2numpy import get_buffer_hist1, get_bin_edges_axis cfg = self.cfg.annihilation_electrons file = R.TFile(cfg.file, 'read') hist = file.Get(cfg.histogram) buf = get_buffer_hist1(hist).copy() buf *= cfg.scale edges = get_bin_edges_axis(hist.GetXaxis()) self.annihilation_electrons_p_input = buf self.annihilation_electrons_edges_input = edges self.annihilation_electrons_centers_input = 0.5 * (edges[1:] + edges[:-1]) file.Close()