-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplotResponseMat.py
More file actions
executable file
·96 lines (81 loc) · 3.37 KB
/
plotResponseMat.py
File metadata and controls
executable file
·96 lines (81 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import ROOT
import datetime
import os
import array
from Utilities.scripts import makeSimpleHtml
ROOT.gROOT.SetBatch(True)
canvas = ROOT.TCanvas("canvas", "canvas")
def getTextBox(obj, extra_text=""):
text_box = ROOT.TPaveText(0.2, 0.88, 0.4+0.02*len(extra_text), 0.81, "blNDC")
text_box.SetFillColor(0)
text_box.SetLineColor(ROOT.kBlack)
text_box.SetTextFont(42)
text_box.AddText(" %s Fake Rate %s" % ("#mu" if "Mu" in obj else "e", extra_text))
text_box.SetBorderSize(1)
ROOT.SetOwnership(text_box, False)
return text_box
def getLumiTextBox():
texS = ROOT.TLatex(0.615,0.95,"#sqrt{s} = 13 TeV, 41.5 fb^{-1}")
texS.SetNDC()
texS.SetTextFont(42)
texS.SetTextSize(0.040)
texS.Draw()
texS1 = ROOT.TLatex(0.15,0.95,"#bf{CMS} #it{Preliminary}")
texS1.SetNDC()
texS1.SetTextFont(42)
texS1.SetTextSize(0.040)
texS1.Draw()
return texS,texS1
def makeResponseMatrix(hfile,sample,var, outdir,chan):
histfile = ROOT.TFile("/data/uhussain/ZZTo4l/ZZ2018/VVAnalysisTools/CMSSW_9_4_2/src/Analysis/VVAnalysis/HistFiles/"+hfile)
print(histfile)
print("sample: ",sample)
print("variable: ",var)
print("channel: ",chan)
print("%s/Gen%s_%s"%(sample,var,chan))
GenHist = histfile.Get("%s/Gen%s_%s"%(sample,var,chan))
RecoHist = histfile.Get("%s/Gen%s_%s"%(sample,var,chan))
print ("GenHist: ", GenHist)
nbins={"Mass":11,"ZZPt":12}
low={"Mass":100,"ZZPt":0}
high={"Mass":1200,"ZZPt":1200}
RespMat = ROOT.TH2D('RespMat','Reco vs True',nbins[var],low[var],high[var],nbins[var],low[var],high[var])
#Fill the 2D Hist bin by bin
for i in range(1,GenHist.GetNbinsX()+1):
for j in range(1,RecoHist.GetNbinsX()+1):
if(GenHist.GetBinContent(i)>0):
RespMat.SetBinContent(i,j,RecoHist.GetBinContent(j)/GenHist.GetBinContent(i))
else:
RespMat.SetBinContent(i,j,(-1)*RecoHist.GetBinContent(j))
draw_opt = "colz text45"
ROOT.gStyle.SetPaintTextFormat("3.2f");
ROOT.gStyle.SetOptStat(0)
labels={"ZZPt":"Pt_{4l} [GeV]","Mass":"m_{4l} [GeV]"}
print labels[var]
RespMat.SetTitle("")
RespMat.GetXaxis().SetTitle("Reco%s"% (labels[var]))
RespMat.GetYaxis().SetTitle("True%s"% (labels[var]))
RespMat.Draw(draw_opt)
#text_box = getTextBox(obj, "(MC)")
#text_box.Draw()
canvas.Print("%s/matrix%s_%s.png" % (outdir, var, chan))
canvas.Print("%s/matrix%s_%s.pdf" % (outdir, var, chan))
#histfile = ROOT.TFile.Open("/data/uhussain/ZZTo4l/ZZ2018/VVAnalysisTools/CMSSW_9_4_2/src/Analysis/VVAnalysis/HistFiles/Hists05Apr2019-zzPowhegWGen.root")
data_folder_name = datetime.date.today().strftime("ResponseMatrces_"+"%Y%b%d")
mc_outdir = "~/www/ZZAnalysisData/PlottingResults/ZZ4l2018/Unfolding/" + data_folder_name
def mkdir(mc_outdir):
for outdir in [mc_outdir]:
try:
os.makedirs(os.path.expanduser(outdir))
except OSError as e:
print e
pass
hfile="Hists05Apr2019-zzPowhegWGen.root"
for channel in ["eeee","eemm","mmee","mmmm"]:
OutputDir=mc_outdir+"/"+channel+"/plots"
mkdir(OutputDir)
for sample in ["zz4l-powheg"]:
for var in ["ZZPt", "Mass"]:
makeResponseMatrix(hfile,sample, var, OutputDir,channel)
makeSimpleHtml.writeHTML(os.path.expanduser(OutputDir.replace("/plots", "")), "2D ResponseMatrices (from MC)")