Exemplo n.º 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()
Exemplo n.º 2
0
def test():
    from ROOT import TH1F, TGraph, TCanvas, TF1, Double
    from rootUtil import waitRootCmdX, useAtlasStyle
    useAtlasStyle()

    s1 = sampler((0.05, 0.8), 15)
    #     s1.funX = lambda x:0.5*(1+math.erf((x-0.4)/0.04))
    s1.funX = lambda x: 1. if random.random() < 0.5 * (1. + math.erf(
        (x - 0.4) / 0.04)) else 0.
    s1.funY = lambda x: math.sqrt(x * (1. - x))
    #     s1.funY = lambda x:x*(1.-x)/6.
    for i in range(10):
        print s1.funY(0.1 * i)
    print s1.next()

    s1.sFactor = 20

    NEVT = 700
    h1 = TH1F('h1', 'h1;x;Events', 100, 0., 1)
    #     h1 = TH1F('h1','h1;x;Events',NEVT,0,NEVT)
    g1 = TGraph()
    for i in range(NEVT):
        #         h1.Fill(s1.next())
        h1.Fill(s1.generate())
        #         h1.Fill(s1.totalP())
        g1.SetPoint(i, i, s1.totalP())
    s1.show()

    c1 = TCanvas()
    c1.Divide(2)
    c1.cd(1)
    h1.Draw()
    mx, mn = Double(0), Double(0)
    h1.GetMinimumAndMaximum(mn, mx)
    print mx, mn
    fun1 = TF1('fun1',
               '{0:.1f}*TMath::Gaus(x,0.4,0.04/TMath::Sqrt(2))'.format(mx), 0,
               1)
    fun1.SetLineColor(2)
    fun1.Draw('same')
    c1.cd(2)
    g1.Draw('AP')
    c1.cd()

    waitRootCmdX()
    ch2.SetLineColor(4)
    ch2.SetLineStyle(2)
    ch2.SetMarkerColor(4)
    ch2.SetMarkerSize(0.8)
    ch2.SetMarkerStyle(25)

    gStyle.SetOptStat(0)
    gStyle.SetPadTickX(1)
    gStyle.SetPadTickY(1)
    colorful = bcolors()
    #colorful.disable()

    addAlias(ch1)
    addAlias(ch2)
    plotRatio = True
    useAtlasStyle()

    def runRoot(cmd):
        try:
            gROOT.ProcessLine(cmd)
        except RuntimeError as e:
            print colorful.FAIL, e, colorful.ENDC
            return False
        return True

    def colorOutChi2(value):
        colorcode = colorful.OKGREEN
        if value < 0.3173: colorcode = colorful.OKBLUE
        if value < 0.0455: colorcode = colorful.WARNING
        if value < 0.0027: colorcode = colorful.FAIL
        return [colorcode + 'Chi2 Test: ' + colorful.ENDC + '{0:.2g}'.format(value), '#chi^{2} test: '+'{0:.2g}'.format(value)]
Exemplo n.º 4
0
        fun2.Draw('same')

        lg = TLegend(0.7, 0.4, 0.95, 0.5)
        lg.SetFillStyle(0)
        lg.AddEntry(p1, 'Measurement', 'p')
        lg.AddEntry(fun1a, 'Fit', 'l')
        lg.AddEntry(fun2, 'Gaus', 'l')
        lg.Draw()

        waitRootCmdX()


def test1A():
    dir1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/'
    enc1 = encChecker()
    #     enc1.dataFiles = [dir1+'ENC_0504_Chip5Col12_scan_sub-3v.dat']
    #     enc1.Info = 'sub: -3 V'
    #     enc1.dataFiles = [dir1+'ENC_0504_Chip5Col12_scan_sub-4v_bias1.dat']
    #     enc1.Info = 'sub: -4 V (bias1)'
    enc1.dataFiles = [dir1 + 'ENC_0504_Chip5Col12_scan_sub-3v_bias2.dat']
    enc1.Info = 'sub: -3 V (bias2)'

    enc1.showENC()


if __name__ == '__main__':
    useAtlasStyle()
    #     showENC()
    #     test1A()
    showDecay()