<jupyter_start><jupyter_text>Selecting bins from time, energyMay 2018  Summer on campus. Entire family swimming in the fountain.I need to take sums over ranges in time and energy. The challenge is that I can't simply provide an input energy, because that may not correspond to a bin edge. I need to select the energies that correspond to time bin edges.<jupyter_code>import os
import sys
import matplotlib.pyplot as plt
import numpy as np
import imageio
import pandas as pd
import seaborn as sns
sns.set(style='ticks')
sys.path.append('../scripts/')
import bicorr as bicorr
import bicorr_plot as bicorr_plot
%load_ext autoreload
%autoreload 2<jupyter_output><empty_output><jupyter_text>Look at $t \rightarrow E$ conversion Look at detector-FC distance distributionRight now in the time to energy conversion, all of the detectors are using $d=1$ as their distance from the fission chamber to the detector. How accurate is this?<jupyter_code>help(bicorr.convert_energy_to_time)<jupyter_output>Help on function convert_energy_to_time in module bicorr:

convert_energy_to_time(energy, distance=1)
    Convert energy in MeV to time in ns for neutrons that travel 1 m. From Matthew's `reldist.m` script. 
    
    Parameters
    ----------
    energy : float
        Neutron energy in MeV
    distance : float, optional
        Neutron flight distance in meters
        
    Returns
    -------
    time : float
        Time of flight of neutron<jupyter_text>Let's look at the distribution of detector distances. This is stored in an excel file `meas_info > detector_distances.xlsx`.<jupyter_code>os.listdir('../meas_info/')
det_distance_df = pd.read_excel('../meas_info/detector_distances.xlsx')
det_distance_df.head()<jupyter_output><empty_output><jupyter_text>Look at a distibution of the detector distances.<jupyter_code>plt.figure(figsize=(4,3))
plt.hist(det_distance_df['Distance (cm)'])
plt.xlabel('Distance (cm)')
plt.ylabel('Number of detectors')
plt.title('Detector-FC distance distribution')
sns.despine(right=False)
plt.show()<jupyter_output><empty_output><jupyter_text>Yikes, so my first observation is that the distances are *not* centered around 100! They are, in fact, all greater than 100. So I think even just changing the default distance in `bicorr.convert_time_to_energy` would improve things. I'm going to use `pandas.DataFrame.describe` to spit out some metrics: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html<jupyter_code>det_distance_df.describe()['Distance (cm)']
bicorr_plot.histogram_metrics(np.asarray(det_distance_df['Distance (cm)']),'Distance (cm)','Relative number of detectors')<jupyter_output>C:\Users\pfsch\Anaconda3\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j<jupyter_text>I don't know where this error is coming from, so I will just continue on...One nice thing about this distribution is that there are not really any "extremes." The  Look at energy values for 1 m. vs. average (1.05522 m) Look at 25 ns, which is right in the middle of the neutron distribution.<jupyter_code>t = 25
print(bicorr.convert_time_to_energy(t,distance=1))
print(bicorr.convert_time_to_energy(t,distance=1.05522))
print(bicorr.convert_time_to_energy(t,distance=1.05522)/bicorr.convert_time_to_energy(t,distance=1))<jupyter_output>8.407646446907751
9.361823922980244
1.1134892484000003<jupyter_text>So the 5.5% change in distance translates to an 11% change in energy for a 25 ns time of flight.<jupyter_code>t = 50
print(bicorr.convert_time_to_energy(t,distance=1))
print(bicorr.convert_time_to_energy(t,distance=1.05522))
print(bicorr.convert_time_to_energy(t,distance=1.05522)/bicorr.convert_time_to_energy(t,distance=1))<jupyter_output>2.101911611726938
2.340455980745061
1.1134892484000003<jupyter_text>Again, an 11% change in energy for a 50 ns time of flight. This is equal to 1.05522^2.<jupyter_code>1.05522**2<jupyter_output><empty_output><jupyter_text>There we go. So whatever the ratio of distances is, the energy calculations will be off by that amount squared.This really makes me think we need to go back to the original cced files, calculate the energies for each interaction, and then remake the `bicorr_hist_master` from that. This will be a lot of work.  Consider distribution of energies<jupyter_code>det_distance_df.head()
t = 25
energies = [bicorr.convert_time_to_energy(t,distance=dist) for dist in det_distance_df['Distance (cm)']/100]
bicorr_plot.histogram_metrics(energies, xlabel='Energy (MeV)', ylabel='Counts')
pd.DataFrame([bicorr.convert_time_to_energy(t,distance=dist) for dist in det_distance_df['Distance (cm)']/100]).describe()
t = 50
energies = [bicorr.convert_time_to_energy(t,distance=dist) for dist in det_distance_df['Distance (cm)']/100]
bicorr_plot.histogram_metrics(energies, xlabel='Energy (MeV)', ylabel='Counts')
pd.DataFrame([bicorr.convert_time_to_energy(t,distance=dist) for dist in det_distance_df['Distance (cm)']/100]).describe()
dt_bin_edges = np.arange(0,200,2)
print(dt_bin_edges)
energy_bin_edges = np.asarray(np.insert([bicorr.convert_time_to_energy(t) for t in dt_bin_edges[1:]],0,10000))
print(energy_bin_edges)
plt.figure(figsize=(4,3))
plt.plot(dt_bin_edges,energy_bin_edges,'.-k',linewidth=.5)
plt.axvline(15,color='r')
plt.axvline(150,color='r')
plt.yscale('log')
plt.xlabel('time bin edge (ns)')
plt.ylabel('energy bin edge (MeV)')
sns.despine(right=False)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10611220648861804, 'fraction_numerical': 0.04032980820935651, 'mean_word_length': 6.2561768530559165, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '184255', 'license': 'MIT', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1856, 'n_words': 511, 'path': 'methods/time_energy_bin_edges.ipynb', 'repo_name': 'pfschus/fission_bicorrelation', 'size': '5579'}