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

Last change on this file since 1074 was 1063, checked in by srkline, 5 years ago

proper handling of setback, intent, and purpose. New value of setback is included, and proper definition of how purpose and intent are defined within NICE and the GUI are partly completed now. Searches still need to be updated.

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