Skip to content
Snippets Groups Projects
Commit 40c30b5d authored by Laurent Mercadier's avatar Laurent Mercadier
Browse files

Update and move knife-edge notebook to doc

parent 72b8d6f9
No related branches found
No related tags found
1 merge request!276Update and move knife-edge notebook to doc
Pipeline #117886 passed
source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -19,8 +19,13 @@ Extracting peaks from digitizers ...@@ -19,8 +19,13 @@ Extracting peaks from digitizers
* :doc:`How to extract peaks from digitizer traces <How to extract peaks from digitizer traces>`. * :doc:`How to extract peaks from digitizer traces <How to extract peaks from digitizer traces>`.
Determining the FEL or OL beam size and the fluence
---------------------------------------------------
* :doc:`Knife-edge scan and fluence calculation <Knife edge scan and fluence calculation>`.
Finding time overlap by transient reflectivity Finding time overlap by transient reflectivity
----------------------------------------------------------------- ----------------------------------------------
Transient reflectivity of the optical laser measured on a large bandgap material pumped by the FEL is often used at SCS to find the time overlap between the two beams. The example notebook Transient reflectivity of the optical laser measured on a large bandgap material pumped by the FEL is often used at SCS to find the time overlap between the two beams. The example notebook
......
%% Cell type:markdown id: tags:
# Peak fluence calculation using knife-edge scans:
For a Gaussian beam at the waist position, the intensity distribution is defined as:
$I(x,y) = I_0 e^{\left(-\frac{2x^2}{w_{0,x}^2} -\frac{2y^2}{w_{0,y}^2}\right)}$
with $I_0$ the peak intensity of the Gaussian beam, $w_{0,x}$ and $w_{0,y}$ the beam radii at $1/e^2$ in $x$ and $y$ axes, respectively.
Let's consider a knife-edge "corner" at position $(x,y)$ that blocks the beam for $x^\prime < x$ and $y^\prime < y$. The detected power behind the knife-edge is given by:
$P(x,y) = I_0 \int_{x}^\infty \int_{y}^\infty e^{\left(-\frac{2x^{\prime 2}}{w_{0,x}^2} -\frac{2y^{\prime 2}}{w_{0,y}^2}\right)} dx^\prime dy^\prime $
Now let's consider a purely vertical knife-edge. The power in the $y$ axis is integrated from $-\infty$ to $\infty$, thus:
$P(x) = I_0 \sqrt\frac{\pi}{2}w_{0,y}\int_x^\infty e^{\left(-\frac{2x^{\prime 2}}{w_{0,x}^2}\right)}dx^\prime$.
Similarly, for a purely horizontal knife-edge:
$P(y) = I_0 \sqrt\frac{\pi}{2}w_{0,x}\int_y^\infty e^{\left(-\frac{2y^{\prime 2}}{w_{0,y}^2}\right)}dy^\prime$
By fitting the knife edge scans to these functions, we extract the waist in $x$ and $y$ axes.
The total power of one pulse is then:
$P_{TOT} = \frac{I_0 \pi w_{0,x} w_{0,y}}{2}$
Hence, the peak fluence, defined as $F_0=I_0\tau$ with $\tau$ the pulse duration of the laser, is given as:
$F_0 = \frac{2 E_P}{\pi w_{0,x} w_{0,y}}$
where $E_P$ is the pulse energy.
%% Cell type:code id: tags:
``` python
import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.size'] = 12.0
mpl.rcParams['savefig.dpi'] = 100
mpl.rcParams['figure.dpi'] = 100
import toolbox_scs as tb
import toolbox_scs.detectors as tbdet
import toolbox_scs.routines as tbr
import logging
logging.basicConfig(level=logging.WARNING)
log_root = logging.getLogger(__name__)
```
%% Cell type:markdown id: tags:
# Optical laser beam profile and fluence
%% Cell type:markdown id: tags:
## Knife-edge measurement (OL)
%% Cell type:markdown id: tags:
### Load scanning motor and laser photodiode data
%% Cell type:markdown id: tags:
The laser used in these knife-edge scans was the SCS backup laser, for which there was no bunch pattern table, so, whenever a function needs the bunch pattern as input argument, we set it to **'None'**. If the PP laser is used, then the corresponding bunch pattern key is **'scs_ppl'**.
%% Cell type:code id: tags:
``` python
proposal = 900094
runNB = 384
fields = ["FastADC4raw", "scannerX"]
runX, dsX = tb.load(proposal, runNB, fields, laser_bp='None')
fields = ["FastADC4raw", "scannerY"]
runNB = 385
runY, dsY = tb.load(proposal, runNB, fields, laser_bp='None')
```
%% Cell type:markdown id: tags:
### Check diode traces and region of integration for peak calculations
%% Cell type:markdown id: tags:
Using **'show_all=True'** displays the entire trace and all integration regions. We can then zoom and pan in the interactive figure.
%% Cell type:code id: tags:
``` python
paramsX = tbdet.check_peak_params(runX, 'FastADC4raw', show_all=True, bunchPattern='None')
print(paramsX)
```
%% Cell type:markdown id: tags:
using the default **'show_all=False'** parameter only shows the first and last pulses of the trace
%% Cell type:code id: tags:
``` python
tbdet.check_peak_params(runX, 'FastADC4raw', bunchPattern='None')
```
%% Cell type:markdown id: tags:
### Plot intensity vs. knife-edge positions, fit with erfc function
%% Cell type:code id: tags:
``` python
w0_x = tbr.knife_edge(dsX, axisKey='scannerX', plot=True)[0]*1e-3
w0_y = tbr.knife_edge(dsY, axisKey='scannerY', plot=True)[0]*1e-3
print('X-FWHM [um]:', w0_x * np.sqrt(2*np.log(2))*1e6)
print('Y-FWHM [um]:', w0_y * np.sqrt(2*np.log(2))*1e6)
```
%% Cell type:markdown id: tags:
## Fluence calculation (OL)
%% Cell type:markdown id: tags:
### OL power measurement
%% Cell type:code id: tags:
``` python
#measurement performed in Exp Hutch before in-coupling window
rel_powers = np.array([100, 75, 50, 25, 15, 12, 10, 8, 6, 4, 2, 1, 0.75, 0.5, 0.25, 0.1, 0])
powers = np.array([505, 384, 258, 130, 81, 67, 56.5, 45.8, 35.6, 24.1, 14.1, 9.3, 8.0, 6.5, 4.8, 4.1, 1.0])*1e-3 #in W
rep_rate = 10
npulses = 336
```
%% Cell type:markdown id: tags:
### Fluence vs. laser power
%% Cell type:code id: tags:
``` python
pulse_energies = powers/(rep_rate*npulses)
print(pulse_energies*1e6)
fluences = 2*pulse_energies*1e3/(np.pi*w0_x*w0_y*1e4)
print(fluences)
plt.figure()
plt.plot(rel_powers, fluences, 'o-', ms=4)
plt.grid()
plt.ylabel('Peak fluence [mJ/cm$^2$]')
plt.xlabel('Laser power [%]')
e_fit = np.polyfit(rel_powers, pulse_energies*1e6, 1)
plt.figure()
plt.plot(rel_powers, pulse_energies*1e6, 'o-',
ms=4, label='E[$\mu$J] = {:.3f} x power [%] + {:.3f}'.format(e_fit[0], e_fit[1]))
plt.grid()
plt.ylabel('Pulse energy [$\mu$J]')
plt.xlabel('Laser power [%]')
plt.plot(rel_powers,rel_powers*e_fit[0]+ e_fit[1])
plt.legend()
print(e_fit)
```
%% Cell type:markdown id: tags:
# X-ray beam profile and fluence
%% Cell type:markdown id: tags:
## Knife-edge measurement
%% Cell type:markdown id: tags:
### Load runs with horizontal and vertical scans, normalize the transmitted signal by XGM
%% Cell type:code id: tags:
``` python
proposal = 900094
fields = ["MCP2apd", "scannerX", "SCS_SA3"]
runNB = 687
runX, dsX = tb.load(proposal, runNB, fields)
dsX['Tr'] = -dsX['MCP2peaks'] / dsX['SCS_SA3']
fields = ["MCP2apd", "scannerY", "SCS_SA3"]
runNB = 688
runY, dsY = tb.load(proposal, runNB, fields)
dsY['Tr'] = -dsY['MCP2peaks'] / dsY['SCS_SA3']
dsY
```
%% Cell type:markdown id: tags:
### Fit scan to erfc function and plot
%% Cell type:code id: tags:
``` python
w0_x = tbr.knife_edge(dsX, axisKey='scannerX', signalKey='Tr', plot=True)[0]*1e-3
w0_y = tbr.knife_edge(dsY, axisKey='scannerY', signalKey='Tr', plot=True)[0]*1e-3
print(w0_x, w0_y)
print('X-FWHM [um]:', w0_x * np.sqrt(2*np.log(2))*1e6)
print('Y-FWHM [um]:', w0_y * np.sqrt(2*np.log(2))*1e6)
```
%% Cell type:markdown id: tags:
## Fluence calculation
%% Cell type:markdown id: tags:
### Load XGM data
%% Cell type:code id: tags:
``` python
proposal = 900094
runNB = 647
run, ds = tb.load(proposal, runNB, 'SCS_SA3')
ds
```
%% Cell type:markdown id: tags:
### Calibrate XGM fast data using photon flux and plot
%% Cell type:code id: tags:
``` python
f_scs = tbdet.calibrate_xgm(run, ds, plot=True)
f_xtd10 = tbdet.calibrate_xgm(run, ds, xgm='SCS')
pulse_energy = ds['SCS_SA3'].mean().values*f_scs*1e-6 #average energy in J
ds['pulse_energy'] = ds['SCS_SA3']*f_scs*1e-6
ds['fluence'] = 2*ds['pulse_energy']/(np.pi*w0_x*w0_y)
print('Pulse energy [J]:',pulse_energy)
F0 = 2*pulse_energy/(np.pi*w0_x*w0_y)
print('Fluence [mJ/cm^2]:', F0*1e-1)
plt.figure()
plt.hist(ds['pulse_energy'].values.flatten()*1e6, bins=50, rwidth=0.7, color='orange', label='Run 645')
plt.axvline(pulse_energy*1e6, color='r', lw=2, ls='--')
plt.xlabel('Pulse energy [$\mu$J]', size=14)
plt.ylabel('Number of pulses', size=14)
#plt.xlim(0,50)
plt.legend()
ax = plt.gca()
plt.twiny()
plt.xlim(np.array(ax.get_xlim())*2e-6/(np.pi*w0_x*w0_y)*1e-1)
plt.xlabel('Fluence [mJ/cm$^2$]', labelpad=10, size=14)
plt.tight_layout()
```
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment