"""extracts area data for gnuplot"""
import numpy as np
import matplotlib.pyplot as plt

trace_parameters = np.genfromtxt('trace_params.dat', names=True)

area = trace_parameters['area_win_abs']

numbns = 200
# lims = (0,20)
plt.figure()
plt.hist(area,numbns,alpha=0.5);

freq_ar, bn_ar = np.histogram(area,numbns)
x_val = bn_ar[:-1]+np.diff(bn_ar)/2

g1 = np.loadtxt('g1_area_component.dat')
g2 = np.loadtxt('g2_area_component.dat')
g3 = np.loadtxt('g3_area_component.dat')

plt.plot(x_val, g1, color='blue', label='n=1')
plt.plot(x_val, g2, color='red', label='n=2')
plt.plot(x_val, g3, color='orange', label='n=3')

print np.sum(freq_ar)
print np.max(freq_ar)
ar_width_ht = bn_ar[1]-bn_ar[0]

"""RECOVER GAUSSIAN PROPERTIES"""

"""SAVE FIT DATA"""
# np.savetxt('area_histo_with_fit.dat',
#            zip(x_val*2, freq_ar, np.sqrt(freq_ar), g1, g2, g3),
#            header='area(nVs)\tcounts\tsqrt(counts)\tg1\tg2\tg3')

# np.savetxt('area_histo.dat',
#            zip((bn_ar[:-1]+ar_width_ht/2)*2, freq_ar, np.sqrt(freq_ar)),
#            header='area(pVs)\tcounts\tsqrt(counts)')
plt.show()