def setCMSLumiStyle(pad, iPosX, **kwargs): global outOfFrame, lumiTextSize, lumiText if iPosX / 10 == 0: outOfFrame = True lumiTextSize_ = lumiTextSize relPosX_ = kwargs.get('relPosX', relPosX) lumiText_ = kwargs.get('lumiText', lumiText) if outOfFrame: lumiTextSize_ *= 0.90 if 'era' in kwargs: # one era era = kwargs.get('era') setCMSEra(era, **kwargs) elif 'eras' in kwargs: # list of multiple eras eras = kwargs.get('eras') setCMSEra(*eras, **kwargs) #if lumiText=="": # if iPeriod==1: # lumiText += lumi_7TeV # lumiText += " (7 TeV)" # elif iPeriod==2: # lumiText += lumi_8TeV # lumiText += " (8 TeV)" # elif iPeriod==3: # lumiText = lumi_8TeV # lumiText += " (8 TeV)" # lumiText += " + " # lumiText += lumi_7TeV # lumiText += " (7 TeV)" # elif iPeriod==4: # lumiText += lumi_13TeV # lumiText += " (13 TeV)" # elif iPeriod==7: # if outOfFrame: lumiTextSize_ *= 0.85 # lumiText += lumi_13TeV # lumiText += " (13 TeV)" # lumiText += " + " # lumiText += lumi_8TeV # lumiText += " (8 TeV)" # lumiText += " + " # lumiText += lumi_7TeV # lumiText += " (7 TeV)" # elif iPeriod==12: # lumiText += "8 TeV" # else: # if outOfFrame: lumiTextSize_ *= 0.90 # if iPeriod==13: # lumiText += lumi_13TeV # lumiText += " (13 TeV)" # elif iPeriod==2016: # lumiText += lumi_2016 # lumiText += " (13 TeV)" # elif iPeriod==2017: # lumiText += lumi_2017 # lumiText += " (13 TeV)" # elif iPeriod==2018: # lumiText += lumi_2018 # lumiText += " (13 TeV)" # elif iPeriod==14: # lumiText += lumi_14TeV # lumiText += " (14 TeV, 200 PU)" ##print lumiText alignY_ = 3 alignX_ = 2 if iPosX == 0: alignY_ = 1 if iPosX / 10 == 0: alignX_ = 1 elif iPosX / 10 == 1: alignX_ = 1 elif iPosX / 10 == 2: alignX_ = 2 elif iPosX / 10 == 3: alignX_ = 3 align = 10 * alignX_ + alignY_ extraTextSize = extraOverCmsTextSize * cmsTextSize H = pad.GetWh() * pad.GetHNDC() W = pad.GetWw() * pad.GetWNDC() l = pad.GetLeftMargin() t = pad.GetTopMargin() r = pad.GetRightMargin() b = pad.GetBottomMargin() e = 0.025 scale = float(H) / W if W > H else 1 # float(W)/H pad.cd() latex = TLatex() latex.SetNDC() latex.SetTextAngle(0) latex.SetTextColor(kBlack) latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(lumiTextSize_ * t) if lumiText_: latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText_) if iPosX == 0: relPosX_ = relPosX_ * (50 * t * scale) * (cmsTextSize / 0.84) posX = l + relPosX_ * (1 - l - r) posY = 1 - t + lumiTextOffset * t else: posX = 0 posY = 1 - t - relPosY * (1 - t - b) if iPosX % 10 <= 1: posX = l + relPosX_ * (1 - l - r) # left aligned elif iPosX % 10 == 2: posX = l + 0.5 * (1 - l - r) # centered elif iPosX % 10 == 3: posX = 1 - r - relPosX_ * (1 - l - r) # right aligned if outOfFrame: TGaxis.SetExponentOffset(-0.12 * float(H) / W, 0.015, 'y') latex.SetTextFont(cmsTextFont) latex.SetTextAlign(11) latex.SetTextSize(cmsTextSize * t) latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextSize(extraTextSize * t) latex.SetTextAlign(align) latex.DrawLatex(posX, posY, extraText) elif drawLogo: posX = l + 0.045 * (1 - l - r) * W / H posY = 1 - t - 0.045 * (1 - t - b) xl_0 = posX yl_0 = posY - 0.15 xl_1 = posX + 0.15 * H / W yl_1 = posY CMS_logo = TASImage("CMS-BW-label.png") pad_logo = TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1) pad_logo.Draw() pad_logo.cd() CMS_logo.Draw('X') pad_logo.Modified() pad.cd() else: latex.SetTextFont(cmsTextFont) latex.SetTextSize(cmsTextSize * t) latex.SetTextAlign(align) latex.DrawLatex(posX, posY, cmsText) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextAlign(align) latex.SetTextSize(extraTextSize * t) latex.DrawLatex(posX, posY - relExtraDY * cmsTextSize * t, extraText) pad.Update()
def cms_lumi(pad, iPeriod, iPosX): outOfFrame = False if iPosX / 10 == 0: outOfFrame = True alignY_ = 3 alignX_ = 2 if iPosX / 10 == 0: alignX_ = 1 if iPosX == 0: alignY_ = 1 if iPosX / 10 == 1: alignX_ = 1 if iPosX / 10 == 2: alignX_ = 2 if iPosX / 10 == 3: alignX_ = 3 align_ = 10 * alignX_ + alignY_ H = pad.GetWh() W = pad.GetWw() l = pad.GetLeftMargin() t = pad.GetTopMargin() r = pad.GetRightMargin() b = pad.GetBottomMargin() # e = 0.025 pad.cd() lumiText = TString('') if iPeriod == 1: lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 2: lumiText += lumi_8TeV lumiText += " (8 TeV)" elif iPeriod == 3: lumiText = lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 4: lumiText += lumi_13TeV lumiText += " (13 TeV)" elif iPeriod == 7: if outOfFrame: lumiText += "#scale[0.85]{" lumiText += lumi_13TeV lumiText += " (13 TeV)" lumiText += " + " lumiText += lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" if outOfFrame: lumiText += "}" elif iPeriod == 12: lumiText += "8 TeV" elif iPeriod == 14: lumiText += lumi_14TeV lumiText += ", 14 TeV" elif iPeriod == 1420: lumiText += lumi_1420TeV lumiText += ", 14 TeV" print lumiText latex = TLatex() latex.SetNDC() latex.SetTextAngle(0) latex.SetTextColor(TStyle.kBlack) extraTextSize = extraOverCmsTextSize * cmsTextSize latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(lumiTextSize * t) latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText.Data()) if outOfFrame: latex.SetTextFont(cmsTextFont) latex.SetTextAlign(11) latex.SetTextSize(cmsTextSize * t) latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText) pad.cd() posX_ = 0 if iPosX % 10 <= 1: posX_ = l + relPosX * (1 - l - r) elif iPosX % 10 == 2: posX_ = l + 0.5 * (1 - l - r) elif iPosX % 10 == 3: posX_ = 1 - r - relPosX * (1 - l - r) posY_ = 1 - t - relPosY * (1 - t - b) if not outOfFrame: if drawLogo: posX_ = l + 0.045 * (1 - l - r) * W / H posY_ = 1 - t - 0.045 * (1 - t - b) xl_0 = posX_ yl_0 = posY_ - 0.15 xl_1 = posX_ + 0.15 * H / W yl_1 = posY_ CMS_logo = TASImage("CMS-BW-label.png") pad_logo = TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1) pad_logo.Draw() pad_logo.cd() CMS_logo.Draw("X") pad_logo.Modified() pad.cd() else: latex.SetTextFont(cmsTextFont) latex.SetTextSize(cmsTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, cmsText.Data()) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextAlign(align_) latex.SetTextSize(extraTextSize * t) latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText) elif writeExtraText: if iPosX == 0: posX_ = l + relPosX * (1 - l - r) posY_ = 1 - t + lumiTextOffset * t latex.SetTextFont(extraTextFont) latex.SetTextSize(extraTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, extraText)
class EEG_Graph(object): def __init__(self, maxpoints=60): self.maxpoints = maxpoints self.gq = False self.canvas = TCanvas('c1', 'A Simple Graph Example', 200, 10, 700, 500) self.canvas_1 = TPad("c1_1", "c1_1", 0.01, 0.67, 0.99, 0.99) self.canvas_2 = TPad("c1_2", "c1_2", 0.01, 0.01, 0.99, 0.66) self.canvas_1.SetGrid() self.canvas_2.SetGridx() self.canvas_1.Draw() self.canvas_2.Draw() self.data = [0] self.data_time = [time.time()] n = 1 x = array('d') y = array('d') x.append(0) y.append(0) self.canvas_1.cd() self.graph = TGraph(n, x, y) self.graph.SetLineColor(2) self.graph.SetLineWidth(4) self.graph.SetMarkerColor(4) self.graph.SetMarkerStyle(2) self.graph.SetTitle('EEG Signal') self.graph.GetXaxis().SetTitle('Time') self.graph.GetYaxis().SetTitle('Amplitude') self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.graph.Draw('ACP') self.canvas_2.cd() TVirtualFFT.SetTransform(0) self.fft = TH1F("fft", "eeg_fft", 3, 0, 3) self.fft.SetTitle("EEG FFT") self.fft.Fill("1 Hz", 0) self.fft.Fill("2 Hz", 0) self.fft.SetMinimum(0) self.fft.SetMaximum(100000) self.fft.SetFillStyle(3001) self.fft.SetFillColor(30) self.fft.Draw("B HIST") self.ampmax = 100000 self.fft.SetStats(False) self.fft.GetXaxis().SetLabelSize(0.05) self.fft.GetYaxis().SetLabelSize(0.05) def setQuality(self, good): self.gq = good def append(self, timep, num): n = self.graph.GetN() if len(self.data) < 2048: self.data = self.data + [num] self.data_time = self.data_time + [time.time()] else: self.data = self.data[1:] + [num] self.data_time = self.data_time[1:] + [time.time()] if n < self.maxpoints: self.graph.Set(n + 1) self.graph.SetPoint(n, timep, num) else: self.graph.RemovePoint(0) self.graph.Set(n) self.graph.SetPoint(n - 1, timep, num) self.data_fft = np.abs(np.fft.fft(self.data)) self.fft.Reset() if len(self.data_fft) > 256: delta = self.data_time[-1] - self.data_time[0] for i in range(50): amp = np.sum(self.data_fft[round(i * delta):round(i * delta + delta)]) self.fft.Fill("%i Hz" % (i + 1, ), amp) if amp > self.ampmax: self.ampmax = amp self.fft.SetMaximum(amp) self.update() def update(self): self.canvas_1.cd() if self.gq: self.canvas_1.GetFrame().SetFillColor(30) else: self.canvas_1.GetFrame().SetFillColor(46) self.canvas.GetFrame().SetBorderSize(12) self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.canvas_2.Modified() self.canvas.Modified() self.canvas.Update()
def CMS_lumi(pad, iPeriod, iPosX, lumiText="", **kwargs): global outOfFrame if iPosX / 10 == 0: outOfFrame = True lumiTextSize_ = lumiTextSize relPosX_ = kwargs.get('relPosX', relPosX) if lumiText == "": if iPeriod == 1: lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 2: lumiText += lumi_8TeV lumiText += " (8 TeV)" elif iPeriod == 3: lumiText = lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 4: lumiText += lumi_13TeV lumiText += " (13 TeV)" elif iPeriod == 7: if outOfFrame: lumiTextSize_ *= 0.85 lumiText += lumi_13TeV lumiText += " (13 TeV)" lumiText += " + " lumiText += lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" elif iPeriod == 12: lumiText += "8 TeV" else: if outOfFrame: lumiTextSize_ *= 0.90 if iPeriod == 13: lumiText += lumi_13TeV lumiText += " (13 TeV)" elif iPeriod == 2016: lumiText += lumi_2016 lumiText += " (13 TeV)" elif iPeriod == 2017: lumiText += lumi_2017 lumiText += " (13 TeV)" elif iPeriod == 2018: lumiText += lumi_2018 lumiText += " (13 TeV)" elif iPeriod == 14: lumiText += lumi_14TeV lumiText += " (14 TeV, 200 PU)" #print lumiText alignY_ = 3 alignX_ = 2 if iPosX == 0: alignY_ = 1 if iPosX / 10 == 0: alignX_ = 1 elif iPosX / 10 == 1: alignX_ = 1 elif iPosX / 10 == 2: alignX_ = 2 elif iPosX / 10 == 3: alignX_ = 3 align = 10 * alignX_ + alignY_ extraTextSize = extraOverCmsTextSize * cmsTextSize H = pad.GetWh() W = pad.GetWw() l = pad.GetLeftMargin() t = pad.GetTopMargin() r = pad.GetRightMargin() b = pad.GetBottomMargin() e = 0.025 pad.cd() latex = TLatex() latex.SetNDC() latex.SetTextAngle(0) latex.SetTextColor(kBlack) latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(lumiTextSize_ * t) if lumiText: latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText) if iPosX == 0: relPosX_ = relPosX_ * 32 * t posX = l + relPosX_ * (1 - l - r) posY = 1 - t + lumiTextOffset * t else: posX = 0 posY = 1 - t - relPosY * (1 - t - b) if iPosX % 10 <= 1: posX = l + relPosX_ * (1 - l - r) # left aligned elif iPosX % 10 == 2: posX = l + 0.5 * (1 - l - r) # centered elif iPosX % 10 == 3: posX = 1 - r - relPosX_ * (1 - l - r) # right aligned if outOfFrame: #TGaxis.SetExponentOffset(-0.074,0.015,'y') latex.SetTextFont(cmsTextFont) latex.SetTextAlign(11) latex.SetTextSize(cmsTextSize * t) latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextSize(extraTextSize * t) latex.SetTextAlign(align) latex.DrawLatex(posX, posY, extraText) elif drawLogo: posX = l + 0.045 * (1 - l - r) * W / H posY = 1 - t - 0.045 * (1 - t - b) xl_0 = posX yl_0 = posY - 0.15 xl_1 = posX + 0.15 * H / W yl_1 = posY CMS_logo = TASImage("CMS-BW-label.png") pad_logo = TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1) pad_logo.Draw() pad_logo.cd() CMS_logo.Draw('X') pad_logo.Modified() pad.cd() else: latex.SetTextFont(cmsTextFont) latex.SetTextSize(cmsTextSize * t) latex.SetTextAlign(align) latex.DrawLatex(posX, posY, cmsText) if writeExtraText: latex.SetTextFont(extraTextFont) latex.SetTextAlign(align) latex.SetTextSize(extraTextSize * t) latex.DrawLatex(posX, posY - relExtraDY * cmsTextSize * t, extraText) pad.Update()
def PlotRatio(h_reco_unfolded,h_ptcl_or,h_reco_unfolded_roof, h_reco_unfolded_svd, h_reco_unfolded_T,h_reco_unfolded_Ids, svd_par, Ids_par ,outputname="test.png"): gStyle.SetPadLeftMargin(0.12) gStyle.SetPadRightMargin(0.12) c = TCanvas("canvas_"+outputname,"canvas_"+outputname,0,0,800, 800) c.cd() pad1 = TPad("pad1","pad1",0,0.40,1,1) pad1.SetTopMargin(0.15) pad1.SetBottomMargin(0.01) pad1.SetFillStyle(0) pad1.SetTicks(1,1) pad1.SetBorderMode(0) pad1.Draw() c.cd() pad2 = TPad("pad2","pad2",0,0.01,1,0.422) pad2.SetFillStyle(0) pad2.SetTopMargin(0.043) pad2.SetBottomMargin(0.2) pad2.SetBorderMode(0) pad2.SetTicks(1,1) pad2.Draw() pad2.Modified() c.cd() pad1.cd() gStyle.SetOptStat(0) h_ptcl_or.SetTitle("") h_ptcl_or.SetLineColor(2) #h_ptcl_or.GetYaxis().SetRangeUser(0,h_ptcl_or.GetMaximum()*1.5) h_ptcl_or.GetXaxis().SetTitleSize(34) h_ptcl_or.GetXaxis().SetTitleFont(43) h_ptcl_or.GetYaxis().SetTitleSize(27) h_ptcl_or.GetYaxis().SetTitleFont(43) h_ptcl_or.GetYaxis().SetTitleOffset(1.5) h_ptcl_or.GetYaxis().SetTitle("Events") h_ptcl_or.GetYaxis().SetLabelFont(43) h_ptcl_or.GetYaxis().SetLabelSize(25) legend = TLegend(0.55,0.5,0.85,0.8) legend.SetFillStyle(0) legend.AddEntry(h_ptcl_or,"Simulation") legend.AddEntry(h_reco_unfolded,"Fully Bayesian Unfolding","p") legend.AddEntry(h_reco_unfolded_roof,"D'Agostini RooUnfold, par. 4","p") legend.AddEntry(h_reco_unfolded_svd,"SVD RooUnfold, par. " + str(svd_par),"p") legend.AddEntry(h_reco_unfolded_T,"T RooUnfold","p") legend.AddEntry(h_reco_unfolded_Ids,"Ids RooUnfold, par. " + str(Ids_par),"p") legend.SetBorderSize(0) h_reco_unfolded.SetLineColor(1) h_reco_unfolded.SetMarkerColor(1) h_reco_unfolded.SetMarkerStyle(22) h_reco_unfolded_roof.SetMarkerColor(6) h_reco_unfolded_roof.SetLineColor(6) h_reco_unfolded_roof.SetMarkerStyle(20) h_reco_unfolded_svd.SetMarkerColor(4) h_reco_unfolded_svd.SetLineColor(4) h_reco_unfolded_svd.SetMarkerStyle(5) h_reco_unfolded_T.SetMarkerColor(7) h_reco_unfolded_T.SetLineColor(7) h_reco_unfolded_T.SetMarkerStyle(34) h_reco_unfolded_Ids.SetMarkerColor(8) h_reco_unfolded_Ids.SetLineColor(8) h_reco_unfolded_Ids.SetMarkerStyle(3) h_ptcl_or.Draw("hist") h_reco_unfolded.Draw("same p x0") h_reco_unfolded_roof.Draw("same p x0") h_reco_unfolded_svd.Draw("same p x0") h_reco_unfolded_T.Draw("same p x0") h_reco_unfolded_Ids.Draw("same p x0") legend.Draw("same") pad1.RedrawAxis() pad2.cd() h_ptcl_or_clone = h_ptcl_or.Clone(h_ptcl_or.GetName()+"_clone") h_reco_unfolded_clone = h_reco_unfolded.Clone(h_reco_unfolded.GetName()+"_clone") h_reco_unfolded_roof_clone = h_reco_unfolded_roof.Clone(h_reco_unfolded_roof.GetName()+"_clone") h_reco_unfolded_svd_clone = h_reco_unfolded_svd.Clone(h_reco_unfolded_svd.GetName()+"_clone") h_reco_unfolded_T_clone = h_reco_unfolded_T.Clone(h_reco_unfolded_T.GetName()+"_clone") h_reco_unfolded_Ids_clone = h_reco_unfolded_Ids.Clone(h_reco_unfolded_Ids.GetName()+"_clone") h_ptcl_or_clone.Divide(h_ptcl_or) h_reco_unfolded_clone.Divide(h_ptcl_or) h_reco_unfolded_roof_clone.Divide(h_ptcl_or) h_reco_unfolded_svd_clone.Divide(h_ptcl_or) h_reco_unfolded_T_clone.Divide(h_ptcl_or) h_reco_unfolded_Ids_clone.Divide(h_ptcl_or) h_ptcl_or_clone.GetXaxis().SetTitleSize(27) h_ptcl_or_clone.GetXaxis().SetTitleFont(43) h_ptcl_or_clone.GetYaxis().SetTitleSize(27) h_ptcl_or_clone.GetYaxis().SetTitleFont(43) h_ptcl_or_clone.GetXaxis().SetLabelFont(43) h_ptcl_or_clone.GetXaxis().SetLabelSize(25) h_ptcl_or_clone.GetYaxis().SetLabelFont(43) h_ptcl_or_clone.GetYaxis().SetLabelSize(25) h_ptcl_or_clone.SetMaximum(1.3) h_ptcl_or_clone.SetMinimum(0.7) h_ptcl_or_clone.GetXaxis().SetTitleOffset(2.5) h_ptcl_or_clone.GetXaxis().SetTitle(args.title) h_ptcl_or_clone.GetYaxis().SetTitle("#frac{Unfolded}{Simulation} ") h_ptcl_or_clone.Draw("hist") h_reco_unfolded_clone.Draw("same p x0") h_reco_unfolded_roof_clone.Draw("same p x0") h_reco_unfolded_svd_clone.Draw("same p x0") h_reco_unfolded_T_clone.Draw("same p x0") h_reco_unfolded_Ids_clone.Draw("same p x0") pad2.RedrawAxis() c.Update() histograms.append(c) # here is the crash probably PrintCan(c, outputname)
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')
def set_CMS_lumi(pad, iPeriod, iPosX, lumival): #pad = TPad('pad1','This is pad1',0.02,0.52,0.48,0.98,21) outOfFrame = False if (iPosX / 10 == 0): outOfFrame = True alignY_ = 3 alignX_ = 2 if (iPosX == 0): alignX_ = 1 if (iPosX == 0): alignY_ = 1 if (iPosX / 10 == 1): alignX_ = 1 if (iPosX / 10 == 2): alignX_ = 2 if (iPosX / 10 == 3): alignX_ = 3 align_ = 10 * alignX_ + alignY_ H = pad.GetWindowHeight() W = pad.GetWindowWidth() l = pad.GetLeftMargin() r = pad.GetRightMargin() t = pad.GetTopMargin() b = pad.GetBottomMargin() pad.cd() lumi_7TeV = str(lumival) + " fb^{-1}" lumi_8TeV = str(lumival) + " fb^{-1}" lumi_13TeV = str(lumival) + " fb^{-1}" if (iPeriod == 1): lumiText = lumi_7TeV lumiText += " (7TeV)" elif (iPeriod == 2): lumiText = lumi_8TeV lumiText += " (8TeV)" elif (iPeriod == 3): lumiText = lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" elif (iPeriod == 4): lumiText = lumi_13TeV lumiText += " (13 TeV)" elif (iPeriod == 7): if (outOfFrame): lumiText += "#scale[0.85]{" lumiText += lumi_13TeV lumiText += " (13 TeV)" lumiText += " + " lumiText += lumi_8TeV lumiText += " (8 TeV)" lumiText += " + " lumiText += lumi_7TeV lumiText += " (7 TeV)" if (outOfFrame): lumiText += "}" elif (iPeriod == 12): lumiText += "8 TeV" elif (iPeriod == 0): lumiText += lumi_sqrtS latex = ROOT.TLatex() latex.SetNDC() latex.SetTextAngle(0) latex.SetTextColor(kBlack) extraTextSize = extraOverCmsTextSize * cmsTextSize latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(lumiTextSize * t) latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText) if (outOfFrame): latex.SetTextFont(cmsTextFont) latex.SetTextAlign(11) latex.SetTextSize(cmsTextSize * t) latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText) pad.cd() posX_ = 0 if (iPosX % 10 <= 1): posX_ = l + relPosX * (1 - l - r) elif (iPosX % 10 == 2): posX_ = l + 0.5 * (1 - l - r) elif (iPosX % 10 == 3): posX_ = 1 - r - relPosX * (1 - l - r) posY_ = 1 - t - relPosY * (1 - t - b) if (outOfFrame == False): if (drawLogo): posX_ = l + 0.045 * (1 - l - r) * W / H posY_ = 1 - t - 0.045 * (1 - t - b) xl_0 = posX_ yl_0 = posY_ - 0.15 xl_1 = posX_ + 0.15 * H / W yl_1 = posY_ #TASImage* CMS_logo = new TASImage("CMSlogoBW.png"); pad_logo = TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1) pad_logo.raw() pad_logo.cd() CMS_logo.Draw("X") pad_logo.Modified() pad.cd() else: latex.SetTextFont(cmsTextFont) latex.SetTextSize(cmsTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, cmsText) if (writeExtraText == True): #posX_ = l + relPosX*(1-l-r); #posY_ = 1-t+lumiTextOffset*t; # posX_= l + relPosX*(1-l-r) #posY_= 1-t+lumiTextOffset*t latex.SetTextFont(extraTextFont) latex.SetTextAlign(align_) latex.SetTextSize(extraTextSize * t) latex.DrawLatex(posX_ + relExtraDX * cmsTextSize * t, posY_, extraText) #posY_-relExtraDY*cmsTextSize*t, extraText) #latex.DrawLatex(posX_, posY_, extraText) elif (writeExtraText): if (iPosX == 0): posX_ = l + relPosX * (1 - l - r) posY_ = 1 - t + lumiTextOffset * t latex.SetTextFont(extraTextFont) latex.SetTextSize(extraTextSize * t) latex.SetTextAlign(align_) latex.DrawLatex(posX_, posY_, extraText) return
pad2 = TPad("pad2", "pad2", 0.05, 0.05, 0.95, 0.45, 21) pad1.Draw() pad2.Draw() gBenchmark.Start("fillrandom") form1 = TFormula("form1", "abs(sin(x)/x)") sqroot = TF1("sqroot", "x*gaus(0) + [3]*form1", 0, 10) sqroot.SetParameters(10, 4, 1, 20) #pad1.SetGridx() pad2.SetGridy() pad1.SetGrid() c1.Update() pad1.cd() sqroot.Draw() pad1.Modified() pad1.Update() pad2.cd() pad2.GetFrame().SetFillColor(42) pad2.GetFrame().SetBorderMode(-1) pad2.GetFrame().SetBorderSize(5) h1f = TH1F("h1f", "h1f", 200, 0, 10) h1f.FillRandom("sqroot", 10000) h1f.Draw() pad2.Update() myfile = TFile("py-fillrandom.root", "recreate") form1.Write() sqroot.Write() h1f.Write()