10 parser = argparse.ArgumentParser()
11 parser.add_argument(
'infile', type=str, help=
'input HIST file')
12 parser.add_argument(
'--indir', type=str, help=
'Directory with input file',
14 parser.add_argument(
'--plotdir', type=str, help=
'Directory to dump plots',
16 args = parser.parse_args()
19 runnum = args.infile.split(
'_')[0]
21 f = ROOT.TFile.Open(os.path.join(args.indir, args.infile),
'UPDATE')
25 runs=[0,1]; fills=[0,1]
26 lumitree.Draw(
"run:lhcfill",
"",
"goff")
27 if lumitree.GetSelectedRows() > 0:
28 runs =
list(lumitree.GetV1()[_]
for _
in xrange(lumitree.GetSelectedRows()))
29 fills =
list(lumitree.GetV2()[_]
for _
in xrange(lumitree.GetSelectedRows()))
32 titlestr +=
'Fill %d' %
min(fills)
34 titlestr +=
' Run %d' %
min(runs)
36 lumitree.Draw(
"zrate:lb+10:zratestat",
"",
"goff")
37 print(
'Selected rows', lumitree.GetSelectedRows())
38 if lumitree.GetSelectedRows() > 0:
39 gr = ROOT.TGraphErrors(lumitree.GetSelectedRows(), lumitree.GetV2(), lumitree.GetV1(), ROOT.nullptr, lumitree.GetV3())
41 gr.GetHistogram().SetXTitle(
'LB')
42 gr.GetHistogram().SetYTitle(
'Fiducial Z yield/second')
45 f.WriteTObject(gr,
'fid_z_rate')
47 c1.Print(os.path.join(args.plotdir,
'%s_fidyield.eps' % runnum))
50 csvout =
open(os.path.join(args.plotdir,
'%s_zrate.csv' % runnum),
'w')
51 lumitree.Draw(
"zrate:lbwhen[0]:lbwhen[1]:lhcfill:lblive:offlumi",
"",
"goff,para")
52 timeformat =
'%y/%m/%d %H:%M:%S'
54 for i
in xrange(lumitree.GetSelectedRows()):
55 zrate = lumitree.GetV1()[i]
56 instlumi = lumitree.GetVal(5)[i]
57 livetime = lumitree.GetVal(4)[i]
58 print(
'%d, %s, %s, %6f, %6f, %4f, %6f' % (lumitree.GetV4()[i],
59 time.strftime(timeformat, time.gmtime(lumitree.GetV2()[i])),
60 time.strftime(timeformat, time.gmtime(lumitree.GetV3()[i])),
63 instlumi*livetime/1e3,
64 lumitree.GetV1()[i]*livetime
69 lumitree.Draw(
"zlumi:lb+10:zlumistat",
"",
"goff")
70 if lumitree.GetSelectedRows() > 0:
71 gr = ROOT.TGraphErrors(lumitree.GetSelectedRows(), lumitree.GetV2(), lumitree.GetV1(), ROOT.nullptr, lumitree.GetV3())
72 zlumi =
list(lumitree.GetV1()[_]
for _
in xrange(lumitree.GetSelectedRows()));
73 zlumierr =
list(lumitree.GetV3()[_]
for _
in xrange(lumitree.GetSelectedRows()))
75 gr.GetHistogram().SetXTitle(
'LB')
76 gr.GetHistogram().SetYTitle(
'Luminosity (x10^{33})')
79 f.WriteTObject(gr,
'z_lumi')
80 lumitree.Draw(
"offlumi:lb+10",
"",
"goff")
81 gr2 = ROOT.TGraphErrors(lumitree.GetSelectedRows(), lumitree.GetV2(), lumitree.GetV1())
82 offlumi =
list(lumitree.GetV1()[_]
for _
in xrange(lumitree.GetSelectedRows()))
83 gr2.SetMarkerStyle(21)
84 gr2.SetMarkerSize(0.5)
85 gr2.SetMarkerColor(ROOT.kRed)
86 gr2.SetLineColor(ROOT.kRed)
88 f.WriteTObject(gr2,
'official_lumi')
89 leg = ROOT.TLegend(0.65, 0.7, 0.89, 0.89)
91 leg.AddEntry(gr,
'Z luminosity',
'pl')
92 leg.AddEntry(gr2,
'Official',
'l')
95 c1.Print(os.path.join(args.plotdir,
'%s_lumicomp.eps' % runnum))
96 f.WriteTObject(c1,
'lumicomp_canvas')
97 zlumirat = array.array(
'd', [_[0]/_[1]
for _
in zip(zlumi, offlumi)])
98 zlumiraterr = array.array(
'd', [_[0]/_[1]
for _
in zip(zlumierr, offlumi)])
99 gr3 = ROOT.TGraphErrors(lumitree.GetSelectedRows(), lumitree.GetV2(), zlumirat, ROOT.nullptr, zlumiraterr)
101 gr3.SetMarkerStyle(20)
103 gr3.SetTitle(titlestr)
104 gr3.GetHistogram().SetXTitle(
'LB')
105 gr3.GetHistogram().SetYTitle(
'Z Counting/Official Lumi')
106 c1.Print(os.path.join(args.plotdir,
'%s_lumicompratio.eps' % runnum))
107 f.WriteTObject(c1,
'lumicompratio_canvas')