Skip to content

Commit 5ecb3ff

Browse files
committed
add parameter generation
1 parent 453e5a5 commit 5ecb3ff

File tree

1 file changed

+72
-70
lines changed

1 file changed

+72
-70
lines changed

tutorial/13_hextof_dld_sector_alignment_with_photon_peak.ipynb

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"\n",
3737
"from pathlib import Path\n",
3838
"import os\n",
39+
"import numpy as np\n",
3940
"\n",
4041
"from sed import SedProcessor\n",
4142
"from sed.dataset import dataset\n",
@@ -206,7 +207,7 @@
206207
"metadata": {},
207208
"outputs": [],
208209
"source": [
209-
"sp_ph_peak.dataframe"
210+
"sp_ph_peak.dataframe[[\"dldTimeSteps\", \"dldSectorID\"]].head()"
210211
]
211212
},
212213
{
@@ -233,55 +234,23 @@
233234
"outputs": [],
234235
"source": [
235236
"axes = ['dldSectorID', 'dldTimeSteps','dldPosX','dldPosY']\n",
236-
"ranges = [[0,8], [2360,2760], [435,885], [445,895]]\n",
237-
"bins = [8,400,225,225]\n",
238-
"res_ph_peak = sp_ph_peak.compute(bins=bins, axes=axes, ranges=ranges)\n",
239-
"\n",
240-
"res_ph_peak['dldPosX'].attrs['unit'] = 'µm'\n",
241-
"res_ph_peak['dldPosY'].attrs['unit'] = 'µm'\n",
242-
"\n",
243-
"fig,ax = plt.subplots(1,2,figsize=(6,2.25), layout='tight')\n",
244-
"res_ph_peak.sum(('dldSectorID','dldPosX','dldPosY')).plot(ax=ax[0])\n",
245-
"res_ph_peak.mean(('dldSectorID','dldTimeSteps')).plot(ax=ax[1], robust=True)"
246-
]
247-
},
248-
{
249-
"cell_type": "markdown",
250-
"id": "4fe4915e",
251-
"metadata": {},
252-
"source": [
253-
"### time-of-flight spectrum\n",
254-
"To see the photon peak on the ns scale we plot the time-of-flight spectrum. This is done here."
255-
]
256-
},
257-
{
258-
"cell_type": "code",
259-
"execution_count": null,
260-
"id": "ebdf8f75",
261-
"metadata": {},
262-
"outputs": [],
263-
"source": [
264-
"sp_ph_peak.append_tof_ns_axis()"
237+
"ranges = [[0,8], [2360,2460], [435,885], [445,895]]\n",
238+
"bins = [8,700,225,225]\n",
239+
"res_ph_peak = sp_ph_peak.compute(bins=bins, axes=axes, ranges=ranges)"
265240
]
266241
},
267242
{
268243
"cell_type": "code",
269244
"execution_count": null,
270-
"id": "55c96a30",
245+
"id": "e326e279",
271246
"metadata": {},
272247
"outputs": [],
273248
"source": [
274-
"axes = ['dldSectorID', 'dldTime','dldPosX','dldPosY']\n",
275-
"ranges = [[0,8], [390,460], [435,885], [445,895]]\n",
276-
"bins = [8,700,225,225]\n",
277-
"res_ph_peak_ns = sp_ph_peak.compute(bins=bins, axes=axes, ranges=ranges)\n",
278-
"\n",
279-
"res_ph_peak_ns['dldPosX'].attrs['unit'] = 'µm'\n",
280-
"res_ph_peak_ns['dldPosY'].attrs['unit'] = 'µm'\n",
281-
"\n",
249+
"res_ph_peak['dldPosX'].attrs['unit'] = 'pixel'\n",
250+
"res_ph_peak['dldPosY'].attrs['unit'] = 'pixel'\n",
282251
"fig,ax = plt.subplots(1,2,figsize=(6,2.25), layout='tight')\n",
283-
"res_ph_peak_ns.sum(('dldSectorID','dldPosX','dldPosY')).plot(ax=ax[0])\n",
284-
"res_ph_peak_ns.mean(('dldSectorID','dldTime')).plot(ax=ax[1], robust=True)"
252+
"res_ph_peak.sum(('dldSectorID','dldPosX','dldPosY')).plot(ax=ax[0])\n",
253+
"res_ph_peak.sel(dldTimeSteps=slice(2380,2400)).mean(('dldSectorID','dldTimeSteps')).plot(ax=ax[1], robust=True)"
285254
]
286255
},
287256
{
@@ -299,9 +268,9 @@
299268
"metadata": {},
300269
"outputs": [],
301270
"source": [
302-
"ph_peak_ns = res_ph_peak_ns.sel(dldTime=slice(390,397)).sum(('dldPosX','dldPosY'))\n",
271+
"ph_peak = res_ph_peak.sel(dldTimeSteps=slice(2380,2400)).sum(('dldPosX','dldPosY'))\n",
303272
"plt.figure(figsize=(6,4))\n",
304-
"ph_peak_ns.sum('dldSectorID').plot()"
273+
"ph_peak.sum('dldSectorID').plot()"
305274
]
306275
},
307276
{
@@ -312,6 +281,17 @@
312281
"Let's check the signal (photon peak) from every single sector"
313282
]
314283
},
284+
{
285+
"cell_type": "code",
286+
"execution_count": null,
287+
"id": "2fc9f73c",
288+
"metadata": {},
289+
"outputs": [],
290+
"source": [
291+
"plt.figure(figsize=(6,4))\n",
292+
"ph_peak.plot()"
293+
]
294+
},
315295
{
316296
"cell_type": "code",
317297
"execution_count": null,
@@ -320,7 +300,7 @@
320300
"outputs": [],
321301
"source": [
322302
"plt.figure(figsize=(6,4))\n",
323-
"for i, item in enumerate(ph_peak_ns):\n",
303+
"for i, item in enumerate(ph_peak):\n",
324304
" item.plot(label=f'S{i}')\n",
325305
" plt.legend()"
326306
]
@@ -330,7 +310,7 @@
330310
"id": "9a43f35b",
331311
"metadata": {},
332312
"source": [
333-
"### Width of the photon peak"
313+
"### Position of the photon peak"
334314
]
335315
},
336316
{
@@ -342,17 +322,17 @@
342322
"source": [
343323
"Gauss_mod = GaussianModel()\n",
344324
"\n",
345-
"x=ph_peak_ns['dldTime']\n",
346-
"y=ph_peak_ns.sum('dldSectorID')\n",
325+
"x=ph_peak['dldTimeSteps']\n",
326+
"y=ph_peak.sum('dldSectorID')\n",
347327
"\n",
348-
"pars = Gauss_mod.make_params(amplitude=1360.0, center=393.2, sigma=0.19)\n",
328+
"pars = Gauss_mod.make_params(amplitude=200, center=2390, sigma=1)\n",
349329
"# pars = Gauss_mod.guess(y, x=x)\n",
350330
"out = Gauss_mod.fit(y, pars, x=x)\n",
351331
"\n",
352332
"print(out.fit_report())\n",
353333
"plt.figure(figsize=(6,4))\n",
354334
"plt.plot(x,y, 'rx')\n",
355-
"plt.plot(x,out.best_fit, \"b\", label=\"FWHM = {:.3f} ns\".format(out.values['fwhm']))\n",
335+
"plt.plot(x,out.best_fit, \"b\", label=\"FWHM = {:.3f}\".format(out.values['fwhm']))\n",
356336
"plt.title(f'Run {run_number}, full photon peak')\n",
357337
"plt.legend(loc=\"best\")\n",
358338
"plt.xlabel(\"dldTime [ns]\")"
@@ -374,19 +354,32 @@
374354
"outputs": [],
375355
"source": [
376356
"plt.figure(figsize=(6,4))\n",
377-
"for i, item in enumerate(ph_peak_ns):\n",
378-
" x=ph_peak_ns['dldTime']\n",
357+
"sector_delays = np.zeros(8)\n",
358+
"for i, item in enumerate(ph_peak):\n",
359+
" x=ph_peak['dldTimeSteps']\n",
379360
" y=item\n",
380-
" pars = Gauss_mod.make_params(amplitude=800.1, center=393.0, sigma=0.3)\n",
361+
" pars = Gauss_mod.make_params(amplitude=200, center=2390, sigma=1)\n",
381362
" out = Gauss_mod.fit(y, pars, x=x)\n",
382-
" Center = 393.38961071\n",
363+
" Center = 2388.984276411258\n",
383364
" Diff = \"{:.3f}\".format(Center - out.values['center'])\n",
365+
" sector_delays[i] = (out.values['center'])\n",
384366
" FWHM = \"{:.3f}\".format(out.values['fwhm'])\n",
385-
" item.plot(label=f'S{i}={Diff}, FWHM = {FWHM} ns')\n",
367+
" item.plot(label=f'S{i}={Diff}, FWHM = {FWHM}')\n",
386368
" plt.title(f'Run {run_number}, individual sectors, not aligned')\n",
387369
" plt.legend()"
388370
]
389371
},
372+
{
373+
"cell_type": "code",
374+
"execution_count": null,
375+
"id": "a41757a4",
376+
"metadata": {},
377+
"outputs": [],
378+
"source": [
379+
"sector_delays = sector_delays - np.mean(sector_delays)\n",
380+
"sector_delays"
381+
]
382+
},
390383
{
391384
"cell_type": "markdown",
392385
"id": "ba4edbe6",
@@ -403,7 +396,17 @@
403396
"metadata": {},
404397
"outputs": [],
405398
"source": [
406-
"sp_ph_peak.align_dld_sectors()"
399+
"sp_ph_peak.align_dld_sectors(sector_delays=sector_delays)"
400+
]
401+
},
402+
{
403+
"cell_type": "code",
404+
"execution_count": null,
405+
"id": "e1e7ed7a",
406+
"metadata": {},
407+
"outputs": [],
408+
"source": [
409+
"sp_ph_peak.dataframe[[\"dldTimeSteps\", \"dldSectorID\"]].head()"
407410
]
408411
},
409412
{
@@ -422,16 +425,16 @@
422425
"metadata": {},
423426
"outputs": [],
424427
"source": [
425-
"axes = ['dldSectorID', 'dldTime','dldPosX','dldPosY']\n",
426-
"ranges = [[0,8], [390,460], [435,885], [445,895]]\n",
428+
"axes = ['dldSectorID', 'dldTimeSteps','dldPosX','dldPosY']\n",
429+
"ranges = [[0,8], [2360,2460], [435,885], [445,895]]\n",
427430
"bins = [8,700,225,225]\n",
428-
"res_ph_peak_ns_align = sp_ph_peak.compute(bins=bins, axes=axes, ranges=ranges)\n",
431+
"res_ph_peak_align = sp_ph_peak.compute(bins=bins, axes=axes, ranges=ranges)\n",
429432
"\n",
430-
"ph_peak_ns_align = res_ph_peak_ns_align.sel(dldTime=slice(390,397)).sum(('dldPosX','dldPosY'))\n",
433+
"ph_peak_align = res_ph_peak_align.sel(dldTimeSteps=slice(2380,2400)).sum(('dldPosX','dldPosY'))\n",
431434
"\n",
432435
"fig,ax = plt.subplots(1,2,figsize=(6,3.25), layout='tight')\n",
433-
"ph_peak_ns_align.sum('dldSectorID').plot(ax=ax[0])\n",
434-
"for i, item in enumerate(ph_peak_ns_align):\n",
436+
"ph_peak_align.sum('dldSectorID').plot(ax=ax[0])\n",
437+
"for i, item in enumerate(ph_peak_align):\n",
435438
" item.plot(ax=ax[1], label=f'S{i}')\n",
436439
" plt.legend()"
437440
]
@@ -445,17 +448,16 @@
445448
"source": [
446449
"Gauss_mod = GaussianModel()\n",
447450
"\n",
448-
"x=ph_peak_ns_align['dldTime']\n",
449-
"y=ph_peak_ns_align.sum('dldSectorID')\n",
451+
"x=ph_peak_align['dldTimeSteps']\n",
452+
"y=ph_peak_align.sum('dldSectorID')\n",
450453
"\n",
451-
"pars = Gauss_mod.make_params(amplitude=1360.1, center=393.2, sigma=0.2)\n",
452-
"# pars = Gauss_mod.guess(y, x=x)\n",
454+
"pars = Gauss_mod.make_params(amplitude=200, center=2390, sigma=1)\n",
453455
"out = Gauss_mod.fit(y, pars, x=x)\n",
454456
"\n",
455457
"print(out.fit_report())\n",
456458
"plt.figure(figsize=(6,4))\n",
457459
"plt.plot(x,y, 'rx')\n",
458-
"plt.plot(x,out.best_fit, \"b\", label=\"FWHM = {:.3f} ns\".format(out.values['fwhm']))\n",
460+
"plt.plot(x,out.best_fit, \"b\", label=\"FWHM = {:.3f}\".format(out.values['fwhm']))\n",
459461
"plt.title(f'Run {run_number}, full photon peak, sectors aligned')\n",
460462
"plt.legend(loc=\"best\")\n",
461463
"plt.xlabel(\"dldTime [ns]\")\n",
@@ -486,12 +488,12 @@
486488
"outputs": [],
487489
"source": [
488490
"plt.figure(figsize=(6,4))\n",
489-
"for i, item in enumerate(ph_peak_ns):\n",
490-
" x=ph_peak_ns_align['dldTime']\n",
491+
"for i, item in enumerate(ph_peak_align):\n",
492+
" x=ph_peak_align['dldTimeSteps']\n",
491493
" y=item\n",
492-
" pars = Gauss_mod.make_params(amplitude=800.0, center=393.0, sigma=0.3)\n",
494+
" pars = Gauss_mod.make_params(amplitude=800.0, center=2390, sigma=1)\n",
493495
" out = Gauss_mod.fit(y, pars, x=x)\n",
494-
" Center = 393.3899565\n",
496+
" Center = 2388.984276411258\n",
495497
" Diff = \"{:.3f}\".format(Center - out.values['center'])\n",
496498
" FWHM = \"{:.3f}\".format(out.values['fwhm'])\n",
497499
" item.plot(label=f'S{i}={Diff}, FWHM = {FWHM} ns')\n",

0 commit comments

Comments
 (0)