6from collections
import Counter
10_error_log: Counter[str] = Counter()
16 if fname[0:4] ==
"/eos":
17 eospath = ROOT.gSystem.Getenv(
"EOSSHIP") + fname
18 f = ROOT.TFile.Open(eospath)
21 for akey
in f.GetListOfKeys():
27 if len(wanted) > 0
and hname
not in wanted:
30 cln = obj.Class().GetName()
32 h[hname] = obj.Clone()
36 rc = h[hname].Add(obj)
38 print(
"Error when adding histogram ", hname)
40 h[hname] = obj.Clone()
41 if h[hname].GetSumw2N() == 0:
43 h[hname].SetDirectory(ROOT.gROOT)
44 if cln
in {
"TH2D",
"TH2F"}:
45 for p
in [
"_projx",
"_projy"]:
46 if isinstance(hname, str):
49 projname = str(hname) + p
51 h[projname] = h[hname].ProjectionX()
53 h[projname] = h[hname].ProjectionY()
54 h[projname].SetName(name + p)
55 h[projname].SetDirectory(ROOT.gROOT)
80 h[key] = ROOT.TH3D(rkey, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax)
82 h[key] = ROOT.TH2D(rkey, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax)
84 h[key] = ROOT.TH1D(rkey, title, nbinsx, xmin, xmax)
85 h[key].SetDirectory(ROOT.gROOT)
95 ymin: float |
None =
None,
96 ymax: float |
None =
None,
105 if ymin
is None or ymax
is None:
106 h[key] = ROOT.TProfile(rkey, title, nbinsx, xmin, xmax, option)
108 h[key] = ROOT.TProfile(rkey, title, nbinsx, xmin, xmax, ymin, ymax, option)
109 h[key].SetDirectory(ROOT.gROOT)
113 f = ROOT.TFile(fname,
"RECREATE")
115 if not hasattr(h[akey],
"Class"):
117 cln = h[akey].Class().GetName()
118 if "TH" in cln
or "TP" in cln:
120 if plusCanvas
and "TC" in cln:
125def bookCanvas(h, key=None, title: str =
"", nx: int = 900, ny: int = 600, cx: int = 1, cy: int = 1) ->
None:
130 h[key] = ROOT.TCanvas(key, title, nx, ny)
131 h[key].Divide(cx, cy)
140 print(
"Summary of recorded incidents:")
142 print(e,
":", _error_log[e])
146 if isinstance(x, str):
150 if isinstance(tx, (list, tuple)):
154 if _f[0:4] ==
"/eos":
155 f = ROOT.gSystem.Getenv(
"EOSSHIP") + _f
158 test = ROOT.TFile.Open(f)
160 print(
"ERROR FileCheck: input file", f,
" does not exist. Missing authentication?")
162 if test.FindObjectAny(
"cbmsim")
and fileType
in [
"tree",
""]:
164 elif fileType
in [
"ntuple",
""]:
167 print(
"ERROR FileCheck: Supplied list of files not all of tree or ntuple type")
170 print(
"ERROR FileCheck: File must be either a string or list of files")
None writeHists(h, fname, bool plusCanvas=False)
None readHists(h, fname, wanted=None)
None bookHist(h, key=None, str title="", int nbinsx=100, float xmin=0, float xmax=1, int nbinsy=0, float ymin=0, float ymax=1, int nbinsz=0, float zmin=0, float zmax=1)
None bookProf(h, key=None, str title="", int nbinsx=100, float xmin=0, float xmax=1, float|None ymin=None, float|None ymax=None, str option="")
None bookCanvas(h, key=None, str title="", int nx=900, int ny=600, int cx=1, int cy=1)