Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# coding: utf-8
# In[13]:
import numpy as np
import matplotlib.pyplot as plt
def asymmetry():
B = 0.2
Nplus_array = np.arange(10, 1000, 1) # an array of Nplus values from 10 to 1000
Nminus_array = (1 - B) * Nplus_array
N_array = Nplus_array + Nminus_array # total number
A_array = (Nplus_array - Nminus_array) / (Nplus_array + Nminus_array) # calculate the value of asymmetry A
# Calculte the uncertainty of Nplus and Nminus
sigma_Nplus_array = np.sqrt(Nplus_array)
sigma_Nminus_array = (1 - B) * sigma_Nplus_array
# Calculate the uncertainty of A due to the uncertainty of N, where dA/dNplus and dA/dNminus are the partial derivative
#of A with respect to Nplus and Nminus and then add these contribution to the uncertainty of A
sigma_A1_array = ((2 * Nminus_array * sigma_Nplus_array) / (Nplus_array + Nminus_array)**2)**2 #using the formula (dA/dNplus)^2*(sigmaNplus)^2
sigma_A2_array = (-(2 * Nplus_array * sigma_Nminus_array) / (Nplus_array + Nminus_array)**2)**2 #using the formula (dA/dNminus)^2*(sigmaNplus)^2
delta_A_array = np.sqrt(sigma_A1_array + sigma_A2_array) # the uncertainty of A
# plot the asymmetry and its uncertainty as two separate lines
fig, ax = plt.subplots()
ax.plot(Nplus_array, A_array, label='Asymmetry')
ax.plot(Nplus_array, delta_A_array, label='Uncertainty')
ax.set_xlabel('Nplus')
ax.set_ylabel('Asymmetry and Uncertainty')
ax.set_title('Asymmetry and Uncertainty vs. Nplus for B=0.3')
ax.legend()
plt.show()
asymmetry()
# In[ ]: