5 from array
import array
6 from pprint
import pprint
7 from get_xsec
import signalCrossSection
8 from get_xsec_stop
import stopCrossSection
9 from set_palette
import set_palette
12 from ROOT
import TMath
14 parser = argparse.ArgumentParser()
15 parser.add_argument(
"-b",
"--babydir")
16 parser.add_argument(
"-i",
"--input")
17 parser.add_argument(
"-o",
"--outfilename")
18 parser.add_argument(
"-f",
"--first")
19 parser.add_argument(
"-l",
"--last")
20 parser.add_argument(
"-t",
"--topology")
21 args = parser.parse_args()
24 temphist = ROOT.TH1D(
"temp",
"temp",2,0,2)
25 chain.Project(
"temp",
"1",
"weight*("+cuts+
")")
26 n = temphist.GetBinContent(2)
36 print "Did you mean to use T5ttttDM175 ???" 42 outdir =
"/net/cms2/cms2r0/babymaker/babies/2016_01_11/mc/T1tttt/skim_abcd/" 43 elif topo ==
"T5ttttDM175":
44 outdir =
"/net/cms2/cms2r0/babymaker/babies/2016_02_09/mc/T5tttt/skim_abcd/" 46 sys.exit(
"Please provide a baby directory")
57 minnum = int(args.first)
61 maxnum = int(args.last)
64 print "starting with "+str(minnum)
65 print "until "+str(maxnum)
74 print "Recalculating.." 76 if (args.outfilename):
77 outfile = args.outfilename
78 if ".root" in outfile: outfile = outfile.split(
".root")[0]
79 else: sys.exit(
"Please provide name for output root file")
82 ROOT.gROOT.SetBatch(ROOT.kTRUE)
83 ROOT.gStyle.SetCanvasDefW(600);
84 ROOT.gStyle.SetCanvasDefH(600);
85 ROOT.gStyle.SetTitleOffset(1.2,
"x")
86 ROOT.gStyle.SetTitleOffset(1.7,
"y")
87 ROOT.gStyle.SetTitleOffset(1.7,
"z")
88 ROOT.gStyle.SetPadRightMargin(0.19)
89 ROOT.gStyle.SetPadLeftMargin(0.14)
90 ROOT.gStyle.SetPadBottomMargin(0.14)
91 ROOT.gStyle.SetPadTopMargin(0.08)
94 ROOT.gStyle.SetLabelFont(42)
95 ROOT.gStyle.SetLabelSize(0.04)
96 ROOT.gStyle.SetTitleFont(42)
97 ROOT.gStyle.SetTitleSize(0.05)
107 if not os.path.exists(outdir):
108 sys.exit(
"Can't find babies directory %s" %outdir)
110 if not skipcalc
and not os.path.exists(
"plots/maps"):
111 sys.exit(
"Can't find directory for output root file plots/maps")
115 masspoints = set([x.split(topo+
"_").pop().split(
"_Tune")[0]
for x
in glob.glob(outdir+
"/baby_SMS-"+topo+
"*.root")])
120 npoints = len(masspoints)
122 sys.exit(
"Need to run on renormalized ABCD skim")
124 bg = [3.5,0.5,2.7,0.5,0.8,0.1,1.3,0.3,0.5,0.1]
127 bindefs = [
"njets<=8&&nbm==1&&met<=400",
"njets>=9&&nbm==1&&met<=400",
"njets<=8&&nbm==2&&met<=400",
"njets>=9&&nbm==2&&met<=400",
"njets<=8&&nbm>=3&&met<=400",
"njets>=9&&nbm>=3&&met<=400",
"njets<=8&&nbm==1&&met>400",
"njets>=9&&nbm==1&&met>400",
"njets<=8&&nbm>=2&&met>400",
"njets>=9&&nbm>=2&&met>400"]
128 cosmeticbindefs = [cut.replace(
"<=",
" #leq ").replace(
">=",
" #geq ").replace(
">",
" > ").replace(
"==",
" = ").replace(
"&&",
", ").replace(
"met",
"MET").replace(
"ht",
"H_{T}").replace(
"njets",
"n_{jets}").replace(
"nleps",
"n_{lep}").replace(
"nbm",
"n_{b}")
for cut
in bindefs]
132 effs = [[]
for i
in range(2+len(bindefs))]
133 yields = [[]
for i
in range(2+len(bindefs))]
143 ch = ROOT.TChain(
"tree")
146 print "looking for file "+outdir+
"/baby_SMS-"+topo+
"_"+m+
"_TuneCUETP8M1*.root" 147 ch.Add(outdir+
"/baby_SMS-"+topo+
"_"+m+
"_TuneCUETP8M1*.root")
148 print "nentries is " + str(ch.GetEntries())
149 glu = float(m.split(
"mGluino-").pop().split(
"_")[0])
150 lsp = float(m.split(
"mLSP-").pop().split(
"_")[0])
155 print "glu is " + str(glu)
156 print "lsp is " + str(lsp)
158 if "T1" in topo
or "T5" in topo:
160 elif "T2" in topo
or "T6" in topo:
163 print "tot = "+str(tot)
170 effs[0].append(reg4/tot)
171 yields[0].append(lumi*reg4)
172 effs[-1].append(reg3/tot)
173 yields[-1].append(lumi*reg3)
174 print "R4 is "+str(reg4)
175 print "eff = "+str(effs[0][-1])
176 print "completed "+str(sofar-1)+
" out of "+str(npoints)
178 for i,cut
in enumerate(bindefs):
184 effs[i+1].append(num/reg4)
187 yields[i+1].append(lumi*num)
191 outputFile = ROOT.TFile(
"plots/maps/"+outfile+
".root",
"recreate")
202 for j,vec
in enumerate(effs):
204 graphs.append(ROOT.TGraph2D(
"effmap",
"R4 Efficiency",len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",effs[j])))
205 graphs.append(ROOT.TGraph2D(
"yieldmap",
"R4 Yield",len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",yields[j])))
206 elif j-1 < len(cosmeticbindefs):
207 graphs.append(ROOT.TGraph2D(cosmeticbindefs[j-1],
"Fraction of R4 efficiency with "+cosmeticbindefs[j-1],len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",effs[j])))
208 graphs.append(ROOT.TGraph2D(cosmeticbindefs[j-1]+
"_yield",
"Yield in R4 with "+cosmeticbindefs[j-1],len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",yields[j])))
210 graphs.append(ROOT.TGraph2D(
"effmapR3",
"R3 Efficiency",len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",effs[j])))
211 graphs.append(ROOT.TGraph2D(
"yieldmapR3",
"R3 Yield",len(glumass),array(
"d",glumass),array(
"d",lspmass),array(
"d",yields[j])))
214 hist = graphs[-1].GetHistogram()
215 if(
"T1tttt" in topo):
216 val1 = hist.GetBinContent(hist.FindBin(700,0))
217 val2 = hist.GetBinContent(hist.FindBin(600,100))
221 graphs[-1].SetPoint(graphs[-1].GetN(),ROOT.Double(600.),0.,(val1+val2)/2.)
222 hist = graphs[-2].GetHistogram()
223 val1 = hist.GetBinContent(hist.FindBin(700,0))
224 val2 = hist.GetBinContent(hist.FindBin(600,100))
225 graphs[-2].SetPoint(graphs[-2].GetN(),ROOT.Double(600.),0.,(val1+val2)/2.)
233 outputFile = ROOT.TFile(infile,
"read")
239 if(
"T2" not in topo):
240 graphTitles.append([
"effmap",
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 4 Efficiency"])
241 graphTitles.append([
"yieldmap",
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 4 Yield"])
242 for name
in cosmeticbindefs:
243 graphTitles.append([name,
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Fraction of R4 efficiency from "+name])
244 graphTitles.append([name+
"_yield",
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; R4 Yield with "+name])
245 graphTitles.append([
"effmapR3",
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 3 Efficiency"])
246 graphTitles.append([
"yieldmapR3",
"; m_{#tilde{g}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 3 Yield"])
249 graphTitles.append([
"effmap",
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 4 Efficiency"])
250 graphTitles.append([
"yieldmap",
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 4 Yield"])
251 for name
in cosmeticbindefs:
252 graphTitles.append([name,
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Fraction of R4 efficiency from "+name])
253 graphTitles.append([name+
"_yield",
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; R4 Yield with "+name])
254 graphTitles.append([
"effmapR3",
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 3 Efficiency"])
255 graphTitles.append([
"yieldmapR3",
"; m_{#tilde{t}} [GeV]; m_{#tilde{#chi}^{0}_{1}} [GeV]; Region 3 Yield"])
261 for name,title
in graphTitles:
262 if "map" in name:
continue 264 graph = outputFile.Get(name)
265 if "yield" not in name:
266 if graph.GetHistogram().GetMaximum() > maxfrac: maxfrac = graph.GetHistogram().GetMaximum()
268 if graph.GetHistogram().GetMaximum() > maxyield: maxyield = graph.GetHistogram().GetMaximum()
273 if "T1" in topo
or "T5" in topo:
274 frame = ROOT.TH2F(
"frame",
"",100,700,1950,152,0,1450)
276 frame = ROOT.TH2F(
"frame",
"",100,700,1700,152,0,1300)
277 elif "T2" in topo
or "T6" in topo:
278 frame = ROOT.TH2F(
"frame",
"",100,200,1000,152,0,500)
280 frame.GetXaxis().SetNdivisions(506)
285 npx = int((1950-700)/17.68)
286 npy = int(1450/17.68)
287 if "T5tttt" in topo: npy = int(1300/17.68)
289 for name,title
in graphTitles:
290 graph = outputFile.Get(name)
291 graph.SetTitle(title)
292 frame.SetTitle(title)
296 if "map" not in name:
297 if"yield" not in name:
298 graph.GetHistogram().SetMaximum(maxfrac)
299 graph.GetHistogram().SetMinimum(0)
301 graph.GetHistogram().SetMaximum(maxyield)
302 graph.GetHistogram().SetMinimum(0.01)
312 graph.GetHistogram().SetAxisRange(700,1950,
"X")
313 graph.GetHistogram().SetAxisRange(0,1450,
"Y")
315 if(
"T5tttt" in topo):
317 graph.GetHistogram().GetXaxis().SetNdivisions(506)
320 graph.GetHistogram().Draw(
"colz same")
322 frame.Draw(
"X axis same")
325 tla.SetTextSize(0.038)
327 tla.DrawLatexNDC(0.14,0.93,
"#font[62]{CMS} #scale[0.8]{#font[52]{Supplementary (Simulation)}}")
328 if "T1tttt" in topo: tla.DrawLatexNDC(0.17,0.87,
"pp #rightarrow #tilde{g}#tilde{g}, #tilde{g} #rightarrow t#bar{t} #tilde{#chi}_{1}^{0}")
329 elif "T5tttt" in topo:
330 tla.DrawLatexNDC(0.17,0.87,
"pp #rightarrow #tilde{g}#tilde{g}, #tilde{g} #rightarrow #tilde{t}#bar{t}, #tilde{t} #rightarrow t#tilde{#chi}_{1}^{0}")
331 tla.DrawLatexNDC(0.2,0.82,
"m_{#tilde{t}} - m_{#tilde{#chi}_{1}^{0}} = 175 GeV")
332 elif "T5ZZ" in topo: tla.DrawLatexNDC(0.17,0.87,
"pp #rightarrow #tilde{g}#tilde{g}, #tilde{g} #rightarrow q#bar{q} #tilde{#chi}_{1}^{0}, #tilde{#chi}_{1}^{0} #rightarrow Z^{0} #tilde{G}")
334 if "yield" in name: tla.DrawLatexNDC(0.62,0.93, str(lumi)+
" fb^{-1} (13 TeV)")
335 else: tla.DrawLatexNDC(0.75,0.93,
"13 TeV")
338 if "yield" not in name:
339 outname =outfile+
"efficiency_"+name.replace(
" #leq",
"lte").replace(
" #geq",
"gte").replace(
" >",
"gt").replace(
" =",
"").replace(
", ",
"_").replace(
"H_{T}",
"ht").replace(
"n_{jets}",
"njets").replace(
"n_{lep}",
"nleps").replace(
"n_{b}",
"nbm").replace(
" ",
"")
341 outname =outfile+
"yield_"+name.replace(
" #leq",
"lte").replace(
" #geq",
"gte").replace(
" >",
"gt").replace(
" =",
"").replace(
", ",
"_").replace(
"H_{T}",
"ht").replace(
"n_{jets}",
"njets").replace(
"n_{lep}",
"nleps").replace(
"n_{b}",
"nbm").replace(
" ",
"")
342 c.Print(
"plots/maps/"+outname+
".pdf")
344 c.Print(
"plots/maps/log_"+outname+
".pdf")
def signalCrossSection(glu_mass)
def get_weighted_entries(chain, cuts)
def stopCrossSection(stop_mass)