def CMSPrelim(dataset, channel, lowX, lowY): cmsprel = TPaveText(lowX, lowY + 0.06, lowX + 0.30, lowY + 0.16, "NDC") cmsprel.SetBorderSize(0) cmsprel.SetFillStyle(0) cmsprel.SetTextAlign(12) cmsprel.SetTextSize(0.04) cmsprel.SetTextColor(1) cmsprel.SetTextFont(62) cmsprel.AddText(dataset) ## lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") ## lumi.SetBorderSize( 0 ) ## lumi.SetFillStyle( 0 ) ## lumi.SetTextAlign( 12 ) ## lumi.SetTextSize ( 0.04 ) ## lumi.SetTextColor( 1 ) ## lumi.SetTextFont ( 62 ) ## lumi.AddText(dataset) chan = TPaveText(lowX + 0.68, lowY + 0.061, lowX + 0.80, lowY + 0.161, "NDC") chan.SetBorderSize(0) chan.SetFillStyle(0) chan.SetTextAlign(12) chan.SetTextSize(0.05) chan.SetTextColor(1) chan.SetTextFont(62) chan.AddText(channel) return cmsprel, chan
def drawenergy1D(is2017, text_="Work in progress 2018", data=True): pt = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(52) cmstextSize = 0.07 preliminarytextfize = cmstextSize * 0.7 lumitextsize = cmstextSize *0.7 pt.SetTextSize(cmstextSize) text = pt.AddText(0.063,0.57,"#font[61]{CMS}") pt1 = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") pt1.SetBorderSize(0) pt1.SetTextAlign(12) pt1.SetFillStyle(0) pt1.SetTextFont(52) pt1.SetTextSize(preliminarytextfize) text1 = pt1.AddText(0.215,0.4,text_) pt2 = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") pt2.SetBorderSize(0) pt2.SetTextAlign(12) pt2.SetFillStyle(0) pt2.SetTextFont(52) pt2.SetTextFont(42) pt2.SetTextSize(lumitextsize) # text3 = pt2.AddText(0.53,0.5,"#sqrt{s} = 13 TeV(2017)") #pavetext = '' #if is2017: pavetext = "#sqrt{s} = 13 TeV(2017)" #if not is2017: pavetext = "#sqrt{s} = 13 TeV(2018)" #text3 = pt2.AddText(0.61,0.5,pavetext) pavetext = '' if is2017 and data: pavetext = "(13 TeV)" if (not is2017) and data: pavetext = "(13 TeV)" if is2017 and not data: pavetext = "13 TeV" if (not is2017) and not data: pavetext = "13 TeV" if data: text3 = pt2.AddText(0.81,0.5,pavetext) if not data: text3 = pt2.AddText(0.85,0.5,pavetext) return [pt,pt1,pt2] return [pt,pt1,pt2]
def bpmass_nonres_below5(args, figname): datatype = args[0] label = args[1] test = option_exists(args, '-t') rootname = figname.replace('bpmass_nonres_below5', 'summary') rootfile = set_file(atr.figpath, label, rootname, '.root', test=test) figfile = set_file(atr.figpath, label, figname, '.pdf', test=test) c = TCanvas("aCanvas", "Canvas", 600, 600) gStyle.SetPadLeftMargin(0.15) gStyle.SetOptTitle(0) c.UseCurrentStyle() f = TFile(rootfile) h = f.Get('h_bpmass_nonres_below5') h.GetYaxis().SetTitle(get_y_title(h, 'GeV')) h.GetYaxis().SetTitleOffset(1.6) h.Draw() pt = TPaveText() if label == 'Run2011v10.2': pt = TPaveText(4.2, 10, 4.8, 12) pt.SetBorderSize(0) pt.SetFillColor(0) pt.AddText("Entries = %d" % h.GetEntries()) pt.Draw() c.Print(figfile) f.Close()
def bctau(args, figname): datatype = args[0] label = args[1] test = option_exists(args, '-t') rootname = figname.replace('bctau', 'summary') rootfile = set_file(atr.figpath, label, rootname, '.root', test=test) figfile = set_file(atr.figpath, label, figname, '.pdf', test=test) c = TCanvas("aCanvas", "Canvas", 600, 600) gStyle.SetPadLeftMargin(0.15) gStyle.SetOptTitle(0) c.UseCurrentStyle() f = TFile(rootfile) h = f.Get('h_bctau') h.GetYaxis().SetTitle(get_y_title(h, 'cm')) h.GetYaxis().SetTitleOffset(1.6) h.Draw() pt = TPaveText(0.2, 1.6e5, 0.6, 1.8e5) pt.SetBorderSize(0) pt.SetFillColor(0) pt.AddText("Entries = %d" % h.GetEntries()) pt.Draw() c.Print(figfile) f.Close()
def kstarpmass(args, figname): datatype = args[0] label = args[1] test = option_exists(args, '-t') #rootname = 'SingleBuToKstarMuMu_summary_data_Run2011v10' rootname = figname.replace('kstarpmass', 'summary') rootfile = set_file(atr.figpath, label, rootname, '.root', test=test) figfile = set_file(atr.figpath, label, figname, '.pdf', test=test) c = TCanvas("aCanvas", "Canvas", 600, 600) gStyle.SetPadLeftMargin(0.15) gStyle.SetOptTitle(0) c.UseCurrentStyle() f = TFile(rootfile) h = f.Get('h_kstarpmass') h.GetYaxis().SetTitle(get_y_title(h, 'GeV')) h.GetYaxis().SetTitleOffset(1.5) h.Draw() pt = TPaveText() if label == 'Run2011v10.1': pt = TPaveText(1, 70, 1.1, 80) if label == 'Run2011v10.2': pt = TPaveText(1, 70, 1.1, 80) pt.SetBorderSize(0) pt.SetFillColor(0) pt.AddText("Entries = %d" % h.GetEntries()) pt.Draw() c.Print(figfile) f.Close()
def plot(obj, plot_name, plot_notes=[]): canvas = TCanvas('canvas' + plot_name, "Canvas", 450, 450) gPad.SetLeftMargin(.13) gPad.SetTopMargin(.05) gStyle.SetOptStat(11) gStyle.SetOptFit(1111) if 'TH2' in obj.ClassName(): gPad.SetRightMargin(.13) draw_options = 'COLZ' if 'profile' in obj.GetName(): gPad.SetRightMargin(.05) draw_options = '' if 'graph' in obj.GetName(): gPad.SetRightMargin(.05) draw_options = 'APE' obj.SetMarkerSize(.7) obj.SetMarkerStyle(21) note = TPaveText(.2, .7, .5, .9, "brNDC") note.SetFillStyle(0) note.SetFillColor(0) note.SetBorderSize(0) note.SetTextColor(1) note.SetTextFont(42) note.SetTextAlign(11) for note_text in plot_notes: note.AddText(note_text) obj.Draw(draw_options) note.Draw() canvas.Print('output/' + plot_name + '.pdf')
def plotHoAboveThr(): c5 = TCanvas("c5","c5",1200,1200) noTrgTdmiAboveThrNotConverted = file.Get("hoMuonAnalyzer/graphs/NoTrgTdmiAboveThr") noTrgTdmiAboveThr = PlotStyle.convertToHcalCoords(noTrgTdmiAboveThrNotConverted) noTrgTdmiAboveThr.GetXaxis().SetTitle("i#eta / a.u.") noTrgTdmiAboveThr.GetYaxis().SetTitle("i#phi / a.u.") noTrgTdmiAboveThr.SetMarkerStyle(6) noTrgTdmiAboveThr.SetMarkerColor(PlotStyle.colorRwthDarkBlue) noTrgTdmiAboveThr.SetTitle("#eta #phi plot of HO > 0.2 GeV in no Single #mu Trg. events") noTrgTdmiAboveThr.Draw("AP") pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.AddText('No Single #mu in GA: %d' % (noSingleMuEventsInGa)) pText.AddText('Events in Plot: %d' % (noTrgTdmiAboveThr.GetN())) pText.SetBorderSize(1) pText.Draw() chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 labelCmsPrivateSimulation = PlotStyle.getLabelCmsPrivateSimulation() chimney1Converted.Draw("same,l") chimney2Converted.Draw("same,l") labelCmsPrivateSimulation.Draw() legend = TLegend(0.1,0.87,0.3,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.Draw() #c5.SetGridY(0) #c5.SetGridX(0) c5.Update() c5.SaveAs("plots/graphsEtaPhi/gNoTrgTdmiHoAboveThr.png")
def checklatex(texts, tag=""): """Check legend entries: colors, titles, ...""" # https://root.cern.ch/doc/master/classTPaveText.html LOG.header("checklegend" + tag.replace('_', ' ')) output = ensuredir('plots') fname = "%s/testLatex%s" % (output, tag) xdim = 500 ydim = 50 * (len(texts) + 2.5) print ">>> Canvas: %sx%s (nlines=%d)" % (xdim, ydim, len(texts)) canvas = TCanvas('canvas', 'canvas', xdim, int(ydim)) #pave1 = TPaveText(0.0,0,0.5,1,'ARC') #,'BR') pave2 = TPaveText(0.04, 0.04, 0.96, 0.96) #'ARC') #,'BR') #pave1.SetBorderSize(0) pave2.SetBorderSize(0) #pave1.SetTextAlign(12) pave2.SetTextAlign(12) #pave1.SetTextFont(42) pave2.SetTextFont(42) #pave1.SetFillColor(0) pave2.SetFillColor(0) #pave1.SetCornerRadius(0.05) #pave2.SetCornerRadius(0.05) #pave1.SetMargin(0.12) #pave1.SetTextSize(tsize) #pave2.Copy(pave1) for line in texts: latex = makelatex(line) print ">>> %r -> %r" % (line, latex) #pave1.AddText(line) pave2.AddText(latex) #pave1.Draw() pave2.Draw() canvas.SaveAs(fname + ".png") #canvas.SaveAs(fname+".pdf") canvas.Close()
def doPlotEventCount(filename='L1MuonHistogram.root'): if (DEBUG): print 'Opening file:', filename file = TFile.Open(filename) if (file == None): print 'Error opening file:', filename histoNames = [ 'hoMuonAnalyzer/L1_SingleMu3_Trig', 'hoMuonAnalyzer/etaPhi/NoSingleMu_DeltaEtaDeltaPhi', 'hoMuonAnalyzer/count/Events_Count' ] histograms = [] for s in histoNames: histograms.append(file.Get(s)) yValues = [] yValues.append(histograms[0].GetBinContent(1)) yValues.append(histograms[1].GetEntries()) nEvents = histograms[2].GetEntries() xLabels = ['No Single #mu trigger', 'HO > 0.2 GeV matched to Gen'] c = TCanvas('eventCountCanvas', 'PostLS1 Single #mu gun', 1200, 1200) hist = TH1D("eventCount", "PostLS1 Single #mu gun", len(xLabels), 0, len(xLabels)) for i, v in enumerate(xLabels): hist.SetBinContent(i + 1, yValues[i]) hist.GetXaxis().SetBinLabel(i + 1, str(v)) hist.SetStats(0) hist.SetLineColor(PlotStyle.colorRwthDarkBlue) hist.GetYaxis().SetTitle('#') # hist.GetYaxis().SetRangeUser(0.5,1.1) hist.SetLabelFont(62) hist.SetTitleFont(62) hist.Draw("") paveText = TPaveText(0.51, 0.75, 0.9, 0.9, 'NDC') paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[0], yValues[0], yValues[0] / nEvents * 100, calcSigma(yValues[0], nEvents) * 100)) paveText.AddText('%s: %d => %.2f%% #pm %.2f%%' % (xLabels[1], yValues[1], yValues[1] / yValues[0] * 100, calcSigma(yValues[1], yValues[0]) * 100)) paveText.SetBorderSize(1) paveText.Draw() PlotStyle.labelCmsPrivateSimulation.Draw() c.Update() c.SaveAs("eventCount.png") c.SaveAs("eventCount.pdf") c.SaveAs("eventCount.root") return c, hist
def printLHCb(optLR='L', isPrelim=False, optText=''): global lhcbStyle global lhcbNames lhcbName = None if (optLR is 'R'): lhcbName = TPaveText(0.70 - lhcbStyle.GetPadRightMargin(), 0.85 - lhcbStyle.GetPadTopMargin(), 0.95 - lhcbStyle.GetPadRightMargin(), 0.95 - lhcbStyle.GetPadTopMargin(), "BRNDC") elif (optLR is 'L'): lhcbName = TPaveText(lhcbStyle.GetPadLeftMargin() + 0.05, 0.85 - lhcbStyle.GetPadTopMargin(), lhcbStyle.GetPadLeftMargin() + 0.30, 0.95 - lhcbStyle.GetPadTopMargin(), "BRNDC") elif (optLR is 'BR'): lhcbName = TPaveText(0.70 - lhcbStyle.GetPadRightMargin(), 0.05 + lhcbStyle.GetPadBottomMargin(), 0.95 - lhcbStyle.GetPadRightMargin(), 0.15 + lhcbStyle.GetPadBottomMargin(), "BRNDC") if (isPrelim): lhcbName.AddText('#splitline{LHCb}{#scale[1.0]{Preliminary}}') else: lhcbName.AddText('LHCb') lhcbName.SetFillColor(0) lhcbName.SetTextAlign(12) lhcbName.SetBorderSize(0) lhcbName.Draw() lhcbNames += [lhcbName] return
def add_desc_to_canvas(config, xmin, ymin, xmax, ymax, size, content): txt1 = TPaveText(xmin, ymin, xmax, ymax, "NDC") txt1.SetFillColor(kWhite) txt1.SetFillStyle(0) txt1.SetBorderSize(0) txt1.SetTextAlign(12) # middle,left txt1.SetTextFont(42) # helvetica txt1.SetTextSize(size) if content["add_alice"]: txt1.AddText("ALICE work in progress") if content["add_gran"]: gran_desc = "#it{n}_{#it{#varphi}} #times #it{n}_{#it{r}} #times #it{n}_{#it{z}}" gran_str = "%d #times %d #times %d" % (config.grid_phi, config.grid_r, config.grid_z) txt1.AddText("%s = %s" % (gran_desc, gran_str)) if content["add_inputs"]: if config.opt_train[0] == 1 and config.opt_train[1] == 1: txt1.AddText("inputs: #it{#rho}_{SC} - <#it{#rho}_{SC}>, <#it{#rho}_{SC}>") elif config.opt_train[1] == 1: txt1.AddText("inputs: #it{#rho}_{SC} - <#it{#rho}_{SC}>") if content["add_events"]: txt1.AddText("#it{N}_{ev}^{training} = %d" % config.train_events) # txt1.AddText("#it{N}_{ev}^{validation} = %d" % config.test_events) # txt1.AddText("#it{N}_{ev}^{apply} = %d" % config.apply_events) if config.name == "dnn": txt1.AddText("%d epochs" % config.epochs) return txt1
def CreateLabel(self, xmin, ymin, xmax, ymax): label = TPaveText(xmin, ymin, xmax, ymax, "NDC") label.SetBorderSize(0) label.SetFillStyle(0) label.SetTextFont(42) label.AddText("Trigger: %s" % (self.__triggername)) return label
def plotEventsInAcceptance(): c = TCanvas("c","c",1200,1200) gTdmiInGaNotConverted = file.Get("hoMuonAnalyzer/graphs/tdmiInGaNotDead") gTdmiInGa = PlotStyle.convertToHcalCoords(gTdmiInGaNotConverted) gTdmiInGa.GetXaxis().SetTitle("i#eta") gTdmiInGa.GetYaxis().SetTitle("i#phi") gTdmiInGa.SetMarkerStyle(6) gTdmiInGa.SetMarkerColor(PlotStyle.colorRwthDarkBlue) gTdmiInGa.SetTitle("#eta #phi plot of HO geom. Acceptance and not dead channels") gTdmiInGa.Draw("AP") pText = TPaveText(0.7,0.85,0.9,0.9,'NDC') pText.AddText('Total Events: %d' % (totalEvents)) pText.AddText('Events in Plot: %d' % (gTdmiInGa.GetN())) pText.SetBorderSize(1) pText.Draw() chimney1 = PlotStyle.chimney1 chimney2 = PlotStyle.chimney2 labelCmsPrivateSimulation = PlotStyle.getLabelCmsPrivateSimulation() chimney1Converted.Draw("same,l") chimney2Converted.Draw("same,l") labelCmsPrivateSimulation.Draw() legend = TLegend(0.1,0.87,0.3,0.9) legend.AddEntry(chimney2Converted,"chimney","l") legend.Draw() c.Update() c.SaveAs("plots/graphsEtaPhi/gTdmiInGaNotDead.png")
def plotHoTime(self): c3 = TCanvas("c3","HO Time",1200,1200) skipNoisePlot = False if not skipNoisePlot: c3.Divide(1,2) c3.cd(1).SetLogy() label = getLabelCmsPrivateSimulation() label.Draw() hHoTime = self.fileHandler.getHistogram('hoRecHits_Time') hHoTime.SetStats(0) hHoTime.SetTitle("Time distribution for all HO Rec Hits") hHoTime.SetLineColor(colorRwthDarkBlue) hHoTime.SetLineWidth(3) hHoTime.Draw() label = getLabelCmsPrivateSimulation() label.Draw() hHoTimeAboveThr = self.fileHandler.getHistogram('hoRecHitsAboveThr_Time') c3.cd(2).SetLogy() hHoTimeAboveThr.SetStats(0) hHoTimeAboveThr.SetTitle("Time distribution for HO Rec Hits > 0.2 GeV") hHoTimeAboveThr.SetLineColor(colorRwthDarkBlue) hHoTimeAboveThr.SetLineWidth(3) setupAxes(hHoTimeAboveThr) hHoTimeAboveThr.Draw() label = getLabelCmsPrivateSimulation() label.Draw() self.debug(80*'#') self.debug( 'Integral of HO > 0.2 GeV time histogram:') self.debug( hHoTimeAboveThr.Integral()) self.debug('') xLow = -5 xHigh = 5 histogramBetween = hHoTimeAboveThr.Integral(hHoTimeAboveThr.FindBin(xLow),hHoTimeAboveThr.FindBin(xHigh)) histogramTotal = float(hHoTimeAboveThr.Integral()) self.debug( 'Histogram integral between %.f ns and %.f ns' % (xLow,xHigh) ) self.debug( '%d/%d => %.2f +/- %f' % (histogramBetween,histogramTotal ,histogramBetween/histogramTotal,calcSigma(histogramBetween, histogramTotal))) self.debug( 80*'#') fit = TF1("fit","gaus",-10,10) hHoTimeAboveThr.Fit(fit) pText = TPaveText(0.7,0.8,0.9,0.9,'NDC') pText.AddText('Mean: %.2f ns' % (fit.GetParameter(1))) pText.AddText('#sigma: %.2f ns' % (fit.GetParameter(2))) pText.SetBorderSize(1) pText.SetFillColor(0) pText.Draw() c3.Update() self.storeCanvas(c3,"hoTime") return c3,label,hHoTimeAboveThr,pText
def plotTriggerEfficiency(self, passesHist, totalHist, label=""): if self._fout and self._canvas: passesHist = passesHist.Rebin(self._rebinFactor, "passesHist") totalHist = totalHist.Rebin(self._rebinFactor, "totalHist") self.makePassesConsistentWithTotal(passesHist, totalHist) metGraph = TGraphAsymmErrors(passesHist, totalHist) metGraph.SetEditable(0) pt = TPaveText(0.409774, 0.843023, 0.809524, 0.890827, "brNDC") pt.SetBorderSize(0) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.0387597) pt.AddText(str(self._plotLabel)) cmsLabel = TPaveText(0.134085, 0.937984, 0.418546, 0.984496, "brNDC") cmsLabel.SetBorderSize(0) cmsLabel.SetFillStyle(0) cmsLabel.SetTextFont(62) cmsLabel.SetTextSize(0.0387597) cmsLabel.AddText("CMS Preliminary") lumiLabel = TPaveText(0.575188, 0.937339, 0.874687, 0.992894, "brNDC") lumiLabel.SetBorderSize(0) lumiLabel.SetFillStyle(0) lumiLabel.SetTextFont(42) lumiLabel.SetTextSize(0.0387597) lumiLabel.AddText(str(self._luminosityLabel)) setStyle(metGraph) self._canvas.cd() metGraph.Draw("ap") setAxisStyle(metGraph, "E_{T}^{miss, no #mu} [GeV]", label + " trigger efficiency", (0.0, 500.0), (0.0, 1.4)) pt.Draw("same") cmsLabel.Draw("same") lumiLabel.Draw("same") self._fout.cd() self._canvas.Write("triggerEfficiency_" + label) else: print "A TFile and TCanvas must be added. Not making plots..."
def identification(config): text = TPaveText(0.0, 0.95, 1.0, 1.0, "blNDC") text.AddText(config.message) text.SetBorderSize(0) text.SetTextAlign(12) text.SetTextSizePixels(10) text.SetTextFont(82) text.SetFillColor(0) return text
def getWaterMark(markPosition): watermark = TPaveText(markPosition['x1ndc'], markPosition['y1ndc'], markPosition['x2ndc'], markPosition['y2ndc'],"NDC") markText = watermark.AddText("A. Kuensken") markText.SetTextAlign(12) markText.SetTextSize(0.0316456) markText.SetTextColor(15) watermark.SetBorderSize(0) watermark.SetFillStyle(0) return watermark
def draw_canvas_1d(name): f_mc = TFile("plots/mc/%s_mcc7.root" % name) print(f_mc.ls()) print(name) h_mc = gDirectory.Get("h_%s_reco" % name) h_mc.SetName("h_%s_reco" % name) h_mc.SetLineColor(kRed + 1) h_mc.SetFillColor(kRed + 1) h_mc.SetFillStyle(0) h_mc.GetYaxis().SetTitle("Efficiency") h_mc.GetYaxis().SetRangeUser(0.61, 1.04) f = TFile("plots/data/e_%s_pandoraCosmic.root" % name) h = gDirectory.Get("h_%s" % name) h.SetMarkerStyle(20) h.SetLineColor(1) f_sys = TFile("plots/data/e_%s_sys_pandoraCosmic.root" % name) h_sys = gDirectory.Get("h_%s_sys" % name) h_ratio = h_sys.Clone() h_ratio.Divide(h_mc) x_minbin = h_mc.FindFirstBinAbove() low = h_mc.GetXaxis().GetBinLowEdge(x_minbin) x_maxbin = h_mc.FindLastBinAbove() high = h_mc.GetXaxis().GetBinUpEdge(x_maxbin) h_mc.GetXaxis().SetRangeUser(low, high) h_mc.GetYaxis().SetTitleSize(0.08) h_mc.GetYaxis().SetLabelSize(0.065) h_mc.GetYaxis().SetTitleOffset(0.59) h_ratio.GetXaxis().SetRangeUser(low, high) g_stat = histo2graph(h) g_sys = histo2graph(h_sys) g_sys.SetMarkerStyle(20) g_sys.SetLineWidth(2) g_stat.SetFillStyle(3001) g_stat.SetFillColor(kGray + 2) g_stat.SetLineWidth(2) g_stat.SetLineColor(kGray + 2) pt = TPaveText(0.09, 0.855, 0.32, 0.98, "ndc") pt.AddText("MicroBooNE") pt.SetFillColor(0) pt.SetBorderSize(0) pt.SetShadowColor(0) leg = TLegend(0.55, 0.09, 0.86, 0.4) leg.AddEntry(g_sys, "Data - stat. #oplus sys.", "ep") leg.AddEntry(g_stat, "Data - stat. only", "f") leg.AddEntry(h_mc, "Monte Carlo", "f") canvas = draw_ratio("c_%s" % name, [h_mc, g_stat, g_sys, pt, leg], [h_ratio], ["hist", "2", "p", "", ""], ["ep"]) canvas.SaveAs("plots/%s.pdf" % name) canvas.SaveAs("plots/%s.C" % name)
def getPavetext(): addInfo = TPaveText(0.3010112, 0.2066292, 0.4202143, 0.3523546, "NDC") addInfo.SetFillColor(0) addInfo.SetLineColor(0) addInfo.SetFillStyle(0) addInfo.SetBorderSize(0) addInfo.SetTextFont(42) addInfo.SetTextSize(0.040) addInfo.SetTextAlign(12) return addInfo
def drawenergy(is2017, data=True): pt = TPaveText(0.0877181, 0.9, 0.9580537, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(52) cmstextSize = 0.07 preliminarytextfize = cmstextSize * 0.7 lumitextsize = cmstextSize * 0.7 pt.SetTextSize(cmstextSize) text = pt.AddText(0.01, 0.57, "#font[61]{CMS}") pt1 = TPaveText(0.0877181, 0.904, 0.9580537, 0.96, "brNDC") pt1.SetBorderSize(0) pt1.SetTextAlign(12) pt1.SetFillStyle(0) pt1.SetTextFont(52) pt1.SetTextSize(preliminarytextfize) #text1 = pt1.AddText(0.155,0.4,"Preliminary") text1 = pt1.AddText(0.125, 0.4, " Internal") pt2 = TPaveText(0.0877181, 0.9, 0.7280537, 0.96, "brNDC") pt2.SetBorderSize(0) pt2.SetTextAlign(12) pt2.SetFillStyle(0) pt2.SetTextFont(52) pt2.SetTextFont(42) pt2.SetTextSize(lumitextsize) # text3 = pt2.AddText(0.53,0.5,"#sqrt{s} = 13 TeV(2017)") pavetext = '' if is2017 and data: pavetext = "41.1 fb^{-1} (13 TeV)" if (not is2017) and data: pavetext = "(13 TeV)" if is2017 and not data: pavetext = "(13 TeV)" if (not is2017) and not data: pavetext = "(13 TeV)" if data: text3 = pt2.AddText(0.735, 0.5, pavetext) if not data: text3 = pt2.AddText(0.75, 0.5, pavetext) return [pt, pt1, pt2]
class HistogramSaver: def __init__(self, settings=None): print 'Starting Histogram Saver' self.settings = settings self.run = array(self.settings.runInfo['run'], 'I') self.eventNumber = array(int(0), 'I') self.plotPath = '.' self.plotRootPath = './root/' self.plotPdfPath = './pdf/' self.paveTextOptions = {} self.dateTime = TDatime() self.paveText = TPaveText(0.07, 0, 0.22, 0.10, 'NDC') self.UpdatePaveText() self.verb = self.settings.runInfo['verbose'] self.optStat1D = 'nemr' self.optStat2D = 'ne' self.DefaultPlotStyle() def DefaultPlotStyle(self): gStyle.SetPalette(55) # 55 is kRainBow. 53 is kDarkBodyRadiator gStyle.SetOptStat(self.optStat1D) gStyle.SetOptFit(11111) gStyle.SetStatH(0.12) gStyle.SetStatW(0.15) gStyle.SetPadBottomMargin(0.15) gStyle.SetPadTopMargin(0.15) def SetPath(self, path='.'): self.plotPath = self.RemoveExtraBackSlashes(path, 2) self.plotRootPath = self.RemoveExtraBackSlashes(path + '/root/', 3) self.plotPdfPath = self.RemoveExtraBackSlashes(path + '/pdf/', 3) self.settings.CheckDirExistence(self.plotPath, True) self.settings.CheckDirExistence(self.plotRootPath, True) self.settings.CheckDirExistence(self.plotPdfPath, True) def RemoveExtraBackSlashes(self, string, times=1): if times == 0: return string string = string.replace('//', '/') return self.RemoveExtraBackSlashes(string, times - 1) def UpdatePaveText(self): self.paveText.Clear() self.paveText.SetTextSize(0.025) self.paveTextOptions['svn'] = 'Rev: ' + self.settings.version self.paveTextOptions['run'] = 'Run ' + str(self.run) self.paveTextOptions['nEvents'] = 'with ' + str( self.settings.runInfo['nEvents']) + 'Events' self.paveTextOptions['DateTime'] = self.dateTime.AsSQLString() self.paveText.AddText(self.paveTextOptions['svn']) self.paveText.AddText(self.paveTextOptions['run']) self.paveText.AddText(self.paveTextOptions['nEvents']) self.paveText.AddText(self.paveTextOptions['DateTime']) self.paveText.SetBorderSize(0) self.paveText.SetFillColor(0)
def plotGenEtaPhi(): c = TCanvas("canvasGenEtaPhi", "canvas Gen Eta Phi", 1200, 1200) graph = file.Get('hoMuonAnalyzer/graphs/gen') graph.SetMarkerColor(PlotStyle.colorRwthDarkBlue) graph.SetMarkerStyle(2) graph.GetXaxis().SetTitleFont(62) graph.GetYaxis().SetTitleFont(62) graph.GetYaxis().SetLabelFont(62) graph.GetYaxis().SetTitle('#phi') graph.GetXaxis().SetTitle('#eta') graph.SetTitle('#eta #phi distribution for GEN') graph.Draw('AP') #CMS label label = PlotStyle.getLabelCmsPrivateSimulation() label.Draw() pText = TPaveText(0.7, 0.85, 0.9, 0.9, 'NDC') pText.SetBorderSize(1) pText.AddText('Total Events: %d' % (totalEvents)) pText.Draw() c.SaveAs('plots/genControlPlots/genEtaPhi.pdf') c.SaveAs('plots/genControlPlots/genEtaPhi.png') #Prepare histograms for eta and phi alone histPhi = TH1D('histGenPhi', "#phi GEN;#phi;#", 80, -3.48, 3.48) histEta = TH1D('histGenEta', "#eta GEN;#eta;#", 40, -1.74, 1.74) #Get the data from the graph x = Double(0) y = Double(0) for i in range(0, graph.GetN()): graph.GetPoint(i, x, y) histPhi.Fill(y) histEta.Fill(x) #Draw phi histogram cPhi = TCanvas("canvasGenPhi", "canvas Gen Phi", 1200, 1200) histPhi.SetStats(0) histPhi.Draw() label.Draw() cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') cPhi.SaveAs('plots/genControlPlots/genPhi.pdf') #Draw eta histogram cEta = TCanvas("canvasGenEta", "canvas Gen Eta", 1200, 1200) histEta.SetStats(0) histEta.Draw() label.Draw() cEta.SaveAs('plots/genControlPlots/genEta.pdf') cEta.SaveAs('plots/genControlPlots/genEta.pdf') return c, graph, label, histEta, histPhi, cEta, cPhi, pText
def __MakeLabel(self, xmin, xmax, ymin, ymax, trigger): """ Add label with trigger, cuts and pileup """ lab = TPaveText(xmin, xmax, ymin, ymax, "NDC") lab.SetBorderSize(0) lab.SetFillStyle(0) lab.SetTextFont(42) lab.SetTextAlign(12) lab.AddText("Trigger: %s" %(trigger)) return lab
def prelimLabel(): label = TPaveText( 0.2, 0.9, 0.27, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(31) label.AddText( "#font[62]{CMS} #font[52]{Preliminary}" ) label.SetTextSize(0.03) label.SetTextColor( 1 ) return label
def add_pave(self, x1, y1, x2, y2, border=False): """Creates a pave and adds it to the plot.""" pave = TPaveText(x1, y1, x2, y2, 'NDC') n = len(self._container_draw) pave.SetTextFont(42) pave.SetTextSize(0.025) if border: pave.SetBorderSize(1) pave.SetFillColor(0) self.add(pave) return (lambda n: lambda s: self._container_draw[n].AddText(s))(n)
def draw_text(lines, coordinates = [0.1,0.8,0.5,0.9], colour = 36, border = 1): text = TPaveText(coordinates[0], coordinates[1], coordinates[2], coordinates[3],"brNDC") text.SetFillColorAlpha(0,1) text.SetBorderSize(border) for line in lines: text.AddText("#color["+str(colour)+"]{"+line+"}") print(line) text.Draw() ROOT.SetOwnership(text,False)
def simLabel(): label = TPaveText( 0.12, 0.9, 0.18, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(11) label.AddText( "#font[62]{CMS} #font[52]{Simulation}" ) label.SetTextSize(0.035) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def condLabel(): label = TPaveText( 0.67, 0.9, 0.81, 0.93, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( "%s cond. (13 TeV)" % era ) label.SetTextSize( 0.034 ) label.SetTextAlign(11) label.SetTextFont( 42 ) label.SetTextColor( 1 ) return label
def selectionLabel(text): label = TPaveText( 0.15, 0.9, 0.23, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( text ) label.SetTextSize( 0.048 ) label.SetTextAlign(11) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def condLabel(): label = TPaveText(0.63, 0.9, 0.8, 0.92, 'NB NDC') label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText("2017 PU cond. (13 TeV)") label.SetTextSize(0.034) label.SetTextAlign(11) label.SetTextFont(42) label.SetTextColor(1) return label