Example #1
0
def analyze_raw_data(in_file_h5, start, stop):
    logging.info('Analyze raw data from word index ' + str(start) + ' to ' +
                 str(stop))
    n_hits = 0
    if not analysis_configuration['integrate']:
        histograming.reset()
    for iWord in range(start, stop, analysis_configuration['chunk_size']):
        if stop - start <= analysis_configuration['chunk_size']:
            stop_index = stop
        else:
            stop_index = iWord + analysis_configuration['chunk_size']
        try:
            logging.info('Take chunk from ' + str(iWord) + ' to ' +
                         str(stop_index))
            raw_data = in_file_h5.root.raw_data.read(iWord, stop_index)
            interpreter.interpret_raw_data(raw_data)  # interpret the raw data
            Nhits = interpreter.get_n_array_hits()
            histograming.add_hits(hits[0:Nhits], Nhits)
            n_hits += Nhits
        except tb.exceptions.NoSuchNodeError:
            logging.info('File in inconsistent state, omit hits')
        except tb.exceptions.HDF5ExtError:
            logging.info('File in inconsistent state, omit hits')

    occupancy = np.zeros(
        80 * 336 * histograming.get_n_parameters(), dtype=np.uint32
    )  # create linear array as it is created in histogram class
    histograming.get_occupancy(occupancy)
    occupancy_array = np.reshape(
        a=occupancy.view(),
        newshape=(80, 336, histograming.get_n_parameters()),
        order='F')  # make linear array to 3d array (col,row,parameter)
    occupancy_array = np.swapaxes(occupancy_array, 0, 1)
    occupancy_array_ma = np.ma.array(occupancy_array)[:, :, 0]
    plotting.plot_fancy_occupancy(occupancy_array_ma, z_max='median')
    #     plotting.plot_occupancy(occupancy_array_ma)
    error_counter_hist = np.zeros(16, dtype=np.uint32)
    interpreter.get_error_counters(error_counter_hist)
    plotting.plot_event_errors(error_counter_hist)

    rel_bcid_hist = np.empty(16, dtype=np.uint32)
    histograming.get_rel_bcid_hist(rel_bcid_hist)
    plotting.plot_relative_bcid(rel_bcid_hist)
    plt.pause(0.0001)
    return n_hits
def analyze_data(scan_data_filenames, ignore_columns, fei4b=False):
    logging.info("Analyzing and plotting results...")
    output_h5_filename = local_configuration['output_data_filename'] + '.h5'
    logging.info('Saving calibration in: %s' % output_h5_filename)

    if local_configuration['create_plots'] or local_configuration['create_result_plots']:
        output_pdf_filename = local_configuration['output_data_filename'] + '.pdf'
        logging.info('Saving plots in: %s' % output_pdf_filename)
        output_pdf = PdfPages(output_pdf_filename)

    # define output data structures
    mean_threshold_calibration = np.zeros(shape=(len(local_configuration['delays']),), dtype='<f8')  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_noise_calibration = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_noise_rms_calibration = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration = np.zeros(shape=(80, 336, len(local_configuration['delays'])), dtype='<f8')  # array to hold the analyzed data in ram
    noise_calibration = np.zeros_like(threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_calibration_1 = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration_1 = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration_1 = np.zeros_like(threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_calibration_2 = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration_2 = np.zeros_like(mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration_2 = np.zeros_like(threshold_calibration)  # array to hold the analyzed data in ram
    # initialize progress bar
    progress_bar = progressbar.ProgressBar(widgets=['', progressbar.Percentage(), ' ', progressbar.Bar(marker='*', left='|', right='|'), ' ', analysis_utils.ETA()], maxval=len(local_configuration['delays']), term_width=80)
    progress_bar.start()
    # loop over all delay values and analyze the corresponding data
    for delay_index, delay_value in enumerate(local_configuration['delays']):
        # interpret the raw data from the actual delay value
        raw_data_file = scan_data_filenames[delay_value]
        analyzed_data_file = raw_data_file[:-3] + '_interpreted.h5'
        analyze(raw_data_file=raw_data_file, analyzed_data_file=analyzed_data_file, fei4b=fei4b)

        scan_parameters = None
        with tb.openFile(analyzed_data_file, mode="r") as in_file_h5:
            # mask the not scanned columns for analysis and plotting
            mask = np.logical_or(mask_columns(pixel_array=in_file_h5.root.HistThresholdFitted[:], ignore_columns=ignore_columns), mask_pixel(steps=3, shift=0).T) == 0
            occupancy_masked = mask_columns(pixel_array=in_file_h5.root.HistOcc[:], ignore_columns=ignore_columns)
            thresholds_masked = np.ma.masked_array(in_file_h5.root.HistThresholdFitted[:], mask)
            noise_masked = np.ma.masked_array(in_file_h5.root.HistNoiseFitted[:], mask)
            # plot the threshold distribution and the s curves
            if local_configuration['create_plots']:
                plotting.plotThreeWay(hist=thresholds_masked * 55., title='Threshold Fitted for delay = ' + str(delay_value), x_axis_title='threshold [e]', filename=output_pdf)
                plotting.plot_relative_bcid(hist=in_file_h5.root.HistRelBcid[0:16], title='Relative BCID (former LVL1ID) for delay = ' + str(delay_value), filename=output_pdf)
                plotting.plot_event_errors(hist=in_file_h5.root.HistErrorCounter[:], title='Event status for delay = ' + str(delay_value), filename=output_pdf)
            meta_data_array = in_file_h5.root.meta_data[:]
            parameter_settings = analysis_utils.get_scan_parameter(meta_data_array=meta_data_array)
            scan_parameters = parameter_settings['PlsrDAC']
            if local_configuration['create_plots']:
                plotting.plot_scurves(occupancy_hist=occupancy_masked, title='S-Curves, delay ' + str(delay_value), scan_parameters=scan_parameters, scan_parameter_name='PlsrDAC', filename=output_pdf)
            # fill the calibration data arrays
            mean_threshold_calibration[delay_index] = np.ma.mean(thresholds_masked)
            mean_threshold_rms_calibration[delay_index] = np.ma.std(thresholds_masked)
            threshold_calibration[:, :, delay_index] = thresholds_masked.T
            mean_noise_calibration[delay_index] = np.ma.mean(noise_masked)
            mean_noise_rms_calibration[delay_index] = np.ma.std(noise_masked)
            noise_calibration[:, :, delay_index] = noise_masked.T

        # if activated analyze also the trigger seperately
        if local_configuration['analysis_two_trigger']:
            with tb.openFile(analyzed_data_file[:-3] + '_analyzed_1.h5', mode="r") as in_file_1_h5:
                with tb.openFile(analyzed_data_file[:-3] + '_analyzed_2.h5', mode="r") as in_file_2_h5:
                    # mask the not scanned columns for analysis and plotting
                    try:
                        occupancy_masked_1 = occupancy_masked = mask_columns(pixel_array=in_file_1_h5.root.HistOcc[:], ignore_columns=ignore_columns)
                        thresholds_masked_1 = np.ma.masked_array(in_file_1_h5.root.HistThresholdFitted[:], mask)
                        rel_bcid_1 = in_file_1_h5.root.HistRelBcid[0:16]
                    except tb.exceptions.NoSuchNodeError:
                        occupancy_masked_1 = np.zeros(shape=(336, 80, 2))
                        thresholds_masked_1 = np.zeros(shape=(336, 80))
                        rel_bcid_1 = np.zeros(shape=(16, ))
                    try:
                        occupancy_masked_2 = occupancy_masked = mask_columns(pixel_array=in_file_2_h5.root.HistOcc[:], ignore_columns=ignore_columns)
                        thresholds_masked_2 = np.ma.masked_array(in_file_2_h5.root.HistThresholdFitted[:], mask)
                        rel_bcid_2 = in_file_2_h5.root.HistRelBcid[0:16]
                    except tb.exceptions.NoSuchNodeError:
                        occupancy_masked_2 = np.zeros(shape=(336, 80, 2))
                        thresholds_masked_2 = np.zeros(shape=(336, 80))
                        rel_bcid_2 = np.zeros(shape=(16, ))
                    # plot the threshold distribution and the s curves
                    if local_configuration['create_plots']:
                        plotting.plotThreeWay(hist=thresholds_masked_1 * 55., title='Threshold Fitted for 1. trigger, delay ' + str(delay_value), x_axis_title='threshold [e]', filename=output_pdf)
                        plotting.plot_relative_bcid(hist=rel_bcid_1, title='Relative BCID (former LVL1ID) for 1. trigger, delay = ' + str(delay_value), filename=output_pdf)
                        plotting.plotThreeWay(hist=thresholds_masked_2 * 55., title='Threshold Fitted for 2. trigger, delay ' + str(delay_value), x_axis_title='threshold [e]', filename=output_pdf)
                        plotting.plot_relative_bcid(hist=rel_bcid_2, title='Relative BCID (former LVL1ID) for 2. trigger, delay = ' + str(delay_value), filename=output_pdf)
                    if local_configuration['create_plots']:
                        plotting.plot_scurves(occupancy_hist=occupancy_masked_1, title='S-Curves 1. trigger, delay ' + str(delay_value), scan_parameters=scan_parameters, scan_parameter_name='PlsrDAC', filename=output_pdf)
                        plotting.plot_scurves(occupancy_hist=occupancy_masked_2, title='S-Curves 2. trigger, delay ' + str(delay_value), scan_parameters=scan_parameters, scan_parameter_name='PlsrDAC', filename=output_pdf)
                    # fill the calibration data arrays
                    mean_threshold_calibration_1[delay_index] = np.ma.mean(thresholds_masked_1)
                    mean_threshold_rms_calibration_1[delay_index] = np.ma.std(thresholds_masked_1)
                    threshold_calibration_1[:, :, delay_index] = thresholds_masked_1.T
                    mean_threshold_calibration_2[delay_index] = np.ma.mean(thresholds_masked_2)
                    mean_threshold_rms_calibration_2[delay_index] = np.ma.std(thresholds_masked_2)
                    threshold_calibration_2[:, :, delay_index] = thresholds_masked_2.T
        progress_bar.update(delay_index)
    progress_bar.finish()

    # plot the parameter against delay plots
    if local_configuration['create_result_plots']:
        plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration * 55., title='Threshold as a function of the delay', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=False, filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration * 55., title='Threshold as a function of the delay', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=True, filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration * 55., title='Threshold as a function of the delay', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=False, filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration * 55., title='Threshold as a function of the delay', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=True, filename=output_pdf)
        if local_configuration['analysis_two_trigger']:
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration_1 * 55., title='Threshold as a function of the delay, 1. trigger', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=False, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration_1 * 55., title='Threshold as a function of the delay, 1. trigger', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=True, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration_1 * 55., title='Threshold as a function of the delay, 1. trigger', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=False, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration_1 * 55., title='Threshold as a function of the delay, 1. trigger', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=True, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration_2 * 55., title='Threshold as a function of the delay, 2. trigger', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=False, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_calibration_2 * 55., title='Threshold as a function of the delay, 2. trigger', x_label='delay [BCID]', y_label='Mean threshold [e]', log_x=True, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration_2 * 55., title='Threshold as a function of the delay, 2. trigger', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=False, filename=output_pdf)
            plotting.plot_scatter(x=local_configuration['delays'], y=mean_threshold_rms_calibration_2 * 55., title='Threshold as a function of the delay, 2. trigger', x_label='delay [BCID]', y_label='Threshold RMS [e]', log_x=True, filename=output_pdf)

        plotting.plot_scatter(x=local_configuration['delays'], y=mean_noise_calibration * 55., title='Noise as a function of the delay', x_label='delay [BCID]', y_label='Mean noise [e]', log_x=False, filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'], y=mean_noise_rms_calibration * 55., title='Noise as a function of the delay', x_label='delay [BCID]', y_label='Noise RMS [e]', log_x=False, filename=output_pdf)

    if local_configuration['create_plots'] or local_configuration['create_result_plots']:
        output_pdf.close()

    # store the calibration data into a hdf5 file as an easy to read table and as an array for quick data access
    with tb.openFile(output_h5_filename, mode="w") as out_file_h5:
        store_calibration_data_as_array(out_file_h5, mean_threshold_calibration, mean_threshold_rms_calibration, threshold_calibration, mean_noise_calibration, mean_noise_rms_calibration, noise_calibration)
        store_calibration_data_as_table(out_file_h5, mean_threshold_calibration, mean_threshold_rms_calibration, threshold_calibration, mean_noise_calibration, mean_noise_rms_calibration, noise_calibration)
Example #3
0
def analyze_data(scan_data_filenames, ignore_columns, fei4b=False):
    logging.info("Analyzing and plotting results...")
    output_h5_filename = local_configuration['output_data_filename'] + '.h5'
    logging.info('Saving calibration in: %s' % output_h5_filename)

    if local_configuration['create_plots'] or local_configuration[
            'create_result_plots']:
        output_pdf_filename = local_configuration[
            'output_data_filename'] + '.pdf'
        logging.info('Saving plots in: %s' % output_pdf_filename)
        output_pdf = PdfPages(output_pdf_filename)

    # define output data structures
    mean_threshold_calibration = np.zeros(
        shape=(len(local_configuration['delays']), ),
        dtype='<f8')  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_noise_calibration = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_noise_rms_calibration = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration = np.zeros(
        shape=(80, 336, len(local_configuration['delays'])),
        dtype='<f8')  # array to hold the analyzed data in ram
    noise_calibration = np.zeros_like(
        threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_calibration_1 = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration_1 = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration_1 = np.zeros_like(
        threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_calibration_2 = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    mean_threshold_rms_calibration_2 = np.zeros_like(
        mean_threshold_calibration)  # array to hold the analyzed data in ram
    threshold_calibration_2 = np.zeros_like(
        threshold_calibration)  # array to hold the analyzed data in ram
    # initialize progress bar
    progress_bar = progressbar.ProgressBar(widgets=[
        '',
        progressbar.Percentage(), ' ',
        progressbar.Bar(marker='*', left='|', right='|'), ' ',
        analysis_utils.ETA()
    ],
                                           maxval=len(
                                               local_configuration['delays']),
                                           term_width=80)
    progress_bar.start()
    # loop over all delay values and analyze the corresponding data
    for delay_index, delay_value in enumerate(local_configuration['delays']):
        # interpret the raw data from the actual delay value
        raw_data_file = scan_data_filenames[delay_value]
        analyzed_data_file = raw_data_file[:-3] + '_interpreted.h5'
        analyze(raw_data_file=raw_data_file,
                analyzed_data_file=analyzed_data_file,
                fei4b=fei4b)

        scan_parameters = None
        with tb.openFile(analyzed_data_file, mode="r") as in_file_h5:
            # mask the not scanned columns for analysis and plotting
            mask = np.logical_or(
                mask_columns(
                    pixel_array=in_file_h5.root.HistThresholdFitted[:],
                    ignore_columns=ignore_columns),
                mask_pixel(steps=3, shift=0).T) == 0
            occupancy_masked = mask_columns(
                pixel_array=in_file_h5.root.HistOcc[:],
                ignore_columns=ignore_columns)
            thresholds_masked = np.ma.masked_array(
                in_file_h5.root.HistThresholdFitted[:], mask)
            noise_masked = np.ma.masked_array(
                in_file_h5.root.HistNoiseFitted[:], mask)
            # plot the threshold distribution and the s curves
            if local_configuration['create_plots']:
                plotting.plotThreeWay(hist=thresholds_masked * 55.,
                                      title='Threshold Fitted for delay = ' +
                                      str(delay_value),
                                      x_axis_title='threshold [e]',
                                      filename=output_pdf)
                plotting.plot_relative_bcid(
                    hist=in_file_h5.root.HistRelBcid[0:16],
                    title='Relative BCID (former LVL1ID) for delay = ' +
                    str(delay_value),
                    filename=output_pdf)
                plotting.plot_event_errors(
                    hist=in_file_h5.root.HistErrorCounter[:],
                    title='Event status for delay = ' + str(delay_value),
                    filename=output_pdf)
            meta_data_array = in_file_h5.root.meta_data[:]
            parameter_settings = analysis_utils.get_scan_parameter(
                meta_data_array=meta_data_array)
            scan_parameters = parameter_settings['PlsrDAC']
            if local_configuration['create_plots']:
                plotting.plot_scurves(occupancy_hist=occupancy_masked,
                                      title='S-Curves, delay ' +
                                      str(delay_value),
                                      scan_parameters=scan_parameters,
                                      scan_parameter_name='PlsrDAC',
                                      filename=output_pdf)
            # fill the calibration data arrays
            mean_threshold_calibration[delay_index] = np.ma.mean(
                thresholds_masked)
            mean_threshold_rms_calibration[delay_index] = np.ma.std(
                thresholds_masked)
            threshold_calibration[:, :, delay_index] = thresholds_masked.T
            mean_noise_calibration[delay_index] = np.ma.mean(noise_masked)
            mean_noise_rms_calibration[delay_index] = np.ma.std(noise_masked)
            noise_calibration[:, :, delay_index] = noise_masked.T

        # if activated analyze also the trigger seperately
        if local_configuration['analysis_two_trigger']:
            with tb.openFile(analyzed_data_file[:-3] + '_analyzed_1.h5',
                             mode="r") as in_file_1_h5:
                with tb.openFile(analyzed_data_file[:-3] + '_analyzed_2.h5',
                                 mode="r") as in_file_2_h5:
                    # mask the not scanned columns for analysis and plotting
                    try:
                        occupancy_masked_1 = occupancy_masked = mask_columns(
                            pixel_array=in_file_1_h5.root.HistOcc[:],
                            ignore_columns=ignore_columns)
                        thresholds_masked_1 = np.ma.masked_array(
                            in_file_1_h5.root.HistThresholdFitted[:], mask)
                        rel_bcid_1 = in_file_1_h5.root.HistRelBcid[0:16]
                    except tb.exceptions.NoSuchNodeError:
                        occupancy_masked_1 = np.zeros(shape=(336, 80, 2))
                        thresholds_masked_1 = np.zeros(shape=(336, 80))
                        rel_bcid_1 = np.zeros(shape=(16, ))
                    try:
                        occupancy_masked_2 = occupancy_masked = mask_columns(
                            pixel_array=in_file_2_h5.root.HistOcc[:],
                            ignore_columns=ignore_columns)
                        thresholds_masked_2 = np.ma.masked_array(
                            in_file_2_h5.root.HistThresholdFitted[:], mask)
                        rel_bcid_2 = in_file_2_h5.root.HistRelBcid[0:16]
                    except tb.exceptions.NoSuchNodeError:
                        occupancy_masked_2 = np.zeros(shape=(336, 80, 2))
                        thresholds_masked_2 = np.zeros(shape=(336, 80))
                        rel_bcid_2 = np.zeros(shape=(16, ))
                    # plot the threshold distribution and the s curves
                    if local_configuration['create_plots']:
                        plotting.plotThreeWay(
                            hist=thresholds_masked_1 * 55.,
                            title='Threshold Fitted for 1. trigger, delay ' +
                            str(delay_value),
                            x_axis_title='threshold [e]',
                            filename=output_pdf)
                        plotting.plot_relative_bcid(
                            hist=rel_bcid_1,
                            title=
                            'Relative BCID (former LVL1ID) for 1. trigger, delay = '
                            + str(delay_value),
                            filename=output_pdf)
                        plotting.plotThreeWay(
                            hist=thresholds_masked_2 * 55.,
                            title='Threshold Fitted for 2. trigger, delay ' +
                            str(delay_value),
                            x_axis_title='threshold [e]',
                            filename=output_pdf)
                        plotting.plot_relative_bcid(
                            hist=rel_bcid_2,
                            title=
                            'Relative BCID (former LVL1ID) for 2. trigger, delay = '
                            + str(delay_value),
                            filename=output_pdf)
                    if local_configuration['create_plots']:
                        plotting.plot_scurves(
                            occupancy_hist=occupancy_masked_1,
                            title='S-Curves 1. trigger, delay ' +
                            str(delay_value),
                            scan_parameters=scan_parameters,
                            scan_parameter_name='PlsrDAC',
                            filename=output_pdf)
                        plotting.plot_scurves(
                            occupancy_hist=occupancy_masked_2,
                            title='S-Curves 2. trigger, delay ' +
                            str(delay_value),
                            scan_parameters=scan_parameters,
                            scan_parameter_name='PlsrDAC',
                            filename=output_pdf)
                    # fill the calibration data arrays
                    mean_threshold_calibration_1[delay_index] = np.ma.mean(
                        thresholds_masked_1)
                    mean_threshold_rms_calibration_1[delay_index] = np.ma.std(
                        thresholds_masked_1)
                    threshold_calibration_1[:, :,
                                            delay_index] = thresholds_masked_1.T
                    mean_threshold_calibration_2[delay_index] = np.ma.mean(
                        thresholds_masked_2)
                    mean_threshold_rms_calibration_2[delay_index] = np.ma.std(
                        thresholds_masked_2)
                    threshold_calibration_2[:, :,
                                            delay_index] = thresholds_masked_2.T
        progress_bar.update(delay_index)
    progress_bar.finish()

    # plot the parameter against delay plots
    if local_configuration['create_result_plots']:
        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_threshold_calibration * 55.,
                              title='Threshold as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Mean threshold [e]',
                              log_x=False,
                              filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_threshold_calibration * 55.,
                              title='Threshold as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Mean threshold [e]',
                              log_x=True,
                              filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_threshold_rms_calibration * 55.,
                              title='Threshold as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Threshold RMS [e]',
                              log_x=False,
                              filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_threshold_rms_calibration * 55.,
                              title='Threshold as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Threshold RMS [e]',
                              log_x=True,
                              filename=output_pdf)
        if local_configuration['analysis_two_trigger']:
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_calibration_1 * 55.,
                title='Threshold as a function of the delay, 1. trigger',
                x_label='delay [BCID]',
                y_label='Mean threshold [e]',
                log_x=False,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_calibration_1 * 55.,
                title='Threshold as a function of the delay, 1. trigger',
                x_label='delay [BCID]',
                y_label='Mean threshold [e]',
                log_x=True,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_rms_calibration_1 * 55.,
                title='Threshold as a function of the delay, 1. trigger',
                x_label='delay [BCID]',
                y_label='Threshold RMS [e]',
                log_x=False,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_rms_calibration_1 * 55.,
                title='Threshold as a function of the delay, 1. trigger',
                x_label='delay [BCID]',
                y_label='Threshold RMS [e]',
                log_x=True,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_calibration_2 * 55.,
                title='Threshold as a function of the delay, 2. trigger',
                x_label='delay [BCID]',
                y_label='Mean threshold [e]',
                log_x=False,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_calibration_2 * 55.,
                title='Threshold as a function of the delay, 2. trigger',
                x_label='delay [BCID]',
                y_label='Mean threshold [e]',
                log_x=True,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_rms_calibration_2 * 55.,
                title='Threshold as a function of the delay, 2. trigger',
                x_label='delay [BCID]',
                y_label='Threshold RMS [e]',
                log_x=False,
                filename=output_pdf)
            plotting.plot_scatter(
                x=local_configuration['delays'],
                y=mean_threshold_rms_calibration_2 * 55.,
                title='Threshold as a function of the delay, 2. trigger',
                x_label='delay [BCID]',
                y_label='Threshold RMS [e]',
                log_x=True,
                filename=output_pdf)

        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_noise_calibration * 55.,
                              title='Noise as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Mean noise [e]',
                              log_x=False,
                              filename=output_pdf)
        plotting.plot_scatter(x=local_configuration['delays'],
                              y=mean_noise_rms_calibration * 55.,
                              title='Noise as a function of the delay',
                              x_label='delay [BCID]',
                              y_label='Noise RMS [e]',
                              log_x=False,
                              filename=output_pdf)

    if local_configuration['create_plots'] or local_configuration[
            'create_result_plots']:
        output_pdf.close()

    # store the calibration data into a hdf5 file as an easy to read table and as an array for quick data access
    with tb.openFile(output_h5_filename, mode="w") as out_file_h5:
        store_calibration_data_as_array(
            out_file_h5, mean_threshold_calibration,
            mean_threshold_rms_calibration, threshold_calibration,
            mean_noise_calibration, mean_noise_rms_calibration,
            noise_calibration)
        store_calibration_data_as_table(
            out_file_h5, mean_threshold_calibration,
            mean_threshold_rms_calibration, threshold_calibration,
            mean_noise_calibration, mean_noise_rms_calibration,
            noise_calibration)