163 def histogram(self, var, bins, when=NTupleProc(), flatten_runs=
False, flatten_cryo=
False, maxfile=
None, nproc=1):
165 nproc = multiprocessing.cpu_count()
167 if not isinstance(var, list):
170 if not isinstance(when, list):
177 thisglob = thisglob[:maxfile]
179 globdata = [(f, self.
branches, var, when, bins)
for f
in thisglob]
181 with Pool(processes=nproc)
as pool:
182 for hists
in tqdm(pool.imap_unordered(_process, globdata), total=len(globdata), unit=
"file", delay=5):
183 for cname
in hists.keys():
184 for runname
in hists[cname].keys():
185 for varname
in hists[cname][runname].keys():
186 for whenname
in hists[cname][runname][varname].keys():
189 ret[cname][runname][varname][whenname] = hists[cname][runname][varname][whenname]
191 ret[cname][runname][varname][whenname] = self.
_hadd(hist, hists[cname][runname][varname][whenname])
196 for runname
in ret[
"E"].keys():
197 flatret_cryo[runname] = {}
198 for valname
in ret[
"E"][runname].keys():
199 flatret_cryo[runname][valname] = {}
200 for whenname
in ret[
"E"][runname][valname].keys():
201 flatret_cryo[runname][valname][whenname] = self.
_hadd(ret[
"E"][runname][valname][whenname], ret[
"W"][runname][valname][whenname])
206 flatret_run[
"E"] = {}
207 flatret_run[
"W"] = {}
210 histlist = [ret]
if flatten_cryo
else [ret[
"E"], ret[
"W"]]
211 makeflatlist = [flatret_run]
if flatten_cryo
else [flatret_run[
"E"], flatret_run[
"W"]]
213 for hists, makeflat
in zip(histlist, makeflatlist):
214 run0 =
list(hists.keys())[0]
216 for valname
in hists[run0].keys():
217 makeflat[valname] = {}
218 for whenname
in hists[run0][valname].keys():
219 makeflat[valname][whenname] = self.
_hadd(*[hists[runname][valname][whenname]
for runname
in hists.keys()])
224 if len(when) == 1
and not when[0]:
225 if flatten_runs
and flatten_cryo:
226 for varname
in ret.keys():
227 ret[varname] = ret[varname][
"None"]
229 for cname
in ret.keys():
230 for varname
in ret[cname].keys():
231 ret[cname][varname] = ret[cname][varname][
"None"]
233 for runname
in ret.keys():
234 for varname
in ret[runname].keys():
235 ret[runname][varname] = ret[runname][varname][
"None"]
237 for cname
in ret.keys():
238 for runname
in ret[cname].keys():
239 for varname
in ret[cname][runname].keys():
240 ret[cname][runname][varname] = ret[cname][runname][varname][
"None"]