def rebin_plot(histogram, bins_array):
    """Will rebin the histogram
    Draws a legend onto the plot with the specified histograms.

    Bin edges and overflow bins must be carefully considered, see the documentation
    https://root.cern.ch/doc/master/classTH1.html#aff6520fdae026334bf34fa1800946790
    Bin 0 contains the underflow
    Nbins+1 contains the overflow

    The Rebin function is also a bit messy:
    Double_t xbins[25] = {...} // array of low-edges (xbins[25] is the upper edge of last bin)
    h1->Rebin(24,"hnew",xbins);  //creates a new variable bin size histogram hnew

    Args:
        histogram: A single histogram
        bins_array: an array containing the list of bin edges
    """
    newname = histogram.GetName()+'_rebinned'
    newplot = histogram.Rebin(len(bins_array)-1, newname, bins_array)
    newplot.SetDirectory(0)

    return newplot