import numpy as np
import os
import inspect

def get_energy_bins(coinc):
  # coinc may be: "ab", "abc", "abcd", "abcde"
  coinc=coinc.lower()
  if coinc not in ["ab", "abc", "abcd", "abcde"]:
    print 'Wrong coinc! coinc has to be "ab", "abc", "abcd" or "abcde"! aborting..'
  else:
    if coinc=="ab":
      coinccol=3
    elif coinc=="abc":
      coinccol=4
    else:
      coinccol=5
    try:
			binnumber, emax=np.loadtxt("table_e1_sierks.tab",unpack=True,usecols=(0,coinccol))
    except:
		  path=os.path.dirname(inspect.getfile(inspect.currentframe()))
		  binnumber, emax=np.loadtxt("%s/table_e1_sierks.tab"%path,unpack=True,usecols=(0,coinccol))
    emax=emax/1e3
    emin=np.zeros(len(emax))
    emin[1:]=emax[:-1]
    ewidth=emax-emin
    ebinedges=np.zeros(len(emax)+1)
    ebinedges[1:]=emax
    ecenter=emin+0.5*ewidth
    ecenter=ecenter
    energybins_dict={
    "coincname":coinc    ,
    "emax":emax,
    "emin":emin,
    "ewidth":ewidth,
    "ebinedges":ebinedges,
    "ecenter":ecenter
    }
    return energybins_dict





