Patricia Schuster
University of Michigan
2/9/2018
We are expecting 8.5" of snow today. ..........
I am combining four data sets:
I have combined the sparse_bhm.npz
, sparse_bhm_neg.npz
, and singles_hist.npz
files on flux and downloaded to my local machine.
Now I will revive those files and produce bhp_nn
for positive and negative time ranges. This is so that I don't have to keep importing the entire bhm
files each time because it takes forever and a ton of memory.
I'm going to use 1 ns time binning for this to save 16x space in the time dimensions.
In [12]:
import os
import sys
import matplotlib.pyplot as plt
import matplotlib.colors
import numpy as np
import imageio
import scipy.io as sio
In [2]:
sys.path.append('../../scripts/')
In [35]:
import bicorr as bicorr
import bicorr_plot as bicorr_plot
In [4]:
%load_ext autoreload
%autoreload 2
Use seaborn to make plots prettier
In [5]:
import seaborn as sns
sns.set(style='ticks')
In [6]:
os.listdir('../../meas_info/')
Out[6]:
In [7]:
det_df = bicorr.load_det_df('../../meas_info/det_df_pairs_angles.csv',plot_flag=True)
In [8]:
chList, fcList, detList, num_dets, num_det_pairs = bicorr.build_ch_lists(print_flag=True)
In [18]:
num_fissions = int(int(sio.loadmat('datap/num_fissions.mat')['num_fissions'])*float(sio.loadmat('datap/fc_efficiency.mat')['fc_efficiency']))
In [19]:
num_fissions
Out[19]:
In [20]:
os.listdir()
Out[20]:
In [21]:
sparse_bhm, dt_bin_edges, note = bicorr.load_sparse_bhm(filepath='datap')
In [22]:
sparse_bhm.nbytes
Out[22]:
In [23]:
bhm_pos = bicorr.revive_sparse_bhm(sparse_bhm, det_df, dt_bin_edges)
In [24]:
(bhm_pos.nbytes)/16 # .5 ns bins
Out[24]:
I'm going to perform the background subtraction, then store bhp_nn_diff
for all 990 pairs to disk so I can reload it later.
In [26]:
sparse_bhm_neg, dt_bin_edges_neg, note_neg = bicorr.load_sparse_bhm(filename = 'sparse_bhm_neg.npz', filepath='datap')
In [27]:
bhm_neg = bicorr.revive_sparse_bhm(sparse_bhm_neg, det_df, dt_bin_edges_neg)
In [31]:
singles_hist, dt_bin_edges_sh, dict_det_to_index, dict_index_to_det = bicorr.load_singles_hist(filepath='datap')
In [32]:
help(bicorr.load_singles_hist)
In [36]:
plt.figure(figsize=(4,3))
dt_bin_centers_sh = (dt_bin_edges_sh[:-1]+dt_bin_edges_sh[1:])/2
plt.plot(dt_bin_centers_sh,np.sum(singles_hist,axis=(0,1)))
plt.xlabel('Time (ns)')
plt.ylabel('Number of events')
plt.title('TOF distribution, all events')
plt.yscale('log')
sns.despine(right=False)
bicorr_plot.save_fig_to_folder('singles_hist_allt_allp',extensions=['png','pdf'])
plt.show()
In [37]:
plt.figure(figsize=(4,3))
plt.plot(dt_bin_centers_sh,np.sum(singles_hist[0,:,:],axis=(0)))
plt.plot(dt_bin_centers_sh,np.sum(singles_hist[1,:,:],axis=(0)))
plt.xlabel('Time (ns)')
plt.ylabel('Number of events')
plt.title('TOF distribution, all detectors')
plt.legend(['N','G'])
plt.yscale('log')
sns.despine(right=False)
bicorr_plot.save_fig_to_folder('singles_hist_ng_allp',extensions=['png','pdf'])
plt.show()
In [38]:
plt.figure(figsize=(4,3))
plt.plot(dt_bin_centers_sh,singles_hist[0,dict_det_to_index[2],:])
plt.plot(dt_bin_centers_sh,singles_hist[1,dict_det_to_index[2],:])
plt.xlabel('Time (ns)')
plt.ylabel('Number of events')
plt.title('TOF distribution, channel 2')
plt.legend(['N','G'])
plt.yscale('log')
sns.despine(right=False)
bicorr_plot.save_fig_to_folder('singles_hist_ng_ch2',extensions=['png','pdf'])
plt.show()
In [39]:
print(bhm_pos.shape)
print(bhm_neg.shape)
In [40]:
bhm_pos, dt_bin_edges = bicorr.coarsen_bhm(bhm_pos,dt_bin_edges, 4,True)
bhm_neg, dt_bin_edges_neg = bicorr.coarsen_bhm(bhm_neg,dt_bin_edges_neg,4,True)
In [41]:
print(bhm_pos.shape)
print(bhm_neg.shape)
One key piece of data that I am going to work with for producing multiple plots is the bhp
for $nn$ events across all detector pairs. (Actually, only the pairs not next to the fission chambers)
So I am going to produce that for future use. This will be copied into another notebook, but the process of loading all of the data is the same so I'm doing that here since all the data is loaded.
I'm going to make this with 1 ns time binning to keep the file size manageable.
In [42]:
pair_is = bicorr.generate_pair_is(det_df, ignore_fc_neighbors_flag=True)
len(pair_is)
Out[42]:
Look at this distribution.
In [45]:
plt.figure(figsize=(6,6))
plt.plot(det_df.iloc[pair_is]['d1'],det_df.iloc[pair_is]['d2'],'sk')
for i in [1,17,33]:
plt.axvline(i,c='r')
plt.axhline(i,c='r')
plt.xlabel('Detector 1 channel')
plt.ylabel('Detector 2 channel')
plt.title('Included detector pairs')
sns.despine(right=False)
bicorr_plot.save_fig_to_folder(fig_filename='pair_is_without_fc_neighbors',extensions=['png','pdf'])
plt.show()
In [46]:
bhm_pos.shape
Out[46]:
In [47]:
bhm_pos_shape = bhm_pos[pair_is,:,:,:].shape
print(bhm_pos_shape)
The challenge here is that I want to preserve the dimension of pair_is
(I don't want to sum across all pairs in pair_is
). How can I do this without significantly modifying my code base?
Set up arrays to fill
In [48]:
bhp_nn_pos = np.zeros((bhm_pos_shape[0],bhm_pos_shape[2],bhm_pos_shape[3]))
bhp_nn_neg = np.zeros((bhm_pos_shape[0],bhm_pos_shape[2],bhm_pos_shape[3]))
In [49]:
bhp_nn_neg.shape
Out[49]:
In [50]:
for i in np.arange(len(pair_is)):
pair_i = pair_is[i]
bhp_nn_pos[i,:,:] = bicorr.build_bhp(bhm_pos,dt_bin_edges,pair_is=[pair_i],type_is=[0])[0]
bhp_nn_neg[i,:,:] = bicorr.build_bhp(bhm_neg,dt_bin_edges_neg,pair_is=[pair_i],type_is=[0])[0]
print(bhp_nn_pos.shape)
print(bhp_nn_neg.shape)
Plot a few to make sure they look good.
In [54]:
i = 500
bicorr_plot.bhp_plot(bhp_nn_pos[i,:,:],dt_bin_edges,show_flag=True,title='bhp_nn_pos at i={}'.format(i))
bicorr_plot.bhp_plot(bhp_nn_neg[i,:,:],dt_bin_edges_neg,show_flag=True,title='bhp_nn_neg at i={}'.format(i))
Out[54]:
Plot them now as sums across all pairs.
In [55]:
bicorr_plot.bhp_plot(np.sum(bhp_nn_pos,axis=0),dt_bin_edges,show_flag=True,title='bhp_nn_pos')
bicorr_plot.bhp_plot(np.sum(bhp_nn_neg,axis=0),dt_bin_edges_neg,show_flag=True,title='bhp_nn_neg')
Out[55]:
Now create bhp_nn_diff
.
Question: Should I create bhp_nn_diff
here, or work with bhp_nn_pos
and bhp_nn_neg
? The data is still pretty sparse, so bhp_nn_diff
would end up with a lot of negative values in it. Mathematically, once I start taking sums, it would be the same. But I will always have to load bhp_nn_pos
and bhp_nn_neg
anyway, so I could just create bhp_nn_diff
whenever I load them. Yeah. Do that.
In [56]:
bhp_nn_diff = np.subtract(bhp_nn_pos.astype(np.int32),bhp_nn_neg[:,::-1,::-1].astype(np.int32))
In [57]:
bicorr_plot.bhp_plot(np.sum(bhp_nn_diff,axis=0),dt_bin_edges,show_flag=True,title='bhp_nn_diff')
Out[57]:
In [58]:
i = 4
bicorr_plot.bhp_plot(bhp_nn_diff[i,:,:],dt_bin_edges,show_flag=True,title='bhp_nn_diff')
Out[58]:
One thing to keep in mind is that bicorr.bicorr_plot
does not show negative values, so the background subtraction makes it look "cleaner" than it is in reality.
Calculate bhp_nn_diff
pair by pair and make sure it matches what I've already done.
In [59]:
bhp_nn_diff_pair = np.zeros((861, 200, 200))
In [60]:
for i in np.arange(len(pair_is)):
pair_i = pair_is[i]
bhp_nn_diff_pair[i,:,:] = np.subtract(bhp_nn_pos[i,:,:].astype(np.int32),bhp_nn_neg[i,::-1,::-1].astype(np.int32))
In [61]:
bhp_nn_diff_pair.shape
Out[61]:
In [62]:
np.array_equal(bhp_nn_diff,bhp_nn_diff_pair)
Out[62]:
In [63]:
note = 'Stored from Cf072115_to_Cf072215b with 1 ns time binning. Pairs are without fc neighbors. -PFS, 2/9/18'
In [64]:
save_filename = 'datap/bhp_nn_by_pair_1ns'
In [65]:
np.savez(save_filename, bhp_nn_neg = bhp_nn_neg, bhp_nn_pos = bhp_nn_pos,
dt_bin_edges = dt_bin_edges, pair_is = pair_is, note = note)
In [1]:
whos
Go back and import all the packages.
In [7]:
whos
In [8]:
load_filename = 'datap/bhp_nn_by_pair_1ns.npz'
In [12]:
npzfile = np.load(load_filename)
print(npzfile.files)
print(npzfile['note'])
In [15]:
pair_is = npzfile['pair_is']
bhp_nn_pos = npzfile['bhp_nn_pos']
bhp_nn_neg = npzfile['bhp_nn_neg']
dt_bin_edges = npzfile['dt_bin_edges']
Calculate bhp_nn_diff
.
In [19]:
bhp_nn_diff = np.subtract(bhp_nn_pos.astype(np.int32),bhp_nn_neg[:,::-1,::-1].astype(np.int32))
In [20]:
bhp_nn_diff.shape
Out[20]:
Plot them to make sure they look good.
In [21]:
bicorr.bicorr_plot(np.sum(bhp_nn_diff,axis=0),dt_bin_edges,show_flag=True,title='bhp_nn_diff')