Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
0b00553
fixed gas_scatter_proportion tested
casesyh Jun 26, 2020
9bf9ca2
add chi2 calculation
casesyh Jul 8, 2020
bb0bc61
fix the checking of scatter spectra file
casesyh Jul 11, 2020
fab92a7
fix the checking of scatter spectra file
casesyh Jul 11, 2020
c173168
internal config error
casesyh Jul 11, 2020
fa62da5
fix magnetic field mismatch between notebook and mermithid result
casesyh Aug 20, 2020
96f1259
add radiation loss
casesyh Sep 3, 2020
a27dc40
check in before adding file for composite trap fitting
casesyh Sep 9, 2020
021156b
composite gaussian resolution function implemented
casesyh Sep 10, 2020
6727ea2
add poisson chi2
casesyh Sep 15, 2020
5a8fae7
update KrComplexLineShape to use simulated resolution for fake data g…
casesyh Sep 16, 2020
69617b9
add convolve_ins_resolution
casesyh Sep 17, 2020
6ac5ac1
resolve probabilities containing NaN
casesyh Sep 23, 2020
d5d090a
testing stan analysis test scripts in termite
casesyh Sep 27, 2020
a582ef7
use termite script for testing
casesyh Sep 27, 2020
e04a4f3
update the files
casesyh Sep 28, 2020
be09e5a
delete configuration for magnetic field
casesyh Sep 28, 2020
5825a96
make path_to_ins_resolution_data_txt configurable in fake_data_stan_a…
casesyh Oct 1, 2020
352c672
test resolution function configurable
casesyh Oct 5, 2020
d5ddea3
Loading/using simulated resolution file
taliaweiss Oct 9, 2020
1494fd0
Adopting YuHao's simulated res file naming
taliaweiss Oct 9, 2020
186ee0f
Sample simulated resolution counts rates to account for errors
taliaweiss Oct 9, 2020
10c08f3
add MultiGAsComplexLineShape.py
casesyh Oct 18, 2020
7c013dc
np.random in convolve_ins_resolution
casesyh Oct 18, 2020
cc4f411
update convolve_ins_resolution_combining_four_trap
casesyh Oct 19, 2020
bd27aaa
update convolve_ins_resolution_combining_four_trap
casesyh Oct 20, 2020
acf830a
started adding new options re ins resolution
taliaweiss Oct 20, 2020
5fd5dde
Merge branch 'simulated_ins_resolution_in_fake_data_generator' of htt…
taliaweiss Oct 20, 2020
3231065
add dirac peak option to every make_spectrum
casesyh Oct 20, 2020
0d6cd30
change fix_ftc to use_simulated_inst_reso
casesyh Oct 20, 2020
33dece6
add configuration use_combined_four_trap_inst_reso
casesyh Oct 20, 2020
5474e89
add configuration use_combined_four_trap_inst_reso in FakeDataGenerat…
casesyh Oct 20, 2020
a9b1ac7
Continued YuHao's work adding trap combining/error sampling
taliaweiss Oct 20, 2020
ab5ecc1
Made my naming consistent with YuHao's
taliaweiss Oct 20, 2020
d3496c9
Set radiation loss to True by default
taliaweiss Oct 20, 2020
673bd51
add base_shape configuration to multi gas line shape processor
casesyh Oct 20, 2020
c03617e
Make B-field fixed input for fake data gen
taliaweiss Oct 20, 2020
e0693de
Merge branch 'simulated_ins_resolution_in_fake_data_generator' of htt…
taliaweiss Oct 20, 2020
726b88d
Added missing commas
taliaweiss Oct 20, 2020
fd5eead
put emitted_peak = self.base_shape inside make_spectrum functions
casesyh Oct 20, 2020
684ca43
fixed various small errors in implementation of new features
taliaweiss Oct 21, 2020
ab86d1d
prepare to add smeared triangle resolutio and gaussian+lorentzian res…
casesyh Oct 21, 2020
2871962
Fixed errors; added temporary diagnoistic plots
taliaweiss Oct 21, 2020
7801316
Changed default inst res files
taliaweiss Oct 21, 2020
3fc6772
Fixed temporary diagnostic plots
taliaweiss Oct 21, 2020
f884b91
add smeared triangle and gaussian + lorentzian reoslution
casesyh Oct 22, 2020
d0bf786
Enabled FakeDataGenerator to use complex ls as func of K
taliaweiss Oct 22, 2020
6d99c11
Fixed scatter peak bug; removed temporary plots/printing
taliaweiss Oct 22, 2020
dc418e7
Set bin width of std_eV_array manually
taliaweiss Oct 24, 2020
aed8ddc
Changed default simulated res to T2 version
taliaweiss Oct 24, 2020
6cf5179
push the changes in there
casesyh Oct 25, 2020
2cd91fa
add fitting with composite gaussian lorentzian resolution
casesyh Nov 2, 2020
350f496
fix survival probability
casesyh Nov 3, 2020
8227397
fixed survival probability free scatter proportion
casesyh Nov 4, 2020
d70e4c0
add fitting with partially fixed scatter proportion
casesyh Nov 5, 2020
a94dfc5
update fitting with fixed survival probability partially fixed scatte…
casesyh Nov 6, 2020
2229336
add mass 28 gases
casesyh Nov 16, 2020
5fbb06f
make gases and scatter proportion configurable
casesyh Nov 17, 2020
2323155
make gases and scatter_proportion configurable
casesyh Nov 17, 2020
6325498
add elevated, composite, composite with pedestal factor gaussian reso…
casesyh Nov 17, 2020
bb46e17
composite gaussian resolution scaled and simulated resolution scaled
casesyh Nov 24, 2020
86dee6e
add fitting with simulated resolution scaled and fit reconstruction e…
casesyh Dec 5, 2020
033937d
test git it's been a while
casesyh Jan 24, 2021
514305d
make recon eff param configurable
casesyh Jan 25, 2021
fbb7b49
Merge branch 'multi_gas_scattering' into combining_multi_gas_scatteri…
casesyh Jan 26, 2021
4bc4e14
fix typo in variable name recon_eff_param_c
casesyh Jan 28, 2021
bf8f2a1
Fixed the interface between the fake data generator and the complex l…
huyanxy Jan 28, 2021
b376b79
Merge branch 'combining_multi_gas_scattering_with_simulated_ins_resol…
huyanxy Jan 28, 2021
cac1723
Testing merge of simulated_ins... and multigas... branches
taliaweiss Jan 28, 2021
50089b1
Merge branch 'combining_multi_gas_scattering_with_simulated_ins_resol…
taliaweiss Jan 28, 2021
b32b50b
Testing changes
taliaweiss Jan 28, 2021
a160e85
added more configurables in the fake data generator. Changed variabl…
huyanxy Jan 29, 2021
1249f6a
organized configs
huyanxy Jan 29, 2021
26b7b1d
Testing recon eff in Stan
taliaweiss Jan 29, 2021
3d94d86
Fixed bug in recon eff implementation in complex lineshape
taliaweiss Jan 29, 2021
b830e9c
Removed double-definition of self.scatter_proportion in FakeDataGener…
taliaweiss Jan 29, 2021
2fc7e17
move self.shakeSpectrumClassInstance into InternalConfigure
casesyh Feb 5, 2021
7d29504
Commenting changes
taliaweiss Feb 8, 2021
c7ff7a3
Merge branch 'combining_multi_gas_scattering_with_simulated_ins_resol…
taliaweiss Feb 8, 2021
236a737
add a few comments above the make spectrum's
casesyh Feb 8, 2021
97386cf
Merge branch 'combining_multi_gas_scattering_with_simulated_ins_resol…
taliaweiss Feb 8, 2021
ff744ef
Merged in develop; added comments to FakeDataGenerator's InternalConf…
taliaweiss Feb 8, 2021
0283d97
added shake json file path in the fake data generator; fixed bug (ext…
huyanxy Feb 9, 2021
7719ce2
fixed result dictionary keys for the fitted survival probability. No…
huyanxy Feb 9, 2021
fc3a164
changed comments about the options for the resolution function config
huyanxy Feb 9, 2021
bf49a03
Removed unnecessary path config from FakeDataGenerator
taliaweiss Feb 9, 2021
4f37578
Pulling Xueying's changes
taliaweiss Feb 9, 2021
f16a5e6
fix bug (incorrect function name)
huyanxy Feb 10, 2021
6a2dd07
fix bug (incorrect function name in multi gas lineshape)
huyanxy Feb 10, 2021
a0f279e
removed self.path_to_quad_trap_eff_interp variable (no longer needed)
huyanxy Feb 10, 2021
fbacdb7
fix make spectrum function call bug in method spectrum_func_composite…
casesyh Feb 10, 2021
021ddca
make self.shakeSpectrumClassInstance configuration only happen when s…
casesyh Feb 10, 2021
5be7d8a
fixed function call in complex lineshape
huyanxy Feb 10, 2021
9d6ca2c
included Yu-Hao's change to the shape spectrum input option
huyanxy Feb 10, 2021
a482415
fixed function call
huyanxy Feb 10, 2021
41bbe00
fixed function call
huyanxy Feb 10, 2021
297eb80
Cleaned up code per Christine's recommendations on pull request
taliaweiss Feb 12, 2021
250d3e7
fit with modified exponential scatter peak amplitude ratios
casesyh Mar 15, 2021
2f6f6ed
Added function to compute frac events in ROI for count rate predictions
taliaweiss Mar 16, 2021
7900b6d
Merge branch 'combining_multi_gas_scattering_with_simulated_ins_resol…
taliaweiss Mar 16, 2021
aa3a1c3
add survival probability in parameters
casesyh Mar 16, 2021
79909fd
Updated FakeDataGenerator to use correct recon eff model
taliaweiss Mar 31, 2021
0c3398c
Added Dirac delta option to new complex lineshape function, fixed errors
taliaweiss Apr 1, 2021
0bee194
Added gaussian res option to main lineshape model
taliaweiss Apr 23, 2021
a87f642
migrating to add gaussian resolution model
casesyh Apr 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ services:
volumes:
# share a subdirectory from the host to /host in the docker (can be edited)
- ~/mermithid_share:/host
- ~/mermithid_FDG2/mermithid:/host-mermithid
- ~:/home_directory
25 changes: 17 additions & 8 deletions mermithid/misc/ComplexLineShapeUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def read_oscillator_str_file(filename):

for line in lines:
if line != "" and line[0]!="#":
raw_data = [float(i) for i in line.split("\t")]
energyOsc[0].append(raw_data[0])
energyOsc[1].append(raw_data[1])
try:
raw_data = [float(i) for i in line.split("\t")]
energyOsc[0].append(raw_data[0])
energyOsc[1].append(raw_data[1])
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there no warning or error when the try fails?
should energyOsc not always be read in from the file?

continue

energyOsc = np.array(energyOsc)
### take data and sort by energy
Expand All @@ -62,14 +65,21 @@ def aseev_func_tail(energy_loss_array, gas_type):
A2, omeg2, eps2 = 0.1187, 33.40, 10.43
elif gas_type=="Ar":
A2, omeg2, eps2 = 0.3344, 21.91, 21.14
elif gas_type=="N2":
A2, omeg2, eps2 = 0.21754816, 44.99897054, 20.43916114
elif gas_type=="CO":
A2, omeg2, eps2 = 0.19583454, 55.21888452, 16.44972596
elif gas_type=="C2H4":
A2, omeg2, eps2 = 0.57492182, 23.77501391, 14.33107345
return A2*omeg2**2./(omeg2**2.+4*(energy_loss_array-eps2)**2.)

#convert oscillator strength into energy loss spectrum
def get_eloss_spec(e_loss, oscillator_strength, kr_17keV_line): #energies in eV
kinetic_en = kr_17keV_line * 1000
kinetic_en = kr_17keV_line
e_rydberg = 13.605693009 #rydberg energy (eV)
a0 = 5.291772e-11 #bohr radius
return np.where(e_loss>0 , 4.*np.pi*a0**2 * e_rydberg / (kinetic_en * e_loss) * oscillator_strength * np.log(4. * kinetic_en * e_loss / (e_rydberg**3.) ), 0)
argument_of_log = np.where(e_loss > 0, 4. * kinetic_en * e_rydberg / (e_loss**2.) , 1e-5)
return np.where(e_loss>0 , 1./(e_loss) * oscillator_strength* np.log(argument_of_log), 0)

# Takes only the nonzero bins of a histogram
def get_only_nonzero_bins(bins,hist):
Expand Down Expand Up @@ -109,11 +119,10 @@ def energy_guess_to_frequency(energy_guess, energy_guess_err, B_field_guess):
return frequency , frequency_err

# Given a frequency and error, converts those to B field values assuming the line is the 17.8 keV line
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment. error is no longer a parameter here.

def central_frequency_to_B_field(central_freq,central_freq_err):
def central_frequency_to_B_field(central_freq):
const = (2.*np.pi*m_e)*(1+kr_17keV_line/mass_energy_electron)/e_charge
B_field = const*central_freq
B_field_err = const*central_freq_err
return B_field , B_field_err
return B_field

# given a FWHM for the lorentian component and the FWHM for the gaussian component,
# this function estimates the FWHM of the resulting voigt distribution
Expand Down
54 changes: 32 additions & 22 deletions mermithid/misc/FakeTritiumDataFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def convolved_bkgd_rate(K, Kmin, Kmax, lineshape, ls_params, min_energy, max_ene

#Convolution of signal and lineshape using scipy.signal.convolve
def convolved_spectral_rate_arrays(K, Q, mnu, Kmin,
lineshape, ls_params, min_energy, max_energy,
lineshape, ls_params, scatter_peak_ratio_b, scatter_peak_ratio_c, scatter_fraction, min_energy, max_energy,
complexLineShape, final_state_array):
"""K is an array-like object
"""
Expand All @@ -293,23 +293,22 @@ def convolved_spectral_rate_arrays(K, Q, mnu, Kmin,
elif lineshape=='simplified_scattering' or lineshape=='simplified':
lineshape_rates = simplified_ls(K_lineshape, 0, ls_params[0], ls_params[1], ls_params[2], ls_params[3], ls_params[4], ls_params[5])
elif lineshape=='detailed_scattering' or lineshape=='detailed':
lineshape_rates = complexLineShape.make_spectrum_simulated_resolution_scaled_fit_scatter_peak_ratio(1, ls_params[1], scatter_peak_ratio_b, scatter_peak_ratio_c, scatter_fraction, gauss_FWHM_eV=ls_params[0], emitted_peak='dirac')
lineshape_rates = np.flipud(lineshape_rates)

lineshape_rates = complexLineShape.spectrum_func_1(K_lineshape/1000., ls_params[0], 0, 1, ls_params[1])

beta_rates = spectral_rate(K, Q, mnu, final_state_array) #np.zeros(len(K))
#for i,ke in enumerate(K):
# beta_rates[i] = spectral_rate(ke, Q, mnu, final_state_array)
beta_rates = spectral_rate(K, Q, mnu, final_state_array)

#Convolving
convolved = convolve(beta_rates, lineshape_rates, mode='same')

below_Kmin = np.where(K < Kmin)
np.put(convolved, below_Kmin, np.zeros(len(below_Kmin)))
return convolved



#Convolution of background and lineshape using scipy.signal.convolve
def convolved_bkgd_rate_arrays(K, Kmin, Kmax, lineshape, ls_params, min_energy, max_energy, complexLineShape):
def convolved_bkgd_rate_arrays(K, Kmin, Kmax, lineshape, ls_params, scatter_peak_ratio_b, scatter_peak_ratio_c, scatter_fraction, min_energy, max_energy, complexLineShape):
"""K is an array-like object
"""
energy_half_range = max(max_energy, abs(min_energy))
Expand All @@ -325,8 +324,9 @@ def convolved_bkgd_rate_arrays(K, Kmin, Kmax, lineshape, ls_params, min_energy,
elif lineshape=='simplified_scattering' or lineshape=='simplified':
lineshape_rates = simplified_ls(K_lineshape, 0, ls_params[0], ls_params[1], ls_params[2], ls_params[3], ls_params[4], ls_params[5])
elif lineshape=='detailed_scattering' or lineshape=='detailed':
lineshape_rates = complexLineShape.spectrum_func_1(K_lineshape/1000., ls_params[0], 0, 1, ls_params[1])

lineshape_rates = complexLineShape.make_spectrum_simulated_resolution_scaled_fit_scatter_peak_ratio(1, ls_params[1], scatter_peak_ratio_b, scatter_peak_ratio_c, scatter_fraction, gauss_FWHM_eV=ls_params[0], emitted_peak='dirac')
lineshape_rates = np.flipud(lineshape_rates)

bkgd_rates = np.full(len(K), bkgd_rate())
if len(K) < len(K_lineshape):
raise Exception("lineshape array is longer than Koptions")
Expand All @@ -335,30 +335,40 @@ def convolved_bkgd_rate_arrays(K, Kmin, Kmax, lineshape, ls_params, min_energy,
convolved = convolve(bkgd_rates, lineshape_rates, mode='same')
below_Kmin = np.where(K < Kmin)
np.put(convolved, below_Kmin, np.zeros(len(below_Kmin)))

return convolved



##Fraction of events near the endpoint
##Currently, this only holds for the last 13.6 eV of the spectrum
#def frac_near_endpt(Kmin, Q, mass, atom_or_mol='atom'):
# A = integrate.quad(spectral_rate, Kmin, Q-mass, args=(Q,mass))
# B = integrate.quad(spectral_rate, V0, Q-mass, args=(Q,mass)) #Minimum at V0 because electrons with energy below screening barrier do not escape
# f = (A[0])/(B[0])
# if atom_or_mol=='atom':
# return 0.7006*f
# elif atom_or_mol=='mol' or atom_or_mol=='molecule':
# return 0.57412*f
# else:
# print("Choose 'atom' or 'mol'.")
#Fraction of events near the endpoint
def frac_near_endpt(Kmin, Q, mass, final_state_array, atom_or_mol='mol', range='wide'):
"""
Options for range:
- 'narrow': Only extends ~18 eV (or less) below the endpoint, so that all decays are to the ground state
- 'wide': Wide enough that the probability of decay to a 3He electronic energy level that would shift Q below the ROI is very low
"""
A = integrate.quad(spectral_rate, Kmin, Q-mass, args=(Q, mass, final_state_array))
B = integrate.quad(spectral_rate, V0, Q-mass, args=(Q, mass, final_state_array)) #Minimum at V0 because electrons with energy below screening barrier do not escape
f = (A[0])/(B[0])
if range=='narrow':
if atom_or_mol=='atom':
return 0.7006*f
elif atom_or_mol=='mol' or atom_or_mol=='molecule':
return 0.57412*f
else:
logger.warn("Choose 'atom' or 'mol'.")
elif range=='wide':
return f
else:
logger.warn("Choose range 'narrow' or 'wide'")


#Convert [number of particles]=(density*volume*efficiency) to a signal activity A_s, measured in events/second.
def find_signal_activity(Nparticles, m, Q, Kmin, atom_or_mol='atom', nTperMolecule=2):
"""
Functions to calculate number of events to generate
"""
br = frac_near_endpt(Kmin, Q, m, atom_or_mol)
br = frac_near_endpt(Kmin, Q, m, final_state_array, atom_or_mol)
Thalflife = 3.8789*10**8
A_s = Nparticles*np.log(2)/(Thalflife)*br
if atom_or_mol=='atom':
Expand Down
Loading