def drawPlots(data, mc, period): """draw final plots comparing distributions in data and in mc""" files = {'data': data, 'mc': mc} base = 'passStrip' baseTitle = '=2 strip' base = 'passPix' baseTitle = '=2 px' for d, pfix in [ ('xangle', ''), #('nvtx',''), ('yboson',''), ('dyboson',''), #('n','RP003'), ('n','RP023'), ('n','RP103'), ('n','RP123'), #('csi','RP003'), ('csi','RP023'), ('csi','RP103'), ('csi','RP123'), ('mpp', 'far'), ('mpp', 'near'), ('mmass', 'far'), ('mmass', 'near'), #('dmpp',''), ('dmmass',''), ]: hpercat = {} for tag in ['', 'matched']: for x in files: for cat in [base, 'passPixandpassStrip']: try: hpercat[(x, tag, cat)] = files[x].Get( '%s_%s%s%s' % (d, cat, tag, pfix)) hpercat[(x, tag, cat)].SetDirectory(0) hpercat[(x, tag, cat)].Sumw2() hpercat[(x, tag, cat)].GetYaxis().SetTitle('PDF') except: pass #remove overlap #hpercat[(x,tag,base)].Add(hpercat[(x,tag,'passPixandpassStrip')],-1) #build the total hpercat[(x, tag, 'tot')] = hpercat[(x, tag, base)].Clone( 'tot_%s_%s' % (d, tag)) hpercat[(x, tag, 'tot')].Add(hpercat[(x, tag, 'passPixandpassStrip')]) hpercat[(x, tag, 'tot')].SetDirectory(0) ntot = hpercat[(x, tag, 'tot')].Integral() continue for cat in [base, 'passPixandpassStrip']: hpercat[(x, tag, cat)].Scale(1. / ntot) if tag == '': print base, hpercat[('data', '', base)].Integral() print base + 'passPixandpassStrip', hpercat[( 'data', '', 'passPixandpassStrip')].Integral() print '\t', hpercat[('data', '', base)].Integral() / hpercat[ ('data', '', 'passPixandpassStrip')].Integral() continue if tag == 'matched': continue p = Plot('%s%s_%s_era%s' % (d, pfix, tag, period), com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False p.add(hpercat[('data', tag, base)], title=baseTitle, color=633, isData=False, spImpose=False, isSyst=False) p.add(hpercat[('data', tag, 'passPixandpassStrip')], title='=2 px+strip', color="#fdc086", isData=False, spImpose=False, isSyst=False) try: hpercat[('mc', tag, 'tot')].Scale( 1. / hpercat[('mc', tag, 'tot')].Integral()) p.add(hpercat[('mc', tag, 'tot')], title='signal', color=1, isData=False, spImpose=True, isSyst=False) except: pass p.show(outDir='./', lumi=37500, noStack=False) continue #efficiency effgr = {} for x, ms in [('data', 20), ('mc', 24)]: effgr[x] = ROOT.TGraphAsymmErrors() effgr[x].Divide(hpercat[(x, 'matched', 'tot')], hpercat[(x, '', 'tot')]) effgr[x].SetMarkerStyle(ms) effgr[x].SetTitle(x) effgr[x].SetName(x) p = Plot('%s%s_eff_era%s' % (d, pfix, period), com='13 TeV') p.ytit = 'Efficiency' p.xtit = hpercat[(x, 'matched', 'tot')].GetXaxis().GetTitle() p.savelog = False p.range = [1e-3, 1] #p.add(effgr['mc'], title='MC', color=ROOT.kCyan+1, isData=False, spImpose=True, isSyst=False) p.add(effgr['data'], title='Data', color=1, isData=False, spImpose=True, isSyst=False) p.show(outDir='./', lumi=37500, noStack=True)
'genmass'), getDist(url, 'rwgt_genmass')) rwScenariosMassH[key][0].SetName('mass%d' % len(rwScenariosH)) rwScenariosMassH[key][1].SetName('rwmass%d' % len(rwScenariosH)) rwScenariosMassH[key][0].SetTitle('(172.5,1.32)') rwScenariosMassH[key][1].SetTitle('(%3.1f,%3.2f) wgt' % key) norig = rwScenariosMassH[key][0].Integral() rwScenariosMassH[key][0].Scale(1. / norig) rwScenariosMassH[key][1].Scale(1. / norig) ROOT.gStyle.SetOptTitle(0) ROOT.gStyle.SetOptStat(0) ROOT.gROOT.SetBatch(True) p = Plot('mlbwidth_closure', '13 TeV') p.ratiorange = [0.958, 1.042] p.savelog = True p.doPoissonErrorBars = False p.range = (1e-4, 0.014) p.ytit = 'PDF' p.add(h=simScenariosH[(172.5, 0.90)].Clone(), title=simScenariosH[(172.5, 0.90)].GetTitle(), color=1, isData=True, spImpose=False, isSyst=False, doDivideByBinWidth=True) p.add(h=rwScenariosH[(172.5, 0.90)].Clone(), title=rwScenariosH[(172.5, 0.90)].GetTitle(), color=2, isData=False, spImpose=False,
def drawPlots(): """draw final plots comparing distributions in data""" def fillHistos(fIn, histos, era, ch): eraKey = (era, ch) for k in fIn.GetListOfKeys(): kname = k.GetName() hname = kname.split('_')[0] tag = ''.join(kname.split('_')[1:]) key = (hname, tag) if not key in histos: histos[key] = {} histos[key][eraKey] = k.ReadObj().Clone(kname + '%s_%d' % (era, ch)) histos[key][eraKey].SetDirectory(0) histos[key][eraKey].GetYaxis().SetTitle('PDF') return histos histos = {} for era, ch in list(product(list('BCDEF'), [11 * 11, 13 * 13])): fIn = ROOT.TFile.Open('RPcontrol_era%s_ch%d.root' % (era, ch)) fillHistos(fIn, histos, era, ch) fIn.Close() perAlgo = ['multi', 'px', 'strip'] perAlgoPlusInc = perAlgo + [''] + ['a120', 'a130', 'a140', 'a150'] perSide = product(perAlgo, ['pos', 'posinc', 'neg', 'neginc']) colors = ["#fdc086", "#7fc97f", "#DCDCDC", 633, "#386cb0", 9] for d, tags in [ #('n', perSide), #('csi', perSide), #('mpp', perAlgo), ##('mmass', perAlgo), ('nvtx', perAlgoPlusInc), #('xangle', perAlgoPlusInc), ('ptll', perAlgoPlusInc), #('nch', perAlgoPlusInc), #('rue', perAlgoPlusInc), #('met', perAlgoPlusInc), #('dphimetz', perAlgoPlusInc), ]: hglobal = None hperAlgo = {} hperXangle = {} for tag in tags: hinc = None hperEra = {} hperCh = {} key = (d, ''.join(tag)) if not key in histos: continue for eraKey, h in histos[key].items(): era, ch = eraKey #global inclusive histogram if len(tag) == 0: print key, eraKey if hglobal is None: hglobal = h.Clone(d + '_global') hglobal.SetDirectory(0) else: hglobal.Add(h) #inclusive histogram (this tag only) if hinc is None: hinc = h.Clone(d + '_inc') hinc.SetDirectory(0) else: hinc.Add(h) #per angle histos if len(tag) == 4 and tag[0] == 'a': xangle = tag[1:] print key, xangle if not xangle in hperXangle: hperXangle[xangle] = h.Clone(d + '_' + xangle) hperXangle[xangle].SetDirectory(0) else: hperXangle[xangle].Add(h) #per era histogram if not era in hperEra: hperEra[era] = h.Clone('%s_%s' % (d, era)) hperEra[era].SetDirectory(0) else: hperEra[era].Add(h) #per ch histogram if not ch in hperCh: hperCh[ch] = h.Clone('%s_%d' % (d, ch)) hperCh[ch].SetDirectory(0) else: hperCh[ch].Add(h) #per algo histogram algo = tag algoExtra = None if d == 'csi' and not 'inc' in tag[1]: algo = tag[0] algoExtra = '_pos' if 'pos' in tag[1] else '_neg' if isinstance(algo, str) and (algo in perAlgo + ['']): algoKey = algo if algoExtra: algoKey += algoExtra if not algoKey in hperAlgo: hperAlgo[algoKey] = h.Clone('%s_%s' % (d, algoKey)) hperAlgo[algoKey].SetDirectory(0) else: hperAlgo[algoKey].Add(h) if hinc is None: continue hinc.Scale(1. / hinc.Integral()) #per era p = Plot('%s_%s_perEra' % key, com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False for i, era in enumerate(hperEra.keys()): hperEra[era].Scale(1. / hperEra[era].Integral()) p.add(hperEra[era], title=era, color=colors[i], isData=False, spImpose=False, isSyst=False) p.add(hinc.Clone(), title='total', color=1, isData=False, spImpose=True, isSyst=False) p.show(outDir='./', lumi=37500, noStack=True) #per ch p = Plot('%s_%s_perCh' % key, com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False for i, ch in enumerate(hperCh.keys()): hperCh[ch].Scale(1. / hperCh[ch].Integral()) p.add(hperCh[ch], title='ee' if ch == 11 * 11 else '#mu#mu', color=colors[i], isData=False, spImpose=False, isSyst=False) p.add(hinc.Clone(), title='total', color=1, isData=False, spImpose=True, isSyst=False) p.show(outDir='./', lumi=37500, noStack=True) #per xangle p = Plot('%s_perxangle' % d, com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False for i, xangle in enumerate(['120', '130', '140', '150']): hperXangle[xangle].Scale(1. / hperXangle[xangle].Integral()) spImpose = True if xangle == '' else False title = '%s#murad' % xangle ci = colors[i] p.add(hperXangle[xangle], title=title, color=ci, isData=False, spImpose=spImpose, isSyst=False) if hglobal: hglobal.Scale(1. / hglobal.Integral()) p.add(hglobal.Clone(), title='total', color=1, isData=False, spImpose=True, isSyst=False) try: p.show(outDir='./', lumi=37500, noStack=True) except Exception as e: print d, e #per algo p = Plot('%s_peralgo' % d, com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False for i, algo in enumerate(hperAlgo.keys()): hperAlgo[algo].Scale(1. / hperAlgo[algo].Integral()) spImpose = True if algo == '' else False title = 'inclusive' if algo == '' else algo title = title.replace('_pos', ' (+)') title = title.replace('_neg', ' (-)') ci = colors[i] if algo != '' else 1 p.add(hperAlgo[algo], title=title, color=ci, isData=False, spImpose=spImpose, isSyst=False) p.show(outDir='./', lumi=37500, noStack=True)
var = totalMCShape.GetBinContent(xbin) if nom == 0: continue r = abs(1 - var / nom) np = relShapeGr.GetN() relShapeGr.SetPoint(np, xcen, 1) relShapeGr.SetPointError(np, 0.5 * xwid, r) relShapeGr.SetFillStyle(3354) #3001) relShapeGr.SetFillColor(ROOT.kGray + 3) #ROOT.kRed) relShapeGr.SetLineWidth(2) totalMCShape.Delete() #show finalOutpName = outpName if countOnly: finalOutpName += '_count' plot = Plot(finalOutpName) plot.savelog = True plot.wideCanvas = False plot.doMCOverData = False plot.ratioFrameFill = 3444 plot.ratioFrameColor = 1 #plot.ratiorange=(0.655,1.385) doDivideByBinWidth = False if 'mlb' in outpName or 'ptlb' in outpName: doDivideByBinWidth = True if relShapeGr: plot.relShapeGr = relShapeGr plot.plotformats = ['pdf', 'png'] for key in ['Data', 't#bar{t}', 'Single top', 'W', 'DY', 'Multiboson']: if not key in plotsPerProc: continue isData = True if 'Data' in plotsPerProc[key].GetTitle() else False color = COLORS[plotsPerProc[key].GetTitle()] if key == 'DY': plotsPerProc[key].Scale(0.83) plot.add(plotsPerProc[key], plotsPerProc[key].GetTitle(), color,
def drawPlots(data, period): """draw final plots comparing distributions in data and in mc""" base = 'passStrip' baseTitle = '=2 strip' base = 'passPix' baseTitle = '=2 px' for d, pfix in [ ('xangle', ''), ('nvtx', ''), ('yboson', ''), ('dyboson', ''), ('n', 'RP003'), ('n', 'RP023'), ('n', 'RP103'), ('n', 'RP123'), ('csi', 'RP003'), ('csi', 'RP023'), ('csi', 'RP103'), ('csi', 'RP123'), ('mpp', 'far'), ('mpp', 'near'), ('mmass', 'far'), ('mmass', 'near'), ('dmpp', ''), ('dmmass', ''), ]: hpercat = {} for tag in ['', 'matched']: for cat in [base, 'passPixandpassStrip']: try: hpercat[(tag, cat)] = data.Get('%s_%s%s%s' % (d, cat, tag, pfix)) hpercat[(tag, cat)].SetDirectory(0) hpercat[(tag, cat)].Sumw2() hpercat[(tag, cat)].GetYaxis().SetTitle('PDF') except Exception as e: print e pass #build the total hpercat[(tag, 'tot')] = hpercat[(tag, base)].Clone('tot_%s_%s' % (d, tag)) hpercat[(tag, 'tot')].Add(hpercat[(tag, 'passPixandpassStrip')]) hpercat[(tag, 'tot')].SetDirectory(0) ntot = hpercat[(tag, 'tot')].Integral() continue for cat in [base, 'passPixandpassStrip']: hpercat[(tag, cat)].Scale(1. / ntot) if tag == '': print base, hpercat[('', base)].Integral() print base + 'passPixandpassStrip', hpercat[( '', 'passPixandpassStrip')].Integral() print '\t', hpercat[('', base)].Integral() / hpercat[ ('', 'passPixandpassStrip')].Integral() continue if tag == 'matched': continue p = Plot('%s%s_%s_era%s' % (d, pfix, tag, period), com='13 TeV') p.savelog = True p.range = [1e-3, 1] p.doPoissonErrorBars = False p.add(hpercat[(tag, base)], title=baseTitle, color=633, isData=False, spImpose=False, isSyst=False) p.add(hpercat[(tag, 'passPixandpassStrip')], title='=2 px+strip', color="#fdc086", isData=False, spImpose=False, isSyst=False) p.show(outDir='./', lumi=37500, noStack=False) continue