ATLAS Offline Software
Loading...
Searching...
No Matches
dqt_zlumi_combine_lumi.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
3import ROOT
4import sys
5
6import argparse
7parser = argparse.ArgumentParser()
8parser.add_argument('recofile', type=str, help='File with per-LB yields')
9parser.add_argument('efffile', type=str, help='File with efficiencies')
10parser.add_argument('outfile', type=str, help='Output file')
11parser.add_argument('--nlb', type=int, help='# of LBs to combine',
12 default=20)
13args = parser.parse_args()
14
15recozfname = args.recofile
16effzfname = args.efffile
17outfname = args.outfile
18
19LUMIBLOCKS = args.nlb
20#ACCEPTANCE = 3.173927e-01
21ACCEPTANCE = 3.323224e-01
22ZXSEC=1.929
23ZPURITYFACTOR=0.9935
24
25def correction(mu):
26 # R20.7
27 # return 1.04524-0.000108956*mu
28 # R21
29 #return 1.04701-0.000206159*mu
30 return 0.998758-0.000157214*mu
31 #return 1.
32
33recozfile = ROOT.TFile.Open(recozfname)
34effzfile = ROOT.TFile.Open(effzfname)
35
36recoztree = recozfile.lumitree
37effztree = effzfile.lumitree
38
39entrydict = {}
40
41for i in xrange(recoztree.GetEntries()):
42 recoztree.GetEntry(i)
43 if not recoztree.pass_grl: continue
44 # If livetime less than 10 sec, ignore
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))
50 continue
51 lbzero = (recoztree.lb // LUMIBLOCKS)*LUMIBLOCKS
52 run = recoztree.run
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)]
55 effcy = (effztree.GetV1()[0]*correction(recoztree.mu))
56 #thisdict['zcount'] += recoztree.zraw/effcy
57 #thisdict['zcounterrsq'] += (1/effcy*recoztree.zrawstat)**2+(recoztree.zraw/effcy**2*effztree.GetV2()[0])**2
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
64 #loclivetime = (recoztree.lbwhen[1]-recoztree.lbwhen[0])
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]
72
73from array import array
74
75fout = ROOT.TFile.Open(outfname, 'RECREATE')
76o_run = array('I', [0])
77o_lb = array('I', [0])
78o_lbwhen = array('d', [0., 0.])
79o_zrate = array('f', [0.])
80o_zratestat = array('f', [0.])
81o_zlumi = array('f', [0.])
82o_zlumistat = array('f', [0.])
83o_mu = array('f', [0.])
84o_alleffcorr = array('f', [0.])
85o_alleffcorrstat = array('f', [0.])
86o_offlumi = array('f', [0.])
87o_lblive = array('f', [0.])
88o_lhcfill = array('I', [0])
89t = ROOT.TTree( 'lumitree', 'Luminosity tree' )
90t.Branch('run', o_run, 'run/i')
91t.Branch('lb', o_lb, 'lb/i')
92t.Branch('lbwhen', o_lbwhen, 'lbwhen[2]/D')
93t.Branch('zrate', o_zrate, 'zrate/F')
94t.Branch('zratestat', o_zratestat, 'zratestat/F')
95t.Branch('zlumi', o_zlumi, 'zlumi/F')
96t.Branch('zlumistat', o_zlumistat, 'zlumistat/F')
97t.Branch('offlumi', o_offlumi, 'offlumi/F')
98t.Branch('mu', o_mu, 'mu/F')
99t.Branch('alleffcorr', o_alleffcorr, 'alleffcorr/F')
100t.Branch('alleffcorrstat', o_alleffcorrstat, 'alleffcorrstat/F')
101t.Branch('lblive', o_lblive, 'lblive/F')
102t.Branch('lhcfill', o_lhcfill, 'lhcfill/i')
103
104for 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
110 #print('LIVETIME2', entryval['livetime'])
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'])
127 t.Fill()
128#t.Write()
129newrzt = recoztree.CloneTree()
130newrzt.SetName("recolumitree")
131newezt = effztree.CloneTree()
132newezt.SetName("efflumitree")
133fout.Write()
134fout.Close()
135
void print(char *figname, TCanvas *c1)
STL class.
void xrange(TH1 *h, bool symmetric)