def showShapes(resultsDir,name,plotTitle,mass,boson,lumi,plotData=True,showPseudoData=True,showAllBkgs=True,plotpfix=''): """ show the shapes corresponding to a given analysis """ colors=[ROOT.kGreen+1,ROOT.kAzure+3,ROOT.kOrange+2,ROOT.kGray,ROOT.kRed+2] shapeFiles=[os.path.join(resultsDir,f) for f in os.listdir(resultsDir) if 'shapes_' in f and '.root' in f] for f in shapeFiles: fIn=ROOT.TFile.Open(f) #check consistency of the file with the boson to plot if 'shapes_22' in f and boson=='g': v='g' channel='#gamma' elif 'shapes_169' in f and boson=='z': v='zmm' channel='Z#rightarrow#mu#mu' elif 'shapes_121' in f and boson=='z': v='zee' channel='Z#rightarrowee' else: continue bkgH = fIn.Get('bkg_%s'%v) fidsigH = fIn.Get('fidsig_%s_m%d'%(v,mass)) outfidsigH = fIn.Get('outfidsig_%s_m%d'%(v,mass)) dataH = fIn.Get('data_obs_%s'%(v)) if showPseudoData: dataH.Reset('ICE') nexp=bkgH.Integral() if fidsigH: nexp+=bkgH.Integral() if outfidsigH: nexp+=outfidsigH.Integral() for iev in range( ROOT.gRandom.Poisson( nexp ) ): dataH.Fill( bkgH.GetRandom() ) try: p=Plot('%s_%s_inc%s'%(name,v,plotpfix)) p.xtit='Missing mass [GeV]' p.ytit='Events' if fidsigH: p.add(fidsigH, title='fiducial #scale[0.8]{(%d)}'%mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=False, isSyst=False) if showAllBkgs: if outfidsigH: p.add(outfidsigH, title='non-fiducial', color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=False, isSyst=False) p.add(bkgH, title='background', color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False) else: allBkg=bkgH.Clone('allbkg') if outfidsigH : allBkg.Add(outfidsigH) p.add(allBkg, title='background', color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False) if plotData: dtitle='pseudo-data' if showPseudoData else 'Data' p.add(dataH, title=dtitle, color=1, isData=True, spImpose=False, isSyst=False) if fidsigH: p.add(fidsigH.Clone(), title=plotTitle+'#scale[0.8]{(%d)}'%mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=True, isSyst=False) if showAllBkgs and outfidsigH: p.add(outfidsigH.Clone(), title='non-fiducial', color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=True, isSyst=False) p.ratiorange=[0.68,1.32] p.show('./',lumi*1000,extraText=plotTitle) #background systs p=Plot('%s_%s_inc_bkgunc%s'%(name,v,plotpfix)) p.noErrorsOnRatio=True p.doPoissonErrorBars=False p.xtit='Missing mass [GeV]' p.ytit='Events' p.add(bkgH, title='background', color=1, isData=True,spImpose=False, isSyst=False) ic=0 for syst,title in [('Up', 'e#mu mix'), ('SingleDiffUp', 'single arm mix')]: h=fIn.Get('bkg_%s_bkgShape%s'%(v,syst)) p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic+=1 p.ratiorange=[0.76,1.24] p.show('./',lumi,noStack=True,extraText=plotTitle) #signal systs if fidsigH: p=Plot('%s_%s_sigunc%s'%(name,v,plotpfix)) #fidsigH.Scale(1./5.) p.doPoissonErrorBars=False p.noErrorsOnRatio=True p.xtit='Missing mass [GeV]' p.ytit='Events' p.add(fidsigH, title='signal', color=1, isData=True,spImpose=False, isSyst=False) ic=0 for syst,title in [('ShapeUp', 'e#mu mix.'), ('CalibUp', 'Time dependence'), ('PPSEffUp', 'PPS efficiency'), ('PzModelUp', 'p_{z}(pp)')]: h=fIn.Get('fidsig_%s_m%d_sig%s'%(v,mass,syst)) print ic,syst,title,h p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic+=1 p.ratiorange=[0.5,1.46] p.show('./',lumi,noStack=True,extraText=plotTitle) #out fiducial signal systs if outfidsigH: p=Plot('%s_%s_outfidsigunc%s'%(name,v,plotpfix)) #outfidsigH.Scale(1./5.) p.doPoissonErrorBars=False p.noErrorsOnRatio=True p.xtit='Missing mass [GeV]' p.ytit='Events' p.add(outfidsigH, title='out-fid. signal', color=1, isData=True,spImpose=False, isSyst=False) ic=0 for syst,title in [('ShapeUp', 'e#mu mix.'), ('CalibUp', 'Time dependence'), ('PPSEffUp', 'PPS efficiency'), ('PzModelUp', 'p_{z}(pp)')]: h=fIn.Get('outfidsig_%s_m%d_sig%s'%(v,mass,syst)) p.add(h, title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic+=1 p.ratiorange=[0.5,1.46] p.show('./',lumi,noStack=True,extraText=plotTitle) except Exception as e: print e pass fIn.Close()
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)
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, isSyst=False, doDivideByBinWidth=True) #p.add(h=rwScenariosH[(172.5,2.0)].Clone(), title=rwScenariosH[(172.5,2.0)].GetTitle(),color=3,isData=False,spImpose=False,isSyst=False,doDivideByBinWidth=True)
def showShapes(resultsDir, name, title, mass, boson, r95, sig, lumi, plotData=True, showPseudoData=True, showAllBkgs=True): """ show the shapes corresponding to a given analysis """ shapeFiles = [ os.path.join(resultsDir, f) for f in os.listdir(resultsDir) if 'shapes_' in f and '.root' in f ] for f in shapeFiles: try: angle = int(re.search('_a(\d+)', f).group(1)) except: print 'No angle could be parsed, assuming this is an inclusive analysis' angle = None fIn = ROOT.TFile.Open(f) #check consistency of the file with the boson to plot if 'shapes_22' in f and boson == 'g': v = 'g' channel = '#gamma' elif 'shapes_169' in f and boson == 'z': v = 'zmm' channel = 'Z#rightarrow#mu#mu' elif 'shapes_121' in f and boson == 'z': v = 'zee' channel = 'Z#rightarrowee' else: continue for icat in range(2): if angle: bkgH = fIn.Get('bkg_%s_a%d_%d' % (v, angle, icat)) fidsigH = fIn.Get('fidsig_%s_a%d_%d_m%d' % (v, angle, icat, mass)) outfidsigH = fIn.Get('outfidsig_%s_a%d_%d_m%d' % (v, angle, icat, mass)) dataH = fIn.Get('data_obs_%s_a%d_%d' % (v, angle, icat)) else: bkgH = fIn.Get('bkg_%s_%d' % (v, icat)) fidsigH = fIn.Get('fidsig_%s_%d_m%d' % (v, icat, mass)) outfidsigH = fIn.Get('outfidsig_%s_%d_m%d' % (v, icat, mass)) dataH = fIn.Get('data_obs_%s_%d' % (v, icat)) print bkgH, fidsigH, outfidsigH, dataH try: fidsigH.Scale(5) outfidsigH.Scale(5) except: fidsigH = None outfidsigH = None if showPseudoData: dataH.Reset('ICE') nexp = bkgH.Integral() if fidsigH: nexp += bkgH.Integral() if outfidsigH: nexp += outfidsigH.Integral() for iev in range(ROOT.gRandom.Poisson(nexp)): dataH.Fill(bkgH.GetRandom()) try: #main shapes if angle: p = Plot('%s_%s_a%d_cat%d' % (name, v, angle, icat)) else: p = Plot('%s_%s_inc_cat%d' % (name, v, icat)) p.xtit = 'Missing mass [GeV]' p.ytit = 'Events' if fidsigH: p.add(fidsigH, title='#scale[0.5]{5x}' + title + '#scale[0.8]{(%d)}' % mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=False, isSyst=False) if showAllBkgs: if outfidsigH: p.add(outfidsigH, title='#scale[0.5]{5x}non-fiducial', color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=False, isSyst=False) p.add(bkgH, title='background', color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False) else: allBkg = bkgH.Clone('allbkg') if outfidsigH: allBkg.Add(outfidsigH) p.add(allBkg, title='background', color=ROOT.TColor.GetColor('#1f78b4'), isData=False, spImpose=False, isSyst=False) if plotData: dtitle = 'pseudo-data' if showPseudoData else 'Data' p.add(dataH, title=dtitle, color=1, isData=True, spImpose=False, isSyst=False) if fidsigH: p.add(fidsigH.Clone(), title=title + '#scale[0.8]{(%d)}' % mass, color=ROOT.TColor.GetColor('#fdc086'), isData=False, spImpose=True, isSyst=False) if showAllBkgs and outfidsigH: p.add(outfidsigH.Clone(), title='non-fiducial', color=ROOT.TColor.GetColor('#a6cee3'), isData=False, spImpose=True, isSyst=False) p.ratiorange = [0.68, 1.32] subcatName = 'low pileup' if icat == 0 else 'high pileup' if angle: extraText = '%s, %d#murad\\%s' % (channel, angle, subcatName) else: extraText = '%s, inclusive\\%s' % (channel, subcatName) if r95: extraText += '\\#mu_{95}(exp.)<%3.3f' % r95 if sig: extraText += '\\S(exp.)=%3.3f' % sig p.show('./', lumi * 1000, extraText=extraText) colors = [ROOT.kGreen + 1, ROOT.kAzure + 3, ROOT.kRed + 2] #background systs if angle: p = Plot('%s_%s_a%d_cat%d_bkgunc' % (name, v, angle, icat)) else: p = Plot('%s_%s_inc_cat%d_bkgunc' % (name, v, icat)) p.noErrorsOnRatio = True p.doPoissonErrorBars = False p.xtit = 'Missing mass [GeV]' p.ytit = 'Events' p.add(bkgH, title='background', color=1, isData=True, spImpose=False, isSyst=False) ic = 0 for syst, title in [('Up', 'Pileup spec.'), ('SingleDiffUp', 'Single diff.')]: if angle: p.add(fIn.Get('bkg_%s_a%d_%d_bkgShape%s' % (v, angle, icat, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) else: p.add(fIn.Get('bkg_%s_inc_%d_bkgShape%s' % (v, icat, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic += 1 p.ratiorange = [0.76, 1.24] if angle: extraText = '%s, %d#murad' % (channel, angle) else: extraText = '%s, inclusive' % (channel) p.show('./', lumi, noStack=True, extraText=extraText) #signal systs if fidsigH: if angle: p = Plot('%s_%s_a%d_cat%d_sigunc' % (name, v, angle, icat)) else: p = Plot('%s_%s_inc_cat%d_sigunc' % (name, v, icat)) fidsigH.Scale(1. / 5.) p.doPoissonErrorBars = False p.noErrorsOnRatio = True p.xtit = 'Missing mass [GeV]' p.ytit = 'Events' p.add(fidsigH, title='signal', color=1, isData=True, spImpose=False, isSyst=False) ic = 0 for syst, title in [('ShapeUp', 'Pileup spec.'), ('CalibUp', 'Time dependence'), ('PzModelUp', 'p_{z}(pp)')]: if angle: p.add(fIn.Get('fidsig_%s_a%d_%d_m%d_sig%s' % (v, angle, icat, mass, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) else: p.add(fIn.Get('fidsig_%s_%d_m%d_sig%s' % (v, icat, mass, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic += 1 p.ratiorange = [0.76, 1.24] if angle: extraText = '%s, %d#murad\\m_{X}=%d GeV' % ( channel, angle, mass) else: extraText = '%s, inclusive\\m_{X}=%d GeV' % (channel, mass) p.show('./', lumi, noStack=True, extraText=extraText) #out fiducial signal systs if outfidsigH: if angle: p = Plot('%s_%s_a%d_cat%d_outfidsigunc' % (name, v, angle, icat)) else: p = Plot('%s_%s_inc_cat%d_outfidsigunc' % (name, v, icat)) outfidsigH.Scale(1. / 5.) p.doPoissonErrorBars = False p.noErrorsOnRatio = True p.xtit = 'Missing mass [GeV]' p.ytit = 'Events' p.add(outfidsigH, title='out-fid. signal', color=1, isData=True, spImpose=False, isSyst=False) ic = 0 for syst, title in [('ShapeUp', 'Pileup spec.'), ('CalibUp', 'Time dependence'), ('PzModelUp', 'p_{z}(pp)')]: if angle: p.add(fIn.Get('outfidsig_%s_a%d_%d_m%d_sig%s' % (v, angle, icat, mass, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) else: p.add(fIn.Get('outfidsig_%s_%d_m%d_sig%s' % (v, icat, mass, syst)), title=title, color=colors[ic], isData=False, spImpose=False, isSyst=False) ic += 1 p.ratiorange = [0.76, 1.24] if angle: extraText = '%s, %d#murad\\m_{X}=%d GeV' % ( channel, angle, mass) else: extraText = '%s, inclusive\\m_{X}=%d GeV' % (channel, mass) p.show('./', lumi, noStack=True, extraText=extraText) except Exception as e: print e pass fIn.Close()
import ROOT import sys from TopLJets2015.TopAnalysis.Plot import * ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptTitle(0) ROOT.gROOT.SetBatch(True) colors = [ ROOT.kBlack, ROOT.kGreen + 1, ROOT.kAzure + 1, ROOT.kRed + 1, ROOT.kGray ] p = Plot('limitcomparison') p.spimposeOpt = 'l' p.xtit = 'm_{X} [GeV]' p.ytit = '95% CL limits on #sigma_{fid}#timesBR [pb]' for i in range(len(sys.argv) - 1): name, url = sys.argv[i + 1].split(':') fIn = ROOT.TFile.Open(url) c = fIn.Get('c') gr = c.GetListOfPrimitives().At(2).GetListOfGraphs().At(2) gr.SetLineWidth(3) gr.SetLineStyle(1 + i % 2) p.add(gr, title=name, color=colors[i], isData=False, spImpose=True, isSyst=False) fIn.Close() p.show('./', lumi=37500, noRatio=True) p.reset()
xangle=120 ROOT.gROOT.SetBatch(True) ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptTitle(0) ROOT.gStyle.SetPaintTextFormat("4.2f"); for ppsEffFile in ['PreliminaryEfficiencies_October92019_1D2DMultiTrack.root', #'pixelEfficiencies.root' ]: ppsEffReader=PPSEfficiencyReader(os.path.join(baseDir,ppsEffFile)) for rp in [23,123]: p=Plot('raddameff_%d'%rp,com='13 TeV') p.range=[0,1] p.xtit='#xi' p.ytit='Efficiency' for i,era in enumerate(['B','C','D','E','F']): gr=ROOT.TGraphErrors() gr.SetMarkerStyle(20+i) gr.SetTitle('2017'+era) for xi in np.linspace(0,0.2,50): ip=gr.GetN() eff,effUnc=ppsEffReader.getPPSEfficiency('2017'+era,xangle,xi,rp) gr.SetPoint(ip,xi,eff) gr.SetPointError(ip,0,effUnc) p.add(gr,'2017'+era, color=1, isData=False, spImpose=True, isSyst=False) p.show(outDir='./', lumi=37500)