def RatioCanvas(canvas_name, canvas_title, canw=500, canh=600, ratio_size_as_fraction=0.35): from ROOT import TCanvas, TPad c = TCanvas(canvas_name, canvas_title, canw, canh) c.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.02 / float(top.GetHNDC())) top.SetTopMargin(0.04 / float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw() tobject_collector.append(top) c.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.11 / float(bot.GetHNDC())) bot.SetTopMargin(0.02 / float(bot.GetHNDC())) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw() tobject_collector.append(bot) return c
def __plot_quadrant_template2(self, h_oo, h_xo, h_ox, h_xx, alias, xlabel, plotname, doLogY): from TrigEgammaDevelopments.plots import AutoFixAxes from TrigEgammaDevelopments.helper.util import setBoxes from ROOT import TCanvas, gStyle, TLegend, kRed, kBlue, kGreen, kGray, kBlack, TLine, TPad, TLatex from TrigEgammaDevelopments.plots.AtlasStyle import AtlasStyle, atlas_template ratio_size_as_fraction = 0.35 # Internal method def sortHistograms(hists): nevents = [o.GetEntries() for o in hists] from operator import itemgetter hist_sorted_index = sorted(enumerate(nevents), key=itemgetter(1)) hist_sorted = list() for index in hist_sorted_index: hist_sorted.append(hists[index[0]]) hist_sorted.reverse() return hist_sorted h_agree = h_xx + h_oo h_disagree = h_ox + h_xo hsum = h_agree + h_disagree gStyle.SetOptStat(111111) canvas = TCanvas('canvas', 'canvas', 2500, 1600) drawopt = 'pE1' canvas.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.0) top.SetBottomMargin(0.06 / float(top.GetHNDC())) #top.SetTopMargin (0.04/float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw(drawopt) canvas.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.10 / float(bot.GetHNDC())) #bot.SetTopMargin (0.02/float(bot.GetHNDC())) bot.SetTopMargin(0.0) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw(drawopt) top.cd() h_agree.SetLineWidth(1) h_agree.SetLineColor(kBlack) h_agree.SetMarkerColor(kBlack) h_disagree.SetLineWidth(1) h_disagree.SetLineColor(kRed) h_disagree.SetMarkerColor(kRed) h_agree.SetName('Agreement') h_disagree.SetName('Disagreement') h_agree.SetStats(1) h_disagree.SetStats(1) # top h1 = sortHistograms([h_agree, h_disagree]) # bot h2 = sortHistograms([h_agree.Clone(), h_disagree.Clone()]) h1[0].GetXaxis().SetTitle('') h1[0].GetYaxis().SetTitle('Counts') #h1[0].GetYaxis().SetTitleOffset(0.5) #h1[0].GetYaxis().SetLabelSize(0.10) #h1[0].GetYaxis().SetTitleSize(0.10) #h1[0].GetXaxis().SetLabelSize(0.10) h1[0].Draw() for i in range(1, len(h1)): h1[i].Draw('sames') top.Update() setBoxes(top, h1) if doLogY: top.SetLogy() AutoFixAxes(top, False, False, 9000) else: AutoFixAxes(top, False, False, 2) bot.cd() if doLogY: bot.SetLogy() hsum.Sumw2() for h in h2: h.SetStats(0) h.Sumw2() h.Divide(h, hsum, 1., 1.) h2[0].GetYaxis().SetTitle('ratio') h2[0].GetXaxis().SetTitle(xlabel) h2[0].GetYaxis().SetTitleOffset(0.5) h2[0].GetYaxis().SetLabelSize(0.10) h2[0].GetYaxis().SetTitleSize(0.10) h2[0].GetXaxis().SetLabelSize(0.10) h2[0].GetXaxis().SetTitleSize(0.10) if not doLogY: h2[0].GetYaxis().SetRangeUser(0, 1.05) h2[0].Draw('ep1') for i in range(1, len(h2)): h2[i].Draw('sames') if doLogY: AutoFixAxes(bot, False, False, 1.1) # Loop over histograms canvas.SaveAs(plotname)
def plot(self, **kw): from ROOT import kRed dirname = retrieve_kw(kw, 'dirname', 'Distribution') basecolor = retrieve_kw(kw, 'basecolor', kRed - 7) pdftitle = retrieve_kw(kw, 'pdftitle', 'Distributions') pdfoutput = retrieve_kw(kw, 'pdfoutput', 'distributions') import os # Organize outputs (.py and .pdf) prefix = self._basepath.split('/')[-1] localpath = os.getcwd() + '/' + dirname + '/' + prefix try: if not os.path.exists(localpath): os.makedirs(localpath) except: self._logger.warning('The director %s exist.', localpath) hist_names = [ 'et', 'eta', 'mu', 'nvtx', 'reta', 'eratio', 'weta2', 'rhad', 'rphi', 'f1', 'f3' ] hist_labels = [ 'E_{T}', "#eta", "<#mu>", 'N_{vtx}', 'R_{eta}', 'E_{ratio}', 'W_{eta2}', 'R_{had}', 'R_{phi}', 'f_{1}', 'f_{3}' ] from ROOT import TCanvas, TH1F, gStyle, TLegend, TPad from ROOT import kGreen, kRed, kBlue, kBlack, kGray, gPad, kAzure from TrigEgammaDevelopments.plots.AtlasStyle import AtlasStyle, atlas_template, setLegend1 canvas1 = TCanvas('canvas1', 'canvas1', 2500, 1600) canvas1.Divide(4, 3) # Concatenate distributions for all regions def sumAllRegions(histname): h = None for etBinIdx in range(len(self._etBins) - 1): for etaBinIdx in range(len(self._etaBins) - 1): binningname = ('et%d_eta%d') % (etBinIdx, etaBinIdx) path = self._basepath + '/' + self.currentDir( ) + '/' + binningname if h: h += self.storeSvc().histogram(path + '/' + histname) else: h = self.storeSvc().histogram(path + '/' + histname).Clone() return h collector = [] figures = { 'rings': [], 'rnnOutput': [], 'ringer_profile': str(), 'shower_shapes': str() } """ Plot all shower shapes distributins """ for idx, histname in enumerate(hist_names): self.setDir('Data') h_data = sumAllRegions(histname) self.setDir('MonteCarlo') h_mc = sumAllRegions(histname) #h_mc, h_data = self.__scale_histograms(h_mc, h_data, 100, 0.01, 0.01) pad = canvas1.cd(idx + 1) gStyle.SetOptStat(110011) collector.append(pad) h_mc.SetFillColor(basecolor) h_mc.SetLineColor(basecolor) h_data.SetLineColor(kBlack) h_mc.Scale(1. / h_mc.GetMaximum()) h_data.Scale(1. / h_data.GetMaximum()) h_mc.Draw() h_data.Draw('same') leg1 = TLegend(0.2, 0.75, 0.5, 0.95) setLegend1(leg1) leg1.AddEntry(h_mc, 'MC') leg1.AddEntry(h_data, 'Data') leg1.Draw() collector[-1].Update() collector.append(h_mc) collector.append(h_data) collector.append(leg1) canvas1.SaveAs(localpath + '/shower_shapes_distributions.pdf') figures[ 'shower_shapes'] = localpath + '/shower_shapes_distributions.pdf' """ Plot all shower ringer shapes for each ring """ ratio_size_as_fraction = 0.35 from RingerCore import progressbar rings_localpath = [] for r in progressbar(range(100), 100, step=1, logger=self._logger, prefix="Looping over rings (Plotting...) "): canvas2 = TCanvas('canvas2', 'canvas2', 2500, 1600) drawopt = 'pE1' canvas2.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.0) top.SetBottomMargin(0.06 / float(top.GetHNDC())) #top.SetTopMargin (0.04/float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw(drawopt) canvas2.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.10 / float(bot.GetHNDC())) #bot.SetTopMargin (0.02/float(bot.GetHNDC())) bot.SetTopMargin(0.0) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw(drawopt) self.setDir('MonteCarlo') h_mc = sumAllRegions('rings/ring_' + str(r)) self.setDir('Data') h_data = sumAllRegions('rings/ring_' + str(r)) gStyle.SetOptStat(000000) h_mc, h_data = self.__scale_histograms(h_mc, h_data, 100, 0.0001, 0.025) h_mc.Scale(1. / h_mc.GetMaximum()) h_data.Scale(1. / h_data.GetMaximum()) from ROOT import TH1, kGray divide = "" drawopt = 'pE1' bot.cd() ref = h_mc.Clone() h = h_data.Clone() ref.Sumw2() h.Sumw2() ratioplot = h.Clone() ratioplot.Sumw2() ratioplot.SetName(h.GetName() + '_ratio') ratioplot.Divide(h, ref, 1., 1., '') ratioplot.SetFillColor(0) ratioplot.SetFillStyle(0) ratioplot.SetMarkerColor(1) ratioplot.SetLineColor(kGray) ratioplot.SetMarkerStyle(24) ratioplot.SetMarkerSize(1.2) ratioplot.GetYaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetRangeUser(-1.6, 3.7) ratioplot.GetYaxis().SetTitleOffset(0.7) ratioplot.GetYaxis().SetTitle('Data/MC') ratioplot.GetXaxis().SetTitle('Ring #' + str(r + 1) + ' [MeV]') ratioplot.Draw(drawopt) from ROOT import TLine nbins = h_data.GetNbinsX() xmin = h_data.GetXaxis().GetBinLowEdge(1) xmax = h_data.GetXaxis().GetBinLowEdge(nbins + 1) l1 = TLine(xmin, 1, xmax, 1) l1.SetLineColor(kRed) l1.SetLineStyle(2) l1.Draw() bot.Update() top.cd() h_mc.SetFillColor(basecolor) h_mc.SetLineWidth(1) h_mc.SetLineColor(basecolor) h_data.SetLineColor(kBlack) h_data.SetLineWidth(1) h_mc.GetYaxis().SetTitle('Count') h_mc.Draw() h_data.Draw('same') leg1 = TLegend(0.8, 0.70, 0.95, 0.95) setLegend1(leg1) leg1.AddEntry(h_mc, 'MC') leg1.AddEntry(h_data, 'Data') leg1.Draw() atlas_template(top) top.Update() canvas2.SaveAs(localpath + '/distribution_ring_' + str(r + 1) + '.pdf') figures['rings'].append(localpath + '/distribution_ring_' + str(r + 1) + '.pdf') """ Plot ringer mean shapes """ h_mean_data = TH1F('h_mean_data', '', 100, 0, 100) h_mean_mc = TH1F('h_mean_mc', '', 100, 0, 100) for bin in range(100): self.setDir('MonteCarlo') h_mc = sumAllRegions('rings/ring_' + str(bin)) self.setDir('Data') h_data = sumAllRegions('rings/ring_' + str(bin)) h_mean_data.SetBinContent(bin + 1, h_data.GetMean()) h_mean_mc.SetBinContent(bin + 1, h_mc.GetMean()) canvas3 = TCanvas('canvas3', 'canvas3', 2500, 1600) drawopt = 'pE1' canvas3.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.0) top.SetBottomMargin(0.06 / float(top.GetHNDC())) #top.SetTopMargin (0.04/float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw(drawopt) canvas3.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.10 / float(bot.GetHNDC())) #bot.SetTopMargin (0.02/float(bot.GetHNDC())) bot.SetTopMargin(0.0) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw(drawopt) gStyle.SetOptStat(000000) from ROOT import TH1, kGray divide = "" drawopt = 'pE1' bot.cd() ref = h_mean_mc.Clone() h = h_mean_data.Clone() ref.Sumw2() h.Sumw2() ratioplot = h.Clone() ratioplot.Sumw2() ratioplot.SetName(h.GetName() + '_ratio') ratioplot.Divide(h, ref, 1., 1., '') ratioplot.SetFillColor(0) ratioplot.SetFillStyle(0) ratioplot.SetMarkerColor(1) ratioplot.SetLineColor(kGray) ratioplot.SetMarkerStyle(24) ratioplot.SetMarkerSize(1.2) ratioplot.GetYaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetRangeUser(-1.6, 3.7) ratioplot.GetYaxis().SetTitleOffset(0.7) ratioplot.GetYaxis().SetTitle('Data/MC') ratioplot.GetXaxis().SetTitle('Rings') ratioplot.Draw(drawopt) from ROOT import TLine nbins = h_mean_data.GetNbinsX() xmin = h_mean_data.GetXaxis().GetBinLowEdge(1) xmax = h_mean_data.GetXaxis().GetBinLowEdge(nbins + 1) l1 = TLine(xmin, 1, xmax, 1) l1.SetLineColor(kRed) l1.SetLineStyle(2) l1.Draw() bot.Update() top.cd() h_mean_mc.SetFillColor(basecolor) h_mean_mc.SetLineWidth(1) h_mean_mc.SetLineColor(basecolor) h_mean_data.SetLineColor(kBlack) h_mean_data.SetLineWidth(1) #h_mean_mc.Scale( 1./h_mean_mc.GetEntries() ) #h_mean_data.Scale( 1./h_mean_data.GetEntries() ) if h_mean_mc.GetMaximum() > h_mean_data.GetMaximum(): ymin = h_mean_mc.GetMinimum() ymax = h_mean_mc.GetMaximum() h_mean_mc.Draw() h_mean_mc.GetYaxis().SetTitle('E[Ring] MeV') h_mean_data.Draw('same') else: ymin = h_mean_data.GetMinimum() ymax = h_mean_data.GetMaximum() h_mean_data.GetYaxis().SetTitle('E[Ring] MeV') h_mean_data.Draw() h_mean_mc.Draw('same') h_mean_data.Draw('same') # prepare ringer lines def gen_line_90(x, ymin, ymax, text): from ROOT import TLine, TLatex ymax = 1.05 * ymax l = TLine(x, ymin, x, ymax) l.SetLineStyle(2) l.Draw() txt = TLatex() txt.SetTextFont(12) txt.SetTextAngle(90) txt.SetTextSize(0.04) txt.DrawLatex(x - 1, (ymax - ymin) / 2., text) return l, txt l_ps, t_ps = gen_line_90(8, ymin, ymax, 'presampler') l_em1, t_em1 = gen_line_90(72, ymin, ymax, 'EM.1') l_em2, t_em2 = gen_line_90(80, ymin, ymax, 'EM.2') l_em3, t_em3 = gen_line_90(88, ymin, ymax, 'EM.3') l_had1, t_had1 = gen_line_90(92, ymin, ymax, 'Had.1') l_had2, t_had2 = gen_line_90(96, ymin, ymax, 'Had.2') l_had3, t_had3 = gen_line_90(100, ymin, ymax, 'Had.3') leg1 = TLegend(0.8, 0.70, 0.95, 0.95) setLegend1(leg1) leg1.AddEntry(h_mean_mc, 'MC') leg1.AddEntry(h_mean_data, 'Data') leg1.Draw() atlas_template(top) top.Update() canvas3.SaveAs(localpath + '/ringer_profile.pdf') figures['ringer_profile'] = localpath + '/ringer_profile.pdf' """ Plot all NN distributions for each calo region """ for algname in self._discrList: for etBinIdx in range(len(self._etBins) - 1): for etaBinIdx in range(len(self._etaBins) - 1): binningname = ('et%d_eta%d') % (etBinIdx, etaBinIdx) path = self._basepath + '/MonteCarlo/' + binningname h_mc = self.storeSvc().histogram( path + '/' + algname + '/discriminantVsMu').ProjectionX().Clone() path = self._basepath + '/Data/' + binningname h_data = self.storeSvc().histogram( path + '/' + algname + '/discriminantVsMu').ProjectionX().Clone() h_mc.Rebin(10) h_data.Rebin(10) h_mc.Scale(1. / h_mc.GetMaximum()) h_data.Scale(1. / h_data.GetMaximum()) canvas4 = TCanvas('canvas4', 'canvas4', 2500, 1600) drawopt = 'pE1' canvas4.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.0) top.SetBottomMargin(0.06 / float(top.GetHNDC())) #top.SetTopMargin (0.04/float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw(drawopt) canvas4.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.10 / float(bot.GetHNDC())) bot.SetTopMargin(0.0) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw(drawopt) gStyle.SetOptStat(000000) from ROOT import TH1, kGray divide = "" drawopt = 'pE1' bot.cd() ref = h_mc.Clone() h = h_data.Clone() ref.Sumw2() h.Sumw2() ratioplot = h.Clone() ratioplot.Sumw2() ratioplot.SetName(h.GetName() + '_ratio') ratioplot.Divide(h, ref, 1., 1., '') ratioplot.SetFillColor(0) ratioplot.SetFillStyle(0) ratioplot.SetMarkerColor(1) ratioplot.SetLineColor(kGray) ratioplot.SetMarkerStyle(24) ratioplot.SetMarkerSize(1.2) ratioplot.GetYaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetRangeUser(-1.6, 3.7) ratioplot.GetYaxis().SetTitleOffset(0.7) ratioplot.GetYaxis().SetTitle('Data/MC') ratioplot.GetXaxis().SetTitle( 'Neural Network (Discriminant)') ratioplot.Draw(drawopt) from ROOT import TLine nbins = h_data.GetNbinsX() xmin = h_data.GetXaxis().GetBinLowEdge(1) xmax = h_data.GetXaxis().GetBinLowEdge(nbins + 1) l1 = TLine(xmin, 1, xmax, 1) l1.SetLineColor(kRed) l1.SetLineStyle(2) l1.Draw() bot.Update() top.cd() h_mc.SetFillColor(basecolor) h_mc.SetLineWidth(1) h_mc.SetLineColor(basecolor) h_data.SetLineColor(kBlack) h_data.SetLineWidth(1) h_mc.Scale(1. / h_mc.GetMaximum()) h_data.Scale(1. / h_data.GetMaximum()) h_mc.GetYaxis().SetTitle( ('Counts (%s)') % (binningname.replace('_', ','))) h_mc.Draw() h_data.Draw('same') leg1 = TLegend(0.8, 0.70, 0.95, 0.95) setLegend1(leg1) leg1.AddEntry(h_mc, 'MC') leg1.AddEntry(h_data, 'Data') leg1.Draw() atlas_template(top) top.Update() canvas4.SaveAs(localpath + '/' + algname + '_rnnOutput_' + binningname + '.pdf') figures['rnnOutput'].append(localpath + '/' + algname + '_rnnOutput_' + binningname + '.pdf') #from RingerCore.tex.TexAPI import * from RingerCore.tex.BeamerAPI import BeamerTexReportTemplate1, BeamerSection, BeamerMultiFigureSlide, BeamerFigureSlide with BeamerTexReportTemplate1(theme='Berlin', _toPDF=True, title=pdftitle, outputFile=pdfoutput, font='structurebold'): with BeamerSection(name='Shower Shapes'): BeamerMultiFigureSlide( title='Shower Shapes (MC and Data)', paths=[figures['shower_shapes']], nDivWidth=1 # x , nDivHeight=1 # y , texts=None, fortran=False, usedHeight=0.8, usedWidth=1.1) with BeamerSection(name='Ringer Shapes Profile'): BeamerMultiFigureSlide( title='Ringer Profile (MC and Data)', paths=[figures['ringer_profile']], nDivWidth=1 # x , nDivHeight=1 # y , texts=None, fortran=False, usedHeight=0.8, usedWidth=1.1) with BeamerSection(name='Ringer Shapes'): for s in range(4): paths1 = [ path for path in figures['rings'][s * 25:s * 25 + 25] ] BeamerMultiFigureSlide( title='Ringer Shapes (MC and Data)', paths=paths1, nDivWidth=5 # x , nDivHeight=5 # y , texts=None, fortran=False, usedHeight=0.8, usedWidth=1.1) for algname in self._discrList: with BeamerSection(name=('%s Neural Network Output') % (algname.replace('_', '\_'))): paths2 = [] for etBinIdx in range(len(self._etBins) - 1): for etaBinIdx in range(len(self._etaBins) - 1): binningname = ('et%d_eta%d') % (etBinIdx, etaBinIdx) paths2.append(localpath + '/' + algname + '_rnnOutput_' + binningname + '.pdf') BeamerMultiFigureSlide( title=algname.replace('_', '\_'), paths=paths2, nDivWidth=len(self._etaBins) # x , nDivHeight=len(self._etBins) # y , texts=None, fortran=False, usedHeight=1.0, usedWidth=1.1) return StatusCode.SUCCESS
def __plot_profiles_in_same_canvas(self, hist_objs, hist_names, legends, y_limits, **kwargs): legend_position = retrieve_kw(kwargs, 'legend_position', (0.36, 0.20, 0.66, 0.36)) legend_prefix = retrieve_kw(kwargs, 'legend_prefix', 'Z#rightarrowee, ') legend_header = retrieve_kw(kwargs, 'legend_header', 'Trigger step') ylabel = retrieve_kw(kwargs, 'ylabel', 'Trigger Efficiency') title = retrieve_kw(kwargs, 'title', 'Trigger Efficiency') oname = retrieve_kw(kwargs, 'oname', 'plot_efficiencys') column = retrieve_kw(kwargs, 'column', 2) doRatio = retrieve_kw(kwargs, 'doRatio', False) canvas_size = retrieve_kw(kwargs, 'canvas_size', (1800, 1500)) # FIXME: This must be disable for now, there is some problem into the xaxis scale # The top and bot axis must be match! tobject_collector = [] ratio_size_as_fraction = 0.35 from ROOT import TCanvas, TLegend, TProfile, TPad rows = int(round(len(hist_objs) / float(column))) canvas = TCanvas('canvas', 'canvas', canvas_size[0], canvas_size[1]) canvas.Divide(rows, column) leg_holder = [] for index, hist_str in enumerate(hist_names): hists = hist_objs[hist_str] pad = canvas.cd(index + 1) # Force disable if != of 2 if len(hists) != 2: doRatio = False if doRatio: drawopt = 'pE1' pad.cd() top = TPad("pad_top", "This is the top pad", 0.0, ratio_size_as_fraction, 1.0, 1.0) top.SetBottomMargin(0.0) top.SetBottomMargin(0.06 / float(top.GetHNDC())) #top.SetTopMargin (0.04/float(top.GetHNDC())) top.SetRightMargin(0.05) top.SetLeftMargin(0.16) top.SetFillColor(0) top.Draw(drawopt) tobject_collector.append(top) pad.cd() bot = TPad("pad_bot", "This is the bottom pad", 0.0, 0.0, 1.0, ratio_size_as_fraction) bot.SetBottomMargin(0.10 / float(bot.GetHNDC())) #bot.SetTopMargin (0.02/float(bot.GetHNDC())) bot.SetTopMargin(0.0) bot.SetRightMargin(0.05) bot.SetLeftMargin(0.16) bot.SetFillColor(0) bot.Draw(drawopt) tobject_collector.append(bot) if type(legend_prefix) is not list: legend_prefix = [legend_prefix] * len(legends) if doRatio: top.cd() leg = TLegend(legend_position[0], legend_position[1], legend_position[2], legend_position[3]) from AtlasStyle import setLegend1, atlas_template setLegend1(leg) leg.SetHeader(legend_header) for i, eff in enumerate(hists): eff.SetLineColor(self._curve_color[i]) eff.SetMarkerColor(self._curve_color[i]) eff.SetMarkerStyle(self._marker_style[i]) if type(eff) is TProfile: eff.SetStats(0) leg.AddEntry(eff, legend_prefix[i] + legends[i], 'p') if i is 0: eff.Draw() else: eff.Draw('same') leg.SetTextSize(0.03) leg.SetBorderSize(0) leg.Draw() if doRatio: top.Modified() top.Update pad.Modified() pad.Update() from ROOT import TProfile, TEfficiency, kFALSE xmin = 0 xmax = 999 if type(hists[0]) is TProfile: hists[0].GetYaxis().SetRangeUser(y_limits[index][0], y_limits[index][1]) elif type(hists[0]) is TEfficiency: hists[0].GetPaintedGraph().GetYaxis().SetRangeUser( y_limits[index][0], y_limits[index][1]) hists[0].GetPaintedGraph().GetYaxis().SetTitle('A') # Fix the X axis nbins = hists[0].GetTotalHistogram().GetNbinsX() xmin = hists[0].GetTotalHistogram().GetXaxis().GetBinLowEdge(1) xmax = hists[0].GetTotalHistogram().GetXaxis().GetBinLowEdge( nbins + 1) hists[0].GetPaintedGraph().GetXaxis().SetLimits(xmin, xmax) else: hists[0].GetYaxis().SetRangeUser(y_limits[index][0], y_limits[index][1]) pad.Modified() pad.Update() tobject_collector.append(leg) if doRatio: atlas_template(top, **kwargs) top.Update() from ROOT import TH1 divide = "" drawopt = 'pE1' bot.cd() ref = hists[0].GetPassedHistogram().Clone() h = hists[1].GetPassedHistogram().Clone() #ref = hists[0].Clone() #h = hists[1].Clone() ref.Sumw2() h.Sumw2() ref.Divide(hists[0].GetTotalHistogram().Clone()) h.Divide(hists[1].GetTotalHistogram().Clone()) #ratioplot = TEfficiency(h,ref) ratioplot = h.Clone() ratioplot.Sumw2() ratioplot.SetName(h.GetName() + '_ratio') ratioplot.Divide(h, ref, 1., 1., '') #ratioplot.Divide(ref) ratioplot.SetFillColor(0) ratioplot.SetFillStyle(0) ratioplot.SetMarkerColor(1) ratioplot.SetLineColor(kBlack) ratioplot.SetMarkerStyle(24) ratioplot.SetMarkerSize(1.2) ratioplot.GetYaxis().SetTitle('trigger / ref') ratioplot.GetYaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetTitleSize(0.10) ratioplot.GetXaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetLabelSize(0.10) ratioplot.GetYaxis().SetRangeUser(0.9, 1.07) ratioplot.Draw(drawopt) tobject_collector.append(ratioplot) #atlas_template(bot, **kwargs) from ROOT import TLine l1 = TLine(xmin, 1, xmax, 1) l1.SetLineColor(kRed) l1.SetLineStyle(2) l1.Draw() tobject_collector.append(l1) bot.Update() else: atlas_template(pad, **kwargs) pad.Update() canvas.SaveAs(oname + '.pdf')