8 logging.basicConfig(format=
'%(levelname)s:%(message)s', level=logging.INFO)
17 ROOT.gStyle.SetOptStat(0)
19 fin = ROOT.TFile.Open(sys.argv[1])
21 for key
in fin.GetListOfKeys():
22 if key.GetName().startswith(
'run_'):
23 runname = key.GetName()
27 logging.critical(
"Can't find run_* directory in input file %s", sys.argv[1])
30 z_m = fin.Get(
'%s/GLOBAL/DQTGlobalWZFinder/m_Z_Counter_mu' % runname)
33 logging.critical(
"Can't retrieve m_Z_Counter_mu")
36 lb_length = fin.Get(
'%s/GLOBAL/DQTGlobalWZFinder/m_lblength_lb' % runname)
37 lbmin, lbmax = lb_length.GetXaxis().GetXmin(), lb_length.GetXaxis().GetXmax()
39 logging.info(
'Starting livetime lookup ... (remove when we have a proper in-file implementation ...)')
40 livetime = ROOT.TProfile(
'livetime',
'Livetime',
int(lbmax-lbmin), lbmin, lbmax)
41 official_lum = ROOT.TProfile(
'official_lum',
'official integrated luminosity',
int(lbmax-lbmin), lbmin, lbmax)
42 official_lum_zero = ROOT.TProfile(
'official_lum_zero',
'official inst luminosity',
int(lbmax-lbmin), lbmin, lbmax)
43 from DQUtils
import fetch_iovs
44 from DQUtils.iov_arrangement
import inverse_lblb
48 iovs_acct =
fetch_iovs(
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LumiAccounting', lbtime.first.since, lbtime.last.until, tag=
'OflLumiAcct-13TeV-004')
53 if not lbmin < iov.LumiBlock < lbmax:
55 livetime.Fill(iov.LumiBlock, iov.LiveFraction)
57 official_lum_zero.Fill(iov.LumiBlock, iov.InstLumi/1e3)
58 official_lum.Fill(iov.LumiBlock, iov.InstLumi*iov.LBTime*iov.LiveFraction)
60 divisor = lb_length.Clone(
'divisor').ProjectionX()
61 px = livetime.ProjectionX()
64 nrebinned_bins = ((lbmax-lbmin) // BINWIDTH) + 1
66 lumiplot_m = ROOT.TH1F(
'lumiplot_m',
'Lumi, Z->#mu#mu (Run %s)' % runname[4:],
68 lbmin, lbmin+BINWIDTH*nrebinned_bins)
69 lumiplot_m.SetXTitle(
'LB')
70 xsec_m = ROOT.TH1F(
'xsec_m',
'eff #sigma, Z->#mu#mu',
int(nrebinned_bins),
71 lbmin, lbmin+BINWIDTH*nrebinned_bins)
72 lumiplot_raw_m = ROOT.TH1F(
'lumiplot_raw_m',
'Lumi, Z->#mu#mu, per LB',
76 num_m, lum, denom = 0, 0, 0
77 for ibin
in xrange(1,
int(lbmax-lbmin)+1):
79 lumiplot_raw_m.SetBinContent(ibin, z_m[ibin]/divisor[ibin]*ZPURITYFACTOR/ZATIMESC/ZXSEC)
80 lumiplot_raw_m.SetBinError(ibin, z_m[ibin]**.5/divisor[ibin]*ZPURITYFACTOR/ZATIMESC/ZXSEC)
82 denom += divisor[ibin]
83 lum += official_lum[ibin]
84 if (ibin % BINWIDTH) == 0:
85 ribin =
int(ibin // BINWIDTH)
87 lumiplot_m.SetBinContent(ribin, num_m/denom*ZPURITYFACTOR/ZATIMESC/ZXSEC)
88 lumiplot_m.SetBinError(ribin, num_m**.5/denom*ZPURITYFACTOR/ZATIMESC/ZXSEC)
90 xsec_m.SetBinContent(ribin, num_m/lum*ZPURITYFACTOR/ZATIMESC)
91 xsec_m.SetBinError(ribin, num_m**.5/lum*ZPURITYFACTOR/ZATIMESC)
92 num_m, lum, denom = 0, 0, 0
95 leg = ROOT.TLegend(0.6, 0.75, 0.89, 0.88)
97 official_lum_zero.SetLineColor(ROOT.kRed)
98 official_lum_zero.Draw(
'SAME,HIST')
99 leg.AddEntry(lumiplot_m,
'Z luminosity')
100 leg.AddEntry(official_lum_zero,
'ATLAS preferred lumi',
'L')