Commit dfa6553c authored by Tobias Jörg Theodor Kempe's avatar Tobias Jörg Theodor Kempe
Browse files

resolved merge conflict

parents 5a9d341d 306f34e3
......@@ -6,12 +6,12 @@ report.pdf:
script:
- pip3 install --requirement python/requirements.txt
- python3 python/main.py
- mkdir plots
- find . -name '*.pdf' -exec mv {} plots/ \;
- cd latex/
- latexmk -pdf report.tex
- cd ..
- mv latex/report.pdf Report\_$REPORT_NUMBER\_Kempe_Sensebat.pdf
- mkdir plots
- find . -name '*.pdf' -exec mv {} plots/ \;
- mv plots/report.pdf Report\_$REPORT_NUMBER\_Kempe_Sensebat.pdf
artifacts:
paths:
......
import numpy as np
<<<<<<< HEAD
import time
import matplotlib.pyplot as plt
......@@ -108,3 +109,113 @@ print(f'total simulation duration: {round(duration, 2)} s')
=======
import matplotlib.pyplot as plt
import time
# settings
N = int(1e6)
T_0 = 1000
W = 1
showPlots = True
def simulate(phi1, phi2):
# generate random phis
thetas = np.empty((N, 2), dtype=np.float32)
thetas[:, 0] = np.random.rand(N) * 2 * np.pi
thetas[:, 1] = thetas[:, 0] + np.pi / 2
# generate random number for timestamp
rs = np.random.rand(N)
# calculate outcome of observation station
x1 = (np.cos(2 * (phi1 - thetas[:, 0])) >= (2*np.random.rand(N) -1)).reshape(N, 1)
t1 = T_0 * rs * np.sin(2 * (phi1 - thetas[:, 0])) ** 2
x2 = (np.cos(2 * (phi2 - thetas[:, 1])) >= (2*np.random.rand(N) -1)).reshape(N, 1)
t2 = T_0 * rs * np.sin(2 * (phi2 - thetas[:, 1])) ** 2
# determine which events are conincidences (1) and which not (0)
coincidences = np.abs(t1 - t2) < W
# zip measurement outcome together
x1x2 = np.concatenate((x1, x2), axis=1)
counts = np.empty((2, 4), dtype=np.int32)
counts[0, 0] = np.sum(np.all(x1x2 == np.array([0, 0]), axis=1), axis=0)
counts[0, 1] = np.sum(np.all(x1x2 == np.array([0, 1]), axis=1), axis=0)
counts[0, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1), axis=0)
counts[0, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1), axis=0)
counts[1, 0] = np.sum(np.all(x1x2 == np.array([0, 0]), axis=1) == coincidences, axis=0)
counts[1, 1] = np.sum(np.all(x1x2 == np.array([0, 1]), axis=1) == coincidences, axis=0)
counts[1, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1) == coincidences, axis=0)
counts[1, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1) == coincidences, axis=0)
E_all = np.sum(counts, axis=1).astype(float)
E_12 = (counts[:, 0] - counts[:, 1] - counts[:, 2] + counts[:, 3]).astype(float)
E_1 = (counts[:, 0] + counts[:, 1] - counts[:, 2] - counts[:, 3]).astype(float)
E_2 = (counts[:, 0] - counts[:, 1] + counts[:, 2] - counts[:, 3]).astype(float)
if (np.all(E_all > 0)):
E_12 /= E_all
E_1 /= E_all
E_2 /= E_all
return E_12, E_1, E_2
def try_all_configs(n_configs):
E_12 = np.empty((n_configs, 2), dtype=np.float32)
E_1 = np.empty((n_configs, 2), dtype=np.float32)
E_2 = np.empty((n_configs, 2), dtype=np.float32)
for i in range(n_configs):
phi1 = 0
phi2 = i * 2 * np.pi / n_configs
E_12_, E_1_, E_2_ = simulate(phi1, phi2)
E_12[i, :] = E_12_
E_1[i, :] = E_1_
E_2[i, :] = E_2_
x = np.linspace(0, 360, n_configs)
plt.figure()
plt.plot(x, E_12[:, 0])
plt.show()
# correlation
phi = np.linspace(0, 360, n_configs)
phi_theory = np.linspace(0, 360, n_configs*100)
theory = -np.cos(2 * phi_theory * (2 * np.pi / 360))
plt.figure()
plt.xlabel(r'$\Delta \varphi$')
plt.ylabel(r'$<x_1 x_2>$')
plt.plot(phi_theory, theory, '.', markersize=1, color='orange')
plt.plot(phi, E_12[:, 0], 'o', color='blue')
#plt.savefig('correlation.pdf')
if showPlots:
plt.show()
plt.close()
# product of expectation values
line = np.zeros(phi_theory.shape)
plt.figure()
plt.xlabel(r'$\Delta \varphi$')
plt.ylabel(r'$<x_1><x_2>$')
plt.ylim([-1, 1])
plt.xticks([0, 45, 90, 135, 180, 225, 270, 305, 360])
plt.plot(phi_theory, line, '.', markersize=1, color='orange')
plt.plot(phi, E_1[:, 0]*E_2[:, 0], 'o', color='blue')
#plt.savefig('expectation_value.pdf')
if showPlots:
plt.show()
plt.close()
start = time.time()
try_all_configs(32)
duration = time.time() - start
print(f'simulation took {round(duration, 2)} seconds')
>>>>>>> 306f34e3cfd8a671917195d947d9ef22046bb21a
import numpy as np
import matplotlib.pyplot as plt
# some initialization
wxyz = 1234
np.random.seed(wxyz)
# input data
nsteps = 32
nsamples = 100000
T0 = 1000 # (ns), maximum time delay
W = 1 # (ns), time coincidence window
HWP2 = 0 # degrees, orientation of wave plate 2 (EOM2)
cHWP2 = np.cos(HWP2*np.pi/180)
sHWP2 = np.sin(HWP2*np.pi/180)
def analyzer(c, s, cHWP, sHWP, T0):
# EOM : plane rotation
c2 = cHWP*c + sHWP*s
s2 = -sHWP*c + cHWP*s
x = c2*c2 - s2*s2 # cos(2(x-a))
y = 2*c2*s2 # sin(2(x-a))
# Malus law
r0 = np.random.rand()
if(x>2*r0 - 1):
j = 0 # +1 event
else:
j = 1 #-1 event
# time delay
r1 = np.random.rand()
l = y**4*T0*r1 # delay time: T_0 sin(2*(theta1 - x))**4
return j, l
count = np.zeros(shape=(2, 2, 2, nsteps), dtype=np.int32) # set all counts to zero
for ipsi0 in range(nsteps): # loop over different settings of EOM1
cHWP1 = np.cos(ipsi0*2*np.pi/nsteps)
sHWP1 = np.sin(ipsi0*2*np.pi/nsteps)
for i in range(nsamples):
# source
r0 = np.random.rand()
c1 = np.cos(r0*2*np.pi) # polarization angle x of particle going to station 1
s1 = np.sin(r0*2*np.pi) # polarization angle x + pi/2 of particle going to station 2
c2 = -s1
s2 = c1
# station 1
j1, l1 = analyzer(c1, s1, cHWP1, sHWP1, T0)
# station 2
j2, l2 = analyzer(c2, s2, cHWP2, sHWP2, T0)
# count
count[j1, j2, 0, ipsi0] = count[j1, j2, 0, ipsi0] + 1 # Malus law model
if(abs(l1 - l2)<W):
count[j1, j2, 1, ipsi0] = count[j1, j2, 1, ipsi0] + 1 # Malus law model + time window
# data analysis
tot = np.zeros(shape=(2, nsteps), dtype=np.int32)
E12 = np.zeros(shape=(2, nsteps), dtype=np.float64)
E1 = np.zeros(shape=(2, nsteps), dtype=np.float64)
E2 = np.zeros(shape=(2, nsteps), dtype=np.float64)
for j in range(nsteps):
for i in [0, 1]:
# i = 0 <==> no time window, i = 1 <=> use time coincidences
#tot[i, j] = np.sum(count[:, :, i, j])
tot[i, j] = count[0, 0, i, j] + count[1, 1, i, j] + count[1, 0, i, j] + count[0, 1, i, j]
E12[i, j] = count[0, 0, i, j] + count[1, 1, i, j] - count[1, 0, i, j] - count[0, 1, i, j]
E1[i, j] = count[0, 0, i, j] + count[0, 1, i, j] - count[1, 1, i, j] - count[1, 0, i, j]
E2[i, j] = count[0, 0, i, j] + count[1, 0, i, j] - count[1, 1, i, j] - count[0, 1, i, j]
if(tot[i, j]>0):
E12[i, j] = E12[i, j]/tot[i, j]
E1[i, j] = E1[i, j]/tot[i, j]
E2[i, j] = E2[i, j]/tot[i, j]
theta = np.linspace(0, 360, nsteps)
theta_theory = np.linspace(0, 360, nsteps*100)
theory = []
for j in range(nsteps*100):
theory.append(-np.cos(2 * j * 2 * np.pi / nsteps / 100))
plt.plot(theta, E12[0, :], 'o')
plt.plot(theta_theory, theory, '.', markersize=1)
plt.savefig('e12.pdf')
plt.close()
\ No newline at end of file
import example
import eprb
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment