Example #1
0
def make_d(iter_array):
    [Q, T, St, N, F, Tf, Ts, R, a, v] = iter_array
    Strig = 2
    d = np.zeros((200, len(Q)))
    t0 = np.zeros(len(Q))
    trig = np.random.normal(0, Strig, 1)
    ex = np.random.binomial(N, 1 - R)
    recomb = N - ex
    t = np.zeros(recomb + ex)
    u = np.random.uniform(size=recomb)
    t[:recomb] += 1 / a * (u / (1 - u))
    ch = np.random.choice(2, size=recomb + ex, replace=True, p=[F, 1 - F])
    t[ch == 0] += np.random.exponential(Tf, len(t[ch == 0]))
    t[ch == 1] += np.random.exponential(Ts, len(t[ch == 1]))
    slow_i = np.nonzero(ch == 1)[0]
    fast_i = np.nonzero(ch == 0)[0]

    costheta = np.random.uniform(-1, 1, len(t))
    phi = np.random.uniform(0, 2 * np.pi, len(t))
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v, us)
    for j in range(len(Q)):
        hits = np.nonzero(pmt_hit == j)[0]
        ind = np.nonzero(1 == np.random.choice(
            2, size=len(hits), replace=True, p=[1 - Q[j], Q[j]]))[0]
        tj = np.random.normal(trig + T[j] + t[hits[ind]], St[j], len(ind))
        h, bins = np.histogram(tj, bins=np.arange(201))
        d[:, j] = h
        if np.any(h > 0):
            t0[j] = np.amin(np.nonzero(h > 0)[0])
    for j in range(len(Q)):
        d[:, j] = np.roll(d[:, j], -int(np.amin(t0)))
    return d[:100]
Example #2
0
def make_d_show(iter_array):
    [Q, T, St, N, F, Tf, Ts, R, a, eta, v, f] = iter_array
    Strig = 2
    d = np.zeros((5, 200, len(Q)))
    # trp=np.zeros((N_events, 200, len(Q)))
    # sng=np.zeros((N_events, 200, len(Q)))
    # Rtrp=np.zeros((N_events, 200, len(Q)))
    # Rsng=np.zeros((N_events, 200, len(Q)))
    t0 = np.zeros(len(Q))
    trig = np.random.normal(0, Strig, 1)
    ex = np.random.binomial(N, 1 - R)
    recomb = np.random.binomial(N - ex, 1 - eta)
    t = np.zeros(recomb + ex)
    t[:recomb] += np.random.choice(np.arange(len(f[:])) / 5,
                                   size=recomb,
                                   replace=True,
                                   p=f[:])
    ch = np.random.choice(2, size=recomb + ex, replace=True, p=[F, 1 - F])
    t[ch == 0] += np.random.exponential(Tf, len(t[ch == 0]))
    t[ch == 1] += np.random.exponential(Ts, len(t[ch == 1]))
    slow_i = np.nonzero(ch == 1)[0]
    fast_i = np.nonzero(ch == 0)[0]

    costheta = np.random.uniform(-1, 1, len(t))
    phi = np.random.uniform(0, 2 * np.pi, len(t))
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v, us)
    for j in range(len(Q)):
        hits = np.nonzero(pmt_hit == j)[0]
        ind = np.nonzero(1 == np.random.choice(
            2, size=len(hits), replace=True, p=[1 - Q[j], Q[j]]))[0]
        tj = np.random.normal(trig + T[j] + t[hits[ind]], St[j], len(ind))
        h, bins = np.histogram(tj, bins=np.arange(201))
        d[0, :, j] = h
        d[1, :, j] = np.histogram(tj[np.nonzero(
            np.logical_and(hits[ind] >= recomb, np.isin(hits[ind],
                                                        slow_i)))[0]],
                                  bins=np.arange(201))[0]
        d[2, :, j] = np.histogram(tj[np.nonzero(
            np.logical_and(hits[ind] >= recomb, np.isin(hits[ind],
                                                        fast_i)))[0]],
                                  bins=np.arange(201))[0]
        d[3, :, j] = np.histogram(tj[np.nonzero(
            np.logical_and(hits[ind] < recomb, np.isin(hits[ind],
                                                       slow_i)))[0]],
                                  bins=np.arange(201))[0]
        d[4, :, j] = np.histogram(tj[np.nonzero(
            np.logical_and(hits[ind] < recomb, np.isin(hits[ind],
                                                       fast_i)))[0]],
                                  bins=np.arange(201))[0]
        if np.any(h > 0):
            t0[j] = np.amin(np.nonzero(h > 0)[0])
    for i in range(5):
        for j in range(len(Q)):
            d[i, :, j] = np.roll(d[i, :, j], -int(np.amin(t0)))
    return d
Example #3
0
def make_d(N,Q,v):
    s=np.zeros((len(N), len(Q)))
    for i in range(len(N)):
        costheta=np.random.uniform(-1,1, N[i])
        phi=np.random.uniform(0,2*np.pi, N[i])
        us=np.vstack((np.vstack((np.sin(np.arccos(costheta))*np.cos(phi), np.sin(np.arccos(costheta))*np.sin(phi))), costheta))
        pmt_hit=whichPMT(v[i], us)
        for j in range(len(Q)):
            s[i, j]=np.random.binomial(len(np.nonzero(pmt_hit==j)[0]), Q[j])
    return s
Example #4
0
def make_d_show(iter_array):
    [Q, T, St, N, F, Tf, Ts, R, a, v, dl] = iter_array
    Strig = 2
    d = np.zeros((6, 200, len(Q)))
    t0 = np.zeros(len(Q))
    trig = np.random.normal(0, Strig, 1)
    ex = np.random.binomial(N, 1 - R)
    sr = np.random.binomial(ex, dl)
    recomb = N - ex
    t = np.zeros(recomb + ex)
    u = np.random.uniform(size=recomb)
    t[sr:sr + recomb] += 1 / a * (u / (1 - u))
    ch = np.random.choice(2, size=recomb + ex - sr, replace=True, p=[F, 1 - F])
    slow_i = sr + np.nonzero(ch == 1)[0]
    fast_i = sr + np.nonzero(ch == 0)[0]
    t[fast_i] += np.random.exponential(Tf, len(fast_i))
    t[slow_i] += np.random.exponential(Ts, len(slow_i))

    costheta = np.random.uniform(-1, 1, len(t))
    phi = np.random.uniform(0, 2 * np.pi, len(t))
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v, us)
    for j in range(len(Q)):
        hits = np.nonzero(pmt_hit == j)[0]
        ind = np.nonzero(1 == np.random.choice(
            2, size=len(hits), replace=True, p=[1 - Q[j], Q[j]]))[0]
        tj = np.random.normal(trig + T[j] + t[hits[ind]], St[j], len(ind))
        h = np.histogram(tj, bins=np.arange(201))[0]
        d[0, :, j] = h
        d[1, :, j] = np.histogram(tj[hits[ind] < sr], bins=np.arange(201))[0]
        d[2, :, j] = np.histogram(tj[np.logical_and(hits[ind] >= sr + recomb,
                                                    np.isin(hits[ind],
                                                            slow_i))],
                                  bins=np.arange(201))[0]
        d[3, :, j] = np.histogram(tj[np.logical_and(hits[ind] >= sr + recomb,
                                                    np.isin(hits[ind],
                                                            fast_i))],
                                  bins=np.arange(201))[0]
        d[4, :, j] = np.histogram(tj[np.logical_and(
            np.logical_and(hits[ind] >= sr, hits[ind] < sr + recomb),
            np.isin(hits[ind], slow_i))],
                                  bins=np.arange(201))[0]
        d[5, :, j] = np.histogram(tj[np.logical_and(
            np.logical_and(hits[ind] >= sr, hits[ind] < sr + recomb),
            np.isin(hits[ind], fast_i))],
                                  bins=np.arange(201))[0]

        if np.any(h > 0):
            t0[j] = np.amin(np.nonzero(h > 0)[0])
    for i in range(np.shape(d)[0]):
        for j in range(len(Q)):
            d[i, :, j] = np.roll(d[i, :, j], -int(np.amin(t0)))
    return d
Example #5
0
def make_d(iter_array):
    [Q, N, v] = iter_array
    costheta = np.random.uniform(-1, 1, N)
    phi = np.random.uniform(0, 2 * np.pi, N)
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v, us)
    s = np.zeros(len(Q))
    for j in range(len(Q)):
        s[j] = np.random.binomial(len(np.nonzero(pmt_hit == j)[0]), Q[j])
    return s
Example #6
0
def make_d_show(iter_array):
    [Q, T, St, Sa, N, F, Tf, Ts, R, a, v]=iter_array
    Strig=2
    d=np.zeros((5, 200, len(Q)))
    t0=np.zeros(len(Q))
    trig=np.random.normal(0, Strig, 1)
    ex=np.random.binomial(N, 1-R)
    recomb=N-ex
    t=np.zeros(recomb+ex)
    u=np.random.uniform(size=recomb)
    t[:recomb]+=1/a*(u/(1-u))
    ch=np.random.choice(2, size=recomb+ex, replace=True, p=[F, 1-F])
    t[ch==0]+=np.random.exponential(Tf, len(t[ch==0]))
    t[ch==1]+=np.random.exponential(Ts, len(t[ch==1]))
    slow_i=np.nonzero(ch==1)[0]
    fast_i=np.nonzero(ch==0)[0]

    costheta=np.random.uniform(-1,1, len(t))
    phi=np.random.uniform(0,2*np.pi, len(t))
    us=np.vstack((np.vstack((np.sin(np.arccos(costheta))*np.cos(phi), np.sin(np.arccos(costheta))*np.sin(phi))), costheta))
    pmt_hit=whichPMT(v, us)
    for j in range(len(Q)):
        hits=np.nonzero(pmt_hit==j)[0]
        ind=np.nonzero(1==np.random.choice(2, size=len(hits), replace=True, p=[1-Q[j], Q[j]]))[0]
        tj=np.random.normal(trig+T[j]+t[hits[ind]], St[j], len(ind))
        h0, bins=np.histogram(tj, bins=np.arange(201))
        As=np.random.normal(loc=h0[h0>0], scale=np.sqrt(h0[h0>0]*Sa[j]))
        d[0,h0>0,j]+=np.round(As).astype(int)

        h=np.histogram(tj[np.nonzero(np.logical_and(hits[ind]>=recomb, np.isin(hits[ind], slow_i)))[0]], bins=np.arange(201))[0]
        As=np.random.normal(loc=h[h>0], scale=np.sqrt(h[h>0]*Sa[j]))
        d[1,h>0,j]+=np.round(As).astype(int)

        h=np.histogram(tj[np.nonzero(np.logical_and(hits[ind]>=recomb, np.isin(hits[ind], fast_i)))[0]], bins=np.arange(201))[0]
        As=np.random.normal(loc=h[h>0], scale=np.sqrt(h[h>0]*Sa[j]))
        d[2,h>0,j]+=np.round(As).astype(int)

        h=np.histogram(tj[np.nonzero(np.logical_and(hits[ind]<recomb, np.isin(hits[ind], slow_i)))[0]], bins=np.arange(201))[0]
        As=np.random.normal(loc=h[h>0], scale=np.sqrt(h[h>0]*Sa[j]))
        d[3,h>0,j]+=np.round(As).astype(int)

        h=np.histogram(tj[np.nonzero(np.logical_and(hits[ind]<recomb, np.isin(hits[ind], fast_i)))[0]], bins=np.arange(201))[0]
        As=np.random.normal(loc=h[h>0], scale=np.sqrt(h[h>0]*Sa[j]))
        d[4,h>0,j]+=np.round(As).astype(int)

        if np.any(h0>0):
            t0[j]=np.amin(np.nonzero(h0>0)[0])
    for i in range(5):
        for j in range(len(Q)):
            d[i,:,j]=np.roll(d[i,:,j], -int(np.amin(t0)))
    return d
Example #7
0
def make_d(iter):
    x1, x2, Q, Sa, N, i = iter
    np.random.seed(int(i * time.time() % (2**32)))
    s = np.zeros(len(Q))
    costheta = np.random.uniform(-1, 1, N)
    phi = np.random.uniform(0, 2 * np.pi, N)
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))

    vs = np.zeros((3, N))
    count = 0
    while count < N:
        #d=np.random.exponential(mu, N-count)
        d = np.random.uniform(0, 0.5, N - count)
        ind = np.nonzero(d < 0.5)[0]
        if len(ind) == 1:
            X1 = d[ind] - 0.25
            r = np.sqrt(np.random.uniform(0, 0.25**2 - X1**2))
            phi = np.random.uniform(0, 2 * np.pi)
            v = np.zeros((3, 1))
            v[x1] = X1
            v[x2] = r * np.cos(phi)
            v[2] = r * np.sin(phi)
            vs[:, count:count + 1] = v
            count += 1
        else:
            X1 = d[ind] - 0.25
            r = np.sqrt(np.random.uniform(0, 0.25**2 - X1**2))
            phi = np.random.uniform(0, 2 * np.pi, len(r))
            v = np.zeros((3, len(r)))
            v[x1] = X1
            v[x2] = r * np.cos(phi)
            v[2] = r * np.sin(phi)
            vs[:, count:count + len(r)] = v
            count += len(r)
    pmt_hit = whichPMT(vs, us)
    for j in range(len(Q)):
        area = np.sum(
            np.random.normal(
                1, Sa[j],
                np.random.binomial(len(np.nonzero(pmt_hit == j)[0]), Q[j])))
        #s[j]=np.random.binomial(len(np.nonzero(pmt_hit==j)[0]), Q[j])
        if area > 0:
            s[j] = int(np.round(area))
    return s
Example #8
0
def make_d(iter):
    np.random.seed(int(iter * time.time() % (2 * 32)))
    Strig = 2
    d = np.zeros((200, len(Q)))

    t0 = np.zeros(len(Q))
    trig = np.random.normal(0, Strig, 1)
    N_glob = np.random.poisson(N.value)
    ex = np.random.binomial(N_glob, 1 - R.value)
    recomb = np.random.binomial(N_glob - ex, 1 - eta.value)
    t = np.zeros(recomb + ex)
    t[:recomb] += np.random.choice(np.arange(len(f)) / 5,
                                   size=recomb,
                                   replace=True,
                                   p=f)
    ch = np.random.choice(2,
                          size=recomb + ex,
                          replace=True,
                          p=[F.value, 1 - F.value])
    t[ch == 0] += np.random.exponential(Tf.value, len(t[ch == 0]))
    t[ch == 1] += np.random.exponential(Ts.value, len(t[ch == 1]))
    slow_i = np.nonzero(ch == 1)[0]
    fast_i = np.nonzero(ch == 0)[0]

    costheta = np.random.uniform(-1, 1, len(t))
    phi = np.random.uniform(0, 2 * np.pi, len(t))
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v[iter], us)

    for j in range(len(Q)):
        hits = np.nonzero(pmt_hit == j)[0]
        ind = np.nonzero(1 == np.random.choice(
            2, size=len(hits), replace=True, p=[1 - Q[j], Q[j]]))[0]
        tj = np.random.normal(trig + T[j] + t[hits[ind]], St[j], len(ind))
        h, bins = np.histogram(tj, bins=np.arange(201))
        d[:, j] = h
        if np.any(h > 0):
            t0[j] = np.amin(np.nonzero(h > 0)[0])
    for j in range(len(Q)):
        d[:, j] = np.roll(d[:, j], -int(np.amin(t0)))
    return d
Example #9
0
def make_d(iter):
    N, Q, Sa, v, i, Abins = iter
    np.random.seed(int(i * time.time() % (2**32)))
    s = np.zeros(len(Q))
    costheta = np.random.uniform(-1, 1, N)
    phi = np.random.uniform(0, 2 * np.pi, N)
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    pmt_hit = whichPMT(v.reshape(3, 1), us)
    # pmt_hit=whichPMT(vs, us)
    Areas = np.zeros((len(Q), len(Abins[0]) - 1))
    for j in range(len(Q)):
        areas = np.random.normal(
            1, Sa[j], np.random.binomial(len(np.nonzero(pmt_hit == j)[0]),
                                         Q[j]))
        Areas[j] = np.histogram(areas, bins=Abins[j])[0]
        #s[j]=np.random.binomial(len(np.nonzero(pmt_hit==j)[0]), Q[j])
        A = np.sum(areas)
        if A > 0:
            s[j] = int(np.round(A))
    return [s, Areas]
Example #10
0
def make_d(iter):
    Q, N, v, i = iter
    np.random.seed(int(i * time.time() % (2**32)))
    s = np.zeros(len(Q))
    costheta = np.random.uniform(-1, 1, N)
    phi = np.random.uniform(0, 2 * np.pi, N)
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    vs = np.repeat(v, N).reshape(3, N)
    # count=np.zeros(N)
    # while np.any(np.sqrt(np.sum(vs**2, axis=0))<0.75):
    #
    #     absorb=np.nonzero(count>10)[0]
    #     vs[0,absorb]=2
    #     us[:,absorb]=vs[:,absorb]
    #
    #     ind_LXe=np.nonzero(np.sqrt(np.sum(vs**2, axis=0))<=0.25)[0]
    #     ind_toLXe=np.nonzero(np.logical_and(np.sqrt(np.sum(vs**2, axis=0))>0.25, np.sum(vs*us, axis=0)<=0))[0]
    #     ind_toVac=np.nonzero(np.logical_and(np.logical_and(np.sqrt(np.sum(vs**2, axis=0))<0.75, np.sqrt(np.sum(vs**2, axis=0))>0.25), np.sum(vs*us, axis=0)>0))[0]
    #
    #     count[ind_LXe]+=1
    #     count[ind_toLXe]+=1
    #     count[ind_toVac]+=1
    #
    #     if len(ind_LXe)>0:
    #         vs[:,ind_LXe], us[:,ind_LXe]=traceLXe(vs[:,ind_LXe], us[:,ind_LXe], nLXe, sigma_smr)
    #     if len(ind_toLXe)>0:
    #         vs[:,ind_toLXe], us[:,ind_toLXe]=tracetoLXe(vs[:,ind_toLXe], us[:,ind_toLXe], nLXe, sigma_smr)
    #     if len(ind_toVac)>0:
    #         vs[:,ind_toVac], us[:,ind_toVac]=tracetoVac(vs[:,ind_toVac], us[:,ind_toVac], nLXe, sigma_smr)

    pmt_hit = whichPMT(v, us)
    for j in range(len(Q)):
        #area=np.sum(np.random.normal(1, 1, np.random.binomial(len(np.nonzero(pmt_hit==j)[0]), Q[j])))
        s[j] = np.random.binomial(len(np.nonzero(pmt_hit == j)[0]), Q[j])
        #s[j]=int(np.round(area))
    return s
Example #11
0
def Sim(N, F, Tf, Ts, R, a, eta, Q, T, St, PEs, mu, x1, x2, left, right):
    f = np.sum(make_recomb(np.arange(1000 * 20) / 100, a,
                           eta).reshape(1000, 20),
               axis=1)
    i = 2
    while 1 - np.sum(f) > 1e-4:
        f = np.sum(make_recomb(np.arange(i * 1000 * 20) / 100, a,
                               eta).reshape(i * 1000, 20),
                   axis=1)
        i += 1
    if np.sum(f) - 1 > 1e-4:
        print('In recombenation model:')
        print('sum(f):', np.sum(f))
        sys.exit()
    else:
        f = f / np.sum(f)
    N_events = 10000
    Strig = 2
    d = np.zeros((N_events, 200, len(Q)))
    H = np.zeros((50, 200, len(Q)))
    spectra = np.zeros((len(PEs), len(Q)))
    cov = np.zeros((11, 15))

    G = np.zeros((250, 200))
    trp = np.zeros((N_events, 200, len(Q)))
    sng = np.zeros((N_events, 200, len(Q)))
    Rtrp = np.zeros((N_events, 200, len(Q)))
    Rsng = np.zeros((N_events, 200, len(Q)))
    Gtrp = np.zeros((250, 200))
    Gsng = np.zeros((250, 200))
    GRtrp = np.zeros((250, 200))
    GRsng = np.zeros((250, 200))

    v = make_v(N_events, mu, x1, x2)
    for i in range(N_events):
        # print(i, 'out of', N_events)
        t0 = np.zeros(len(Q))
        trig = np.random.normal(0, Strig, 1)
        N_glob = np.random.poisson(N)
        ex = np.random.binomial(N_glob, 1 - R)
        recomb = np.random.binomial(N_glob - ex, 1 - eta)
        t = np.zeros(recomb + ex)
        t[:recomb] += np.random.choice(np.arange(len(f)) / 5,
                                       size=recomb,
                                       replace=True,
                                       p=f)
        ch = np.random.choice(2, size=recomb + ex, replace=True, p=[F, 1 - F])
        t[ch == 0] += np.random.exponential(Tf, len(t[ch == 0]))
        t[ch == 1] += np.random.exponential(Ts, len(t[ch == 1]))
        slow_i = np.nonzero(ch == 1)[0]
        fast_i = np.nonzero(ch == 0)[0]

        costheta = np.random.uniform(-1, 1, len(t))
        phi = np.random.uniform(0, 2 * np.pi, len(t))
        us = np.vstack((np.vstack(
            (np.sin(np.arccos(costheta)) * np.cos(phi),
             np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
        pmt_hit = whichPMT(v[i], us)
        for j in range(len(Q)):
            hits = np.nonzero(pmt_hit == j)[0]
            ind = np.nonzero(1 == np.random.choice(
                2, size=len(hits), replace=True, p=[1 - Q[j], Q[j]]))[0]
            tj = np.random.normal(trig + T[j] + t[hits[ind]], St[j], len(ind))
            h, bins = np.histogram(tj, bins=np.arange(201))
            if np.any(h > 0):
                t0[j] = np.amin(np.nonzero(h > 0)[0])
            d[i, :, j] = h
            trp[i, :, j] = np.histogram(tj[np.nonzero(
                np.logical_and(hits[ind] >= recomb, np.isin(hits[ind],
                                                            slow_i)))[0]],
                                        bins=np.arange(201))[0]
            sng[i, :, j] = np.histogram(tj[np.nonzero(
                np.logical_and(hits[ind] >= recomb, np.isin(hits[ind],
                                                            fast_i)))[0]],
                                        bins=np.arange(201))[0]
            Rtrp[i, :, j] = np.histogram(tj[np.nonzero(
                np.logical_and(hits[ind] < recomb, np.isin(hits[ind],
                                                           slow_i)))[0]],
                                         bins=np.arange(201))[0]
            Rsng[i, :, j] = np.histogram(tj[np.nonzero(
                np.logical_and(hits[ind] < recomb, np.isin(hits[ind],
                                                           fast_i)))[0]],
                                         bins=np.arange(201))[0]
        for j in range(len(Q)):
            d[i, :, j] = np.roll(d[i, :, j], -int(np.amin(t0)))
            trp[i, :, j] = np.roll(trp[i, :, j], -int(np.amin(t0)))
            sng[i, :, j] = np.roll(sng[i, :, j], -int(np.amin(t0)))
            Rtrp[i, :, j] = np.roll(Rtrp[i, :, j], -int(np.amin(t0)))
            Rsng[i, :, j] = np.roll(Rsng[i, :, j], -int(np.amin(t0)))

    s = np.sum(np.sum(d[:, :100], axis=1), axis=1)
    ind = np.nonzero(np.logical_and(s > left, s < right))[0]
    if len(ind) == 0:
        w = np.abs(np.mean(s) - (left + right) / 2)
        return H - w, spectra - w, cov - w, G - w, Gtrp - w, Gsng - w, GRtrp - w, GRsng - w
    d = d[ind]
    trp = trp[ind]
    sng = sng[ind]
    Rtrp = Rtrp[ind]
    Rsng = Rsng[ind]

    for i in range(len(Q)):
        spectra[:, i] = np.histogram(np.sum(d[:, :100, i], axis=1),
                                     bins=np.arange(len(PEs) + 1) - 0.5)[0]

    k = 0
    for i in range(5):
        Si = np.sum(d[:, :100, i], axis=1)
        Mi = np.mean(Si)
        for j in range(i + 1, 6):
            Sj = np.sum(d[:, :100, j], axis=1)
            Mj = np.mean(Sj)
            cov[:, k] = np.histogram((Si - Mi) * (Sj - Mj) / (Mi * Mj),
                                     bins=11,
                                     range=[-0.1, 0.1])[0]
            k += 1

    for k in range(200):
        G[:, k] = np.histogram(np.sum(d[:, k, :], axis=1),
                               bins=np.arange(np.shape(G)[0] + 1) - 0.5)[0]
        Gtrp[:, k] = np.histogram(np.sum(trp[:, k, :], axis=1),
                                  bins=np.arange(np.shape(G)[0] + 1) - 0.5)[0]
        Gsng[:, k] = np.histogram(np.sum(sng[:, k, :], axis=1),
                                  bins=np.arange(np.shape(G)[0] + 1) - 0.5)[0]
        GRtrp[:, k] = np.histogram(np.sum(Rtrp[:, k, :], axis=1),
                                   bins=np.arange(np.shape(G)[0] + 1) - 0.5)[0]
        GRsng[:, k] = np.histogram(np.sum(Rsng[:, k, :], axis=1),
                                   bins=np.arange(np.shape(G)[0] + 1) - 0.5)[0]
        for j in range(len(Q)):
            H[:, k,
              j] = np.histogram(d[:, k, j],
                                bins=np.arange(np.shape(H)[0] + 1) - 0.5)[0]
    return H / len(ind), spectra / len(ind), cov / len(ind), G / len(
        ind), Gtrp / len(ind), Gsng / len(ind), GRtrp / len(ind), GRsng / len(
            ind), len(ind)
Example #12
0
def make_d(iter):
    N, Q, T, St, nLXe, sigma_smr, R, a, F, Tf, Ts, v, i = iter
    np.random.seed(int(i * time.time() % (2**32)))
    h = np.zeros((200, len(Q)))

    Strig = 2
    trig = np.random.normal(0, Strig, 1)
    recomb = np.random.binomial(N, R)
    ex = N - recomb
    t = np.zeros(recomb + ex)
    u = np.random.uniform(size=recomb)
    t[:recomb] += 1 / a * (u / (1 - u))
    sng_ind = np.random.choice(2, size=N, replace=True, p=[F, 1 - F])
    t[sng_ind == 0] += np.random.exponential(Tf, len(t[sng_ind == 0]))
    t[sng_ind == 1] += np.random.exponential(Ts, len(t[sng_ind == 1]))

    costheta = np.random.uniform(-1, 1, N)
    phi = np.random.uniform(0, 2 * np.pi, N)
    us = np.vstack(
        (np.vstack((np.sin(np.arccos(costheta)) * np.cos(phi),
                    np.sin(np.arccos(costheta)) * np.sin(phi))), costheta))
    vs = np.repeat(v, N).reshape(3, N)
    count = np.zeros(N)
    while np.any(np.sqrt(np.sum(vs**2, axis=0)) < 0.75):

        absorb = np.nonzero(count > 10)[0]
        vs[0, absorb] = 2
        us[:, absorb] = vs[:, absorb]

        ind_LXe = np.nonzero(np.sqrt(np.sum(vs**2, axis=0)) <= 0.25)[0]
        ind_toLXe = np.nonzero(
            np.logical_and(
                np.sqrt(np.sum(vs**2, axis=0)) > 0.25,
                np.sum(vs * us, axis=0) <= 0))[0]
        ind_toVac = np.nonzero(
            np.logical_and(
                np.logical_and(
                    np.sqrt(np.sum(vs**2, axis=0)) < 0.75,
                    np.sqrt(np.sum(vs**2, axis=0)) > 0.25),
                np.sum(vs * us, axis=0) > 0))[0]

        count[ind_LXe] += 1
        count[ind_toLXe] += 1
        count[ind_toVac] += 1

        if len(ind_LXe) > 0:
            vs[:, ind_LXe], us[:, ind_LXe] = traceLXe(vs[:, ind_LXe],
                                                      us[:, ind_LXe], nLXe,
                                                      sigma_smr)
        if len(ind_toLXe) > 0:
            vs[:,
               ind_toLXe], us[:,
                              ind_toLXe] = tracetoLXe(vs[:, ind_toLXe],
                                                      us[:, ind_toLXe], nLXe,
                                                      sigma_smr)
        if len(ind_toVac) > 0:
            vs[:,
               ind_toVac], us[:,
                              ind_toVac] = tracetoVac(vs[:, ind_toVac],
                                                      us[:, ind_toVac], nLXe,
                                                      sigma_smr)
    pmt_hit = whichPMT(vs, us)
    t0 = np.zeros(len(Q)) + 1000
    for j in range(len(Q)):
        hit_ind = np.nonzero(pmt_hit == j)[0]
        PE_extrct = hit_ind[np.nonzero(
            np.random.choice(
                2, size=len(hit_ind), replace=True, p=[Q[j], 1 -
                                                       Q[j]]) == 0)[0]]
        tj = np.random.normal(trig + T[j] + t[PE_extrct], St[j],
                              len(PE_extrct))
        h[:, j] = np.histogram(tj, bins=np.arange(201) - 0.5)[0]
        if np.any(h[:, j] > 0):
            t0[j] = np.amin(np.nonzero(h[:, j] > 0)[0])

    for j in range(len(Q)):
        h[:, j] = np.roll(h[:, j], -int(np.amin(t0)))
    return h[:100]