function overlaying_histograms(histogram_data_cell,color_array,bin_centers,xtickstep)
%called by analyze_size_distributions, permits overlaying the histogram of success event sizes in one color and failure event sizes in another

rectangle_width=.125;
emptyspace_width=.025;
rectangle_linewidth=.0001;
fill_rectangles=1;

num_categories=length(histogram_data_cell);
interbinspace=(rectangle_width*num_categories)+emptyspace_width;

for category=1:num_categories
    data_now=histogram_data_cell{category};
    n=hist(data_now,bin_centers);
    category_x_startpoint=(category-1)*rectangle_width;
    for bin=1:length(n)
        if n(bin)
            if fill_rectangles
                rectangle('position',[category_x_startpoint+(bin-1)*interbinspace 0 rectangle_width n(bin)],'linewidth',rectangle_linewidth,'facecolor',color_array(category,:),'edgecolor',[1 1 1])
            else
                rectangle('position',[category_x_startpoint+(bin-1)*interbinspace 0 rectangle_width n(bin)],'linewidth',rectangle_linewidth,'edgecolor',color_array(category,:))
            end
            if ~exist('x_range_plotted_bars'),x_range_plotted_bars=[(bin-1)*interbinspace (bin-1)*interbinspace];end
            if ((bin-1)*interbinspace)<x_range_plotted_bars(1),x_range_plotted_bars(1)=(bin-1)*interbinspace;end
            if ((bin-1)*interbinspace)>x_range_plotted_bars(2),x_range_plotted_bars(2)=(bin-1)*interbinspace;end
        end
    end
    centers_of_filled_bins=bin_centers(find(n));
    if ~exist('lowest_and_highest_centers_of_filled_bins'),lowest_and_highest_centers_of_filled_bins=[centers_of_filled_bins(1) centers_of_filled_bins(1)];end
    if min(centers_of_filled_bins)<lowest_and_highest_centers_of_filled_bins(1),lowest_and_highest_centers_of_filled_bins(1)=min(centers_of_filled_bins);end
    if max(centers_of_filled_bins)>lowest_and_highest_centers_of_filled_bins(2),lowest_and_highest_centers_of_filled_bins(2)=max(centers_of_filled_bins);end
end
range_centers=range(lowest_and_highest_centers_of_filled_bins);
range_x_range=range(x_range_plotted_bars);
set(gca,'xtick',[x_range_plotted_bars(1):(range_x_range*xtickstep)/range_centers:x_range_plotted_bars(2)],'xticklabel',[lowest_and_highest_centers_of_filled_bins(1):xtickstep:lowest_and_highest_centers_of_filled_bins(2)])