1 from __future__
import print_function
2 from __future__
import absolute_import
3 from builtins
import range
4 from .officialStyle
import officialStyle
5 from array
import array
6 from ROOT
import gROOT, gStyle, TH1F, TH1D, TF1, TFile, TCanvas, TH2F, TLegend, TGraphAsymmErrors, Double, TLatex
21 print(
'Please specify the runtype : python tauPOGplot.py <ZTT, ZEE, ZMM, QCD>')
25 print(
'You selected', runtype)
28 tlabel =
'Z #rightarrow #tau#tau'
29 xlabel =
'gen. tau p_{T}^{vis} (GeV)'
33 xlabel =
'jet p_{T} (GeV)'
34 elif runtype ==
'ZEE':
35 tlabel =
'Z #rightarrow ee'
36 xlabel =
'electron p_{T} (GeV)'
37 elif runtype ==
'ZMM':
38 tlabel =
'Z #rightarrow #mu#mu'
39 xlabel =
'muon p_{T} (GeV)'
45 if not os.path.exists(directory):
46 os.makedirs(directory)
50 canvas.SaveAs(name.replace(
' ',
'').
replace(
'&&',
'')+
'.pdf')
51 canvas.SaveAs(name.replace(
' ',
'').
replace(
'&&',
'')+
'.gif')
55 leg.SetNColumns(ncolumn)
65 def makeCompareVars(tree, var, sel, leglist, nbin, xmin, xmax, xtitle, ytitle, scale, name):
75 for ii, isel
in enumerate(sel):
76 hist = TH1F(
'h_' +
str(ii),
'h_' +
str(ii), nbin, xmin, xmax)
77 hist.GetXaxis().SetTitle(xtitle)
78 hist.GetYaxis().SetTitle(ytitle)
79 hist.GetYaxis().SetNdivisions(507)
80 hist.SetLineColor(col[ii])
81 hist.SetLineWidth(len(sel)+1-ii)
88 tree.Project(hist.GetName(), var, isel)
89 hist.Scale(1./hist.GetEntries())
91 if ymax < hist.GetMaximum():
92 ymax = hist.GetMaximum()
97 leg = TLegend(0.6,0.65,0.91,0.9)
100 for ii, ihist
in enumerate(hists):
101 ihist.SetMaximum(ymax*1.2)
109 if leglist[ii] !=
'None':
110 leg.AddEntry(ihist, leglist[ii],
"l")
113 if leglist[0]!=
'None':
125 print(
'number of histograms = ', len(hists))
128 leg = TLegend(0.2,0.7,0.5,0.9)
131 col = [1,2,4,6,8,9,12]
136 for ii, hist
in enumerate(hists):
137 hist.GetYaxis().SetTitle(
'efficiency')
138 hist.SetLineColor(col[ii])
139 hist.SetMarkerColor(col[ii])
141 hist.SetMarkerSize(1)
144 for ip
in range(hist.GetN()):
147 hist.GetPoint(ip, x, y)
167 legname = hist.GetName()
169 leg.AddEntry(hist, legname,
'lep')
173 hist.SetMaximum(ymax*2)
178 tex = TLatex( hists[-1].GetXaxis().GetXmin() + 0.01*(hists[-1].GetXaxis().GetXmax() - hists[-1].GetXaxis().GetXmin()), ymax*2.1, addon.replace(
'tau_',
''))
181 tex.SetTextSize(0.03)
184 tex2 = TLatex( hists[-1].GetXaxis().GetXmin() + 0.87*(hists[-1].GetXaxis().GetXmax() - hists[-1].GetXaxis().GetXmin()), ymax*2.1, tlabel)
187 tex2.SetTextSize(0.03)
192 save(canvas,
'compare_' + runtype +
'/' + header)
202 if ymax < hist.GetMaximum():
203 ymax = hist.GetMaximum()
206 leg = TLegend(0.6,0.65,0.91,0.9)
209 for ii, ihist
in enumerate(hists):
210 ihist.SetMaximum(ymax*1.2)
212 ihist.SetMarkerSize(0.)
213 ihist.GetXaxis().SetTitle(xtitle)
214 ihist.GetYaxis().SetTitle(ytitle)
221 leg.AddEntry(ihist, ihist.GetName(),
"l")
227 save(c,
'compare_' + runtype +
'/hist_' + name)
232 def makeEffPlotsVars(tree, varx, vary, sel, nbinx, xmin, xmax, nbiny, ymin, ymax, xtitle, ytitle, leglabel = None, header='', addon='', option='pt', marker=20):
234 binning = [20,30,40,50,60,70,80,100,150,200]
239 _hist_ = TH1F(
'h_effp_' + addon,
'h_effp' + addon, len(binning)-1,
array(
'd',binning))
240 _ahist_ = TH1F(
'ah_effp_' + addon,
'ah_effp' + addon, len(binning)-1,
array(
'd',binning))
242 _hist_ = TH1F(
'h_effp_' + addon,
'h_effp' + addon, nbinx, xmin, xmax)
243 _ahist_ = TH1F(
'ah_effp_' + addon,
'ah_effp' + addon, nbinx, xmin, xmax)
245 _hist_ = TH1F(
'h_effp_' + addon,
'h_effp' + addon, len(vbinning)-1,
array(
'd',vbinning))
246 _ahist_ = TH1F(
'ah_effp_' + addon,
'ah_effp' + addon, len(vbinning)-1,
array(
'd',vbinning))
249 tree.Draw(varx +
' >> ' + _hist_.GetName(), sel)
250 tree.Draw(varx +
' >> ' + _ahist_.GetName(), sel +
' && ' + vary)
252 g_efficiency = TGraphAsymmErrors()
253 g_efficiency.BayesDivide(_ahist_, _hist_)
254 g_efficiency.GetXaxis().SetTitle(xtitle)
255 g_efficiency.GetYaxis().SetTitle(
'efficiency')
256 g_efficiency.GetYaxis().SetNdivisions(507)
257 g_efficiency.SetLineWidth(3)
258 g_efficiency.SetName(header)
259 g_efficiency.SetMinimum(0.)
260 g_efficiency.GetYaxis().SetTitleOffset(1.3)
261 g_efficiency.SetMarkerStyle(marker)
262 g_efficiency.SetMarkerSize(1)
263 g_efficiency.Draw(
'ap')
267 return copy.deepcopy(g_efficiency)
273 if __name__ ==
'__main__':
277 'againstMuonLoose3':{
'var':
'tau_againstMuonLoose3 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstMuonLoose3'},
278 'againstMuonTight3':{
'var':
'tau_againstMuonTight3 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstMuonTight3'},
280 'againstElectronVLooseMVA5':{
'var':
'tau_againstElectronVLooseMVA5 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronVLooseMVA5'},
281 'againstElectronLooseMVA5':{
'var':
'tau_againstElectronLooseMVA5 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronLooseMVA5'},
282 'againstElectronMediumMVA5':{
'var':
'tau_againstElectronMediumMVA5 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronMediumMVA5'},
284 'againstElectronVLooseMVA6':{
'var':
'tau_againstElectronVLooseMVA6 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronVLooseMVA6'},
285 'againstElectronLooseMVA6':{
'var':
'tau_againstElectronLooseMVA6 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronLooseMVA6'},
286 'againstElectronMediumMVA6':{
'var':
'tau_againstElectronMediumMVA6 > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'againstElectronMediumMVA6'},
288 'byLoosePileupWeightedIsolation3Hits':{
'var':
'tau_byLoosePileupWeightedIsolation3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byLoosePileupWeightedIsolation3Hits'},
289 'byMediumPileupWeightedIsolation3Hits':{
'var':
'tau_byMediumPileupWeightedIsolation3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byMediumPileupWeightedIsolation3Hits'},
290 'byTightPileupWeightedIsolation3Hits':{
'var':
'tau_byTightPileupWeightedIsolation3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byTightPileupWeightedIsolation3Hits'},
292 'byLooseCombinedIsolationDeltaBetaCorr3Hits':{
'var':
'tau_byLooseCombinedIsolationDeltaBetaCorr3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byLooseCombinedIsolationDeltaBetaCorr3Hits'},
293 'byMediumCombinedIsolationDeltaBetaCorr3Hits':{
'var':
'tau_byMediumCombinedIsolationDeltaBetaCorr3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byMediumCombinedIsolationDeltaBetaCorr3Hits'},
294 'byTightCombinedIsolationDeltaBetaCorr3Hits':{
'var':
'tau_byTightCombinedIsolationDeltaBetaCorr3Hits > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byTightCombinedIsolationDeltaBetaCorr3Hits'},
296 'byLooseIsolationMVA3oldDMwLT':{
'var':
'tau_byLooseIsolationMVA3oldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byLooseIsolationMVA3oldDMwLT'},
297 'byMediumIsolationMVA3oldDMwLT':{
'var':
'tau_byMediumIsolationMVA3oldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byMediumIsolationMVA3oldDMwLT'},
298 'byTightIsolationMVA3oldDMwLT':{
'var':
'tau_byTightIsolationMVA3oldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byTightIsolationMVA3oldDMwLT'},
300 'byLooseIsolationMVArun2v1DBoldDMwLT':{
'var':
'tau_byLooseIsolationMVArun2v1DBoldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byLooseIsolationMVArun2v1DBoldDMwLT'},
301 'byMediumIsolationMVArun2v1DBoldDMwLT':{
'var':
'tau_byMediumIsolationMVArun2v1DBoldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byMediumIsolationMVArun2v1DBoldDMwLT'},
302 'byTightIsolationMVArun2v1DBoldDMwLT':{
'var':
'tau_byTightIsolationMVArun2v1DBoldDMwLT > 0.5 && tau_decayModeFindingOldDMs > 0.5',
'nbin':2,
'min':-0.5,
'max':1.5,
'title':
'byTightIsolationMVArun2v1DBoldDMwLT'},
307 reco_cut =
'tau_pt > 20 && abs(tau_eta) < 2.3'
308 loose_id =
'tau_decayModeFindingOldDMs > 0.5 && tau_byLooseCombinedIsolationDeltaBetaCorr3Hits > 0.5'
314 '7_6_1_v3':{
'file':
'Myroot_7_6_1_v3_' + runtype +
'.root',
'col':3,
'marker':23,
'width':1},
317 for hname, hdict
in sorted(six.iteritems(vardict)):
321 for rel, rdict
in sorted(six.iteritems(sampledict)):
323 if rel.find(
'7_6_1')==-1
and (hname.find(
'MVA6')!=-1
or hname.find(
'MVArun2')!=-1):
continue
325 tfile = TFile(rdict[
'file'])
326 tree = tfile.Get(
'per_tau')
331 if hname.find(
'against')!=-1:
333 den_sel = reco_cut +
' && ' + loose_id
335 hists.append(
makeEffPlotsVars(tree,
'tau_genpt', num_sel +
'&&' + hdict[
'var'], den_sel, 30, 0, 300, hdict[
'nbin'], hdict[
'min'], hdict[
'max'], xlabel, hdict[
'title'],
'', rel, rel,
'pt', rdict[
'marker']))
346 overlay(hists, hname, hname, hdict[
'title'])
352 'tau_dm':{
'var':
'tau_dm',
'nbin':12,
'min':0.,
'max':12,
'title':
'decay Mode',
'sel':
'1'},
353 'tau_mass_1prong':{
'var':
'tau_mass',
'nbin':30,
'min':0.,
'max':2.5,
'title':
'Tau mass, 1prong',
'sel':
'tau_dm==0'},
354 'tau_mass_1prongp0':{
'var':
'tau_mass',
'nbin':30,
'min':0.,
'max':2.5,
'title':
'Tau mass, 1prong+#pi^{0}',
'sel':
'tau_dm==1'},
355 'tau_mass_2prong':{
'var':
'tau_mass',
'nbin':30,
'min':0.,
'max':2.5,
'title':
'Tau mass, 2prong',
'sel':
'(tau_dm==5 || tau_dm==6)'},
356 'tau_mass_3prong':{
'var':
'tau_mass',
'nbin':30,
'min':0.,
'max':2.5,
'title':
'Tau mass, 3prong (+#pi^{0})',
'sel':
'(tau_dm==10 || tau_dm==11)'},
357 'pt_resolution_1prong':{
'var':
'(tau_genpt-tau_pt)/(tau_genpt)',
'nbin':30,
'min':-1.,
'max':1.,
'title':
'pT resolution, 1prong',
'sel':
'tau_dm==0'},
358 'pt_resolution_1prongp0':{
'var':
'(tau_genpt-tau_pt)/(tau_genpt)',
'nbin':30,
'min':-1.,
'max':1.,
'title':
'pT resolution, 1prong+#pi^{0}',
'sel':
'tau_dm==1'},
359 'pt_resolution_2prong':{
'var':
'(tau_genpt-tau_pt)/(tau_genpt)',
'nbin':30,
'min':-1.,
'max':1.,
'title':
'pT resolution, 2prong',
'sel':
'(tau_dm==5 || tau_dm==6)'},
360 'pt_resolution_3prong':{
'var':
'(tau_genpt-tau_pt)/(tau_genpt)',
'nbin':30,
'min':-1.,
'max':1.,
'title':
'pT resolution, 3prong (+#pi^{0})',
'sel':
'(tau_dm==10 || tau_dm==11)'},
364 for hname, hdict
in sorted(six.iteritems(hvardict)):
368 if runtype !=
'ZTT' and hname.find(
'pt_resolution')!=-1:
continue
371 for rel, rdict
in sorted(six.iteritems(sampledict)):
373 tfile = TFile(rdict[
'file'])
374 tree = tfile.Get(
'per_tau')
376 hist = TH1F(
'h_' + hname +
'_' + rel,
'h_' + hname +
'_' + rel, hdict[
'nbin'], hdict[
'min'], hdict[
'max'])
377 hist.GetYaxis().SetNdivisions(507)
378 hist.SetLineColor(rdict[
'col'])
379 hist.SetLineWidth(rdict[
'width'])
384 tree.Project(hist.GetName(), hdict[
'var'], hdict[
'sel'])
385 hist.Scale(1./hist.GetEntries())
387 hists.append(copy.deepcopy(hist))
389 hoverlay(hists, hdict[
'title'],
'a.u.', hname)