Example #1
0
def Read_Current(config):

    header, config_file = ConfigReader.open(config)

    pool = mp.Pool()
    output = pool.map_async(_read_current, config_file)
    pool.close()
    pool.join()

    output_data = output.get()

    return {key: value for key, value in output_data}
def Get_Time_Resolution(
    config,
    CFD="20",
    scope=None,
    trig_name=None,
    run_number=None,
    trig_cali="default",
    *,
    get_histo=True,
    xmin=None,
    xmax=None,
    nbin=None,
):

    ROOT.gROOT.SetBatch(True)
    ROOT.gStyle.SetOptFit(1)

    header, config_file = ConfigReader.open(config)

    # getting trigger time resolution information
    if header["trigger_res"] != "NA":
        trig_res = header["trigger_res"]
        trig_res_err = header["trigger_res_err"]
        trig_var = header["trigger_var"]
    else:
        trig_cali_run = sorted(list(TRIG_CALI.keys()))
        use_cali_run = None
        for i in range(len(trig_cali_run)):
            try:
                if trig_cali_run[i] <= run_number:
                    use_cali_run = trig_cali_run[i]
            except:
                pass
        if use_cali_run:
            trig_info = TRIG_CALI[use_cali_run]
            try:
                trig_res = trig_info[(scope, trig_name, trig_cali)]["res"]
                trig_res_err = trig_info[(scope, trig_name,
                                          trig_cali)]["res_err"]
                trig_var = trig_info[(scope, trig_name, trig_cali)]["var"]
            except KeyError:
                log.warning(
                    f"{(scope, trig_name, trig_cali)} is not in cali {use_cali_run}"
                )
                trig_res = 17.0
                trig_res_err = 1.0
                trig_var = "cfd3[20]"
        else:
            log.warning("Cannot match trigger calibration run number.")
            trig_res = 17.0
            trig_res_err = 1.0
            trig_var = "cfd3[20]"

    log.info(f"Trigger info: {trig_res}+-{trig_res_err}, var {trig_var}")

    output = {}
    for runIndex, run in enumerate(config_file):

        if run_number:
            run_num = run_number
        else:
            run_num = run.file_name.split("Sr_Run")[1].split("_")[0]

        result = Get_Time_Diff(
            run.file_name,
            run.cuts,
            CFD,
            run.dut_ch,
            trig_var.format(trig_ch=run.trig_ch),
            return_histo=get_histo,
            xmin=xmin,
            xmax=xmax,
            nbin=nbin,
        )

        if result is None:
            return None

        if result["sigma"] < 1:
            result = Get_Time_Diff(
                run.file_name,
                run.cuts,
                CFD,
                run.dut_ch,
                trig_var.format(trig_ch=run.trig_ch),
                return_histo=get_histo,
                xmin=1,
                xmax=1,
                nbin=100,
            )

        # saving plots
        c = ROOT.TCanvas(f"c{runIndex}")
        c.cd()
        result["histo"].Draw()

        if not os.path.exists(f"plots.{run.file_name}/"):
            os.makedirs(f"plots.{run.file_name}/")

        c.SaveAs(
            f"plots.{run.file_name}/bias_{run.bias}_temp_{run.temperature}C_tdiff_CFD{CFD}.png"
        )

        dut_time_res, dut_time_res_err = Compute_Res(result["sigma"],
                                                     result["sigma_err"],
                                                     trig_res, trig_res_err)

        output[(run.bias, run.cycle)] = [
            run_num,
            run.temperature,
            run.bias,
            dut_time_res,
            dut_time_res_err,
            run.cycle,
        ]

    return output