"print(f\"Acquisition rate and memory cells set from file {fname} are \" \n",
" f\"{acqrate} MHz and {max_cells}, respectively\")"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Gain Characterization (Flat Fields) #
The following code characterizes the gain of the AGIPD detector from flat field data, i.e. data with X-rays of defined intensity. This data should fullfil the following requirements:
* intensity should be such that single photon peaks are visible
* data for all modules should be present
* no shadowing should occur on any of the modules
* each pixel should have at minimum arround 100 events per photon peak per memory cell
* if central beam edges are visible, they should not be significantly more intense
Characterization is done by a weighted average algorithm, which evaluates the peak locations for all pixels
and memory cells of a given module. These locations are then fitted to a linear function of the average peak
location in each module, such that it yield a relative gain correction.
%% Cell type:code id: tags:
``` python
# the following lines should be adjusted depending on data
in_folder='/gpfs/exfel/exp/MID/201931/p900091/raw/'# path to input data, required
modules=[3]# modules to work on, required, range allowed
out_folder="/gpfs/exfel/exp/MID/201931/p900091/usr/FF/2.2"# path to output to, required
runs=[484,485,]# runs to use, required, range allowed
sequences=[0,1,2,3]#,4,5,6,7,8] #,5,6,7,8,9,10] # sequences files to use, range allowed
cluster_profile="noDB"# The ipcluster profile to use
local_output=True# output constants locally
db_output=True# output constants to database
db_output=False# output constants to database
bias_voltage=300# detector bias voltage
cal_db_interface="tcp://max-exfl016:8026#8035"# the database interface to use
mem_cells=250# number of memory cells used
mem_cells=0# number of memory cells used
interlaced=False# assume interlaced data format, for data prior to Dec. 2017
fit_hook=True# fit a hook function to medium gain slope
rawversion=2# RAW file format version
instrument="MID"
photon_energy=9.2# the photon energy in keV
offset_store=""# for file-baed access
high_res_badpix_3d=False# set this to True if you need high-resolution 3d bad pixel plots. Runtime: ~ 1h
db_input=True# retreive data from calibration database, setting offset-store will overwrite this
deviation_threshold=0.75# peaks with an absolute location deviation larger than the medium are are considere bad
acqrate=2.2# acquisition rate
acqrate=0.# acquisition rate
use_dir_creation_date=True
creation_time=""# To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC.ms e.g. 2019-07-04 11:02:41.00
gain_setting=0.1# gain setting can have value 0 or 1, Default=0.1 for no (None) gain-setting
karabo_da_control="AGIPD1MCTRL00"# karabo DA for control infromation
```
%% Cell type:code id: tags:
``` python
# std library imports
fromdatetimeimportdatetime
importdateutil
fromfunctoolsimportpartial
importwarnings
warnings.filterwarnings('ignore')
importos
importh5py
# numpy and matplot lib specific
importnumpyasnp
importmatplotlib
matplotlib.use("Agg")
importmatplotlib.pyplotasplt
%matplotlibinline
# parallel processing via ipcluster
# make sure a cluster is running with ipcluster start --n=32, give it a while to start
print("PC map was injected on: {}".format(metadata.calibration_constant_version.begin_at))
first_ex=False
```
%% Cell type:markdown id: tags:
## Initial peak estimates ##
First initial peak estimates need to be defined. This is done by inspecting histograms created from (a subset of) the offset-corrected data for peak locations and peak heights.
Finally, we inspect the results, by plotting the number of entries, peak locations and resulting gain maps for each peak. In the course of doing so, we identify bad pixels by either having 0 entries for a peak, or having `nan` values for the peak location.
The gain slopes and offsets are deduced by fitting a linear function $y = mx + b$ to the evaluated peaks. Gains are normalized to all pixels and all memory cells of a module by using the average peak locations a $x$ values. Thus slopes centered around 1 are to be expected.
Finally, we perform a correction of the data used to derive the gain constants with said constants. We expected an improvement in peak FWHM, if constants have been deduced correctly.