Exemple #1
0
                                 calo_init.args.fitRangeUp[ifile])
                print("fitting in range: ", 0,
                      calo_init.args.fitRangeUp[ifile])
        else:
            fitProfile = TF1("fitProfile", "pol1", 0, energy)
        result = hUpstremCellProfile.Fit(fitProfile, "SNR")

        # fill energy-dependent graphs
        param0.SetPoint(ifile, energyGraph, result.Get().Parameter(0))
        param0.SetPointError(ifile, energyErrorGraph, result.Get().Error(0))
        param1.SetPoint(ifile, energyGraph, result.Get().Parameter(1))
        param1.SetPointError(ifile, energyErrorGraph, result.Get().Error(1))

        if calo_init.args.preview:
            canvProfile = prepare_single_canvas(
                'upstreamEnergy_e' + str(energy) + 'GeV_eta' + str(eta),
                'Upstream energy vs energy in first layer for #eta = ' +
                str(eta))
            draw_1histogram(hUpstremCellProfile,
                            'E_{firstLayer} ' + energyUnit,
                            'upstream energy ' + energyUnit)
            hUpstremCellProfile.Fit(fitProfile, "SR")
            for ibin in reversed(
                    range(0,
                          hUpstremCellProfile.GetXaxis().GetNbins())):
                if hUpstremCellProfile.GetBinContent(ibin) > 0:
                    lastNonEmpty = ibin
                    break
            hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3)
            legendProfile = draw_text([str(energy) + ' GeV e^{-}, B = 4T'],
                                      [0.67, 0.18, 0.85, 0.28], 9, 0)
            legendProfile.SetTextSize(0.05)
    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
fRes = TF1("res", "sqrt([0]*[0] + pow([1]/sqrt(x),2))",5,600)
fRes.SetParName(0,"const")
fRes.SetParName(1,"sqrt")
fRes.SetLineColor(colour)
fitResult = gRes.Fit(fRes, 'S')

# Draw graph and all labels
gRes.Draw("ape")
if calo_init.args.axisMax:
    gRes.GetYaxis().SetRangeUser(0, calo_init.args.axisMax)
formula = "#frac{#sigma_{E}}{E} = " + str(round(fitResult.Get().Parameter(0)*100,2))+"% #oplus #frac{"+str(round(fitResult.Get().Parameter(1)*100,2))+"%}{#sqrt{E}}"
if not calo_init.args.noLinearity:
            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
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], 65, avgSF[iLine]))
                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:
            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]))
from ROOT import gSystem, gROOT, TCanvas, TGraphErrors, TF1, gStyle, kRed, kBlue, kGray, TFile, TTree, TPad, TGaxis, gPad, TLine, kOrange, kGreen, SetOwnership
from draw_functions import prepare_histogram, prepare_divided_canvas,  prepare_single_canvas, draw_text, draw_1histogram
import numpy
gStyle.SetOptFit(0)
gStyle.SetOptStat(0)

colours = [ kRed + 2, 8, kGray + 3 , kOrange + 1 , 8, 9]
coloursFit = [kRed, kGreen+2, kGray+3, kOrange + 2 , kGreen + 2, kBlue + 2]

if len(calo_init.energies) > 1:
    print("Plotting of the enrgy distribution can be performed only for one energy value")
    exit()

energy = calo_init.energy(0)
canv = prepare_single_canvas( 'energyDistribution_'+str(energy)+'GeV', 'Energy distribution for '+str(energy)+'GeV' )
canv.cd()
energy = calo_init.energy(0)
resolution_list = []
mean_list = []
# files represent different types for the same particle energy:
for ifile, filename in enumerate(calo_init.filenamesIn):
    f = TFile(filename, "READ")
    hEn = f.Get(histogramNames[ifile])
    hEn.Sumw2()
    if hEn.GetEntries() > 0:
        hEn.Scale(1./hEn.GetEntries())
    hEn.Rebin(4)
    hEn.SetTitle('')
    if calo_init.args.axisMax:
        hEn.GetYaxis().SetRangeUser(0, calo_init.args.axisMax)
                print("fitting in range: ", calo_init.args.fitRangeDown[ifile], calo_init.args.fitRangeUp[ifile])
            else:
                fitProfile = TF1("fitProfile","pol1", 0, calo_init.args.fitRangeUp[ifile])
                print("fitting in range: ", 0, calo_init.args.fitRangeUp[ifile])
        else:
            fitProfile = TF1("fitProfile","pol1", 0, energy)
        result = hUpstremCellProfile.Fit(fitProfile, "SNR")

        # fill energy-dependent graphs
        param0.SetPoint(ifile,energyGraph,result.Get().Parameter(0))
        param0.SetPointError(ifile,energyErrorGraph,result.Get().Error(0))
        param1.SetPoint(ifile,energyGraph,result.Get().Parameter(1))
        param1.SetPointError(ifile,energyErrorGraph,result.Get().Error(1))

        if calo_init.args.preview:
            canvProfile = prepare_single_canvas( 'upstreamEnergy_e'+str(energy)+'GeV_eta'+str(eta), 'Upstream energy vs energy in first layer for #eta = '+str(eta))
            draw_1histogram(hUpstremCellProfile, 'E_{firstLayer} '+energyUnit,'upstream energy '+energyUnit)
            hUpstremCellProfile.Fit(fitProfile, "SR")
            for ibin in reversed(range(0,hUpstremCellProfile.GetXaxis().GetNbins())):
                if hUpstremCellProfile.GetBinContent(ibin) > 0:
                    lastNonEmpty = ibin
                    break
            hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3)
            legendProfile = draw_text([str(energy)+' GeV e^{-}, B = 4T'], [0.67,0.18, 0.85,0.28], 9, 0)
            legendProfile.SetTextSize(0.05)
            legendProfile.SetTextFont(42)
            canvProfile.Update()
            # save canvases filled for each energy and eta
            if calo_init.output(ifile):
                canvProfile.SaveAs(calo_init.output(ifile) + "_previewProfile_eta" + str(eta) + "_e"+str(energy)+"GeV.png")
            else:
Exemple #7
0
import numpy

gStyle.SetOptFit(0)
gStyle.SetOptStat(0)

colours = [kRed + 2, 8, kGray + 3, kOrange + 1, 8, 9]
coloursFit = [kRed, kGreen + 2, kGray + 3, kOrange + 2, kGreen + 2, kBlue + 2]

if len(calo_init.energies) > 1:
    print(
        "Plotting of the enrgy distribution can be performed only for one energy value"
    )
    exit()

energy = calo_init.energy(0)
canv = prepare_single_canvas('energyDistribution_' + str(energy) + 'GeV',
                             'Energy distribution for ' + str(energy) + 'GeV')
canv.cd()
energy = calo_init.energy(0)
resolution_list = []
mean_list = []
# files represent different types for the same particle energy:
for ifile, filename in enumerate(calo_init.filenamesIn):
    f = TFile(filename, "READ")
    hEn = f.Get(histogramNames[ifile])
    hEn.Sumw2()
    if hEn.GetEntries() > 0:
        hEn.Scale(1. / hEn.GetEntries())
    hEn.Rebin(4)
    hEn.SetTitle('')
    if calo_init.args.axisMax:
        hEn.GetYaxis().SetRangeUser(0, calo_init.args.axisMax)