Simulation of CHSH inequality experiment in Excel

  • #36
lostinmygarden said:
A photon that is mostly vertically aligned to a polarizer, will/should be detected as vertically polarized.
Not 100% of the time, no. For example, if you have photons coming out of one polarizer at an angle of 30 degrees, and they encounter a second polarizer at an angle of 0 degrees, not all of them will get through. That is what happens in actual experiments. Note that we are not talking here about pairs of entangled photons, just about single photons going through polarizers. If your model cannot reproduce the correct experimentally observed behavior for single photons going through polarizers, it is of no use in trying to simulate the behavior of entangled photon pairs.
 
  • Like
Likes PeroK
Physics news on Phys.org
  • #37
lostinmygarden said:
This is why detection on a single detector is 50%.
The probability of passing through a single polarizer will not always be 50%. It depends on how the photons are prepared and how the polarizer is aligned. If you are talking about "unpolarized" photons, then yes, the probability of passing through a single polarizer will be 50%, but that will be true for any angle of the polarizer, not just 0 degrees. And once photons have passed through one polarizer, they are no longer "unpolarized".
 
  • Like
Likes PeroK
  • #38
lostinmygarden said:
real world testing cannot actually detect both
It can if you use a polarizing beam splitter (where one output beam is H polarized and the other is V polarized) with detectors in each output beam.
 
  • #39
lostinmygarden said:
You may have quoted, but you are wrong in your conclusions.
What "conclusions"? I'm just pointing out things about what you have posted.

lostinmygarden said:
I clearly state measurement criteria in my document
And you also stated them clearly in posts in this thread. I suppose I am indeed making an assumption, that your posts in this thread accurately describe what is in your Excel document. Are you saying I should not be making that assumption?
 
  • #40
PeterDonis said:
Not 100% of the time, no. For example, if you have photons coming out of one polarizer at an angle of 30 degrees, and they encounter a second polarizer at an angle of 0 degrees, not all of them will get through. That is what happens in actual experiments. Note that we are not talking here about pairs of entangled photons, just about single photons going through polarizers. If your model cannot reproduce the correct experimentally observed behavior for single photons going through polarizers, it is of no use in trying to simulate the behavior of entangled photon pairs.
Again, you have not read my document. Experiments do not know polarization of photons. My test says these are determined at creation and generates results based on the criteria I have written. It may go against what you are saying, this is the point, it is another view. Doing what I suggest will generate S value that exceeds 2, around 50% of the time.
I do not really subscribe to this blocking of photons, that is, all would effectively pass through/ re-emitted (near 100%), but detection of these is 50%.
If you take my suggestions, then telhe simulation and my criteria wouls make more sense. It is not based off of the blocked/not blocked model.
 
  • #41
PeterDonis said:
What "conclusions"? I'm just pointing out things about what you have posted.


And you also stated them clearly in posts in this thread. I suppose I am indeed making an assumption, that your posts in this thread accurately describe what is in your Excel document. Are you saying I should not be making that assumption?
I will include the python code I have updated, if you would like to run it yourself.
Code:
import numpy as np
import pandas as pd

# Step 1: Create a list of 360 values with random angles between 0 and 89
# reducing from 359 to 89 for easier testing of detection
# reducing photons for easier readout
# NoOfPhotons must be a whole number when divided by 90
# photon angles are adjusted to make easier detection criteria.
# this adjustment does not impact detection results, they would be the same, regardless.
# ShowTests is either 1 (output test results) or 0 (just give a value)

NoOfPhotons = 720
photonAngles = 359
ShowTests = 1
L1 = round(NoOfPhotons/4)
L2 = L1 + L1
L3 = L2 + L1
L4 = L3 + L1

angles = np.random.randint(0, photonAngles, NoOfPhotons)

# Step 2: Add a random number between 0 and 1 to each angle
polarizations = angles + np.random.rand(NoOfPhotons)

# Step 3: Create a new column with the same value as the first column (entangled photons)
photon_pairs = pd.DataFrame({'Photon 1': polarizations, 'Photon 2': polarizations.copy()})

# Step 4: Divide the list into 4 separate lists
list_1 = photon_pairs.iloc[:L1]
list_2 = photon_pairs.iloc[L1:L2]
list_3 = photon_pairs.iloc[L2:L3]
list_4 = photon_pairs.iloc[L3:L4]

# Step 5: Detector combinations and angle thresholds for CHSH experiment
# A1 = 0°, A2 = 45°, B1 = 22.5°, B2 = 67.5°

def detector_response(photon_angle, detector_angle):
    """
    Function to simulate detector response
    """
    detectFrom = detector_angle-45
    detectTo = detector_angle+45
    ogPhotonAngle = photon_angle

    # fix photon_angle to fit measurement criteria 
    if photon_angle > 180:
        photon_angle = photon_angle-180
    if photon_angle > 90:
        photon_angle = 180-photon_angle

    if ShowTests == 1:
        print("unmodified photon angle: ", ogPhotonAngle)
        print("1. Photon: ",photon_angle)
        print("2. Detector angle: ",detector_angle)
        print("3. Detection range: ",detectFrom," to ",detectTo)
        print("4. Result: ",photon_angle % 360 <=detectTo and photon_angle % 360 >=detectFrom)
        print("")
    return photon_angle % 360<=detectTo and photon_angle % 360>=detectFrom


# Detector responses for each list
results_A1B1 = list_1.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A1B2 = list_2.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 67.5), axis=1)
results_A2B1 = list_3.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A2B2 = list_4.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 67.5), axis=1)

# Step 6: Calculate the S value using the standard CHSH formula
# S = |E(A1,B1) - E(A1,B2) + E(A2,B1) + E(A2,B2)|

def expectation_value(results):
    """
    Function to calculate the expectation value from the detector results.
    """
    return 2 * np.mean(results) - 1

E_A1B1 = expectation_value(results_A1B1)
E_A1B2 = expectation_value(results_A1B2)
E_A2B1 = expectation_value(results_A2B1)
E_A2B2 = expectation_value(results_A2B2)

S_value = abs(E_A1B1 - E_A1B2 + E_A2B1 + E_A2B2)
print("S value: ",S_value)
 
  • #42
lostinmygarden said:
Experiments do not know polarization of photons.
Um, what? Experimenters measure photon polarizations all the time.

lostinmygarden said:
I do not really subscribe to this blocking of photons
Again, what? It happens in experiments with photons and polarizers all the time.

At this point I simply can't make sense of what you are saying so I'll bow out and let someone else attempt it if they want to.
 
  • #43
PeterDonis said:
Um, what? Experimenters measure photon polarizations all the time.

At this point I simply can't make sense of what you are saying so I'll bow out and let someone else attempt it if they want to.
Please show me an experiment which tells you the exact polarization of a photon, prior to it being modified by a polarizer.
 
  • #44
lostinmygarden said:
Please show me an experiment which tells you the exact polarization of a photon, prior to it being modified by a polarizer.
PeterDonis said:
At this point I simply can't make sense of what you are saying so I'll bow out
Read what you quoted from me (which I just re-quoted above) again.
 
  • #45
lostinmygarden said:
Please show me an experiment which tells you the exact polarization of a photon, prior to it being modified by a polarizer.
And I mean the exact angle, not a yes/no answer
 
  • #46
PeterDonis said:
Read what you quoted from me (which I just re-quoted above) again.
Yes, I think it is a good time for you to do so.
 
  • #47
lostinmygarden said:
I appreciate any constructive feedback on this.
Two more things you may want to consider:

First, 1440 pairs may not be enough (and because of the issue below in fact you only have 360, repeated four times.) The simulation here (uses spin-1/2 particles and the original form of Bell's inequality, pedagogically better and experimentally worse than CHSH with photons) routinely finds inequality violations just from statistical variance across a thousand test cases. See how it works with, say 10,000 pairs.

Second, your input angles are not randomly distributed across the range from 0 to ##2\pi##, the distribution is too flat. It may be that this doesn't matter, but it is silly to develop a simulation with the wrong probability distribution and then develop an argument that it won't matter when you could use the right distribution from the start.
 
  • Like
Likes lostinmygarden
  • #48
Nugatory said:
Two more things you may want to consider:

First, 1440 pairs may not be enough (and because of the issue below in fact you only have 360, repeated four times.) The simulation here (uses spin-1/2 particles and the original form of Bell's inequality, pedagogically better and experimentally worse than CHSH with photons) routinely finds inequality violations just from statistical variance across a thousand test cases. See how it works with, say 10,000 pairs.

Second, your input angles are not randomly distributed across the range from 0 to ##2\pi##, the distribution is too flat. It may be that this doesn't matter, but it is silly to develop a simulation with the wrong probability distribution and then develop an argument that it won't matter when you could use the right distribution from the start.
Thanks. Yes, I didn't go too large in excel as it doesn't like it much. It gives the general idea, but it is limited. I will try my python equivalent. I wasn't intending on using python, but I have made it scalable. I'll ensure it just generates a random distribution too.
 
  • #49
Nugatory said:
Two more things you may want to consider:

First, 1440 pairs may not be enough (and because of the issue below in fact you only have 360, repeated four times.) The simulation here (uses spin-1/2 particles and the original form of Bell's inequality, pedagogically better and experimentally worse than CHSH with photons) routinely finds inequality violations just from statistical variance across a thousand test cases. See how it works with, say 10,000 pairs.

Second, your input angles are not randomly distributed across the range from 0 to ##2\pi##, the distribution is too flat. It may be that this doesn't matter, but it is silly to develop a simulation with the wrong probability distribution and then develop an argument that it won't matter when you could use the right distribution from the start.
The code randomly generates angles between 0 and 359, then adds a random number between 0 and 1. This is to ensure values are between 0 and 360, also ensures that angles can vary, very slightly. It does this for each photon generated.

I ran with 10800 photons in python and on first run got S = 2.0370370370370368. This can always vary, as does real world testing results.
 
  • #50
lostinmygarden said:
I will try my python equivalent.
Python will minimize another concern, namely the quality of the random number generator, but still sanity check your generated data and that the raw measurement results pass minimal sanity tests.
And to avoid possible floating point arithmetic artifacts do everything from the start in radians.
 
  • Like
Likes lostinmygarden
  • #51
Nugatory said:
Python will minimize another concern, namely the quality of the random number generator, but still sanity check your generated data and that the raw measurement results pass minimal sanity tests.
And to avoid possible floating point arithmetic artifacts do everything from the start in radians.
I have added a flag to enable and disable test output. The logic passes sanity checks.
Nugatory said:
Python will minimize another concern, namely the quality of the random number generator, but still sanity check your generated data and that the raw measurement results pass minimal sanity tests.
And to avoid possible floating point arithmetic artifacts do everything from the start in radians.
There is a flag to enable and disable test output. The logic passes sanity checks. I'll look into adapting this to radians too. Pass my bedtime here now. Thank you for your feedback ☺️
 
  • #52
Nugatory said:
Python will minimize another concern, namely the quality of the random number generator, but still sanity check your generated data and that the raw measurement results pass minimal sanity tests.
And to avoid possible floating point arithmetic artifacts do everything from the start in radians.
I have added a flag to enable and disable test output. The logic passes sanity checks.
lostinmygarden said:
TL;DR Summary: I have tried to create a simulation of CHSH experiment in Excel. I am assuming photons have a set polarization after creation and the entangled pairs have the same polarization. I would like feedback on this.

I would like reviews of the CHSH inequality experiment simulation, that I have created in excel.

This is an open share, you can access anonymously in a private browser session.

https://1drv.ms/x/s!Arfr_5NFNXw8aPC38X3LUGQI7oU?e=hDQTof

The simulation follows setup as per those listed here -

https://en.m.wikipedia.org/wiki/CHSH_inequality

My simulation is set to test photons with fixed polarization after creation, also the entangled photons would have identical polarization. This is a Local hidden variables simulation.

In running this simulation, CHSH values for S can exceed 2 around 50% of the time, as per real world tests (in real world tests, false negatives and positives suggest that this can impact results, these of course are not possible in the simulation).

The simulation creates 1440 (2880 if you account for the partner photon that is identical) photons with random polarization angles between 0 and 360, ensuring an even distribution. 360 was chosen for ease of measurements; for example, 45 degree polarization is detected the same as 225 degrees, as they have the same polarization.

These photons are then randomly ordered and assigned for measurement, evenly, across the 4 detector combinations (a,b a1,b a,b1 a1,b1), ensuring photons from the ones created, are only measured once.

I was under the impression that if you assume fixed polarization prior to measurement (LHV), then simulations cannot achieve value S>2.

My thinking here is that, due to the combination of separate measurements for detector combinations, can lead to a result where value S>2.

This is an early version of my test simulation in excel (it works well for it and it is quite visual, in that you can see how everything is set up and where results come from. Hopefully not many errors in it, if so, I will correct them following feedback from here).

I appreciate any constructive feedback on this.

Thanks

This isPython code to simulate same as excel document, with some adjustments.
S value can be achieved around 50% of the time, simply re-run simulation.

In this code, you can amend NoOfPhotons to create a set amount of randomly generated photon pairs (given by their polarization).
ShowTests will output the results of individual photons measurements when set to 1, otherwise just S value will be given.

Code:
import numpy as np
import pandas as pd

# NoOfPhotons must be a whole number when divided by 90

NoOfPhotons = 720
photonAngles = 359
ShowTests = 1
L1 = round(NoOfPhotons/4)
L2 = L1 + L1
L3 = L2 + L1
L4 = L3 + L1

angles = np.random.randint(0, photonAngles, NoOfPhotons)

# Step 2: Add a random number between 0 and 1 to each angle
polarizations = angles + np.random.rand(NoOfPhotons)

# Step 3: Create a new column with the same value as the first column (entangled photons)
photon_pairs = pd.DataFrame({'Photon 1': polarizations, 'Photon 2': polarizations.copy()})

# Step 4: Divide the list into 4 separate lists
list_1 = photon_pairs.iloc[:L1]
list_2 = photon_pairs.iloc[L1:L2]
list_3 = photon_pairs.iloc[L2:L3]
list_4 = photon_pairs.iloc[L3:L4]

# Step 5: Detector combinations and angle thresholds for CHSH experiment
# A1 = 0°, A2 = 45°, B1 = 22.5°, B2 = 67.5°

def detector_response(photon_angle, detector_angle):
    """
    Function to simulate detector response
    """
    detectFrom = detector_angle-45
    detectTo = detector_angle+45
    ogPhotonAngle = photon_angle

    # fix photon_angle to fit measurement criteria 
    if photon_angle > 180:
        photon_angle = photon_angle-180
    if photon_angle > 90:
        photon_angle = 180-photon_angle

    if ShowTests == 1:
        print("unmodified photon angle: ", ogPhotonAngle)
        print("1. Photon: ",photon_angle)
        print("2. Detector angle: ",detector_angle)
        print("3. Detection range: ",detectFrom," to ",detectTo)
        print("4. Result: ",photon_angle % 360 <=detectTo and photon_angle % 360 >=detectFrom)
        print("")
    return photon_angle % 360<=detectTo and photon_angle % 360>=detectFrom


# Detector responses for each list
results_A1B1 = list_1.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A1B2 = list_2.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 67.5), axis=1)
results_A2B1 = list_3.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A2B2 = list_4.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 67.5), axis=1)

# Step 6: Calculate the S value using the standard CHSH formula
# S = |E(A1,B1) - E(A1,B2) + E(A2,B1) + E(A2,B2)|

def expectation_value(results):
    """
    Function to calculate the expectation value from the detector results.
    """
    return 2 * np.mean(results) - 1

E_A1B1 = expectation_value(results_A1B1)
E_A1B2 = expectation_value(results_A1B2)
E_A2B1 = expectation_value(results_A2B1)
E_A2B2 = expectation_value(results_A2B2)

S_value = abs(E_A1B1 - E_A1B2 + E_A2B1 + E_A2B2)
print("S value: ",S_value)
 
  • #53
lostinmygarden said:
Again, you have not read my document. Experiments do not know polarization of photons. My test says these are determined at creation and generates results based on the criteria I have written. It may go against what you are saying, this is the point, it is another view. Doing what I suggest will generate S value that exceeds 2, around 50% of the time.
I do not really subscribe to this blocking of photons, that is, all would effectively pass through/ re-emitted (near 100%), but detection of these is 50%.
If you take my suggestions, then telhe simulation and my criteria wouls make more sense. It is not based off of the blocked/not blocked model.
Bell's theorem proves mathematically that this cannot reproduce the predictions of QM. Your model must be wrong in some way.
 
  • Like
Likes DrChinese and Lord Jestocost
  • #54
Nugatory said:
Python will minimize another concern, namely the quality of the random number generator, but still sanity check your generated data and that the raw measurement results pass minimal sanity tests.
And to avoid possible floating point arithmetic artifacts do everything from the start in radians.
I have added a flag to enable and disable test output. The logic passes sanity checks.
lostinmygarden said:
TL;DR Summary: I have tried to create a simulation of CHSH experiment in Excel. I am assuming photons have a set polarization after creation and the entangled pairs have the same polarization. I would like feedback on this.

I would like reviews of the CHSH inequality experiment simulation, that I have created in excel.

This is an open share, you can access anonymously in a private browser session.

https://1drv.ms/x/s!Arfr_5NFNXw8aPC38X3LUGQI7oU?e=hDQTof

The simulation follows setup as per those listed here -

https://en.m.wikipedia.org/wiki/CHSH_inequality

My simulation is set to test photons with fixed polarization after creation, also the entangled photons would have identical polarization. This is a Local hidden variables simulation.

In running this simulation, CHSH values for S can exceed 2 around 50% of the time, as per real world tests (in real world tests, false negatives and positives suggest that this can impact results, these of course are not possible in the simulation).

The simulation creates 1440 (2880 if you account for the partner photon that is identical) photons with random polarization angles between 0 and 360, ensuring an even distribution. 360 was chosen for ease of measurements; for example, 45 degree polarization is detected the same as 225 degrees, as they have the same polarization.

These photons are then randomly ordered and assigned for measurement, evenly, across the 4 detector combinations (a,b a1,b a,b1 a1,b1), ensuring photons from the ones created, are only measured once.

I was under the impression that if you assume fixed polarization prior to measurement (LHV), then simulations cannot achieve value S>2.

My thinking here is that, due to the combination of separate measurements for detector combinations, can lead to a result where value S>2.

This is an early version of my test simulation in excel (it works well for it and it is quite visual, in that you can see how everything is set up and where results come from. Hopefully not many errors in it, if so, I will correct them following feedback from here).

I appreciate any constructive feedback on this.

Thanks

This isPython code to simulate same as excel document, with some adjustments.
S value can be achieved around 50% of the time, simply re-run simulation.
In this code, you can amend NoOfPhotons to create a set amount of randomly generated photon pairs (given by their polarization).
ShowTests will output the results of individual photons measurements when set to 1, otherwise just S value will be given.

Code:
import numpy as np
import pandas as pd

# NoOfPhotons must be a whole number when divided by 90

NoOfPhotons = 720
photonAngles = 359
ShowTests = 1
L1 = round(NoOfPhotons/4)
L2 = L1 + L1
L3 = L2 + L1
L4 = L3 + L1

angles = np.random.randint(0, photonAngles, NoOfPhotons)

# Step 2: Add a random number between 0 and 1 to each angle
polarizations = angles + np.random.rand(NoOfPhotons)

# Step 3: Create a new column with the same value as the first column (entangled photons)
photon_pairs = pd.DataFrame({'Photon 1': polarizations, 'Photon 2': polarizations.copy()})

# Step 4: Divide the list into 4 separate lists
list_1 = photon_pairs.iloc[:L1]
list_2 = photon_pairs.iloc[L1:L2]
list_3 = photon_pairs.iloc[L2:L3]
list_4 = photon_pairs.iloc[L3:L4]

# Step 5: Detector combinations and angle thresholds for CHSH experiment
# A1 = 0°, A2 = 45°, B1 = 22.5°, B2 = 67.5°

def detector_response(photon_angle, detector_angle):
    """
    Function to simulate detector response
    """
    detectFrom = detector_angle-45
    detectTo = detector_angle+45
    ogPhotonAngle = photon_angle

    # fix photon_angle to fit measurement criteria
    if photon_angle > 180:
        photon_angle = photon_angle-180
    if photon_angle > 90:
        photon_angle = 180-photon_angle

    if ShowTests == 1:
        print("unmodified photon angle: ", ogPhotonAngle)
        print("1. Photon: ",photon_angle)
        print("2. Detector angle: ",detector_angle)
        print("3. Detection range: ",detectFrom," to ",detectTo)
        print("4. Result: ",photon_angle % 360 <=detectTo and photon_angle % 360 >=detectFrom)
        print("")
    return photon_angle % 360<=detectTo and photon_angle % 360>=detectFrom


# Detector responses for each list
results_A1B1 = list_1.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A1B2 = list_2.apply(lambda row: detector_response(row['Photon 1'], 0) == detector_response(row['Photon 2'], 67.5), axis=1)
results_A2B1 = list_3.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 22.5), axis=1)
results_A2B2 = list_4.apply(lambda row: detector_response(row['Photon 1'], 45) == detector_response(row['Photon 2'], 67.5), axis=1)

# Step 6: Calculate the S value using the standard CHSH formula
# S = |E(A1,B1) - E(A1,B2) + E(A2,B1) + E(A2,B2)|

def expectation_value(results):
    """
    Function to calculate the expectation value from the detector results.
    """
    return 2 * np.mean(results) - 1

E_A1B1 = expectation_value(results_A1B1)
E_A1B2 = expectation_value(results_A1B2)
E_A2B1 = expectation_value(results_A2B1)
E_A2B2 = expectation_value(results_A2B2)

S_value = abs(E_A1B1 - E_A1B2 + E_A2B1 + E_A2B2)
print("S value: ",S_value)
PeroK said:
Bell's theorem proves mathematically that this cannot reproduce the predictions of QM. Your model must be wrong in some way.
If you run a single list against all detector combinations, you reach the S=2 value, constantly. This is supposedly the LHV limit and probably derived from that thinking. The tests that show S>2 are all independent, separate tests, that are combined at the end. This seemingly allows S>2. My approach gives photons definitive polarization at creation and detection is set within boundaries that would be typical for vertical and horizontal detection. There certainly could be mistakes, but the math is relatively simple as you can see in the code. Th excel document is more visual and contains, essentially, the same calculations.
 
  • #56
lostinmygarden said:
There certainly could be mistakes
I added one of the sanity tests suggested in post #14:
Code:
raw = {0.0:[0,0,0], 22.5:[0,0,0], 45.0:[0,0,0], 67.5:[0,0,0]}
.................
def detector_response(photon_angle, detector_angle):
    ........
    r = photon_angle % 360<=detectTo and photon_angle % 360>=detectFrom
    if r:
      raw[detector_angle][0] += 1
    else:
      raw[detector_angle][1] += 1
    raw[detector_angle][2] += 1
    return r
...........
S_value = abs(E_A1B1 - E_A1B2 + E_A2B1 + E_A2B2)
print("S value: ",S_value)

print(raw)
to get the output
Code:
python orig
S value:  1.9555555555555557
{0.0: [189, 171, 360], 22.5 :[286, 74, 360], 45.0: [360, 0, 360], 67.5: [265, 95, 360]}
so something seems wrong with either the data distribution or the detector_response function.

I am also somewhat perplexed by the definition of the expectation_value function. Why not do the calculation directly from the simulated results as is usually done:$$E=\frac{N_{++}+N_{+-}-N_{-+}+N_{--}}{N_{++}+N_{+-}+N_{-+}+N_{--}}$$
 
  • #57
Nugatory said:
I added one of the sanity tests suggested in post #14:
Code:
raw = {0.0:[0,0,0], 22.5:[0,0,0], 45.0:[0,0,0], 67.5:[0,0,0]}
.................
def detector_response(photon_angle, detector_angle):
    ........
    r = photon_angle % 360<=detectTo and photon_angle % 360>=detectFrom
    if r:
      raw[detector_angle][0] += 1
    else:
      raw[detector_angle][1] += 1
    raw[detector_angle][2] += 1
    return r
...........
S_value = abs(E_A1B1 - E_A1B2 + E_A2B1 + E_A2B2)
print("S value: ",S_value)

print(raw)
to get the output
Code:
python orig
S value:  1.9555555555555557
{0.0: [189, 171, 360], 22.5 :[286, 74, 360], 45.0: [360, 0, 360], 67.5: [265, 95, 360]}
so something seems wrong with either the data distribution or the detector_response function.

I am also somewhat perplexed by the definition of the expectation_value function. Why not do the calculation directly from the simulated results as is usually done:$$E=\frac{N_{++}+N_{+-}-N_{-+}+N_{--}}{N_{++}+N_{+-}+N_{-+}+N_{--}}$$
Feel free to make amendments, I really appreciate it. I haven't done programming in years, so bit slow. If you enable the output of test data, you will see how it handles the angles and how it checks if detected or not.
I'm probably not going to be able to do much this evening, but will try and recreate it another way.
 

Similar threads

Replies
17
Views
848
Replies
1
Views
1K
Replies
49
Views
3K
Replies
80
Views
4K
Replies
4
Views
651
Replies
4
Views
1K
Replies
1
Views
999
Replies
5
Views
1K
  • Quantum Physics
Replies
16
Views
2K
Replies
58
Views
925
Back
Top