Example #1
0
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")
Example #2
0
def makePage( algorithm , pagename , cdash = False, prefix=""):
    from ROOT import TCanvas,kBlue,kRed,gROOT,kGreen,kYellow
    gROOT.SetBatch(True)
    c=TCanvas( algorithm.output.name , algorithm.output.name )
    c.Divide(1,2)
    from Interface import Result
    aColor = None
    if algorithm.output.result == Result.FAILED:
        aColor = kRed
    if algorithm.output.result == Result.NOTPASSED:
        aColor = kYellow
    if algorithm.output.result == Result.SUCCESS:
        aColor = kGreen
    if aColor:
        c.SetFillColor( aColor )
    aPad = c.cd(1)
    from Utils import draw
    lims = ()
    if "TH1" not in algorithm.test.dataset1.__class__.__name__:
        lims = ( 100, 
                min( algorithm.test.dataset1.tolist() + algorithm.test.dataset2.tolist() ),
                max( algorithm.test.dataset1.tolist() + algorithm.test.dataset2.tolist() )
               )
    h1=draw( algorithm.test.dataset1 , kBlue , ""    , lims , algorithm.output.name )
    h1.SetName(h1.GetName()+"_new")
    aPad.Update()
    from ROOT import TPaveStats
    statBox = h1.GetListOfFunctions().FindObject("stats")
    statBox.SetName('new_stat')
    statBox.SetY1NDC(statBox.GetY1NDC()-.18)
    statBox.SetY2NDC(statBox.GetY2NDC()-.18)
    statBox.SetTextColor(kBlue)
    statBox.SetBorderSize(2)
    h2=draw( algorithm.test.dataset2 , kRed  , "sames", lims , algorithm.output.name+"ref")
    h2.SetName(h2.GetName()+"_ref")
    aPad.Update()
    statBox2 = h2.GetListOfFunctions().FindObject("stats")
    statBox2.SetName('ref_stat')
    statBox2.SetTextColor(kRed)
    from ROOT import TPaveText
    pave=TPaveText(0.02,0.85,0.35,0.99,"NDC")
    pave.SetTextColor(aColor)
    pave.SetFillColor(1)
    pave.AddText(" %s "%algorithm.output.result)
    pave.AddText("(p-val: %s Test: %s)"%(algorithm.output.value,
                                         algorithm.test.__class__.__name__))
    pave.Draw()
    c.cd(2)
    if 'residuals' in algorithm.test.__dict__:
        algorithm.test.residuals.Draw()
    else:
        from Utils import makeResiduals
        algorithm.test.residuals = makeResiduals( h1 , h2 )
        algorithm.test.residuals.Draw()
    c.Print(pagename+prefix)
    # only print CDASH info if the test has failed (saves space on webserver)
    if cdash == True and not (algorithm.output.result == Result.SUCCESS):
        import os
        c.Print(os.path.dirname(pagename)+"/"+algorithm.output.name.replace('/','_')+".png")
        print " <DartMeasurementFile name=\"" + algorithm.output.name +  "\" type=\"image/png\"> " + os.path.dirname(pagename) + "/" + algorithm.output.name.replace('/','_') + ".png" + " </DartMeasurementFile>"
Example #3
0
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
Example #4
0
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 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
Example #6
0
def radialResidualPlots(crossings, shapes, chiSq, dof):
    kBird()
    gStyle.SetOptStat(0)
    components = ('X1', 'Y1', 'X2', 'Y2')
    for shape in shapes:
        for bx in crossings:
            f = TFile.Open('DataAnalysisBunch' + bx + shape +
                           '_new_StronRescale.root')
            if not f:
                continue
            for comp in components:
                dataHist = f.Get('dataHist' + comp)
                modelHist = f.Get('modelHist' + comp)
                nbinsx = dataHist.GetXaxis().GetNbins()
                nbinsy = dataHist.GetYaxis().GetNbins()
                radialDat = TH1D('radialDat_'+shape+bx+comp, '', nbinsx/2, 0.0, \
                                 dataHist.GetXaxis().GetXmax())
                radialMod = TH1D('radialMod_'+shape+bx+comp, '', nbinsx/2, 0.0, \
                                 dataHist.GetXaxis().GetXmax())
                hist = TH1D('radialRes_'+shape+bx+comp, '', nbinsx/2, 0.0, \
                            dataHist.GetXaxis().GetXmax())
                radialDat.Sumw2()
                for xbin in range(nbinsx + 1):
                    for ybin in range(nbinsy + 1):
                        r = (dataHist.GetXaxis().GetBinCenter(xbin)**2 + \
                            dataHist.GetYaxis().GetBinCenter(ybin)**2) ** 0.5
                        radialDat.Fill(r, dataHist.GetBinContent(xbin, ybin))
                        radialMod.Fill(r, modelHist.GetBinContent(xbin, ybin))
                for rbin in range(nbinsx / 2 + 1):
                    err = radialDat.GetBinError(rbin)
                    if err > 0.0:
                        pull = (radialDat.GetBinContent(rbin) - \
                                radialMod.GetBinContent(rbin)) / err
                    else:
                        pull = 0.0
                    hist.SetBinContent(rbin, pull)
                canvas = TCanvas('c_' + hist.GetName(), '', 600, 600)
                hist.Draw('HF')
                canvas.Update()
                hist.SetFillColor(4)
                hist.SetLineColor(1)
                hist.GetXaxis().SetTitle('r [cm]')
                hist.GetXaxis().SetLabelSize(0.025)
                hist.GetYaxis().SetTitle('Pulls')
                hist.GetYaxis().SetLabelSize(0.025)
                hist.GetYaxis().SetTitleOffset(1.1)
                hist.GetYaxis().SetRangeUser(-1.5, 5.0)
                pave = TPaveText(0.15, 0.79, 0.42, 0.88, 'NDC')
                pave.SetTextFont(42)
                pave.SetTextSize(0.025)
                pave.AddText('Scan ' + comp + ', BX ' + bx)
                pave.AddText(shapeNames[shape] + ' fit')
                redChiSq = chiSq[shape][bx] / dof[shape][bx]
                pave.AddText('#chi^{2}/d.o.f. = %6.4f' % (redChiSq))
                pave.Draw('same')
                drawCMS()
                canvas.Modified()
                canvas.Update()
                canvas.SaveAs('summaryPlots/' + canvas.GetName() + '.pdf')
                canvas.SaveAs('summaryPlots/' + canvas.GetName() + '.C')
Example #7
0
def get_ccdb_obj(ccdb_path, timestamp, out_path, host, show, verbose):
    """
    Gets the ccdb object from 'ccdb_path' and 'timestamp' and downloads it into 'out_path'
    """
    if verbose:
        print("Getting obj", ccdb_path, "with timestamp", timestamp,
              convert_timestamp(timestamp))
    cmd = f"o2-ccdb-downloadccdbfile --host {host} --path {ccdb_path} --dest {out_path} --timestamp {timestamp}"
    subprocess.run(cmd.split())
    if verbose:
        f = TFile(os.path.join(out_path, ccdb_path, "snapshot.root"), "READ")
        meta = f.Get("ccdb_meta")
        if False:
            print("Metadata")
            for i in meta:
                print(i)

        def print_info(entry):
            print("Object", entry, meta[entry])

        print_info("Last-Modified")
        if show:
            obj = f.Get("ccdb_object")
            obj.Draw()
            time_box = TPaveText(.01, .9, 0.3, 0.99, "NDC")
            time_box.AddText(ccdb_path)
            time_box.AddText(f"timestamp {timestamp}")
            time_box.AddText(f"{convert_timestamp(timestamp)}")
            time_box.Draw()
            gPad.Update()
            input("Press enter to continue")
Example #8
0
def exampleDataPlot(bx, shape, comp):
    kBird()
    f = TFile.Open('DataAnalysisBunch' + bx + shape + '_new_StronRescale.root')
    if f:
        hist = f.Get('dataHist' + comp)
        hist.SetTitle('')
        hist.SetName(bx + shape + '_dataHist' + comp)
        canvas = TCanvas('c_' + hist.GetName(), '', 600, 600)
        canvas.SetFrameFillColor(0)
        hist.Draw("COLZ")
        canvas.Update()
        hist.GetXaxis().SetTitle('x [cm]')
        hist.GetXaxis().SetLabelSize(0.025)
        hist.GetYaxis().SetTitle('y [cm]')
        hist.GetYaxis().SetLabelSize(0.025)
        hist.GetYaxis().SetTitleOffset(1.3)
        hist.GetZaxis().SetTitle('Number of Vertices')
        hist.GetZaxis().SetLabelSize(0.025)
        hist.GetZaxis().SetTitleOffset(0.7)
        hist.GetZaxis().SetRangeUser(0.0, 240.0)
        hist.GetZaxis().CenterTitle()
        hist.GetZaxis().SetNdivisions(1, False)
        palette = hist.GetListOfFunctions().FindObject('palette')
        palette.SetX2NDC(0.929)
        pave = TPaveText(0.65, 0.82, 0.88, 0.88, 'NDC')
        pave.SetTextFont(42)
        pave.SetTextSize(0.025)
        pave.AddText('Scan ' + comp + ', BX ' + bx)
        pave.AddText('Measured data')
        pave.Draw('same')
        drawCMS()
        canvas.Modified()
        canvas.Update()
        canvas.SaveAs('summaryPlots/' + canvas.GetName() + '.pdf')
        canvas.SaveAs('summaryPlots/' + canvas.GetName() + '.C')
Example #9
0
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")
Example #10
0
	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
Example #11
0
def makeStats(mean,rms):
    label = TPaveText( 0.25, 0.7, 0.3, 0.8, 'NB NDC' )
    label.SetTextSize( 0.035 )
    label.SetTextFont( 42 )
    label.SetFillStyle( 0 )
    label.SetLineWidth( 0 )
    label.AddText( 'Mean = ' + str(mean) )
    label.AddText( 'RMS = ' + str(rms) )
    return label
Example #12
0
def addText():
    label = TPaveText( 0.7, 0.7, 0.75, 0.8, 'NB NDC' )
    label.SetTextSize( 0.04 )
    label.SetTextFont( 42 )
    label.SetFillStyle( 0 )
    label.SetLineWidth( 0 )
    label.AddText( "Elastic #gamma#gamma#rightarrow#gamma#gamma" )
    label.AddText( "FPMC, BSM pred." )
    return label
Example #13
0
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)
Example #14
0
	def plotHoTimeLog(self):
		c3 = TCanvas("c3Log","HO Time Log",1200,1200)
		skipNoisePlot = True
		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()
	
		fit = TF1("fit","gaus",-10,10)
		fit.SetParameter(1,0)
		fit.SetParameter(2,1)
		hHoTimeAboveThr.Fit(fit,'','R',-12.5,12.5)
		
		self.debug(80*'#')
		self.debug('Chi^2: %5.2f' % fit.GetChisquare())
		self.debug('NDF: %d' % fit.GetNDF())
		self.debug(80*'#')
		
		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,"hoTimeLog")
		
		return c3,pText,hHoTimeAboveThr
Example #15
0
def prelimLabel():
    label = TPaveText( 0.14, 0.8, 0.2, 0.87, 'NB NDC' )
    label.SetFillStyle(0)
    label.SetBorderSize(0)
    label.SetLineWidth(0)
    label.SetLineStyle(0)
    label.SetTextAlign(11)
    label.AddText( "#font[62]{CMS}" )
    #label.AddText( "#scale[0.75]{#font[52]{Preliminary}}" )
    label.AddText( "#scale[0.75]{#font[52]{Inteneral}}" )
    label.SetTextSize(0.043)
    label.SetTextFont( 52 )
    label.SetTextColor( 1 )
    return label
Example #16
0
def descriptionLabel():
    label = TPaveText( 0.73, 0.65, 0.81, 0.8, 'NB NDC' )
    label.SetFillStyle(0)
    label.SetBorderSize(0)
    label.SetLineWidth(0)
    label.SetLineStyle(0)
    label.AddText( "Elastic #gamma#gamma#rightarrow#gamma#gamma" )
    label.AddText( "FPMC BSM pred." )
    label.AddText( "#sigma_{bd} = 30 #murads" )
    label.SetTextSize( 0.032 )
    label.SetTextAlign(11)
    label.SetTextFont( 42 )
    label.SetTextColor( 1 )
    return label
Example #17
0
def plotR2(seq_pol_sell):
    """On a TCanvas, plot R2 for a list of particular SEQ and POL selections
	
	Keyword arguments:
	seq_pol_sell -- A List of DataFrame selections based on SEQ and POL

	"""
    l = TLine(0, 0, 180, 0)  # will be used for all hR2 objects

    for seq_pol_sel in seq_pol_sell:
        d_q2w_seq_pol = d_q2w[seq_pol_sel]
        #print dq2w_seq_pol
        seq = d_q2w_seq_pol.iloc[0]['SEQ']
        pol = d_q2w_seq_pol.iloc[0]['POL']
        outdir_seq_pol = os.path.join(outdir_q2w, SEQ_NAME[seq],
                                      POLS_NAME[pol])
        if not os.path.isdir(outdir_seq_pol):
            os.makedirs(outdir_seq_pol)

        for pob in range(0, NPOBS):
            if pob == A: continue
            for var in range(0, NVARS):
                if var == PHI or var == ALPHA: continue
                hR2_name = 'hR2_%s_1%s' % (POBS_NAME[pob], VARS_NAME[var])
                hR2 = d_q2w_seq_pol.iloc[0][hR2_name]
                cR2 = TCanvas(hR2_name, hR2_name)
                hR2.SetLineColor(gROOT.ProcessLine("%s" % POLS_COLOR[pol]))
                hR2.SetTitle("")  # will be made "prettier" later
                hR2.Draw("ep")

                #make Title of hR2 "pretty"
                l.Draw("same")
                pt = TPaveText(0.3, 0.85, 0.7, 1.0, "NDC")
                q2wt = pt.AddText('[Q^{2}][W] = %s' % q2wbin)
                q2wt.SetTextColor(gROOT.ProcessLine("kBlue"))
                vart = pt.AddText(
                    ("%s,%s: %s^{%s} vs. %s") %
                    (SEQ_NAME[seq], POLS_NAME[pol], POBS_NAME[pob],
                     VARS_TITLE[0][var], VARS_TITLE[0][var]))
                vart.SetTextSize(0.05)
                pt.Draw()

                csavename = ('%s/%s') % (outdir_seq_pol, cR2.GetName())
                cR2.SaveAs(('%s.png') % (csavename))
                print('>>>convert %s.png %s.pdf') % (csavename, csavename)
                rc = subprocess.call(
                    ['convert',
                     '%s.png' % csavename,
                     '%s.pdf' % csavename])
                if rc != 0: print '.png to .pdf failed for %s' % csavename
Example #18
0
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]
Example #19
0
 def add_desc_to_canvas(self):
     txt1 = TPaveText(0.15, 0.8, 0.4, 0.92, "NDC")
     txt1.SetFillColor(kWhite)
     txt1.SetFillStyle(0)
     txt1.SetBorderSize(0)
     txt1.SetTextAlign(12) # middle,left
     txt1.SetTextFont(42) # helvetica
     txt1.SetTextSize(0.04)
     txt1.AddText("#varphi slice = %d, r slice = %d, z slice = %d" % \
                  (self.grid_phi, self.grid_r, self.grid_z))
     if self.opt_train[0] == 1 and self.opt_train[1] == 1:
         txt1.AddText("inputs: #rho_{SC} - <#rho_{SC}>, <#rho_{SC}>")
     elif self.opt_train[1] == 1:
         txt1.AddText("inputs: #rho_{SC} - <#rho_{SC}>")
     txt1.Draw()
Example #20
0
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()
Example #21
0
def add_cut_desc(cuts, x_var):
    txt = TPaveText(0.5, 0.75, 0.9, 0.89, "NDC")
    txt.SetFillColor(kWhite)
    txt.SetBorderSize(0)
    txt.SetTextAlign(12)  # left, middle
    txt.SetTextSize(0.03)
    txt.AddText(cuts["deltaSC"]["desc"](cuts["deltaSC"]["%s_lim" % x_var]))
    txt.AddText("%s, 20 epochs" %
                cuts["z"]["desc"](cuts["z"]["%s_lim" % x_var]))
    #for cut_var in cuts:
    #if cut_var == "sector":
    #    txt.AddText("%s %d" % (cut_var, int(round(cut[cut_var][0]))))
    #if cut_var not in ("fsector", "phi", "r"):
    #    txt.AddText(cuts[cut_var]["desc"](cuts[cut_var]["%s_lim" % x_var]))
    #txt.AddText("20 epochs")
    return txt
Example #22
0
def simLabel():
    #label = TPaveText( 0.11, 0.9, 0.2, 0.92, 'NB NDC' )
    label = TPaveText(0.8, 0.79, 0.87, 0.86, 'NB NDC')
    label.SetFillStyle(0)
    label.SetBorderSize(0)
    label.SetLineWidth(0)
    label.SetLineStyle(0)
    #label.SetTextAlign(11)
    label.SetTextAlign(31)
    #label.AddText( "#font[62]{CMS} #font[52]{Simulation}" )
    label.AddText("#font[62]{CMS}")
    label.AddText("#scale[0.75]{#font[52]{Simulation}}")
    label.SetTextSize(0.045)
    #label.SetTextFont( 52 )
    label.SetTextColor(1)
    return label
Example #23
0
	def plot1DEMaxAroundL1(self):	
		'''
			eta[P,M][2,1,0]phi[P,M][2,1,0]_averageEnergyAroundPoint
			Central tile is central
		'''
		histList = []
		fitList = []
		labelList = []
		canvas = TCanvas('canvas1DEMax','1D EMax',1200,1200)
		for p in reversed(range(-2,3)):
			for e in range(-2,3):
				if e == 0 and p == 0:
					histList.append(self.fileHandler.getHistogram('etaPhi/energy1D/central_averageEMaxAroundPoint' + self.key))
				else:
					histName = ('etaPhi/energy1D/eta%s%dPhi%s%d_averageEMaxAroundPoint' + self.key) % ('P' if e >= 0 else 'M',abs(e),'P' if p >= 0 else 'M',abs(p))
					histList.append(self.fileHandler.getHistogram(histName))
		canvas.Divide(5,5)
		for i,hist in enumerate(histList):
			canvas.cd(i+1).SetLogy()
			hist.GetXaxis().SetRangeUser(-0.5,4)
			hist.SetLineWidth(3)
			setupAxes(hist)
			hist.Draw()
			fit = TF1('fit%d' % (i),'landau',0.5,2)
			hist.Fit(fit,'RQ')
			label = TPaveText(0.6,0.7,0.9,0.9,"NDC")
			label.AddText('MPV: %5.2f' % (fit.GetParameter(1)))
			label.Draw()
			labelList.append(label)
			fitList.append(fit)
		canvas.Update()
		self.storeCanvas(canvas, '1DEMaxPlots')
		return histList,canvas,fitList,labelList
Example #24
0
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()
Example #25
0
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()
Example #26
0
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 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 drawcounts(h):
    txt = TPaveText(0.75, 0.55, 0.88, 0.7, "NDC")
    for i in h:
        txt.AddText("{}={}".format(i.GetTitle(), i.GetEntries()))
    txt.Draw()
    latexdrawn.append(txt)
    gPad.Update()
Example #29
0
def plot(data_path, pt_title, ecms, xmin, xmax, xbins):
    try:
        f_data = TFile(data_path)
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error('File paths are invalid!')
        sys.exit()

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    set_canvas_style(mbc)
    content = (xmax - xmin) / xbins * 1000
    ytitle = 'Events/%.1f MeV' % content
    xtitle = 'M(K^{-}#pi^{+}#pi^{+})(GeV)'
    h_data = TH1F('data', 'data', xbins, xmin, float(xmax))

    set_histo_style(h_data, xtitle, ytitle)
    rawm_D_fill(t_data, h_data)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')

    h_data.Draw('E1')

    pt = TPaveText(0.6, 0.7, 0.75, 0.75, "BRNDC")
    set_pavetext(pt)
    pt.Draw()
    pt.AddText(pt_title)

    mbc.SaveAs('./figs/m_Kpipi_' + str(ecms) + '.pdf')

    raw_input('Enter anything to end...')
Example #30
0
def FIT_XS():
    is_fit = True
    gaexs_list_fit, geeff_list_fit, gexs_list_fit, func_list = fit_xs(label_list, iter_old, old_xs_list, tfunc_list, par_list, par_range_list, xmin_list, xmax_list, is_fit)
    for f, label, gaexs, geeff, gexs, xtitle, xs_ytitle, eff_ytitle in zip(func_list, label_list, gaexs_list_fit, geeff_list_fit, gexs_list_fit, xtitle_list, xs_ytitle_list, eff_ytitle_list):
        xs_mbc = TCanvas('xs_mbc_' + label + '_' + iter_old + '_fit', '', 700, 600)
        set_canvas_style(xs_mbc)
        xs_mbc.cd()
        if not label == 'DDPIPI':
            set_graph_style(gaexs, xtitle, xs_ytitle)
            gaexs.Draw('ap')
        else:
            set_graph_style(gaexs, xtitle, xs_ytitle)
            set_graph_style(gexs, xtitle, xs_ytitle)
            mg = TMultiGraph()
            mg.Add(gaexs)
            mg.Add(gexs)
            mg.Draw('ap')
        chi2 =  f.GetChisquare()
        if label == 'DDPIPI': ndf = f.GetNDF() + 1
        else: ndf = f.GetNDF()
        pt = TPaveText(0.15, 0.8, 0.55, 0.9, "BRNDC")
        set_pavetext(pt)
        pt.Draw()
        line = '#chi^{2}/ndf = ' + str(round(chi2, 3)) + '/' + str(round(ndf, 3)) + ' = ' + str(round(chi2/ndf, 3))
        with open('./txts/likelihood_' + label + '.txt', 'w') as f:
            f.write(str(chi2) + '\n' + str(ndf))
        pt.AddText(line)
        xs_mbc.SaveAs('./figs/xs_' + label + '_' + iter_old + '_fit.pdf')
    raw_input('Press <Enter> to end...')
    return func_list