def drawInfo(c,h,more,x=0.6,size=0.04):
    what = c.GetName()
    info  = 'Entries  %5i' % h.GetEntries()
    info += ';RMS %s   %6.3g mm' % (what[0],h.GetRMS(2))
    info += ';RMS %s   %6.3g mm' % (what[1],h.GetRMS(1))
    ROOTUtils.drawText(x,0.88,size,info,font=102)
    if more:
        ROOTUtils.drawText(x,0.73,size,more,font=102)
def drawLabels():
    if options.prelim:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=None)
    if options.approval:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=None)
    if options.published:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=None)

    ROOTUtils.drawText(options.atlasx,0.77,0.06,runFillInfo,font=42)
    comment = options.comment if options.comment is not None else '#geq %i tracks/vertex' % (options.ntracks)
    ROOTUtils.drawText(options.atlasx,0.71,0.06,lhcEnergyInfo+comment,font=42)
 def yx(self):
     ROOT.gStyle.SetOptStat(0)
     c = ROOTUtils.protect(ROOTUtils.MyCanvas('yx',options.canvas))
     c.SetRightMargin(0.14)
     h = ROOTUtils.protect(ROOT.TH2F('pvYX','Primary vertex: y vs x;Primary vertex x [mm];Primary vertex y [mm]',nbins,xmin,xmax,nbins,ymin,ymax))
     nt.Draw('y:x >> pvYX',cuts)
     h.Draw('COLZ')
     h.GetYaxis().SetTitleOffset(1.0)
     drawLabels()
     drawInfo(c,h,options.more)
     ROOT.gPad.Update()
     c.save()
 def xz(self):
     #ROOT.gStyle.SetOptStat(1010)       
     ROOT.gStyle.SetOptStat(0)
     c = ROOTUtils.protect(ROOTUtils.MyCanvas('xz',options.canvas))
     c.SetRightMargin(0.14)
     h = ROOTUtils.protect(ROOT.TH2F('pvXZ','Primary vertex: x vs z;Primary vertex z [mm];Primary vertex x [mm]',nbins,xmin,xmax,nbins,ymin,ymax))
     nt.Draw('x:z >> pvXZ',cuts)
     h.Draw('COLZ')
     h.GetYaxis().SetTitleOffset(1.0)
     drawLabels()
     #ROOTUtils.moveStats(h,-0.16,-0.08)
     drawInfo(c,h,options.more)
     ROOT.gPad.Update()
     c.save()
 def histErrComp(self):
     hname = getPlotDef(options.plot,'hname','h')
     var = getPlotDef(options.plot,'var')
     vName = var[1:] # Ugly - should take from plotDef
     ROOT.gStyle.SetOptStat(0)
     ROOT.gStyle.SetOptFit(0)
     c = ROOTUtils.protect(ROOTUtils.MyCanvas(var,options.canvas))
     c.SetRightMargin(0.14)
     h = ROOTUtils.protect(ROOT.TH1F(hname,'Vertex Error: %s;Vertex error #sqrt{V_{%s}} [#mum];Fraction of entries' % (hname,vName),
                                     nbins,xmin,xmax))
     nt.Draw('1e3*sqrt(%s) >> %s' % (var,hname),cuts)
     norm = h.Integral()
     h.Scale(1./norm)
     pname = hname+'_pileup'
     p = ROOTUtils.protect(ROOT.TH1F(pname,'Vertex Error: %s;Vertex error #sqrt{V_{%s}} [#mum];Fraction of entries' % (hname,vName),
                                     nbins,xmin,xmax))
     pcuts = cuts.replace('vType==1','vType==3')
     print pcuts
     nt.Draw('1e3*sqrt(%s) >> %s' % (var,pname),pcuts,"SAME")
     pnorm = p.Integral()
     p.Scale(1./pnorm)
     p.SetLineColor(4)
     p.SetLineStyle(2)
     ROOTUtils.drawText(0.51,0.86,0.06,'Vertex error #sqrt{V_{%s}}' % vName)
     comment = options.comment if options.comment is not None else '#geq %i tracks/vertex;%s' % (options.ntracks,options.cuts)
     ROOTUtils.drawText(0.51,0.8,0.06,lhcEnergyInfo+comment,font=42)
     legend = ROOT.TLegend(.50,.6,.85,.72)
     legend.AddEntry(h,'Primary vertices','L')
     legend.AddEntry(p,'Pileup vertices','L')
     legend.SetFillColor(0)
     legend.SetBorderSize(0)
     legend.Draw()
     ROOT.gPad.SetLogy(options.logy)
     ROOT.gPad.Update()
     c.save()
Esempio n. 6
0
def LHCBeamSpotSize(lhcTimeString,     # E.g. ['Apr 4 14:27:30 2010'] (list)
                    lhcBeta1,          # beta* in m (scalar), beam 1
                    lhcEmit1,          # Norm. emittance in um rad (list), beam 1
                    lhcBeta2,          # dito beam 2
                    lhcEmit2,          # dito beam 2
                    betaGamma = 3730.  # Default value of betaGamma for 7 TeV
                    ):
    lhcTime = array([ mktime(strptime(s,'%b %d %H:%M:%S %Y')) for s in lhcTimeString])
    print lhcTime

    # Normalized emittance quoted in um rad; lhcEps arrays are emittance in m rad
    lhcEps1 = lhcEmit1 * 1.0e-6 / betaGamma
    lhcEps2 = lhcEmit2 * 1.0e-6 / betaGamma

    # Beam sizes in mm
    lhcSigmaBeam1 = sqrt(lhcBeta1*lhcEps1) * 1.0e3
    print 'Size of beam 1 (mm): ',lhcSigmaBeam1
    lhcSigmaBeam2 = sqrt(lhcBeta2*lhcEps2) * 1.0e3
    print 'Size of beam 2 (mm): ',lhcSigmaBeam2

    # Beam spot size in mm
    lhcSigma = 1. / sqrt(1./lhcSigmaBeam1**2 + 1./lhcSigmaBeam2**2)
    print 'Beam spot size (mm): ',lhcSigma

    # Draw on existing plot
    gr = ROOTUtils.protect( ROOT.TGraph(len(lhcTime),lhcTime,lhcSigma) )
    gr.SetMarkerColor(2)
    gr.SetLineColor(2)
    #gr.SetMarkerSize(1.0)
    #gr.SetMarkerStyle(25)
    gr.SetMarkerSize(1.5)
    gr.SetMarkerStyle(20)
    gr.Draw('PSAME')
    return [(gr,'Expected from  #sqrt{#epsilon #beta*}','P')]
Esempio n. 7
0
def LHCEmittance(
        lhcTimeString,  # E.g. ['Apr 4 14:27:30 2010'] (list)
        lhcEmit1,  # Norm. emittance in um rad (list), beam 1
        lhcEmit2,  # dito beam 2
        minEmittance=0.,
        maxEmittance=8.):
    lhcTime = array(
        [mktime(strptime(s, '%b %d %H:%M:%S %Y')) for s in lhcTimeString])
    ROOT.gPad.SetTicky(0)  # Remove tick marks on right side y axis
    ROOT.gPad.SetRightMargin(0.1)
    #maxEmittance = max(max(lhcEmit1),max(lhcEmit2))*1.7
    hmin = ROOT.gPad.GetUymin()
    hmax = ROOT.gPad.GetUymax()

    lhcEmit1Data = (lhcEmit1 - minEmittance) / (
        maxEmittance - minEmittance) * (hmax - hmin) + hmin
    gr1 = ROOTUtils.protect(ROOT.TGraph(len(lhcTime), lhcTime, lhcEmit1Data))
    gr1.SetMarkerColor(4)
    gr1.SetLineColor(4)
    gr1.SetMarkerStyle(25)
    gr1.Draw('PSAME')
    #gr1.Draw('PLSAME')

    lhcEmit2Data = (lhcEmit2 - minEmittance) / (
        maxEmittance - minEmittance) * (hmax - hmin) + hmin
    gr2 = ROOTUtils.protect(ROOT.TGraph(len(lhcTime), lhcTime, lhcEmit2Data))
    gr2.SetMarkerColor(4)
    gr2.SetLineColor(4)
    gr2.SetMarkerStyle(26)
    gr2.Draw('PSAME')
    #gr2.Draw('PLSAME')

    raxis = ROOTUtils.protect(
        ROOT.TGaxis(ROOT.gPad.GetUxmax(), hmin, ROOT.gPad.GetUxmax(), hmax,
                    minEmittance, maxEmittance, 510, '+L'))
    raxis.SetLineColor(4)
    raxis.SetTitle('Invariant Emittance (#mum rad)')
    raxis.SetTitleColor(4)
    raxis.SetTitleSize(0.05)
    raxis.SetTextFont(42)
    raxis.SetLabelFont(42)
    raxis.SetLabelSize(0.05)
    raxis.SetLabelColor(4)
    raxis.Draw()
    return [(gr1, 'Emittance beam 1', 'P'), (gr2, 'Emittance beam 2', 'P')]
 def histErr(self):
     hname = getPlotDef(options.plot,'hname','h')
     var = getPlotDef(options.plot,'var')
     vName = var[1:] # Ugly - should take from plotDef
     ROOT.gStyle.SetOptStat(options.optstat)
     ROOT.gStyle.SetOptFit(0)
     c = ROOTUtils.protect(ROOTUtils.MyCanvas(var,options.canvas))
     c.SetRightMargin(0.14)
     h = ROOTUtils.protect(ROOT.TH1F(hname,'Primary vertex error: %s;Primary vertex error #sqrt{V_{%s}} (#mum);Number of vertices' % (hname,vName),
                                     nbins,xmin,xmax))
     nt.Draw('1e3*sqrt(%s) >> %s' % (var,hname),cuts)
     ROOTUtils.drawText(0.45,0.86,0.06,'Primary Vertex Error #sqrt{V_{%s}}' % vName)
     comment = options.comment if options.comment is not None else '#geq %i tracks/vertex;%s' % (options.ntracks,options.cuts)
     ROOTUtils.drawText(0.45,0.8,0.06,lhcEnergyInfo+comment,font=42)
     ROOT.gPad.SetLogy(options.logy)
     ROOT.gPad.Update()
     c.save()
 def hist(self):
     hname = getPlotDef(options.plot,'hname','h')
     var = getPlotDef(options.plot,'var')
     units = getPlotDef(options.plot,'units','')
     ROOT.gStyle.SetOptStat(options.optstat)
     if options.fit:
         ROOT.gStyle.SetOptFit(1111)
     c = ROOTUtils.protect(ROOTUtils.MyCanvas(var,options.canvas))
     c.SetRightMargin(0.14)
     h = ROOTUtils.protect(ROOT.TH1F(hname,'Primary vertex: %s;Primary vertex %s %s' % (var,var,units),nbins,xmin,xmax))
     nt.Draw('%s >> %s' % (var,hname),cuts)
     if options.fit:
         h.Fit(options.fit)
     ROOTUtils.drawText(0.2,0.77,0.06,runFillInfo,font=42)
     comment = options.comment if options.comment is not None else '#geq %i tracks/vertex;%s' % (options.ntracks,options.cuts)
     ROOTUtils.drawText(0.2,0.71,0.06,lhcEnergyInfo+comment,font=42)
     ROOT.gPad.SetLogy(options.logy)
     ROOT.gPad.Update()
     c.save()
Esempio n. 10
0
    parser.error('wrong number of command line arguments')
filename = args[0]
run = getRunFromName(filename)
if run:
    basename = run+'-'
else:
    run = 'UNKNOWN'
    basename = ''


# Setup ROOT
if options.batch:
    os.unsetenv('DISPLAY')
import ROOT
from InDetBeamSpotExample import ROOTUtils
ROOTUtils.setStyle()
ROOT.gStyle.SetPalette(1)
c = ROOT.TCanvas('BeamSpotMonitoring','Beam Spot Monitoring',750,1000)
c.Divide(3,4)


# Open monitoring file
mon = ROOT.TFile(filename)
mondir = 'InDetGlobal/BeamSpot/'


# Summary frame
c.cd(1)
ROOTUtils.drawText(0.14,0.9,0.06,'Beam spot monitoring for run %s:' % run)
yline = 0.83
for f in args:
# Reset DISPLAY if in batch
import os
if options.batch:
    os.unsetenv('DISPLAY')


# Import ROOT (do this only now to avoid conlicts w/OptionParser)
import ROOT
from InDetBeamSpotExample import ROOTUtils
from InDetBeamSpotExample.Utils import getRunFromName
# TODO: Switch to using COOLQuery from COOLUtils for LHC info
from InDetBeamSpotExample.LHCInfoUtils import lhcFillData
from InDetBeamSpotExample.LHCInfoUtils import lhcEnergyData
from InDetBeamSpotExample.BeamSpotData import *
ROOTUtils.setStyle()
ROOT.gStyle.SetPalette(1)  # Better color scheme than default


def drawLabels():
    if options.prelim:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,True,offset=options.atlasdx,energy=None)
    if options.approval:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,isForApproval=True,energy=None)
    if options.published:
        ROOTUtils.atlasLabel(options.atlasx,options.atlasy,False,offset=options.atlasdx,energy=None)

    ROOTUtils.drawText(options.atlasx,0.77,0.06,runFillInfo,font=42)
    comment = options.comment if options.comment is not None else '#geq %i tracks/vertex' % (options.ntracks)
    ROOTUtils.drawText(options.atlasx,0.71,0.06,lhcEnergyInfo+comment,font=42)
Esempio n. 12
0
def main():
    f1 = "%s::%s" % (db1, options.folderBS)
    f2 = "%s::%s" % (db2, options.folderLumi)

    print("=" * 100)
    print("Comparing: ")
    print("  * ", f1, options.tagBS)
    print("  * ", f2, options.tagLumi)
    print("=" * 100)

    requiredForNtuple = ['posX', 'posY', 'posZ', 'sigmaX', 'sigmaY', 'sigmaZ']
    checkNtupleProd = all(item in varColl for item in requiredForNtuple)
    if not checkNtupleProd:
        print('Ntuple will not be filled missing vars')

    #Open up required databases
    from PyCool import cool
    from CoolConvUtilities import AtlCoolLib
    cooldbBS = AtlCoolLib.indirectOpen(db1, True, True, False)
    cooldbLumi = AtlCoolLib.indirectOpen(db2, True, True, False)

    folderBS = cooldbBS.getFolder(options.folderBS)
    folderLumi = cooldbLumi.getFolder(options.folderLumi)

    from InDetBeamSpotExample.COOLUtils import COOLQuery
    coolQuery = COOLQuery()

    if options.runMin is not None:
        iov1 = options.runMin << 32
        if options.runMax is not None:
            iov2 = (options.runMax + 1) << 32
        else:
            iov2 = (options.runMin + 1) << 32
        print('Plotting runs %i to %i ' % (iov1, iov2))
    else:
        print('No run selected -- ERROR')
        return

    if (iov2 > cool.ValidityKeyMax):
        iov2 = cool.ValidityKeyMax

    print("Reading data from database")
    itrBS = folderBS.browseObjects(iov1, iov2, cool.ChannelSelection.all(),
                                   options.tagBS)
    print("...finished getting BS data")

    lbDict = dict()

    startRLB = 0x7FFFFFFFFFFFFFFF
    endRLB = 0

    outfile = ROOT.TFile("BeamspotLumi_%i.root" % (options.runMin), "recreate")
    ntuple = ROOT.TNtupleD(
        'BeamspotLumi', 'BeamSpotLumi',
        "x:y:z:sigma_x:sigma_y:sigma_z:run:mu:lumi:year:month:day:hour:minute:epoch"
    )

    runs = set()
    while itrBS.goToNext():

        obj = itrBS.currentRef()

        since = obj.since()

        runBegin = since >> 32
        lumiBegin = since & 0xFFFFFFFF

        until = obj.until()
        runUntil = until >> 32
        lumiUntil = until & 0xFFFFFFFF

        status = int(obj.payloadValue('status'))
        if status != 59:
            continue

        runs.add(runBegin)

        if since < startRLB:
            startRLB = since
        if until > endRLB:
            endRLB = until

        values = {}
        for var in varColl:
            values[var] = float(obj.payloadValue(var))
            values[var + 'Err'] = float(obj.payloadValue(var + 'Err'))
        values['until'] = until
        lbDict[since] = values

    print('Runs: ', runs)

    lumi = array('d')
    xd = array('d')
    exd = array('d')
    ydDict = {}
    eydDict = {}
    ydDict2 = {}

    sqtrt2pi = math.sqrt(2 * math.pi)

    lblb = CoolDataReader('COOLONL_TRIGGER/CONDBR2', '/TRIGGER/LUMI/LBLB')
    from DQUtils.sugar import RANGEIOV_VAL, RunLumi
    from DQUtils import IOVSet

    grlIOVs = IOVSet.from_grl(
        "data15_13TeV.periodAllYear_DetStatus-v89-pro21-02_Unknown_PHYS_StandardGRL_All_Good_25ns.xml"
    )
    grlIOVs += IOVSet.from_grl(
        "data16_13TeV.periodAllYear_DetStatus-v89-pro21-01_DQDefects-00-02-04_PHYS_StandardGRL_All_Good_25ns.xml"
    )
    grlIOVs += IOVSet.from_grl(
        "data17_13TeV.periodAllYear_DetStatus-v99-pro22-01_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml"
    )
    grlIOVs += IOVSet.from_grl(
        "data18_13TeV.periodAllYear_DetStatus-v102-pro22-04_Unknown_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.xml"
    )

    for run in runs:
        iov1 = run << 32
        iov2 = (run + 1) << 32

        itrLumi = folderLumi.browseObjects(iov1, iov2,
                                           cool.ChannelSelection.all(),
                                           options.tagLumi)
        print("...finished getting Lumi data for run %i" % run)

        lblb.setIOVRangeFromRun(run)
        lblb.readData()
        if len(lblb.data) < 1:
            print('No LBLB data found!')
            continue
        # Make time map
        lblbMap = dict()
        for obj in lblb.data:
            lblbMap[obj.since()] = (obj.payload()['StartTime'],
                                    obj.payload()['EndTime'])

        while itrLumi.goToNext():
            obj = itrLumi.currentRef()

            since = obj.since()
            runBegin = since >> 32
            lumiBegin = since & 0xFFFFFFFF

            until = obj.until()
            runUntil = until >> 32
            lumiUntil = until & 0xFFFFFFFF

            inGRL = False
            for sinceGRL, untilGRL, grl_states in process_iovs(grlIOVs):
                if grl_states[0].since == None:
                    continue
                if (sinceGRL.run <= runBegin and untilGRL.run >= runUntil
                        and sinceGRL.lumi <= lumiBegin
                        and untilGRL.lumi >= lumiUntil):
                    inGRL = True
                    break

            if not inGRL:
                continue

            mu = float(obj.payloadValue('LBAvEvtsPerBX'))
            instlumi = float(obj.payloadValue('LBAvInstLumi'))

            #if( mu <  10 or mu > 65 ):
            #print 'Mu: %2.1f Run : %d  LB: %d - %d Lumi: %f' % (mu,runBegin,lumiBegin,lumiUntil,instlumi)

            if since in lbDict:
                if lbDict[since]['sigmaX'] > 0.1:
                    continue
                startTime = lblbMap.get(obj.since(), (0., 0.))[0]
                endTime = lblbMap.get(lbDict[since]['until'],
                                      (0., 0.))[0]  #[1] end of lumiblock
                mylumi = (endTime - startTime) / 1e9 * instlumi / 1e9
                thisTime = time.gmtime(startTime / 1.e9)
                year = thisTime[0]
                month = thisTime[1]
                day = thisTime[2]
                hour = thisTime[3]
                mins = thisTime[4]
                sec = thisTime[5]
                lumi.append(mylumi)
                # in fb^-1
                xd.append(mu)
                exd.append(0)

                if options.plotSomething:
                    for var in varColl:
                        if not var in ydDict:
                            ydDict[var] = array('d')
                            ydDict2[var] = array('d')
                            eydDict[var] = array('d')

                        ydDict2[var].append(mu /
                                            (lbDict[since][var] * sqtrt2pi))
                        ydDict[var].append(lbDict[since][var])
                        eydDict[var].append(lbDict[since][var + 'Err'])

                if checkNtupleProd and lbDict[since]['sigmaZErr'] < 5:
                    ntuple.Fill(lbDict[since]['posX'], lbDict[since]['posY'],
                                lbDict[since]['posZ'], lbDict[since]['sigmaX'],
                                lbDict[since]['sigmaY'],
                                lbDict[since]['sigmaZ'], runBegin, mu, mylumi,
                                year, month, day, hour, mins, startTime / 1.e9)

    runStart = startRLB >> 32
    runEnd = endRLB >> 32
    fillStart = fillEnd = 0
    timeStart = timeEnd = 0
    beamEnergy = 13
    try:
        timeStart = coolQuery.lbTime(int(startRLB >> 32),
                                     int(startRLB & 0xFFFFFFFF))[0]
    except:
        pass
    try:
        timeEnd = coolQuery.lbTime(int(endRLB >> 32),
                                   int(endRLB & 0xFFFFFFFF) - 1)[1]
    except:
        pass
    try:
        fillStart = coolQuery.getLHCInfo(timeStart).get('FillNumber', 0)
    except:
        pass
    try:
        fillEnd = coolQuery.getLHCInfo(timeEnd).get('FillNumber', 0)
    except:
        pass
    try:
        beamEnergy = coolQuery.getLHCInfo(timeStart).get('BeamEnergyGeV', 0)
        beamEnergy *= 2e-3
    except:
        pass

    ntuple.Write()

    if not options.plotSomething:
        return

    from InDetBeamSpotExample import ROOTUtils
    ROOTUtils.setStyle()
    canvas = ROOT.TCanvas('BeamSpotComparison', 'BeamSpotComparison', 1600,
                          1200)

    canvas.cd()
    ROOT.gPad.SetTopMargin(0.05)
    ROOT.gPad.SetLeftMargin(0.15)
    ROOT.gPad.SetRightMargin(0.05)

    if not options.plotGraph:
        ROOT.gPad.SetRightMargin(0.15)

    #Plot each variable
    for var in varColl:
        if var not in ydDict:
            print('Missing yd: ', var)
        if var not in eydDict:
            print('Missing eyd: ', var)
            continue

        gr = ROOT.TGraphErrors(len(xd), xd, ydDict[var], exd, eydDict[var])
        xmin = min(xd)
        xmax = max(xd)
        ymin = min(ydDict[var])
        ymax = max(ydDict[var])

        h = (ymax - ymin)
        ymin -= 0.25 * h
        ymaxSmall = ymax + 0.25 * h
        ymax += 0.75 * h

        ymin2 = min(ydDict2[var])
        ymax2 = max(ydDict2[var])

        h = (ymax2 - ymin2)
        ymin2 -= 0.25 * h
        ymax2 += 0.75 * h

        h = (xmax - xmin)
        xmin -= 0.05 * h
        xmax += 0.05 * h

        #This histogram is made just to make it easier to manipulate the margins
        histo = ROOT.TH2D('hd' + var, 'hd' + var, 100, xmin, xmax, 100, ymin,
                          ymax)
        histo.GetYaxis().SetTitle(varDef(var, 'atit', var))
        histo.GetXaxis().SetTitle('Average interactions per bunch crossing')
        histo.GetZaxis().SetTitle('Entries')

        histo2 = ROOT.TH2D('hd2' + var, 'hd2' + var, 100, xmin, xmax, 100,
                           ymin2, ymax2)
        histo2.GetYaxis().SetTitle(
            "<Interaction density> @ z=0 [interactions/mm]")
        histo2.GetXaxis().SetTitle('Average interactions per bunch crossing')
        histo2.GetZaxis().SetTitle('Entries')

        histo2W = ROOT.TH2D('hd3' + var, 'hd3' + var, 100, xmin, xmax, 100,
                            ymin2, ymax2)
        histo2W.GetYaxis().SetTitle(
            "<Interaction density> @ z=0 [interactions/mm]")
        histo2W.GetXaxis().SetTitle('Average interactions per bunch crossing')
        histo2W.GetZaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')

        histoW = ROOT.TH2D('hdW' + var, 'hdW' + var, 100, xmin, xmax, 100,
                           ymin, ymax)
        histoW.GetYaxis().SetTitle(varDef(var, 'atit', var))
        histoW.GetXaxis().SetTitle('Average interactions per bunch crossing')
        histoW.GetZaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')

        histoW1D = ROOT.TH1D('hd1D' + var, 'hd1D' + var, 100, ymin, ymaxSmall)
        histoW1D.GetXaxis().SetTitle(varDef(var, 'atit', var))
        histoW1D.GetYaxis().SetTitle('Integrated Luminosity (fb^{-1}/bin)')

        histo.Draw()
        if options.plotGraph:
            gr.Draw("p")
        else:
            for mu, x, l in zip(xd, ydDict[var], lumi):
                histo.Fill(mu, x)
                histoW.Fill(mu, x, l)
                histoW1D.Fill(x, l)
            for mu, x, l in zip(xd, ydDict2[var], lumi):
                histo2.Fill(mu, x)
                histo2W.Fill(mu, x, l)
            histo.Draw("colz")

        histo.Write()
        histoW.Write()
        histo2.Write()
        histo2W.Write()
        histoW1D.Write()

        # Add some information to the graph
        ROOTUtils.atlasLabel(0.53,
                             0.87,
                             False,
                             offset=0.12,
                             isForApproval=False,
                             customstring="Internal",
                             energy='%2.0f' % beamEnergy,
                             size=0.055)
        ROOTUtils.drawText(0.18, 0.87, 0.055, varDef(var, 'title', var))

        comments = []

        if runStart == runEnd:
            comments.append('Run %i' % runStart)
        else:
            comments.append('Runs %i - %i' % (runStart, runEnd))

        if fillStart == fillEnd:
            comments.append('Fill %i' % fillStart)
        else:
            comments.append('Fills %i - %i' % (fillStart, fillEnd))

        t1 = time.strftime('%d %b %Y', time.localtime(timeStart))
        t2 = time.strftime('%d %b %Y', time.localtime(timeEnd))
        if t1 == t2:
            comments.append(t1)
        else:
            comments.append('%s - %s' % (t1, t2))

        ROOTUtils.drawText(0.18, 0.81, 0.05, ';'.join(comments), font=42)

        canvas.Print("Run_%d_%sVsMu.png" % (options.runMin, var))
        canvas.Print("Run_%d_%sVsMu.pdf" % (options.runMin, var))
        if not options.plotGraph:
            canvas.SetLogz(True)
            canvas.Print("Run_%d_%sVsMuLog.png" % (options.runMin, var))
            canvas.Print("Run_%d_%sVsMuLog.pdf" % (options.runMin, var))
            canvas.SetLogz(False)

            histo2.Draw("colz")
            ROOTUtils.atlasLabel(0.53,
                                 0.87,
                                 False,
                                 offset=0.12,
                                 isForApproval=False,
                                 customstring="Internal",
                                 energy='%2.0f' % beamEnergy,
                                 size=0.055)
            ROOTUtils.drawText(0.18, 0.87, 0.055, "Interaction density")
            ROOTUtils.drawText(0.18, 0.81, 0.05, ';'.join(comments), font=42)
            canvas.Print("Run_%d_Mu%sVsMu.png" % (options.runMin, var))
            canvas.Print("Run_%d_Mu%sVsMu.pdf" % (options.runMin, var))
            canvas.SetLogz(True)
            canvas.Print("Run_%d_Mu%sVsMuLog.png" % (options.runMin, var))
            canvas.Print("Run_%d_Mu%sVsMuLog.pdf" % (options.runMin, var))
            canvas.SetLogz(False)

            histoW.Draw("colz")
            histoW.SetMinimum(0.005)
            ROOTUtils.atlasLabel(0.53,
                                 0.87,
                                 False,
                                 offset=0.12,
                                 isForApproval=False,
                                 customstring="Internal",
                                 energy='%2.0f' % beamEnergy,
                                 size=0.055)
            ROOTUtils.drawText(0.18, 0.87, 0.055, varDef(var, 'title', var))
            ROOTUtils.drawText(0.18, 0.81, 0.05, ';'.join(comments), font=42)
            canvas.Print("Run_%d_%sVsMuW.png" % (options.runMin, var))
            canvas.Print("Run_%d_%sVsMuW.pdf" % (options.runMin, var))
            canvas.SetLogz(True)
            canvas.Print("Run_%d_%sVsMuWLog.png" % (options.runMin, var))
            canvas.Print("Run_%d_%sVsMuWLog.pdf" % (options.runMin, var))
            canvas.SetLogz(False)

            histo2W.Draw("colz")
            histo2W.SetMinimum(0.01)

            ROOTUtils.atlasLabel(0.53,
                                 0.87,
                                 False,
                                 offset=0.12,
                                 isForApproval=False,
                                 customstring="Internal",
                                 energy='%2.0f' % beamEnergy,
                                 size=0.055)
            ROOTUtils.drawText(0.18, 0.87, 0.055, "Interaction density")
            ROOTUtils.drawText(0.18, 0.81, 0.05, ';'.join(comments), font=42)
            canvas.Print("Run_%d_Mu%sVsMuW.png" % (options.runMin, var))
            canvas.Print("Run_%d_Mu%sVsMuW.pdf" % (options.runMin, var))
            canvas.SetLogz(True)
            canvas.Print("Run_%d_Mu%sVsMuWLog.png" % (options.runMin, var))
            canvas.Print("Run_%d_Mu%sVsMuWLog.pdf" % (options.runMin, var))
            canvas.SetLogz(False)

            histoW1D.Draw("colz")
            ROOTUtils.atlasLabel(0.53,
                                 0.87,
                                 False,
                                 offset=0.12,
                                 isForApproval=False,
                                 customstring="Internal",
                                 energy='%2.0f' % beamEnergy,
                                 size=0.055)
            ROOTUtils.drawText(0.18, 0.87, 0.055, varDef(var, 'title', var))
            ROOTUtils.drawText(0.18,
                               0.81,
                               0.05,
                               "#mu=%2.4f RMS=%2.4f" %
                               (histoW1D.GetMean(), histoW1D.GetRMS()),
                               font=42)
            canvas.Print("Run_%d_%s1D.png" % (options.runMin, var))
            canvas.Print("Run_%d_%s1D.pdf" % (options.runMin, var))
            canvas.SetLogy(True)
            canvas.Print("Run_%d_%s1DLog.png" % (options.runMin, var))
            canvas.Print("Run_%d_%s1DLog.pdf" % (options.runMin, var))
            canvas.SetLogy(False)
Esempio n. 13
0
def drawSummary(var=''):
    # description
    descrText = ''
    if options.config == 'OnlineOffline':
        descrText += 'Online - Offline comparison'
        legText1 = 'Offine'
        legText2 = 'Online'
    elif options.config == 'Reproc':
        if not options.multicanv:
            descrText += 'Reprocessed - Tier0 comparison'
        if options.label1 == '':
            legText1 = 'Tier0'
        if options.label2 == '':
            legText2 = 'Reproc'
    else:
        legText1 = 'Beamspots 1'
        legText2 = 'Beamspots 2'

    if options.label1 != '':
        legText1 = options.label1

    if options.label2 != '':
        legText2 = options.label2

    if options.multicanv:
        primarypad[var].cd()
    if not options.multicanv:
        ROOTUtils.drawText(0.14, 0.95, 0.1, descrText)
    else:
        ROOTUtils.drawText(0.14, 0.95, 0.1, descrText)

    # legend
    legendList = []

    legendList.append([gr1, legText1, 'LP'])
    legendList.append([gr2, legText2, 'LP'])
    legendList.append([grdiff, 'Difference', 'LP'])
    if options.multicanv:
        ROOTUtils.drawLegend(0.25, 0.6, 0.60, 0.92, legendList)
    elif not options.plotHistos:
        ROOTUtils.drawLegend(0.14, 0.67, 0.9, 0.9, legendList)
    if runNumber != 0:
        if options.multicanv:
            ROOTUtils.drawText(0.6, 0.7, 0.1, 'Run = %i' % runNumber)
        else:
            ROOTUtils.drawText(0.14, 0.55, 0.1, 'Run = %i' % runNumber)
    if options.multicanv:
        primarypad[var].Update()
Esempio n. 14
0
    runNumber = getRunFromName(tag2, '0', True)
    print('Doing comparison for run %i' % runNumber)
else:
    runNumber = 0
    #print ('Doing comparison for all runs in %s' % tag1)

# Precision
ndp = 5
ndptilt = 8

# Setup ROOT
if options.batch:
    ROOT.gROOT.SetBatch(1)
import ROOT
from InDetBeamSpotExample import ROOTUtils
ROOTUtils.setStyle()

# Flag for DB info
fromDB = False
fromCSV = False

# Determine type of input
if tag1.find('.root') > -1:
    # It's a root file
    if options.finder1:
        BSData1 = BeamSpotFinderNt(tag1)
    else:
        BSData1 = BeamSpotNt(tag1)
elif tag1.find('.csv') > -1:
    # comma-separated format
    BSData1 = BeamSpotCSV(tag1)