Skip to content
Snippets Groups Projects
Asymmetric.py 1.59 KiB
Newer Older
  • Learn to ignore specific revisions
  • An Bui's avatar
    An Bui committed
    #!/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[ ]: