ATLAS Offline Software
dqt_zlumi_display_z_rate.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 
4 import ROOT
5 import sys, os
6 import array
7 import argparse
8 import time
9 
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',
13  default='')
14 parser.add_argument('--plotdir', type=str, help='Directory to dump plots',
15  default='plots')
16 args = parser.parse_args()
17 
18 # runnum = sys.argv[1].split('_')[0]
19 runnum = args.infile.split('_')[0]
20 # f = ROOT.TFile.Open(sys.argv[1], 'UPDATE')
21 f = ROOT.TFile.Open(os.path.join(args.indir, args.infile), 'UPDATE')
22 c1 = ROOT.TCanvas()
23 lumitree = f.lumitree
24 #get range
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()))
30 titlestr = ''
31 if min(fills)==max(fills):
32  titlestr += 'Fill %d' % min(fills)
33 if min(runs) == max(runs):
34  titlestr += ' Run %d' % min(runs)
35 
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())
40  gr.Draw("ap")
41  gr.GetHistogram().SetXTitle('LB')
42  gr.GetHistogram().SetYTitle('Fiducial Z yield/second')
43  gr.SetMarkerStyle(20)
44  gr.SetTitle('')
45  f.WriteTObject(gr, 'fid_z_rate')
46  c1.Update()
47  c1.Print(os.path.join(args.plotdir, '%s_fidyield.eps' % runnum))
48 
49 # dump CSV
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'
53 #timeformat = '%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])),
61  lumitree.GetV1()[i],
62  instlumi/1e3,
63  instlumi*livetime/1e3,
64  lumitree.GetV1()[i]*livetime
65  ),
66  file=csvout)
67 csvout.close()
68 
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()))
74  gr.Draw("ap")
75  gr.GetHistogram().SetXTitle('LB')
76  gr.GetHistogram().SetYTitle('Luminosity (x10^{33})')
77  gr.SetMarkerStyle(20)
78  gr.SetTitle(titlestr)
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)
87  gr2.Draw('same,l')
88  f.WriteTObject(gr2, 'official_lumi')
89  leg = ROOT.TLegend(0.65, 0.7, 0.89, 0.89)
90  leg.SetBorderSize(0)
91  leg.AddEntry(gr, 'Z luminosity', 'pl')
92  leg.AddEntry(gr2, 'Official', 'l')
93  leg.Draw()
94  c1.Update()
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)
100  c1.Clear()
101  gr3.SetMarkerStyle(20)
102  gr3.Draw('ap')
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')
108 
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:515
max
#define max(a, b)
Definition: cfImp.cxx:41
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
min
#define min(a, b)
Definition: cfImp.cxx:40
Trk::open
@ open
Definition: BinningType.h:40
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70