6 ROOT.gStyle.SetOptStat(0)
9 ACCEPTANCE = 3.323224e-01
12 parser = argparse.ArgumentParser()
13 parser.add_argument(
'infile', type=str, help=
'input HIST file')
14 parser.add_argument(
'--out', type=str, help=
'output ROOT file')
15 parser.add_argument(
'--plotdir', type=str, help=
'Directory to dump plots',
17 parser.add_argument(
'--debug', action=
'store_true', help=
'Be verbose in output')
18 parser.add_argument(
'--mode', type=str, help=
'Zee or Zmumu')
21 args = parser.parse_args()
23 infilename = args.infile
24 infile = ROOT.TFile.Open(infilename,
'READ')
27 print(
'Running in', runmode,
'mode')
31 for k
in infile.GetListOfKeys():
32 if k.GetName().startswith(
'run_'):
36 print(
'Cannot find run directory in input file')
39 print(
'Found runname', runname)
42 for k
in infile.Get(runname).GetListOfKeys():
43 if k.GetName().startswith(
'lb_'):
44 lbdirs.append(k.GetName())
49 effcyt = ROOT.TH1F(
'effcyt',
'Trigger efficiency', lbnums[-1]-lbnums[0]+1, lbnums[0]-0.5,
51 effcyr = ROOT.TH1F(
'effcyr',
'Loose muon reco efficiency', lbnums[-1]-lbnums[0]+1, lbnums[0]-0.5,
53 effcya = ROOT.TH1F(
'effcya',
'Combined acc x efficiency', lbnums[-1]-lbnums[0]+1, lbnums[0]-0.5,
55 effcydir = ROOT.TH1F(
'effcydir',
'Direct acc x efficiency', lbnums[-1]-lbnums[0]+1, lbnums[0]-0.5,
58 from array
import array
59 fout = ROOT.TFile(args.out
if args.out
else '%s_all.root' % runname[4:],
'RECREATE')
66 o_trigeffstat =
array(
'f', [0.])
68 o_recoeffstat =
array(
'f', [0.])
73 tl = ROOT.TTree(
'lumitree',
'Luminosity tree' )
74 tl.Branch(
'run', o_run,
'run/i')
75 tl.Branch(
'lb', o_lb,
'lb/i')
76 tl.Branch(
'lbwhen', o_lbwhen,
'lbwhen[2]/D')
77 tl.Branch(
'z_one', o_z_one,
'z_one/F')
78 tl.Branch(
'z_two', o_z_two,
'z_two/F')
79 tl.Branch(
'trigeff', o_trigeff,
'trigeff/F')
80 tl.Branch(
'trigeffstat', o_trigeffstat,
'trigeffstat/F')
81 tl.Branch(
'recoeff', o_recoeff,
'recoeff/F')
82 tl.Branch(
'recoeffstat', o_recoeffstat,
'recoeffstat/F')
83 tl.Branch(
'alleff', o_alleff,
'alleff/F')
84 tl.Branch(
'alleffstat', o_alleffstat,
'alleffstat/F')
85 tl.Branch(
'ae', o_ae,
'ae/F')
86 tl.Branch(
'aestat', o_aestat,
'aestat/F')
89 from DQUtils
import fetch_iovs
95 h = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_eltrigtp_matches' % (runname, lb))
96 hmo = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_ele_tight_good_os' % (runname, lb))
97 hms = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_ele_tight_good_ss' % (runname, lb))
98 hno = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_ele_tight_bad_os' % (runname, lb))
99 hns = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_ele_tight_bad_ss' % (runname, lb))
100 if runmode ==
"Zmumu":
101 h = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_mutrigtp_matches' % (runname, lb))
102 hmo = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_muloosetp_match_os' % (runname, lb))
103 hms = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_muloosetp_match_ss' % (runname, lb))
104 hno = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_muloosetp_nomatch_os' % (runname, lb))
105 hns = infile.Get(
'%s/%s/GLOBAL/DQTGlobalWZFinder/m_muloosetp_nomatch_ss' % (runname, lb))
108 ylderr = (h.GetBinError(2), h.GetBinError(3))
111 o_z_one[0], o_z_two[0] = yld
114 inverrsq = ((1/2./B)*ylderr[0])**2+((A/2./B**2)*ylderr[1])**2
116 o_trigeffstat[0] = (inverrsq**.5)*(eff**2)
117 o_run[0], o_lb[0] =
int(runname[4:]), lbnum
119 iov = lblb[
int(runname[4:])][lbnum-1]
120 o_lbwhen[0], o_lbwhen[1] = iov.StartTime/1e9, iov.EndTime/1e9
121 except Exception
as e:
122 o_lbwhen[0], o_lbwhen[1] = 0, 0
123 effcyt.SetBinContent(lbnum-lbnums[0]+1, eff)
124 effcyt.SetBinError(lbnum-lbnums[0]+1, o_trigeffstat[0])
128 rv1 = histogram.IntegralAndError(21, 30, dbl)
129 return (rv1,
float(dbl))
136 print(
' ->', matchos, matchoserr)
137 print(
' ->', matchss, matchsserr)
138 print(
' ->', nomatchos, nomatchoserr)
139 print(
' ->', nomatchss, nomatchsserr)
140 A =
float(matchos-matchss)
141 Aerr = (matchoserr**2+matchsserr**2)**.5
142 B =
float(nomatchos-nomatchss)
143 Berr = (nomatchoserr**2+nomatchsserr**2)**.5
144 if Berr == 0: Berr = 1.
145 if A == 0
or B/A == -1:
150 inverrsq = ((-B/A**2)*Aerr)**2+((1./A)*Berr)**2
152 o_recoeffstat[0] = (inverrsq**.5)*(eff**2)
153 effcyr.SetBinContent(lbnum-lbnums[0]+1, eff)
154 effcyr.SetBinError(lbnum-lbnums[0]+1, o_recoeffstat[0])
156 o_ae[0] = ACCEPTANCE*(1-(1-o_trigeff[0])**2)*(o_recoeff[0])**2
157 o_aestat[0] = ACCEPTANCE*((o_recoeff[0]**2*2*(1-o_trigeff[0])*o_trigeffstat[0])**2+(2*o_recoeff[0]*(1-(1-o_trigeff[0])**2)*o_recoeffstat[0])**2)**.5
158 o_alleff[0] = (1-(1-o_trigeff[0])**2)*(o_recoeff[0])**2
159 o_alleffstat[0] = ((o_recoeff[0]**2*2*(1-o_trigeff[0])*o_trigeffstat[0])**2+(2*o_recoeff[0]*(1-(1-o_trigeff[0])**2)*o_recoeffstat[0])**2)**.5
160 effcya.SetBinContent(lbnum-lbnums[0]+1, o_ae[0])
161 effcya.SetBinError(lbnum-lbnums[0]+1, o_aestat[0])
169 effcya.SetMarkerStyle(21)
170 effcya.SetMarkerColor(ROOT.kBlue)
171 effcya.GetYaxis().SetRangeUser(0.25,0.31)
173 c1.Print(os.path.join(args.plotdir,
'%s_combined_efficiency.eps' % runname[4:]))
174 fout.WriteTObject(effcya)
176 effcyt.SetMarkerStyle(21)
177 effcyt.SetMarkerColor(ROOT.kBlue)
178 effcyt.GetYaxis().SetRangeUser(0.66,0.86)
180 c1.Print(os.path.join(args.plotdir,
'%s_trigger_efficiency.eps' % runname[4:]))
181 fout.WriteTObject(effcyt)
183 effcyr.SetMarkerStyle(21)
184 effcyr.SetMarkerColor(ROOT.kBlue)
185 effcyr.GetYaxis().SetRangeUser(0.9,1.0)
187 c1.Print(os.path.join(args.plotdir,
'%s_reco_efficiency.eps' % runname[4:]))
188 fout.WriteTObject(effcyr)
192 sumweights = infile.Get(
'%s/GLOBAL/DQTDataFlow/m_sumweights' % runname)
193 ctr = infile.Get(
'%s/GLOBAL/DQTGlobalWZFinder/m_Z_Counter_el' % runname)
194 if runmode ==
"Zmumu":
195 sumweights = infile.Get(
'%s/GLOBAL/DQTDataFlow/m_sumweights' % runname)
196 ctr = infile.Get(
'%s/GLOBAL/DQTGlobalWZFinder/m_Z_Counter_mu' % runname)
198 for ibin
in xrange(1,sumweights.GetNbinsX()+1):
199 o_lb[0] =
int(sumweights.GetBinCenter(ibin))
200 ctrbin = ctr.FindBin(o_lb[0])
201 print(ibin, o_lb[0], sumweights[ibin], ctr[ctrbin])
202 if sumweights[ibin] == 0:
continue
203 p = ctr[ctrbin]/sumweights[ibin]
206 o_alleffstat[0]=(p*(1-p))**.5*(sumweights.GetBinError(ibin)/sumweights[ibin])
208 o_alleffstat[0]=(sumweights.GetBinError(ibin)/sumweights[ibin])
209 effcydir.SetBinContent(effcydir.FindBin(o_lb[0]), p)
210 effcydir.SetBinError(effcydir.FindBin(o_lb[0]), o_alleffstat[0])
212 effcya.GetYaxis().SetRangeUser(0.27,0.31)
214 effcydir.SetMarkerStyle(20)
215 effcydir.SetMarkerColor(ROOT.kRed)
216 effcydir.Draw(
'SAME,PE')
217 leg=ROOT.TLegend(0.65, 0.7, 0.89, 0.89)
218 leg.AddEntry(effcya,
'Predicted A#epsilon',
'PE')
219 leg.AddEntry(effcydir,
'Actual A#epsilon',
'PE')
221 c1.Print(os.path.join(args.plotdir,
'%s_tp_comparison.eps' % runname[4:]))
223 effcyrat=effcydir.Clone()
224 effcyrat.Divide(effcya)
225 effcyrat.SetTitle(
'MC Correction Factor')
226 effcyrat.SetXTitle(
'<#mu>')
229 c1.Print(os.path.join(args.plotdir,
'%s_tp_correction.eps' % runname[4:]))