In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit # import the curve fitting function
import matplotlib.mlab as mlab
%matplotlib inline
In [2]:
V = np.array([550,560,570,580,590,601,610,620,630,640,650,660,670,680,690,701,720,740,760,780,
802,820,840,860,880,900])
In [3]:
Height = np.array([0,0,0,0,.64,1.1,1.63,2.25,2.81,3.02])
In [4]:
plt.plot(V[4:10],Height[4:10]);
plt.xlabel('High Voltage (V)');
plt.ylabel('Pulse Height (V)');
In [5]:
Counts = np.array([0,0,0,0,0,3046,3536,3941,4179,4322,
4489,4628,4807,4825,4963,4969,5158,5225,5403,5434,5581,5607,5711,5848,6013,6092])
In [6]:
plt.figure(figsize=(10,6))
plt.scatter(V,Counts);
plt.xlim(550,900);
plt.ylim(-1,7000)
plt.ylabel('Decay Counts',size=20);
plt.xlabel('Tube Voltage (Volts)',size=20);
plt.xticks(size = 16);
plt.yticks(size = 16);
plt.savefig('CountsVsVoltage')
In [7]:
HighCounts = np.array([980,993,975,984,950,1023,1000,998,943,995,
995,1043,977,981,994,917,989,993,
938,967,976,937,969,939,906,
990,988,959,983,974])
In [8]:
Rates = np.array([entry/10 for entry in HighCounts]) #HighCounts measured for 10s
Rates
Out[8]:
In [9]:
def correction(Rate):
tau = 478*1e-6
return 1/(1-Rate*tau)
In [10]:
TrueCounts = np.array([correction(entry)*entry*10 for entry in Rates])
TrueCounts
Out[10]:
In [11]:
import numpy.ma as ma
In [12]:
N_best = np.mean(TrueCounts)
N_best
Out[12]:
In [13]:
sigma_th = np.sqrt(N_best)
sigma_th
Out[13]:
In [14]:
sigma_exp = np.std(TrueCounts)
sigma_exp
Out[14]:
In [15]:
len(ma.masked_outside(TrueCounts, N_best - 1*sigma_exp, N_best + 1*sigma_exp).compressed())
Out[15]:
In [16]:
22/30
Out[16]:
In [17]:
len(ma.masked_outside(TrueCounts, N_best - 2*sigma_exp, N_best + 2*sigma_exp).compressed())
Out[17]:
In [18]:
27/30
Out[18]:
In [19]:
sigma_exp/sigma_th
Out[19]:
In [20]:
plt.figure(figsize=(10,6))
plt.xlabel('Measured Decays in 10 seconds',size=20);
plt.ylabel('Counts',size=20);
bins = np.arange(940,1110,10)
CountsPerBin = np.array([1,1,0,0,4,1,1,2,6,5,6,1,0,1,0,1])
MidBin = np.arange(945,1105,10)
n, bins, patches = plt.hist(TrueCounts, bins, normed=0, facecolor='green', alpha=0.75)
#plt.xlim(930,1110)
#plt.ylim(0,.03)
plt.scatter(MidBin,CountsPerBin)
mu = N_best
sigma = sigma_exp
y = mlab.normpdf(bins, mu, sigma)
l = plt.plot(bins, y*300, 'r--', linewidth=1)
plt.xticks(size = 13);
plt.yticks(size = 13);
plt.legend(['Normal Dist.','Counts'],loc='best');
plt.savefig('HighCount.png')
In [21]:
from scipy.special import factorial
In [22]:
def poisson(k,mu):
return np.exp(-mu) * mu**k / factorial(k,0)
In [23]:
x = np.array([2,2,1,0,3,0,0,1,1,1,2,2,1,1,0,2,3,1,0,2,0,0,2,3,2,3,1,0,5,1,1,3,2,2,2,4,2,1,1,0,0,1,1,0,0,0,3,3,3,0])
In [24]:
mu2 = np.mean(x)
In [25]:
x2 = ma.masked_not_equal(x,2).compressed()
len(x2)
Out[25]:
In [26]:
x5 = ma.masked_not_equal(x,5).compressed()
len(x5)
Out[26]:
In [27]:
plt.figure(figsize=(10,6))
n, bins, patches = plt.hist(x, bins = 5,normed = 0, facecolor='green', alpha=0.75)
plt.xlim(-1,6);
plt.ylim(-1,18);
bins = [0,1,2,3,4,5,6]
y = poisson(bins, mu2)
l = plt.plot(bins, y*50, 'r--', linewidth=1)
plt.scatter
plt.legend(['Poisson Dist.','Counts'],loc='best');
plt.xlabel('Background Radioactivity in 6.7 second Intervals',size=20);
plt.ylabel('Counts',size=20);
plt.xticks(size = 13);
plt.yticks(size = 13);
plt.savefig('Background.png')
plt.xticks(size = 13);
plt.yticks(size = 13);
In [28]:
Nv = np.array([len(ma.masked_not_equal(x, i).compressed()) for i in [0,1,2,3,4,5]])
In [29]:
plt.errorbar([0,1,2,3,4,5], Nv, yerr=np.array([np.sqrt(entry) for entry in Nv]),fmt = 'o')
plt.xlim(-1,6);
plt.ylim(-1,20);
bins = [0,1,2,3,4,5]
y = poisson(bins, mu2)
l = plt.plot(bins, y*50, 'r--', linewidth=1)
plt.scatter
plt.legend(['Poisson Dist.','Counts'],loc='best');
In [ ]: