def makeEffPlot(fs, sp, quantity, region): if sp is None: hDen = HG.getAddedSignalHistograms( FILES[fs], fs, '{}-Den-{}'.format(quantity, region))['{}-Den-{}'.format(quantity, region)] hNum = HG.getAddedSignalHistograms( FILES[fs], fs, '{}-Eff-{}'.format(quantity, region))['{}-Eff-{}'.format(quantity, region)] prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}{}'.format( prettyFS, ' + trigger' if ARGS.TRIGGER else '', ' wrt acc.' if region == 'Acc' else '') else: hDen = HG.getHistogram(FILES[fs], (fs, sp), '{}-Den-{}'.format(quantity, region)).Clone() hNum = HG.getHistogram(FILES[fs], (fs, sp), '{}-Eff-{}'.format(quantity, region)).Clone() prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}{}'.format( prettyFS, sp[0], sp[1], sp[2], ' + trigger' if ARGS.TRIGGER else '', ' wrt acc.' if region == 'Acc' else '') spstr = '{:4d} {:3d} {:4d}'.format( *sp) if sp is not None else '{:4s} {:3s} {:4s}'.format('', '', '') hNumInt = hNum.Integral(0, hNum.GetNbinsX() + 1) hDenInt = hDen.Integral(0, hDen.GetNbinsX() + 1) print '\033[m{:19s} {:5s} {:3s} {:13s} {:6.0f} {:6.0f} {:6.2%}\033[m'.format( ARGS.TAG, quantity, region, spstr, hNumInt, hDenInt, hNumInt / hDenInt)
def makeColorPlot(MUON, fs, quantity, sp=None, q2=None): if q2 is None: fstring = '{M}_{Q}VS{Q}'.format(M=MUON, Q=quantity) else: fstring = '{M}_{Q}ResVS{Q2}'.format(M=MUON, Q=quantity, Q2=q2) if sp is None: for i, SP in enumerate(SIGNALPOINTS): if i == 0: h = HistogramGetter.getHistogram(f, (fs, SP), fstring).Clone() else: h.Add(HistogramGetter.getHistogram(f, (fs, SP), fstring).Clone()) fname = 'pdfs/SRR_{}_{}HTo2XTo{}_Global.pdf'.format(fstring, 'Trig-' if TRIGGER else '', fs) else: h = HistogramGetter.getHistogram(f, (fs, sp), fstring).Clone() fname = 'pdfs/SRR_{}_{}HTo2XTo{}_{}.pdf'.format(fstring, 'Trig-' if TRIGGER else '', fs, SPStr(sp)) h.Rebin2D(10, 10) p = Plotter.Plot(h, '', '', 'colz') canvas = Plotter.Canvas(lumi=SPLumiStr(fs, *sp) if sp is not None else fs) canvas.mainPad.SetLogz(True) canvas.addMainPlot(p) canvas.scaleMargins(1.75, edges='R') canvas.scaleMargins(0.8, edges='L') canvas.cleanup(fname)
def makeEffPlot(fs, sp): hNum = HG.getHistogram(FILES[fs], (fs, sp), 'LxyEff').Clone() hDen = HG.getHistogram(FILES[fs], (fs, sp), 'LxyDen').Clone() hNum.Rebin(10) hDen.Rebin(10) g = R.TGraphAsymmErrors(hNum, hDen, 'cp') p = Plotter.Plot(g, '', '', 'p') prettyFS = '2#mu' if '2Mu' in fs else '4#mu' c = Plotter.Canvas( lumi='H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm)'.format( prettyFS, *sp), cWidth=600 if ARGS.SQUARE else 800) c.addMainPlot(p) p.setColor(R.kBlue, which='LM') c.firstPlot.SetMinimum(0.) c.firstPlot.SetMaximum(1.) c.firstPlot.setTitles(X='', Y='', copy=hNum) if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.cleanup('pdfs/VFE_Lxy_{}_{}_{}_{}.pdf'.format(fs, *sp), mode='LUMI')
def makeMCPlots(): f = R.TFile.Open('roots/PATMuonStudyPlots_Combined_BS8_MC.root') #f = R.TFile.Open('roots/PATMuonStudyPlots_Combined_BS8_MC_OldPATMatch.root') BGORDER = ('WJets', 'WW', 'WZ', 'ZZ', 'tW', 'tbarW', 'ttbar', 'QCD20toInf-ME', 'DY10to50', 'DY50toInf') PC = HG.PLOTCONFIG for hkey in ('PAT-LxySig', 'DSA-LxySig', 'PAT-vtxChi2', 'DSA-vtxChi2'): HISTS = {} HISTS['stack'] = R.THStack('hStack', '') PConfig = {'stack':('', '', 'hist')} for ref in BGORDER: HISTS[ref] = HG.getHistogram(f, ref, hkey).Clone() #RT.addFlows(HISTS[ref]) HISTS[ref].Scale(PC[ref]['WEIGHT']) HISTS[ref].Rebin(10) HISTS['stack'].Add(HISTS[ref]) PConfig[ref] = (PC[ref]['LATEX'], 'f', 'hist') PLOTS = {} for key in BGORDER + ('stack',): PLOTS[key] = Plotter.Plot(HISTS[key], *PConfig[key]) canvas = Plotter.Canvas(logy=True) for key in BGORDER: PLOTS[key].setColor(PC[key]['COLOR'], which='LF') canvas.addMainPlot(PLOTS['stack']) # this has to be here because it has to be drawn first if 'LxySig' in hkey: canvas.firstPlot.GetXaxis().SetRangeUser(0., 1000.) pass if 'vtxChi2' in hkey: #canvas.firstPlot.GetXaxis().SetRangeUser(0., 200.) pass canvas.firstPlot.setTitles(X='', copy=PLOTS[BGORDER[0]]) canvas.firstPlot.setTitles(Y='Normalized Counts') canvas.makeLegend(lWidth=.27, pos='tr', autoOrder=False, fontscale=0.8) for ref in reversed(BGORDER): canvas.addLegendEntry(PLOTS[ref]) canvas.legend.resizeHeight() RT.addBinWidth(canvas.firstPlot) HISTS['sum'] = HISTS['stack'].GetStack().Last() nBins = HISTS['sum'].GetNbinsX() if 'LxySig' in hkey: val = 100. if 'vtxChi2' in hkey: val = 50. print '{} Mean : {}'.format(hkey, HISTS['sum'].GetMean()) print '{} Overflow % : {}'.format(hkey, HISTS['sum'].GetBinContent( nBins+1)/HISTS['sum'].Integral(0, nBins+1)*100.) print '{} > {:<8.0f} % : {}'.format(hkey, val, HISTS['sum'].Integral (HISTS['sum'].FindBin(val), nBins+1)/HISTS['sum'].Integral(0, nBins+1)*100.) if hkey == 'PAT-LxySig': h = HG.getHistogram(f, 'DY50toInf', hkey).Clone() print '{} DY50toInf : {}'.format(hkey, h.Integral(h.FindBin(100.), h.GetNbinsX()+1)) canvas.firstPlot.SetMaximum(HISTS['sum'].GetMaximum()*1.05) canvas.firstPlot.SetMinimum(1.) canvas.cleanup('pdfs/MC_'+hkey+'.pdf')
def makeLxyEffPlot(key, colorAxis, fs, sp, pTCut=''): config = { 'Correct': ('Correct', 'Matches'), } if colorAxis == 'nMuons': num, den = config[key] nums = ['Lxy' + pTCut + '_n' + num + '_' + m for m in mnames] dens = ['Lxy' + pTCut + '_n' + den + '_' + m for m in mnames] tags = list(set(nums + dens)) legs = { num: m if 'All' in m else m + ' #mu' for num, m in zip(nums, mnames) } cols = {num: c for num, c in zip(nums, colors)} if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() for z in h: h[z].Rebin(10) p = {} graphs = {} for num, den in zip(nums, dens): realDen = h[den].Clone() graphs[num] = R.TGraphAsymmErrors(h[num], realDen, 'cp') p[num] = Plotter.Plot(graphs[num], legs[num], 'l', 'px') canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs) for tag in nums: canvas.addMainPlot(p[tag]) canvas.firstPlot.SetMaximum(1.01) canvas.firstPlot.SetMinimum(0.) canvas.firstPlot.setTitles(X=h[tags[0]].GetXaxis().GetTitle(), Y='Efficiency') for tag in p: p[tag].setColor(cols[tag], which='LM') canvas.makeLegend(lWidth=.275, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/RA_{}-Lxy{}-{}{}_HTo2XTo{}_{}.pdf'.format( 'ComboMu' if colorAxis == 'nMuons' else 'ComboEff', pTCut, key, ARGS.CUTSTRING, fs, SPStr(sp) if sp is not None else 'Global'))
def makeDistPlot(quantity, criteria, fs, sp=None): # configy type stuff legs = ('All', 'Matched', 'NotMatched') tags = [ quantity + '_' + ('All' + ('-4' if '-4' in criteria else '') if 'All' in leg else criteria + '_' + leg) for leg in legs ] cols = (R.kBlack, R.kBlue, R.kRed) # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() # make plots p = {} for i, tag in enumerate(tags): p[tag] = Plotter.Plot(h[tag], legs[i], 'l', 'hist') # canvas, plots, min max logy = True canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs, logy=logy) for tag in tags: canvas.addMainPlot(p[tag]) canvas.setMaximum() if not logy: canvas.firstPlot.SetMinimum(0) else: canvas.firstPlot.SetMinimum(1.) if 'Lxy' in quantity: canvas.firstPlot.GetXaxis().SetRangeUser(0., 330.) # colors for i, tag in enumerate(tags): p[tag].SetLineColor(cols[i]) # legend, cleanup canvas.makeLegend(lWidth=.2, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/LCD_{}Dist_{}{}_HTo2XTo{}_{}.pdf'.format( quantity, criteria, ARGS.CUTSTRING, fs, SPStr(sp) if sp is not None else 'Global'))
def makeStackPlot(key, colorAxis, fs, sp): if colorAxis == 'nMuons': tags = ['n' + key + '_' + m for m in mnames[1:]] legs = {tag: m + ' #mu' for tag, m in zip(tags, mnames[1:])} cols = {tag: R.kRed + i for i, tag in enumerate(tags)} elif colorAxis == 'Eff': tags = ['n' + k + '_' + key for k in hnames[1:]] legs = {tag: k for tag, k in zip(tags, hnames[1:])} cols = {tag: c for tag, c in zip(tags, colors[1:])} if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() h['stack'] = R.THStack('hBG' + key, '') p = {} for tag in tags: if fs == '4Mu' and 'Event' in tag and colorAxis == 'Eff': h[tag].Scale(2.) h['stack'].Add(h[tag]) p['stack'] = Plotter.Plot(h['stack'], '', '', 'hist' if colorAxis == 'nMuons' else 'nostack') for tag in tags: p[tag] = Plotter.Plot(h[tag], legs[tag], 'f', 'hist') for tag in tags: p[tag].setColor(cols[tag], which='LMF') canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs) for tag in ('stack', ): canvas.addMainPlot(p[tag]) if colorAxis == 'nMuons': canvas.setMaximum(recompute=True) canvas.firstPlot.SetMinimum(0.) canvas.makeLegend(lWidth=.2, pos='tr', autoOrder=False) canvas.firstPlot.setTitles(X=h[tags[0]].GetXaxis().GetTitle(), Y='Counts') for tag in tags: canvas.addLegendEntry(p[tag]) canvas.legend.resizeHeight() canvas.cleanup('pdfs/RA_{}-{}{}_HTo2XTo{}_{}.pdf'.format( 'StackMu' if colorAxis == 'nMuons' else 'StackEff', key, ARGS.CUTSTRING, fs, sp if sp is not None else 'Global'))
def makeLessMorePlot(fs, sp, quantity): h = { 'Less': HG.getHistogram(FILES[fs], (fs, sp), '{}-Less'.format(quantity)).Clone(), 'More': HG.getHistogram(FILES[fs], (fs, sp), '{}-More'.format(quantity)).Clone(), } for key in h: try: h[key].Scale(1. / h[key].Integral()) except: return pretty = { 'Less': { 'leg': 'L_{xy} < 320 cm', 'col': R.kBlue }, 'More': { 'leg': 'L_{xy} > 320 cm', 'col': R.kRed }, } p = { key: Plotter.Plot(h[key], pretty[key]['leg'], 'l', 'hist') for key in h } prettyFS = '2#mu' if '2Mu' in fs else '4#mu' c = Plotter.Canvas( lumi='H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm)'.format( prettyFS, *sp), cWidth=600 if ARGS.SQUARE else 800) for key in p: c.addMainPlot(p[key]) p[key].setColor(pretty[key]['col'], which='LM') RT.addBinWidth(c.firstPlot) c.makeLegend(lWidth=0.125, pos='tr') c.legend.resizeHeight() c.legend.moveLegend(X=-.4) c.setMaximum() if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.cleanup('pdfs/LESSMORE_{}_{}_{}_{}_{}.pdf'.format(quantity, fs, *sp), mode='LUMI')
def makeEffPlot(fs, sp): if sp is None: hNum = HG.getAddedSignalHistograms(FILES[fs], fs, 'Lxy-Num')['Lxy-Num'] hDen = HG.getAddedSignalHistograms(FILES[fs], fs, 'Lxy-Den')['Lxy-Den'] else: hNum = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Num').Clone() hDen = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Den').Clone() hNumInt = hNum.Integral(hNum.GetXaxis().FindBin(65.), hNum.GetNbinsX() + 1) hDenInt = hDen.Integral(hDen.GetXaxis().FindBin(65.), hDen.GetNbinsX() + 1) #if sp == (sp[0], sp[1], SIGNALS[sp[0]][sp[1]][0]): return print '{:5s} {:4d} {:3d} {:4d} ::: {:5.0f} {:5.0f} {:7.2%}'.format( fs, sp[0], sp[1], sp[2], hNumInt, hDenInt, hNumInt / hDenInt if hDenInt != 0. else 0.) return hNum.Rebin(2) hDen.Rebin(2) g = R.TGraphAsymmErrors(hNum, hDen, 'cp') p = Plotter.Plot(g, '', '', 'p') prettyFS = '2#mu' if '2Mu' in fs else '4#mu' if sp is not None: lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm)'.format( prettyFS, *sp) else: lumi = 'H#rightarrow2X#rightarrow{}, all samples combined'.format( prettyFS) c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) c.addMainPlot(p) p.setColor(R.kBlue, which='LM') c.firstPlot.SetMinimum(0.) c.firstPlot.SetMaximum(1.) c.firstPlot.setTitles(X='', copy=hNum) c.firstPlot.setTitles( Y='Efficiency for pairing criteria to select correct dimuons') if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.cleanup('pdfs/PC_Lxy_{}_{}.pdf'.format( fs, 'Global' if sp is None else SPStr(sp)), mode='LUMI')
def makePTCutPlot(fs, sp=None): # configy type stuff legs = ('All', 'Matched', 'Wrong', 'Right', 'Hopeless', 'Lost') tags = ['pT_' + tag for tag in legs] cols = (R.kBlack, R.kGreen, R.kOrange, R.kBlue, R.kRed, R.kMagenta) # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() # make plots p = {} for i, tag in enumerate(tags): p[tag] = Plotter.Plot(h[tag], legs[i], 'l', 'hist') # canvas, plots, min max logy = True canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs, logy=logy) for tag in tags: canvas.addMainPlot(p[tag]) canvas.setMaximum() if not logy: canvas.firstPlot.SetMinimum(0) else: canvas.firstPlot.SetMinimum(1.) #canvas.firstPlot.GetXaxis().SetRangeUser(0., 200.) canvas.firstPlot.GetXaxis().SetRangeUser(0., 30.) # colors for i, tag in enumerate(tags): p[tag].SetLineColor(cols[i]) # legend, cleanup canvas.makeLegend(lWidth=.2, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/HPD_pTDist_HTo2XTo{}_{}.pdf'.format( fs, SPStr(sp) if sp is not None else 'Global'))
def makeBinnedResPlot(MUON, fs, sp, quantity, q2): h = HistogramGetter.getHistogram(f, (fs, sp), '{M}_{Q}ResVS{Q2}'.format(M=MUON, Q=quantity, Q2=q2)).Clone() fname = 'pdfs/SRR_{}_{}_{}-Binned_{}HTo2XTo{}_{}.pdf'.format(MUON, quantity+'Res', q2, 'Trig-' if TRIGGER else '', fs, SPStr(sp)) pretty, binranges, values, colors, colors2, legName = getBinningValues(q2) projections = {key:h.ProjectionY('_'+str(i), key[0], key[1]) for i,key in enumerate(binranges)} plots = {key:Plotter.Plot(projections[key], legName.format(Q2=pretty, V1=values[key][0], V2=values[key][1]), 'l', 'hist') for key in binranges} canvas = Plotter.Canvas(lumi=SPLumiStr(fs, *sp)) for key in binranges: RT.addFlows(plots[key]) plots[key].Rebin(10) if plots[key].Integral() != 0: plots[key].Scale(1./plots[key].Integral()) canvas.addMainPlot(plots[key]) canvas.makeLegend(lWidth=.25, pos='tr') canvas.legend.moveLegend(X=-.08) canvas.legend.resizeHeight() canvas.setMaximum(recompute=True) for i, key in enumerate(binranges): plots[key].SetLineColor(colors[key]) plots[key].setTitles(X=plots[key].GetXaxis().GetTitle(), Y='Normalized Counts') canvas.drawText('#color[{}]{{'.format(colors2[key]) + 'RMS = {:.4f}'.format(plots[key].GetStdDev()) + '}', (canvas.legend.GetX1NDC()+.01, canvas.legend.GetY1NDC()-(i*0.04)-.04) ) RT.addBinWidth(canvas.firstPlot) canvas.cleanup(fname)
def makeDSASignal2DPlots(): for quantity in ('pT', 'eta', 'trkChi2'): hkey = 'DSA-12-' + quantity HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (hkey, )) if 'trkChi2' not in hkey: HISTS[hkey].Rebin2D(10, 10) for sp in SIGNALPOINTS: HISTS[sp] = HG.getHistogram(FILES[fs], (fs, sp), hkey).Clone() if 'trkChi2' not in hkey: HISTS[sp].Rebin2D(10, 10) opt = 'colz' #opt = 'scat=0.2' PLOTS = {hkey: Plotter.Plot(HISTS[hkey], '', '', opt)} for sp in SIGNALPOINTS: PLOTS[sp] = Plotter.Plot(HISTS[sp], '', '', opt) for sp in [ hkey, ] + SIGNALPOINTS: canvas = Plotter.Canvas(lumi=fs + lumiExtra.get(CUTSTRING) if type(sp) != tuple else SPLumiStr(fs, *sp)) canvas.addMainPlot(PLOTS[sp]) canvas.mainPad.SetLogz() if quantity == 'trkChi2': canvas.firstPlot.GetXaxis().SetRangeUser(0., 10.) canvas.firstPlot.GetYaxis().SetRangeUser(0., 10.) canvas.scaleMargins(1.75, edges='R') canvas.scaleMargins(0.8, edges='L') canvas.cleanup('pdfs/ZEP_2D_{}_{}_{}_{}.pdf'.format( quantity, CUTSTRING, fs, 'Global' if type(sp) != tuple else SPStr(sp)))
def makeEffPlot(quantity, den, fs, sp=None): tags = (quantity + '_MSD', quantity + '_LCD', quantity + '_CID') effTag = quantity + '_CID' # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() hNum = h[quantity + '_CID'] h[quantity + '_' + den].Add(h[quantity + '_CID']) hDen = h[quantity + '_' + den] graph = R.TGraphAsymmErrors(hNum, hDen, 'cp') # make plots p = Plotter.Plot(graph, '', 'l', 'px') # canvas, plots, min max canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs) canvas.addMainPlot(p) canvas.setMaximum() canvas.firstPlot.SetMinimum(0) # set titles canvas.firstPlot.setTitles(X=hNum.GetXaxis().GetTitle(), Y='Efficiency') # colors p.setColor(R.kBlue, which='M') # legend, cleanup #canvas.makeLegend(lWidth=.2, pos='tr') #canvas.legend.resizeHeight() canvas.cleanup('pdfs/3Mu_{}Eff-{}{}_HTo2XTo{}_{}.pdf'.format( quantity, den, ARGS.CUTSTRING, fs, SPStr(sp) if sp is not None else 'Global'))
def makeEffPlot(fs, sp): if sp is None: hNum = HG.getAddedSignalHistograms(FILES[fs], fs, ['nRec' + MUON for MUON in MUONS]) hDen = HG.getAddedSignalHistograms(FILES[fs], fs, ['nGen' + MUON for MUON in MUONS]) prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}'.format( prettyFS, ' + trigger' if ARGS.TRIGGER else '') else: hNum, hDen = {}, {} for MUON in MUONS: hNum['nRec' + MUON] = HG.getHistogram(FILES[fs], (fs, sp), 'nRec' + MUON).Clone() hDen['nGen' + MUON] = HG.getHistogram(FILES[fs], (fs, sp), 'nGen' + MUON).Clone() prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}'.format( prettyFS, sp[0], sp[1], sp[2], ' + trigger' if ARGS.TRIGGER else '') c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) pretty = {'DSA': {'col': R.kBlue}, 'RSA': {'col': R.kRed}} g, p = {}, {} for MUON in MUONS: hNum['nRec' + MUON].Rebin(10) hDen['nGen' + MUON].Rebin(10) g[MUON] = R.TGraphAsymmErrors(hNum['nRec' + MUON], hDen['nGen' + MUON], 'cp') p[MUON] = Plotter.Plot(g[MUON], MUON, 'l', 'p') c.addMainPlot(p[MUON]) p[MUON].setColor(pretty[MUON]['col'], which='LM') c.makeLegend(lWidth=0.125, pos='bl') c.legend.resizeHeight() c.firstPlot.SetMinimum(0.) c.firstPlot.SetMaximum(1.) c.firstPlot.setTitles(X='', Y='', copy=hNum['nRecDSA']) if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.cleanup('pdfs/REFF_Lxy{}_{}_{}.pdf'.format( '_Trig' if ARGS.TRIGGER else '', fs, 'Global' if sp is None else SPStr(sp)), mode='LUMI')
def makePlot(fs, sp, quantity): # configy type stuff tags = ('Matched', 'Junk') legs = {'Matched': 'Matched', 'Junk': 'Incorrect Pair'} cols = {'Matched': R.kBlue, 'Junk': R.kRed} # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram( f, (fs, SIGNALPOINTS[0]), quantity + '_' + tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add( HistogramGetter.getHistogram(f, (fs, SP), quantity + '_' + tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), quantity + '_' + tag).Clone() # make plots p = {} for tag in tags: p[tag] = Plotter.Plot(h[tag], legs[tag], 'l', 'hist') # canvas, plots, min max canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs, logy=True) for tag in tags: canvas.addMainPlot(p[tag]) canvas.setMaximum() # colors for tag in tags: p[tag].SetLineColor(cols[tag]) # legend, cleanup canvas.makeLegend(lWidth=.2, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/PV_{}{}_HTo2XTo{}_{}.pdf'.format( quantity, args.CUTSTRING, fs, SPStr(sp) if sp is not None else 'Global'))
def makeSplit4Plot(quantity, fs, sp=None): tags = [quantity + '_' + tag for tag in ('CID', 'MSD', 'LCD', 'UMD')] legs = dict( zip(tags, ('correct', 'signal', 'lowest #chi^{2}/dof', 'unmatched'))) cols = dict(zip(tags, (R.kBlue, R.kGreen, R.kMagenta, R.kRed))) # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() # make plots p = {} for tag in tags: p[tag] = Plotter.Plot(h[tag], legs[tag], 'l', 'hist') # canvas, plots, min max canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs, logy=True) for tag in tags: canvas.addMainPlot(p[tag]) canvas.setMaximum(scale=2.) canvas.firstPlot.SetMinimum(1.) # colors for tag in tags: p[tag].setColor(cols[tag], which='L') # legend, cleanup canvas.makeLegend(lWidth=.2, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/3Mu_{}Dist{}_HTo2XTo{}_{}.pdf'.format( quantity, ARGS.CUTSTRING, fs, SPStr(sp) if sp is not None else 'Global'))
def makeCombinedSignalPlots(fs, hkey): h = HistogramGetter.getHistogram(fSig, (fs, SIGNALPOINTS[0]), hkey).Clone() #h.Rebin2D(10, 10) for sp in SIGNALPOINTS[1:]: thisH = HistogramGetter.getHistogram(fSig, (fs, sp), hkey).Clone() #thisH.Rebin2D(10, 10) h.Add(thisH) p = Plotter.Plot(h, '', '', 'colz') if 'd0Sig' not in hkey: h.GetXaxis().SetRangeUser(0., 50.) h.GetYaxis().SetRangeUser(0., 20. / (2 if 'Err' in hkey else 1)) canvas = Plotter.Canvas() canvas.mainPad.SetLogz(True) canvas.addMainPlot(p) canvas.scaleMargins(1.75, edges='R') canvas.scaleMargins(0.8, edges='L') canvas.cleanup('pdfs/COR_{}_{}_{}.pdf'.format(fs, REGION, hkey))
def makePTCutPlot(fs, sp=None, PC=False, extra=''): # configy type stuff tags = TAGS[ARGS.FS + ('' if not PC else 'PC') + extra] legs = [CONFIG[tag]['LEG_H'] for tag in tags] cols = [CONFIG[tag]['COL'] for tag in tags] # get/add histograms if sp is None: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: for tag in tags: h[tag].Add(HistogramGetter.getHistogram(f, (fs, SP), tag)) else: h = {} for tag in tags: h[tag] = HistogramGetter.getHistogram(f, (fs, sp), tag).Clone() # make plots p = {} for i, tag in enumerate(tags): p[tag] = Plotter.Plot(h[tag], legs[i], 'l', 'hist') # canvas, plots, min max canvas = Plotter.Canvas(lumi=SPLumiStr(fs, sp) if sp is not None else fs) for tag in tags: canvas.addMainPlot(p[tag]) canvas.setMaximum() canvas.setMinimum() # colors for i, tag in enumerate(tags): p[tag].SetLineColor(cols[i]) # legend, cleanup canvas.makeLegend(lWidth=.275, pos='tr') canvas.legend.resizeHeight() canvas.cleanup('pdfs/PC_Match{}{}_HTo2XTo{}_{}.pdf'.format( '-PC' if PC else '', extra, fs, SPStr(sp) if sp is not None else 'Global'))
def getDenHist(SIG4, SEL=None): DENS = {} if SEL is None: for sel in SELS: FILES[sel].cd() htags = [quantity + '_All-4' if SIG4 else quantity + '_All'] for tag in htags: DENS[sel.lstrip('_')] = HistogramGetter.getHistogram( FILES[sel], (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: DENS[sel.lstrip('_')].Add( HistogramGetter.getHistogram( FILES[sel], (fs, SP), tag)) else: FILES[SEL].cd() if SIG4 is None: htags = [quantity + '_All', quantity + '_All-4'] for tag in htags: DENS[tag] = HistogramGetter.getHistogram( FILES[SEL], (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: DENS[tag].Add( HistogramGetter.getHistogram( FILES[SEL], (fs, SP), tag)) else: htags = [quantity + '_All-4' if SIG4 else quantity + '_All'] for tag in htags: DENS['All'] = HistogramGetter.getHistogram( FILES[SEL], (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: DENS['All'].Add( HistogramGetter.getHistogram( FILES[SEL], (fs, SP), tag)) return DENS
def makeMultipleEffPlot(fs, spList): hNum, hDen, g, p = {}, {}, {}, {} for sp in spList: hNum[sp] = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Num').Clone() hDen[sp] = HG.getHistogram(FILES[fs], (fs, sp), 'Lxy-Den').Clone() hNum[sp].Rebin(10) hDen[sp].Rebin(10) g[sp] = R.TGraphAsymmErrors(hNum[sp], hDen[sp], 'cp') p[sp] = Plotter.Plot( g[sp], 'm_{{H}} = {} GeV, m_{{X}} = {} GeV, c#tau = {} mm'.format(*sp), 'lp', 'p') prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{}'.format(prettyFS) c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) colors = (R.kRed, R.kAzure + 7, R.kGreen + 1) for col, sp in zip(colors, spList): c.addMainPlot(p[sp]) p[sp].setColor(col, which='LMF') c.makeLegend(lWidth=.7, pos='br', fontscale=.9) c.legend.SetMargin(0.1) c.legend.resizeHeight() c.firstPlot.SetMinimum(0.5) c.firstPlot.SetMaximum(1.) c.firstPlot.setTitles(X='', copy=hNum[spList[0]]) c.firstPlot.setTitles( Y='Efficiency for pairing criteria to select correct dimuons') if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.firstPlot.scaleTitleOffsets(1.2, 'Y') c.cleanup('pdfs/PC_Lxy_{}_Mul.pdf'.format(fs), mode='LUMI')
def makeHists(htags, SEL=None): HISTS = {} if SEL is None: for sel in SELS: FILES[sel].cd() # when SEL is None, htags is of length 1 for tag in htags: HISTS[sel.lstrip('_')] = HistogramGetter.getHistogram( FILES[sel], (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: HISTS[sel.lstrip('_')].Add( HistogramGetter.getHistogram( FILES[sel], (fs, SP), tag)) else: FILES[SEL].cd() for tag in htags: HISTS[tag] = HistogramGetter.getHistogram( FILES[SEL], (fs, SIGNALPOINTS[0]), tag).Clone() for SP in SIGNALPOINTS[1:]: HISTS[tag].Add( HistogramGetter.getHistogram(FILES[SEL], (fs, SP), tag)) return HISTS
def makeStackPlots(hkey): BGORDER = ('WJets', 'WW', 'WZ', 'ZZ', 'tW', 'tbarW', 'ttbar', 'QCD20toInf-ME', 'DY10to50', 'DY50toInf') PC = HistogramGetter.PLOTCONFIG h = HistogramGetter.getHistogram(fMC, BGORDER[0], hkey).Clone() h.Scale(PC[BGORDER[0]]['WEIGHT']) #h.Rebin2D(10, 10) for ref in BGORDER[1:]: thisH = HistogramGetter.getHistogram(fMC, ref, hkey).Clone() thisH.Scale(PC[ref]['WEIGHT']) #thisH.Rebin2D(10, 10) h.Add(thisH) p = Plotter.Plot(h, '', '', 'colz') if 'd0Sig' not in hkey: h.GetXaxis().SetRangeUser(0., 50.) h.GetYaxis().SetRangeUser(0., 20. / (2 if 'Err' in hkey else 1)) canvas = Plotter.Canvas() canvas.mainPad.SetLogz(True) canvas.addMainPlot(p) canvas.scaleMargins(1.75, edges='R') canvas.scaleMargins(0.8, edges='L') canvas.cleanup('pdfs/COR_MC_{}_{}.pdf'.format(REGION, hkey))
def makeRepEffectPlots(sp=None): lumi = 'H#rightarrow2X#rightarrow2#mu' if sp is None: lumi += ', all samples combined' else: lumi += ' ({} GeV, {} GeV, {} mm)'.format(*sp) hkeys = ('Lxy-before', 'Lxy-after') if sp is None: HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys) else: HISTS = {} for key in hkeys: HISTS[key] = HG.getHistogram(FILES['Signal'], ('2Mu2J', sp), key).Clone() nPass = HISTS['Lxy-after'].Integral( HISTS['Lxy-after'].GetXaxis().FindBin(65.), HISTS['Lxy-after'].GetNbinsX() + 1) nTot = HISTS['Lxy-before'].Integral( HISTS['Lxy-before'].GetXaxis().FindBin(65.), HISTS['Lxy-before'].GetNbinsX() + 1) print nPass / nTot for key in hkeys: HISTS[key].Rebin(2) g = R.TGraphAsymmErrors(HISTS['Lxy-after'], HISTS['Lxy-before'], 'cp') p = Plotter.Plot(g, '', '', 'p') canvas = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) canvas.addMainPlot(p) p.setColor(R.kBlue) canvas.firstPlot.setTitles(X='generated L_{xy} [cm]', Y='Dimuons after / before association') canvas.firstPlot.SetMaximum(1.) canvas.firstPlot.SetMinimum(0.) if ARGS.SQUARE: canvas.firstPlot.scaleTitleOffsets(1.1, 'X') canvas.cleanup('pdfs/REPEFF_Signal_{}.pdf'.format( 'Global' if sp is None else SPStr(sp)), mode='LUMI')
def makeResPlot(fs, sp): if sp is None: h = HG.getAddedSignalHistograms(FILES[fs], fs, ['pTRes-' + MUON for MUON in MUONS]) prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{}, all samples combined{}'.format( prettyFS, ' + trigger' if ARGS.TRIGGER else '') else: h = {} for MUON in MUONS: h['pTRes-' + MUON] = HG.getHistogram(FILES[fs], (fs, sp), 'pTRes-' + MUON).Clone() prettyFS = '2#mu' if '2Mu' in fs else '4#mu' lumi = 'H#rightarrow2X#rightarrow{} ({} GeV, {} GeV, {} mm){}'.format( prettyFS, sp[0], sp[1], sp[2], ' + trigger' if ARGS.TRIGGER else '') c = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) pretty = {'DSA': {'col': R.kBlue}, 'RSA': {'col': R.kRed}} p = {} for MUON in MUONS: h['pTRes-' + MUON].Scale( 1. / h['pTRes-' + MUON].Integral(0, h['pTRes-' + MUON].GetNbinsX() + 1)) #h['pTRes-'+MUON].Rebin(10) p[MUON] = Plotter.Plot(h['pTRes-' + MUON], MUON, 'l', 'hist') c.addMainPlot(p[MUON]) p[MUON].setColor(pretty[MUON]['col'], which='LM') c.makeLegend(lWidth=0.125, pos='tr') c.legend.resizeHeight() c.setMaximum() c.firstPlot.setTitles(X='', Y='', copy=h['pTRes-DSA']) RT.addBinWidth(c.firstPlot) if ARGS.SQUARE: c.firstPlot.scaleTitleOffsets(1.1, 'X') c.firstPlot.scaleTitleOffsets(1.3, 'Y') c.cleanup('pdfs/PTRES{}_{}_{}.pdf'.format( '_Trig' if ARGS.TRIGGER else '', fs, 'Global' if sp is None else SPStr(sp)), mode='LUMI')
def fillDistributionParameters(MUON, fs, sp, quantity): # get histograms and define plots h = HistogramGetter.getHistogram(f, (fs, sp), MUON+'_'+quantity+'_Matched').Clone() mean = h.GetMean() sigma = h.GetStdDev() overflow = h.GetBinContent(h.GetNbinsX()+1) if sp not in DATA[fs]: DATA[fs][sp] = {} if MUON not in DATA[fs][sp]: DATA[fs][sp][MUON] = {} if quantity not in DATA[fs][sp][MUON]: DATA[fs][sp][MUON][quantity] = { 'mean':0, 'sigma':0, 'overflow':0, } DATA[fs][sp][MUON][quantity]['mean' ] = mean DATA[fs][sp][MUON][quantity]['sigma'] = sigma DATA[fs][sp][MUON][quantity]['overflow'] = overflow
def makeBinnedResPlotBinwise(MUONS, outputTag, quantity, q2, fs, sp): defaultColorOrder = (R.kRed, R.kBlue, R.kGreen, R.kMagenta) h = {} for MUON in MUONS: h[MUON] = HistogramGetter.getHistogram(f, (fs, sp), '{M}_{Q}ResVS{Q2}'.format(M=MUON, Q=quantity, Q2=q2)).Clone() # leaving space for the bin number fname = 'pdfs/SRR_{}_{}_{}-Binned-Bin-{{}}_{}HTo2XTo{}_{}.pdf'.format(outputTag, quantity+'Res', q2, 'Trig-' if TRIGGER else '', fs, SPStr(sp)) pretty, binranges, values, colors, colors2, legName = getBinningValues(q2) for i, key in enumerate(binranges): canvas = Plotter.Canvas(lumi=SPLumiStr(fs, *sp)) projections, plots = {}, {} for j, MUON in enumerate(MUONS): projections[MUON] = h[MUON].ProjectionY('_'+str(i)+'_'+str(j), key[0], key[1]) plots[MUON] = Plotter.Plot(projections[MUON], MUON, 'l', 'hist') RT.addFlows(plots[MUON]) plots[MUON].Rebin(10) if plots[MUON].Integral() != 0: plots[MUON].Scale(1./plots[MUON].Integral()) plots[MUON].SetLineColor(defaultColorOrder[j]) canvas.addMainPlot(plots[MUON]) canvas.makeLegend(lWidth=.25, pos='tr') canvas.legend.resizeHeight() canvas.setMaximum(recompute=True) canvas.drawText(legName.format(Q2=pretty, V1=values[key][0], V2=values[key][1]), (canvas.legend.GetX1NDC()+.01, canvas.legend.GetY1NDC()-.04)) for j, MUON in enumerate(MUONS): plots[MUON].SetLineColor(defaultColorOrder[j]) plots[MUON].setTitles(X=plots[MUON].GetXaxis().GetTitle(), Y='Normalized Counts') canvas.drawText('#color[{}]{{'.format(defaultColorOrder[j]) + 'RMS = {:.4f}'.format(plots[MUON].GetStdDev()) + '}', (canvas.legend.GetX1NDC()+.01, canvas.legend.GetY1NDC()-(j*0.04)-.08) ) RT.addBinWidth(canvas.firstPlot) canvas.cleanup(fname.format(i+1))
def makeSignal2DPlots(): for quantity in ('normChi2', 'nTrkLay', 'nPxlHit', 'highPurity', 'isGlobal', 'isMedium', 'hitsBeforeVtx', 'missingHitsAfterVtx'): if quantity == 'nTrkLay': R.gStyle.SetPaintTextFormat('.1f') else: R.gStyle.SetPaintTextFormat('g') hkey = 'PAT-12-' + quantity HISTS = HG.getAddedSignalHistograms(FILES[fs], fs, (hkey, )) for sp in SIGNALPOINTS: HISTS[sp] = HG.getHistogram(FILES[fs], (fs, sp), hkey).Clone() if quantity != 'normChi2': opt = 'colz text' else: opt = 'colz' PLOTS = {hkey: Plotter.Plot(HISTS[hkey], '', '', opt)} for sp in SIGNALPOINTS: PLOTS[sp] = Plotter.Plot(HISTS[sp], '', '', opt) for sp in [ hkey, ] + SIGNALPOINTS: canvas = Plotter.Canvas(lumi=fs + lumiExtra.get(CUTSTRING) if type(sp) != tuple else SPLumiStr(fs, *sp)) canvas.addMainPlot(PLOTS[sp]) canvas.firstPlot.SetMarkerColor(R.kWhite) if quantity == 'normChi2': canvas.firstPlot.GetXaxis().SetRangeUser(0., 10.) canvas.firstPlot.GetYaxis().SetRangeUser(0., 10.) canvas.scaleMargins(1.75, edges='R') canvas.scaleMargins(0.8, edges='L') canvas.cleanup('pdfs/ZEP_2D_{}_{}_{}_{}.pdf'.format( quantity, CUTSTRING, fs, 'Global' if type(sp) != tuple else SPStr(sp)))
def fillData(fs, sp, quantity, factor): # get histograms s = HG.getHistogram(FILES['Signal'], (fs, sp), '{}_{}'.format(quantity, factor)).Clone() DHists, DPConfig = HG.getDataHistograms(FILES['Data'], '{}_1'.format(quantity), addFlows=False) b = DHists['{}_1'.format(quantity)]['data'] if SignalInfo[sp]['sigmaBLimit'] == 0.: return s.Scale(ScaleFactor(sp, factor, 1.e-2)) # get cumulatives sCum = s.GetCumulative(CONFIG[quantity]['forward']) bCum = b.GetCumulative(CONFIG[quantity]['forward']) # fill f.o.m. histogram, and keep track of max f.o.m. and cut value nBins = sCum.GetNbinsX() xAxis = sCum.GetXaxis() fom_max = 0. opt_cut = 0. opt_s = 0. opt_b = 0. for ibin in range(1,nBins+1): S, B, cutVal, FOMs = calculateFOM(s, b, sCum, bCum, nBins, ibin, xAxis, CONFIG[quantity]['forward']) if FOMs[FIGURE_OF_MERIT] > fom_max: fom_max = FOMs[FIGURE_OF_MERIT] opt_cut = cutVal opt_s = S opt_b = B # for each (mH, mX) pair, store the xvalue: cTau (mm) / 10 -> cm, divided by factor # this will run for each sample point, meaning afterwards, the (mH, mX) x and y lists # will have len(factors) * 2 (maybe 3 if we put the small lifetimes in) points masses = (sp[0], sp[1]) cTau = sp[-1] DATA[masses][quantity]['x'].append(cTau/10./factor) DATA[masses][quantity]['y'].append(opt_cut)
def fillData(fs, sp, quantity, hkey): # get histograms s = HG.getHistogram(FILES['Signal'], (fs, sp), hkey) DHists, DPConfig = HG.getDataHistograms(FILES['Data'], hkey, addFlows=False) b = DHists[hkey]['data'] if SignalInfo[sp]['sigmaBLimit'] == 0.: return s.Scale(ScaleFactor(sp, sigmaB=1.e-2)) # get cumulatives sCum = s.GetCumulative(CONFIG[quantity]['forward']) bCum = b.GetCumulative(CONFIG[quantity]['forward']) # fill f.o.m. histogram, and keep track of max f.o.m. and cut value nBins = sCum.GetNbinsX() xAxis = sCum.GetXaxis() data = [] for ibin in range(1, nBins + 1): S, B, cutVal, FOMs = calculateFOM(s, b, sCum, bCum, nBins, ibin, xAxis, CONFIG[quantity]['forward']) for gridPoint in CONFIG[quantity]['VALS']: if abs(cutVal - gridPoint) < .01: data.append({ 'cut': cutVal, 'ZBi': FOMs['ZBi'], 'ZPL': FOMs['ZPL'], 's': S, 'b': B }) break DATA[hkey] = data
def makeResPlots(metric, quantity, sp=None): PRETTY = { 'pTRes_hits_less': { 'mnice': 'p_{T} res.', 'qnice': 'N(hits)', 'leg': 'N(hits) #leq 12', 'col': R.kRed }, 'pTRes_hits_more': { 'mnice': 'p_{T} res.', 'qnice': 'N(hits)', 'leg': 'N(hits) > 12', 'col': R.kBlue }, 'pTRes_fpte_less': { 'mnice': 'p_{T} res.', 'qnice': '#sigma_{p_{T}}/p_{T}', 'leg': '#sigma_{p_{T}}/p_{T} < 1', 'col': R.kBlue }, 'pTRes_fpte_more': { 'mnice': 'p_{T} res.', 'qnice': '#sigma_{p_{T}}/p_{T}', 'leg': '#sigma_{p_{T}}/p_{T} #geq 1', 'col': R.kRed }, 'qdiff_hits_less': { 'mnice': 'charge diff.', 'qnice': 'N(hits)', 'leg': 'N(hits) #leq 12', 'col': R.kRed }, 'qdiff_hits_more': { 'mnice': 'charge diff.', 'qnice': 'N(hits)', 'leg': 'N(hits) > 12', 'col': R.kBlue }, 'qdiff_fpte_less': { 'mnice': 'charge diff.', 'qnice': '#sigma_{p_{T}}/p_{T}', 'leg': '#sigma_{p_{T}}/p_{T} < 1', 'col': R.kBlue }, 'qdiff_fpte_more': { 'mnice': 'charge diff.', 'qnice': '#sigma_{p_{T}}/p_{T}', 'leg': '#sigma_{p_{T}}/p_{T} #geq 1', 'col': R.kRed }, } witches = ('less', 'more') if quantity == 'fpte' else ('more', 'less') hkeys = ['{}_{}_{}'.format(metric, quantity, which) for which in witches] if sp is None: HISTS = HG.getAddedSignalHistograms(FILES['Signal'], '2Mu2J', hkeys) else: HISTS = {} for key in hkeys: HISTS[key] = HG.getHistogram(FILES['Signal'], ('2Mu2J', sp), key).Clone() PLOTS = {} for key in hkeys: HISTS[key].Scale(1. / HISTS[key].Integral(0, HISTS[key].GetNbinsX() + 1)) #RT.addFlows(HISTS[key]) PLOTS[key] = Plotter.Plot(HISTS[key], PRETTY[key]['leg'], 'l', 'hist') #canvas = Plotter.Canvas(lumi='{} by {}'.format(PRETTY[hkeys[0]]['mnice'], PRETTY[hkeys[0]]['qnice'])) lumi = 'H#rightarrow2X#rightarrow2#mu' if sp is None: lumi += ', all samples combined' else: lumi += ' ({} GeV, {} GeV, {} mm)'.format(*sp) canvas = Plotter.Canvas(lumi=lumi, cWidth=600 if ARGS.SQUARE else 800) for key in hkeys: canvas.addMainPlot(PLOTS[key]) PLOTS[key].setColor(PRETTY[key]['col'], which='L') canvas.firstPlot.SetMinimum(0.) canvas.setMaximum() if metric == 'qdiff': canvas.firstPlot.SetMaximum(1.) canvas.firstPlot.setTitles(Y='Density') if 'qdiff' in hkeys[0]: canvas.firstPlot.SetNdivisions(3) canvas.makeLegend(lWidth=0.27, pos='tr') canvas.legend.resizeHeight() RT.addBinWidth(canvas.firstPlot) if ARGS.SQUARE: canvas.firstPlot.scaleTitleOffsets(1.1, 'X') if metric == 'pTRes': canvas.firstPlot.scaleTitleOffsets(1.3, 'Y') canvas.cleanup('pdfs/QCUTRES_Sig_{}_{}_{}.pdf'.format( metric, quantity, 'Global' if sp is None else SPStr(sp)), mode='LUMI')