def make_l(i, l, G, H, Spectrum, Spectra, Bins, bins, Abins, left, right, x1, x2, gamma, Q, T, St, W, std, Nbg, nLXe, sigma_smr, mu, R, a, F, Tf, Ts): np.random.seed(int(i * time.time() % 2**32)) spectrum, spectra, g, h = Sim_fit(x1, x2, left, right, gamma, Q, T, St, W, std, nLXe, sigma_smr, mu, R, a, F, Tf, Ts, binsSpec, bins) if np.any(spectrum < 0): l.value = 1e20 * (1 - np.amin(spectrum)) else: data = Spectrum model = Nbg * BGspectrum + (np.sum(Spectrum) - Nbg * np.sum(BGspectrum)) * spectrum l.value = -np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) data = np.ravel(Spectra) model = np.ravel(Nbg * BGspectra + (np.sum(Spectra, axis=0) - Nbg * np.sum(BGspectra, axis=0)) * spectra) l.value = -np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) data = np.ravel(G) model = np.ravel(Nbg * BGG + (np.sum(G[:, 0]) - Nbg * np.sum(BGG[:, 0])) * g) l.value = -np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) data = np.ravel(H) model = np.ravel( Nbg * BGH + (np.sum(H[:, 0], axis=0) - Nbg * np.sum(BGH[:, 0], axis=0)) * h) l.value = -np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model)
def make_l(l, H, spectra, cov, left, right, Xcov, x1, x2, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a): S, Sspectra, Scov=Sim_fit(x1, x2, left, right, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a, np.arange(np.shape(spectra)[0])) if np.any(S<0): print('S<0', S[S<0]) print(Q, T, St, mu, W, F, Tf, Ts, R, a) l.value=-1e10*(1-np.amin(S)) else: # model=np.sum(H[:,0,0])*np.ravel(S) # data=np.ravel(H[:,:100,:]) model=np.sum(H[:,0,0])*np.ravel(np.sum(S, axis=-1)) data=np.ravel(np.sum(H[:,:100,:], axis=-1)) l.value+=np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model)
def make_l(i, l, H, spectrum, spectra, T, Bins, bins, cov, left, right, x1, x2, gamma, Q, W, nLXe, mu): np.random.seed(int(i*time.time()%2**32)) Sspectrum, Sspectra, Scov=Sim_fit(x1, x2, left, right, gamma, Q, W, nLXe, mu, Bins, bins) if np.any(Sspectrum<0): l.value=1e10*(1-np.amin(Sspectrum)) else: data=spectrum model=T/TBG*BGspectrum+(np.sum(spectrum)-T/TBG*np.sum(BGspectrum))*Sspectrum l.value=-np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model) data=np.ravel(spectra) model=np.ravel(T/TBG*BGspectra+(np.sum(spectra, axis=0)-T/TBG*np.sum(BGspectra, axis=0))*Sspectra) l.value=-np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model)
def make_l(i, l, SAreas, H, spectrum, spectra, T, Bins, bins, Abins, left, right, x1, x2, gamma, Q, Sa, W, std, Nbg): np.random.seed(int(i*time.time()%2**32)) Sspectrum, Sspectra, Sareas=Sim_fit(x1, x2, left, right, gamma, Q, Sa, W, std, binsSpec, bins, Abins) if np.any(Sspectrum<0): l.value=1e20*(1-np.amin(Sspectrum)) else: data=spectrum model=Nbg*BGspectrum+(np.sum(spectrum)-Nbg*np.sum(BGspectrum))*Sspectrum l.value=-np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model) data=np.ravel(spectra) model=np.ravel(Nbg*BGspectra+(np.sum(spectra, axis=0)-Nbg*np.sum(BGspectra, axis=0))*Sspectra) l.value=-np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model) SAreas+=np.ravel(Sareas.T)
def make_l(H, spectra, bins, cov, left, right, Xcov, x1, x2, gamma, Q, w, mu, N): Sspectra = Sim_fit(x1, x2, left, right, gamma, Q, w, mu, bins) if np.any(Sspectra < 0): return 1e10 * (1 - np.amin(Sspectra)) else: # model=np.sum(H[:,0,0])*np.ravel(S) # data=np.ravel(H[:,:100,:]) # model=np.sum(H[:,0,0])*np.ravel(np.sum(S, axis=-1)) # data=np.ravel(np.sum(H[:,:100,:], axis=-1)) # l.value+=np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model) data = np.ravel(spectra) model = N * np.ravel(Sspectra) return -np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model)
def make_l(l, H, spectra, cov, left, right, Xcov, x1, x2, gamma, Q, N): Sspectra = Sim_fit(x1, x2, left, right, gamma, Q, 13.7, np.arange(np.shape(spectra)[0])) if np.any(Sspectra < 0): l.value = -1e10 * (1 - np.amin(Sspectra)) else: # model=np.sum(H[:,0,0])*np.ravel(S) # data=np.ravel(H[:,:100,:]) # model=np.sum(H[:,0,0])*np.ravel(np.sum(S, axis=-1)) # data=np.ravel(np.sum(H[:,:100,:], axis=-1)) # l.value+=np.sum(data*np.log((model+1e-10)/(data+1e-10))+data-model) spectra = rebin_spectra(spectra)[1] Sspectra = rebin_spectra(Sspectra)[1] data = np.ravel(spectra) model = N * np.ravel(Sspectra) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model)
def make_l(l, H, spectra, cov, left, right, Xcov, x1, x2, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a, dl): S, Sspectra, Scov = Sim_fit(x1, x2, left, right, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a, dl, np.arange(np.shape(spectra)[0])) if np.any(S < 0): l.value = -1e10 * (1 - np.amin(S)) else: model = np.sum(H[:, 0, 0]) * np.ravel(S) data = np.ravel(H[:, :100, :]) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) data = np.ravel(spectra) model = np.sum(H[:, 0, 0]) * np.ravel(Sspectra) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) model = np.sum(H[:, 0, 0]) * np.ravel(Scov) data = np.ravel(cov) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model)
def make_l(l, H, spectra, cov, left, right, Xcov, PEbins, x1, x2, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a): S, Sspectra, Scov = Sim_fit(x1, x2, left, right, gamma, Q, T, St, mu, W, F, Tf, Ts, R, a, PEbins) if np.any(S < 0): print('S<0') l.value = -1e10 * (1 - np.amin(S)) else: model = np.sum(H[:, 0, 0]) * np.ravel(S) data = np.ravel(H[:, :, :]) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) data = np.ravel(spectra) model = np.sum(H[:, 0, 0]) * np.ravel(Sspectra) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model) model = np.sum(H[:, 0, 0]) * np.ravel(Scov) data = np.ravel(cov) l.value += np.sum(data * np.log((model + 1e-10) / (data + 1e-10)) + data - model)
x2 = 1 T = 1564823506349 - 1564820774226 p = ([ 0.1025416, 0.22955419, 0.12410873, 0.13288353, 0.1176724, 0.20605295, 17.63976215, 0.1237789, 1.73823515, 0.88490154 ]) Q, W, mu, nLXe, sigma_smr = make_glob_array(p) Sspectrum = np.zeros((10, len(binsSpec) - 1)) Sspectra = np.zeros((10, len(bins) - 1, 6)) fig, ax = plt.subplots(3, 5) for i in range(10): print(i) s, ss, Scov = Sim_fit(x1, x2, left, right, gamma, Q, W, mu, nLXe, sigma_smr, binsSpec, bins) Sspectrum[i] = T / TBG * BGspectrum + (np.sum(spectrum) - T / TBG * np.sum(BGspectrum)) * s Sspectra[i] = T / TBG * BGspectra + ( np.sum(spectra, axis=0) - T / TBG * np.sum(BGspectra, axis=0)) * ss for j in range(15): np.ravel(ax)[j].plot(i, Scov[j], 'ko') j = 0 for i in range(5): for k in range(i + 1, 6): np.ravel(ax)[j].axhline(cov[j], 0, 1, color='r', label='Cov\n PMT{}-PMT{}'.format(i, k),
gamma = 122 elif source == 'Cs137': gamma = 662 Rec = np.recarray(1, dtype=[ ('Q', 'f8', len(pmts)), ]) p = [ 0.23744822, 0.19335455, 0.27713303, 0.2391398, 0.2424144, 0.27420061, 14.68521394, 0.93384985 ] Q, W, mu = make_glob_array(p) Sspectra = Sim_fit(x1, x2, left, right, gamma, Q[:], W[0], mu[0], bins) # PEs, spectra=rebin_spectra(spectra) # PEs, Sspectra=rebin_spectra(Sspectra) fig, ax = plt.subplots(2, 3) for i in range(len(pmts)): np.ravel(ax)[i].bar(0.5 * (bins[1:] + bins[:-1]), spectra[:, i], linewidth=5, width=bins[1:] - bins[:-1], align='center', label='spectrum - PMT{}'.format(pmts[i]), alpha=0.5) np.ravel(ax)[i].plot(0.5 * (bins[1:] + bins[:-1]), N * Sspectra[:, i],
if source=='Co57': gamma=122 elif source=='Cs137': gamma=662 p=([0.19838883, 0.13568442, 0.10828627, 0.17653182, 0.17463287, 0.28635258, 1.39186269, 1.30583897, 14.15082216]) Q, nLXe, mu, W=make_glob_array(p) Sspectrum=np.zeros((10, len(binsSpec)-1)) Sspectra=np.zeros((10, len(bins)-1, 6)) fig, ax=plt.subplots(3,5) for i in range(10): print(i) s, ss, Scov=Sim_fit(x1, x2, left, right, gamma, Q, 13.7, nLXe, mu, binsSpec, bins) Sspectrum[i]=T/TBG*BGspectrum+(np.sum(spectrum)-T/TBG*np.sum(BGspectrum))*s Sspectra[i]=T/TBG*BGspectra+(np.sum(spectra, axis=0)-T/TBG*np.sum(BGspectra, axis=0))*ss for j in range(15): np.ravel(ax)[j].plot(i, Scov[j], 'ko') j=0 for i in range(5): for k in range(i+1,6): np.ravel(ax)[j].axhline(cov[j], 0,1, color='r', label='Cov\n PMT{}-PMT{}'.format(i, k), linewidth=5) np.ravel(ax)[j].legend(fontsize=15) # np.ravel(ax)[j].set_ylim(-70, 40) j+=1 plt.figure()
x1 = 1 x2 = 0 elif type == '': x1 = 0 x2 = 1 if source == 'Co57': gamma = 122 elif source == 'Cs137': gamma = 662 Rec = np.recarray(1, dtype=[ ('Q', 'f8', len(pmts)), ]) p = np.array([ 0.22863552, 0.26201005, 0.26584989, 0.20042843, 0.19058325, 0.25078971 ]) * 0.9 Q = make_glob_array(p) Sspectrum = Sim_fit(x1, x2, left, right, gamma, Q, 13.7, bins) plt.figure() plt.bar(0.5 * (bins[1:] + bins[:-1]), spectrum, width=bins[1:] - bins[:-1]) plt.plot(0.5 * (bins[1:] + bins[:-1]), Sspectrum * N, 'k.') plt.errorbar(0.5 * (bins[1:] + bins[:-1]), Sspectrum * N, N * np.sqrt(Sspectrum / 1000), fmt='k.') plt.show()
x1 = 0 x2 = 1 if source == 'Co57': gamma = 122 elif source == 'Cs137': gamma = 662 Rec = np.recarray(1, dtype=[ ('Q', 'f8', len(pmts)), ]) p = [0.22, 0.19041186, 0.22063317, 0.20403208, 0.20959739, 0.24661499] Q = make_glob_array(p) Sspectra = Sim_fit(x1, x2, left, right, gamma, Q[:], 13.7, np.arange(np.shape(spectra)[0])) PEs, spectra = rebin_spectra(spectra) PEs, Sspectra = rebin_spectra(Sspectra) fig, ax = plt.subplots(2, 3) for i in range(len(pmts)): np.ravel(ax)[i].bar(PEs, spectra[:, i], linewidth=5, width=PEs[1] - PEs[0], align='edge', label='spectrum - PMT{}'.format(pmts[i])) np.ravel(ax)[i].plot(PEs + 0.5 * (PEs[1] - PEs[0]), N * Sspectra[:, i], 'g.',
0.19672198, 0.13481802, 0.10158334, 0.16812452, 0.14911151, 0.25114549, 0.38766503, 0.6670629, 0.83024831, 0.62834315, 1.22890051, 0.79467679, 32.39085721, 0.10672545 ]) N = 10 Q, Sa, W, g = make_glob_array(p) Sspectrum = np.zeros((N, len(binsSpec) - 1)) Sspectra = np.zeros((N, len(bins) - 1, 6)) # fig, ax=plt.subplots(3,5) for i in range(N): l = 0 #l=L(np.array(p), -100, -100, np.zeros((1, len(p))), [], 1000) print(i, l) s, ss, Scov = Sim_fit(x1, x2, left, right, gamma, Q, W, Sa, g, binsSpec, bins) Sspectrum[i] = T / TBG * BGspectrum + (np.sum(spectrum) - T / TBG * np.sum(BGspectrum)) * s Sspectra[i] = T / TBG * BGspectra + ( np.sum(spectra, axis=0) - T / TBG * np.sum(BGspectra, axis=0)) * ss # for j in range(15): # np.ravel(ax)[j].plot(i, Scov[j], 'ko') # j=0 # for i in range(5): # for k in range(i+1,6): # np.ravel(ax)[j].axhline(cov[j], 0,1, color='r', label='Cov\n PMT{}-PMT{}'.format(i, k), linewidth=5) # np.ravel(ax)[j].legend(fontsize=15) # j+=1 plt.figure()
1.71385413e-01, 1.75494553e-01, 1.10843989e+00, 7.60654309e-01, 4.98808286e-01, 6.27130735e-01, 9.39779196e-01, 8.96174105e-01, 4.77687664e-01, 2.80100432e-01, 3.90831974e+01, 6.87363235e+02 ]) N = 10 Q, Sa, W, std, Nbg = make_glob_array(p) Sspectrum = np.zeros((N, len(binsSpec) - 1)) Sspectra = np.zeros((N, len(bins) - 1, 6)) SAreas = np.zeros((N, len(Q), len(Abins[0]) - 1)) # fig, ax=plt.subplots(3,5) for i in range(N): l = 0 # l=L(np.array(p), -100, -100, np.zeros((1, len(p))), [], 1000) print(i, l) s, ss, sa = Sim_fit(x1, x2, left, right, gamma, Q, Sa, W, std, binsSpec, bins, Abins) Sspectrum[i] = Nbg[I] * BGspectrum + (np.sum(spectrum) - Nbg[I] * np.sum(BGspectrum)) * s Sspectra[i] = Nbg[I] * BGspectra + ( np.sum(spectra, axis=0) - Nbg[I] * np.sum(BGspectra, axis=0)) * ss SAreas[i] = (np.sum(Areas, axis=1) * sa).T plt.figure() plt.bar(0.5 * (binsSpec[1:] + binsSpec[:-1]), spectrum, width=binsSpec[1:] - binsSpec[:-1], label='data') plt.bar(0.5 * (binsSpec[1:] + binsSpec[:-1]), BGspectrum * Nbg[I], width=binsSpec[1:] - binsSpec[:-1], label='Background',