In [7]:
%pylab inline
import sys ; sys.path.append("../")
import Icarus


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [245]:
def normalize(x, y, pulse_width):
    hold_int = []
    
    for j in xrange(int(x.max()/pulse_width)):
        minIdx = np.abs(x - pulse_width*j).argmin()
        maxIdx = np.abs(x - pulse_width*(j+1)).argmin()
        peakX = x[minIdx: maxIdx]
        peakY = y[minIdx:maxIdx]	
        
        if j != 7:
            #lt.plot(peakX, peakY)
            if np.sum(peakY) != 0.0:
                hold_int.append( np.sum(peakY) )
        else:
            delay_peak = np.sum(peakY)
    if np.array(hold_int).mean() > 0:
        y = y/np.mean(hold_int)
    
    if np.array(hold_int).mean() > 0:
        g2 = delay_peak/np.array(hold_int).mean()
        g2 = np.around(g2, decimals=3)
    else:
        g2 = 0
    
    return y, g2

In [268]:
def HBT(power = 10, efficiency = 1, int_time = 2000):
    """
    Does HBT correlation in real time on photon streams.
    """
    
    
    qd = Icarus.QuantumDot()
    
    start = None
    stop = None
    
    pulse_width = 25
    delay = 180
    
    starts = []
    stops  = []
    
    
    bins = np.linspace(0, 400, 300)
    counts = np.zeros(bins.size - 1)
    
    for i in xrange(int_time):
        if i%pulse_width == 0:
            
            xlifetime, xxlifetime = qd.generate_lifetimes()
            xxtrue, xtrue = qd.emission(power)
            
            if xxtrue and start is None and (np.random.random_sample() < efficiency):
                start = i + xxlifetime
                starts.append(start)
                
            if xtrue and stop is None and (np.random.random_sample() < efficiency):
                stop = i + xlifetime + delay
                stops.append(stop)
                
            if start is not None and stop is not None:
                temp_counts, bin_edges = np.histogram(stop - start, bins)
                counts += temp_counts
                start = None
                stop = None
            

    counts, g2 = normalize(bins, counts, pulse_width)
    
    plot_histogram(bins - delay ,counts)

In [269]:
def plot_histogram(x, y):
    plt.bar(x[0:x.size-1], y, width = 10)
    plt.xlim([-400, 400])
    plt.xlabel("$\\tau(ns)$")
    plt.ylabel("$g^{(2)}(\\tau)$")

In [270]:
HBT(efficiency=1,int_time=2000)



In [271]:
HBT(efficiency=0.5, int_time=10000)



In [273]:
HBT(power = 100, efficiency=0.3, int_time=100000)



In [250]:
HBT(power = 0.2, efficiency=0.01, int_time=1000000000)