r0 = 2.818e-15
alpha = 662 * 1.602e-19 / (9.109e-31 * 3e8 ** 2)
theta = arange(0, 161) * pi / 180
cross_section = (
    r0 ** 2
    * (1 / (1 + alpha * (1 - cos(theta)))) ** 2
    * (1 + cos(theta) ** 2)
    / 2
    * (1 + (alpha ** 2 * (1 - cos(theta)) ** 2) / ((1 + cos(theta) ** 2) * (1 + alpha * (1 - cos(theta)))))
)

# plot(theta, cross_section)
# show()

R = 190e-3
l = log(2) / (30.17 * yrs(1, 0, 0))
activity = 122.1e6 * exp(-l * (yrs(2013, 1, 2) - yrs(1979, 3, 22)))
print "activity is %d" % activity
flux = activity / (4 * pi * R ** 2)
print "flux is %d" % flux

fileset = [
    ("AX20.ASC", (3350, 3850)),
    ("AX40.ASC", (3350, 3800)),
    ("AX60.ASC", (3400, 3750)),
    ("AX80.ASC", (3300, 3750)),
    ("AX90.ASC", (3300, 3900)),
    ("AX140.ASC", (3300, 3750)),
]

dataset = []
rcParams['text.usetex'] = True
rcParams['text.latex.unicode'] = True
rcParams['font.family'] = 'serif'

datapath = "data/effectivity/"
imgpath = "img/"

# For activities we have
# n(t) = n_0 exp(- l t) <=>
# n(0) = n_0 =>
# n(t) = n(0) exp(- l (t-0))
# DO NOT CHANGE THE DATES!!!

gamma_R = 0.155  # Distance between preparate (on electron detector)
                 # and gamma detector
l_cs = log(2) / (30.17 * yrs(1, 1, 0))
l_am = log(2) / (432.2 * yrs(1, 1, 0))
cesium_activity = 404e3 * exp(
    -l_cs * (yrs(2013, 1, 5) - yrs(1979, 12, 01)))
americium_activity = 401e3 * exp(
    -l_am * (yrs(2013, 1, 5) - yrs(1986, 02, 01)))

gamma_area = pi * (50.8e-3) ** 2 / 4

data = [
    ("ABGG", mins(1, 13)),
    ("CC", mins(15, 26)),
    ("CA", mins(22, 48))]

dataset = []

def eff_error(E): return sqrt((E * scales[1, 0]) ** 2 + (scales[1, 1]) ** 2)


def cross_section(theta):
    return r0 ** 2 * (1 / (1 + alpha * (1 - cos(theta)))) ** 2 * \
        (1 + cos(theta) ** 2) / 2 * (1 + (alpha ** 2 * (1 - cos(theta)) ** 2) \
                                         / ((1 + cos(theta) ** 2) * \
                                                (1 + alpha * \
                                                     (1 - cos(theta)))))

# Flux phi
R = 0.19 + 0.0045  # Distance from preparate to electron detector
R_error = 0.005
l = log(2) / (30.17 * yrs(1, 1, 0))
l_error = l / (30.17 * yrs(1, 1, 0)) * 24 * 3600 * 0.5
n0 = 122100e3
n0_error = 50e3
t = yrs(2013, 1, 3)
t_error = 24 * 3600 * 0.5
t0 = yrs(1979, 3, 22)
t0_error = 24 * 3600 * 0.5
activity = n0 * exp(
    -l * (t - t0))
print "activity is %d" % activity
phi = activity * 0.851 / (4 * pi * R ** 2)
phi_error = 0.851 / (4 * pi) * sqrt(
    (2 * activity / R ** 3 * R_error) ** 2 +
    (activity / n0 / R ** 2 * n0_error) ** 2 +
    (activity * (t - t0) / R ** 2 * l_error) ** 2 +