ATLAS Offline Software
compute_lumi.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
4 
5 import ROOT
6 import sys
7 import logging
8 logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
9 
10 BINWIDTH=5
11 
12 ZPURITYFACTOR=0.9935
13 ZXSEC=1.929
14 #ZATIMESC=0.2578
15 ZATIMESC=0.29632
16 
17 ROOT.gStyle.SetOptStat(0)
18 
19 fin = ROOT.TFile.Open(sys.argv[1])
20 runname = None
21 for key in fin.GetListOfKeys():
22  if key.GetName().startswith('run_'):
23  runname = key.GetName()
24  break
25 
26 if not runname:
27  logging.critical("Can't find run_* directory in input file %s", sys.argv[1])
28  sys.exit(1)
29 
30 z_m = fin.Get('%s/GLOBAL/DQTGlobalWZFinder/m_Z_Counter_mu' % runname)
31 
32 if not z_m:
33  logging.critical("Can't retrieve m_Z_Counter_mu")
34  sys.exit(1)
35 
36 lb_length = fin.Get('%s/GLOBAL/DQTGlobalWZFinder/m_lblength_lb' % runname)
37 lbmin, lbmax = lb_length.GetXaxis().GetXmin(), lb_length.GetXaxis().GetXmax()
38 
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
45 lblb = fetch_iovs("LBLB", runs=int(runname[4:]))
46 lbtime = inverse_lblb(lblb)
47 #print list(lbtime)
48 iovs_acct = fetch_iovs('COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LumiAccounting', lbtime.first.since, lbtime.last.until, tag='OflLumiAcct-13TeV-004')
49 #iovs_lum = fetch_iovs('COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/OflPrefLumi', lblb.first.since, lblb.last.until, tag='OflLumi-13TeV-003')
50 #print list(iovs_lum)
51 
52 for iov in iovs_acct:
53  if not lbmin < iov.LumiBlock < lbmax:
54  continue
55  livetime.Fill(iov.LumiBlock, iov.LiveFraction)
56  #print iov.InstLumi, iovs_lum[iov.LumiBlock-1].LBAvInstLumi
57  official_lum_zero.Fill(iov.LumiBlock, iov.InstLumi/1e3)
58  official_lum.Fill(iov.LumiBlock, iov.InstLumi*iov.LBTime*iov.LiveFraction)
59 
60 divisor = lb_length.Clone('divisor').ProjectionX()
61 px = livetime.ProjectionX()
62 divisor.Multiply(px)
63 
64 nrebinned_bins = ((lbmax-lbmin) // BINWIDTH) + 1
65 
66 lumiplot_m = ROOT.TH1F('lumiplot_m', 'Lumi, Z->#mu#mu (Run %s)' % runname[4:],
67  int(nrebinned_bins),
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',
73  int(lbmax-lbmin),
74  lbmin, lbmax)
75 
76 num_m, lum, denom = 0, 0, 0
77 for ibin in xrange(1, int(lbmax-lbmin)+1):
78  if divisor[ibin] > 0:
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)
81  num_m += z_m[ibin]
82  denom += divisor[ibin]
83  lum += official_lum[ibin]
84  if (ibin % BINWIDTH) == 0:
85  ribin = int(ibin // BINWIDTH)
86  if denom > 0:
87  lumiplot_m.SetBinContent(ribin, num_m/denom*ZPURITYFACTOR/ZATIMESC/ZXSEC)
88  lumiplot_m.SetBinError(ribin, num_m**.5/denom*ZPURITYFACTOR/ZATIMESC/ZXSEC)
89  if lum > 0:
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
93 
94 
95 leg = ROOT.TLegend(0.6, 0.75, 0.89, 0.88)
96 lumiplot_m.Draw()
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')
101 leg.SetBorderSize(0)
102 leg.Draw()
xrange
void xrange(TH1 *h, bool symmetric)
Definition: computils.cxx:515
python.iov_arrangement.inverse_lblb
def inverse_lblb(iovs)
Definition: iov_arrangement.py:34
python.db.fetch_iovs
def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="", what="all", max_records=-1, with_channel=True, loud=False, database=None, convert_time=False, named_channels=False, selection=None, runs=None, with_time=False, unicode_strings=False)
Definition: DQUtils/python/db.py:67
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24