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

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

many changes to get the basics of a reduction protocol working

File size: 14.2 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       
46                Execute "VC_Initialize_Space()"         // initializes VCALC space, so that dummy values are present for MSK and DIV
47       
48                Execute "V_IsolateDetectorPanel()"
49        endif
50End
51
52
53//
54// TODO - may need to adjust the display for the different pixel dimensions
55//      ModifyGraph width={Plan,1,bottom,left}
56//
57Proc V_IsolateDetectorPanel() : Panel
58        PauseUpdate; Silent 1           // building window...
59
60
61        NewPanel /W=(662,418,1586,960)/N=IsolateDetector /K=1
62//      ShowTools/A
63       
64        PopupMenu popup_0,pos={169,18},size={109,20},proc=V_isoSetDetPanelPopMenuProc,title="Detector Panel"
65        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
66//      PopupMenu popup_1,pos={200,20},size={157,20},proc=DetModelPopMenuProc,title="Model Function"
67//      PopupMenu popup_1,mode=1,popvalue="BroadPeak",value= #"\"BroadPeak;other;\""
68        PopupMenu popup_2,pos={20,18},size={109,20},title="Data Source",proc=V_SetFldrPopMenuProc
69        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;SAM;EMP;BGD;DIV;MSK;\""
70               
71        Button button_0,pos={541,79},size={130,20},proc=V_isoCorrectButtonProc,title="Apply Corrections"
72//      Button button_1,pos={651,79},size={80,20},proc=V_isoDetFitGuessButtonProc,title="Guess"
73        Button button_2,pos={821,20},size={80,20},proc=V_isoHelpButtonProc,title="Help"
74
75
76
77        CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
78        CheckBox check_0,value= 0
79        CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
80        CheckBox check_1,value= 0
81        CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
82        CheckBox check_2,value= 0
83        CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
84        CheckBox check_3,value= 0
85        CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
86        CheckBox check_4,value= 0
87        CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
88        CheckBox check_5,value= 0
89        CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
90        CheckBox check_6,value= 0
91
92
93
94//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
95
96//      duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
97//      SetScale/P x 0,1, curDispPanel
98//      SetScale/P y 0,1, curDispPanel
99//      Duplicate/O curDispPanel correctedPanel
100
101//      SetDataFolder root:
102       
103        V_CopyHDFToWorkFolder("RAW","ADJ")
104       
105        // draw the correct images
106        V_isoDrawDetPanel("FL")
107
108       
109
110// edit the fit coefficients   
111//      Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
112//      ModifyTable width(Point)=0
113//      ModifyTable width(parameters_PeakPix2D)=120
114//      ModifyTable width(coef_PeakPix2D)=100
115//      RenameWindow #,T0
116//      SetActiveSubwindow ##
117
118       
119EndMacro
120
121
122//
123// function to choose which detector panel to display, and then to actually display it
124//
125Function V_isoSetDetPanelPopMenuProc(pa) : PopupMenuControl
126        STRUCT WMPopupAction &pa
127
128        switch( pa.eventCode )
129                case 2: // mouse up
130                        Variable popNum = pa.popNum
131                        String popStr = pa.popStr
132                                               
133                        // remove the old image (it may not be the right shape)
134                        // -- but make sure it exists first...
135                        String childList = ChildWindowList("IsolateDetector")
136                        Variable flag
137                       
138                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
139                        if(flag != -1)
140                                KillWindow IsolateDetector#DetData
141                        endif
142                       
143                        flag = WhichListItem("ModelData", ChildList)
144                        if(flag != -1)
145                                KillWindow IsolateDetector#ModelData
146                        endif
147       
148                        // draw the correct images
149                        V_isoDrawDetPanel(popStr)
150                       
151                        break
152                case -1: // control being killed
153                        break
154        endswitch
155
156        return 0
157End
158
159
160// TODO - currently is hard-wired for the simulation path!
161//     need to make it more generic, especially for RAW data
162//
163// -- need to adjust the size of the image subwindows to keep the model
164//    calculation from spilling over onto the table (maybe just move the table)
165// -- need to do something for panel "B". currently ignored
166// -- currently the pixel sizes for "real" data is incorrect in the file
167//     and this is why the plots are incorrectly sized
168// -- need to be able to display MASK and DIV data (or any data without a full set of metadata)
169//
170//
171// draw the selected panel and the model calculation, adjusting for the
172// orientation of the panel and the number of pixels, and pixel sizes
173//
174// str input is the panelStr ("FL" for example)
175Function V_isoDrawDetPanel(str)
176        String str
177       
178        // from the selection, find the path to the data
179
180
181        Variable xDim,yDim
182        Variable left,top,right,bottom
183        Variable height, width
184        Variable left2,top2,right2,bottom2
185        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
186
187
188//      Wave dispW=root:Packages:NIST:VSANS:Globals:Isolate:curDispPanel
189//      Wave corrW=root:Packages:NIST:VSANS:Globals:Isolate:correctedPanel
190
191        //plot it in the subwindow with the proper aspect and positioning
192        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
193        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
194       
195       
196        // using two switches -- one to set the panel-specific dimensions
197        // and the other to set the "common" values, some of which are based on the panel dimensions
198
199// set the source of the data. not always VCALC anymore
200        String folder
201        ControlInfo popup_2
202        folder = S_Value
203
204        Variable VC_nPix_X,VC_nPix_Y,VC_pixSize_X,VC_pixSize_Y
205        // TODO -- fix all of this mess
206        strswitch(folder)
207                case "VCALC":
208//                      VC_nPix_X = VCALC_get_nPix_X(str)
209//                      VC_nPix_Y = VCALC_get_nPix_Y(str)
210//                      VC_pixSize_X = VCALC_getPixSizeX(str)
211//                      VC_pixSize_Y = VCALC_getPixSizeY(str)
212//                      wave dispW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
213//                      nPix_X = VC_nPix_X
214//                      nPix_Y = VC_nPix_Y
215//                      pixSize_X = VC_pixSize_X
216//                      pixSize_Y = VC_pixSize_Y
217       
218                        break
219                       
220                case "DIV":
221                case "MSK":
222                // TODO
223                // -- this takes fake data from VCALC, which is very likely wrong for DIV data
224                        VC_nPix_X = VCALC_get_nPix_X(str)
225                        VC_nPix_Y = VCALC_get_nPix_Y(str)
226                        VC_pixSize_X = VCALC_getPixSizeX(str)
227                        VC_pixSize_Y = VCALC_getPixSizeY(str)
228                        wave dispW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
229                        nPix_X = VC_nPix_X
230                        nPix_Y = VC_nPix_Y
231                        pixSize_X = VC_pixSize_X
232                        pixSize_Y = VC_pixSize_Y
233                        break
234
235                case "RAW":
236                case "ADJ":
237                        wave dispW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
238       
239                        nPix_X = V_getDet_pixel_num_x(folder,str)
240                        nPix_Y = V_getDet_pixel_num_Y(folder,str)
241                        pixSize_X = V_getDet_x_pixel_size(folder,str)/10
242                        pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
243                        break
244                               
245                default:
246                        return(0)
247        endswitch
248
249
250        // and the ADJusted wave to display     
251        wave corrW = $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str+":data")
252
253        Variable scale = 5
254       
255        // common values (panel position, etc)
256        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
257        strswitch(str)
258                case "FL":
259                case "FR":
260                case "ML":
261                case "MR":
262                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
263                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
264                       
265                        left = 20
266                        top = 80
267                        right = left+width
268                        bottom = top+height
269                       
270                        left2 = right + 20
271                        right2 = left2 + width
272                        top2 = top
273                        bottom2 = bottom
274                       
275                        break                   
276                case "FT":
277                case "FB":
278                case "MT":
279                case "MB":
280                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
281                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
282                                               
283                        left = 20
284                        top = 80
285                        right = left+width
286                        bottom = top+height
287                       
288                        left2 = left
289                        right2 = right
290                        top2 = top + height + 20
291                        bottom2 = bottom + height + 20
292                       
293                        break
294                case "B":
295                        return(0)               //just exit
296                        break                                           
297                default:
298                        return(0)               //just exit
299        endswitch
300
301
302
303//      SetDataFolder root:Packages:NIST:VSANS:Globals:Isolate
304        // generate the new panel display and corrected panel (just a copy right now)
305//      duplicate/O newW curDispPanel
306//      SetScale/P x 0,1, curDispPanel
307//      SetScale/P y 0,1, curDispPanel
308//      Duplicate/O curDispPanel correctedPanel
309       
310        // need to be in the same folder as the data
311        SetDataFolder $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str)
312        Wave data1 = data
313       
314        //draw the detector panel
315        Display/W=(left,top,right,bottom)/HOST=#
316        RenameWindow #,DetData
317        AppendImage/W=IsolateDetector#DetData data1
318        ModifyImage/W=IsolateDetector#DetData '' ctab= {*,*,ColdWarm,0}
319        Label left "Y pixels"
320        Label bottom "X pixels"
321        SetActiveSubwindow ##   
322       
323       
324        SetDataFolder $("root:Packages:NIST:VSANS:ADJ:entry:instrument:detector_"+str)
325        Wave data2 = data
326       
327        //draw the corrected detector panel
328        // see the main display of RAW data for example of multiple 'data' images
329        Display/W=(left2,top2,right2,bottom2)/HOST=#
330        RenameWindow #,ModelData
331        AppendImage/W=IsolateDetector#ModelData data2
332        ModifyImage/W=IsolateDetector#ModelData '' ctab= {*,*,ColdWarm,0}               // the image is called '' even though the local ref is data2
333        Label left "Y pixels"
334        Label bottom "X pixels"
335
336        SetActiveSubwindow ##   
337
338
339        SetDataFolder root:
340               
341        DoUpdate
342       
343        return(0)
344End
345
346
347
348//
349Function V_isoCorrectButtonProc(ba) : ButtonControl
350        STRUCT WMButtonAction &ba
351
352        Variable sav0,sav1,sav2,sav3,sav4,sav5,sav6
353       
354        switch( ba.eventCode )
355                case 2: // mouse up
356                        // click code here
357                       
358                        // save the state of the global flags
359                        // poll the state of the checkboxes
360                        // temporarily set the global (preference) flags
361
362//                      CheckBox check_0,pos={542.00,131.00},size={110.00,16.00},title="non-linear correction"
363                        NVAR gDoNonLinearCor = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor
364                        sav0 = gDoNonLinearCor
365                        ControlInfo check_0
366                        gDoNonLinearCor = V_Value
367                       
368//                      CheckBox check_1,pos={542.00,159.00},size={110.00,16.00},title="dead time correction"
369                        NVAR gDoDeadTimeCor = root:Packages:NIST:VSANS:Globals:gDoDeadTimeCor
370                        sav1 = gDoDeadTimeCor
371                        ControlInfo check_1
372                        gDoDeadTimeCor = V_Value
373                       
374//                      CheckBox check_2,pos={542.00,187.00},size={110.00,16.00},title="solid angle correction"
375                        NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor
376                        sav2 = gDoSolidAngleCor
377                        ControlInfo check_2
378                        gDoSolidAngleCor = V_Value
379                       
380//                      CheckBox check_3,pos={542.00,215.00},size={110.00,16.00},title="sensitivity (DIV) correction"
381                        NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
382                        sav3 = gDoDIVCor
383                        ControlInfo check_3
384                        gDoDIVCor = V_Value
385                       
386//                      CheckBox check_4,pos={542.00,243.00},size={110.00,16.00},title="transmission correction"
387                        NVAR gDoTrans = root:Packages:NIST:VSANS:Globals:gDoTransmissionCor
388                        sav4 = gDoTrans
389                        ControlInfo check_4
390                        gDoTrans = V_Value
391                       
392//                      CheckBox check_5,pos={542.00,271.00},size={110.00,16.00},title="tube shadow correction"
393                        NVAR gDoTubeShadowCor = root:Packages:NIST:VSANS:Globals:gDoTubeShadowCor
394                        sav5 = gDoTubeShadowCor
395                        ControlInfo check_5
396                        gDoTubeShadowCor = V_Value
397                       
398//                      CheckBox check_6,pos={542.00,300.00},size={110.00,16.00},title="monitor normalization"
399                        NVAR gDoMonitorNormalization = root:Packages:NIST:VSANS:Globals:gDoMonitorNormalization
400                        sav6 = gDoMonitorNormalization
401                        ControlInfo check_6
402                        gDoMonitorNormalization = V_Value
403                       
404       
405                       
406                        // raw_to_work to apply the selected corrections
407                        // TODO -- verify that this works correctly, since ADJ has waves in use and the folder
408                        //         can't be directly killed. Copy is the first step - so verify.
409                        V_Raw_to_work("ADJ")
410                       
411                       
412                       
413                        // set the globals back the the prior state
414                        gDoNonlinearCor = sav0
415                        gDoDeadTimeCor = sav1
416                        gDoSolidAngleCor = sav2
417                        gDoDIVCor = sav3
418                        gDoTrans = sav4
419                        gDoTubeShadowCor = sav5
420                        gDoMonitorNormalization = sav6
421                       
422                       
423                       
424                        break
425                case -1: // control being killed
426                        break
427        endswitch
428
429        return 0
430End
431
432
433
434
435////
436// copies the data from the popped folder (either RAW or VCALC) to ADJ
437//
438Function V_SetFldrPopMenuProc(pa) : PopupMenuControl
439        STRUCT WMPopupAction &pa
440
441        switch( pa.eventCode )
442                case 2: // mouse up
443                        Variable popNum = pa.popNum
444                        String popStr = pa.popStr
445                       
446                        V_CopyHDFToWorkFolder(popStr,"ADJ")
447                       
448                        break
449                case -1: // control being killed
450                        break
451        endswitch
452
453        return 0
454End
455
456
457Function V_isoHelpButtonProc(ba) : ButtonControl
458        STRUCT WMButtonAction &ba
459
460        switch( ba.eventCode )
461                case 2: // mouse up
462                        // click code here
463                       
464                        DoAlert 0,"Help file not written yet..."
465                       
466                        break
467                case -1: // control being killed
468                        break
469        endswitch
470
471        return 0
472End
473
Note: See TracBrowser for help on using the repository browser.