Exemplo n.º 1
0
def DrawEfficiencyCluster(file_names, output_name, ref_file=""):
    """A function to plot efficiency and cluster size.
    
    Parameters
    ----------
    file_names : list
        List with file names
    output_name : str
        File name of the produced output file
    ref_file : str
        Optional name of the file with reference results
    """

    file_paths = ["data/" + file_name for file_name in file_names]
    input_files = [TFile(file_path, "r") for file_path in file_paths]

    eff = [input_file.Get("Efficiency") for input_file in input_files]
    clus = [
        input_file.Get("Average_cluster_size") for input_file in input_files
    ]
    titles = [
        str(input_file.Get("Info").Get("title")) for input_file in input_files
    ]

    # Create a legend
    legendHeight = 0.13 * len(eff)
    if not ref_file: legendHeight += 0.13
    legend = TLegend(0.5, 1 - legendHeight, 0.85, 0.85)
    legend.SetTextSize(0.03)
    legend.SetBorderSize(0)

    canvas = TCanvas("canvas1", "canvas1", 800, 600)
    for i in range(len(eff)):
        if i == 0:
            eff[i].Draw()
        else:
            eff[i].Draw("same")
        eff[i].SetLineColor(i + 1)
        eff[i].GetListOfFunctions().FindObject("Efficiency_fit").SetLineColor(
            i + 1)
        legend.AddEntry(eff[i], titles[i], "l")
    if ref_file:
        eff_ref = TFile("data/" +
                        ref_file).Get("efficiency_vs_threshold_time_corrected")
        eff_ref.SetMarkerStyle(2)
        eff_ref.SetLineColor(51)
        eff_ref.SetMarkerColor(51)
        eff_ref.GetListOfFunctions().FindObject("erfcFit_timing").SetLineColor(
            51)
        eff_ref.Draw("PEsame")
        legend.AddEntry(eff_ref, "test beam", "l")
    legend.Draw("same")
    canvas.SaveAs("results/" + output_name + "_eff.pdf")

    canvas = TCanvas("canvas2", "canvas2", 800, 600)
    for i in range(len(clus)):
        if i == 0:
            clus[i].Draw()
        else:
            clus[i].Draw("same")
        clus[i].SetLineColor(i + 1)
    if ref_file:
        clus_ref = TFile("data/" + ref_file).Get("cluster_size_vs_threshold")
        clus_ref.SetLineColor(51)
        clus_ref.Draw("same")
    legend.Draw("same")
    canvas.SaveAs("results/" + output_name + "_clus.pdf")
Exemplo n.º 2
0
for ev in range(nevents2):
    fChain2.GetEntry(ev)
    for i in range(NSCA):
        TS[i] = HITS.rollposition[i]
        for hit in range(nhits):
            H=HITS2.Hits.at(nhits2)
            if(H.CCorNC ==0):
                continue
            if(H.chip == 0 and H.ch == 20):
                if(TS[i]<9):
                    h_Charge.Fill(H.SCA_hg[0]-Ped_Mean)

h_Charge.Fit(Full_Gaussian2,"R")
Char_Chi=Full_Gaussian2.GetChisquare()
Char_NDF=Full_Gaussian2.GetNDF()
Char_Degree_part2=Char_Chi/Char_NDF
Char_Mean=Full_Gaussian2.GetParameter(1)
Char_Error=Full_Gaussian2.GetParameter(2)

leg = TLegend(0.1,0.4,0.5,0.8)
leg.SetFillColor(0)
leg.SetFillStyle(0)
leg.SetTextSize(0.05)
leg.SetTextFont(22)
leg.SetBorderSize(0)

h_Charge.Draw()
leg.Draw()
c2.Print("HG_Chip0_SCA0_channel20.pdf")