Commit e6e4ee04 authored by feichtinger's avatar feichtinger
Browse files

version following meeting, to be used by the others

added some comments and cleaned a bit
parent 39b15533
This diff is collapsed.
......@@ -15,7 +15,7 @@
# + {"toc": true, "cell_type": "markdown"}
# <h1>Table of Contents<span class="tocSkip"></span></h1>
# <div class="toc"><ul class="toc-item"><li><span><a href="#Configuration" data-toc-modified-id="Configuration-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Configuration</a></span></li><li><span><a href="#Support-Routines" data-toc-modified-id="Support-Routines-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Support Routines</a></span><ul class="toc-item"><li><span><a href="#Visualization" data-toc-modified-id="Visualization-2.1"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Visualization</a></span></li></ul></li><li><span><a href="#Dataset-creation" data-toc-modified-id="Dataset-creation-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Dataset creation</a></span><ul class="toc-item"><li><span><a href="#Dataset-reading-and-preprocessing-definition" data-toc-modified-id="Dataset-reading-and-preprocessing-definition-3.1"><span class="toc-item-num">3.1&nbsp;&nbsp;</span>Dataset reading and preprocessing definition</a></span></li><li><span><a href="#Make-dataset" data-toc-modified-id="Make-dataset-3.2"><span class="toc-item-num">3.2&nbsp;&nbsp;</span>Make dataset</a></span></li></ul></li><li><span><a href="#Examining-data" data-toc-modified-id="Examining-data-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Examining data</a></span><ul class="toc-item"><li><span><a href="#Observations-from-data-set-inspection" data-toc-modified-id="Observations-from-data-set-inspection-4.1"><span class="toc-item-num">4.1&nbsp;&nbsp;</span>Observations from data set inspection</a></span></li></ul></li><li><span><a href="#physics-based-model" data-toc-modified-id="physics-based-model-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>physics based model</a></span><ul class="toc-item"><li><span><a href="#Equations-for-average-number-of-photons-per-pulse" data-toc-modified-id="Equations-for-average-number-of-photons-per-pulse-5.1"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Equations for average number of photons per pulse</a></span></li><li><span><a href="#Equations-for-Electromultiplier-response" data-toc-modified-id="Equations-for-Electromultiplier-response-5.2"><span class="toc-item-num">5.2&nbsp;&nbsp;</span>Equations for Electromultiplier response</a></span></li><li><span><a href="#Additional-way-to-measure-constant-B-of-the-response-equation" data-toc-modified-id="Additional-way-to-measure-constant-B-of-the-response-equation-5.3"><span class="toc-item-num">5.3&nbsp;&nbsp;</span>Additional way to measure constant B of the response equation</a></span></li><li><span><a href="#Data-set-preparation" data-toc-modified-id="Data-set-preparation-5.4"><span class="toc-item-num">5.4&nbsp;&nbsp;</span>Data set preparation</a></span></li><li><span><a href="#Xe-data-on-cross-section,-charge-vs-photon-energy" data-toc-modified-id="Xe-data-on-cross-section,-charge-vs-photon-energy-5.5"><span class="toc-item-num">5.5&nbsp;&nbsp;</span>Xe data on cross section, charge vs photon energy</a></span></li><li><span><a href="#Nphot---avg-number-of-photons-per-pulse" data-toc-modified-id="Nphot---avg-number-of-photons-per-pulse-5.6"><span class="toc-item-num">5.6&nbsp;&nbsp;</span>Nphot - avg number of photons per pulse</a></span></li><li><span><a href="#Nphot-vs-CALCS-for-some-narrow-supply-Voltage-ranges" data-toc-modified-id="Nphot-vs-CALCS-for-some-narrow-supply-Voltage-ranges-5.7"><span class="toc-item-num">5.7&nbsp;&nbsp;</span>Nphot vs CALCS for some narrow supply Voltage ranges</a></span></li></ul></li><li><span><a href="#Model1:-fitting-the-gain-equation" data-toc-modified-id="Model1:-fitting-the-gain-equation-6"><span class="toc-item-num">6&nbsp;&nbsp;</span>Model1: fitting the gain equation</a></span><ul class="toc-item"><li><span><a href="#Optimization-of-a-suitable-subrange" data-toc-modified-id="Optimization-of-a-suitable-subrange-6.1"><span class="toc-item-num">6.1&nbsp;&nbsp;</span>Optimization of a suitable subrange</a></span></li><li><span><a href="#Optimization-on-the-full-data-set" data-toc-modified-id="Optimization-on-the-full-data-set-6.2"><span class="toc-item-num">6.2&nbsp;&nbsp;</span>Optimization on the full data set</a></span></li><li><span><a href="#using-cutoff-for-CALCS-<-4000-uJ" data-toc-modified-id="using-cutoff-for-CALCS-<-4000-uJ-6.3"><span class="toc-item-num">6.3&nbsp;&nbsp;</span>using cutoff for CALCS &lt; 4000 uJ</a></span></li></ul></li><li><span><a href="#Model-2:-semi-empirical" data-toc-modified-id="Model-2:-semi-empirical-7"><span class="toc-item-num">7&nbsp;&nbsp;</span>Model 2: semi-empirical</a></span><ul class="toc-item"><li><span><a href="#fitting-an-empirical-correction-to-the-gain-equation" data-toc-modified-id="fitting-an-empirical-correction-to-the-gain-equation-7.1"><span class="toc-item-num">7.1&nbsp;&nbsp;</span>fitting an empirical correction to the gain equation</a></span></li></ul></li><li><span><a href="#deduce-information-from-CALCS-distribution-as-function-of-voltage" data-toc-modified-id="deduce-information-from-CALCS-distribution-as-function-of-voltage-8"><span class="toc-item-num">8&nbsp;&nbsp;</span>deduce information from CALCS distribution as function of voltage</a></span></li><li><span><a href="#Looking-at-relationship-of-CALCS-and-CALCT" data-toc-modified-id="Looking-at-relationship-of-CALCS-and-CALCT-9"><span class="toc-item-num">9&nbsp;&nbsp;</span>Looking at relationship of CALCS and CALCT</a></span></li></ul></div>
# <div class="toc"><ul class="toc-item"><li><span><a href="#Configuration" data-toc-modified-id="Configuration-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Configuration</a></span></li><li><span><a href="#Support-Routines" data-toc-modified-id="Support-Routines-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Support Routines</a></span><ul class="toc-item"><li><span><a href="#Visualization" data-toc-modified-id="Visualization-2.1"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Visualization</a></span></li></ul></li><li><span><a href="#Dataset-creation" data-toc-modified-id="Dataset-creation-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Dataset creation</a></span><ul class="toc-item"><li><span><a href="#Dataset-reading-and-preprocessing-definition" data-toc-modified-id="Dataset-reading-and-preprocessing-definition-3.1"><span class="toc-item-num">3.1&nbsp;&nbsp;</span>Dataset reading and preprocessing definition</a></span></li><li><span><a href="#Make-dataset" data-toc-modified-id="Make-dataset-3.2"><span class="toc-item-num">3.2&nbsp;&nbsp;</span>Make dataset</a></span></li></ul></li><li><span><a href="#Examining-data" data-toc-modified-id="Examining-data-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Examining data</a></span><ul class="toc-item"><li><span><a href="#Observations-from-data-set-inspection" data-toc-modified-id="Observations-from-data-set-inspection-4.1"><span class="toc-item-num">4.1&nbsp;&nbsp;</span>Observations from data set inspection</a></span></li></ul></li><li><span><a href="#physics-based-model" data-toc-modified-id="physics-based-model-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>physics based model</a></span><ul class="toc-item"><li><span><a href="#Equations-for-average-number-of-photons-per-pulse" data-toc-modified-id="Equations-for-average-number-of-photons-per-pulse-5.1"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Equations for average number of photons per pulse</a></span></li><li><span><a href="#Equations-for-Electromultiplier-response" data-toc-modified-id="Equations-for-Electromultiplier-response-5.2"><span class="toc-item-num">5.2&nbsp;&nbsp;</span>Equations for Electromultiplier response</a></span></li><li><span><a href="#Additional-relationship-to-measure-constant-B-of-the-EM-gain-equation" data-toc-modified-id="Additional-relationship-to-measure-constant-B-of-the-EM-gain-equation-5.3"><span class="toc-item-num">5.3&nbsp;&nbsp;</span>Additional relationship to measure constant B of the EM gain equation</a></span></li><li><span><a href="#Data-set-preparation" data-toc-modified-id="Data-set-preparation-5.4"><span class="toc-item-num">5.4&nbsp;&nbsp;</span>Data set preparation</a></span></li><li><span><a href="#Xe-data-on-cross-section,-charge-vs-photon-energy" data-toc-modified-id="Xe-data-on-cross-section,-charge-vs-photon-energy-5.5"><span class="toc-item-num">5.5&nbsp;&nbsp;</span>Xe data on cross section, charge vs photon energy</a></span></li><li><span><a href="#Nphot---avg-number-of-photons-per-pulse" data-toc-modified-id="Nphot---avg-number-of-photons-per-pulse-5.6"><span class="toc-item-num">5.6&nbsp;&nbsp;</span>Nphot - avg number of photons per pulse</a></span></li><li><span><a href="#Nphot-vs-CALCS-for-some-narrow-supply-Voltage-ranges" data-toc-modified-id="Nphot-vs-CALCS-for-some-narrow-supply-Voltage-ranges-5.7"><span class="toc-item-num">5.7&nbsp;&nbsp;</span>Nphot vs CALCS for some narrow supply Voltage ranges</a></span></li></ul></li><li><span><a href="#Model1:-fitting-the-gain-equation" data-toc-modified-id="Model1:-fitting-the-gain-equation-6"><span class="toc-item-num">6&nbsp;&nbsp;</span>Model1: fitting the gain equation</a></span><ul class="toc-item"><li><span><a href="#Optimization-of-a-suitable-subrange" data-toc-modified-id="Optimization-of-a-suitable-subrange-6.1"><span class="toc-item-num">6.1&nbsp;&nbsp;</span>Optimization of a suitable subrange</a></span></li><li><span><a href="#Optimization-on-the-full-data-set" data-toc-modified-id="Optimization-on-the-full-data-set-6.2"><span class="toc-item-num">6.2&nbsp;&nbsp;</span>Optimization on the full data set</a></span></li><li><span><a href="#using-cutoff-for-CALCS-<-4000-uJ" data-toc-modified-id="using-cutoff-for-CALCS-<-4000-uJ-6.3"><span class="toc-item-num">6.3&nbsp;&nbsp;</span>using cutoff for CALCS &lt; 4000 uJ</a></span></li></ul></li><li><span><a href="#Model-2:-semi-empirical" data-toc-modified-id="Model-2:-semi-empirical-7"><span class="toc-item-num">7&nbsp;&nbsp;</span>Model 2: semi-empirical</a></span><ul class="toc-item"><li><span><a href="#fitting-an-empirical-correction-to-the-gain-equation" data-toc-modified-id="fitting-an-empirical-correction-to-the-gain-equation-7.1"><span class="toc-item-num">7.1&nbsp;&nbsp;</span>fitting an empirical correction to the gain equation</a></span></li></ul></li><li><span><a href="#deduce-information-from-CALCS-distribution-as-function-of-voltage" data-toc-modified-id="deduce-information-from-CALCS-distribution-as-function-of-voltage-8"><span class="toc-item-num">8&nbsp;&nbsp;</span>deduce information from CALCS distribution as function of voltage</a></span></li><li><span><a href="#Looking-at-relationship-of-CALCS-and-CALCT" data-toc-modified-id="Looking-at-relationship-of-CALCS-and-CALCT-9"><span class="toc-item-num">9&nbsp;&nbsp;</span>Looking at relationship of CALCS and CALCT</a></span></li></ul></div>
# +
import os
......@@ -394,7 +394,7 @@ sns.lmplot(x="PEPP", y='CALCT', hue="rawDataFile",
# with A and B being model parameters to be fit to the data.
#
# ## Additional way to measure constant B of the response equation
# ## Additional relationship to measure constant B of the EM gain equation
#
# The variation of the electromultiplier response grows with the supply voltage.
#
......@@ -467,7 +467,7 @@ fig,ax = plt.subplots(figsize=(12,6))
tmpdf['cross-section'].plot(marker='.', ax=ax)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_ylabel('cross section')
ax.set_ylabel('cross section / Mb')
# +
physdf = pd.concat([data_mean.reset_index().set_index('SPECTRUM_CENTER'), tmpdf], axis=1, join='inner') \
......@@ -482,7 +482,8 @@ physdf.plot(x='SPECTRUM_CENTER', y='cross-section',
linestyle='', marker='o', ax=ax, legend=False)
#ax.set_xscale('log')
#ax.set_yscale('log')
ax.set_ylabel('cross section')
ax.set_xlabel('SPECTRUM_CENTER / eV')
ax.set_ylabel('cross section / Mb')
ax.set_title("Xe cross section across data's photon energy range")
physdf.XeMultVoltag.plot(linestyle='', marker='o')
......@@ -577,7 +578,7 @@ for row in range(0, tmpdf.shape[0]):
# -
# # Model1: fitting the gain equation
# # Model1: fitting the Electromultiplier gain equation
# \begin{aligned} {\text CALC} = N_{\text ph} \cdot A \cdot V^{B} \end{aligned}
#
......@@ -586,7 +587,7 @@ for row in range(0, tmpdf.shape[0]):
physdf1 = physdf.copy()
# x input is composed of 2 arrays: [ nphot, voltage]
# x input is an array of 2 arrays: [nphot, voltage]
def calcs_fn(x, kcoeff, kpow):
return x[0] * kcoeff * np.power(x[1], kpow)
......@@ -684,12 +685,12 @@ colbar.set_label('beam energy (SPECTRUM_CENTER) / eV')
ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linestyle='--')
ax.set_xlabel('CALCS measured')
ax.set_ylabel('CALCS predicted')
ax.set_title('CALCS predicted vs measured, beam energy dependence')
ax.set_title('Model 1: CALCS predicted vs measured, beam energy dependence')
# -
# **There clearly is a systematic dependence on the beam energy.** Higher beam energies are predicted to lead to higher CALCS responses than were measured. No such systematic dependency is visible if we color according to the EM Voltage (plot below).
# **There clearly is a systematic dependence on the beam energy.** The CALCS predictions for higher beam energies are systematically too high in this fit. No such systematic dependency is visible if we look at the influence of the EM Voltage (plot below).
#
# The dependency on the beam energy above suggests that we could introduce a simple correction term based on the beam energy. But one should think about what this dependence really suggests in terms of the physics.
# The dependency on the beam energy above suggests that we could introduce a simple correction term as a function of beam energy. But one should think about what this dependence really signifies in terms of the physics.
#
# +
......@@ -706,10 +707,12 @@ colbar.set_label('EM Voltage')
ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linestyle='--')
ax.set_xlabel('CALCS measured')
ax.set_ylabel('CALCS predicted')
ax.set_title('CALCS predicted vs measured, EM Voltage dependence')
ax.set_title('Model 1: CALCS predicted vs measured, EM Voltage dependence')
# -
# In the plot above no simple dependence on the EM Voltage is visible
# In the plot above no simple dependence on the EM Voltage is visible.
#
# Below, we transform the result into the PEP predictions space.
# +
# measured vs. predicted
......@@ -726,7 +729,7 @@ ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linest
ax.set_xlabel('PEP measured')
ax.set_ylabel('PEP predicted')
ax.set_title('PEP predicted vs measured, beam energy dependence')
ax.set_title('Model 1: PEP predicted vs measured, beam energy dependence')
# -
# ## using cutoff for CALCS < 4000 uJ
......@@ -773,7 +776,7 @@ colbar.set_label('beam energy (SPECTRUM_CENTER) / eV')
ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linestyle='--')
ax.set_xlabel('CALCS measured')
ax.set_ylabel('CALCS predicted')
ax.set_title('CALCS predicted vs measured, beam energy dependence')
ax.set_title('Model 1 (cut): CALCS predicted vs measured, beam energy dependence')
# +
# measured vs. predicted
......@@ -790,7 +793,7 @@ ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linest
ax.set_xlabel('PEP measured')
ax.set_ylabel('PEP predicted')
ax.set_title('PEP predicted vs measured, beam energy dependence')
ax.set_title('Model 1 (cut): PEP predicted vs measured, beam energy dependence')
# -
physdf1_cut
......@@ -798,14 +801,16 @@ physdf1_cut
# # Model 2: semi-empirical
# ## fitting an empirical correction to the gain equation
# Based on the beam energy dependency of the predictions from the EM gain curve, it seems that a simple correction as a function of beam energy can produce a better fit. I try with a primitive correction factor linearly dependent on the beam energy.
#
# N.B.: this is just a simple test inspired by math. Maybe we can find a correction term grounded in physics.
# \begin{aligned} {\text CALC} = (1 + C \cdot E_{\text {beam}} ) \cdot N_{\text {ph}} \cdot A \cdot V^{B} \end{aligned}
#
# # copy of our data for experimenting
physdf2 = physdf.copy()
# \begin{aligned} {\text CALC} = (1 + C \cdot E_{\text {beam}} ) \cdot N_{\text {ph}} \cdot A \cdot V^{B} \end{aligned}
#
# x input is composed of 3 arrays: [ nphot, voltage, Ebeam]
def calcs_fn2(x, kcoeff, kpow, ecoeff):
return (1 + x[2] * ecoeff) * x[0] * kcoeff * np.power(x[1], kpow)
......@@ -826,15 +831,32 @@ popt2, pcov2 = scipy.optimize.curve_fit(calcs_fn2,
maxfev=10000
)
# **Results for the fitted constants A, B, and C of the gain equation**
# **Results for the fitted constants A, B, and C of the modified gain equation**
popt2
pcov2
# +
# TODO
# -
# Since C is negative, it signifies that the same number of incident photons (~ photoions) produce a weaker EM signal at higher beam energies.
#
# What could be the physical explanation for this? The number of photons for this fitting we get from the longer-timescale electrode measurements. Is there a difference in the Ion production at the electrodes or near the electromultipliers that could account for the beam energy dependence?
# Visualizing the beam energy dependent gain curves and comparing to the simeple electromultiplier gain fit from above:
fig,ax = plt.subplots(figsize=(12,8))
v_ax = np.linspace(physdf1.XeMultVoltag.min(),physdf1.XeMultVoltag.max(), 100)
# we get the gain by setting Nphot=1.0
ax.plot(v_ax, -calcs_fn([np.full(v_ax.shape, 1.0 ), v_ax], popt[0], popt[1]),
label='M1: EM gain', linestyle='--')
for enrg in [7000, 9000, 11000]:
ax.plot(v_ax, -calcs_fn2([np.full(v_ax.shape, 1.0 ), v_ax, np.full(v_ax.shape, enrg )],
popt2[0], popt2[1], popt2[2]), label=f'M2: E={enrg} eV')
ax.set_yscale('log')
ax.set_xlabel('XeMultVoltag')
ax.set_ylabel('Gain')
ax.legend()
# \begin{aligned} \text{PEP}_{\text{pred}} = \frac{\text {CALC} \cdot E_{\text {beam}}}{(1 + C \cdot E_{\text {beam}} ) \cdot A \cdot V^{B}} \end{aligned}
# the predictions for CALCS given the experiments Nphot [from PEP / h \omega)]
# predictions for PEP based on the measured CALCS
......@@ -857,7 +879,7 @@ colbar.set_label('beam energy (SPECTRUM_CENTER) / eV')
ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linestyle='--')
ax.set_xlabel('CALCS measured')
ax.set_ylabel('CALCS predicted')
ax.set_title('CALCS predicted vs measured, beam energy dependence')
ax.set_title('Model 2: CALCS predicted vs measured, beam energy dependence')
# +
# measured vs. predicted
......@@ -874,10 +896,14 @@ ax.plot([tmp_xcol.min(),tmp_xcol.max()], [tmp_xcol.min(),tmp_xcol.max()], linest
ax.set_xlabel('PEP measured')
ax.set_ylabel('PEP predicted')
ax.set_title('PEP predicted vs measured, beam energy dependence')
ax.set_title('Model 2: PEP predicted vs measured, beam energy dependence')
# -
# N.B.: The fit looks good, but we need to find out whether the points at high beam energy are real outliers, or whether it's just an artifact of my new modulated fit function.
# # deduce information from CALCS distribution as function of voltage
# (this test I had done earlier... it is an interesting complementary way, but I guess without much practical impact, since the uncertainties are large)
#
# As described above, we can try to obtain the constant B from the gain formula by looking at the variation of the CALCS values in function of the supply voltage
#
# \begin{aligned}
......@@ -941,6 +967,7 @@ lreg.slope, lreg.intercept
# So, this method gave 6.12 for the parameter B, while the regression of the simple gain equation (earlier section) gave 6.5.
# # Looking at relationship of CALCS and CALCT
# (unfinished)
# Looking at the response from both electromultipliers. What is the expected relation if the gain equation is valid?
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment