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

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

ADDED:

included common NCNR procedures for the PlotManager?, to allow plotting of 1D data sets using a familiar interface

greatly expanded Patch functionality to include input in the multiple sections of the Nexus file, including separate panels to handle patching of waves to the file - needed for non-linear coefficients, dead time, and XY beam centers. All patch operations are expandable as more fields become necessary to patch.

removed bug of group_id being defined in /reduction and in /sample (removed R/W that referenced /reduction)

added panel to "isolate" a single detector panel, allowing the corrections to be applied/removed/recalculated as needed to directly see their effects.

linked new procedures to their appropriate action buttons

Added more data fields (label, intent, etc.) to the VCALC to Nexus data writer to get more realistic values into the fake data files for testing

Added VCALC simulation functions with EMP and BGD in anticipation of testing the CORRECT step

more little bug and documentation fixes which I can't remember, but they are all important...

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