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

Last change on this file since 1109 was 1109, checked in by srkline, 4 years ago

Many changes:

Made the VCALC panel aware of all of the binning options
Corrected the behavior of the VCALC preset conditions
Adjusted how the Slit data is binned so that there are not duplicated q-values in the output

Made Absolute scaling aware of the back detector. Now the ABS String in the protocol has a second
set of scaling constants tagged with "_B" for the back detector. There is an added button
on the protocol panel to set the second set of constants. For the back detector, the read noise
is subtracted by reading it from the empty beam file (shifting over to the right by one box width)
All of the associated abs procedures are now aware of this.
More error checking needs to be added.

Back detector image is now shifted upon loading of the data. the default mask takes this into account
and masks out the padded (zero) regions.

in the protocol, DIV and MSK do not use grep any longer. it was just way too slow. Now it depends on

the file name having DIV or MASK respectively.



Raw data files can now be added together, in the usual way from the protocol panel.



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