import numpy as np

def coverage(a,cl=68):
    ''' For an array a return width for which cl percent of the distribution is covered'''
    b = np.percentile(abs(a - np.median(a)), cl)
    return b



#
# Example application of the estimator, using 10000 random Gaussian events
#

g = np.random.normal(0.,1.0,10000)

print ("68% Coverage of g:", coverage(g))
print ("90% Coverage of g:", coverage(g,90.))
print ("95% Coverage of g:", coverage(g,95.))


