source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Detector_Isolate.ipf @ 1024

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

minor changes to prefix functions with "V_" to avoid conflicts with non-VSANS functions.

File size: 13.5 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5// Isolation of a single detector panel for inspection, verifying the corrections, troubleshooting, etc.
6
7
8// show:
9// graph (raw + corrected?)
10// all the fields pertinent to the detector
11// all of the tables of parameters (one at a time?)
12// + a way to edit them if possible? or leave this to patch?
13// way to toggle corrections on/off
14// draw arcs to show concentric rings around the beam center
15
16
17// TODO
18// -- verify the flow of operations - that is, what is the state of what is displayed? After doing
19//    the corrections, popping the detector panel will display from RAW, but really should display from ADJ
20// -- need labels on images to know what they are
21// -- does it mean anything to "not" do the non-linear correction. I think I always calculate it in the background
22//    when the RAW data is loaded, and always use the corrected real-space distances for the calculation of q-values
23//    (so there is no visible effect on pixels)...
24// -- interaction with the main data display will allow seeing the whole set of detectors. What is the benefit of
25//    this isolation? Should I make a bigger, more visible detector image?
26// x- link the function to the Isolate button on the main panel
27//
28// -- figure out how to (better?) re-plot the images when swapping between LR and TB panels
29// -- graphically show the beam center / radius of where it is in relation to the panel
30//
31// -- when selecting the detector, set the x/y pixel sizes -- un-do this?
32// -- The xPixels, yPixels axis labels are not correct. The axes are scaled to the beam center, through
33//    a call to V_RestorePanels() when the raw data is loaded. The BeamCenter panel removes this wave scaling
34//    so that the data can be presented (and fit) purely as pixels. On the isolate panel, the scaling has not
35//    been removed and is confusing, especially on T/B panels.
36// -- add a checkbox or button to remove/replace the wave scaling to the beam center. this is in a sense,
37//    a correction to toggle.
38//
39//
40
41
42Function V_DetectorIsolate()
43        DoWindow/F IsolateDetector
44        if(V_flag==0)
45                Execute "V_IsolateDetectorPanel()"
46        endif
47End
48
49
50//
51// TODO - may need to adjust the display for the different pixel dimensions
52//      ModifyGraph width={Plan,1,bottom,left}
53//
54Proc V_IsolateDetectorPanel() : Panel
55        PauseUpdate; Silent 1           // building window...
56
57
58        NewPanel /W=(662,418,1586,960)/N=IsolateDetector /K=1
59//      ShowTools/A
60       
61        PopupMenu popup_0,pos={169,18},size={109,20},proc=V_isoSetDetPanelPopMenuProc,title="Detector Panel"
62        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
63//      PopupMenu popup_1,pos={200,20},size={157,20},proc=DetModelPopMenuProc,title="Model Function"
64//      PopupMenu popup_1,mode=1,popvalue="BroadPeak",value= #"\"BroadPeak;other;\""
65        PopupMenu popup_2,pos={20,18},size={109,20},title="Data Source",proc=V_SetFldrPopMenuProc
66        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;VCALC;\""
67               
68        Button button_0,pos={541,79},size={130,20},proc=V_isoCorrectButtonProc,title="Apply Corrections"
69//      Button button_1,pos={651,79},size={80,20},proc=V_isoDetFitGuessButtonProc,title="Guess"
70        Button button_2,pos={821,20},size={80,20},proc=V_isoHelpButtonProc,title="Help"
71
72
73
74        CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
75        CheckBox check_0,value= 0
76        CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
77        CheckBox check_1,value= 0
78        CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
79        CheckBox check_2,value= 0
80        CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
81        CheckBox check_3,value= 0
82        CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
83        CheckBox check_4,value= 0
84        CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
85        CheckBox check_5,value= 0
86        CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
87        CheckBox check_6,value= 0
88
89
90
91//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
92
93//      duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
94//      SetScale/P x 0,1, curDispPanel
95//      SetScale/P y 0,1, curDispPanel
96//      Duplicate/O curDispPanel correctedPanel
97
98//      SetDataFolder root:
99       
100        V_CopyHDFToWorkFolder("RAW","ADJ")
101       
102        // draw the correct images
103        V_isoDrawDetPanel("FL")
104
105       
106
107// edit the fit coefficients   
108//      Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
109//      ModifyTable width(Point)=0
110//      ModifyTable width(parameters_PeakPix2D)=120
111//      ModifyTable width(coef_PeakPix2D)=100
112//      RenameWindow #,T0
113//      SetActiveSubwindow ##
114
115       
116EndMacro
117
118
119//
120// function to choose which detector panel to display, and then to actually display it
121//
122Function V_isoSetDetPanelPopMenuProc(pa) : PopupMenuControl
123        STRUCT WMPopupAction &pa
124
125        switch( pa.eventCode )
126                case 2: // mouse up
127                        Variable popNum = pa.popNum
128                        String popStr = pa.popStr
129                                               
130                        // remove the old image (it may not be the right shape)
131                        // -- but make sure it exists first...
132                        String childList = ChildWindowList("IsolateDetector")
133                        Variable flag
134                       
135                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
136                        if(flag != -1)
137                                KillWindow IsolateDetector#DetData
138                        endif
139                       
140                        flag = WhichListItem("ModelData", ChildList)
141                        if(flag != -1)
142                                KillWindow IsolateDetector#ModelData
143                        endif
144       
145                        // draw the correct images
146                        V_isoDrawDetPanel(popStr)
147                       
148                        break
149                case -1: // control being killed
150                        break
151        endswitch
152
153        return 0
154End
155
156
157// TODO - currently is hard-wired for the simulation path!
158//     need to make it more generic, especially for RAW data
159//
160// -- need to adjust the size of the image subwindows to keep the model
161//    calculation from spillon over onto the table (maybe just move the table)
162// -- need to do something for panel "B". currently ignored
163// -- currently the pixel sizes for "real" data is incorrect in the file
164//     and this is why the plots are incorrectly sized
165//
166// draw the selected panel and the model calculation, adjusting for the
167// orientation of the panel and the number of pixels, and pixel sizes
168Function V_isoDrawDetPanel(str)
169        String str
170       
171        // from the selection, find the path to the data
172
173
174        Variable xDim,yDim
175        Variable left,top,right,bottom
176        Variable height, width
177        Variable left2,top2,right2,bottom2
178        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
179
180
181//      Wave dispW=root:Packages:NIST:VSANS:Globals:Isolate:curDispPanel
182//      Wave corrW=root:Packages:NIST:VSANS:Globals:Isolate:correctedPanel
183
184        //plot it in the subwindow with the proper aspect and positioning
185        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
186        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
187       
188       
189        // using two switches -- one to set the panel-specific dimensions
190        // and the other to set the "common" values, some of which are based on the panel dimensions
191
192// set the source of the data. not always VCALC anymore
193        String folder
194        ControlInfo popup_2
195        folder = S_Value
196
197        // TODO -- fix all of this mess
198        if(cmpstr(folder,"VCALC") == 0)
199                // panel-specific values
200                Variable VC_nPix_X = VCALC_get_nPix_X(str)
201                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
202                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
203                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
204
205       
206        // if VCALC declare this way   
207                wave dispW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
208                nPix_X = VC_nPix_X
209                nPix_Y = VC_nPix_Y
210                pixSize_X = VC_pixSize_X
211                pixSize_Y = VC_pixSize_Y
212       
213        else
214        // TODO: if real data, need new declaration w/ data as the wave name
215                wave dispW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
216
217                nPix_X = V_getDet_pixel_num_x(folder,str)
218                nPix_Y = V_getDet_pixel_num_Y(folder,str)
219                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
220                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
221        endif
222
223        // and the ADJusted wave to display     
224        wave corrW = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str+":data")
225
226        Variable scale = 5
227       
228        // common values (panel position, etc)
229        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
230        strswitch(str)
231                case "FL":
232                case "FR":
233                case "ML":
234                case "MR":
235                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
236                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
237                       
238                        left = 20
239                        top = 80
240                        right = left+width
241                        bottom = top+height
242                       
243                        left2 = right + 20
244                        right2 = left2 + width
245                        top2 = top
246                        bottom2 = bottom
247                       
248                        break                   
249                case "FT":
250                case "FB":
251                case "MT":
252                case "MB":
253                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
254                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
255                                               
256                        left = 20
257                        top = 80
258                        right = left+width
259                        bottom = top+height
260                       
261                        left2 = left
262                        right2 = right
263                        top2 = top + height + 20
264                        bottom2 = bottom + height + 20
265                       
266                        break
267                case "B":
268                        return(0)               //just exit
269                        break                                           
270                default:
271                        return(0)               //just exit
272        endswitch
273
274
275
276//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
277        // generate the new panel display and corrected panel (just a copy right now)
278//      duplicate/O newW curDispPanel
279//      SetScale/P x 0,1, curDispPanel
280//      SetScale/P y 0,1, curDispPanel
281//      Duplicate/O curDispPanel correctedPanel
282       
283        // need to be in the same folder as the data
284        SetDataFolder $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str)
285        Wave data1 = data
286       
287        //draw the detector panel
288        Display/W=(left,top,right,bottom)/HOST=#
289        RenameWindow #,DetData
290        AppendImage/W=IsolateDetector#DetData data1
291        ModifyImage/W=IsolateDetector#DetData '' ctab= {*,*,ColdWarm,0}
292        Label left "Y pixels"
293        Label bottom "X pixels"
294        SetActiveSubwindow ##   
295       
296       
297        SetDataFolder $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str)
298        Wave data2 = data
299       
300        //draw the corrected detector panel
301        // see the main display of RAW data for example of multiple 'data' images
302        Display/W=(left2,top2,right2,bottom2)/HOST=#
303        RenameWindow #,ModelData
304        AppendImage/W=IsolateDetector#ModelData data2
305        ModifyImage/W=IsolateDetector#ModelData '' ctab= {*,*,ColdWarm,0}               // the image is called '' even though the local ref is data2
306        Label left "Y pixels"
307        Label bottom "X pixels"
308
309        SetActiveSubwindow ##   
310
311
312        SetDataFolder root:
313               
314        DoUpdate
315       
316        return(0)
317End
318
319
320
321//
322Function V_isoCorrectButtonProc(ba) : ButtonControl
323        STRUCT WMButtonAction &ba
324
325        Variable sav0,sav1,sav2,sav3,sav4,sav5,sav6
326       
327        switch( ba.eventCode )
328                case 2: // mouse up
329                        // click code here
330                       
331                        // save the state of the global flags
332                        // poll the state of the checkboxes
333                        // temporarily set the global (preference) flags
334
335//                      CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
336                        NVAR gDoNonLinearCor = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor
337                        sav0 = gDoNonLinearCor
338                        ControlInfo check_0
339                        gDoNonLinearCor = V_Value
340                       
341//                      CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
342                        NVAR gDoDeadTimeCor = root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor
343                        sav1 = gDoDeadTimeCor
344                        ControlInfo check_1
345                        gDoDeadTimeCor = V_Value
346                       
347//                      CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
348                        NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor
349                        sav2 = gDoSolidAngleCor
350                        ControlInfo check_2
351                        gDoSolidAngleCor = V_Value
352                       
353//                      CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
354                        NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
355                        sav3 = gDoDIVCor
356                        ControlInfo check_3
357                        gDoDIVCor = V_Value
358                       
359//                      CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
360                        NVAR gDoTrans = root:Packages:NIST:VSANS:Globals:gDoTransmissionCor
361                        sav4 = gDoTrans
362                        ControlInfo check_4
363                        gDoTrans = V_Value
364                       
365//                      CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
366                        NVAR gDoTubeShadowCor = root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor
367                        sav5 = gDoTubeShadowCor
368                        ControlInfo check_5
369                        gDoTubeShadowCor = V_Value
370                       
371//                      CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
372                        NVAR gDoMonitorNormalization = root:Packages:NIST:VSANS:Globals:gDoMonitorNormalization
373                        sav6 = gDoMonitorNormalization
374                        ControlInfo check_6
375                        gDoMonitorNormalization = V_Value
376                       
377       
378                       
379                        // raw_to_work to apply the selected corrections
380                        // TODO -- verify that this works correctly, since ADJ has waves in use and the folder
381                        //         can't be directly killed. Copy is the first step - so verify.
382                        V_Raw_to_work("ADJ")
383                       
384                       
385                       
386                        // set the globals back the the prior state
387                        gDoNonlinearCor = sav0
388                        gDoDeadTimeCor = sav1
389                        gDoSolidAngleCor = sav2
390                        gDoDIVCor = sav3
391                        gDoTrans = sav4
392                        gDoTubeShadowCor = sav5
393                        gDoMonitorNormalization = sav6
394                       
395                       
396                       
397                        break
398                case -1: // control being killed
399                        break
400        endswitch
401
402        return 0
403End
404
405
406
407
408////
409// copies the data from the popped folder (either RAW or VCALC) to ADJ
410//
411Function V_SetFldrPopMenuProc(pa) : PopupMenuControl
412        STRUCT WMPopupAction &pa
413
414        switch( pa.eventCode )
415                case 2: // mouse up
416                        Variable popNum = pa.popNum
417                        String popStr = pa.popStr
418                       
419                        V_CopyHDFToWorkFolder(popStr,"ADJ")
420                       
421                        break
422                case -1: // control being killed
423                        break
424        endswitch
425
426        return 0
427End
428
429
430Function V_isoHelpButtonProc(ba) : ButtonControl
431        STRUCT WMButtonAction &ba
432
433        switch( ba.eventCode )
434                case 2: // mouse up
435                        // click code here
436                       
437                        DoAlert 0,"Help file not written yet..."
438                       
439                        break
440                case -1: // control being killed
441                        break
442        endswitch
443
444        return 0
445End
446
Note: See TracBrowser for help on using the repository browser.