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

Compare with Current View Page History

« Previous Version 4 Next »

Content

This note describes the python modules which help to get calibrated geometry information for CSPAD2x2.

Calibration types

Type

Shape

Description

center

(3, 2)

x, y, z coordinates of the two 2x1 centers

tilt

(2,)

tilt angle of the two 2x1s assuming rotation angle = 180 degrees

beam_vector

(3,)

The same as for CSPAD

filter

(3,)

The same as for CSPAD

common_mode

(3,)

The same as for CSPAD

pedestals

(185, 388, 2)

The same as for CSPAD

pixel_status

(185, 388, 2)

The same as for CSPAD

Functionality of modules

Class name

Functionality

CSPAD2x2CalibPars.py

Provides access to the calibration parameters through the DB

CSPAD2x2CalibParsDefault.py

Sets default values for all calibration types

CSPAD2x2Examples.py

Example of how to get calibrated data, get image, and plot it

CSPAD2x2PixCoords.py

Provides access to the pixel coordinate arrays

PixCoords2x1.py

Provides access to the pixel coordinate arrays for 2x1 sensor

Interface

Mandatory imports

import CSPAD2x2PixCoords as pixcoor
import CSPAD2x2CalibPars as calpars

Instantiate object with calibration parameters

Define path to the directory with calibration types and instantiate the calib object
for run:int number with access to the calibration constants from the list 'center', 'tilt', 'pedestals':

    # Official path:
    path = '/reg/d/psdm/mec/mec73313/calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.1/
    # or local:
    # path = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-01-2013-02-13/'

    calib = calpars.CSPAD2x2CalibPars(path, run, ['center', 'tilt', 'pedestals'])

Get pixel coordinates

Instantiate the coord object, using calibration parameters loaded ib the calib object and get the X and Y pixel coordinate arrays of shape (185, 388, 2):

    coord = pixcoor.CSPAD2x2PixCoords(calib)
    X,Y = coord.get_cspad2x2_pix_coordinate_arrays_pix()

Get array of calibration parameters

Get array of calibration parameters of specific type:

    peds_arr = calib.getCalibPars('pedestals')

Get CSPAD2x2 data array from hdf5 file

import HDF5Methods as hm 
    fname  = '/reg/neh/home1/dubrovin/LCLS/HDF5Analysis-v01/PyCSPadImage/src/mec73313-r0180.h5
    dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/MecTargetChamber.0:Cspad2x2.1/data'
    data_arr = hm.getDataSetForOneEvent(fname, dsname, event=0)

Get CSPAD2x2 data array from hdf5 file

import GlobalGraphics as gg
    my_range = None
    my_range = (-10,40)
    gg.plotImageLarge(img2d, range=my_range)        
    gg.plotSpectrum(img2d, range=my_range)
    gg.show()

Code example

Essential code of the module CSPAD2x2Examples.py:

import sys
import numpy as np
import CSPAD2x2PixCoords as pixcoor
import CSPAD2x2CalibPars as calpars

import HDF5Methods       as hm 
import GlobalGraphics    as gg
#------------------------------

def test_cspad2x2_calib() :


    #======= Input parameters
    Ndet = 5
    run  = 180

    path = '/reg/d/psdm/mec/mec73313/calib/CsPad2x2::CalibV1/MecTargetChamber.0:Cspad2x2.%1d/' % Ndet
    #path = '/reg/neh/home1/dubrovin/LCLS/CSPad2x2Alignment/calib-cspad2x2-0%1d-2013-02-13/' % Ndet

    #fname  = '/reg/d/psdm/mec/mec73313/hdf5/mec73313-r%04d.h5' % run
    fname  = '/reg/neh/home1/dubrovin/LCLS/HDF5Analysis-v01/PyCSPadImage/src/mec73313-r%04d.h5' % run
    dsname = '/Configure:0000/Run:0000/CalibCycle:0000/CsPad2x2::ElementV1/MecTargetChamber.0:Cspad2x2.%1d/data' % Ndet

    #======= Get calibration parameters

    calib = calpars.CSPAD2x2CalibPars(path, run, ['center', 'tilt', 'pedestals'])

    #======= Get CSPAD2x2 pixel coordinate arrays
    
    coord = pixcoor.CSPAD2x2PixCoords(calib)
    X,Y = coord.get_cspad2x2_pix_coordinate_arrays_pix()

    #======= Get CSPAD2x2 pedestals array

    peds_arr = calib.getCalibPars('pedestals')

    #======= Get data array from hdf5 dataset
    data_arr = hm.getDataSetForOneEvent(fname, dsname, event=0) - peds_arr
    
    ord_arr  = calpars.data2x2ToTwo2x1(data_arr)

    #======= Compose and plot CSPAD2x2 image from coordinate and intensity arrays

    img2d = pixcoor.getImage(X,Y,ord_arr)

    #======= Print for test purpose 

    calib.printCalibParsStatus()

    #print 'pedestals:\n', calib.getCalibPars('pedestals')
    print 'center:\n',    calib.getCalibPars('center')
    print 'tilt:\n',      calib.getCalibPars('tilt')
    print 'peds_arr.shape:', peds_arr.shape  # = (185, 388, 2)  
    print 'Get data array from file: ' + fname
    print 'data_arr.shape:', data_arr.shape
    print 'ord_arr.shape:', ord_arr.shape
    print 'img2d.shape:', img2d.shape

    #======= Plot image and spectrum

    my_range = (-10,40) # or None by default
    gg.plotImageLarge(img2d, range=my_range)        
    gg.plotSpectrum(img2d, range=my_range)
    gg.show()

#------------------------------
 
if __name__ == "__main__" :
    test_cspad2x2_calib()
    sys.exit ( 'End of test.' )

#------------------------------
  • No labels