def BLMatrixMult(LensMatrX, LensMatrY, DriftMatr, DriftMatr0): """Computes envelope in free space""" InitDriftLenseX = matr_prod(LensMatrX, DriftMatr0) tRMSfunX = matr_prod(DriftMatr, InitDriftLenseX) InitDriftLenseY = matr_prod(LensMatrY, DriftMatr0) tRMSfunY = matr_prod(DriftMatr, InitDriftLenseY) return (tRMSfunX, tRMSfunY)
def set_optics(_v): """This function describes optical layout of the Coherent Hoard X-ray (CHX) beamline of NSLS-II. Such function has to be written for every beamline to be simulated; it is specific to a particular beamline. :param _v: structure containing all parameters allowed to be varied for that particular beamline """ #---Nominal Positions of Optical Elements [m] (with respect to straight section center) zS0 = 33.1798 #White Beam Slits (S0) zHFM = 34.2608 #Horizontally-Focusing Mirror M1 (HFM) zS1 = 35.6678 #Pink Beam Slits (S1) zDCM = 36.4488 #Horizontall-Deflecting Double-Crystal Monochromator (DCM) zBPM1 = 38.6904 #BPM-1 zBPM2 = 50.3872 #BPM-2 zSSA = 50.6572 #Secondary Source Aperture (SSA) zEA = 61.9611 #Energy Absorber (EA) zDBPM1 = 62.272 #Diamond BPM-1 zKBFV = 62.663 #High-Flux Vertically-Focusing KB Mirror M2 zKBFH = 63.0 #High-Flux Horizontally-Focusing KB Mirror M3 zSF = 63.3 #High-Flux Sample position (focus of KBF) zDBPM2 = 65.9178 #Diamond BPM-2 zKBRV = 66.113 #High-Resolution Vertically-Focusing KB Mirror M4 zKBRH = 66.220 #High-Resolution Horizontally-Focusing KB Mirror M5 zSR = 63.3 #High-Resolution Sample position (focus of KBR) #zD = 65 #Detector position (?) #---Instantiation of the Optical Elements arElNamesAll_01 = ['S0', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_KBFV', 'KBFV', 'KBFV_KBFH', 'KBFH', 'KBFH_zSF'] arElNamesAll_02 = ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'] arElNamesAll_03 = ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_DBPM2', 'DBPM2_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'] arElNamesAll_04 = ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_SSA', 'SSA', 'SSA_DBPM2', 'DBPM2_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'] arElNamesAll = arElNamesAll_01 if(_v.op_BL == 2): arElNamesAll = arElNamesAll_02 elif(_v.op_BL == 3): arElNamesAll = arElNamesAll_03 elif(_v.op_BL == 4): arElNamesAll = arElNamesAll_04 ''' #Treat beamline sub-cases / alternative configurations if(len(_v.op_fin) > 0): if(_v.op_fin not in arElNamesAll): raise Exception('Optical element with the name specified in the "op_fin" option is not present in this beamline') #Could be made more general ''' arElNames = []; for i in range(len(arElNamesAll)): arElNames.append(arElNamesAll[i]) if(len(_v.op_fin) > 0): if(arElNamesAll[i] == _v.op_fin): break el = []; pp = [] #lists of SRW optical element objects and their corresponding propagation parameters #S0 (primary slit) if('S0' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_S0_dx, _v.op_S0_dy)); pp.append(_v.op_S0_pp) #Drift S0 -> HFM if('S0_HFM' in arElNames): el.append(SRWLOptD(zHFM - zS0)); pp.append(_v.op_S0_HFM_pp) #HDM (Height Profile Error) if('HFM' in arElNames): lenHFM = 0.95 #Length [m] horApHFM = lenHFM*_v.op_HFM_ang #Projected dimensions verApHFM = 5.e-03 #? el.append(SRWLOptA('r', 'a', horApHFM, verApHFM)); pp.append(_v.op_HFMA_pp) if(_v.op_HFM_f != 0.): el.append(SRWLOptL(_Fx=_v.op_HFM_f)); pp.append(_v.op_HFML_pp) #To treat Reflectivity (maybe by Planar Mirror?) #elif(_v.op_HFM_r != 0.): #Setup Cylindrical Mirror, take into account Reflectivity #Height Profile Error ifnHFM = os.path.join(_v.fdir, _v.op_HFM_ifn) if len(_v.op_HFM_ifn) > 0 else '' if(len(ifnHFM) > 0): #hProfDataHFM = srwl_uti_read_data_cols(ifnHFM, '\t', 0, 1) hProfDataHFM = srwl_uti_read_data_cols(ifnHFM, '\t') opHFM = srwl_opt_setup_surf_height_2d(hProfDataHFM, 'x', _ang=_v.op_HFM_ang, _amp_coef=_v.op_HFM_amp, _nx=1500, _ny=200) ofnHFM = os.path.join(_v.fdir, _v.op_HFM_ofn) if len(_v.op_HFM_ofn) > 0 else '' if(len(ofnHFM) > 0): pathDifHFM = opHFM.get_data(3, 3) srwl_uti_save_intens_ascii(pathDifHFM, opHFM.mesh, ofnHFM, 0, ['', 'Horizontal Position', 'Vertical Position', 'Opt. Path Dif.'], _arUnits=['', 'm', 'm', 'm']) el.append(opHFM); pp.append(_v.op_HFMT_pp) #Drift HFM -> S1 if('HFM_S1' in arElNames): el.append(SRWLOptD(zS1 - zHFM + _v.op_S1_dz)); pp.append(_v.op_HFM_S1_pp) #S1 slit if('S1' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_S1_dx, _v.op_S1_dy)); pp.append(_v.op_S1_pp) #Drift S1 -> DCM if('S1_DCM' in arElNames): el.append(SRWLOptD(zDCM - zS1 - _v.op_S1_dz)); pp.append(_v.op_S1_DCM_pp) #Drift S1 -> SSA if('S1_SSA' in arElNames): el.append(SRWLOptD(zSSA - zS1 - _v.op_S1_dz + _v.op_SSA_dz)); pp.append(_v.op_S1_SSA_pp) #Double-Crystal Monochromator if('DCM' in arElNames): tc = 1e-02 # [m] crystal thickness angAs = 0.*pi/180. # [rad] asymmetry angle hc = [1,1,1] if(_v.op_DCM_r == '311'): hc = [3,1,1] dc = srwl_uti_cryst_pl_sp(hc, 'Si') #print('DCM Interplannar dist.:', dc) psi = srwl_uti_cryst_pol_f(_v.op_DCM_e0, hc, 'Si') #MR15032016: replaced "op_DCM_e" by "op_DCM_e0" to test the import in Sirepo #print('DCM Fourier Components:', psi) #---------------------- DCM Crystal #1 opCr1 = SRWLOptCryst(_d_sp=dc, _psi0r=psi[0], _psi0i=psi[1], _psi_hr=psi[2], _psi_hi=psi[3], _psi_hbr=psi[2], _psi_hbi=psi[3], _tc=tc, _ang_as=angAs, _ang_roll=1.5707963, _e_avg=_v.op_DCM_e0) #Find appropriate orientation of the Crystal #1 and the Output Beam Frame (using a member-function in SRWLOptCryst): orientDataCr1 = opCr1.find_orient(_en=_v.op_DCM_e0, _ang_dif_pl=1.5707963) # Horizontally-deflecting #MR15032016: replaced "op_DCM_e" by "op_DCM_e0" to test the import in Sirepo #Crystal #1 Orientation found: orientCr1 = orientDataCr1[0] tCr1 = orientCr1[0] #Tangential Vector to Crystal surface sCr1 = orientCr1[1] nCr1 = orientCr1[2] #Normal Vector to Crystal surface # print('DCM Crystal #1 Orientation (original):') # print(' t =', tCr1, 's =', orientCr1[1], 'n =', nCr1) import uti_math if(_v.op_DCM_ac1 != 0): #Small rotation of DCM Crystal #1: rot = uti_math.trf_rotation([0,1,0], _v.op_DCM_ac1, [0,0,0]) tCr1 = uti_math.matr_prod(rot[0], tCr1) sCr1 = uti_math.matr_prod(rot[0], sCr1) nCr1 = uti_math.matr_prod(rot[0], nCr1) #Set the Crystal #1 orientation: opCr1.set_orient(nCr1[0], nCr1[1], nCr1[2], tCr1[0], tCr1[1]) #Orientation of the Outgoing Beam Frame being found: orientCr1OutFr = orientDataCr1[1] rxCr1 = orientCr1OutFr[0] #Horizontal Base Vector of the Output Beam Frame ryCr1 = orientCr1OutFr[1] #Vertical Base Vector of the Output Beam Frame rzCr1 = orientCr1OutFr[2] #Longitudinal Base Vector of the Output Beam Frame # print('DCM Crystal #1 Outgoing Beam Frame:') # print(' ex =', rxCr1, 'ey =', ryCr1, 'ez =', rzCr1) #Incoming/Outgoing beam frame transformation matrix for the DCM Crystal #1 TCr1 = [rxCr1, ryCr1, rzCr1] # print('Total transformation matrix after DCM Crystal #1:') # uti_math.matr_print(TCr1) #print(' ') el.append(opCr1); pp.append(_v.op_DCMC1_pp) #---------------------- DCM Crystal #2 opCr2 = SRWLOptCryst(_d_sp=dc, _psi0r=psi[0], _psi0i=psi[1], _psi_hr=psi[2], _psi_hi=psi[3], _psi_hbr=psi[2], _psi_hbi=psi[3], _tc=tc, _ang_as=angAs, _ang_roll=-1.5707963, _e_avg=_v.op_DCM_e0) #Find appropriate orientation of the Crystal #2 and the Output Beam Frame orientDataCr2 = opCr2.find_orient(_en=_v.op_DCM_e0, _ang_dif_pl=-1.5707963) #MR15032016: replaced "op_DCM_e" by "op_DCM_e0" to test the import in Sirepo #Crystal #2 Orientation found: orientCr2 = orientDataCr2[0] tCr2 = orientCr2[0] #Tangential Vector to Crystal surface sCr2 = orientCr2[1] nCr2 = orientCr2[2] #Normal Vector to Crystal surface # print('Crystal #2 Orientation (original):') # print(' t =', tCr2, 's =', sCr2, 'n =', nCr2) if(_v.op_DCM_ac2 != 0): #Small rotation of DCM Crystal #2: rot = uti_math.trf_rotation([0,1,0], _v.op_DCM_ac2, [0,0,0]) tCr2 = uti_math.matr_prod(rot[0], tCr2) sCr2 = uti_math.matr_prod(rot[0], sCr2) nCr2 = uti_math.matr_prod(rot[0], nCr2) #Set the Crystal #2 orientation opCr2.set_orient(nCr2[0], nCr2[1], nCr2[2], tCr2[0], tCr2[1]) #Orientation of the Outgoing Beam Frame being found: orientCr2OutFr = orientDataCr2[1] rxCr2 = orientCr2OutFr[0] #Horizontal Base Vector of the Output Beam Frame ryCr2 = orientCr2OutFr[1] #Vertical Base Vector of the Output Beam Frame rzCr2 = orientCr2OutFr[2] #Longitudinal Base Vector of the Output Beam Frame # print('DCM Crystal #2 Outgoing Beam Frame:') # print(' ex =', rxCr2, 'ey =', ryCr2, 'ez =',rzCr2) #Incoming/Outgoing beam transformation matrix for the DCM Crystal #2 TCr2 = [rxCr2, ryCr2, rzCr2] Ttot = uti_math.matr_prod(TCr2, TCr1) # print('Total transformation matrix after DCM Crystal #2:') # uti_math.matr_print(Ttot) #print(' ') el.append(opCr2); pp.append(_v.op_DCMC2_pp) #Drift DCM -> SSA if('DCM_SSA' in arElNames): el.append(SRWLOptD(zSSA - zDCM + _v.op_SSA_dz)); pp.append(_v.op_DCM_SSA_pp) #SSA slit if('SSA' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_SSA_dx, _v.op_SSA_dy)); pp.append(_v.op_SSA_pp) #Drift SSA -> DBPM2 if('SSA_DBPM2' in arElNames): el.append(SRWLOptD(zDBPM2 - zSSA - _v.op_SSA_dz + _v.op_DBPM2_dz)); pp.append(_v.op_SSA_DBPM2_pp) ###############To continue ## #Sample ## if('SMP' in arElNames): ## ifnSMP = os.path.join(v.fdir, v.op_SMP_ifn) if len(v.op_SMP_ifn) > 0 else '' ## if(len(ifnSMP) > 0): ## ifSMP = open(ifnSMP, 'rb') ## opSMP = pickle.load(ifSMP) ## ofnSMP = os.path.join(v.fdir, v.op_SMP_ofn) if len(v.op_SMP_ofn) > 0 else '' ## if(len(ofnSMP) > 0): ## pathDifSMP = opSMP.get_data(3, 3) ## srwl_uti_save_intens_ascii(pathDifSMP, opSMP.mesh, ofnSMP, 0, ['', 'Horizontal Position', 'Vertical Position', 'Opt. Path Dif.'], _arUnits=['', 'm', 'm', 'm']) ## el.append(opSMP); pp.append(v.op_SMP_pp) ## ifSMP.close() ## #Drift Sample -> Detector ## if('SMP_D' in arElNames): ## el.append(SRWLOptD(zD - zSample + v.op_D_dz)); pp.append(v.op_SMP_D_pp) pp.append(_v.op_fin_pp) return SRWLOptC(el, pp)
def set_optics(_v): """This function describes optical layout of the Coherent Hoard X-ray (CHX) beamline of NSLS-II. Such function has to be written for every beamline to be simulated; it is specific to a particular beamline. :param _v: structure containing all parameters allowed to be varied for that particular beamline """ #---Nominal Positions of Optical Elements [m] (with respect to straight section center) zS0 = 33.1798 #White Beam Slits (S0) zHFM = 34.2608 #Horizontally-Focusing Mirror M1 (HFM) zS1 = 35.6678 #Pink Beam Slits (S1) zDCM = 36.4488 #Horizontall-Deflecting Double-Crystal Monochromator (DCM) zBPM1 = 38.6904 #BPM-1 zBPM2 = 50.3872 #BPM-2 zSSA = 50.6572 #Secondary Source Aperture (SSA) zEA = 61.9611 #Energy Absorber (EA) zDBPM1 = 62.272 #Diamond BPM-1 zKBFV = 62.663 #High-Flux Vertically-Focusing KB Mirror M2 zKBFH = 63.0 #High-Flux Horizontally-Focusing KB Mirror M3 zSF = 63.3 #High-Flux Sample position (focus of KBF) zDBPM2 = 65.9178 #Diamond BPM-2 zKBRV = 66.113 #High-Resolution Vertically-Focusing KB Mirror M4 zKBRH = 66.220 #High-Resolution Horizontally-Focusing KB Mirror M5 zSR = 63.3 #High-Resolution Sample position (focus of KBR) #zD = 65 #Detector position (?) #---Instantiation of the Optical Elements arElNamesAllOpt = [ ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_KBFV', 'KBFV', 'KBFV_KBFH', 'KBFH', 'KBFH_zSF'], #1 ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'], #2 ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_DCM', 'DCM', 'DCM_SSA', 'SSA', 'SSA_DBPM2', 'DBPM2_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'], #3 ['S0', 'S0_HFM', 'HFM', 'HFM_S1', 'S1', 'S1_SSA', 'SSA', 'SSA_DBPM2', 'DBPM2_KBRV', 'KBRV', 'KBRV_KBRH', 'KBRH', 'KBRH_zSR'] #4 ] arElNamesAll = arElNamesAllOpt[int(round(_v.op_BL - 1))] ''' #Treat beamline sub-cases / alternative configurations if(len(_v.op_fin) > 0): if(_v.op_fin not in arElNamesAll): raise Exception('Optical element with the name specified in the "op_fin" option is not present in this beamline') #Could be made more general ''' arElNames = []; for i in range(len(arElNamesAll)): arElNames.append(arElNamesAll[i]) if(len(_v.op_fin) > 0): if(arElNamesAll[i] == _v.op_fin): break el = []; pp = [] #lists of SRW optical element objects and their corresponding propagation parameters #S0 (primary slit) if('S0' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_S0_dx, _v.op_S0_dy)); pp.append(_v.op_S0_pp) #Drift S0 -> HFM if('S0_HFM' in arElNames): el.append(SRWLOptD(zHFM - zS0)); pp.append(_v.op_S0_HFM_pp) #HFM (Height Profile Error) if('HFM' in arElNames): lenHFM = 0.95 #Length [m] horApHFM = lenHFM*_v.op_HFM_ang #Projected dimensions verApHFM = 5.e-03 #? el.append(SRWLOptA('r', 'a', horApHFM, verApHFM)); pp.append(_v.op_HFMA_pp) if(_v.op_HFM_f != 0.): el.append(SRWLOptL(_Fx=_v.op_HFM_f)); pp.append(_v.op_HFML_pp) #To treat Reflectivity (maybe by Planar Mirror?) #elif(_v.op_HFM_r != 0.): #Setup Cylindrical Mirror, take into account Reflectivity #Height Profile Error ifnHFM = os.path.join(_v.fdir, _v.op_HFM_ifn) if len(_v.op_HFM_ifn) > 0 else '' if(len(ifnHFM) > 0): #hProfDataHFM = srwl_uti_read_data_cols(ifnHFM, '\t', 0, 1) hProfDataHFM = srwl_uti_read_data_cols(ifnHFM, '\t') opHFM = srwl_opt_setup_surf_height_2d(hProfDataHFM, 'x', _ang=_v.op_HFM_ang, _amp_coef=_v.op_HFM_amp, _nx=1500, _ny=200) ofnHFM = os.path.join(_v.fdir, _v.op_HFM_ofn) if len(_v.op_HFM_ofn) > 0 else '' if(len(ofnHFM) > 0): pathDifHFM = opHFM.get_data(3, 3) srwl_uti_save_intens_ascii(pathDifHFM, opHFM.mesh, ofnHFM, 0, ['', 'Horizontal Position', 'Vertical Position', 'Opt. Path Dif.'], _arUnits=['', 'm', 'm', 'm']) el.append(opHFM); pp.append(_v.op_HFMT_pp) #Drift HFM -> S1 if('HFM_S1' in arElNames): el.append(SRWLOptD(zS1 - zHFM + _v.op_S1_dz)); pp.append(_v.op_HFM_S1_pp) #S1 slit if('S1' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_S1_dx, _v.op_S1_dy)); pp.append(_v.op_S1_pp) #Drift S1 -> DCM if('S1_DCM' in arElNames): el.append(SRWLOptD(zDCM - zS1 - _v.op_S1_dz)); pp.append(_v.op_S1_DCM_pp) #Drift S1 -> SSA if('S1_SSA' in arElNames): el.append(SRWLOptD(zSSA - zS1 - _v.op_S1_dz + _v.op_SSA_dz)); pp.append(_v.op_S1_SSA_pp) #Double-Crystal Monochromator if('DCM' in arElNames): tc = 1e-02 # [m] crystal thickness angAs = 0.*pi/180. # [rad] asymmetry angle hc = [1,1,1] if(_v.op_DCM_r == '311'): hc = [3,1,1] dc = srwl_uti_cryst_pl_sp(hc, 'Si') #print('DCM Interplannar dist.:', dc) psi = srwl_uti_cryst_pol_f(_v.op_DCM_e, hc, 'Si') #print('DCM Fourier Components:', psi) #---------------------- DCM Crystal #1 opCr1 = SRWLOptCryst(_d_sp=dc, _psi0r=psi[0], _psi0i=psi[1], _psi_hr=psi[2], _psi_hi=psi[3], _psi_hbr=psi[2], _psi_hbi=psi[3], _tc=tc, _ang_as=angAs) #Find appropriate orientation of the Crystal #1 and the Output Beam Frame (using a member-function in SRWLOptCryst): orientDataCr1 = opCr1.find_orient(_en=_v.op_DCM_e, _ang_dif_pl=1.5707963) # Horizontally-deflecting #Crystal #1 Orientation found: orientCr1 = orientDataCr1[0] tCr1 = orientCr1[0] #Tangential Vector to Crystal surface sCr1 = orientCr1[1] nCr1 = orientCr1[2] #Normal Vector to Crystal surface # print('DCM Crystal #1 Orientation (original):') # print(' t =', tCr1, 's =', orientCr1[1], 'n =', nCr1) import uti_math if(_v.op_DCM_ac1 != 0): #Small rotation of DCM Crystal #1: rot = uti_math.trf_rotation([0,1,0], _v.op_DCM_ac1, [0,0,0]) tCr1 = uti_math.matr_prod(rot[0], tCr1) sCr1 = uti_math.matr_prod(rot[0], sCr1) nCr1 = uti_math.matr_prod(rot[0], nCr1) #Set the Crystal #1 orientation: opCr1.set_orient(nCr1[0], nCr1[1], nCr1[2], tCr1[0], tCr1[1]) #Orientation of the Outgoing Beam Frame being found: orientCr1OutFr = orientDataCr1[1] rxCr1 = orientCr1OutFr[0] #Horizontal Base Vector of the Output Beam Frame ryCr1 = orientCr1OutFr[1] #Vertical Base Vector of the Output Beam Frame rzCr1 = orientCr1OutFr[2] #Longitudinal Base Vector of the Output Beam Frame # print('DCM Crystal #1 Outgoing Beam Frame:') # print(' ex =', rxCr1, 'ey =', ryCr1, 'ez =', rzCr1) #Incoming/Outgoing beam frame transformation matrix for the DCM Crystal #1 TCr1 = [rxCr1, ryCr1, rzCr1] # print('Total transformation matrix after DCM Crystal #1:') # uti_math.matr_print(TCr1) #print(' ') el.append(opCr1); pp.append(_v.op_DCMC1_pp) #---------------------- DCM Crystal #2 opCr2 = SRWLOptCryst(_d_sp=dc, _psi0r=psi[0], _psi0i=psi[1], _psi_hr=psi[2], _psi_hi=psi[3], _psi_hbr=psi[2], _psi_hbi=psi[3], _tc=tc, _ang_as=angAs) #Find appropriate orientation of the Crystal #2 and the Output Beam Frame orientDataCr2 = opCr2.find_orient(_en=_v.op_DCM_e, _ang_dif_pl=-1.5707963) #Crystal #2 Orientation found: orientCr2 = orientDataCr2[0] tCr2 = orientCr2[0] #Tangential Vector to Crystal surface sCr2 = orientCr2[1] nCr2 = orientCr2[2] #Normal Vector to Crystal surface # print('Crystal #2 Orientation (original):') # print(' t =', tCr2, 's =', sCr2, 'n =', nCr2) if(_v.op_DCM_ac2 != 0): #Small rotation of DCM Crystal #2: rot = uti_math.trf_rotation([0,1,0], _v.op_DCM_ac2, [0,0,0]) tCr2 = uti_math.matr_prod(rot[0], tCr2) sCr2 = uti_math.matr_prod(rot[0], sCr2) nCr2 = uti_math.matr_prod(rot[0], nCr2) #Set the Crystal #2 orientation opCr2.set_orient(nCr2[0], nCr2[1], nCr2[2], tCr2[0], tCr2[1]) #Orientation of the Outgoing Beam Frame being found: orientCr2OutFr = orientDataCr2[1] rxCr2 = orientCr2OutFr[0] #Horizontal Base Vector of the Output Beam Frame ryCr2 = orientCr2OutFr[1] #Vertical Base Vector of the Output Beam Frame rzCr2 = orientCr2OutFr[2] #Longitudinal Base Vector of the Output Beam Frame # print('DCM Crystal #2 Outgoing Beam Frame:') # print(' ex =', rxCr2, 'ey =', ryCr2, 'ez =',rzCr2) #Incoming/Outgoing beam transformation matrix for the DCM Crystal #2 TCr2 = [rxCr2, ryCr2, rzCr2] Ttot = uti_math.matr_prod(TCr2, TCr1) # print('Total transformation matrix after DCM Crystal #2:') uti_math.matr_print(Ttot) #print(' ') el.append(opCr2); pp.append(_v.op_DCMC2_pp) #Drift DCM -> SSA if('DCM_SSA' in arElNames): el.append(SRWLOptD(zSSA - zDCM + _v.op_SSA_dz)); pp.append(_v.op_DCM_SSA_pp) #SSA slit if('SSA' in arElNames): el.append(SRWLOptA('r', 'a', _v.op_SSA_dx, _v.op_SSA_dy)); pp.append(_v.op_SSA_pp) #Drift SSA -> DBPM2 if('SSA_DBPM2' in arElNames): el.append(SRWLOptD(zDBPM2 - zSSA - _v.op_SSA_dz + _v.op_DBPM2_dz)); pp.append(_v.op_SSA_DBPM2_pp) ###############To continue ## #Sample ## if('SMP' in arElNames): ## ifnSMP = os.path.join(v.fdir, v.op_SMP_ifn) if len(v.op_SMP_ifn) > 0 else '' ## if(len(ifnSMP) > 0): ## ifSMP = open(ifnSMP, 'rb') ## opSMP = pickle.load(ifSMP) ## ofnSMP = os.path.join(v.fdir, v.op_SMP_ofn) if len(v.op_SMP_ofn) > 0 else '' ## if(len(ofnSMP) > 0): ## pathDifSMP = opSMP.get_data(3, 3) ## srwl_uti_save_intens_ascii(pathDifSMP, opSMP.mesh, ofnSMP, 0, ['', 'Horizontal Position', 'Vertical Position', 'Opt. Path Dif.'], _arUnits=['', 'm', 'm', 'm']) ## el.append(opSMP); pp.append(v.op_SMP_pp) ## ifSMP.close() ## #Drift Sample -> Detector ## if('SMP_D' in arElNames): ## el.append(SRWLOptD(zD - zSample + v.op_D_dz)); pp.append(v.op_SMP_D_pp) pp.append(_v.op_fin_pp) return SRWLOptC(el, pp)
:return M: result of multiplication. """ M = [] for i in range(len(A[0])): M.append([]) for j in range(len(B[0])): M[i].append(0.0) for i in range(len(A)): # Iterate through columns of B: for j in range(len(B[0])): # Iterate through rows of B: for k in range(len(B)): M[i][j] += A[i][k] * B[k][j] return M if __name__ == "__main__": import numpy as np from uti_math import matr_prod a = [[12.1, 7, 3], [4, 5, 6], [7, 8, 9]] b = [[5, 8, 1, 2], [6, 7, 3, 0], [4, 5, 9, 1]] m1 = dot(a, b) m2 = np.dot(a, b) m3 = matr_prod(a, b) print ""