#pragma rtGlobals=1 // Use modern global access method. #pragma version = 1.0 // written by Andrei Tkachuk (Sept 26, 2003) //Calculates and displayes beam footprint on the tilted sample in reflecting vertical diffraction geometry Menu "Analysis" "Beam Footprint",BuildBeamFootprintPanel() end Function BuildBeamFootprintPanel() if (wintype("BeamFootprint") == 0) BeamFootprintInitPackage() BeamFootprintWindow() NVAR gHsize = root:Packages:BeamFootprint:gHsize NVAR gVsize = root:Packages:BeamFootprint:gVsize CreateDirectBeam(gHsize,gVsize) SetVarCalculateFootprintProc("setvar_th",0," "," ") else DoWindow/F BeamFootprint endif End Function yFootprint(h,w, th,chi) Variable h,w //hight and width of the direct beam variable th,chi Variable y //footprint along the beam propagation Variable x //footprint perependicular to beam th=Pi*th/180 //converts to radians chi=Pi*chi/180 y=h/sin(th)+w*tan(chi)/tan(th) return y end Function xFootprint(h,w, th,chi) Variable h,w //hight and width of the direct beam variable th,chi Variable y //footprint along the beam propagation Variable x //footprint perependicular to beam th=Pi*th/180 //converts to radians chi=Pi*chi/180 x= w/cos(chi) return x end Function allFootprint(x0,y0,x1,y1,th,chi) wave x0,y0 // direct beam cross section wave x1,y1 variable th,chi //in degrees x1=-xFootprint(y0,x0, th,chi) y1=yFootprint(y0,x0, th,chi) end Function SetVarCalculateFootprintProc(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName NVAR vsize=root:Packages:BeamFootprint:gVsize NVAR hsize=root:Packages:BeamFootprint:gHsize NVAR th=root:Packages:BeamFootprint:gth NVAR gchi=root:Packages:BeamFootprint:gchi NVAR fHsize=root:Packages:BeamFootprint:gfHsize NVAR fVsize=root:Packages:BeamFootprint:gfVsize NVAR garea=root:Packages:BeamFootprint:garea wave footprintX=$"root:Packages:BeamFootprint:beamX_tran" wave footprintY=$"root:Packages:BeamFootprint:beamY_tran" Variable chi=90-gchi // for Chi diffractometer setup at 2BM CreateBeamFootprint(th,chi) fHsize=xFootprint(vsize,hsize, th,chi) fVsize=yFootprint(vsize,hsize, th,chi) garea=fHsize*(footprintY[0]-footprintY[3]) //footprint area (mm^2) // same results as x*y/(sin(12*Pi/180)*sin(90*Pi/180)) End Function BeamFootprintInitPackage() NewDataFolder /O root:Packages NewDataFolder /O root:Packages:BeamFootprint if(exists("root:Packages:BeamFootprint:gHsize")!=2) Variable/G root:Packages:BeamFootprint:gHsize=1 // horizontal beam size endif if(exists("root:Packages:BeamFootprint:gVsize")!=2) Variable/G root:Packages:BeamFootprint:gVsize=1 // vertical beam size endif if(exists("root:Packages:BeamFootprint:gfHsize")!=2) Variable/G root:Packages:BeamFootprint:gfHsize=0 // horizontal footprint size endif if(exists("root:Packages:BeamFootprint:gfVsize")!=2) Variable/G root:Packages:BeamFootprint:gfVsize=0 // vertical footprint size endif if(exists("root:Packages:BeamFootprint:gth")!=2) Variable/G root:Packages:BeamFootprint:gth=90 // th (90 deg) endif if(exists("root:Packages:BeamFootprint:gchi")!=2) Variable/G root:Packages:BeamFootprint:gchi=90 //chi (90 deg) endif if(exists("root:Packages:BeamFootprint:garea")!=2) Variable/G root:Packages:BeamFootprint:garea=0 //footprint area (90 deg) endif if(exists("root:Packages:BeamFootprint:beamX_0")!=1) Make/D/N=5 root:Packages:BeamFootprint:beamX_0 endif if(exists("root:Packages:BeamFootprint:beamY_0")!=1) Make/D/N=5 root:Packages:BeamFootprint:beamY_0 endif if(exists("root:Packages:BeamFootprint:beamX_tran")!=1) Make/D/N=5 root:Packages:BeamFootprint:beamX_tran endif if(exists("root:Packages:BeamFootprint:beamY_tran")!=1) Make/D/N=5 root:Packages:BeamFootprint:beamY_tran endif end Function CreateDirectBeam(hsize,vsize) Variable hsize //horizontal direct beam size Variable vsize //horizontal direct beam size wave beamX=$"root:Packages:BeamFootprint:beamX_0" wave beamY=$"root:Packages:BeamFootprint:beamY_0" beamY[0] = vsize/2 beamX[0] = hsize/2 beamY[1] = vsize/2 beamX[1] = -hsize/2 beamY[2] = -vsize/2 beamX[2] = -hsize/2 beamY[3] = -vsize/2 beamX[3] = hsize/2 beamY[4] = vsize/2 beamX[4] = hsize/2 end Function CreateBeamFootprint(th,chi) Variable th Variable chi // wave footprintX=$"root:Packages:BeamFootprint:beamX_tran" wave footprintY=$"root:Packages:BeamFootprint:beamY_tran" wave beamX=$"root:Packages:BeamFootprint:beamX_0" wave beamY=$"root:Packages:BeamFootprint:beamY_0" allFootprint(beamX,beamY,footprintX,footprintY,th,chi) end Function BeamFootprintWindow() // PauseUpdate; Silent 1 // building window... String fldrSav= GetDataFolder(1) SetDataFolder root:Packages:BeamFootprint: Display /K=1/W=(605,44,963,469) beamY_0 vs beamX_0 DoWindow/C BeamFootprint AppendToGraph beamY_tran vs beamX_tran SetDataFolder fldrSav ModifyGraph height={Aspect,1} ModifyGraph lSize(beamY_tran)=2 ModifyGraph lStyle(beamY_0)=3 ModifyGraph rgb(beamY_0)=(1,4,52428) ModifyGraph zero=2 ModifyGraph lblMargin(left)=7,lblMargin(bottom)=4 ModifyGraph axOffset(bottom)=0.909091 ModifyGraph lblLatPos(left)=-2 Label left " y projection along the beam (mm)" Label bottom "x perpendicular to the beam (mm)" SetAxis left -6.58974358974359,7.41025641025641 SetAxis bottom -7.05128205128205,6.94871794871795 Tag/N=text0/F=0/X=-13.19/Y=0.00 beamY_tran, 0, "\\OX" Tag/N=text0_1/F=0/X=11.72/Y=0.00 beamY_tran, 2, "\\OX" Tag/N=text0_2/F=0/X=0.00/Y=-8.42 beamY_tran, 2, "\\OY" Tag/N=text0_3/F=0/X=0.00/Y=9.16 beamY_tran, 1, "\\OY" // ShowTools ControlBar 102 SetVariable setvar_chi,pos={20,58},size={88,15},proc=SetVarCalculateFootprintProc,title="chi" SetVariable setvar_chi,limits={0,Inf,1},value= root:Packages:BeamFootprint:gchi SetVariable setvar_th,pos={21,31},size={89,15},proc=SetVarCalculateFootprintProc,title="th" SetVariable setvar_th,limits={0,Inf,1},value= root:Packages:BeamFootprint:gth SetVariable setvar_area,pos={172,71},size={148,15},title="area (mm^2)" SetVariable setvar_area,limits={-Inf,Inf,0},value= root:Packages:BeamFootprint:garea SetVariable setvar_fhsize,pos={189,26},size={136,15},title="xf(mm)" SetVariable setvar_fhsize,limits={-Inf,Inf,0},value= root:Packages:BeamFootprint:gfHsize SetVariable setvar_fvsize,pos={189,47},size={135,15},title="yf(mm)" SetVariable setvar_fvsize,limits={-Inf,Inf,0},value= root:Packages:BeamFootprint:gfVsize SetVariable setvar_beamh,pos={26,3},size={95,15},proc=SetVarCreateDirectBeamProc,title="xb(mm)" SetVariable setvar_beamh,limits={0,Inf,0.5},value= root:Packages:BeamFootprint:gHsize SetVariable setvar_beamv,pos={149,2},size={95,15},proc=SetVarCreateDirectBeamProc,title="yb(mm)" SetVariable setvar_beamv,limits={0,Inf,0.5},value= root:Packages:BeamFootprint:gVsize SetDrawLayer UserFront SetDrawEnv xcoord= prel,ycoord= left,arrow= 1 DrawLine 0.409605361316645,-6.05128205128205,0.629869678497262,-6.05128205128205 DrawText 0.875593451233842,0.483023071471403,"top view" DrawText 0.660272796605251,0.984899763833734,"chi +" DrawText 0.278757436715467,0.978898896264415,"chi -" SetDrawEnv xcoord= bottom,ycoord= prel,linefgc= (1,4,52428),arrow= 2 DrawLine 0.0530303030303028,0.168877551020408,0.0530303030303028,-0.022959183673469 SetDrawEnv textrot= 90 DrawText 0.524718082329759,0.152861981869951,"x-rays" SetDrawEnv xcoord= prel,ycoord= left,arrow= 2 DrawLine 0.0845070422535211,-1.6585409895269,0.0845070422535211,1.69357168652943 DrawText 0.045184832925738,0.702500238476462,"th +" SetDrawEnv textrgb= (65535,0,0) DrawText 0.18427750410509,0.00758149896080932,"Beam footprint on the tilted sample" DrawRect 0.531135531135531,-0.47985347985348,1.06593406593407,-0.0659340659340659 DrawRect 0.586080586080586,-0.413919413919414,0.717948717948718,-0.201465201465201 DrawRect 0.710622710622711,-0.0512820512820513,0.710622710622711,-0.296703296703297 DrawText 0.457875457875458,-0.263736263736264,"d" End Function SetVarCreateDirectBeamProc(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName NVAR hsize=root:Packages:BeamFootprint:gHsize NVAR vsize=root:Packages:BeamFootprint:gVsize CreateDirectBeam(hsize,vsize) SetVarCalculateFootprintProc("setvar_th",0," "," ") End