source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_DetectorBinning_Q.ipf @ 993

Last change on this file since 993 was 993, checked in by srkline, 6 years ago

lots of changes to plotting of q-values, generating fake data with non-linear corrections, masking of data, etc.

File size: 44.9 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3
4//////////////////
5//
6// Procedures for:
7//
8//              Gathering information to calculate QxQyQz
9//              Filling the panels with Qtot, QxQyQz
10//              Filling the "data" with a model function
11//              Averaging the panels (independently) into I(Q)
12//              Plotting the 9 detector panels in 2D
13//              Plotting the 1D I(q) data depending on the panel combinations
14//
15//
16//  There are some things in the current circular averaging that don't make any sense
17//  and don't seem to really do anything at all, so i have decided to trim them out.
18//  1) subdividing pixels near the beam stop into 9 sub-pixels
19//  2) non-linear correction (only applies to Ordela)
20//
21//
22//  Do I separate out the circular, sector, rectangular, annular averaging into
23//   separate routines?
24//
25//
26//
27///////////////////
28
29
30Proc PlotFrontPanels()
31        fPlotFrontPanels()
32End
33
34//
35// Plot the front panels in 2D and 1D
36//              calcualate Q
37//              fill w/model data
38//              "shadow" the T/B detectors
39//              bin the data to I(q)
40//              draw I(q) graph
41//              draw 2D panel graph
42//
43// *** Call this function when front panels are adjusted, or wavelength, etc. changed
44//
45Function fPlotFrontPanels()
46
47        // space is allocated for all of the detectors and Q's on initialization
48        // calculate Qtot, qxqyqz arrays from geometry
49        VC_CalculateQFrontPanels()
50       
51        // fill the panels with fake sphere scattering data
52        // TODO: am I in the right data folder??
53//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
54
55        String folderStr = "VCALC"
56        String detStr = ""
57
58        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
59        String instPath = ":entry:instrument:detector_"
60
61        detStr = "FL"
62        WAVE det_FL = $(folderPath+instPath+detStr+":det_"+detStr)     
63        WAVE qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)
64       
65        detStr = "FR"
66        WAVE det_FR = $(folderPath+instPath+detStr+":det_"+detStr)     
67        WAVE qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)
68//      WAVE qTot_FR = $("root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FR:qTot_FR")
69       
70        detStr = "FT"
71        WAVE det_FT = $(folderPath+instPath+detStr+":det_"+detStr)     
72        WAVE qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)
73       
74        detStr = "FB"
75        WAVE det_FB = $(folderPath+instPath+detStr+":det_"+detStr)     
76        WAVE qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)
77
78       
79       
80        FillPanel_wModelData(det_FL,qTot_FL,"FL")
81        FillPanel_wModelData(det_FR,qTot_FR,"FR")
82        FillPanel_wModelData(det_FT,qTot_FT,"FT")
83        FillPanel_wModelData(det_FB,qTot_FB,"FB")
84
85        SetDataFolder root:
86               
87        // set any "shadowed" area of the T/B detectors to NaN to get a realistic
88        // view of how much of the detectors are actually collecting data
89        // -- I can get the separation L/R from the panel - only this "open" width is visible.
90        //TODO - make this a proper shadow - TB extent of the LR panels matters too, not just the LR separation
91        VC_SetShadow_TopBottom("VCALC","FT")            // TODO: -- be sure the data folder is properly set (within the function...)
92        VC_SetShadow_TopBottom("VCALC","FB")
93       
94        // do the q-binning for each of the panels to get I(Q)
95        Execute "BinAllFrontPanels()"
96
97        // plot the results
98        Execute "Front_IQ_Graph()"
99        FrontPanels_AsQ()
100       
101        return(0)
102End
103
104
105// works for Left, works for Right... works for T/B too.
106//
107// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
108//     detector, and on different sides of the detector (or T/B) - since it will be in a different
109//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
110//     --- test this...
111// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
112//
113// TODO: make all detector parameters global, not hard-wired
114//
115//
116// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
117//     when anything changes
118//
119// TODO
120// NOTE -- this is VCALC ONLY. data is not referenced for hdf here, and data is rescaled based on VCALC assumptions
121//
122Function VC_CalculateQFrontPanels()
123
124        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
125        Variable F_LR_sep,F_TB_sep,F_offset,F_sdd_offset
126
127        String folderPath = "root:Packages:NIST:VSANS:VCALC"
128        String instPath = ":entry:instrument:detector_"
129        String detStr=""
130
131// get the values from the panel + constants   
132        F_LR_sep = VCALC_getPanelSeparation("FLR")
133        F_TB_sep = VCALC_getPanelSeparation("FTB")
134        F_offset = VCALC_getLateralOffset("FL")
135       
136        SDD = VCALC_getSDD("FL")                //nominal SDD - need offset for TB
137        lam = VCALC_getWavelength()
138
139//separations are in mm -- need to watch the units, convert to cm
140        F_LR_sep /= 10
141        F_TB_sep /= 10
142// TODO - I'm treating the separation as the TOTAL width - so the difference
143//      from the "center" to the edge is 1/2 of the separation
144
145// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
146
147        F_sdd_offset = VCALC_getTopBottomSDDOffset("FT")        //T/B are 300 mm farther back  //TODO: make all detector parameters global, not hard-wired
148
149// detector data to bin
150//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
151        Wave det_FL = $(folderPath+instPath+"FL"+":det_FL")
152        Wave det_FR = $(folderPath+instPath+"FR"+":det_FR")             // these are (48,128)           (nominal, may change)
153
154        Wave det_FT = $(folderPath+instPath+"FT"+":det_FT")
155        Wave det_FB = $(folderPath+instPath+"FB"+":det_FB")             // these are (128,48)
156
157//FRONT/LEFT
158        detStr = "FL"
159        Wave qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
160        Wave qx_FL = $(folderPath+instPath+detStr+":qx_"+detStr)
161        Wave qy_FL = $(folderPath+instPath+detStr+":qy_"+detStr)       
162        Wave qz_FL = $(folderPath+instPath+detStr+":qz_"+detStr)       
163
164        qTot_FL = 0
165        qx_FL = 0
166        qy_FL = 0
167        qz_FL = 0       
168       
169// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
170// pixel sizes are in cm
171        pixSizeX = VCALC_getPixSizeX("FL")
172        pixSizeY = VCALC_getPixSizeY("FL")
173//      pixSizeX = 0.8                  // 0.8 cm/pixel along width
174//      pixSizeY = 0.4                  // approx 0.4 cm/pixel along length
175        nPix_X = VCALC_get_nPix_X("FL")
176        nPix_Y = VCALC_get_nPix_Y("FL")
177       
178        xCtr = nPix_X+(F_LR_sep/2/pixSizeX)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
179        yCtr = nPix_Y/2
180        //put these  beam center values into the local folder
181        V_putDet_beam_center_x("VCALC","FL",xCtr)
182        V_putDet_beam_center_y("VCALC","FL",yCtr)
183       
184//      VC_Detector_2Q(det_FL,qTot_FL,qx_FL,qy_FL,qz_FL,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
185        VC_Detector_2Q_NonLin(det_FL,qTot_FL,qx_FL,qy_FL,qz_FL,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"FL")
186        Print "xy for FL = ",xCtr,yCtr
187       
188        //set the wave scaling for the detector image so that it can be plotted in q-space
189        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
190        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
191        // since qTot is magnitude only, I need to put in the (-ve)
192        SetScale/I x WaveMin(qx_FL),WaveMax(qx_FL),"", det_FL           //this sets the left and right ends of the data scaling
193        SetScale/I y WaveMin(qy_FL),WaveMax(qy_FL),"", det_FL
194//////////////////
195
196//FRONT/RIGHT
197//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
198        detStr = "FR"
199        Wave qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
200        Wave qx_FR = $(folderPath+instPath+detStr+":qx_"+detStr)
201        Wave qy_FR = $(folderPath+instPath+detStr+":qy_"+detStr)       
202        Wave qz_FR = $(folderPath+instPath+detStr+":qz_"+detStr)       
203       
204        qTot_FR = 0
205        qx_FR = 0
206        qy_FR = 0
207        qz_FR = 0
208
209// TODO - these are to be set from globals, not hard-wired
210// pixel sizes are in cm
211        pixSizeX = VCALC_getPixSizeX("FR")
212        pixSizeY = VCALC_getPixSizeY("FR")
213        nPix_X = VCALC_get_nPix_X("FR")
214        nPix_Y = VCALC_get_nPix_Y("FR")
215       
216        xCtr = -(F_LR_sep/2/pixSizeX)-1         
217        yCtr = nPix_Y/2
218        //put these  beam center values into the local folder
219        V_putDet_beam_center_x("VCALC","FR",xCtr)
220        V_putDet_beam_center_y("VCALC","FR",yCtr)       
221//      VC_Detector_2Q(det_FR,qTot_FR,qx_FR,qy_FR,qz_FR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
222        VC_Detector_2Q_NonLin(det_FR,qTot_FR,qx_FR,qy_FR,qz_FR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"FR")
223
224//      Print "xy for FR = ",xCtr,yCtr
225        SetScale/I x WaveMin(qx_FR),WaveMax(qx_FR),"", det_FR           //this sets the left and right ends of the data scaling
226        SetScale/I y WaveMin(qy_FR),WaveMax(qy_FR),"", det_FR
227/////////////////
228
229//FRONT/TOP
230//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
231        detStr = "FT"
232        Wave qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
233        Wave qx_FT = $(folderPath+instPath+detStr+":qx_"+detStr)
234        Wave qy_FT = $(folderPath+instPath+detStr+":qy_"+detStr)       
235        Wave qz_FT = $(folderPath+instPath+detStr+":qz_"+detStr)       
236
237        qTot_FT = 0
238        qx_FT = 0
239        qy_FT = 0
240        qz_FT = 0
241
242// TODO - these are to be set from globals, not hard-wired
243// pixel sizes are in cm
244        pixSizeX = VCALC_getPixSizeX("FT")
245        pixSizeY = VCALC_getPixSizeY("FT")
246        nPix_X = VCALC_get_nPix_X("FT")
247        nPix_Y = VCALC_get_nPix_Y("FT")
248       
249        xCtr = nPix_X/2
250        yCtr = -(F_TB_sep/2/pixSizeY)-1
251                //put these  beam center values into the local folder
252        V_putDet_beam_center_x("VCALC","FT",xCtr)
253        V_putDet_beam_center_y("VCALC","FT",yCtr)
254         
255        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
256//      VC_Detector_2Q(det_FT,qTot_FT,qx_FT,qy_FT,qz_FT,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
257        VC_Detector_2Q_NonLin(det_FT,qTot_FT,qx_FT,qy_FT,qz_FT,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY,"FT")
258
259//      Print "xy for FT = ",xCtr,yCtr
260        SetScale/I x WaveMin(qx_FT),WaveMax(qx_FT),"", det_FT           //this sets the left and right ends of the data scaling
261        SetScale/I y WaveMin(qy_FT),WaveMax(qy_FT),"", det_FT
262//////////////////
263
264//FRONT/BOTTOM
265//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
266        detStr = "FB"
267        Wave qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
268        Wave qx_FB = $(folderPath+instPath+detStr+":qx_"+detStr)
269        Wave qy_FB = $(folderPath+instPath+detStr+":qy_"+detStr)       
270        Wave qz_FB = $(folderPath+instPath+detStr+":qz_"+detStr)       
271
272        qTot_FB = 0
273        qx_FB = 0
274        qy_FB = 0
275        qz_FB = 0
276
277// TODO - these are to be set from globals, not hard-wired
278// pixel sizes are in cm
279        pixSizeX = VCALC_getPixSizeX("FB")
280        pixSizeY = VCALC_getPixSizeY("FB")
281        nPix_X = VCALC_get_nPix_X("FB")
282        nPix_Y = VCALC_get_nPix_Y("FB")
283               
284        xCtr = nPix_X/2
285        yCtr = nPix_Y+(F_TB_sep/2/pixSizeY)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
286                //put these  beam center values into the local folder
287        V_putDet_beam_center_x("VCALC","FB",xCtr)
288        V_putDet_beam_center_y("VCALC","FB",yCtr)
289       
290        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
291//      VC_Detector_2Q(det_FB,qTot_FB,qx_FB,qy_FB,qz_FB,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
292        VC_Detector_2Q_NonLin(det_FB,qTot_FB,qx_FB,qy_FB,qz_FB,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY,"FB")
293
294//      Print "xy for FB = ",xCtr,yCtr
295        SetScale/I x WaveMin(qx_FB),WaveMax(qx_FB),"", det_FB           //this sets the left and right ends of the data scaling
296        SetScale/I y WaveMin(qy_FB),WaveMax(qy_FB),"", det_FB
297/////////////////
298
299        SetDataFolder root:
300               
301        return(0)
302End
303
304
305// TODO - this doesn't quite mask things out as they should be (too much is masked L/R of center)
306// and the outer edges of the detector are masked even if the TB panels extend past the TB of the LR panels.
307// ? skip the masking? but then I bin the detector data directly to get I(q), skipping the masked NaN values...
308//
309Function VC_SetShadow_TopBottom(folderStr,type)
310        String folderStr,type
311       
312        Variable LR_sep,nPix,xCtr,ii,jj,numCol,pixSizeX,pixSizeY,nPix_X,nPix_Y
313
314/// !! type passed in will be FT, FB, MT, MB, so I can't ask for the panel separation -- or I'll get the TB separation...
315        if(cmpstr(type[0],"F")==0)
316                //front
317                ControlInfo/W=VCALC VCALCCtrl_2a
318                LR_sep = V_Value       
319        else
320                //middle
321                ControlInfo/W=VCALC VCALCCtrl_3a
322                LR_sep = V_Value       
323        endif           
324//separations on panel are in mm -- need to watch the units, convert to cm
325        LR_sep /= 10
326
327//detector data
328        Wave det = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+type+":det_"+type)
329
330// TODO - these are to be set from globals, not hard-wired
331// pixel sizes are in cm for T/B detector
332// TODO - the "FT" check is hard wired for FRONT -- get rid of this...
333
334        pixSizeX = VCALC_getPixSizeX(type)
335        pixSizeY = VCALC_getPixSizeY(type)
336
337        nPix_X = VCALC_get_nPix_X(type)
338        nPix_Y = VCALC_get_nPix_Y(type)
339       
340        //TODO -- get this from a global
341        xCtr = nPix_X/2
342        nPix = trunc(LR_sep/2/pixSizeX)         // approx # of pixels Left/right of center that are not obscured by L/R panels
343       
344        numCol = DimSize(det,0)         // x dim (columns)
345        for(ii=0;ii<(xCtr-nPix-2);ii+=1)
346                det[ii][] = NaN
347        endfor
348        for(ii=(xCtr+nPix+2);ii<numCol;ii+=1)
349                det[ii][] = NaN
350        endfor
351       
352        return(0)
353end
354
355
356// After the panels have been calculated and rescaled in terms of Q, and filled with simulated data
357// they can be appended to the subwindow. If they are already there, the axes and coloring
358// are rescaled as needed
359//
360Function FrontPanels_AsQ()
361
362        String frontStr = "root:Packages:NIST:VSANS:VCALC:entry:instrument:"
363//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
364        SetDataFolder $(frontStr+"detector_FB")
365        Wave det_FB = det_FB
366        SetDataFolder $(frontStr+"detector_FT")
367        Wave det_FT = det_FT
368        SetDataFolder $(frontStr+"detector_FL")
369        Wave det_FL = det_FL
370        SetDataFolder $(frontStr+"detector_FR")
371        Wave det_FR = det_FR
372       
373        CheckDisplayed /W=VCALC#Panels_Q det_FB
374        if(V_flag == 0)
375                AppendImage/W=VCALC#Panels_Q det_FB
376                ModifyImage/W=VCALC#Panels_Q det_FB ctab= {*,*,ColdWarm,0}
377                AppendImage/W=VCALC#Panels_Q det_FT
378                ModifyImage/W=VCALC#Panels_Q det_FT ctab= {*,*,ColdWarm,0}
379                AppendImage/W=VCALC#Panels_Q det_FL
380                ModifyImage/W=VCALC#Panels_Q det_FL ctab= {*,*,ColdWarm,0}
381                AppendImage/W=VCALC#Panels_Q det_FR
382                ModifyImage/W=VCALC#Panels_Q det_FR ctab= {*,*,ColdWarm,0}
383        endif
384
385        Variable dval
386        ControlInfo/W=VCALC setVar_b
387        dval = V_Value
388
389        SetAxis/W=VCALC#Panels_Q left -dval,dval
390        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
391
392        ControlInfo/W=VCALC check_0a
393// V_Value == 1 if checked
394        ModifyImage/W=VCALC#Panels_Q det_FB log=V_Value
395        ModifyImage/W=VCALC#Panels_Q det_FT log=V_Value
396        ModifyImage/W=VCALC#Panels_Q det_FL log=V_Value
397        ModifyImage/W=VCALC#Panels_Q det_FR log=V_Value
398
399
400        SetDataFolder root:
401       
402EndMacro
403
404
405
406
407
408
409//
410// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
411// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
412//
413// first - the DeltaQ step is set as the smaller detector resolution (along tube)
414//       which is different for LR / TB geometry. This is not set in stone.
415//
416// second - each detector is binned separately
417//
418// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
419//      you'l end up with < 200 points.
420//
421// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
422//
423Proc BinAllFrontPanels()
424
425        SetDeltaQ("VCALC","FL")
426        SetDeltaQ("VCALC","FR")
427        SetDeltaQ("VCALC","FT")
428        SetDeltaQ("VCALC","FB")
429
430        Variable binType       
431        ControlInfo/W=VCALC popup_b
432        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
433
434        if(binType == 1)
435                VC_BinQxQy_to_1D("VCALC","FL")
436                VC_BinQxQy_to_1D("VCALC","FR")
437                VC_BinQxQy_to_1D("VCALC","FT")
438                VC_BinQxQy_to_1D("VCALC","FB")
439        endif
440       
441        if(binType == 2)       
442                VC_BinQxQy_to_1D("VCALC","FLR")
443                VC_BinQxQy_to_1D("VCALC","FTB")
444        endif
445
446        if(binType == 3)
447                VC_BinQxQy_to_1D("VCALC","FLRTB")
448        endif
449
450// TODO -- this is only a temporary fix for slit mode   
451        if(binType == 4)
452                /// this is for a tall, narrow slit mode       
453                VC_fBinDetector_byRows("VCALC","FL")
454                VC_fBinDetector_byRows("VCALC","FR")
455                VC_fBinDetector_byRows("VCALC","FT")
456                VC_fBinDetector_byRows("VCALC","FB")
457        endif
458               
459End
460
461
462
463
464
465
466
467Proc PlotMiddlePanels()
468        fPlotMiddlePanels()
469End
470
471// to plot I(q) for the 4 Middle panels
472//
473// *** Call this function when Middle panels are adjusted, or wavelength, etc. changed
474//
475Function fPlotMiddlePanels()
476
477        // space is allocated for all of the detectors and Q's on initialization
478        // calculate Qtot, qxqyqz arrays from geometry
479        VC_CalculateQMiddlePanels()
480       
481        // fill the panels with fake sphere scattering data
482        // TODO: am I in the right data folder??
483//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
484
485        String folderStr = "VCALC"
486        String detStr = ""
487
488        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
489        String instPath = ":entry:instrument:detector_"
490
491        detStr = "ML"
492        WAVE det_ML = $(folderPath+instPath+detStr+":det_"+detStr)     
493        WAVE qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)
494
495        detStr = "MR"
496        WAVE det_MR = $(folderPath+instPath+detStr+":det_"+detStr)     
497        WAVE qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)
498
499        detStr = "MT"
500        WAVE det_MT = $(folderPath+instPath+detStr+":det_"+detStr)     
501        WAVE qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)
502
503        detStr = "MB"
504        WAVE det_MB = $(folderPath+instPath+detStr+":det_"+detStr)     
505        WAVE qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)
506
507        FillPanel_wModelData(det_ML,qTot_ML,"ML")
508        FillPanel_wModelData(det_MR,qTot_MR,"MR")
509        FillPanel_wModelData(det_MT,qTot_MT,"MT")
510        FillPanel_wModelData(det_MB,qTot_MB,"MB")                       
511
512        SetDataFolder root:
513               
514        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
515        // view of how much of the detectors are actually collecting data
516        // -- I can get the separation L/R from the panel - only this "open" width is visible.
517        VC_SetShadow_TopBottom("VCALC","MT")            // TODO: -- be sure the data folder is properly set (within the function...)
518        VC_SetShadow_TopBottom("VCALC","MB")
519       
520        // do the q-binning for each of the panels to get I(Q)
521        Execute "BinAllMiddlePanels()"
522
523        // plot the results
524        Execute "Middle_IQ_Graph()"
525        MiddlePanels_AsQ()
526       
527        return(0)
528End
529
530// works for Left, works for Right... works for T/B too.
531//
532// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
533//     detector, and on different sides of the detector (or T/B) - since it will be in a different
534//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
535//     --- test this...
536// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
537//
538// TODO: make all detector parameters global, not hard-wired
539//
540//
541// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
542//     when anything changes
543//
544Function VC_CalculateQMiddlePanels()
545
546        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
547        Variable M_LR_sep,M_TB_sep,M_offset, M_sdd_offset
548
549
550        String folderPath = "root:Packages:NIST:VSANS:VCALC"
551        String instPath = ":entry:instrument:detector_"
552        String detStr=""
553       
554        M_LR_sep = VCALC_getPanelSeparation("MLR")
555        M_TB_sep = VCALC_getPanelSeparation("MTB")
556        M_offset = VCALC_getLateralOffset("ML")
557       
558        SDD = VCALC_getSDD("ML")                //nominal SDD - need offset for TB
559        lam = VCALC_getWavelength()
560
561//separations are in mm -- need to watch the units, convert to cm
562        M_LR_sep /= 10
563        M_TB_sep /= 10
564// TODO - I'm treating the separation as the TOTAL width - so the difference
565//      from the "center" to the edge is 1/2 of the separation
566
567// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
568        M_sdd_offset = VCALC_getTopBottomSDDOffset("MT")        //T/B are 30 cm farther back  //TODO: make all detector parameters global, not hard-wired
569
570
571//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
572        Wave det_ML = $(folderPath+instPath+"ML"+":det_ML")
573        Wave det_MR = $(folderPath+instPath+"MR"+":det_MR")             // these are (48,128)           (nominal, may change)
574
575        Wave det_MT = $(folderPath+instPath+"MT"+":det_MT")
576        Wave det_MB = $(folderPath+instPath+"MB"+":det_MB")             // these are (128,48)
577
578//Middle/LEFT
579        detStr = "ML"
580        Wave qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
581        Wave qx_ML = $(folderPath+instPath+detStr+":qx_"+detStr)
582        Wave qy_ML = $(folderPath+instPath+detStr+":qy_"+detStr)       
583        Wave qz_ML = $(folderPath+instPath+detStr+":qz_"+detStr)       
584       
585        qTot_ML = 0
586        qx_ML = 0
587        qy_ML = 0
588        qz_ML = 0       
589       
590// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
591// pixel sizes are in cm
592        pixSizeX = VCALC_getPixSizeX("ML")
593        pixSizeY = VCALC_getPixSizeY("ML")
594        nPix_X = VCALC_get_nPix_X("ML")
595        nPix_Y = VCALC_get_nPix_Y("ML")
596       
597        xCtr = nPix_X+(M_LR_sep/2/pixSizeX)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
598        yCtr = nPix_Y/2
599                //put these  beam center values into the local folder
600        V_putDet_beam_center_x("VCALC","ML",xCtr)
601        V_putDet_beam_center_y("VCALC","ML",yCtr)
602       
603//      VC_Detector_2Q(det_ML,qTot_ML,qx_ML,qy_ML,qz_ML,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
604        VC_Detector_2Q_NonLin(det_ML,qTot_ML,qx_ML,qy_ML,qz_ML,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"ML")
605
606//      Print "xy for ML = ",xCtr,yCtr
607       
608        //set the wave scaling for the detector image so that it can be plotted in q-space
609        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
610        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
611        // since qTot is magnitude only, I need to put in the (-ve)
612        SetScale/I x WaveMin(qx_ML),WaveMax(qx_ML),"", det_ML           //this sets the left and right ends of the data scaling
613        SetScale/I y WaveMin(qy_ML),WaveMax(qy_ML),"", det_ML
614       
615//////////////////
616
617//Middle/RIGHT
618//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
619        detStr = "MR"
620        Wave qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
621        Wave qx_MR = $(folderPath+instPath+detStr+":qx_"+detStr)
622        Wave qy_MR = $(folderPath+instPath+detStr+":qy_"+detStr)       
623        Wave qz_MR = $(folderPath+instPath+detStr+":qz_"+detStr)
624       
625        qTot_MR = 0
626        qx_MR = 0
627        qy_MR = 0
628        qz_MR = 0
629
630// TODO - these are to be set from globals, not hard-wired
631// pixel sizes are in cm
632        pixSizeX = VCALC_getPixSizeX("MR")
633        pixSizeY = VCALC_getPixSizeY("MR")
634
635        nPix_X = VCALC_get_nPix_X("MR")
636        nPix_Y = VCALC_get_nPix_Y("MR")
637       
638        xCtr = -(M_LR_sep/2/pixSizeX)-1         
639        yCtr = nPix_Y/2
640                //put these  beam center values into the local folder
641        V_putDet_beam_center_x("VCALC","MR",xCtr)
642        V_putDet_beam_center_y("VCALC","MR",yCtr)
643       
644//      VC_Detector_2Q(det_MR,qTot_MR,qx_MR,qy_MR,qz_MR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
645        VC_Detector_2Q_NonLin(det_MR,qTot_MR,qx_MR,qy_MR,qz_MR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"MR")
646
647//      Print "xy for MR = ",xCtr,yCtr
648        SetScale/I x WaveMin(qx_MR),WaveMax(qx_MR),"", det_MR           //this sets the left and right ends of the data scaling
649        SetScale/I y WaveMin(qy_MR),WaveMax(qy_MR),"", det_MR
650/////////////////
651
652//Middle/TOP
653//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
654        detStr = "MT"
655        Wave qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
656        Wave qx_MT = $(folderPath+instPath+detStr+":qx_"+detStr)
657        Wave qy_MT = $(folderPath+instPath+detStr+":qy_"+detStr)       
658        Wave qz_MT = $(folderPath+instPath+detStr+":qz_"+detStr)
659
660        qTot_MT = 0
661        qx_MT = 0
662        qy_MT = 0
663        qz_MT = 0
664
665// TODO - these are to be set from globals, not hard-wired
666// pixel sizes are in cm
667        pixSizeX = VCALC_getPixSizeX("MT")
668        pixSizeY = VCALC_getPixSizeY("MT")
669        nPix_X = VCALC_get_nPix_X("MT")
670        nPix_Y = VCALC_get_nPix_Y("MT")
671       
672        xCtr = nPix_X/2
673        yCtr = -(M_TB_sep/2/pixSizeY)-1
674                //put these  beam center values into the local folder
675        V_putDet_beam_center_x("VCALC","MT",xCtr)
676        V_putDet_beam_center_y("VCALC","MT",yCtr)
677       
678        // global sdd_offset is in (mm), convert to meters here for the Q-calculation 
679//      VC_Detector_2Q(det_MT,qTot_MT,qx_MT,qy_MT,qz_MT,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
680        VC_Detector_2Q_NonLin(det_MT,qTot_MT,qx_MT,qy_MT,qz_MT,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY,"MT")
681
682//      Print "xy for MT = ",xCtr,yCtr
683        SetScale/I x WaveMin(qx_MT),WaveMax(qx_MT),"", det_MT           //this sets the left and right ends of the data scaling
684        SetScale/I y WaveMin(qy_MT),WaveMax(qy_MT),"", det_MT
685//////////////////
686
687//Middle/BOTTOM
688//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
689        detStr = "MB"
690        Wave qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
691        Wave qx_MB = $(folderPath+instPath+detStr+":qx_"+detStr)
692        Wave qy_MB = $(folderPath+instPath+detStr+":qy_"+detStr)       
693        Wave qz_MB = $(folderPath+instPath+detStr+":qz_"+detStr)
694
695        qTot_MB = 0
696        qx_MB = 0
697        qy_MB = 0
698        qz_MB = 0
699
700// TODO - these are to be set from globals, not hard-wired
701// pixel sizes are in cm
702        pixSizeX = VCALC_getPixSizeX("MB")
703        pixSizeY = VCALC_getPixSizeY("MB")
704        nPix_X = VCALC_get_nPix_X("MB")
705        nPix_Y = VCALC_get_nPix_Y("MB")
706               
707        xCtr = nPix_X/2
708        yCtr = nPix_Y+(M_TB_sep/2/pixSizeY)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
709        //put these  beam center values into the local folder
710        V_putDet_beam_center_x("VCALC","MB",xCtr)
711        V_putDet_beam_center_y("VCALC","MB",yCtr)
712       
713                // global sdd_offset is in (mm), convert to meters here for the Q-calculation
714//      VC_Detector_2Q(det_MB,qTot_MB,qx_MB,qy_MB,qz_MB,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
715        VC_Detector_2Q_NonLin(det_MB,qTot_MB,qx_MB,qy_MB,qz_MB,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY,"MB")
716
717//      Print "xy for MB = ",xCtr,yCtr
718        SetScale/I x WaveMin(qx_MB),WaveMax(qx_MB),"", det_MB           //this sets the left and right ends of the data scaling
719        SetScale/I y WaveMin(qy_MB),WaveMax(qy_MB),"", det_MB
720/////////////////
721
722        SetDataFolder root:
723               
724        return(0)
725End
726
727
728Function MiddlePanels_AsQ()
729//      DoWindow/F MiddlePanels_AsQ
730//      if(V_flag == 0)
731//      PauseUpdate; Silent 1           // building window...
732//      Display /W=(1477,44,1978,517)
733
734        String midStr = "root:Packages:NIST:VSANS:VCALC:entry:instrument:"
735//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
736        SetDataFolder $(midStr+"detector_MB")
737        Wave det_MB = det_MB
738        SetDataFolder $(midStr+"detector_MT")
739        Wave det_MT = det_MT
740        SetDataFolder $(midStr+"detector_ML")
741        Wave det_ML = det_ML
742        SetDataFolder $(midStr+"detector_MR")
743        Wave det_MR = det_MR
744
745        CheckDisplayed /W=VCALC#Panels_Q det_MB
746       
747        if(V_flag == 0)
748                AppendImage/W=VCALC#Panels_Q det_MB
749                ModifyImage/W=VCALC#Panels_Q det_MB ctab= {*,*,ColdWarm,0}
750                AppendImage/W=VCALC#Panels_Q det_MT
751                ModifyImage/W=VCALC#Panels_Q det_MT ctab= {*,*,ColdWarm,0}
752                AppendImage/W=VCALC#Panels_Q det_ML
753                ModifyImage/W=VCALC#Panels_Q det_ML ctab= {*,*,ColdWarm,0}
754                AppendImage/W=VCALC#Panels_Q det_MR
755                ModifyImage/W=VCALC#Panels_Q det_MR ctab= {*,*,ColdWarm,0}
756        endif
757
758        Variable dval
759        ControlInfo/W=VCALC setVar_b
760        dval = V_Value
761
762        SetAxis/W=VCALC#Panels_Q left -dval,dval
763        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
764
765        ControlInfo/W=VCALC check_0a
766// V_Value == 1 if checked
767        ModifyImage/W=VCALC#Panels_Q det_MB log=V_Value
768        ModifyImage/W=VCALC#Panels_Q det_MT log=V_Value
769        ModifyImage/W=VCALC#Panels_Q det_ML log=V_Value
770        ModifyImage/W=VCALC#Panels_Q det_MR log=V_Value
771
772
773        SetDataFolder root:
774       
775//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
776//      ModifyGraph grid=2
777//      ModifyGraph mirror=2
778//      SetAxis left -0.2,0.2
779//      SetAxis bottom -0.2,0.2
780//      endif
781EndMacro
782
783//
784// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
785// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
786//
787// first - the DeltaQ step is set as the smaller detector resolution (along tube)
788//       which is different for LR / TB geometry. This is not set in stone.
789//
790// second - each detector is binned separately
791//
792// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
793//      you'l end up with < 200 points.
794//
795// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
796//
797Proc BinAllMiddlePanels()
798
799        SetDeltaQ("VCALC","ML")
800        SetDeltaQ("VCALC","MR")
801        SetDeltaQ("VCALC","MT")
802        SetDeltaQ("VCALC","MB")
803
804        Variable binType       
805        ControlInfo/W=VCALC popup_b
806        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
807
808        if(binType == 1)
809                VC_BinQxQy_to_1D("VCALC","ML")
810                VC_BinQxQy_to_1D("VCALC","MR")
811                VC_BinQxQy_to_1D("VCALC","MT")
812                VC_BinQxQy_to_1D("VCALC","MB")
813        endif
814       
815        if(binType == 2)       
816                VC_BinQxQy_to_1D("VCALC","MLR")
817                VC_BinQxQy_to_1D("VCALC","MTB")
818        endif
819
820        if(binType == 3)
821                VC_BinQxQy_to_1D("VCALC","MLRTB")
822        endif
823       
824        // TODO -- this is only a temporary fix for slit mode   
825        if(binType == 4)
826                /// this is for a tall, narrow slit mode       
827                VC_fBinDetector_byRows("VCALC","ML")
828                VC_fBinDetector_byRows("VCALC","MR")
829                VC_fBinDetector_byRows("VCALC","MT")
830                VC_fBinDetector_byRows("VCALC","MB")
831        endif
832End
833
834////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
835Window Middle_IQ_Graph() : Graph
836
837        Variable binType
838       
839        ControlInfo/W=VCALC popup_b
840        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
841
842        SetDataFolder root:Packages:NIST:VSANS:VCALC
843
844        if(binType==1)
845                ClearIQIfDisplayed("VCALC","MLRTB")
846                ClearIQIfDisplayed("VCALC","MLR")
847                ClearIQIfDisplayed("VCALC","MTB")
848               
849                SetDataFolder root:Packages:NIST:VSANS:VCALC
850                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
851               
852                if(V_flag==0)
853                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
854                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
855                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
856                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
857                        ModifyGraph/W=VCALC#Panels_IQ mode=4
858                        ModifyGraph/W=VCALC#Panels_IQ marker=19
859                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_ML)=(65535,0,0),rgb(iBin_qxqy_MB)=(1,16019,65535),rgb(iBin_qxqy_MR)=(65535,0,0),rgb(iBin_qxqy_MT)=(1,16019,65535)
860                        ModifyGraph/W=VCALC#Panels_IQ msize=2
861                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
862                        ModifyGraph/W=VCALC#Panels_IQ grid=1
863                        ModifyGraph/W=VCALC#Panels_IQ log=1
864                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
865                endif           
866        endif
867       
868        if(binType==2)
869                ClearIQIfDisplayed("VCALC","MLRTB")
870                ClearIQIfDisplayed("VCALC","MT")       
871                ClearIQIfDisplayed("VCALC","ML")       
872                ClearIQIfDisplayed("VCALC","MR")       
873                ClearIQIfDisplayed("VCALC","MB")
874       
875
876                SetDataFolder root:Packages:NIST:VSANS:VCALC
877                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLR
878               
879                if(V_flag==0)
880                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLR vs qBin_qxqy_MLR
881                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MTB vs qBin_qxqy_MTB
882                        ModifyGraph/W=VCALC#Panels_IQ mode=4
883                        ModifyGraph/W=VCALC#Panels_IQ marker=19
884                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLR)=(65535,0,0),rgb(iBin_qxqy_MTB)=(1,16019,65535)
885                        ModifyGraph/W=VCALC#Panels_IQ msize=2
886                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_MLR)={0,2}
887                        ModifyGraph/W=VCALC#Panels_IQ grid=1
888                        ModifyGraph/W=VCALC#Panels_IQ log=1
889                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
890                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
891                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
892                endif   
893                       
894        endif
895       
896        if(binType==3)
897                ClearIQIfDisplayed("VCALC","MLR")
898                ClearIQIfDisplayed("VCALC","MTB")       
899                ClearIQIfDisplayed("VCALC","MT")       
900                ClearIQIfDisplayed("VCALC","ML")       
901                ClearIQIfDisplayed("VCALC","MR")       
902                ClearIQIfDisplayed("VCALC","MB")       
903       
904                SetDataFolder root:Packages:NIST:VSANS:VCALC
905                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLRTB
906               
907                if(V_flag==0)
908                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLRTB vs qBin_qxqy_MLRTB
909                        ModifyGraph/W=VCALC#Panels_IQ mode=4
910                        ModifyGraph/W=VCALC#Panels_IQ marker=19
911                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLRTB)=(65535,0,0)
912                        ModifyGraph/W=VCALC#Panels_IQ msize=2
913                        ModifyGraph/W=VCALC#Panels_IQ grid=1
914                        ModifyGraph/W=VCALC#Panels_IQ log=1
915                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
916                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
917                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
918                endif   
919                       
920        endif
921
922        if(binType==4)          // slit aperture binning - Mt, ML, MR, MB are averaged
923                ClearIQIfDisplayed("VCALC","MLRTB")
924                ClearIQIfDisplayed("VCALC","MLR")
925                ClearIQIfDisplayed("VCALC","MTB")
926               
927                SetDataFolder root:Packages:NIST:VSANS:VCALC
928                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
929               
930                if(V_flag==0)
931                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
932                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
933                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
934                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
935                        ModifyGraph/W=VCALC#Panels_IQ mode=4
936                        ModifyGraph/W=VCALC#Panels_IQ marker=19
937                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_ML)=(65535,0,0),rgb(iBin_qxqy_MB)=(1,16019,65535),rgb(iBin_qxqy_MR)=(65535,0,0),rgb(iBin_qxqy_MT)=(1,16019,65535)
938                        ModifyGraph/W=VCALC#Panels_IQ msize=2
939                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
940                        ModifyGraph/W=VCALC#Panels_IQ grid=1
941                        ModifyGraph/W=VCALC#Panels_IQ log=1
942                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
943                endif           
944                       
945        endif
946        SetDataFolder root:
947EndMacro
948
949
950////////// and for the BACK detector
951Proc PlotBackPanels()
952        fPlotBackPanels()
953End
954
955// to plot I(q) for the Back panel
956//
957// *** Call this function when Back panel is adjusted, or wavelength, etc. changed
958//
959Function fPlotBackPanels()
960
961        // space is allocated for all of the detectors and Q's on initialization
962        // calculate Qtot, qxqyqz arrays from geometry
963        VC_CalculateQBackPanels()
964       
965        // fill the panels with fake sphere scattering data
966        // TODO: am I in the right data folder??
967        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
968
969        WAVE det_B = det_B
970        WAVE qTot_B = qTot_B
971
972        FillPanel_wModelData(det_B,qTot_B,"B")         
973
974        SetDataFolder root:
975               
976        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
977        // view of how much of the detectors are actually collecting data
978        // -- I can get the separation L/R from the panel - only this "open" width is visible.
979//      VC_SetShadow_TopBottom("","MT")         // TODO: -- be sure the data folder is properly set (within the function...)
980//      VC_SetShadow_TopBottom("","MB")
981       
982        // do the q-binning for each of the panels to get I(Q)
983        Execute "BinAllBackPanels()"
984
985        // plot the results
986        Execute "Back_IQ_Graph()"
987        Execute "BackPanels_AsQ()"
988
989        return(0)
990
991End
992
993// works for Left, works for Right... works for T/B too.
994//
995// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
996//     detector, and on different sides of the detector (or T/B) - since it will be in a different
997//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
998//     --- test this...
999// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
1000//
1001// TODO: make all detector parameters global, not hard-wired
1002//
1003//
1004// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
1005//     when anything changes
1006//
1007Function VC_CalculateQBackPanels()
1008
1009        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY
1010        Variable B_offset
1011
1012        String folderPath = "root:Packages:NIST:VSANS:VCALC"
1013        String instPath = ":entry:instrument:detector_"
1014        String detStr = ""
1015       
1016        B_offset = VCALC_getLateralOffset("B")
1017       
1018        SDD = VCALC_getSDD("B")         //nominal SDD - need offset for TB
1019        lam = VCALC_getWavelength()
1020
1021// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
1022//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Back
1023        WAVE det_B = $(folderPath+instPath+"B"+":det_B")                        // this is nominally (150,150)
1024
1025//Back detector
1026//root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B:qTot_B
1027        detStr = "B"
1028        Wave qTot_B = $(folderPath+instPath+detStr+":qTot_"+detStr)                     // 2D q-values
1029        Wave qx_B = $(folderPath+instPath+detStr+":qx_"+detStr)
1030        Wave qy_B = $(folderPath+instPath+detStr+":qy_"+detStr)
1031        Wave qz_B = $(folderPath+instPath+detStr+":qz_"+detStr)
1032
1033        qTot_B = 0
1034        qx_B = 0
1035        qy_B = 0
1036        qz_B = 0       
1037       
1038// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
1039// pixel sizes are in cm
1040        pixSizeX = VCALC_getPixSizeX("B")
1041        pixSizeY = VCALC_getPixSizeY("B")
1042       
1043        xCtr = trunc( DimSize(det_B,0)/2 )              //should be 150/2=75
1044        yCtr = trunc( DimSize(det_B,1)/2 )              //should be 150/2=75
1045                //put these  beam center values into the local folder
1046        V_putDet_beam_center_x("VCALC","B",xCtr)
1047        V_putDet_beam_center_y("VCALC","B",yCtr)
1048       
1049//      VC_Detector_2Q(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
1050        // this will always do the linear calculation, since the real-space distance waves do not exist
1051        VC_Detector_2Q_NonLin(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"B")
1052
1053       
1054        //set the wave scaling for the detector image so that it can be plotted in q-space
1055        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
1056        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
1057        // since qTot is magnitude only, I need to put in the (-ve)
1058        SetScale/I x WaveMin(qx_B),WaveMax(qx_B),"", det_B              //this sets the left and right ends of the data scaling
1059        SetScale/I y WaveMin(qy_B),WaveMax(qy_B),"", det_B
1060
1061        SetDataFolder root:
1062               
1063        return(0)
1064End
1065
1066
1067Window BackPanels_AsQ() : Graph
1068//      DoWindow/F BackPanels_AsQ
1069//      if(V_flag == 0)
1070//      PauseUpdate; Silent 1           // building window...
1071//      Display /W=(1477,44,1978,517)
1072
1073        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1074
1075        CheckDisplayed /W=VCALC#Panels_Q det_B
1076        if(V_flag == 0)
1077                AppendImage/W=VCALC#Panels_Q det_B
1078                ModifyImage/W=VCALC#Panels_Q det_B ctab= {*,*,ColdWarm,0}
1079        endif
1080
1081        Variable dval
1082        ControlInfo/W=VCALC setVar_b
1083        dval = V_Value
1084
1085        SetAxis/W=VCALC#Panels_Q left -dval,dval
1086        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
1087
1088        ControlInfo/W=VCALC check_0a
1089// V_Value == 1 if checked
1090        ModifyImage/W=VCALC#Panels_Q det_B log=V_Value
1091
1092        SetDataFolder root:
1093       
1094//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
1095//      ModifyGraph grid=2
1096//      ModifyGraph mirror=2
1097//      SetAxis left -0.2,0.2
1098//      SetAxis bottom -0.2,0.2
1099//      endif
1100EndMacro
1101
1102//
1103// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
1104// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
1105//
1106// first - the DeltaQ step is set as the smaller detector resolution (along tube)
1107//       which is different for LR / TB geometry. This is not set in stone.
1108//
1109// second - each detector is binned separately
1110//
1111// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
1112//      you'l end up with < 200 points.
1113//
1114// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
1115//
1116Proc BinAllBackPanels()
1117
1118        SetDeltaQ("VCALC","B")
1119
1120        Variable binType       
1121        ControlInfo/W=VCALC popup_b
1122        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1123       
1124        VC_BinQxQy_to_1D("VCALC","B")
1125
1126// TODO -- this is only a temporary fix for slit mode   
1127        if(binType == 4)
1128                /// this is for a tall, narrow slit mode       
1129                VC_fBinDetector_byRows("VCALC","B")
1130        endif   
1131       
1132End
1133
1134////////////to plot the back panel I(q)
1135Window Back_IQ_Graph() : Graph
1136
1137        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1138
1139        Variable binType
1140       
1141        ControlInfo/W=VCALC popup_b
1142        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1143       
1144
1145        if(binType==1 || binType==2 || binType==3)
1146               
1147                SetDataFolder root:Packages:NIST:VSANS:VCALC
1148                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1149               
1150                if(V_flag==0)
1151                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1152                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1153                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1154                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1155                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1156                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1157                        ModifyGraph/W=VCALC#Panels_IQ log=1
1158                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1159                endif
1160        endif
1161
1162        //nothing different here since there is ony a single detector to display, but for the future...
1163        if(binType==4)
1164               
1165                SetDataFolder root:Packages:NIST:VSANS:VCALC
1166                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1167               
1168                if(V_flag==0)
1169                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1170                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1171                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1172                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1173                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1174                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1175                        ModifyGraph/W=VCALC#Panels_IQ log=1
1176                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1177                endif
1178        endif
1179
1180       
1181        SetDataFolder root:
1182EndMacro
1183
1184
1185////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
1186//
1187// ** but now I need to check and see if these waves exist before trying to append them
1188// since the panels may bave been combined when binned - rather than all separate.
1189//
1190// TODO
1191// -- so maybe I want to clear the traces from the graph?
1192// -- set a flag on the panel to know how the binning is applied?
1193//
1194Window Front_IQ_Graph() : Graph
1195
1196        Variable binType
1197        String fldr = "VCALC"
1198       
1199        ControlInfo/W=VCALC popup_b
1200        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1201
1202        SetDataFolder root:Packages:NIST:VSANS:VCALC
1203
1204        if(binType==1)
1205                ClearIQIfDisplayed("VCALC","FLRTB")
1206                ClearIQIfDisplayed("VCALC","FLR")
1207                ClearIQIfDisplayed("VCALC","FTB")
1208               
1209                SetDataFolder root:Packages:NIST:VSANS:VCALC
1210                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1211               
1212                if(V_flag==0)
1213                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1214                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1215                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1216                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1217                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1218                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1219                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FL)=(39321,26208,1),rgb(iBin_qxqy_FB)=(2,39321,1),rgb(iBin_qxqy_FR)=(39321,26208,1),rgb(iBin_qxqy_FT)=(2,39321,1)
1220                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1221                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1222                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1223                        ModifyGraph/W=VCALC#Panels_IQ log=1
1224                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1225                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1226                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1227                endif   
1228                               
1229        endif
1230
1231        if(binType==2)
1232                ClearIQIfDisplayed("VCALC","FLRTB")
1233                ClearIQIfDisplayed("VCALC","FT")       
1234                ClearIQIfDisplayed("VCALC","FL")       
1235                ClearIQIfDisplayed("VCALC","FR")       
1236                ClearIQIfDisplayed("VCALC","FB")
1237       
1238
1239                SetDataFolder root:Packages:NIST:VSANS:VCALC
1240                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLR
1241               
1242                if(V_flag==0)
1243                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLR vs qBin_qxqy_FLR
1244                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FTB vs qBin_qxqy_FTB
1245                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1246                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1247                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLR)=(39321,26208,1),rgb(iBin_qxqy_FTB)=(2,39321,1)
1248                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1249                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FLR)={0,2}
1250                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1251                        ModifyGraph/W=VCALC#Panels_IQ log=1
1252                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1253                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1254                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1255                endif   
1256                       
1257        endif
1258       
1259        if(binType==3)
1260                ClearIQIfDisplayed("VCALC","FLR")
1261                ClearIQIfDisplayed("VCALC","FTB")       
1262                ClearIQIfDisplayed("VCALC","FT")       
1263                ClearIQIfDisplayed("VCALC","FL")       
1264                ClearIQIfDisplayed("VCALC","FR")       
1265                ClearIQIfDisplayed("VCALC","FB")       
1266       
1267                SetDataFolder root:Packages:NIST:VSANS:VCALC
1268                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLRTB
1269               
1270                if(V_flag==0)
1271                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLRTB vs qBin_qxqy_FLRTB
1272                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1273                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1274                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLRTB)=(39321,26208,1)
1275                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1276                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1277                        ModifyGraph/W=VCALC#Panels_IQ log=1
1278                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1279                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1280                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1281                endif   
1282                       
1283        endif
1284
1285
1286        if(binType==4)          //slit mode
1287                ClearIQIfDisplayed("VCALC","FLRTB")
1288                ClearIQIfDisplayed("VCALC","FLR")
1289                ClearIQIfDisplayed("VCALC","FTB")
1290               
1291                SetDataFolder root:Packages:NIST:VSANS:VCALC
1292                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1293               
1294                if(V_flag==0)
1295                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1296                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1297                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1298                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1299                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1300                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1301                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FL)=(39321,26208,1),rgb(iBin_qxqy_FB)=(2,39321,1),rgb(iBin_qxqy_FR)=(39321,26208,1),rgb(iBin_qxqy_FT)=(2,39321,1)
1302                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1303                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1304                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1305                        ModifyGraph/W=VCALC#Panels_IQ log=1
1306                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1307                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1308                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1309                endif   
1310                               
1311        endif
1312
1313       
1314        SetDataFolder root:
1315       
1316EndMacro
1317
1318
1319Function ClearIQIfDisplayed(fldr,type)
1320        String fldr,type
1321
1322        SetDataFolder $("root:Packages:NIST:VSANS:"+fldr)
1323
1324        if(cmpstr(fldr,"VCALC") == 0)
1325                CheckDisplayed/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1326                if(V_flag==1)
1327                        RemoveFromGraph/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1328                endif
1329        else
1330                CheckDisplayed/W=V_1D_Data $("iBin_qxqy_"+type)
1331                if(V_flag==1)
1332                        RemoveFromGraph/W=V_1D_Data $("iBin_qxqy_"+type)
1333                endif
1334        endif
1335
1336        SetDataFolder root:
1337       
1338        return(0)
1339end
1340
1341Window Table_of_QBins() : Table
1342        PauseUpdate; Silent 1           // building window...
1343        String fldrSav0= GetDataFolder(1)
1344        SetDataFolder root:Packages:NIST:VSANS:VCALC:
1345        Edit/W=(5,44,771,898) qBin_qxqy_FL,qBin_qxqy_FR,qBin_qxqy_FT,qBin_qxqy_FB,qBin_qxqy_FLR
1346        AppendToTable qBin_qxqy_FTB,qBin_qxqy_FLRTB
1347        ModifyTable format(Point)=1,width(qBin_qxqy_FLR)=136,width(qBin_qxqy_FLRTB)=120
1348        SetDataFolder fldrSav0
1349EndMacro
1350
1351
1352
1353
Note: See TracBrowser for help on using the repository browser.