You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Area detector analysis in smalldata_tools is handled using sublclasses of DetObjectFunc. In order to be itnegrated in the workflow, the function must subclass that object.

Let's start with an example of how to add a ROI function to a detector and process it over a couple events:

DetObjectFunc simple example
import psana

from smalldata_tools.DetObject import DetObject, DetObjectFunc
from smalldata_tools.SmallDataUtils import getUserData
from smalldata_tools.ana_funcs.roi_rebin import ROIFunc

# get psana data source
exp = 'xpptut15'
run = 650
dsname = f'exp={exp}:run={run}'
ds = ps.MPIDataSource(dsname)

# instantiate Jungfrau detector object
det = dobj.DetObject('jungfrau1M', ds.env(), int(run))

# prepare the ROI function
# See https://github.com/slac-lcls/smalldata_tools/blob/master/smalldata_tools/ana_funcs/roi_rebin.py
# for info on the ROI function arguments
func_kwargs['ROI'] = [ [[0,1],[100,120],[50,60]] ] # a random ROI
func_kwargs['thresADU'] = None
func_kwargs['writeArea'] = False
func = ROIFunc(**func_kwargs)

# Attach function to the detector
det.addFunc(func)

# Process a couple events
userDict = {} # dictionary to store detector data

small_data = ds.small_data('./test.h5', gather_interval=5) # file to save data to
ds.break_after(5) # stop event loop after 5 events

for nevt,evt in enumerate(ds.events()): # usual psana event loop
	det.getData(evt) # get the detector data
	det.processFuncs() # process the attached functions
	userDict[det._name]=getUserData(det) # get the function results
	
	small_data.event(userDict) # write data to h5



  • No labels