Commit 2bdb32cb authored by Orkun Şensebat's avatar Orkun Şensebat
Browse files

Simplify loop ranges

parent 01f0bc4a
Pipeline #463809 passed with stage
in 1 minute and 2 seconds
...@@ -33,10 +33,10 @@ def analyzer(c, s, cHWP, sHWP, T0): ...@@ -33,10 +33,10 @@ def analyzer(c, s, cHWP, sHWP, T0):
count = np.zeros(shape=(2, 2, 2, nsteps), dtype=np.int32) # set all counts to zero count = np.zeros(shape=(2, 2, 2, nsteps), dtype=np.int32) # set all counts to zero
for ipsi0 in range(0, nsteps): # loop over different settings of EOM1 for ipsi0 in range(nsteps): # loop over different settings of EOM1
cHWP1 = np.cos(ipsi0*2*np.pi/nsteps) cHWP1 = np.cos(ipsi0*2*np.pi/nsteps)
sHWP1 = np.sin(ipsi0*2*np.pi/nsteps) sHWP1 = np.sin(ipsi0*2*np.pi/nsteps)
for i in range(0, nsamples): for i in range(nsamples):
# source # source
r0 = np.random.rand() r0 = np.random.rand()
c1 = np.cos(r0*2*np.pi) # polarization angle x of particle going to station 1 c1 = np.cos(r0*2*np.pi) # polarization angle x of particle going to station 1
...@@ -57,8 +57,8 @@ tot = np.zeros(shape=(2, nsteps), dtype=np.int16) ...@@ -57,8 +57,8 @@ tot = np.zeros(shape=(2, nsteps), dtype=np.int16)
E12 = np.zeros(shape=(2, nsteps), dtype=np.float64) E12 = np.zeros(shape=(2, nsteps), dtype=np.float64)
E1 = 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) E2 = np.zeros(shape=(2, nsteps), dtype=np.float64)
for j in range(0, nsteps): for j in range(nsteps):
for i in range(0, 1): # i = 0 <==> no time window, i = 1 <=> use time coincidences 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] = np.sum(count[:, :, 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] 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] E1[i, j] = count[0, 0, i, j] + count[0, 1, i, j] - count[1, 1, i, j] - count[1, 0, i, j]
...@@ -69,7 +69,7 @@ for j in range(0, nsteps): ...@@ -69,7 +69,7 @@ for j in range(0, nsteps):
E2[i, j] = E2[i, j]/tot[i, j] E2[i, j] = E2[i, j]/tot[i, j]
# print out to two different files, suitable for plotting by GNUPLOT # print out to two different files, suitable for plotting by GNUPLOT
for i in range(0, 1): for i in [0, 1]:
print('("# ** DLM Demo EPRB **")') print('("# ** DLM Demo EPRB **")')
print('("# Input variables: ")') print('("# Input variables: ")')
print('("# Nsamples = ', nsamples, '"') print('("# Nsamples = ', nsamples, '"')
...@@ -78,7 +78,7 @@ for i in range(0, 1): ...@@ -78,7 +78,7 @@ for i in range(0, 1):
print('("# W = ', W, '"') print('("# W = ', W, '"')
print('("# seed = ', wxyz, '"') print('("# seed = ', wxyz, '"')
print('("# Theta <S1.a> <S2.b> <S1.a S2.b> theory S N++ N-+ N+- N-- sum(N..)")') print('("# Theta <S1.a> <S2.b> <S1.a S2.b> theory S N++ N-+ N+- N-- sum(N..)")')
for j in range(0, nsteps): for j in range(nsteps):
S = 3*E12[i, j] - E12[i, (j*3)%nsteps] # correlation of QT S = 3*E12[i, j] - E12[i, (j*3)%nsteps] # correlation of QT
r0 = -np.cos(2*j*2*np.pi/nsteps) r0 = -np.cos(2*j*2*np.pi/nsteps)
print(j*360.0/nsteps, E1[i, j], E2[i, j], E12[i, j], r0, S, count[:, :, i, j].flatten(), tot[i, j]) print(j*360.0/nsteps, E1[i, j], E2[i, j], E12[i, j], r0, S, count[:, :, i, j].flatten(), tot[i, j])
\ No newline at end of file
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