Advertisement
Kaze3

B07 Flux-Energy Resolution-Footprint Calculation Macro

Jun 20th, 2013
1,031
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; set parameters for calculations here
  2. slitValues = [];   um
  3. mirrorValues = [];  deg wrt. normal
  4. alphaValues = [];   deg wrt. normal
  5. betaValues = [];    deg wrt. normal
  6. energyValues = [];   eV
  7. divergenceValues = [];   mrad
  8. resolvingPower = ;
  9. lineDensity = ;    l/mm
  10. cff = ;
  11.  
  12. ; ----------------------------------------------------------
  13.  
  14. ; open output file
  15. fname='output.txt';
  16. openw,lun,fname,/get_lun;
  17.  
  18. window,/free;
  19.  
  20. FOR j=0,N_Elements(energyValues)-1 DO BEGIN
  21.   energy=energyValues[j];
  22.   divergence=divergenceValues[j];
  23.   alpha=alphaValues[j];
  24.   beta=betaValues[j];
  25.   mirrorAngle=mirrorValues[j];
  26.  
  27.   ; calculate energy width
  28.   energyHalfWidth=(energy/resolvingPower)*(10.0/2.0);
  29.   eMin=energy-energyHalfWidth;
  30.   eMax=energy+energyHalfWidth;
  31.  
  32.   ; print source parameters
  33.   printf,lun,'energy='+string(energy);
  34.   printf,lun,'eMin='+string(eMin);
  35.   printf,lun,'eMax='+string(eMax);
  36.   printf,lun,'divergence='+string(divergence);
  37.  
  38.   ; set source energy width and divergence
  39.   source=read_gfile('start.00');
  40.   source.PH1=eMin;
  41.   source.PH2=eMax;
  42.   source.VDIV1=divergence/(1000.0*2.0);
  43.   source.VDIV2=divergence/(1000.0*2.0);
  44.   write_gfile,source,'start.00';
  45.  
  46.   ; run source calculation
  47.   xsh_run,'gen_source start.00';
  48.  
  49.   ; set plane mirror angles
  50.   planeMirror=read_gfile('start.02');
  51.   planeMirror.T_INCIDENCE=mirrorAngle
  52.   planeMirror.T_REFLECTION=mirrorAngle
  53.   write_gfile,planeMirror,'start.02';
  54.  
  55.   ; set grating parameters
  56.   pgm=read_gfile('start.03');
  57.   pgm.PHOT_CENT=energy;
  58.   pgm.T_INCIDENCE=alpha;
  59.   pgm.T_REFLECTION=beta;
  60.   pgm.RULING=lineDensity*10.0;
  61.   write_gfile,pgm,'start.03';
  62.  
  63.   ; print angle parameters
  64.   printf,lun,'alpha='+string(alpha);
  65.   printf,lun,'beta='+string(beta);
  66.   printf,lun,'mirrorAngle='+string(mirrorAngle);
  67.   printf,lun,'lineDensity='+string(lineDensity);
  68.   printf,lun,'cff='+string(cff);
  69.   printf,lun,'';
  70.  
  71.   ; print headings for results
  72.   printf,lun,'slit_gap good_rays energy_res hor_size vert_size pgm_foot vfm_foot';
  73.  
  74.   ; run trace for all slit width values
  75.   FOR i=0,N_Elements(slitValues)-1 DO BEGIN
  76.     slit=slitValues[i];
  77.  
  78.     ; set slit gap
  79.     cylindricalMirror=read_gfile('start.04');
  80.     cylindricalMirror.RX_SLIT(0)=slit/10000.0;
  81.     write_gfile,cylindricalMirror,'start.04';
  82.  
  83.     ; run ray trace
  84.     xsh_run,'echo 0 | trace -m menu';
  85.  
  86.     ; find beam size and intensity
  87.     plotxy,'star.06',3,1,nolost=1,cart=1,calfwhm=1,gaussfit=2,mulfac=10000,fwhm_fit=size,extract=points;
  88.  
  89.     horSize=size[0];
  90.     vertSize=size[1];
  91.     goodRays=n_elements(points[0,*]);
  92.  
  93.     ; find energy resolution
  94.     histo1,'star.06',11,gaussfit=2,nolost=1,calfwhm=1,fwhm_fit=energyRes;
  95.  
  96.     ; find pgm footprint
  97.     plotxy,'mirr.03',2,1,nolost=1,cart=1,calfwhm=1,gaussfit=2,mulfac=10,fwhm_val=pgmFootVal;
  98.  
  99.     ; find vfm footprint
  100.     plotxy,'mirr.05',2,1,nolost=1,cart=1,calfwhm=1,gaussfit=2,mulfac=10,fwhm_val=vfmFootVal;
  101.  
  102.     pgmFoot=pgmFootVal[0];
  103.     vfmFoot=vfmFootVal[0];
  104.  
  105.     ; print results line
  106.     printf,lun,string(slit)+' '+string(goodRays)+' '+string(energyRes)+' '+string(horSize)+' '+string(vertSize)+' '+string(pgmFoot)+' '+string(vfmFoot);
  107.   ENDFOR
  108.  
  109.   printf,lun,'';
  110. ENDFOR
  111.  
  112. ; close output file
  113. close,lun;
  114. free_lun,lun;
Advertisement
RAW Paste Data Copied
Advertisement