示例#1
0
def testIthr():
    lines = get_lines('DAC_scan_ithr_0x40to0xf0.dat')

    gr1 = TGraphErrors()
    gr2 = TGraphErrors()

    fUnit = 1000. / 0.7
    yUnit = 'e^{-}'

    for line in lines:
        if len(line) == 0: continue
        if line[0] in ['#', '\n']: continue
        fs = line.rstrip().split()

        ix = int(fs[0])
        gr1.SetPoint(ix, float(fs[1]), float(fs[2]) * fUnit)
        gr1.SetPointError(ix, 0, float(fs[3]) * fUnit)
        gr2.SetPoint(ix, float(fs[1]), float(fs[4]) * fUnit)
        gr2.SetPointError(ix, 0, float(fs[5]) * fUnit)

    useAtlasStyle()
    gStyle.SetMarkerStyle(20)

    gr1.SetMarkerStyle(20)
    gr1.Draw('AP')
    h1 = gr1.GetHistogram()
    h1.GetYaxis().SetTitle("Threshold [" + yUnit + "]")
    h1.GetXaxis().SetTitle("I_{Thre} code")
    # h1.GetYaxis().SetRangeUser(0,0.2)

    gPad.SetTicks(1, 0)
    gPad.SetRightMargin(0.16)

    y1b = 0
    y2b = 15
    x1 = h1.GetXaxis().GetXmax()
    y1 = h1.GetYaxis().GetXmin()
    y2 = h1.GetYaxis().GetXmax()
    raxis = TGaxis(x1, y1, x1, y2, y1b, y2b, 506, "+L")
    raxis.SetLineColor(2)
    raxis.SetLabelColor(2)
    raxis.SetTitleColor(2)
    raxis.SetTitle("ENC [" + yUnit + "]")
    raxis.Draw()

    nP = gr2.GetN()
    Ys = gr2.GetY()
    EYs = gr2.GetEY()
    Y = array(
        'd', [y1 + (y2 - y1) / (y2b - y1b) * (Ys[i] - y1b) for i in range(nP)])
    EY = array('d', [(y2 - y1) / (y2b - y1b) * EYs[i] for i in range(nP)])
    gr2x = TGraphErrors(nP, gr2.GetX(), Y, gr2.GetEX(), EY)
    gr2x.SetMarkerStyle(24)
    gr2x.SetLineColor(2)
    gr2x.SetMarkerColor(2)

    gr2x.Draw('Psame')

    waitRootCmdX()
示例#2
0
gStyle.SetOptFit()
gr = TGraphErrors(17, xarray, yarray, xarrayerror, yarrayerror)
gr1 = TGraphErrors(17, xarray, yarray1, xarrayerror, yarrayerror)

gr.SetLineStyle(1)
gr.SetMarkerColor(2)
gr.SetMarkerStyle(8)
gr.SetLineWidth(2)

gr1.SetLineStyle(1)
gr1.SetMarkerColor(3)
gr1.SetMarkerStyle(8)
gr1.SetLineWidth(2)

gr1.SetTitle(";Concentration(1/cm^{3}) ;# of impurities ")
gr1.GetHistogram().SetMaximum(30)
gr1.GetHistogram().SetMinimum(0)
gr1.GetXaxis().SetLimits(math.pow(10, 10 + 0 * 0.5),
                         math.pow(10, 10 + 16 * 0.5))

leg1 = TLegend(0.2, 0.7, 0.5, 0.9)
leg1.SetFillColor(0)
leg1.SetFillStyle(0)
leg1.SetTextSize(0.05)
leg1.SetBorderSize(0)
leg1.SetTextFont(22)
leg1.AddEntry("", "GeIA group", "")
leg1.AddEntry("", "Avalanche region:", "")
leg1.AddEntry(gr, str(Avalanche_region) + "cm(Square)", "lp")
leg1.AddEntry(gr1, str(Avalanche_region1) + "cm(Circle)", "lp")
示例#3
0
def scanKK():
    '''Used to test the scan of one or more parameters'''
    nChips = 19 # the magic number
#     nChan = len(chans)

    iP = 1
    cd = CommonData()
    cd.setupConnection()
    sc1 = SensorConfig(cd)

    ### get list of chains to be updated
#     chains = set([sc1.tms1mmX19chainSensors[sc1.tms1mmX19sensorInChain[c]][0] for c in chans])

    chan = 5
#     cd.inputVs = [3., 0., 3., 0., 0., 0.]
#     cd.inputVs = [3., 0., 0.732, 1.68, 0., 0.]
#     cd.inputVs = [0.75, 2.15, 0.7, 0., 0., 0.]

    show = True
    g1 = None
    if show:
        g1 = TGraphErrors()

    xj = open('scan_KK_6.ttl','w')

    ### point insert scan
    ipar = 2
    pts = [(0.,None),(3.,None)]
    while True:
        print pts
        pt, xy, r1, k = insertPoint(pts)
        print '-'*30
        print pt,xy,r1, k
        print '-'*30
        if xy<3 and (r1<0.01 or xy/r1<0.1 or k<0.007): break

        cd.inputVs[ipar] = pt
        cd.updatePars(chan, None, False)
        sc1.update_sensor(chan)
        time.sleep(3)
        cd.fetch()

        m,v = getMeanVar(cd.adcData[chan])
        print ' '.join([str(x) for x in [chan, m, v]+cd.inputVs])
        xj.write(' '.join([str(x) for x in [chan, m, v]+cd.inputVs])+'\n')

        if g1:
            n1 = g1.GetN()
            g1.SetPoint(n1, pt, m)
            g1.SetPointError(n1, 0, v)

        if xy == 999:
            pts[r1] = (pt,m)
        else:
            pts.append((pt,m))

    ### simple scan
#     while cd.inputVs[0]>0.001:
#         cd.updatePars(chan, None, False)
#         sc1.update_sensor(chan)
#         time.sleep(2)
#         cd.fetch()
# 
#         m,v = getMeanVar(cd.adcData[chan])
#         print ' '.join([str(x) for x in [chan, m, v]+cd.inputVs])
#         xj.write(' '.join([str(x) for x in [chan, m, v]+cd.inputVs])+'\n')
# 
#         if g1:
#             g1.SetPoint(g1.GetN(), cd.inputVs[0], m)
#         cd.inputVs[0] *= 2./3
    if g1:
        g1.SetMarkerStyle(4)
        g1.SetMarkerColor(2)
        g1.SetLineColor(2)
        g1.Draw("AP")
        h1 = g1.GetHistogram()
        h1.GetXaxis().SetTitle(cd.voltsNames[ipar]+' [V]')
        h1.GetYaxis().SetTitle("V_{out} [V]")
        lt = TLatex()
        lt.DrawLatexNDC(0.2,0.92,"Chip %d"%chan)
        waitRootCmdX()
示例#4
0
def analyzeData(country, total, active, recovered, deaths, tStart, tStop,
                totalPopulation, symptomaticFraction, transmissionProbability,
                recoveryRate, doSmearing, doFit):
    ntuple = [
        tStart, tStop, totalPopulation, symptomaticFraction,
        transmissionProbability, recoveryRate
    ]
    farFromMax = 0.95
    growthRate = 0.13
    carryingCapacity = 4e5

    ################
    # Active cases #
    ################
    myCanvActive = TCanvas('myCanvActive_' + country,
                           'Active cases ' + country)

    xValues = [
        i for i in range(len(active.keys())) if i >= tStart and i <= tStop
    ]
    yValues = [
        active[k] for i, k in enumerate(sorted(active.keys()))
        if i >= tStart and i <= tStop
    ]
    erryValues = assignErrors(yValues)

    myGraphActive = TGraphErrors()
    myGraphActive.SetMarkerStyle(20)
    for i in range(len(xValues)):
        myGraphActive.SetPoint(myGraphActive.GetN(), xValues[i], yValues[i])
        myGraphActive.SetPointError(myGraphActive.GetN() - 1, 0, erryValues[i])
    myGraphActive.Draw('APE1')
    myGraphActive.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphActive.GetHistogram().GetYaxis().SetTitle(
        'Active cases affected by CoViD-19')

    historyActive = 0.
    for i, k in enumerate(sorted(active.keys())):
        if i < tStart:
            historyActive += active[k]
    ntuple.extend([historyActive, xValues, yValues, erryValues])
    print('==> History active cases:', historyActive)

    ###################
    # Build the model #
    ###################
    evActive = evolution([yValues[0], carryingCapacity, growthRate], tStart,
                         tStop, totalPopulation, recoveryRate,
                         symptomaticFraction, transmissionProbability,
                         historyActive)

    if doFit == True:
        evActive.runOptimization(xValues, yValues, erryValues, [], doSmearing)
        evActive.evolve(evActive.tStop, evActive.parValues, True)
        if doSmearing == True:
            evActive.smearing()
        evActiveGraphN = evActive.getGraphN()
        evActiveGraphN.Draw('PL same')
        statActive = evActive.addStats(evActive.parNames, evActive.parValues)

        print(
            '==> Active cases, history active cases, p-infected, Carrying capacity, total population alive',
            evActive.evolve(tStop, evActive.parValues), 'at day', tStop)
        print('==> Percentage population with antibodies',
              round(100. * evActive.totalInfected(tStop) / totalPopulation),
              '% at day', tStop, '(herd immunity at', evActive.herdImmunity(),
              '%)')
        print('==> Doubling time:', round(log(2.) / evActive.parValues[2], 1),
              'days')

        now = TLine(
            len(active) - 1, 0,
            len(active) - 1, evActive.fitFun.Eval(len(active) - 1))
        now = TLine(len(active) - 1, 0, len(active) - 1, 1)
        now.SetLineColor(4)
        now.SetLineWidth(2)
        now.Draw('same')

        willbe = TLine(evActive.fitFun.GetMaximumX(), 0,
                       evActive.fitFun.GetMaximumX(),
                       evActive.fitFun.GetMaximum())
        willbe.SetLineColor(6)
        willbe.SetLineWidth(2)
        willbe.Draw('same')

        myCanvActiveR0 = TCanvas('myCanvActiveR0_' + country, 'R0 ' + country)

        evActiveGraphR0 = evActive.getGraphR0(evActiveGraphN)
        evActiveGraphR0.Draw('APL')
        evActiveGraphR0.GetHistogram().GetXaxis().SetTitle('Time (days)')
        evActiveGraphR0.GetHistogram().GetYaxis().SetTitle('R')

        myCanvActiveR0.SetGrid()
        myCanvActiveR0.Modified()
        myCanvActiveR0.Update()

    myCanvActive.SetGrid()
    myCanvActive.Modified()
    myCanvActive.Update()

    #################
    # CONTROL PLOTS #
    #################

    ###############
    # Total cases #
    ###############
    myCanvTotal = TCanvas('myCanvTotal_' + country, 'Total cases ' + country)
    myGraphTotal = TGraphErrors()
    myGraphTotal.SetMarkerStyle(20)

    for k in sorted(total.keys()):
        myGraphTotal.SetPoint(myGraphTotal.GetN(), myGraphTotal.GetN(),
                              total[k])
        myGraphTotal.SetPointError(myGraphTotal.GetN() - 1, 0, sqrt(total[k]))

    myGraphTotal.Draw('APE1')
    myGraphTotal.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphTotal.GetHistogram().GetYaxis().SetTitle(
        'Total cases affected by CoViD-19')

    myCanvTotal.SetGrid()
    myCanvTotal.Modified()
    myCanvTotal.Update()

    ##########
    # Deaths #
    ##########
    myCanvDeaths = TCanvas('myCanvDeaths_' + country, 'Deaths ' + country)
    myGraphDeaths = TGraphErrors()
    myGraphDeaths.SetMarkerStyle(20)

    for k in sorted(deaths.keys()):
        myGraphDeaths.SetPoint(myGraphDeaths.GetN(), myGraphDeaths.GetN(),
                               deaths[k])
        myGraphDeaths.SetPointError(myGraphDeaths.GetN() - 1, 0,
                                    sqrt(deaths[k]))

    myGraphDeaths.Draw('APE1')
    myGraphDeaths.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphDeaths.GetHistogram().GetYaxis().SetTitle('Total deaths')

    myCanvDeaths.SetGrid()
    myCanvDeaths.Modified()
    myCanvDeaths.Update()

    ########################
    # Ratio deaths / total #
    ########################
    myCanvRatio01 = TCanvas('myCanvRatio01_' + country, 'Ratio ' + country)
    myGraphRatio01 = TGraphErrors()
    myGraphRatio01.SetMarkerStyle(20)

    for k in sorted(deaths.keys()):
        myGraphRatio01.SetPoint(myGraphRatio01.GetN(), myGraphRatio01.GetN(),
                                deaths[k] / total[k])
        myGraphRatio01.SetPointError(
            myGraphRatio01.GetN() - 1, 0,
            myGraphRatio01.GetY()[myGraphRatio01.GetN() - 1] *
            sqrt(deaths[k] / (deaths[k] * deaths[k]) + total[k] /
                 (total[k] * total[k])))

    myGraphRatio01.Draw('APE1')
    myGraphRatio01.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphRatio01.GetHistogram().GetYaxis().SetTitle(
        'Total deaths / Total cases')

    myCanvRatio01.SetGrid()
    myCanvRatio01.Modified()
    myCanvRatio01.Update()

    ############################################
    # Ratio delta(deaths + recovered) / active #
    ############################################
    myCanvRatio02 = TCanvas('myCanvRatio02_' + country, 'Ratio ' + country)
    myGraphRatio02 = TGraphErrors()
    myGraphRatio02.SetMarkerStyle(20)

    sortedKeys = sorted(deaths.keys())
    for i, k in enumerate(sortedKeys[1:]):
        numerator = abs(deaths[k] - deaths[sortedKeys[i]] + recovered[k] -
                        recovered[sortedKeys[i]])
        denominator = active[k]
        myGraphRatio02.SetPoint(
            myGraphRatio02.GetN(),
            myGraphRatio02.GetN() + 1,
            numerator / denominator if denominator != 0 else 0)
        myGraphRatio02.SetPointError(
            myGraphRatio02.GetN() - 1, 0,
            (myGraphRatio02.GetY()[myGraphRatio02.GetN() - 1] *
             sqrt(numerator / pow(numerator, 2) +
                  denominator / pow(denominator, 2)))
            if denominator != 0 else 0)

    myGraphRatio02.Draw('AP')
    myGraphRatio02.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphRatio02.GetHistogram().GetYaxis().SetTitle(
        '#Delta Recovered (alive + dead) / Active cases')

    myCanvRatio02.SetGrid()
    myCanvRatio02.Modified()
    myCanvRatio02.Update()

    ######################################
    # Ratio delta(deaths) / delta(total) #
    ######################################
    myCanvRatio03 = TCanvas('myCanvRatio03_' + country, 'Ratio ' + country)
    myGraphRatio03 = TGraphErrors()
    myGraphRatio03.SetMarkerStyle(20)

    sortedKeys = sorted(deaths.keys())
    for i, k in enumerate(sortedKeys[1:]):
        numerator = abs(deaths[k] - deaths[sortedKeys[i]])
        denominator = total[k] - total[sortedKeys[i]]
        myGraphRatio03.SetPoint(
            myGraphRatio03.GetN(),
            myGraphRatio03.GetN() + 1,
            numerator / denominator if denominator != 0 else 0)
        myGraphRatio03.SetPointError(
            myGraphRatio03.GetN() - 1, 0,
            (myGraphRatio03.GetY()[myGraphRatio03.GetN() - 1] *
             sqrt(numerator / pow(numerator, 2) +
                  denominator / pow(denominator, 2)))
            if denominator != 0 else 0)

    myGraphRatio03.Draw('AP')
    myGraphRatio03.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphRatio03.GetHistogram().GetYaxis().SetTitle(
        '#Delta deaths / #Delta total')

    myCanvRatio03.SetGrid()
    myCanvRatio03.Modified()
    myCanvRatio03.Update()

    if doFit == False:
        return [
            ntuple, myCanvTotal, myGraphTotal, myCanvActive, myGraphActive,
            myCanvDeaths, myGraphDeaths, myCanvRatio01, myGraphRatio01,
            myCanvRatio02, myGraphRatio02, myCanvRatio03, myGraphRatio03
        ]

    return [
        ntuple, myCanvTotal, myGraphTotal, myCanvActive, myGraphActive,
        evActive, evActiveGraphN, statActive, now, willbe, myCanvActiveR0,
        evActiveGraphR0, myCanvDeaths, myGraphDeaths, myCanvRatio01,
        myGraphRatio01, myCanvRatio02, myGraphRatio02, myCanvRatio03,
        myGraphRatio03
    ]
示例#5
0
def runGlobalFit(country, active, totalPopulation, symptomaticFraction,
                 transmissionProbability, recoveryRate, doSmearing, doFit):
    tStart = 0
    tStop = 9 + 6 + 12 + 42 + 61 + 40 + 50 + 200
    timeList = [
        9, 9 + 6, 9 + 6 + 12, 9 + 6 + 12 + 42, 9 + 6 + 12 + 42 + 61,
        9 + 6 + 12 + 42 + 61 + 40, 9 + 6 + 12 + 42 + 61 + 40 + 50, tStop
    ]

    ntuple = [
        tStart, tStop, totalPopulation, symptomaticFraction,
        transmissionProbability, recoveryRate
    ]

    ################
    # Active cases #
    ################
    myCanvActive = TCanvas('myCanvActive_' + country,
                           'Active cases ' + country)

    xValues = [
        i for i in range(len(active.keys())) if i >= tStart and i <= tStop
    ]
    yValues = [
        active[k] for i, k in enumerate(sorted(active.keys()))
        if i >= tStart and i <= tStop
    ]
    erryValues = assignErrors(yValues)

    myGraphActive = TGraphErrors()
    myGraphActive.SetMarkerStyle(20)
    for i in range(len(xValues)):
        myGraphActive.SetPoint(myGraphActive.GetN(), xValues[i], yValues[i])
        myGraphActive.SetPointError(myGraphActive.GetN() - 1, 0, erryValues[i])
    myGraphActive.Draw('APE1')
    myGraphActive.GetHistogram().GetXaxis().SetTitle('Time (days)')
    myGraphActive.GetHistogram().GetYaxis().SetTitle(
        'Active cases affected by CoViD-19')

    ntuple.extend([
        0, xValues, yValues, erryValues, timeList, 1894, 16052, 0.435, 0.438,
        0.308, 0.216, 0.054, 0.435 / 2.5, 0.435 / 1.5, 0.435
    ])  # 0.0133, 0.175, 0.217, 0.393

    if doFit == True:
        ###################
        # Build the model #
        ###################
        evActive = evolution([ntuple[11], ntuple[12], ntuple[13]], tStart,
                             timeList[0], totalPopulation, recoveryRate,
                             symptomaticFraction, transmissionProbability)
        evolutions = [
            evolution([0, 0, ntuple[14 + i]], timeList[i], timeList[i + 1], 0,
                      recoveryRate, symptomaticFraction,
                      transmissionProbability) for i in range(3)
        ]
        evolutions.extend([
            evolution([0, 0, ntuple[14 + 3]], timeList[3], timeList[4], 0,
                      0.035, symptomaticFraction, transmissionProbability / 8)
        ])
        evolutions.extend([
            evolution([0, 0, ntuple[14 + 4]], timeList[4], timeList[5], 0,
                      recoveryRate, symptomaticFraction,
                      transmissionProbability / 2.5)
        ])
        evolutions.extend([
            evolution([0, 0, ntuple[14 + 5]], timeList[5], timeList[6], 0,
                      recoveryRate, symptomaticFraction,
                      transmissionProbability / 1.5)
        ])
        evolutions.extend([
            evolution([0, 0, ntuple[14 + 6]], timeList[6], timeList[7], 0,
                      recoveryRate, symptomaticFraction,
                      transmissionProbability)
        ])

        istat, parValues, parNames = evActive.runGlobalOptimization(
            evolutions, xValues, yValues, erryValues, [0, 1, 2, 3, 4, 5],
            doSmearing)

        evActive.evolveGlobal(evolutions, evolutions[-1].tStop, parValues,
                              True)
        if doSmearing == True:
            evActive.smearing()
        evActive.setFitFun(evActive.evolveLookUpWrapper, tStart, tStop,
                           parNames, parValues)
        evActiveGraphN = evActive.getGraphN()
        evActiveGraphN.Draw('PL same')
        statActive = evActive.addStats(parNames, parValues)

        print(
            '==> Active cases, history active cases * dt, p-infected, Carrying capacity, total population alive',
            evActive.evolveGlobal(evolutions, tStop, parValues), 'at day',
            tStop)
        print(
            '==> Percentage population with antibodies',
            round(100. *
                  evActive.totalInfectedGlobal(evolutions, tStop, parValues) /
                  totalPopulation), '% at day', tStop)

        now = TLine(
            len(active) - 1, 0,
            len(active) - 1, evActive.fitFun.Eval(len(active) - 1))
        now.SetLineColor(4)
        now.SetLineWidth(2)
        now.Draw('same')

        willbe = TLine(evActive.fitFun.GetMaximumX(), 0,
                       evActive.fitFun.GetMaximumX(),
                       evActive.fitFun.GetMaximum())
        willbe.SetLineColor(6)
        willbe.SetLineWidth(2)
        willbe.Draw('same')

        myCanvActiveR0 = TCanvas('myCanvActiveR0_' + country, 'R0 ' + country)

        evActiveGraphR0 = evActive.getGraphR0(evActiveGraphN)
        evActiveGraphR0.Draw('APL')
        evActiveGraphR0.GetHistogram().GetXaxis().SetTitle('Time (days)')
        evActiveGraphR0.GetHistogram().GetYaxis().SetTitle('R')

        myCanvActiveR0.SetGrid()
        myCanvActiveR0.Modified()
        myCanvActiveR0.Update()

    myCanvActive.SetGrid()
    myCanvActive.Modified()
    myCanvActive.Update()

    if doFit == False:
        return [ntuple, myCanvActive, myGraphActive]
    return [
        ntuple, myCanvActive, myGraphActive, evActive, evActiveGraphN,
        statActive, now, willbe, myCanvActiveR0, evActiveGraphR0
    ]
示例#6
0
def makeBeamspotCutPlots(name, points):
    nPoints = len(points)

    x = TGraphErrors(nPoints)
    x.SetName(name)
    x.SetTitle(name + "  x; lb; x [mm]")
    y = TGraphErrors(nPoints)
    y.SetName(name)
    y.SetTitle(name + "  y; lb; y [mm]")
    z = TGraphErrors(nPoints)
    z.SetName(name)
    z.SetTitle(name + "  z; lb; z [mm]")
    sx = TGraphErrors(nPoints)
    sx.SetName(name)
    sx.SetTitle(name + "  sx; lb; #sigma(x) [mm]")
    sy = TGraphErrors(nPoints)
    sy.SetName(name)
    sy.SetTitle(name + "  sy; lb; #sigma(y) [mm]")
    sz = TGraphErrors(nPoints)
    sz.SetName(name)
    sz.SetTitle(name + "  sz; lb; #sigma(z) [mm]")

    xrms = TGraphErrors(nPoints)
    xrms.SetName(name + "_rms")
    xrms.SetTitle(name + "_rms" + "  x")
    yrms = TGraphErrors(nPoints)
    yrms.SetName(name + "_rms")
    yrms.SetTitle(name + "_rms" + "  y")
    zrms = TGraphErrors(nPoints)
    zrms.SetName(name + "_rms")
    zrms.SetTitle(name + "_rms" + "  z")
    sxrms = TGraphErrors(nPoints)
    sxrms.SetName(name + "_rms")
    sxrms.SetTitle(name + "_rms" + "  sx")
    syrms = TGraphErrors(nPoints)
    syrms.SetName(name + "_rms")
    syrms.SetTitle(name + "_rms" + "  sy")
    szrms = TGraphErrors(nPoints)
    szrms.SetName(name + "_rms")
    szrms.SetTitle(name + "_rms" + "  sz")

    graphs.extend([x, y, z, sx, sy, sz, xrms, yrms, zrms, sxrms, syrms, szrms])
    print len(points)
    for i in range(len(points)):
        xval = points[i][0]
        yvals = points[i][1]

        xerr = 0

        x.SetPoint(i, xval, yvals[0][0])
        y.SetPoint(i, xval, yvals[1][0])
        z.SetPoint(i, xval, yvals[2][0])
        sx.SetPoint(i, xval, yvals[3][0])
        sy.SetPoint(i, xval, yvals[4][0])
        sz.SetPoint(i, xval, yvals[5][0])

        x.SetPointError(i, xerr, yvals[0][1])
        y.SetPointError(i, xerr, yvals[1][1])
        z.SetPointError(i, xerr, yvals[2][1])
        sx.SetPointError(i, xerr, yvals[3][1])
        sy.SetPointError(i, xerr, yvals[4][1])
        sz.SetPointError(i, xerr, yvals[5][1])

        xrms.SetPoint(i, xval, yvals[0][2])
        yrms.SetPoint(i, xval, yvals[1][2])
        zrms.SetPoint(i, xval, yvals[2][2])
        sxrms.SetPoint(i, xval, yvals[3][2])
        syrms.SetPoint(i, xval, yvals[4][2])
        szrms.SetPoint(i, xval, yvals[5][2])

        xrms.SetPointError(i, xerr, yvals[0][3])
        yrms.SetPointError(i, xerr, yvals[1][3])
        zrms.SetPointError(i, xerr, yvals[2][3])
        sxrms.SetPointError(i, xerr, yvals[3][3])
        syrms.SetPointError(i, xerr, yvals[4][3])
        szrms.SetPointError(i, xerr, yvals[5][3])

    c = TCanvas("cx")
    c.Divide(3, 1)
    c.cd(1)
    x.Draw("ap")
    c.cd(2)
    y.Draw("ap+Y+")
    c.cd(3)
    yaxis_xrms = TGaxis(-1, 0.2, 1, 0.2, -1, 2, 510, "+R")
    yaxis_xrms.ImportAxisAttributes(y.GetHistogram().GetYaxis())
    #g = TMultiGraph()
    #g.Add(x,"aXp")
    #g.Add(y,"aY*")
    #g.Draw("a")
    # graphs.append(g)
    #   aa = y.GetHistogram()

    #x.Draw("ap")
    yaxis_xrms.Draw()
    #axis.PaintAxis(0,0.5,0.1,0.6,0.4,1.4,510,"+R")
    #y.Draw("pY+sames")
    #b.Draw("sames")
    c.Modified()
    c.Update()
    #c.Print()
    canvases.append(c)
示例#7
0
    #gr.GetXaxis().SetTitle("E[TeV]")
    #gr.GetXaxis().SetTitleColor(4)
    #gr.GetYaxis().SetTitle("<T_{delay>}")

    #gr_QQ.SetTitle("<T_{delay}>[ns] Vs E[TeV]")
    gr_QQ_5TeV.Draw("ALP")
    gr_WW_5TeV.Draw("LPsame")
    gr_QQ_10TeV.Draw("LPsame")
    gr_WW_10TeV.Draw("LPsame")
    gr_QQ_20TeV.Draw("LPsame")
    gr_WW_20TeV.Draw("LPsame")
    gr_QQ_40TeV.Draw("LPsame")
    gr_WW_40TeV.Draw("LPsame")

    if (Sort_particle == 4):
        gr_QQ_5TeV.GetHistogram().SetMaximum(1.5)
        gr_QQ_5TeV.GetHistogram().SetMinimum(0.5)

    else:
        gr_QQ_5TeV.GetHistogram().SetMaximum(0.4)
        gr_QQ_5TeV.GetHistogram().SetMinimum(0)
    gr_QQ_5TeV.GetXaxis().SetLimits(0, 2)
    gr_QQ_5TeV.GetXaxis().CenterTitle()
    gr_QQ_5TeV.GetYaxis().CenterTitle()

    #=================================
    leg1 = TLegend(0.15, 0.55, 0.35, 0.9)
    leg1.SetFillColor(0)
    leg1.SetFillStyle(0)
    leg1.SetTextSize(0.04)
    leg1.SetBorderSize(0)
示例#8
0
gr.SetLineWidth(2)
gr1.SetLineStyle(1)
gr1.SetMarkerColor(3)
gr1.SetMarkerStyle(8)
gr1.SetLineWidth(2)
gr2.SetLineStyle(1)
gr2.SetMarkerColor(4)
gr2.SetMarkerStyle(8)
gr2.SetLineWidth(2)
gr3.SetLineStyle(1)
gr3.SetMarkerColor(5)
gr3.SetMarkerStyle(8)
gr3.SetLineWidth(2)

gr1.SetTitle(";E(V/cm) ;Ionization Rate(/cm) ")
gr.GetHistogram().SetMaximum(3000)
gr.GetHistogram().SetMinimum(0)
gr.GetXaxis().SetLimits(0, 10)
gr.GetXaxis().CenterTitle()
gr.GetYaxis().CenterTitle()
#================================
gr.GetYaxis().SetTitleSize(0.02)
gr.GetXaxis().SetTitleSize(0.02)
gr.GetXaxis().SetLabelSize(0.02)
gr.GetYaxis().SetLabelSize(0.02)
gr.GetXaxis().SetLabelFont(22)
gr.GetYaxis().SetLabelFont(22)
gr.GetXaxis().SetTitleColor(1)
gr.GetYaxis().SetTitleColor(1)

leg1 = TLegend(0.2, 0.6, 0.5, 0.8)
示例#9
0
p2 = round(p2,4)

# error of the first parameter
e2 = fit_x.GetParError(1)
e2 = round(e2,4)

print "Chi2 = " + str(chi2)
print "P1 = " + str(p1)
print "E1 = " + str(e1)


TVirtualFitter.GetFitter().GetConfidenceIntervals(grint)
grint.SetLineColor(1)
grint.SetFillColorAlpha(16,0.65)

grint.GetHistogram().SetTitle(" ");
grint.GetHistogram().GetXaxis().SetTitle("Top P_{T} (GeV)")



if(THEORY == "PWHGP8" ):
    grint.GetHistogram().GetYaxis().SetTitle("DATA/Powheg+Pythia8")
elif(THEORY == "Kidonakis"):
    grint.GetHistogram().GetYaxis().SetTitle("DATA/aN^3LO")
elif(THEORY == "Mitov"):
    grint.GetHistogram().GetYaxis().SetTitle("DATA/NNLO")
elif(THEORY == "Lipka"):
    grint.GetHistogram().GetYaxis().SetTitle("DATA/approx. NNLO")
elif(THEORY == "Pecjak"):
    grint.GetHistogram().GetYaxis().SetTitle("DATA/approx. NLO + NNLL'")
        h_temp.Draw()
        temp_x.append(
            p_ele_dp_ele_from_ang_ftof_isr[ss].GetXaxis().GetBinCenter(xx))
        temp_xerr.append(0)
        temp_y.append(f_temp.GetParameter(1))
        temp_yerr.append(f_temp.GetParError(1))
    can.Print(mon_out_file_name)

    if len(temp_x) == 0: continue
    g_temp = TGraphErrors(len(temp_x), temp_x, temp_y, temp_xerr, temp_yerr)
    g_temp.SetTitle(
        'El. P_{e} from #Theta_{e}#Theta_{p} #Delta P_{e} vs P_{e} Pr (FTOF) S'
        + str(ss) + ', #gamma (ISR) ; P_{e} (GeV); #Delta P_{e}')
    g_temp.SetMarkerStyle(21)
    g_temp.SetMarkerColor(kRed)
    g_temp.GetHistogram().SetMaximum(0.1)
    g_temp.GetHistogram().SetMinimum(-0.1)
    g_temp1.append(g_temp)
    l0 = TLine(temp_x[0], 0.0, temp_x[-1], 0.0)
    l0.SetLineColor(kRed)
    l_temp1.append(l0)

    store_graphs.append(g_temp)

can.Clear()
can.Divide(2, 3)
for ss in range(0, len(g_temp1)):
    can.cd(ss + 1)
    g_temp1[ss].Draw('AP')
    l_temp1[ss].Draw('same')
can.Print(mon_out_file_name)
示例#11
0
fitFcn = TF1("fitFcn","sqrt([0]*[0]/(x)+[1]*[1])",20,300)
fitFcn.SetLineColor(2)
gr.Fit(fitFcn,"R")
print fitFcn.GetChisquare()
print fitFcn.GetNDF()
print fitFcn.GetChisquare()/fitFcn.GetNDF()

fitFcn1 = TF1("fitFcn1","sqrt([0]*[0]/(x)+[1]*[1])",20,300)
fitFcn1.SetLineColor(3)
gr1.Fit(fitFcn1,"R")
print fitFcn1.GetChisquare()
print fitFcn1.GetNDF()
print fitFcn1.GetChisquare()/fitFcn1.GetNDF()
'''

gr_QQ.GetHistogram().SetMaximum(+5)
gr_QQ.GetHistogram().SetMinimum(-5)
#gr.GetXaxis().SetLimits(0,320)
gr_QQ.GetXaxis().CenterTitle()
gr_QQ.GetYaxis().CenterTitle()

#=================================
leg1 = TLegend(0.15, 0.75, 0.35, 0.9)
leg1.SetFillColor(0)
leg1.SetFillStyle(0)
leg1.SetTextSize(0.04)
leg1.SetBorderSize(0)
leg1.SetTextFont(22)
leg1.AddEntry(gr_QQ, "Z'#rightarrowQQ", "lp")
leg1.AddEntry(gr_WW, "Z'#rightarrowWW", "lp")
示例#12
0
def showDAC(fname, Infox=None, saveName='temp_figs/test', mode=1):

    lines = None
    with open(fname, 'r') as f1:
        lines = f1.readlines()

    gr1 = TGraphErrors()
    gr2 = TGraph()
    gr3 = TGraph()
    gr4 = TGraph()

    largeError = -1
    largeErrorI = None
    largeErrorMS = None

    for line in lines:
        line = line.rstrip()
        if len(line) == 0:
            continue
        elif line[0] == '#':
            fs = line.split()
            code = int(fs[3][5:], 16)
            print code
        else:
            ms = [float(x) for x in line.split(',')][1::2]
            if mode == 0: ms = [float(line)]
            mean = nm.mean(ms)
            error = nm.std(ms)

            if error > largeError:
                largeError = error
                largeErrorI = code
                largeErrorMS = ms

            gr1.SetPoint(code, code, mean)
            gr1.SetPointError(code, 0, error)

    print largeErrorI, largeErrorMS, nm.mean(largeErrorMS), nm.mean(ms)
    for i in range(len(largeErrorMS)):
        gr4.SetPoint(i, i, largeErrorMS[i])

    N = gr1.GetN()
    Ys = gr1.GetY()
    print Ys[0], Ys[N - 1], Ys[largeErrorI]
    LSB = (Ys[N - 1] - Ys[0]) / (N - 1)
    print LSB
    for i in range(N):
        gr2.SetPoint(i, i, Ys[i] - (Ys[0] + i * LSB))
        gr3.SetPoint(i, i, Ys[i] - Ys[i - 1] - LSB if i > 0 else 0)

    line = TLine()
    lt = TLatex()

    cav1 = TCanvas('cav1', 'cav1', 1000, 800)
    cav1.Divide(2, 2)
    cav1.cd(1)
    gr1.Draw('AP')
    h1 = gr1.GetHistogram()
    h1.GetXaxis().SetTitle('Code')
    h1.GetYaxis().SetTitle('U [V]')
    ln1 = line.DrawLine(0, Ys[0], N - 1, Ys[N - 1])
    ln1.SetLineColor(2)

    rgInfo = '[{0:.2g},{1:.2g}] V'.format(Ys[0], Ys[N - 1])
    if Infox:
        rgInfo = Infox + ': ' + rgInfo
    lt.DrawLatexNDC(0.2, 0.85, rgInfo)

    cav1.cd(2)
    gr4.SetMarkerStyle(20)
    gr4.Draw('AP')
    h4 = gr4.GetHistogram()
    h4.GetXaxis().SetTitle('#it{i}th')
    h4.GetYaxis().SetTitle('U [V]')
    lt.DrawLatexNDC(
        0.2, 0.85,
        "{0:d} measurements for code={1:d}".format(len(largeErrorMS),
                                                   largeErrorI))

    cav1.cd(3)
    gr2.SetFillColor(2)
    gr2.Draw('APB')
    h2 = gr2.GetHistogram()
    h2.GetXaxis().SetTitle('Code')
    h2.GetYaxis().SetTitle('INL [V]')

    lY = LSB if gr2.GetMean(2) > 0 else -LSB
    ln2 = line.DrawLine(0, lY, N, lY)
    ln2.SetLineStyle(2)

    lt.DrawLatexNDC(
        0.6, 0.85,
        "Max INL={0:.1f} LSB".format(max([abs(x) for x in gr2.GetY()]) / LSB))

    cav1.cd(4)
    gr3.SetFillColor(4)
    gr3.Draw('APB')
    h3 = gr3.GetHistogram()
    h3.GetXaxis().SetTitle('Code')
    h3.GetYaxis().SetTitle('DNL [V]')

    lY = LSB if gr3.GetMean(2) > 0 else -LSB
    ln3 = line.DrawLine(0, lY, N, lY)
    ln3.SetLineStyle(2)
    lt.DrawLatexNDC(
        0.6, 0.85,
        "Max DNL={0:.1f} LSB".format(max([abs(x) for x in gr3.GetY()]) / LSB))

    cav1.cd()
    waitRootCmdX(saveName)
示例#13
0
def MedianCharges():
    canvas = TCanvas("c1", "c1", 800, 600)

    gStyle.SetOptStat(0)  #hides stat table
    gStyle.SetOptTitle(0)

    thick = [25, 50, 100, 150, 200, 250, 270, 280, 290, 300, 310]
    nOfPoints = len(thick)

    #Allpix with CT
    chargesAllpix1 = [
        0.224, 0.468, 1.197, 1.864, 2.521, 3.193, 3.466, 3.592, 3.733, 3.863,
        3.991
    ]
    errorsAllpix1 = [0.063] + [0.002] * (nOfPoints - 1)

    #Allpix no CT
    chargesAllpix2 = [
        0.224, 0.504, 1.266, 1.961, 2.654, 3.361, 3.6479, 3.7848, 3.9223,
        4.058, 4.206
    ]
    errorsAllpix2 = [0.057] + [0.002] * (nOfPoints - 1)

    #Athena
    chargesAthena = [
        0.35, 0.731, 1.364, 1.949, 2.425, 2.809, 2.9257, 2.9877, 3.042, 3.093,
        3.141
    ]
    errorsAthena = [
        0.079, 0.001, 0.002, 0.002, 0.003, 0.003, 0.007, 0.007, 0.007, 0.007,
        0.007
    ]

    graphAllpix1 = TGraphErrors(nOfPoints)
    graphAllpix2 = TGraphErrors(nOfPoints)
    graphAthena = TGraphErrors(nOfPoints)

    for i in range(nOfPoints):
        graphAllpix1.SetPoint(i, thick[i], chargesAllpix1[i])
        graphAllpix1.SetPointError(i, 0, errorsAllpix1[i])
        graphAllpix2.SetPoint(i, thick[i], chargesAllpix2[i])
        graphAllpix2.SetPointError(i, 0, errorsAllpix2[i])
        graphAthena.SetPoint(i, thick[i], chargesAthena[i])
        graphAthena.SetPointError(i, 0, errorsAthena[i])

    graphAllpix1.SetMarkerSize(1)
    graphAllpix1.SetMarkerColor(2)
    graphAllpix1.SetMarkerStyle(22)
    graphAllpix1.GetXaxis().SetTitle("Active sensor thickness [#mum]")
    graphAllpix1.GetYaxis().SetTitle("Median charge [fC]")
    graphAllpix1.GetHistogram().SetMaximum(4.4)
    graphAllpix1.GetHistogram().SetMinimum(2.8)
    graphAllpix1.GetXaxis().SetLimits(260, 320)
    graphAllpix2.GetXaxis().SetLimits(0, 330)
    graphAthena.GetXaxis().SetLimits(0, 330)

    graphAllpix2.SetMarkerSize(1)
    graphAllpix2.SetMarkerColor(1)
    graphAllpix2.SetMarkerStyle(21)

    graphAthena.SetMarkerSize(1)
    graphAthena.SetMarkerColor(4)
    graphAthena.SetMarkerStyle(23)

    graphAllpix1.Draw("AP")
    graphAllpix2.Draw("sameP")
    graphAthena.Draw("sameP")

    graphAllpix1Func = TF1("graphAllpix1Func", "[0]*x+[1]", 0, 310)
    graphAllpix2Func = TF1("graphAllpix2Func", "[0]*x+[1]", 0, 310)
    graphAthenaFunc = TF1("graphAthenaFunc", "[0]*x+[1]", 240, 320)
    # graphAthenaFunc = TF1("graphAthenaFunc","[0]*x**2+[1]*x+[2]",0, 310)

    graphAllpix1Func.SetLineStyle(2)
    graphAllpix1Func.SetLineColor(2)
    graphAllpix2Func.SetLineStyle(2)
    graphAllpix2Func.SetLineColor(1)
    graphAthenaFunc.SetLineStyle(2)
    graphAthenaFunc.SetLineColor(4)

    graphAllpix1.Fit("graphAllpix1Func")
    graphAllpix2.Fit("graphAllpix2Func")
    graphAthena.Fit("graphAthenaFunc", "r")

    # textSize =
    legend = TLegend(0.13, 0.63, 0.33, 0.88)
    legend.SetBorderSize(0)
    # legend.SetTextSize(textSize)
    legend.AddEntry(graphAllpix2, "Allpix, no crosstalk", "p")
    legend.AddEntry(graphAllpix2Func, "Linear fit", "l")
    legend.AddEntry(graphAllpix1, "Allpix, crosstalk", "p")
    legend.AddEntry(graphAllpix1Func, "Linear fit", "l")
    legend.AddEntry(graphAthena, "Athena", "p")
    legend.AddEntry(graphAthenaFunc, "Linear fit", "l")

    legend.Draw("same")

    canvas.SaveAs("results/Thickness.pdf")
        gr_WW = TGraphErrors(4, X_PT, Fraction_WW, X_Error, Y_Error_WW)
        gr_WW.SetLineColor(3)
        gr_WW.SetLineWidth(1)
        gr_WW.SetLineStyle(1)
        gr_WW.SetMarkerColor(2)
        gr_WW.SetMarkerStyle(8)
        gr_WW.SetMarkerSize(1)
        #gr.GetXaxis().SetTitle("E[TeV]")
        #gr.GetXaxis().SetTitleColor(4)
        #gr.GetYaxis().SetTitle("<T_{delay>}")

        #gr_QQ.SetTitle("<T_{delay}>[ns] Vs E[TeV]")
        gr_QQ.Draw("ALP")
        gr_WW.Draw("LPsame")

        gr_QQ.GetHistogram().SetMaximum(1.2)
        gr_QQ.GetHistogram().SetMinimum(0)
        gr_QQ.GetXaxis().SetLimits(0, 2)
        gr_QQ.GetXaxis().CenterTitle()
        gr_QQ.GetYaxis().CenterTitle()

        #=================================
        leg1 = TLegend(0.15, 0.75, 0.35, 0.9)
        leg1.SetFillColor(0)
        leg1.SetFillStyle(0)
        leg1.SetTextSize(0.04)
        leg1.SetBorderSize(0)
        leg1.SetTextFont(22)
        leg1.AddEntry(
            gr_QQ, "Z'(" + str(Energy_List[Energy]) +
            "TeV)#rightarrowq#bar{q}#rightarrow1 subjet", "lp")
示例#15
0
gr4.SetMarkerColor(6)
gr4.SetMarkerStyle(8)
gr4.SetLineWidth(2)

gr5.SetLineStyle(1)
gr5.SetMarkerColor(7)
gr5.SetMarkerStyle(8)
gr5.SetLineWidth(2)

#gr.SetTitle(";mass[GeV] ;Log_{10}P  [GeV] ")
gr.SetTitle(";L[cm] ;p[GeV] ")
gr.GetXaxis().SetRangeUser(0, 200)
gr.GetYaxis().SetRangeUser(0, 14)

#====M vs P
gr.GetHistogram().SetMaximum(6)
gr.GetHistogram().SetMinimum(0)
#gr.GetXaxis().SetLimits(0,1000)
gr.GetXaxis().CenterTitle()
gr.GetYaxis().CenterTitle()
gr.GetXaxis().SetTitleOffset(1)
gr.GetYaxis().SetTitleOffset(1)

#================================
gr.GetYaxis().SetTitleSize(0.04)
gr.GetXaxis().SetTitleSize(0.04)
gr.GetXaxis().SetLabelSize(0.04)
gr.GetYaxis().SetLabelSize(0.04)
gr.GetXaxis().SetLabelFont(22)
gr.GetYaxis().SetLabelFont(22)
gr.GetXaxis().SetTitleColor(1)