<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_histograms_table(samples_table, samples, max_bins=1024):
 """ Generate a table of histograms as a DataFrame. Parameters samples_table : DataFrame Table specifying samples to analyze. For more information about the fields required in this table, please consult the module's documentation. samples : list FCSData objects from which to calculate histograms. ``samples[i]`` should correspond to ``samples_table.iloc[i]`` max_bins : int, optional Maximum number of bins to use. Returns ------- hist_table : DataFrame A multi-indexed DataFrame. Rows cotain the histogram bins and counts for every sample and channel specified in samples_table. `hist_table` is indexed by the sample's ID, the channel name, and whether the row corresponds to bins or counts. """

    # Extract channels that require stats histograms
    headers = list(samples_table.columns)
    hist_headers = [h for h in headers if re_units.match(h)]
    hist_channels = [re_units.match(h).group(1) for h in hist_headers]

    # The number of columns in the DataFrame has to be set to the maximum
    # number of bins of any of the histograms about to be generated.
    # The following iterates through these histograms and finds the
    # largest.
    n_columns = 0
    for sample_id, sample in zip(samples_table.index, samples):
        if isinstance(sample, ExcelUIException):
            continue
        for header, channel in zip(hist_headers, hist_channels):
            if pd.notnull(samples_table[header][sample_id]):
                if n_columns < sample.resolution(channel):
                    n_columns = sample.resolution(channel)
    # Saturate at max_bins
    if n_columns > max_bins:
        n_columns = max_bins

    # Declare multi-indexed DataFrame
    index = pd.MultiIndex.from_arrays([[],[],[]],
                                      names = ['Sample ID', 'Channel', ''])
    columns = ['Bin {}'.format(i + 1) for i in range(n_columns)]
    hist_table = pd.DataFrame([], index=index, columns=columns)

    # Generate histograms
    for sample_id, sample in zip(samples_table.index, samples):
        if isinstance(sample, ExcelUIException):
            continue
        for header, channel in zip(hist_headers, hist_channels):
            if pd.notnull(samples_table[header][sample_id]):
                # Get units in which bins are being reported
                unit = samples_table[header][sample_id]
                # Decide which scale to use
                # Channel units result in linear scale. Otherwise, use logicle.
                if unit == 'Channel':
                    scale = 'linear'
                else:
                    scale = 'logicle'
                # Define number of bins
                nbins = min(sample.resolution(channel), max_bins)
                # Calculate bin edges and centers
                # We generate twice the necessary number of bins. We then take
                # every other value as the proper bin edges, and the remaining
                # values as the bin centers.
                bins_extended = sample.hist_bins(channel, 2*nbins, scale)
                bin_edges = bins_extended[::2]
                bin_centers = bins_extended[1::2]
                # Store bin centers
                hist_table.loc[(sample_id,
                                channel,
                                'Bin Centers ({})'.format(unit)),
                                columns[0:len(bin_centers)]] = bin_centers
                # Calculate and store histogram counts
                hist, __ = np.histogram(sample[:,channel], bins=bin_edges)
                hist_table.loc[(sample_id, channel, 'Counts'),
                               columns[0:len(bin_centers)]] = hist

    return hist_table