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

Last change on this file since 1037 was 1036, checked in by srkline, 5 years ago

added utilities to allow saving of I(q) data sets either individual or concatenated. At this point, it simply trims a nominal number of points from the beginning and end of each set before concatenation (and then sorting).

These operations will need to be augmented in the future.

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