/* Let us demostrate the use of surface roughness generating a
   punctual source at 8035eV with horizontal divergence of 1mrad
   and vertical divergence of 0.1mrad, and trace an ellipsoidal
   mirror focussing the source in a spot placed at 10m downstream
   the mirror. The distance source-mirror is 30m and the incidence
   angle is 88.5 deg. This system produces a punctual image when
   no roughness are considered and we will see how the spot size
   is degradated when including different values of roughness.
   For this purpose we need a file with the PSD function. We use
   the jntpscalc utility to calculate the 2-dimensional PDS function
   with correlation length of 2 microns and stored in the file 
   psd3.dat                                                        */


sanchez@sol> GO source
SOURCE selected. Begin procedure.
This procedure generates a SOURCE for SHADOW.
Mode selected [ ? <ret> for HELP ] ? prompt
Call to INPUT
---------------------------------- S H A D O W  ------------------------------- 
 Jan 1992                     F.Cerrina                         ECE - UW         
 Defining source : 
When prompted for a yes/no answer, you may enter:
for   YES  answer      Y, 1
for   NO   answer      anything else




 Do you want a verbose [ 1 ] or terse [ 0 ] output ?0
 ------------- SOURCE SPECS ------------------
 Source modelling type [ 0-5 ] ? 0
 How many rays [ 1 - 5 000 ] ? 5000
 Seed [ odd, 1000 - 1 000 000 ] ? 12853
 Do you want to optimize the source ? 
	Source type : [ 0 ] regular source
              [ 1 ] normal wiggler
              [ 2 ] undulator
              [ 3 ] elliptical wiggler
 Then ? 0
 X-Z plane source type [ 0-3 ] ? 0
 Source Depth [ 1-4 ] ? 1
 Source Angle Distribution [ 1-6 ] ? 1
 Horizontal half-divergence [ (+)x, rads ] ? .0005
                            [ (-)x, rads ] ? .0005
 Vertical                   [ (+)z, rads ] ? .00005
                            [ (-)z, rads ] ? .00005
 Do you want a Photon energy [ Y/N ] ? 1
 Energy distribution [ 1-3 ] ? 1
 Photon Energy [ 0 ] or Angstroms [ 1 ] ? 
 Energy [ eV ] ? 8035
 Do you want to store the optical paths (OPD) [Y/N] ? 
 Do you want to generate the A vectors (electric field)          [Y/N] ?
Exit from INPUT_SOURCE
Calling gen_source with /u1/src/shadow-6000/bin/gen_source start.00
Generated   250 rays out of   5000
            500
            750
            1000
            1250
            1500
            1750
            2000
            2250
            2500
            2750
            3000
            3250
            3500
            3750
            4000
            4250
            4500
            4750
            5000
Exit from SOURCE
SOURCE => Source has been succesfully generated.

SOURCE procedure completed.

Shadow:: trace

Ray Tracing Selected. Begin procedure.

Mode selected [ ? <ret> for HELP ] ? prompt
Call to RESET
Exit from RESET
Mode selected is: 
PROMPT                                                                          
Options: to start anew                 [ 0 ] 
            to restart from a given OE [ 1 ] 
 Then ? 
Call to INPUT_OE
---------------------------------- S H A D O W  ------------------------------- 
 Jan 1992                     F.Cerrina                         ECE - UW         
 
When prompted for a yes/no answer, you may enter:
for   YES  answer      Y, 1
for   NO   answer      anything else
 

 Defining Optical Element:  1
 Continue ? [ EXIT to terminate OS ] 




 Do you want a verbose [ 1 ] or terse [ 0 ] output ?
 
Files to write out. Options: 
All............................ [ 0 ] 
Mirror only.....................[ 1 ] 
Image at CP only................[ 2 ] 
None............................[ 3 ] 
  Then ? 
 Optical Element definition:
 Incidence Angle ? 88.5
 Source Distance ? 3000
 Reflection Angle? 88.5
 Image Distance  ? 1000
 Reflector [ 0 ] or refractor [ 1 ] ? 1 0
 Mirror surface [ 1-9] ? 2
 Do you want to specify the mirror parameters ?
 Is the mirror Cylindrical ? 
 Is this optical element a Fresnel Zone Plate ? 
 Are we dealing with a Grating ? 
 Are we dealing with a crystal [ Y/N ] ? 
 Is the mirror convex [ Y/N ] ? 
 Reflectivity mode [ 0,1,2 ] ? 
 Orientation Angle [ Alpha ] ? 
 Mirror Dimensions finite [ Y/N ] ?
 Focii placed at continuation planes [ Y/N ] ? 1
 Do you want to move the Source [ Y/N ] ? 
 Do you want to move the mirror itself [ Y/N ] ? 
 Distorted surface [ Y/N ] ? 
 Do you want to include surface roughness [Y/N] ? 1
 File to read ? psd3.dat
 Roughness RMS in Y direction (along the mirror) [Anstrongs] ? 5
 Roughness RMS in X direction (transversal direction) [Anstrongs] ? 5
 Any screens in this OE [ Y/N ] ? 
 Slit at continuation plane [ Y/N ] ? 
 Extra Image plates [ Y/N ] ? 
 File containing the source array ? begin.dat
Exit from INPUT
Tracing optical element #   1
Call to SETSOUR
Exit from SETSOUR
Call to IMREF
Exit from IMREF
Call to OPTAXIS
Exit from OPTAXIS
Call to MSETUP
Exit from MSETUP
Call to RESTART
Exit from RESTART
Call to MIRROR
Exit from MIRROR
Call to IMAGE
Exit from IMAGE
Call to RESET
Exit from RESET
 Do you want to change input mode ? 
Call to INPUT_OE
---------------------------------- S H A D O W  ------------------------------- 
 Jan 1992                     F.Cerrina                         ECE - UW         

 Defining Optical Element:  2
 Continue ? [ EXIT to terminate OS ] exit
End of session

Procedure completed.

Shadow:: exit
23.3u 8.4s 8:18 6% 0+880k 76+198io 134pf+0w

/* Now the analysis; first with plotxy we see the stop dimensions  */

sanchez@sol> plotxy
 PLOT> Input file? star.01
PLOT> Options --- Enter
PLOT>   0   for excluding the losses
PLOT>   1   for including only the losses
PLOT>   2   for including all the rays.
PLOT> Then ? 
PLOT> Comment for plot [ 80 char ] ?

PLOT> File read OK. Full specifications:
     /u3/staff/sanchez/demo/roughness/star.01                   
     Was created : 
 
PLOT>  Found   5000 good points out of  5000
PLOT>  The following columns are defined for each ray :
       1)  the regular columns [1-12]



 Col Par Minimum:       Maximum:       Center:        St. Dev.:

  1  X   -0.67111        0.61144        0.19388E-04    0.48789E-01
  2  Y   -0.16639E-12    0.34197E-12    0.69873E-13    0.81183E-13
  3  Z    -22.135         10.936       -0.11494E-01     1.4539    
  4  X'  -0.19973E-02    0.19279E-02    0.39482E-05    0.86758E-03
  5  Y'   0.99976         1.0000         1.0000             0.    
  6  Z'  -0.22130E-01    0.10878E-01   -0.30258E-04    0.14549E-02
 11   Photon Energy  (eV)      8035.0         8035.0    
 20   Numerical Aperture      0.38546E-05    0.22136E-01
 
 
 /* Now we generate the histogram of the 3rd column   */
sanchez@sol> histo1
 File for analysis ?
star.01
 Column to analyze ? 3
Read    :   5000 rays
Maximum :     10.9356
Minimum :    -22.1348
 Distribution center ? 0
              width ? 20
 Number of bins (odd, please) ? 81
Flag checks. Enter :
0	to exclude lost rays
1	to include lost rays too
2	to use only lost rays
 <?> 
Normalization kind. Enter :
0	for no normalization
1	to normalize to 1
2	area normalized to 1
 <?> 
 Include reflectivity ? 
Output options :
  [ 0 ] store histogram in a file
  [ 1 ] plot histogram on screen
  [ 2 ] both
 Then ? 0
 Another run  [ Y/N ] ?
Return to DCL

/* Now you can do other runs with for example 2 A roughness rms
   and 10 A roughness rms ans see the differences. The standard
   deviation are:
	Roughness	St. Dev col 1	St. Dev. col 3
	2 A		0.021 cm	0.54 cm
	5 A		0.049 cm	1.45 cm
	10A		0.098 cm	2.88 cm


   and you can see the histograms in the file rough_hist.ps      */



