def main():
    
    # coefficients of initial state
    c1 = 0.7
    c2 = 1.0
    
    # length of box
    a  = 1
    
    # detector smearing
    det_smear = 0.1
    
    # detector efficiency if on right side
    det_eff = 0.3

    # events to generate
    nevents = 10000
    
    # for inspection
    h0 = TH1F("h0","h0",400,-2,2)
    
    # write out to file
    fout = open("particle_in_a_box_v3_RealDetector_N"+str(nevents)+".txt","w")
    
    # event generation loop
    for i in range(nevents):

        if i%1000==0:
            print "Processed : ",i

        # get the collapsed wave function of the particle assuming a specific (c1,c2) choice
        pos = GetPositionInterference(c1,c2,a)
        
        # if the true position is on the right side, the decision if it will get detected
        detect = MyRandomLibrary.GetBinomial(det_eff)

        # where the detected position would get smeared to
        smear = MyRandomLibrary.GetRangeUniform(-1*det_smear,det_smear)
        pos_det = pos+smear
    
        if pos>0.5:
            # if true position is on right side, then it may or may not be detected
            if detect==1:
                h0.Fill(pos_det)
                lineout = "{0:10}   {1:10}\n".format(i,pos_det)
                fout.write(lineout)
        else:
            # if it is on left side, it always gets detected
            h0.Fill(pos_det)        
            lineout = "{0:10}   {1:10}\n".format(i,pos_det)
            fout.write(lineout)
        
    fout.close()
        
    # draw histogram for checking
    c = TCanvas("c","c",200,200)
    h0.SetLineColor(1)
    h0.Draw("hist")
    c.SaveAs("datacheck_v3_effsmear.eps")
def GetPositionNoInterference(g1,g2,a):

    #get max val of function
    max=0
    for x in np.arange(0,a,0.1):
        test = EvalNoInterference(g1,g2,a,x)
        if test>max:
            max=test
            
    #print "MaxVal : ",max

    #generate random number
    while True:
        x = MyRandomLibrary.GetRangeUniform(0.0,a)
        y = MyRandomLibrary.GetRangeUniform(0.0,max)
        
        funcVal = EvalNoInterference(g1,g2,a,x)

        if y<funcVal:
            return x
Example #3
0
def main():

    # coefficients of initial state
    c1 = 0.7
    c2 = 1.0

    # length of box
    a = 1

    # detector efficiency if on right side
    det_eff = 0.3

    # events to generate
    nevents = 10000

    # for inspection
    h0 = TH1F("h0", "h0", 400, -2, 2)

    # write out to file
    fout = open("particle_in_a_box_v2_RealDetector_N" + str(nevents) + ".txt",
                "w")

    # event generation loop
    for i in range(nevents):

        if i % 1000 == 0:
            print "Processed : ", i

        # get the collapsed wave function of the particle assuming a specific (c1,c2) choice
        pos = GetPositionInterference(c1, c2, a)

        # probability to detect or not
        detect = MyRandomLibrary.GetBinomial(det_eff)

        if pos > 0.5:
            # if position is on the right side then the detection may or may not happen
            if detect == 1:
                h0.Fill(pos)
                lineout = "{0:10}   {1:10}\n".format(i, pos)
                fout.write(lineout)
        else:
            # but if its on the left side it always happens
            h0.Fill(pos)
            lineout = "{0:10}   {1:10}\n".format(i, pos)
            fout.write(lineout)

    fout.close()

    # print out histogram for checking
    c = TCanvas("c", "c", 200, 200)
    h0.SetLineColor(1)
    h0.Draw("hist")
    c.SaveAs("datacheck_v2_eff.eps")
def main():

    # velocity of particle
    v = 1

    # maximum amount of time that you can wait
    max_waittime = 100

    # width of the box
    box_width = 2

    # for storing the outcome in a histogram
    h = TH1F("h", "h", 20, 0, 2)

    for i in range(100000):

        # print the progress every once in a while
        if i % 1000 == 0:
            print "Event : ", i

        # the amount of time you wait after closing your eyes
        t = MyRandomLibrary.GetRangeUniform(0, max_waittime)

        # the total distance travelled for that single experiment
        x = v * t

        # the number of bounces to know if the modulus will extend from the left or the right
        n_bounces = int(x / box_width)

        # the modulus after the final bounce in the box
        x_leftover = x % box_width

        # print the progress every once in a while
        if i % 1000 == 0:
            print "{0:15} {1:5} {2:15}".format(x, n_bounces, x_leftover)

        if n_bounces % 2 == 0:
            h.Fill(x_leftover)
        else:
            h.Fill(box_width - x_leftover)

    # draw the histogram
    c = TCanvas("c", "c", 200, 200)

    h.SetMinimum(0)
    h.SetMaximum(h.GetBinContent(h.GetMaximumBin()) * 2.0)
    h.GetXaxis().SetTitle("x measured")
    h.GetYaxis().SetTitle("Frequency")

    h.Draw("hist")

    c.SaveAs("classical.eps")