resolutionError = sqrt( resolutionErrorSigma ** 2 +  resolutionErrorMean ** 2 )
    linearity = ( result.Get().Parameter(1) - energy ) / energy
    linearityError = result.Get().Error(1) / energy
    gRes.SetPoint(ifile, energy, resolution)
    gRes.SetPointError(ifile, 0, resolutionError)
    gLin.SetPoint(ifile, energy, linearity)
    gLin.SetPointError(ifile, 0, linearityError)

# Set properties of the graph
if filename.find("Bfield0") > 0:
    colour = kRed + 1 # red colour if no B field in the file name
else:
    colour = kBlue + 1 # blue otherwise (default)

if calo_init.args.roundBrackets:
    prepare_graph(gRes, "resolution", ";E_{beam} (GeV);#sigma_{E_{rec}}/#LTE_{rec}#GT", colour, 21)
else:
    prepare_graph(gRes, "resolution", ";E_{beam} [GeV];#sigma_{E_{rec}}/#LTE_{rec}#GT", colour, 21)
factor=2 # meaning the upper plot is twice smaller than the bottom plot
prepare_second_graph(gLin, gRes, "linearity", ";E_{beam} [GeV];(#LTE_{rec}#GT-E_{beam})/E_{beam}", factor)
gLin.GetYaxis().SetRangeUser(-0.9,0.9)

# Prepare canvas
if not calo_init.args.noLinearity:
    cRes, padRes, padLin = prepare_double_canvas("resolution","Energy resolution", factor)
    padRes.cd()
else:
    cRes = prepare_single_canvas("resolution","Energy resolution")
    cRes.cd()

# Fit energy resolution
        resultPre = h.Fit(fitPre, fitoptions)
        fit = TF1("fit","gaus",resultPre.Get().Parameter(1) - 2. * resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + 2. * resultPre.Get().Parameter(2) )
        result = h.Fit(fit, fitoptions)
        if result and result.Ndf() > 0:
            # if it fits terribly, try to fit in narrower range
            if result.Chi2() / result.Ndf() > 10:
                refit = TF1("refit","gaus",resultPre.Get().Parameter(1) - resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + resultPre.Get().Parameter(2) )
                result = h.Fit(refit, fitoptions)
        if calo_init.args.preview:
            cPreview.cd(islice + 1)
            draw_1histogram(h,"","")
        # make graph
        if result:
            gSF.SetPoint(islice, sliceSum[islice]-sliceWidth[islice]*0.5, result.Get().Parameter(1))
            gSF.SetPointError(islice, sliceWidth[islice]*0.5 , result.Get().Parameter(2))
    prepare_graph(gSF, 'sf_'+str(len(merge))+'layers', ';radial depth [cm];sampling fraction', ifile+9)
    all_graphs.append(gSF)
    graphTitles.append('#color['+str(colour[ifile])+']{'+str(energy)+' GeV e^{-}}')
    print("samplFractMap ["+str(energy)+"]= ", end='')
    for islice in range(0, Nslicesmerged):
        if islice == 0:
            print("{ ", end='')
        if islice > 0:
            print(", ", end='')
        print(str(gSF.GetY()[islice]), end='')
    print("};")


canv = prepare_single_canvas('sf_e'+str(energy)+'GeV', 'Sampling fraction for '+str(energy)+'GeV')

# Draw graph and all labels
Esempio n. 3
0
                    calo_init.output(ifile) + "_previewPhi_eta" + str(eta) +
                    ".png")
            else:
                canvPhi.SaveAs("upstremCorrection_previewPhi_eta" + str(eta) +
                               "_" + str(layer * width) + "cm.png")

    # fit energy-dependent parameters
    fitP0 = TF1("fitP0", "pol1", 0, energy)
    par0result = param0.Fit(fitP0, "SR")
    fitP1 = TF1("fitP1", "[0]+[1]/sqrt(x)", 0, energy)
    par1result = param1.Fit(fitP1, "SR")
    cEnergy = prepare_divided_canvas(
        'upstreamParams_eta' + str(eta),
        'Energy upstream E=p0+p1E for eta=' + str(eta), 2)
    cEnergy.cd(1)
    prepare_graph(param0, "param0", 'P0 (E);' + axisName + '; parameter P0')
    param0.Draw("aep")
    param0.GetYaxis().SetRangeUser(param0.GetYaxis().GetXmin(),
                                   param0.GetYaxis().GetXmax() * 1.2)
    cEnergy.cd(2)
    prepare_graph(param1, "param1", 'P1 (E);' + axisName + '; parameter P1')
    param1.Draw("aep")
    param1.GetYaxis().SetRangeUser(param1.GetYaxis().GetXmin(),
                                   param1.GetYaxis().GetXmax() * 1.2)
    cEnergy.Update()

    # fill energy-dependent graphs
    par0par0.SetPoint(ieta, eta, par0result.Get().Parameter(0))
    par0par0.SetPointError(ieta, etaWidth, par0result.Get().Error(0))
    par0par1.SetPoint(ieta, eta, par0result.Get().Parameter(1))
    par0par1.SetPointError(ieta, etaWidth, par0result.Get().Error(1))
            cPreview.cd(islice + 1)
            draw_1histogram(h,"","")
        # make graph
        if result:
            if islice < len(merge) - 1:
                gSF.SetPoint(islice, (merge[islice] + 0.5 * (merge[islice + 1] - merge[islice])) * sliceWidth, result.Get().Parameter(1))
                gSF.SetPointError(islice, 0.5 * (merge[islice + 1] - merge[islice]) * sliceWidth , result.Get().Parameter(2))
            else:
                gSF.SetPoint(islice, (merge[islice] + 0.5 * (merge[islice] - merge[islice - 1])) * sliceWidth, result.Get().Parameter(1))
                gSF.SetPointError(islice, 0.5 * (merge[islice] - merge[islice - 1]) * sliceWidth , result.Get().Parameter(2))
    all_graphs.append(gSF)

canv = prepare_single_canvas('sf_e'+str(energy)+'GeV', 'Sampling fraction for '+str(energy)+'GeV')

# Draw graph and all labels
prepare_graph(gSF, 'sf_'+str(len(merge))+'layers', ';radial depth;sampling fraction', ifile+9)
all_graphs[0].Draw("ape")
for g in all_graphs[1:]:
    g.Draw("pe")
if calo_init.args.axisMax:
    all_graphs[0].SetMaximum(calo_init.args.axisMax)
if calo_init.args.axisMin:
    all_graphs[0].SetMinimum(calo_init.args.axisMin)
canv.Update()

lines = []
for iLine, line in enumerate(avgSF):
    lines.append(TLine(0, avgSF[iLine], Nslices * sliceWidth, avgSF[iLine]))
    lines[iLine].SetLineColor(iLine+1)
    lines[iLine].Draw('same')
Esempio n. 5
0
P01 = [0.0004518, 0.0004978, 0.0006698, 0.0009367, 0.00138, 0.00211, 0.003343]
P10 = [4.426, 4.312, 4.021, 3.68, 3.324, 2.754, 2.211]
P11 = [2.466, 4.068, 4.132, 6.176, 10.52, 14.62, 22.18]

from ROOT import TCanvas, TGraphErrors
from draw_functions import prepare_graph, prepare_divided_canvas,  prepare_single_canvas, draw_text, draw_1histogram

c = prepare_divided_canvas( 'etaParameters', 'Upstream energy correction parameters E_{upstream}=(p00(#eta)+p01(#eta)#cdot E) + (p10(#eta)+ p11(#eta)/#sqrt{E})#cdot E', 4 )
g00 = TGraphErrors()
g01 = TGraphErrors()
g10 = TGraphErrors()
g11 = TGraphErrors()
for i in range(0,len(eta)):
    g00.SetPoint(i,eta[i],P00[i])
    g00.SetPointError(i,0.125,0)
    g01.SetPoint(i,eta[i],P01[i])
    g01.SetPointError(i,0.125,0)
    g10.SetPoint(i,eta[i],P10[i])
    g10.SetPointError(i,0.125,0)
    g11.SetPoint(i,eta[i],P11[i])
    g11.SetPointError(i,0.125,0)
graphs = [g00, g01, g10, g11]
parTitles = ['P00', 'P01', 'P10', 'P11']
for igraph, g in enumerate(graphs):
    pad = c.cd(igraph + 1)
    prepare_graph(g, parTitles[igraph], parTitles[igraph]+'(#eta);#eta; parameter '+parTitles[igraph])
    g.GetXaxis().SetRangeUser(0,eta[len(eta)-1]+0.125)
    g.Draw("aep")
c.Update()
input("")
        elif len(calo_init.filenamesIn) == 5:
            colour = ['#4aa7bf','#4c90c0','#4f62c4','#5851c6','#8d55c9']
        elif len(calo_init.filenamesIn) == 3:
            colour = ['#4aa7bf','#4f62c4','#8d55c9']
        elif len(calo_init.filenamesIn) == 2:
            colour = ['#4aa7bf','#8d55c9']
        else:
            exit()
        colour = [TColor.GetColor(c) for c in colour]
else:
    colour = [c for c in range(1,100)]
    colour = [TColor.GetColor(c) for c in colour]
minima=[]
maxima=[]
for i,g in enumerate(graphsRes):
    prepare_graph(g, g.GetName(), g.GetTitle(), colour[i])
    g.GetFunction("res").SetLineColor(colour[i])
    minima.append(g.GetYaxis().GetXmin())
    maxima.append(g.GetYaxis().GetXmax())
if calo_init.args.axisMax:
    graphsRes[0].GetYaxis().SetRangeUser(calo_init.args.axisMin, calo_init.args.axisMax)
else:
    graphsRes[0].GetYaxis().SetRangeUser(0.8*min(minima),0.55*max(maxima))
if not calo_init.args.noLinearity:
    for gLin, gRes in zip(graphsLin, graphsRes):
        prepare_second_graph(gLin, gRes, gLin.GetName(), gLin.GetTitle(), factor)

# Draw graphs
graphsRes[0].Draw("aep")
for g in graphsRes[1:]:
    g.Draw("sameep")
            canvProfile.Update()
            canvPhi.Update()
            # save canvases filled for each energy and eta
            if calo_init.output(ifile):
                canvPhi.SaveAs(calo_init.output(ifile) + "_previewPhi_eta" + str(eta) + ".png")
            else:
                canvPhi.SaveAs("upstremCorrection_previewPhi_eta"+str(eta)+"_"+str(layer*width)+"cm.png")

    # fit energy-dependent parameters
    fitP0 = TF1("fitP0","pol1", 0, energy)
    par0result = param0.Fit(fitP0, "SR")
    fitP1 = TF1("fitP1","[0]+[1]/sqrt(x)", 0, energy)
    par1result = param1.Fit(fitP1, "SR")
    cEnergy = prepare_divided_canvas('upstreamParams_eta'+str(eta), 'Energy upstream E=p0+p1E for eta='+str(eta), 2)
    cEnergy.cd(1)
    prepare_graph(param0, "param0", 'P0 (E);'+axisName+'; parameter P0')
    param0.Draw("aep")
    param0.GetYaxis().SetRangeUser(param0.GetYaxis().GetXmin(), param0.GetYaxis().GetXmax() * 1.2)
    cEnergy.cd(2)
    prepare_graph(param1, "param1", 'P1 (E);'+axisName+'; parameter P1')
    param1.Draw("aep")
    param1.GetYaxis().SetRangeUser(param1.GetYaxis().GetXmin(), param1.GetYaxis().GetXmax() * 1.2)
    cEnergy.Update()

    # fill energy-dependent graphs
    par0par0.SetPoint(ieta,eta,par0result.Get().Parameter(0))
    par0par0.SetPointError(ieta,etaWidth,par0result.Get().Error(0))
    par0par1.SetPoint(ieta,eta,par0result.Get().Parameter(1))
    par0par1.SetPointError(ieta,etaWidth,par0result.Get().Error(1))
    par1par0.SetPoint(ieta,eta,par1result.Get().Parameter(0))
    par1par0.SetPointError(ieta,etaWidth,par1result.Get().Error(0))
Esempio n. 8
0
        ]
        colour = [colour[len(colour) - i - 1] for i, c in enumerate(colour)]
        colour = [TColor.GetColor(c) for c in colour]
    else:
        colour = [
            '#4aa7bf', '#4c90c0', '#4d79c2', '#4f62c4', '#5851c6', '#7253c7',
            '#8d55c9'
        ]
        colour = [TColor.GetColor(c) for c in colour]
else:
    colour = [c for c in range(1, 100)]
print(colour)
minima = []
maxima = []
for i, g in enumerate(graphsRes):
    prepare_graph(g, g.GetName(), g.GetTitle(), colour[i])
    g.GetFunction("res").SetLineColor(colour[i])
    minima.append(g.GetYaxis().GetXmin())
    maxima.append(g.GetYaxis().GetXmax())
if calo_init.args.axisMax:
    graphsRes[0].GetYaxis().SetRangeUser(0, calo_init.args.axisMax)
else:
    graphsRes[0].GetYaxis().SetRangeUser(0.8 * min(minima), 0.55 * max(maxima))
if not calo_init.args.noLinearity:
    for gLin, gRes in zip(graphsLin, graphsRes):
        prepare_second_graph(gLin, gRes, gLin.GetName(), gLin.GetTitle(),
                             factor)

# Draw graphs
graphsRes[0].Draw("aep")
for g in graphsRes[1:]: