7 parser = argparse.ArgumentParser()
8 parser.add_argument(
'recofile', type=str, help=
'File with per-LB yields')
9 parser.add_argument(
'efffile', type=str, help=
'File with efficiencies')
10 parser.add_argument(
'outfile', type=str, help=
'Output file')
11 parser.add_argument(
'--nlb', type=int, help=
'# of LBs to combine',
13 args = parser.parse_args()
15 recozfname = args.recofile
16 effzfname = args.efffile
17 outfname = args.outfile
21 ACCEPTANCE = 3.323224e-01
30 return 0.998758-0.000157214*mu
33 recozfile = ROOT.TFile.Open(recozfname)
34 effzfile = ROOT.TFile.Open(effzfname)
36 recoztree = recozfile.lumitree
37 effztree = effzfile.lumitree
41 for i
in xrange(recoztree.GetEntries()):
43 if not recoztree.pass_grl:
continue
45 if recoztree.lblive < 10 :
continue
46 effztree.Draw(
'alleff:alleffstat',
'run==%s&&lb==%s' % (recoztree.run, recoztree.lb),
'goff')
47 if effztree.GetSelectedRows() == 0:
48 print(
'Broken for run, lb %s %s' % (recoztree.run, recoztree.lb))
49 print(
'We THINK there are %d events here ...' % (recoztree.zraw))
51 lbzero = (recoztree.lb // LUMIBLOCKS)*LUMIBLOCKS
53 if (run, lbzero)
not in entrydict: entrydict[(run, lbzero)] = {
'zcount': 0.,
'zcounterrsq': 0.,
'livetime': 0.,
'lbwhen': [-1, -1],
'mu': 0.,
'offlumi': 0.,
'rolleff': 0.,
'rollefferrsq': 0.,
'lhcfill': recoztree.lhcfill}
54 thisdict = entrydict[(run, lbzero)]
58 thisdict[
'zcount'] += recoztree.zraw
59 thisdict[
'zcounterrsq'] += recoztree.zrawstat**2
60 effcywght = (effztree.GetV2()[0]*
correction(recoztree.mu))**2
61 thisdict[
'rolleff'] += effcy/effcywght
62 thisdict[
'rollefferrsq'] += 1/effcywght
63 loclivetime = recoztree.lblive
65 thisdict[
'livetime'] += loclivetime
66 thisdict[
'mu'] += recoztree.mu*loclivetime
67 thisdict[
'offlumi'] += recoztree.offlumi*loclivetime
68 if thisdict[
'lbwhen'][0] > recoztree.lbwhen[0]
or thisdict[
'lbwhen'][0] == -1:
69 thisdict[
'lbwhen'][0] = recoztree.lbwhen[0]
70 if thisdict[
'lbwhen'][1] < recoztree.lbwhen[1]
or thisdict[
'lbwhen'][1] == -1:
71 thisdict[
'lbwhen'][1] = recoztree.lbwhen[1]
73 from array
import array
75 fout = ROOT.TFile.Open(outfname,
'RECREATE')
85 o_alleffcorrstat =
array(
'f', [0.])
89 t = ROOT.TTree(
'lumitree',
'Luminosity tree' )
90 t.Branch(
'run', o_run,
'run/i')
91 t.Branch(
'lb', o_lb,
'lb/i')
92 t.Branch(
'lbwhen', o_lbwhen,
'lbwhen[2]/D')
93 t.Branch(
'zrate', o_zrate,
'zrate/F')
94 t.Branch(
'zratestat', o_zratestat,
'zratestat/F')
95 t.Branch(
'zlumi', o_zlumi,
'zlumi/F')
96 t.Branch(
'zlumistat', o_zlumistat,
'zlumistat/F')
97 t.Branch(
'offlumi', o_offlumi,
'offlumi/F')
98 t.Branch(
'mu', o_mu,
'mu/F')
99 t.Branch(
'alleffcorr', o_alleffcorr,
'alleffcorr/F')
100 t.Branch(
'alleffcorrstat', o_alleffcorrstat,
'alleffcorrstat/F')
101 t.Branch(
'lblive', o_lblive,
'lblive/F')
102 t.Branch(
'lhcfill', o_lhcfill,
'lhcfill/i')
104 for entry, entryval
in sorted(entrydict.items()):
105 if entryval[
'livetime'] > 0:
106 entryval[
'mu'] /= entryval[
'livetime']
107 entryval[
'offlumi'] /= entryval[
'livetime']
108 eff = entryval[
'rolleff']/entryval[
'rollefferrsq']
109 efferr = 1/entryval[
'rollefferrsq']**.5
111 entryval[
'zrate'] = entryval[
'zcount']/eff/entryval[
'livetime']
112 entryval[
'zratestat'] = (entryval[
'zcounterrsq']/eff/eff + (entryval[
'zcount']/eff**2*efferr)**2)**.5/entryval[
'livetime']
113 o_run[0], o_lb[0] = entry
114 o_lbwhen[0], o_lbwhen[1] = entryval[
'lbwhen']
115 o_zrate[0] = entryval[
'zrate']
116 o_zratestat[0] = entryval[
'zratestat']
117 o_zlumi[0] = o_zrate[0]*ZPURITYFACTOR/ACCEPTANCE/ZXSEC
118 o_zlumistat[0] = o_zratestat[0]*ZPURITYFACTOR/ACCEPTANCE/ZXSEC
119 o_mu[0] = entryval[
'mu']
120 o_alleffcorr[0] = eff
121 o_alleffcorrstat[0] = efferr
122 o_offlumi[0] = entryval[
'offlumi']
123 o_lblive[0] = entryval[
'livetime']
124 o_lhcfill[0] = entryval[
'lhcfill']
125 if o_zlumi[0] < 4
or o_zlumi[0] > 15:
126 print(o_lb[0], o_zlumi[0], entryval[
'zcount'], eff, entryval[
'livetime'])
129 newrzt = recoztree.CloneTree()
130 newrzt.SetName(
"recolumitree")
131 newezt = effztree.CloneTree()
132 newezt.SetName(
"efflumitree")