Table of Contents


In [3]:
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')


Build pair_is from det_df

I need a function for selecting the detector pairs within a given theta range. I will add the option of including or discluding the detector pairs that include a channel directly next to the fission chamber. (There were triggering issues in these channels)

Patricia Schuster
Jan 2018
UM NERS


In [4]:
import pandas as pd
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_palette('spectral')
sns.set_style(style='white')

In [5]:
sys.path.append('../scripts/')
import bicorr as bicorr

In [6]:
%load_ext autoreload
%autoreload 2

Load det_df


In [7]:
det_df = bicorr.load_det_df(plot_flag=True)



In [8]:
det_df.head()


Out[8]:
d1 d2 d1d2 angle
0 1 2 102 15.0
1 1 3 103 30.0
2 1 4 104 45.0
3 1 5 105 60.0
4 1 6 106 75.0

Select pairs within a given angle range


In [9]:
th_min = 0
th_max = 20

In [19]:
ind_mask = (det_df['angle'] > th_min) & (det_df['angle'] <= th_max)

In [20]:
det_df[ind_mask].head()


Out[20]:
d1 d2 d1d2 angle
0 1 2 102 15.000000
8 1 10 110 16.328077
44 2 3 203 15.000000
87 3 4 304 15.000000
129 4 5 405 15.000000

In [21]:
det_df[ind_mask].index.values


Out[21]:
array([  0,   8,  44,  87, 129, 170, 210, 249, 287, 332, 360, 368, 395,
       429, 462, 494, 525, 555, 584, 620, 639, 665, 690, 714, 737, 759,
       780, 800, 837, 845, 854, 870, 885, 899, 912, 924, 935, 953, 954,
       962, 969, 975, 980, 984, 987, 989], dtype=int64)

In [22]:
pair_is = det_df[ind_mask].index.values

Select pairs that are not next to the fission chamber channel


In [69]:
chList, fcList, detList, num_dets, num_det_pairs = bicorr.build_ch_lists()

In [70]:
chIgnore = [1,17,33]

Ignore indices in det_df that include one of these channels.


In [77]:
det_df.head()


Out[77]:
d1 d2 d1d2 angle
0 1 2 102 15.0
1 1 3 103 30.0
2 1 4 104 45.0
3 1 5 105 60.0
4 1 6 106 75.0

In [85]:
det_df_ig = det_df[~det_df['d1'].isin(chIgnore) & ~det_df['d2'].isin(chIgnore)]
det_df_ig


Out[85]:
d1 d2 d1d2 angle
44 2 3 203 15.000000
45 2 4 204 30.000000
46 2 5 205 45.000000
47 2 6 206 60.000000
48 2 7 207 75.000000
49 2 8 208 90.000000
50 2 9 209 105.000000
51 2 10 210 24.647971
52 2 11 211 23.170902
53 2 12 212 29.872934
54 2 13 213 40.901585
55 2 14 214 53.627703
56 2 15 215 67.057326
58 2 18 218 94.626775
59 2 19 219 108.412595
60 2 20 220 40.871807
61 2 21 221 45.302126
62 2 22 222 52.941675
63 2 23 223 62.560032
64 2 24 224 73.285301
65 2 25 225 84.560560
66 2 26 226 95.997155
67 2 27 227 107.255406
68 2 28 228 117.941468
69 2 29 229 75.000000
70 2 30 230 90.000000
71 2 31 231 105.000000
73 2 34 234 135.000000
74 2 35 235 150.000000
75 2 36 236 165.000000
... ... ... ... ...
960 39 46 3946 105.000000
961 39 47 3947 120.000000
962 40 41 4041 15.000000
963 40 42 4042 30.000000
964 40 43 4043 45.000000
965 40 44 4044 60.000000
966 40 45 4045 75.000000
967 40 46 4046 90.000000
968 40 47 4047 105.000000
969 41 42 4142 15.000000
970 41 43 4143 30.000000
971 41 44 4144 45.000000
972 41 45 4145 60.000000
973 41 46 4146 75.000000
974 41 47 4147 90.000000
975 42 43 4243 15.000000
976 42 44 4244 30.000000
977 42 45 4245 45.000000
978 42 46 4246 60.000000
979 42 47 4247 75.000000
980 43 44 4344 15.000000
981 43 45 4345 30.000000
982 43 46 4346 45.000000
983 43 47 4347 60.000000
984 44 45 4445 15.000000
985 44 46 4446 30.000000
986 44 47 4447 45.000000
987 45 46 4546 15.000000
988 45 47 4547 30.000000
989 46 47 4647 15.000000

861 rows × 4 columns

Make sure that we don't have any of those channels.


In [86]:
plt.plot(det_df_ig['d1'],det_df_ig['d2'],'.k')
plt.axvline( 1); plt.axhline( 1)
plt.axvline(17); plt.axhline(17)
plt.axvline(33); plt.axhline(33)
plt.xlabel('d1'); plt.ylabel('d2'); plt.title('Channels in det_df_ig')
plt.show()


Combine those options to bicorr.generate_pair_is


In [87]:
import inspect

In [88]:
print(inspect.getsource(bicorr.generate_pair_is))


def generate_pair_is(det_df, th_min = None, th_max = None, i_bin = None, ignore_fc_neighbors_flag = False):
    """
    Generate list of indices of pairs within a given angle range (th_min,th_max] for bicorr_hist_master.
    
    Parameters
    ----------
    det_df : pandas dataFrame
        dataFrame of detector pair indices and angles 
    th_min : int, optional
        Exclusive lower limit (th > th_min)
    th_max : int, optional
        Inclusive upper limit (th <= th_max)  
    i_bin : int, optional
        Index of desired bin in det_df['bin']
    ignore_fc_neighbors_flag : bool, optional
        Whether to ignore channels next to fission chamber [1,17,33]
    
    Return
    ------
    pair_is : list
        Indices of detector pairs in range in bicorr_hist_master
    """
    
    # What are the conditions?    
    by_th_flag = np.logical_and(th_min is not None,th_max is not None) # True: by th range. False: by bins
    by_bin_flag = (i_bin is not None) # True: by bin range. False: by th range
    
    # If you want to ignore the channels next to the fission chamber [1,17,33], remove those lines from det_df
    if ignore_fc_neighbors_flag:
        chIgnore = [1,17,33]
        det_df = det_df[~det_df['d1'].isin(chIgnore) & ~det_df['d2'].isin(chIgnore)]
    
    if by_th_flag:
        ind_mask = (det_df['angle'] > th_min) & (det_df['angle'] <= th_max)
        pair_is = det_df.index[ind_mask].values
    elif by_bin_flag:
        pair_is = det_df[det_df['bin']==i_bin].index.values
    else: # Select all pairs, no constraints
        pair_is = det_df.index.values
            
    return pair_is


In [89]:
bicorr.generate_pair_is(det_df,0,20)


Out[89]:
array([  0,   8,  44,  87, 129, 170, 210, 249, 287, 332, 360, 368, 395,
       429, 462, 494, 525, 555, 584, 620, 639, 665, 690, 714, 737, 759,
       780, 800, 837, 845, 854, 870, 885, 899, 912, 924, 935, 953, 954,
       962, 969, 975, 980, 984, 987, 989], dtype=int64)

In [90]:
det_df.iloc[bicorr.generate_pair_is(det_df,0,20)]


Out[90]:
d1 d2 d1d2 angle
0 1 2 102 15.000000
8 1 10 110 16.328077
44 2 3 203 15.000000
87 3 4 304 15.000000
129 4 5 405 15.000000
170 5 6 506 15.000000
210 6 7 607 15.000000
249 7 8 708 15.000000
287 8 9 809 15.000000
332 9 19 919 16.328077
360 10 11 1011 15.000000
368 10 20 1020 16.328077
395 11 12 1112 15.000000
429 12 13 1213 15.000000
462 13 14 1314 15.000000
494 14 15 1415 15.000000
525 15 17 1517 15.000000
555 17 18 1718 15.000000
584 18 19 1819 15.000000
620 19 28 1928 16.328077
639 20 21 2021 15.000000
665 21 22 2122 15.000000
690 22 23 2223 15.000000
714 23 24 2324 15.000000
737 24 25 2425 15.000000
759 25 26 2526 15.000000
780 26 27 2627 15.000000
800 27 28 2728 15.000000
837 29 30 2930 15.000000
845 29 39 2939 16.328077
854 30 31 3031 15.000000
870 31 33 3133 15.000000
885 33 34 3334 15.000000
899 34 35 3435 15.000000
912 35 36 3536 15.000000
924 36 37 3637 15.000000
935 37 38 3738 15.000000
953 38 47 3847 16.328077
954 39 40 3940 15.000000
962 40 41 4041 15.000000
969 41 42 4142 15.000000
975 42 43 4243 15.000000
980 43 44 4344 15.000000
984 44 45 4445 15.000000
987 45 46 4546 15.000000
989 46 47 4647 15.000000

In [91]:
det_df.iloc[bicorr.generate_pair_is(det_df,0,20,ignore_fc_neighbors_flag=True)]


Out[91]:
d1 d2 d1d2 angle
44 2 3 203 15.000000
87 3 4 304 15.000000
129 4 5 405 15.000000
170 5 6 506 15.000000
210 6 7 607 15.000000
249 7 8 708 15.000000
287 8 9 809 15.000000
332 9 19 919 16.328077
360 10 11 1011 15.000000
368 10 20 1020 16.328077
395 11 12 1112 15.000000
429 12 13 1213 15.000000
462 13 14 1314 15.000000
494 14 15 1415 15.000000
584 18 19 1819 15.000000
620 19 28 1928 16.328077
639 20 21 2021 15.000000
665 21 22 2122 15.000000
690 22 23 2223 15.000000
714 23 24 2324 15.000000
737 24 25 2425 15.000000
759 25 26 2526 15.000000
780 26 27 2627 15.000000
800 27 28 2728 15.000000
837 29 30 2930 15.000000
845 29 39 2939 16.328077
854 30 31 3031 15.000000
899 34 35 3435 15.000000
912 35 36 3536 15.000000
924 36 37 3637 15.000000
935 37 38 3738 15.000000
953 38 47 3847 16.328077
954 39 40 3940 15.000000
962 40 41 4041 15.000000
969 41 42 4142 15.000000
975 42 43 4243 15.000000
980 43 44 4344 15.000000
984 44 45 4445 15.000000
987 45 46 4546 15.000000
989 46 47 4647 15.000000

In [ ]: