Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleCode example for PythonEditor
collapsetrue
import psana.detector.utils_amicalib_components as uaucc

np, info_ndarr, table_nxn_epix10ka_from_ndarr =\
  ucc.np, ucc.info_ndarr, ucc.psu.table_nxn_epix10ka_from_ndarr


class EventProcessor():

    def __init__(self):
        self.counter = 0
        self.cc = None
 
    def begin_run(self):
        pass

    def end_run(self):
        pass

    def begin_step(self, step):
        pass

    def end_step(self, step):
        pass
     
    def on_event(self, raw, config, calibconst, *args, **kwargs):
        self.counter += 1
        if self.cc is None:
            self.cc = uaucc.calib_components_epix(calibconst, config)
        cc = self.cc

        kwa = {'status': True}
        cmpars = (0, 7, 300, 10)

        ctypes   = cc.calib_types() # list of calibration types
        npanels  = cc.number_of_panels() # number of panels/segments in the detector
        peds     = cc.pedestals() # OR cc.calib_constants('pedestals')
        gain     = cc.gain()      # OR cc.calib_constants('pixel_gain') # ADU/keV
        gfactor  = cc.gain_factor() # keV/ADU
        status   = cc.status() # 4-d array of pixel_status constants
        comode   = cc.common_mode()  # tuple of common mode correction parameters
        trbit_p0 = cc.trbit_for_panel(0)  # list of per-ASIC trbit for panel 0
        ascfg_p0 = cc.asicPixelConfig_for_panel(0) # matrix of asicPixelConfig for panel 0
        mask     = cc.mask(status=True)**kwa) # mask defined by kwa
        dettype  = cc.dettype() # detector type, e.g.  "epix10ka" or "epixhr"
        cbitscfg = cc.cbits_config_detector()
        cbitstot = cc.cbits_config_and_data_detector(raw, cbitscfg)
        gmapgmaps     = cc.gain_maps_epix10ka_anyepix(raw) # gain map
        pedest peds_ev  = cc.event_pedestals(raw) # per-pixel array of pedestals in the event
        factor gfac_ev  = cc.event_gain_factor(raw) # per-pixel array of gain factors in the event
        calibcalib0    = cc.calib(raw, cmpars=(0, 7, 300, 10))**kwa) # method calib
        cmcorr   = cc.common_mode_correction(raw, cmpars=(0, 7, 300, 10))cmpars, **kwa) # common mode correction
        arrf = np.array(raw & cc.data_bit_mask(), dtype=np.float32) - pedest

        print('== Event %04d ==' % self.counter)
#        print('config', cc.config)
#        print('calib_typesmetadata', ctypescc.calib_metadata('pedestals'))
#        print('calib_metadatatypes', cc.calib_metadata('pedestals')ctypes)
        print(ua.info_ndarr(peds, 'pedestals'))
        print(ua.info_ndarr(cc.gain(), 'gain'))
        print(ua.info_ndarr(gfactor, 'gain_factor'))
        print(ua.info_ndarr(status, 'status'))
        print('common_mode from caliconst', str(comode))        
        print('number_of_panels', npanels)
        print('trbit_for_panel(0)', trbit_p0)
        print(ua.info_ndarr(ascfg_p0, 'asicPixelConfig_for_panel(0)'))
        print(ua.info_ndarr(raw, 'raw'))
        print(ua.info_ndarr(mask, 'mask'))
        print('dettype', dettype)
        print(ua.info_ndarr(cbitscfg, 'cbitscfg'))
        print(ua.info_ndarr(cbitstot, 'cbitstot'))
        print(ua.info_ndarr(gmapgmaps, 'gmapgmaps'))
        print(ua.info_ndarr(peds_ev, 'peds_evpedest, 'pedest'))
        print(info_ndarr(factor, 'factor'))
        print(info_ndarr(cmcorr, 'cmcorr'))
        print(ua.info_ndarr(gfac_ev(arrf, 'raw(data bits)-peds'))
        print(info_ndarr(calib0, 'gfac_ev'))
calib0'))

        # det.raw.calib(...) algorithm close reproduction
        calib1 = None
        if True:
            arrf1 = arrf.copy()
            cc.common_mode_apply(arrf1, gmaps, cmpars=cmpars, **kwa)
            calib1 = arrf1 * factor if mask is None else arrf1 * factor * mask
            print(ua.info_ndarr(calibcalib1, 'calib'))
calib1'))

        # det.raw.calib(...) - effective algorithm
        calib2 = None
        if True:
            arrf2 = arrf.copy() + cmcorr
            calib2 = arrf2 * factor if mask is None else arrf2 * factor * mask
            print(ua.info_ndarr(cmcorrcalib2, 'cmcorrcalib2'))

        # img = cmcorr[0, 144:, :192]
        # img = ua.psu.table_nxn_epix10ka_from_ndarr(cmcorr)
        img = table_nxn_epix10ka_from_ndarr(calib1)
        print(ua.info_ndarr(img, 'img'))
        return img

Composition of Control Nodes in the example

Implementation of the class calib_

...

componenents_epix

  • Module detector/utils_calib_amicomponents.py will be available in releases grater than ps-4.5.24.
  • It is implemented for epix10ka and epixhr detector types.
  • Code example is also available in the head of this module.
  • Common mode correction methods are not available yet in this example.

...