def plotSelection(histoList, name, log=False, xlabel='', normed=False): plot = Canvas.Canvas(name, 'png', 0.15, 0.77, 0.9, 0.88, 1) sel = [] ymax = 0.0 for histo in histoList: _f = r.TFile(histo[0]) aux_h = copy.deepcopy(_f.Get(histo[1])) if normed: aux_h.Scale(1 / aux_h.Integral()) if aux_h.GetMaximum() > ymax: ymax = aux_h.GetMaximum() for h, histo in enumerate(histoList): _f = r.TFile(histo[0]) _h = copy.deepcopy(_f.Get(histo[1])) _f.Close() _h.GetXaxis().SetTitle(xlabel) if normed: _h.Scale(1 / _h.Integral()) _h.GetYaxis().SetTitle('Event density') else: _h.GetYaxis().SetTitle('Events') if log: _h.SetMaximum(10.0 * ymax) else: _h.SetMaximum(1.3 * ymax) option = 'HIST' if h != 0: option = 'HIST, SAME' plot.addHisto(_h, option, histo[3], 'l', histo[2], 1, h) plot.save(1, 0, log, '', '', outputDir='plots')
def makeAgreementTest(lumi, histo1, histo2, ylog, label1, label2, labela, labelb, name, isData, xlabel = '', outtag = '', yshift = 0.0, LLlabel = '', rebin = 0, rmin = 0.9, rmax = 1.1, maxY = False): ## Histogram tunning if rebin: histo1.Rebin(rebin) histo2.Rebin(rebin) histo1.SetTitle('; Collinearity |#Delta#Phi|; Dimuon pairs') histo1.SetMaximum(1.45*histo1.GetMaximum()) histo1.SetMinimum(0.0) histo1.SetMarkerStyle(20) histo2.SetMarkerStyle(24) plot = Canvas.Canvas(name, 'png,pdf', 0.15, 0.66, 0.45, 0.78, 1) plot.addHisto(histo1, 'P', label1, 'p', r.kBlack, 1, 0) plot.addHisto(histo2, 'P,SAME', label2, 'p', r.kBlue, 1, 1) plot.addLatex(0.16, 0.8, labela, font = 42, size = 0.037, align = 11) plot.addLatex(0.88, 0.88, labelb, font = 42, size = 0.045, align = 31) plot.saveRatio(1, 0, 0, '', histo1, histo2, r_ymin = rmin, r_ymax = rmax, label = 'Ratio', xlog = False, outputDir = WORKPATH + 'SymmetryResults/', maxYnumbers = maxY) print('>>>>>>>>>> KOLMOGOROV test for ' + labela) print('>>>>>>>>>> ' + str(histo1.KolmogorovTest(histo2))) print('>>>>>>>>>> Chi2 test for ' + labela) print('>>>>>>>>>> ' + str(histo1.Chi2Test(histo2, "WWP"))) return
def makePlot(lumi, lumi_str, treeDA, treeMC, var, name, nbin, xmin, xmax, theCut, cuts, labelx, logx, protection): MC = treeMC.getTH1F(lumi, "hMC_%s"%(name), var, nbin, xmin, xmax, theCut, '', labelx) MCS = treeMC.getStack(lumi, "hMCS_%s"%(name), var, nbin, xmin, xmax, theCut, "", labelx) DATA = treeDA.getTH1F(lumi, "hDATA_%s"%(name), var, nbin, xmin, xmax, theCut, '', labelx) maxValmc = MC.GetMaximum() #GetBinContent(MC.GetMaximumBin()) maxValdata = DATA.GetMaximum() #GetBinContent(DATA.GetMaximumBin()) maxVal = max(maxValmc, maxValdata) if not logx: MC.GetYaxis().SetRangeUser(0.1, 1.3*maxVal) MCS.SetMaximum(1.3*maxVal) DATA.GetYaxis().SetRangeUser(0.1, 1.3*maxVal) else: MC.GetYaxis().SetRangeUser(0.1, 2.0*maxVal) MCS.SetMaximum(2.0*maxVal) DATA.GetYaxis().SetRangeUser(0.1, 2.0*maxVal) print "DATA integral ", DATA.Integral() print "MC integral ", MC.Integral() SetOwnership(MC, 0 ) # 0 = release (not keep), 1 = keep SetOwnership(MCS, 0 ) # 0 = release (not keep), 1 = keep SetOwnership(DATA, 0 ) # 0 = release (not keep), 1 = keep plot = Canvas.Canvas('DataMC/%s/plot_%s'%(lumi_str,name), 'png,pdf,root', 0.65, 0.6, 0.85, 0.9) plot.addStack(MCS, "HIST", 1, 1) plot.addHisto(DATA, "E1,SAME", "Data", "P", r.kBlack, 1, 0) plot.saveRatio(1, 1, logx, lumi, DATA, MC)
def makeValidation(lumi, treeMC, var, name, xlabel, logx, LLlabel=False): hSR_MC = treeMC.getLoopTH1F('histMC_SR_' + name, 'SR_' + var, xlabel) hCR_MC = treeMC.getLoopTH1F('histMC_CR_' + name, 'CR_' + var, xlabel) hSR_MC.SetMarkerStyle(20) hSR_MC.SetMarkerSize(0.8) hCR_MC.SetMarkerStyle(20) hCR_MC.SetMarkerSize(0.8) luminosity = lumi ### Get maximum maxValCR = hCR_MC.GetMaximum() maxValSR = hSR_MC.GetMaximum() maxVal = max(maxValCR, maxValSR) ### Set Maximum if not logx: hCR_MC.SetMaximum(1.3 * maxVal) hSR_MC.SetMaximum(1.3 * maxVal) else: hCR_MC.SetMaximum(100.0 * maxVal) hSR_MC.SetMaximum(100.0 * maxVal) hCR_MC.SetMinimum(0.1) hSR_MC.SetMaximum(0.1) ### Canvas object plot = Canvas.Canvas('hist_' + name, 'png', 0.7, 0.79, 0.9, 0.87) plot.addHisto(hCR_MC, 'P', 'Control region', 'l', r.kBlue, 1, 0) plot.addHisto(hSR_MC, 'P, SAME', 'Signal region', 'l', r.kRed, 1, 0) ### Dilepton banner if LLlabel == 'EE': plot.addLatex(0.17, 0.84, 'e^{+}e^{-} channel') if LLlabel == 'MM': plot.addLatex(0.17, 0.84, '#mu^{+}#mu^{-} channel') ### Save it #plot.save(1, 0, logx, luminosity, '') plot.saveRatio(1, 0, logx, luminosity, hSR_MC, hCR_MC, label="SR/CR", outputDir='closurePlots/')
def makeDataMCPlot(lumi, hname, hnameDATA, ylog, treeMC, treeDATA, inputdir, treeSI=False, xlabel='', outtag='', yshift=100.0, LLlabel='', DATAlabel='', extralabel='', xlog=False): luminosity = lumi hSS = treeDATA.getLoopTH1F(inputdir, hnameDATA) hOS = treeMC.getLoopStack(inputdir, hname) # hSS tunning: hSS.SetLineColor(r.kBlack) hSS.SetFillColor(r.kMagenta + 1) hSS.SetTitle('QCD, W+jets') #print(hSS.GetEntries()) ### Combine SS + OS contributions: hBKG = r.THStack('hBKG_%s' % (hname), ';' + hOS.GetXaxis().GetTitle() + ';' + hOS.GetYaxis().GetTitle()) # Background stacked hBKGtotal = copy.deepcopy(hSS) # Background total (for ratio) hBKG.Add(copy.deepcopy(hSS)) for _h in hOS.GetHists(): _h.Scale(lumi / 35.87) hBKG.Add(copy.deepcopy(_h)) hBKGtotal.Add(copy.deepcopy(_h)) nBCK = len(hOS.GetHists()) + 1 hBKGtotal.SetMarkerStyle(20) # Auxiliar to save the ratio correctly ### Signal histograms s_histos = [] if treeSI: hSIS = treeSI.getLoopStack(inputdir, hname) for _i, _h in enumerate(hSIS.GetHists()): s_histos.append(copy.deepcopy(_h)) ### Data histogram hDATA = treeDATA.getLoopTH1F(inputdir, hname) hDATA.SetMarkerStyle(20) hDATA.SetMarkerSize(0.8) ### Get maximum maxValMC = hBKGtotal.GetMaximum() maxValSI = 0 if not treeSI else max( [s_histos[i].GetMaximum() for i in range(0, len(s_histos))]) maxValDATA = 0 if not treeDATA else hDATA.GetMaximum() maxVal = max([maxValMC, maxValSI, maxValDATA]) ### Set Maximum if not ylog: hBKG.SetMaximum(1.3 * maxVal) hBKG.SetMinimum(0.0) hBKGtotal.SetMaximum(1.3 * maxVal) hBKGtotal.SetMinimum(0.0) if treeSI: for _h in s_histos: if not yshift: _h.SetMaximum(1.3 * maxVal) else: _h.SetMaximum(yshift * maxVal) _h.SetMinimum(0.0) if treeDATA: if not yshift: hDATA.SetMaximum(1.3 * maxVal) else: hDATA.SetMaximum(yshift * maxVal) hDATA.SetMinimum(0.0) else: if not yshift: hBKG.SetMaximum(10.0 * maxVal) else: hBKG.SetMaximum(yshift * maxVal) hBKG.SetMinimum(0.1) if not yshift: hBKGtotal.SetMaximum(10.0 * maxVal) else: hBKGtotal.SetMaximum(yshift * maxVal) hBKGtotal.SetMinimum(0.1) if treeSI: for _h in s_histos: if not yshift: _h.SetMaximum(10.0 * maxVal) else: _h.SetMaximum(yshift * maxVal) _h.SetMinimum(0.1) if treeDATA: if not yshift: hDATA.SetMaximum(10.0 * maxVal) else: hDATA.SetMaximum(yshift * maxVal) hDATA.SetMinimum(0.1) ### -> Canvas object if treeDATA: plot = Canvas.Canvas(hname, 'png', 0.6, 0.65, 0.85, 0.9, 1) else: plot = Canvas.Canvas(hname, 'png', 0.6, 0.79, 0.9, 0.9, 1) ### Add background: plot.addStack(hBKG, 'HIST', 1, 0) # Background ### Add signals: if treeSI: for i, _h in enumerate(s_histos): _h.SetLineWidth(2) # provisional plot.addHisto(_h, 'HIST, SAME', _h.GetTitle(), 'l', _h.GetFillColor(), 1, i + nBCK) # Signal ### Add DATA: if treeDATA: plot.addHisto(hDATA, 'P, SAME', 'Data', 'p', r.kBlack, 1, nBCK + len(s_histos)) ### DATAlabel banner: if DATAlabel: plot.addLatex(0.17, 0.85, DATAlabel, font=62) ### Channel banner: if LLlabel == 'EE': plot.addLatex(0.17, 0.81, 'e^{+}e^{-} channel', font=42) if LLlabel == 'MM': plot.addLatex(0.17, 0.81, '#mu^{+}#mu^{-} channel', font=42) ### Extralabel: if extralabel: plot.addLatex(0.17, 0.76, extralabel, font=42) ### Save it outdir = os.path.dirname(os.path.abspath( __main__.__file__)) + '/Plots_' + outtag + '/' if treeDATA: plot.saveRatio(1, 0, ylog, luminosity, hDATA, hBKGtotal, label="Data/BKG", outputDir=outdir, xlog=xlog) else: plot.save(1, 0, ylog, luminosity, '', outputDir=outdir)
print('WORKPATH: ' + WORKPATH) r.setTDRStyle() ########################### #### Parser object #### ########################### parser = optparse.OptionParser(usage='usage: %prog [opts] FilenameWithSamples', version='%prog 1.0') parser.add_option('-t', '--tag', action='store', type=str, dest='tag', default='', help='Output tag') (opts, args) = parser.parse_args() histo = getObject('Vertex-results/th1f_TT2018.root', 'EE_vxIvyI') histo.GetZaxis().SetLabelSize(0.03) histo.GetXaxis().SetTitle('Dielectron vertex x_{PV} (cm)') histo.GetYaxis().SetTitle('Dielectron vertex y_{PV} (cm)') plot = Canvas.Canvas('hist_EE_vxIvyI', 'png,pdf', 0.3, 0.75, 0.89, 0.8, 1) plot.addHisto(histo, 'COLZ', '', 'f', '', 1, 0) plot.addLatex(0.9, 0.93, 't#bar{t} (dilep.) 2018 UL', size = 0.03, align = 31) plot.save(0, 0, 0, '', '', outputDir = WORKPATH + 'harvested/', inProgress = False, maxYnumbers = 2) histo = getObject('Vertex-results/th1f_TT2018.root', 'EE_vx1vy1') histo.GetZaxis().SetLabelSize(0.03) histo.GetXaxis().SetTitle('Dielectron vertex x_{1} (cm)') histo.GetYaxis().SetTitle('Dielectron vertex y_{1} (cm)') plot = Canvas.Canvas('hist_EE_vx1vy1', 'png,pdf', 0.3, 0.75, 0.89, 0.8, 1) plot.addHisto(histo, 'COLZ', '', 'f', '', 1, 0) plot.addLatex(0.9, 0.93, 't#bar{t} (dilep.) 2018 UL', size = 0.03, align = 31) plot.save(0, 0, 0, '', '', outputDir = WORKPATH + 'harvested/', inProgress = False, maxYnumbers = 3) histo = getObject('Vertex-results/th1f_TT2018.root', 'EE_vx2vy2') histo.GetZaxis().SetLabelSize(0.03)
hist_1000_350_1.SetLineWidth(2) hist_1000_350_10 = getObject('Results/th1f_signals.root', 'hist_E_relTrkIso_log_HSS_1000_350_10_2016') hist_1000_350_10.Scale(1. / hist_1000_350_10.Integral()) hist_1000_350_10.SetLineColor(r.kBlue - 4) hist_1000_350_10.SetLineWidth(2) hist_1000_350_100 = getObject( 'Results/th1f_signals.root', 'hist_E_relTrkIso_log_HSS_1000_350_100_2016') hist_1000_350_100.Scale(1. / hist_1000_350_100.Integral()) hist_1000_350_100.SetLineColor(r.kBlue - 7) hist_1000_350_100.SetLineWidth(2) plot = Canvas.Canvas('hist_electron_relTrkIso', 'png,pdf', 0.17, 0.55, 0.45, 0.89, 1, lsize=0.028) plot.addHisto(hist_bkg, 'HIST', 'Background: Hadronic WZ, WW decays', 'f', '', 1, 0) plot.addHisto(hist_125_50_1, 'HIST,SAME', 'm_{H} = 125 GeV, m_{S} = 50 GeV, c#tau = 1 mm', 'l', '', 1, 1) plot.addHisto(hist_125_50_10, 'HIST,SAME', 'm_{H} = 125 GeV, m_{S} = 50 GeV, c#tau = 10 mm', 'l', '', 1, 2) plot.addHisto(hist_125_50_100, 'HIST,SAME', 'm_{H} = 125 GeV, m_{S} = 50 GeV, c#tau = 100 mm', 'l', '', 1, 3) plot.addHisto(hist_400_50_1, 'HIST,SAME',
def makeSymmetryTest(lumi, hname, ylog, tree, inputdir, label, name, isData, xlabel='', outtag='', yshift=0.0, LLlabel='', rebin=0, maxY=False): ## Get the histogram if type(hname) != list: hist = tree.getLoopTH1F(inputdir, hname) else: hist = tree.getLoopTH1F(inputdir, hname[0]) for n in range(1, len(hname)): hist.Add(tree.getLoopTH1F(inputdir, hname[n])) nbins = int(hist.GetNbinsX() / 2.0) xmin = 0.0 # default xmax = 3.14 / 2.0 # default ## Define forward and inverted backward histograms forward = r.TH1F('Forward', ';;Event yield', nbins, xmin, xmax) invBackward = r.TH1F('InvBackward', ';;Event yield', nbins, xmin, xmax) for n in range(1, nbins + 1): forward.SetBinContent(n, hist.GetBinContent(n)) invBackward.SetBinContent(n, hist.GetBinContent(2 * nbins + 1 - n)) forward.SetBinError(n, hist.GetBinError(n)) invBackward.SetBinError(n, hist.GetBinError(2 * nbins + 1 - n)) ## Histogram tunning if rebin: forward.Rebin(rebin) invBackward.Rebin(rebin) forward.SetMaximum(1.45 * forward.GetMaximum()) forward.SetMinimum(0.0) forward.SetMarkerStyle(24) invBackward.SetMarkerStyle(24) plot = Canvas.Canvas(name, 'png,pdf', 0.15, 0.72, 0.45, 0.82, 1) plot.addHisto(forward, 'P', 'Forward: |#Delta#Phi|, for |#Delta#Phi| #in [0, #pi/2]', 'p', r.kGreen + 2, 1, 0) plot.addHisto( invBackward, 'P,SAME', 'Backward inverted: |#Delta#Phi| - #pi/2, for |#Delta#Phi| #in [#pi/2, #pi]', 'p', r.kRed + 2, 1, 1) plot.addLatex(0.18, 0.85, label, font=62, size=0.035, align=11) plot.saveRatio(1, 0, 0, '', forward, invBackward, r_ymin=0.8, r_ymax=1.2, label='Forward / Inv. Backward', xlog=False, outputDir=WORKPATH + 'SymmetryResults/', maxYnumbers=maxY) print('>>>>>>>>>> KOLMOGOROV test for ' + label) print('>>>>>>>>>> ' + str(forward.KolmogorovTest(invBackward))) print('>>>>>>>>>> Chi2 test for ' + label) print('>>>>>>>>>> ' + str(forward.Chi2Test(invBackward, "WWP"))) return
def makeSignalBackgroundPlot(hname, ylog, treeMC, treeDATA, treeSI, inputdir, xlabel='', outtag='', yshift=0.0, LLlabel='', DATAlabel='', extralabel=''): SShname = hname.split('__')[0] + '_SS' hSS = treeDATA.getLoopTH1F(inputdir, SShname) hBKG = treeMC.getLoopTH1F(inputdir, hname) hBKG.Add(hSS) ### Signal histograms s_histos = [] if treeSI: hSIS = treeSI.getLoopStack(inputdir, hname) for _i, _h in enumerate(hSIS.GetHists()): _h.Scale(1.0 / _h.Integral()) s_histos.append(copy.deepcopy(_h)) hBKG.Scale(1.0 / hBKG.Integral()) ### Get maximum maxBKG = hBKG.GetMaximum() maxSI = 0 if not treeSI else max( [s_histos[i].GetMaximum() for i in range(0, len(s_histos))]) maxVal = max([maxBKG, maxSI]) ### Set Maximum if not ylog: hBKG.SetMaximum(1.15 * maxVal) hBKG.SetMinimum(0.0) if treeSI: for _h in s_histos: if not yshift: _h.SetMaximum(1.15 * maxVal) else: _h.SetMaximum(yshift * maxVal) _h.SetMinimum(0.0) else: if not yshift: hBKG.SetMaximum(10.0 * maxVal) else: hBKG.SetMaximum(yshift * maxVal) hBKG.SetMinimum(0.1) if treeSI: for _h in s_histos: if not yshift: _h.SetMaximum(10.0 * maxVal) else: _h.SetMaximum(yshift * maxVal) _h.SetMinimum(0.1) ### -> Canvas object plot = Canvas.Canvas(hname, 'png', 0.55, 0.69, 0.87, 0.87, 1) ### Add background: hBKG.SetLineColor(r.kAzure - 7) hBKG.SetFillColorAlpha(r.kAzure, 0.5) hBKG.GetXaxis().SetLabelSize(0.04) hBKG.GetXaxis().SetTitleSize(0.045) hBKG.GetYaxis().SetLabelSize(0.04) hBKG.GetYaxis().SetTitleSize(0.045) #hBKG.SetFillStyle(3016) plot.addHisto(hBKG, 'HIST', 'Background', 'f', '', 1, 0) # Background ### Add signals: if treeSI: for i, _h in enumerate(s_histos): _h.SetLineWidth(2) # provisional plot.addHisto(_h, 'HIST, SAME', _h.GetTitle(), 'l', _h.GetFillColor(), 1, i + 1) # Signal plot.addLatex(0.17, 0.85, 'Normalized to 1', font=62) ### Channel banner: if LLlabel == 'EE': plot.addLatex(0.17, 0.81, 'e^{+}e^{-} channel', font=42) if LLlabel == 'MM': plot.addLatex(0.17, 0.81, '#mu^{+}#mu^{-} channel', font=42) ### Extralabel: if extralabel: plot.addLatex(0.17, 0.76, extralabel, font=42) ### Save it outdir = os.path.dirname(os.path.abspath( __main__.__file__)) + '/SIvsBKG_' + outtag + '/' plot.save(1, 0, ylog, '', '', outputDir=outdir)
##################################### #### Construct TEfficiencies #### ##################################### BCK_nJet = getObject('jets_DY2M/th1fs.root', 'hist_nJet') SI_nJet = getObject('jets_signal/th1fs.root', 'hist_nJet') BCK_nJet.Scale(1.0/BCK_nJet.Integral()) SI_nJet.Scale(1.0/SI_nJet.Integral()) BCK_nJet.SetLineWidth(2) SI_nJet.SetLineWidth(2) BCK_nJet.SetTitle(';Number of Jets;Normalized event yield') SI_nJet.SetTitle('') nJet_comp = Canvas.Canvas("nJet_comp", 'png', 0.35, 0.77, 0.67, 0.86, 1) nJet_comp.addHisto(BCK_nJet, 'HIST', 'Monte Carlo: Z/#gamma*#rightarrowl#bar{l} (DYJetsToLL_M-50)', 'l', r.kRed+2, 1, 0) nJet_comp.addHisto(SI_nJet, 'HIST,SAME', 'Monte Carlo: H#rightarrowXX#rightarrow4l (All masses)', 'l', r.kBlue+2, 1, 1) nJet_comp.saveRatio(1, 0, 1, '', SI_nJet, BCK_nJet, r_ymin=0, r_ymax=10, label ="Sig/Bkg", outputDir = 'harvested_jets/') BCK_nGenJet = getObject('jets_DY2M/th1fs.root', 'hist_nGenJet') SI_nGenJet = getObject('jets_signal/th1fs.root', 'hist_nGenJet') BCK_nGenJet.Scale(1.0/BCK_nGenJet.Integral()) SI_nGenJet.Scale(1.0/SI_nGenJet.Integral()) BCK_nGenJet.SetLineWidth(2) SI_nGenJet.SetLineWidth(2) BCK_nGenJet.SetTitle(';Number of GenJets;Normalized event yield') SI_nGenJet.SetTitle('') nGenJet_comp = Canvas.Canvas("nGenJet_comp", 'png', 0.35, 0.77, 0.67, 0.86, 1) nGenJet_comp.addHisto(BCK_nGenJet, 'HIST', 'Monte Carlo: Z/#gamma*#rightarrowl#bar{l} (DYJetsToLL_M-50)', 'l', r.kRed+2, 1, 0)
'fakes_DY2M_ptmin31_sigmapt0p3_chi10/th1fs.root', 'total_DG_numberOfValidHits_clone') SI_fake_DG_nvalid_bin1 = getObject( 'fakes_signal_ptmin31_sigmapt0p3_chi10/th1fs.root', 'total_DG_numberOfValidHits_bin1_clone') SI_fake_DG_nvalid_bin2 = getObject( 'fakes_signal_ptmin31_sigmapt0p3_chi10/th1fs.root', 'total_DG_numberOfValidHits_bin2_clone') SI_fake_DG_nvalid_bin3 = getObject( 'fakes_signal_ptmin31_sigmapt0p3_chi10/th1fs.root', 'total_DG_numberOfValidHits_bin3_clone') DY_fake_DG_nvalid.SetTitle(';Numbes of valid hits N_{Hits};Fake rate') SI_fake_DG_nvalid_bin1.SetTitle(';;') SI_fake_DG_nvalid_bin2.SetTitle(';;') SI_fake_DG_nvalid_bin3.SetTitle(';;') SI_fake_DG_nvalid_bins_ = Canvas.Canvas("SI_fake_DG_nvalid_bins", 'png', 0.31, 0.73, 0.53, 0.88, 1) SI_fake_DG_nvalid_bins_.addRate( DY_fake_DG_nvalid, 'AP', 'Monte Carlo: Z/#gamma*#rightarrowl#bar{l} (DYJetsToLL_M-50)', 'p', r.kRed + 2, True, 0, marker=24) SI_fake_DG_nvalid_bins_.addRate( SI_fake_DG_nvalid_bin1, 'AP,SAME', 'H#rightarrowXX#rightarrow4l (All masses): |d_{xy}| < 1 cm', 'p', r.kBlue - 9,
parser.add_option('-t', '--tag', action='store', type=str, dest='tag', default='', help='Output tag') (opts, args) = parser.parse_args() ##################################### #### Construct TEfficiencies #### ##################################### # ptmin > 31, eta cut SI_DG_sigmapt = getObject('resolutions_signal_ptmin31_sigma0p2sep/th1fs.root', 'hist_DG_sigmapt') SI_DG_sigmapt.SetTitle(';DG #sigma_{p_{T}}/p_{T};DG yield') SI_DG_sigmapt.SetLineWidth(1) SI_DG_sigmapt.SetLineColor(r.kBlack) SI_DG_sigmapt.SetFillColorAlpha(r.kBlack, 0.25) SI_DG_sigmapt_ = Canvas.Canvas("SI_DG_sigmapt", 'png', 0.57, 0.75, 0.87, 0.9, 1) SI_DG_sigmapt_.addHisto(SI_DG_sigmapt, 'HIST', '', 'l', '', 1, 0) SI_DG_sigmapt_.addLatex(0.85, 0.85, 'Monte Carlo: H#rightarrowXX#rightarrow4l (All masses)', size = 0.03, align = 31) SI_DG_sigmapt_.addLatex(0.85, 0.8, '|#eta^{DG} < 2.4|, p_{T}^{DG} > 10 GeV', size = 0.03, align = 31) SI_DG_sigmapt_.save(0, 0, 1, '','', ymin = 0.1, ymax = 5000000, outputDir = WORKPATH + 'harvested_resols_'+opts.tag+'/') SI_DG_sigmapt_pass = getObject('resolutions_signal_ptmin31_sigma0p3sep/th1fs.root', 'ptres_DG_sigmapt_bin1') SI_DG_sigmapt_nopass = getObject('resolutions_signal_ptmin31_sigma0p3sep/th1fs.root', 'ptres_DG_sigmapt_bin2') SI_DG_sigmapt_pass.SetTitle(';(p_{T}^{reco}-p_{T}^{gen})/p^{gen}_{T};DG yield') SI_DG_sigmapt_nopass.SetTitle(';;') SI_DG_sigmapt_pass.SetLineWidth(2) SI_DG_sigmapt_nopass.SetLineWidth(2) SI_DG_sigmapt_pass.SetLineColor(r.kGreen+2) SI_DG_sigmapt_nopass.SetLineColor(r.kRed) SI_DG_sigmapt_pass.Scale(1.0/SI_DG_sigmapt_pass.Integral()) SI_DG_sigmapt_nopass.Scale(1.0/SI_DG_sigmapt_nopass.Integral())
##################################### #### Construct TEfficiencies #### ##################################### # Differences in pt BCK_unmatched_DG_pt = getObject('fakes_DY2M_nocut_eta2/th1fs.root', 'unmatched_DG_pt') SI_unmatched_DG_pt = getObject('fakes_signal_nocut_eta2/th1fs.root', 'unmatched_DG_pt') BCK_unmatched_DG_pt.Scale(1.0/BCK_unmatched_DG_pt.Integral()) SI_unmatched_DG_pt.Scale(1.0/SI_unmatched_DG_pt.Integral()) BCK_unmatched_DG_pt.SetLineWidth(2) SI_unmatched_DG_pt.SetLineWidth(2) BCK_unmatched_DG_pt.SetTitle(';Fake DG p_{T} (GeV);Normalized fake DG yield') SI_unmatched_DG_pt.SetTitle('') SI_DG_pt_ = Canvas.Canvas("unmatched_comp_pt", 'png', 0.35, 0.77, 0.67, 0.86, 1) SI_DG_pt_.addHisto(BCK_unmatched_DG_pt, 'HIST', 'Monte Carlo: Z/#gamma*#rightarrowl#bar{l} (DYJetsToLL_M-50)', 'l', r.kRed+2, 1, 0) SI_DG_pt_.addHisto(SI_unmatched_DG_pt, 'HIST,SAME', 'Monte Carlo: H#rightarrowXX#rightarrow4l (All masses)', 'l', r.kBlue+2, 1, 1) SI_DG_pt_.addLatex(0.9, 0.93, 'Displaced Global Muons: |#eta^{DG}| < 2', size = 0.04, align = 31) SI_DG_pt_.saveRatio(1, 0, 1, '', SI_unmatched_DG_pt, BCK_unmatched_DG_pt, r_ymin=0, r_ymax=10, label ="Sig/Bkg", outputDir = 'harvested_diffs/') BCK_matched_DG_pt = getObject('fakes_DY2M_nocut_eta2/th1fs.root', 'matched_DG_pt') SI_matched_DG_pt = getObject('fakes_signal_nocut_eta2/th1fs.root', 'matched_DG_pt') BCK_matched_DG_pt.Scale(1.0/BCK_matched_DG_pt.Integral()) SI_matched_DG_pt.Scale(1.0/SI_matched_DG_pt.Integral()) BCK_matched_DG_pt.SetLineWidth(2) SI_matched_DG_pt.SetLineWidth(2) BCK_matched_DG_pt.SetTitle(';True DG p_{T} (GeV);Normalized true DG yield') SI_matched_DG_pt.SetTitle('') SI_DG_pt_ = Canvas.Canvas("matched_comp_pt", 'png', 0.35, 0.77, 0.67, 0.86, 1)
#### ----------------- for j in range(0, ev.nEE): iee = j if not eval(cm.EE_BS2018): continue if not eval(cm.EE_iso2l): continue if not eval(cm.EE_OS): continue hEE_dPhi_asym.Fill(abs(ev.EE_dPhi[iee])) if ev.EE_leadingEt[iee] > 40 and ev.EE_subleadingEt[iee] > 40: hEE_dPhi_sym.Fill(abs(ev.EE_dPhi[iee])) hMM_dPhi_sym.SetMinimum(0.0) hMM_dPhi_sym.SetMaximum(1.5*hMM_dPhi_asym.GetMaximum()) plot = Canvas.Canvas('MM_dPhi_ptcutsymmetry', 'png,pdf', 0.16, 0.8, 0.35, 0.89, 1, lsize = 0.035) plot.addHisto(hMM_dPhi_sym, 'P', 'Symmetric cuts (p_{T} > 40 GeV)', 'p', r.kBlue-3, 1, 0, marker = 20) plot.addHisto(hMM_dPhi_asym, 'P,SAME', 'Asymmetric cuts (p_{T} > 40, 25 GeV)', 'p', r.kMagenta-3, 1, 1, marker = 25) plot.addLatex(0.9, 0.93, 'Drell-Yan (2018 UL)', font = 42, size = 0.035, align = 31) plot.save(1, 0, 0, '', '', outputDir = WORKPATH + '/', maxYnumbers = 3) hEE_dPhi_sym.SetMinimum(0.0) hEE_dPhi_sym.SetMaximum(1.5*hEE_dPhi_asym.GetMaximum()) plot = Canvas.Canvas('EE_dPhi_ptcutsymmetry', 'png,pdf', 0.16, 0.8, 0.35, 0.89, 1, lsize = 0.035) plot.addHisto(hEE_dPhi_sym, 'P', 'Symmetric cuts (p_{T} > 40 GeV)', 'p', r.kBlue-3, 1, 0, marker = 20) plot.addHisto(hEE_dPhi_asym, 'P,SAME', 'Asymmetric cuts (p_{T} > 40, 25 GeV)', 'p', r.kMagenta-3, 1, 1, marker = 25) plot.addLatex(0.9, 0.93, 'Drell-Yan (2018 UL)', font = 42, size = 0.035, align = 31) plot.save(1, 0, 0, '', '', outputDir = WORKPATH + '/', maxYnumbers = 3)
for _e, ev in enumerate(_tree): for i in range(0, ev.nDG): if ev.DG_phi[i] > 0: upperLegs.Fill(ev.DG_vx[i], ev.DG_vy[i]) if ev.DG_phi[i] < 0: lowerLegs.Fill(ev.DG_vx[i], ev.DG_vy[i]) """ PLOT = Canvas.Canvas('2Dplot', 'png', 0.6, 0.6, 0.89, 0.89, 1) PLOT.addHisto(upperLegs, 'BOX', 'Upper legs', 'f', r.kRed, 1, 0) PLOT.addHisto(lowerLegs, 'BOX, SAME', 'Lower legs', 'f', r.kBlue, 1, 2) PLOT.save(1, 0, 0, '', '') """ lowerLegs.SetFillColor(r.kRed) upperLegs.SetFillColor(r.kBlue) c1 = r.TCanvas("c1", "", 600, 600) lowerLegs.Draw("BOX") upperLegs.Draw("BOX, SAME") c1.SaveAs("2Dlegs.png") allvolume = lowerLegs.Clone() allvolume.Add(upperLegs) allvolume.GetYaxis().SetTitle('DG muon v_{y} (cm)') allvolume.GetXaxis().SetTitle('DG muon v_{x} (cm)') PLOT = Canvas.Canvas('vxvyDGpop', 'png', 0.6, 0.6, 0.89, 0.89, 1) PLOT.addHisto(allvolume, 'COLZ', '', 'f', r.kRed, 1, 0) PLOT.save(0, 0, 0, '', '')
help='Output tag') (opts, args) = parser.parse_args() ##################################### #### Construct TEfficiencies #### ##################################### # No cuts applied SI_matched_DG_pt = getObject('fakes_signal_nocut/th1fs.root', 'matched_DG_pt') SI_unmatched_DG_pt = getObject('fakes_signal_nocut/th1fs.root', 'unmatched_DG_pt') SI_DG_pt = doFakeStack(SI_matched_DG_pt, SI_unmatched_DG_pt, fakedown=True) SI_DG_pt_ = Canvas.Canvas("SI_DG_pt", 'png', 0.52, 0.81, 0.87, 0.9, 1) SI_DG_pt_.addStack(SI_DG_pt, 'HIST', 1, 0) SI_DG_pt_.addLatex(0.41, 0.75, 'Monte Carlo: H#rightarrowXX#rightarrow4l (All masses)', size=0.03, align=11) SI_DG_pt_.addLatex(0.41, 0.71, '|#eta^{DG} < 2.4|', size=0.03, align=11) SI_DG_pt_.save(1, 0, 0, '', '', outputDir=WORKPATH + 'harvested_fakes_' + opts.tag + '/', maxYnumbers=4)
def makeSymmetryTest2(lumi, hname, ylog, tree, inputdir, label, name, isData, xlabel='', outtag='', yshift=0.0, LLlabel='', color=r.kBlack): ## Get the histogram if type(hname) != list: hist = tree.getLoopTH1F(inputdir, hname) else: hist = tree.getLoopTH1F(inputdir, hname[0]) for n in range(1, len(hname)): hist.Add(tree.getLoopTH1F(inputdir, hname[n])) hist.SetMarkerStyle(20) hist.SetMarkerSize(0.8) ## Adjust the maximum hist.SetMaximum(2 * hist.GetMaximum()) hist.SetMinimum(0.5 * hist.GetMinimum()) ## Get Mean and Median: mean = hist.GetMean() print('Mean: ', hist.GetMean()) y = 0. q = np.array([0.]) prob = np.array([0.5]) y = hist.GetQuantiles(1, q, prob) print('Median: ', q[0]) print('Reference: ', 3.14 / 2.0) ## Get populations nbins = hist.GetNbinsX() simbin = int(nbins / 2) forwardErr = np.array([0.]) backwardErr = np.array([0.]) Nforward = hist.IntegralAndError(1, simbin, forwardErr) Nbackward = hist.IntegralAndError(simbin + 1, nbins, backwardErr) print("N in forward: ", Nforward, forwardErr[0]) print("N in backward: ", Nbackward, backwardErr[0]) fullStat = [Nforward, forwardErr[0], Nbackward, backwardErr[0]] ## Plot plot = Canvas.Canvas(name, 'png,pdf', 0.14, 0.8, 0.3, 0.9, 1) plot.addHisto(hist, 'P, SAME', label, 'p', color, 1, 0) plot.addLine(mean, hist.GetMinimum(), mean, hist.GetMaximum(), r.kBlue) plot.addLatex(0.18, 0.75, 'Mean: #bar{{|#Delta#Phi|}} = {0:.4f}'.format(mean), font=42, size=0.03, align=11, color=r.kBlue) plot.addLine(q[0], hist.GetMinimum(), q[0], hist.GetMaximum(), r.kRed) plot.addLatex(0.18, 0.71, 'Median: |#Delta#Phi|_{{1/2}} = {0:.4f}'.format(q[0]), font=42, size=0.03, align=11, color=r.kRed) plot.addLatex(0.18, 0.66, 'N_{{forward}} = {0} #pm {1}'.format(int(Nforward), int(forwardErr[0])), font=42, size=0.03, align=11, color=r.kBlack) plot.addLatex(0.18, 0.62, 'N_{{backward}} = {0} #pm {1}'.format( int(Nbackward), int(backwardErr[0])), font=42, size=0.03, align=11, color=r.kBlack) plot.save(1, 0, ylog, '', '', outputDir=WORKPATH + 'SymmetryResults/') return fullStat
def make2DPlot(h2, name, outdir): plot = Canvas.Canvas(name, 'png', 0.17, 0.8, 0.3, 0.9, 1) plot.addHisto(h2, 'COLZ', '', '', '', 1, 0) plot.save(0, 0, 0, '', '', outputDir=WORKPATH + outdir)
#outputFile.cd() #configs[point]['r_hist'].Write() #configs[point]['dxy_hist'].Write() print(configs) ### Harvesting configs['400_50_1']['r_hist'].SetLineWidth(2) configs['400_50_10']['r_hist'].SetLineWidth(2) configs['400_50_100']['r_hist'].SetLineWidth(2) configs['400_50_1000']['r_hist'].SetLineWidth(2) configs['400_50_10000']['r_hist'].SetLineWidth(2) configs['400_50_1']['r_hist'].SetMaximum( 1.4 * configs['400_50_1']['r_hist'].GetMaximum()) plot = Canvas.Canvas('hist_r_400_50', 'png,pdf', 0.14, 0.74, 0.4, 0.89, 1) plot.addHisto(configs['400_50_1']['r_hist'].Clone(), 'HIST', 'm_{H} = 400 GeV, m_{S} = 50 GeV, c#tau = 1 mm', 'p', r.kRed + 1, 1, 0) plot.addHisto(configs['400_50_10']['r_hist'].Clone(), 'HIST, SAME', 'm_{H} = 400 GeV, m_{S} = 50 GeV, c#tau = 10 mm', 'p', r.kOrange + 1, 1, 1) plot.addHisto(configs['400_50_100']['r_hist'].Clone(), 'HIST, SAME', 'm_{H} = 400 GeV, m_{S} = 50 GeV, c#tau = 100 mm', 'p', r.kGreen + 1, 1, 2) plot.addHisto(configs['400_50_1000']['r_hist'].Clone(), 'HIST, SAME', 'm_{H} = 400 GeV, m_{S} = 50 GeV, c#tau = 1000 mm', 'p', r.kBlue + 1, 1, 3) plot.addHisto(configs['400_50_10000']['r_hist'].Clone(), 'HIST, SAME', 'm_{H} = 400 GeV, m_{S} = 50 GeV, c#tau = 10000 mm', 'p', r.kMagenta + 1, 1, 4)
def makeCumulativeValidation(lumi, tree, var, name, xlabel, logx, LLlabel=False): hSR = tree.getLoopTH1F('histMC_SR_' + name, 'SR_' + var, xlabel) hCR = tree.getLoopTH1F('histMC_CR_' + name, 'CR_' + var, xlabel) cumSR = r.TH1F('cumSR', '', hSR.GetNbinsX(), hSR.GetXaxis().GetXmin(), hSR.GetXaxis().GetXmax()) cumCR = r.TH1F('cumCR', '', hCR.GetNbinsX(), hCR.GetXaxis().GetXmin(), hCR.GetXaxis().GetXmax()) cumSR.GetXaxis().SetTitle('(' + xlabel + ')_{min}') cumSR.GetYaxis().SetTitle('Number of events with ' + xlabel + ' > (' + xlabel + ')_{min}') cumCR.GetXaxis().SetTitle('(' + xlabel + ')_{min}') cumCR.GetYaxis().SetTitle('Number of events with ' + xlabel + ' > (' + xlabel + ')_{min}') for n in range(1, hSR.GetNbinsX() + 1): valSR = 0.0 errSR = 0.0 valCR = 0.0 errCR = 0.0 for j in range(n, hSR.GetNbinsX() + 1): valSR = valSR + hSR.GetBinContent(j) errSR = errSR + hSR.GetBinError(j) valCR = valCR + hCR.GetBinContent(j) errCR = errCR + hCR.GetBinError(j) cumSR.SetBinContent(n, valSR) cumSR.SetBinError(n, errSR) cumCR.SetBinContent(n, valCR) cumCR.SetBinError(n, errCR) cumSR.SetMarkerStyle(20) cumSR.SetMarkerSize(0.8) cumCR.SetMarkerStyle(20) cumCR.SetMarkerSize(0.8) luminosity = lumi ### Get maximum maxValCR = cumCR.GetMaximum() maxValSR = cumSR.GetMaximum() maxVal = max(maxValCR, maxValSR) ### Set Maximum if not logx: cumCR.SetMaximum(1.3 * maxVal) cumSR.SetMaximum(1.3 * maxVal) else: cumCR.SetMaximum(100.0 * maxVal) cumSR.SetMaximum(100.0 * maxVal) cumCR.SetMinimum(0.1) cumSR.SetMaximum(0.1) ### Canvas object plot = Canvas.Canvas('hist_' + name, 'png', 0.7, 0.79, 0.9, 0.87, 1) plot.addHisto(cumCR, 'P', 'Control region', 'l', r.kBlue, 1, 0) plot.addHisto(cumSR, 'P, SAME', 'Signal region', 'l', r.kRed, 1, 0) ### Dilepton banner if LLlabel == 'EE': plot.addLatex(0.17, 0.84, 'e^{+}e^{-} channel') if LLlabel == 'MM': plot.addLatex(0.17, 0.84, '#mu^{+}#mu^{-} channel') ### Save it #plot.save(1, 0, logx, luminosity, '') plot.saveRatio(1, 0, logx, luminosity, cumSR, cumCR, label="SR/CR", outputDir='closureMCPlots/')
def makePromptBKGPlot(name, lumi, hname_SR, hname_CR, ylog, treeDATA, inputdir, rebin = False, limit = 0.0, xlabel = '', outtag = '', yshift = 0.0, LLlabel = '', DATAlabel = '', extralabel = '', xlog = False): ### Get histograms luminosity = lumi hSR_ = treeDATA.getLoopTH1F(inputdir, hname_SR) hCR_ = treeDATA.getLoopTH1F(inputdir, hname_CR) ### rebinins: if type(rebin) != bool: if len(rebin) > 1: hSR = hSR_.Rebin(len(rebin)-1, hSR_.GetName() + '_rebined', rebin) hCR = hCR_.Rebin(len(rebin)-1, hCR_.GetName() + '_rebined', rebin) else: hSR = hSR_.Rebin(rebin) hCR = hCR_.Rebin(rebin) else: hSR = hSR_.Clone() hCR = hCR_.Clone() ### Blinding limits: if limit: for n in range(1, hSR.GetNbinsX()): if hSR.GetBinLowEdge(n) > limit: hSR.SetBinContent(n, 0.0) #if hCR_.GetBinLowEdge(n) > limit: hCR_.SetBinContent(n, 0.0) hCR.SetFillColorAlpha(r.kCyan-6, 0.8) hCR.SetLineColor(r.kCyan+3) hSR.SetMarkerStyle(20) hSR.SetMarkerSize(0.8) hSR.SetMarkerColor(r.kBlack) hCR.GetXaxis().SetTitleSize(0.045) hSR.GetXaxis().SetTitleSize(0.045) hCR.GetYaxis().SetTitleSize(0.045) hSR.GetYaxis().SetTitleSize(0.045) ### Get maximum maxValSR = hSR.GetMaximum() maxValCR = hCR.GetMaximum() maxVal = max([maxValSR, maxValCR]) ### Set Maximum if not ylog: hCR.SetMaximum(1.3*maxVal) else: hCR.SetMaximum(100.0*maxVal) hCR.SetMinimum(0.1) ### Canvas object plot = Canvas.Canvas('BKGVal_'+name, 'png,pdf', 0.51, 0.69, 0.7, 0.82, 1) plot.addHisto(hCR, 'HIST', 'Background (Data-driven)', 'f', '', 1, 0) plot.addHisto(hSR, 'P, SAME', 'Data', 'p', '', 1, 1) plot.addLatex(0.17, 0.8, extralabel, font = 62) ### Channel banner: if LLlabel == 'EE': plot.addLatex(0.17, 0.74, 'Dielectron channel', font = 42) if LLlabel == 'MM': plot.addLatex(0.17, 0.74, 'Dimuon channel', font = 42) ### Save it outdir = os.path.dirname(os.path.abspath(__main__.__file__)) + '/BKGVal_' + outtag + '/' plot.saveRatio(1, 1, ylog, luminosity, hSR, hCR, r_ymin = 0.0, r_ymax = 2.0, label="Obs./Pred.", outputDir = outdir, xlog = xlog)
hist_1d_r_cos = getObject('Results/th1f_2018ABCD.root', 'hist_1d_r_cos') hist_1d_r_id = getObject('Results/th1f_2018ABCD.root', 'hist_1d_r_id') hist_1d_r_chi.SetTitle(';Vertex radius r [cm]; Dimuon vertex yield') hist_1d_r_chi.SetMaximum(100.0 * hist_1d_r_chi.GetMaximum()) hist_1d_r_chi.SetMinimum(0.1) hist_1d_r_chi.Sumw2() hist_1d_r_chi.SetLineColor(r.kBlack) hist_1d_r_char.SetLineColor(r.kBlack) hist_1d_r_cos.SetLineColor(r.kBlack) hist_1d_r_id.SetLineColor(r.kBlack) hist_1d_r_chi.SetFillColor(r.kMagenta - 6) hist_1d_r_char.SetFillColor(r.kBlue - 6) hist_1d_r_cos.SetFillColor(r.kCyan - 6) hist_1d_r_id.SetFillColor(r.kGray) plot = Canvas.Canvas('hist_dr', 'png,pdf', 0.14, 0.75, 0.5, 0.89, 1) plot.addHisto(hist_1d_r_chi, 'HIST', 'Vertices passing kinematic cuts and #chi^{2}/ndf < 7.5', 'f', '', 1, 0) plot.addHisto(hist_1d_r_char, 'HIST,SAME', 'Vertices with OS dGlobals', 'f', '', 1, 1) plot.addHisto(hist_1d_r_cos, 'HIST,SAME', 'Vertices passing dR, mass, isolation and cos(#alpha) cuts', 'f', '', 1, 2) plot.addHisto(hist_1d_r_id, 'HIST,SAME', 'Vertices with dGlobals passing ID', 'f', '', 1, 3) plot.addLatex(0.9, 0.93, '2018 Data (6.0 fb)', size=0.026, align=31) plot.save(1, 1, 1, '',
def makeBlindedPlot(lumi, hname_SI, hname_bkg, ylog, treeDATA, inputdir, treeSI, rebin=False, lines=[], xlabel='', outtag='', ymax=0.0, LLlabel='', DATAlabel='', extralabel=''): ### Get histograms luminosity = lumi print(inputdir, hname_bkg) hbkg_ = treeDATA.getLoopTH1F(inputdir, hname_bkg) ### rebinins: if type(rebin) != bool: if len(rebin) > 1: hbkg = hbkg_.Rebin( len(rebin) - 1, hbkg_.GetName() + '_rebined', rebin) else: hbkg = hbkg_.Rebin(rebin) else: hbkg = hbkg_.Clone() hbkg.SetFillColorAlpha(r.kCyan - 6, 0.8) hbkg.SetLineColor(r.kCyan - 2) hbkg.GetXaxis().SetTitleSize(0.045) hbkg.GetYaxis().SetTitleSize(0.045) ### Signal histograms s_histos = [] hSIS = treeSI.getLoopStack(inputdir, hname_SI) for _i, _h in enumerate(hSIS.GetHists()): #_h.Scale(lumi/35.87) s_histos.append(copy.deepcopy(_h)) ### Get maximum maxValbkg = hbkg.GetMaximum() maxValSI = max([s_histos[i].GetMaximum() for i in range(0, len(s_histos))]) maxVal = max([maxValSI, maxValbkg]) ### Set Maximum if not ylog: hbkg.SetMaximum(1.3 * maxVal) else: hbkg.SetMaximum(100.0 * maxVal) hbkg.SetMinimum(0.0001) if ymax: hbkg.SetMaximum(ymax) ### Count background events backtotal = 0.0 for n in range(1, hbkg.GetNbinsX() + 1): if hbkg.GetBinLowEdge(n) > 20.0: backtotal += hbkg.GetBinContent(n) print("background total", backtotal) ### Canvas object plot = Canvas.Canvas('Blinded_' + hname_bkg, 'png,pdf', 0.15, 0.65, 0.6, 0.89, 1) plot.addHisto(hbkg, 'HIST', 'Background (Data-driven)', 'f', '', 1, 0) ### Add signals: for i, _h in enumerate(s_histos): _h.SetLineWidth(2) # provisional masses = eval(_h.GetTitle()[3:]) legend = 'm_{H} = ' + str(masses[0]) + ' GeV, m_{X} = ' + str( masses[1]) + ' GeV, c#tau = ' + str(masses[2]) + ' mm' plot.addHisto(_h, 'HIST, SAME', legend, 'l', _h.GetFillColor(), 1, i + 1) # Signal for line in lines: plot.addLine(line, hbkg.GetMinimum(), line, hbkg.GetMaximum(), r.kBlack, 2) ### Extralabel #plot.addLatex(0.17, 0.8, extralabel, font = 62) ### Save it outdir = os.path.dirname(os.path.abspath( __main__.__file__)) + '/SRPlots_' + outtag + '/' plot.save(1, 1, ylog, luminosity, '', outputDir=outdir, xlog=False)
### Pt (IFCA) BKG_IFCAeff_pt = getObject('Results/th1fDrell_Yan.root', 'eff_IFCA_pt') SI_4mm_IFCAeff_pt = getObject('Results/th1fHXX_400_50_4mm.root', 'eff_IFCA_pt') SI_40mm_IFCAeff_pt = getObject('Results/th1fHXX_400_50_40mm.root', 'eff_IFCA_pt') SI_400mm_IFCAeff_pt = getObject('Results/th1fHXX_400_50_400mm.root', 'eff_IFCA_pt') BKG_IFCAeff_pt_ = rebinAxis(BKG_IFCAeff_pt, ptbin) SI_4mm_IFCAeff_pt_ = rebinAxis(SI_4mm_IFCAeff_pt, ptbin) SI_40mm_IFCAeff_pt_ = rebinAxis(SI_40mm_IFCAeff_pt, ptbin) SI_400mm_IFCAeff_pt_ = rebinAxis(SI_400mm_IFCAeff_pt, ptbin) EFF_pt = Canvas.Canvas("EFF_IFCA_pt", 'png', 0.15, 0.77, 0.45, 0.9, 1) EFF_pt.addRate( SI_4mm_IFCAeff_pt_, 'AP', 'H#rightarrowXX: m_{H} = 400 GeV, m_{X} = 50 GeV, c#tau = 4 mm', 'p', r.kBlue + 2, True, 0, marker=24) EFF_pt.addRate( SI_40mm_IFCAeff_pt_, 'AP,SAME', 'H#rightarrowXX: m_{H} = 400 GeV, m_{X} = 50 GeV, c#tau = 40 mm', 'p', r.kBlue - 4,
def makePlot(lumi, var, name, xlabel, logx, treeMC, treeSI=False, treeDATA=False, LLlabel=False, normed=False): hMCS = treeMC.getLoopStack('histMC_' + name, var, xlabel) luminosity = lumi ### MC total histogram f = 0 for _i, _h in enumerate(hMCS.GetHists()): if not f: hMC = copy.deepcopy(_h) else: hMC.Add(_h, 1.) f = 1 hMC.SetMarkerStyle(20) # Auxiliar to save the ratio correctly ### Signal histograms if treeSI: hSIS = treeSI.getLoopStack('histSI_' + name, var, xlabel) s_histos = [] for _i, _h in enumerate(hSIS.GetHists()): s_histos.append(copy.deepcopy(_h)) ### Data histogram if treeDATA: hDATA = treeDATA.getLoopTH1F('histDATA_' + name, var, xlabel) hDATA.SetMarkerStyle(20) hDATA.SetMarkerSize(0.8) hDATA.Scale(hMC.Integral() / hDATA.Integral()) # Normalization if normed: hMC.Scale(1.0 / hMC.Integral()) for _h in s_histos: _h.Scale(1.0 / _h.Integral()) luminosity = 1.0 ### Get maximum maxValMC = hMC.GetMaximum() maxValSI = 0 if not treeSI else max( [s_histos[i].GetMaximum() for i in range(0, len(s_histos))]) maxValDATA = 0 if not treeDATA else hDATA.GetMaximum() maxVal = max([maxValMC, maxValSI, maxValDATA]) ### Set Maximum if not logx: hMCS.SetMaximum(1.3 * maxVal) hMCS.SetMinimum(0.0) hMC.SetMaximum(1.3 * maxVal) hMC.SetMinimum(0.0) if treeSI: for _h in s_histos: _h.SetMaximum(1.3 * maxVal) _h.SetMinimum(0.0) if treeDATA: hDATA.SetMaximum(1.3 * maxVal) hDATA.SetMinimum(0.0) else: hMCS.SetMaximum(10.0 * maxVal) hMCS.SetMinimum(0.1) hMC.SetMaximum(10.0 * maxVal) hMC.SetMinimum(0.1) if treeSI: for _h in s_histos: _h.SetMaximum(10.0 * maxVal) _h.SetMinimum(0.1) if treeDATA: hDATA.SetMaximum(10.0 * maxVal) hDATA.SetMinimum(0.1) ### Canvas object plot = Canvas.Canvas('hist_' + name, 'png', 0.34, 0.68, 0.9, 0.9) if normed: plot.addHisto(hMC, 'HIST', '', 'l', r.kBlue, 1, 0) # Background else: plot.addStack(hMCS, 'HIST', 1, 0) # Background if treeSI: for _h in s_histos: plot.addHisto(_h, 'HIST, SAME', '', 'l', _h.GetFillColor(), 1, 3) # Signal if treeDATA: plot.addHisto(hDATA, 'P, SAME', '', 'p', r.kBlack, 1, 4) ### Dilepton banner if LLlabel == 'EE': plot.addLatex(0.17, 0.86, 'e^{+}e^{-} channel') if LLlabel == 'MM': plot.addLatex(0.17, 0.86, '#mu^{+}#mu^{-} channel') ### Save it #plot.save(1, 0, logx, luminosity, '', outputDir = WORKPATH + 'plots/') plot.saveRatio(1, 0, logx, luminosity, hDATA, hMC, label="Data/MC", outputDir='newplots/')
def makeClosureTestMC(lumi, name, hBKG_A, hBKG_B, ylog, tree, inputdir, labelA = 'A', labelB = 'B', xlabel = '', outtag = '', yshift = 0.0, LLlabel = '', DATAlabel = '', extralabel = '', rmin = 0.0, rmax = 2.0): print(rmin, rmax) ### Get histograms luminosity = lumi ### Initialize cumulative histograms cumA = hBKG_A.Clone('cumA') cumB = hBKG_B.Clone('cumB') cumA.Reset() cumB.Reset() #cumA = r.TH1F('cumA', '', hBKG_A.GetNbinsX(), hBKG_A.GetXaxis().GetXmin(), hBKG_A.GetXaxis().GetXmax()) #cumB = r.TH1F('cumB', '', hBKG_B.GetNbinsX(), hBKG_B.GetXaxis().GetXmin(), hBKG_B.GetXaxis().GetXmax()) cumA.SetTitle(';min('+xlabel+');Number of events with '+xlabel+ ' > ('+xlabel+')_{min}') ### Set cumulative values for n in range(1, hBKG_A.GetNbinsX() + 1): valA = 0.0 errA = 0.0 valB = 0.0 errB = 0.0 for j in range(n, hBKG_A.GetNbinsX() + 1): valA = valA + hBKG_A.GetBinContent(j) errA = errA + hBKG_A.GetBinError(j) valB = valB + hBKG_B.GetBinContent(j) errB = errB + hBKG_B.GetBinError(j) cumA.SetBinContent(n, valA) cumA.SetBinError(n, errA) cumB.SetBinContent(n, valB) cumB.SetBinError(n, errB) ### Histogram tuning cumA.SetMarkerStyle(20) cumA.SetMarkerSize(1) cumA.SetMarkerColor(r.kBlue) cumA.GetYaxis().SetTitleOffset(1.3) cumB.SetMarkerStyle(25) cumB.SetMarkerSize(1) cumB.SetMarkerColor(r.kRed) hBKG_A.SetMarkerStyle(20) hBKG_A.SetMarkerSize(1) hBKG_A.SetMarkerColor(r.kBlue) hBKG_B.SetMarkerStyle(25) hBKG_B.SetMarkerSize(1) hBKG_B.SetMarkerColor(r.kRed) ### Get maximum maxValA = cumA.GetMaximum() maxValB = cumB.GetMaximum() maxVal = max(maxValA, maxValB) ### Set Maximum if not ylog: cumA.SetMaximum(1.3*maxVal) cumB.SetMaximum(1.3*maxVal) else: cumA.SetMaximum(100.0*maxVal) cumB.SetMaximum(100.0*maxVal) cumA.SetMinimum(0.1) cumB.SetMaximum(0.1) ### Get maximum maxValA = hBKG_A.GetMaximum() maxValB = hBKG_B.GetMaximum() maxVal = max(maxValA, maxValB) ### Set Maximum if not ylog: hBKG_A.SetMaximum(1.3*maxVal) hBKG_B.SetMaximum(1.3*maxVal) else: hBKG_A.SetMaximum(100.0*maxVal) hBKG_B.SetMaximum(100.0*maxVal) hBKG_A.SetMinimum(0.1) hBKG_B.SetMaximum(0.1) ### Canvas object plot = Canvas.Canvas('closuretest_'+name, 'png,pdf', 0.5, 0.66, 0.7, 0.78, 1) plot.addHisto(cumA, 'P', labelA, 'p', r.kBlue, 1, 0) plot.addHisto(cumB, 'P, SAME', labelB, 'p', r.kRed, 1, 1) ### Channel banner: if LLlabel == 'EE': plot.addLatex(0.17, 0.75, 'Dielectron vertices', font = 42) if LLlabel == 'MM': plot.addLatex(0.17, 0.75, 'Dimuon vertices', font = 42) plot.addLatex(0.85, 0.56, 'Tail cumulative of x = #int^{#infty}_{x_{min}} N(x) dx', font = 42, align = 31) plot.addLatex(0.17, 0.81, extralabel, font = 42, align = 11, size = 0.045) plot.addLatex(0.9, 0.88, DATAlabel, font = 42, align = 31, size = 0.045) ### Save it outdir = os.path.dirname(os.path.abspath(__main__.__file__)) + '/ClosureTests_' + outtag + '/' plot.saveRatio(1, 0, ylog, luminosity, cumA, cumB, r_ymin = rmin, r_ymax = rmax, label="SR/BCR", outputDir = outdir) ### Main comparison cplot = Canvas.Canvas('plaincomparison_'+name, 'png,pdf', 0.5, 0.66, 0.7, 0.78, 1) cplot.addHisto(hBKG_A, 'P', labelA, 'p', r.kBlue, 1, 0) cplot.addHisto(hBKG_B, 'P, SAME', labelB, 'p', r.kRed, 1, 1) if LLlabel == 'EE': cplot.addLatex(0.17, 0.75, 'Dielectron vertices', font = 42) if LLlabel == 'MM': cplot.addLatex(0.17, 0.75, 'Dimuon vertices', font = 42) cplot.addLatex(0.17, 0.81, extralabel, font = 42, align = 11, size = 0.045) cplot.addLatex(0.9, 0.88, DATAlabel, font = 42, align = 31, size = 0.045) cplot.saveRatio(1, 0, ylog, luminosity, hBKG_A, hBKG_B, label="SR/BCR", outputDir = outdir)
#### Construct TEfficiencies #### ##################################### hSR = getObject( 'Results/th1f.root', 'hSR_HLT_Diphoton30_22_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass90') hBCR = getObject( 'Results/th1f.root', 'hBCR_HLT_Diphoton30_22_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass90') hSR.Sumw2() hBCR.Sumw2() plot = Canvas.Canvas('hist_fullPath', 'png,pdf', 0.17, 0.55, 0.45, 0.89, 1, lsize=0.028) plot.addHisto(hSR, 'P', 'SR (fullPath)', 'p', r.kBlue, 1, 0) plot.addHisto(hBCR, 'P,SAME', 'BCR (fullPath)', 'p', r.kRed, 1, 1) plot.addLatex(0.9, 0.93, '2016 UL', size=0.03, align=31) plot.addLatex(0.75, 0.5, 'disp. Electrons:', size=0.03, align=22) plot.addLatex(0.75, 0.44, 'E_{T} > 25 GeV', size=0.03, align=22) plot.addLatex(0.75, 0.4, '|#eta| < 2', size=0.03, align=22) plot.saveRatio(1, 1, 1, '', hSR, hBCR,
def makeSensitivity(lumi, treeSI, treeMC, var, name, xlabel, logx, LLlabel=False, normed=False): hMCS = treeMC.getLoopTH1F('histMC_' + name, var, xlabel) hSIS = treeSI.getLoopStack('histSI_' + name, var, xlabel) luminosity = lumi ### Signal histograms s_histos = [] for _i, _h in enumerate(hSIS.GetHists()): s_histos.append(copy.deepcopy(_h)) ### Get significance values plot = Canvas.Canvas('sensitivity_' + name, 'png', 0.5, 0.7, 0.9, 0.9, 1) sens = [] for _i, _h in enumerate(s_histos): gh = r.TH1F('gr', '', hMCS.GetNbinsX(), hMCS.GetXaxis().GetXmin(), hMCS.GetXaxis().GetXmax()) for n in range(1, hMCS.GetNbinsX() + 1): sig_value = 0.0 back_value = 0.0 value = 0.0 for j in range(n, hMCS.GetNbinsX() + 1): sig_value = sig_value + _h.GetBinContent(j) back_value = back_value + hMCS.GetBinContent(j) if sig_value + back_value == 0: value = 0.0 else: value = sig_value / math.sqrt(sig_value + back_value) gh.SetBinContent(n, value) gh.SetTitle(_h.GetTitle()) gh.SetLineWidth(2) gh.GetYaxis().SetTitle('S/#sqrt{S + B}') gh.GetXaxis().SetTitle(xlabel) gh.SetLineColor(_h.GetFillColor()) gh1 = gh.Clone() gh2 = copy.deepcopy(gh1) sens.append(gh2) print([sens[i].GetMaximum() for i in range(0, len(sens))]) maximum = max([sens[i].GetMaximum() for i in range(0, len(sens))]) print('maximum: ', maximum) for _s, gh2 in enumerate(sens): gh2.SetMaximum(1.3 * maximum) if _s == 0: plot.addHisto(gh2, 'l', gh2.GetTitle(), 'l', gh2.GetLineColor(), 1, 1) else: plot.addHisto(gh2, 'l, same', gh2.GetTitle(), 'l', gh2.GetLineColor(), 1, 1) ### Dilepton banner if LLlabel == 'EE': plot.addLatex(0.17, 0.86, 'e^{+}e^{-} channel') if LLlabel == 'MM': plot.addLatex(0.17, 0.86, '#mu^{+}#mu^{-} channel') ### Save it plot.save(1, 0, logx, luminosity, '', outputDir=WORKPATH + 'sensitivity/')
xmin=0, xmax=10, cut=allcuts, options='', xlabel='Dimuon #mu#mu L_{xy} (cm)') hSI = treeSI.getTH1F(lumi=lumi, name='hSI', var='DMDMBase_Lxy[0]', nbin=20, xmin=0, xmax=10, cut=allcuts, options='', xlabel='Dimuon #mu#mu L_{xy} (cm)') plot = Canvas.Canvas('hist_DMDM_Lxy', 'png', 0.55, 0.8, 0.9, 0.9, 1) plot.addHisto(hBCK, 'hist', '', 'l', '', 1, 0) plot.addHisto(hSI, 'hist, same', '', 'l', '', 1, 1) plot.save(legend=True, isData=False, log=True, lumi=lumi, labelx='', outputDir=outputFolder) ### --> Ejemplo de sacar la sensitivity y las cumulativas Sensitivity, cumSig, cumBkg = computeSensitivity(hBCK, hSI, r.kGreen) plot_sensitivity = Canvas.Canvas('hist_sensitivity', 'png', 0.55, 0.8, 0.9, 0.9, 1) plot_sensitivity.addHisto(Sensitivity, 'hist', '', 'l', '', 1, 0)
############################## #### Some definitions #### ############################## ##################################### #### Construct TEfficiencies #### ##################################### hist_dPhi = getObject('Results/th1f_all.root', 'hist_dPhi') hist_dPhi.Rebin(4) hist_dPhi.SetTitle( ';Dimuon collinearity |#Delta#Phi|; Dimuon vertex yield') hist_dPhi.SetMaximum(1.2 * hist_dPhi.GetMaximum()) hist_dPhi.SetMinimum(0.0) hist_dPhi.Sumw2() plot = Canvas.Canvas('hist_cosmics_dPhi', 'png,pdf', 0.3, 0.75, 0.89, 0.8, 1) plot.addHisto(hist_dPhi, 'P', '', 'p', r.kBlue, 1, 0) plot.addLatex(0.9, 0.93, 'Cosmic data 2018', size=0.026, align=31) plot.addLatex(0.85, 0.85, '/NoBPTX/Run2018B-12Nov2019_UL2018-v1/AOD', size=0.026, align=31) plot.addLatex(0.85, 0.8, 'HLT_L2Mu10_NoVertex_NoBPTX3BX', size=0.026, align=31) plot.save(0, 1, 0,