source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_BeamCenter.ipf @ 1041

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

Added the angle dependent transmission correction to the data correction in the raw_to_work step, in 2D

added a testing file that can generate fake event data, read, write, and decode it. Read is based on GBLoadWave. Hoepfully I'll not need to write an XOP. manipulation of the 64 bit words are done with simple bit shifts and logic.

also added are a number of error checking routines to improve behavior when wave, folders, etc. are missing.

File size: 22.0 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3
4// TODO
5// -- adjust the guesses to some better starting conditions
6// -- multiple fit options with different things held
7// x- when selecting the detector, set the x/y pixel sizes
8// -- figure out how to re-plot the images when swapping between LR and TB panels
9// -- Modify to accept mm (real space dimensions) rather than pixels
10//    -- or be able to swap the answer to mm for a more natural definition of the beam center
11// -- add method to be able to write the values to the local folder / or better, to file on disk
12// -- graphically show the beam center / radius of where it is in relation to the panel
13//
14// x- error checking, if data is selected from a folder that does not exist (like VCALC). Otherwise
15//    the user is caught in a long loop of open file dialogs looking for something...
16//
17// -- move everything into it's own folder, rather than root:
18//
19// -- am I working in detector coordinates (1->n) or in array coordinates (0->n-1)??
20
21
22Function V_FindBeamCenter()
23        DoWindow/F PanelFit
24        if(V_flag==0)
25       
26                NewDataFolder/O root:Packages:NIST:VSANS:Globals:BeamCenter
27
28                Execute "V_DetectorPanelFit()"
29        endif
30End
31//
32// TODO - may need to adjust the display for the different pixel dimensions
33//      ModifyGraph width={Plan,1,bottom,left}
34//
35Proc V_DetectorPanelFit() : Panel
36        PauseUpdate; Silent 1           // building window...
37
38// plot the default model to be sure some data is present
39        if(exists("xwave_PeakPix2D") == 0)
40                V_PlotBroadPeak_Pix2D()
41        endif
42
43        NewPanel /W=(662,418,1586,960)/N=PanelFit/K=1
44//      ShowTools/A
45       
46        PopupMenu popup_0,pos={20,50},size={109,20},proc=V_SetDetPanelPopMenuProc,title="Detector Panel"
47        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
48        PopupMenu popup_1,pos={200,20},size={157,20},proc=V_DetModelPopMenuProc,title="Model Function"
49        PopupMenu popup_1,mode=1,popvalue="BroadPeak",value= #"\"BroadPeak;other;\""
50        PopupMenu popup_2,pos={20,20},size={109,20},title="Data Source"//,proc=SetFldrPopMenuProc
51        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;SAM;VCALC;\""
52               
53        Button button_0,pos={486,20},size={80,20},proc=V_DetFitGuessButtonProc,title="Guess"
54        Button button_1,pos={615,20},size={80,20},proc=V_DetFitButtonProc,title="Do Fit"
55        Button button_2,pos={744,20},size={80,20},proc=V_DetFitHelpButtonProc,title="Help"
56        Button button_3,pos={615,400},size={110,20},proc=V_WriteCtrButtonProc,title="Write Centers"
57        Button button_4,pos={730,400},size={110,20},proc=V_CtrTableButtonProc,title="Ctr table"
58        Button button_5,pos={730,440},size={110,20},proc=V_WriteCtrTableButtonProc,title="Write table"
59
60
61        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
62
63        duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
64        SetScale/P x 0,1, curDispPanel
65        SetScale/P y 0,1, curDispPanel
66
67        SetDataFolder root:
68       
69        // draw the correct images
70        V_DrawDetPanel("FL")
71
72       
73////draw the detector panel
74//      Display/W=(20,80,200,600)/HOST=#
75//      AppendImage curDispPanel
76//      ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
77////    ModifyGraph height={Aspect,2.67}               
78//      Label left "Y pixels"
79//      Label bottom "X pixels"
80//      RenameWindow #,DetData
81//      SetActiveSubwindow ##   
82//     
83////draw the model calculation
84//      Display/W=(220,80,400,600)/HOST=#
85//      AppendImage PeakPix2D_mat
86//      ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
87////    ModifyGraph height={Aspect,2.67}               
88////    ModifyGraph width={Aspect,0.375}               
89//      Label left "Y pixels"
90//      Label bottom "X pixels"
91//      RenameWindow #,ModelData
92//      SetActiveSubwindow ##           
93
94
95
96
97// edit the fit coefficients   
98        Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
99        ModifyTable width(Point)=0
100        ModifyTable width(parameters_PeakPix2D)=120
101        ModifyTable width(coef_PeakPix2D)=100
102        RenameWindow #,T0
103        SetActiveSubwindow ##
104
105       
106EndMacro
107
108
109//
110// function to choose which detector panel to display, and then to actually display it
111//
112Function V_SetDetPanelPopMenuProc(pa) : PopupMenuControl
113        STRUCT WMPopupAction &pa
114
115        switch( pa.eventCode )
116                case 2: // mouse up
117                        Variable popNum = pa.popNum
118                        String popStr = pa.popStr
119                                               
120                        // remove the old image (it may not be the right shape)
121                        // -- but make sure it exists first...
122                        String childList = ChildWindowList("PanelFit")
123                        Variable flag
124                       
125                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
126                        if(flag != -1)
127                                KillWindow PanelFit#DetData
128                        endif
129                       
130                        flag = WhichListItem("ModelData", ChildList)
131                        if(flag != -1)
132                                KillWindow PanelFit#ModelData
133                        endif
134       
135                        // draw the correct images
136                        V_DrawDetPanel(popStr)
137                       
138                        break
139                case -1: // control being killed
140                        break
141        endswitch
142
143        return 0
144End
145
146
147// TODO - currently is hard-wired for the simulation path!
148//     need to make it more generic, especially for RAW data
149//
150// -- need to adjust the size of the image subwindows to keep the model
151//    calculation from spilling over onto the table (maybe just move the table)
152// -- need to do something for panel "B". currently ignored
153// -- currently the pixel sizes for "real" data is incorrect in the file
154//     and this is why the plots are incorrectly sized
155//
156// draw the selected panel and the model calculation, adjusting for the
157// orientation of the panel and the number of pixels, and pixel sizes
158Function V_DrawDetPanel(str)
159        String str
160       
161        // from the selection, find the path to the data
162
163
164        Variable xDim,yDim
165        Variable left,top,right,bottom
166        Variable height, width
167        Variable left2,top2,right2,bottom2
168        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
169
170
171        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
172        Wave cw = root:coef_PeakPix2D
173
174        Wave xwave_PeakPix2D=root:xwave_PeakPix2D
175        Wave ywave_PeakPix2D=root:ywave_PeakPix2D
176        Wave zwave_PeakPix2D=root:zwave_PeakPix2D
177
178        //plot it in the subwindow with the proper aspect and positioning
179        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
180        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
181       
182       
183        // using two switches -- one to set the panel-specific dimensions
184        // and the other to set the "common" values, some of which are based on the panel dimensions
185
186// set the source of the data. not always VCALC anymore
187        String folder
188        ControlInfo popup_2
189        folder = S_Value
190
191// error checking -- if the VCALC folder is the target & does not exist, exit now
192        if( cmpstr(folder,"VCALC") == 0 && DataFolderExists("root:Packages:NIST:VSANS:VCALC") == 0)
193                return(0)
194        endif
195
196// error checking -- if the RAW folder is the target & does not exist, exit now
197        if( cmpstr(folder,"RAW") == 0 && DataFolderExists("root:Packages:NIST:VSANS:RAW:entry") == 0)
198                return(0)
199        endif
200
201// error checking -- if the SAM folder is the target & does not exist, exit now
202        if( cmpstr(folder,"SAM") == 0 && DataFolderExists("root:Packages:NIST:VSANS:SAM:entry") == 0)
203                return(0)
204        endif
205               
206        // TODO -- fix all of this mess
207        if(cmpstr(folder,"VCALC") == 0)
208                // panel-specific values
209                Variable VC_nPix_X = VCALC_get_nPix_X(str)
210                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
211                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
212                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
213//              strswitch(str)
214//                      case "FL":
215//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gFront_L_nPix_X
216//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gFront_L_nPix_Y
217//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gFront_L_pixelX
218//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gFront_L_pixelY
219//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
220//                              break
221//                      case "FR":
222//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gFront_R_nPix_X
223//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gFront_R_nPix_Y
224//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gFront_R_pixelX
225//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gFront_R_pixelY
226//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Front:det_"+str)
227//                              break
228//                      case "ML":
229//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gMiddle_L_nPix_X
230//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_L_nPix_Y
231//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gMiddle_L_pixelX
232//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_L_pixelY
233//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Middle:det_"+str)
234//                              break
235//                      case "MR":
236//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gMiddle_R_nPix_X
237//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_R_nPix_Y
238//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gMiddle_R_pixelX
239//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_R_pixelY
240//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Middle:det_"+str)
241//                              break   
242//     
243//                      case "FT":
244//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gFront_T_nPix_X
245//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gFront_T_nPix_Y
246//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gFront_T_pixelX
247//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gFront_T_pixelY
248//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Front:det_"+str)
249//                              break
250//                      case "FB":
251//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gFront_B_nPix_X
252//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gFront_B_nPix_Y
253//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gFront_B_pixelX
254//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gFront_B_pixelY
255//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Front:det_"+str)
256//                              break
257//                      case "MT":
258//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gMiddle_T_nPix_X
259//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_T_nPix_Y
260//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gMiddle_T_pixelX
261//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_T_pixelY
262//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Middle:det_"+str)
263//                              break
264//                      case "MB":
265//                              NVAR VC_nPix_X = root:Packages:NIST:VSANS:VCALC:gMiddle_B_nPix_X
266//                              NVAR VC_nPix_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_B_nPix_Y
267//                              NVAR VC_pixSize_X = root:Packages:NIST:VSANS:VCALC:gMiddle_B_pixelX
268//                              NVAR VC_pixSize_Y = root:Packages:NIST:VSANS:VCALC:gMiddle_B_pixelY
269//      //                      wave newW = $("root:Packages:NIST:VSANS:VCALC:Middle:det_"+str)
270//                              break   
271//                             
272//                      case "B":
273//                              return(0)               //just exit
274//                              break                                           
275//                      default:
276//                              return(0)               //just exit
277//              endswitch
278       
279        // if VCALC declare this way   
280                wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
281                nPix_X = VC_nPix_X
282                nPix_Y = VC_nPix_Y
283                pixSize_X = VC_pixSize_X
284                pixSize_Y = VC_pixSize_Y
285       
286        else
287        // TODO: if real data, need new declaration w/ data as the wave name
288                wave newW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
289
290                nPix_X = V_getDet_pixel_num_x(folder,str)
291                nPix_Y = V_getDet_pixel_num_Y(folder,str)
292                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
293                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
294        endif
295       
296
297        Variable scale = 5
298       
299        // common values (panel position, etc)
300        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
301        strswitch(str)
302                case "FL":
303                case "FR":
304                case "ML":
305                case "MR":
306                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
307                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
308                       
309                        left = 20
310                        top = 80
311                        right = left+width
312                        bottom = top+height
313                       
314                        left2 = right + 20
315                        right2 = left2 + width
316                        top2 = top
317                        bottom2 = bottom
318                       
319                        break                   
320                case "FT":
321                case "FB":
322                case "MT":
323                case "MB":
324                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
325                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
326                                               
327                        left = 20
328                        top = 80
329                        right = left+width
330                        bottom = top+height
331                       
332                        left2 = left
333                        right2 = right
334                        top2 = top + height + 20
335                        bottom2 = bottom + height + 20
336                       
337                        break
338                case "B":
339                        return(0)               //just exit
340                        break                                           
341                default:
342                        return(0)               //just exit
343        endswitch
344
345        // set from the detector-specific strswitch
346        cw[7] = pixSize_X*10
347        cw[8] = pixSize_Y*10           
348
349        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
350        // generate the new panel display
351        duplicate/O newW curDispPanel
352        SetScale/P x 0,1, curDispPanel
353        SetScale/P y 0,1, curDispPanel
354       
355        //draw the detector panel
356        Display/W=(left,top,right,bottom)/HOST=#
357        AppendImage curDispPanel
358        ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
359        Label left "Y pixels"
360        Label bottom "X pixels"
361        RenameWindow #,DetData
362        SetActiveSubwindow ##   
363       
364        SetDataFolder root:
365       
366       
367               
368        // re-dimension the model calculation to be the proper dimensions       
369        Redimension/N=(nPix_X*nPix_Y) xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D 
370        V_FillPixTriplet(xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D,nPix_X,nPix_Y)
371        Make/O/D/N=(nPix_X,nPix_Y) PeakPix2D_mat                // use the point scaling of the matrix (=pixels)
372
373        Duplicate/O $"PeakPix2D_mat",$"PeakPix2D_lin"           //keep a linear-scaled version of the data
374
375        //draw the model calculation
376        Display/W=(left2,top2,right2,bottom2)/HOST=#
377        AppendImage PeakPix2D_mat
378        ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
379        Label left "Y pixels"
380        Label bottom "X pixels"
381        RenameWindow #,ModelData
382        SetActiveSubwindow ##   
383               
384        DoUpdate
385       
386        return(0)
387End
388
389
390
391
392// TODO:
393// -- allow other model functions as needed.
394//
395// Function to plot the specified 2D model for the detector
396//
397Function V_DetModelPopMenuProc(pa) : PopupMenuControl
398        STRUCT WMPopupAction &pa
399
400        switch( pa.eventCode )
401                case 2: // mouse up
402                        Variable popNum = pa.popNum
403                        String popStr = pa.popStr
404                       
405                        Execute "V_PlotBroadPeak_Pix2D()"
406                       
407                        break
408                case -1: // control being killed
409                        break
410        endswitch
411
412        return 0
413End
414
415
416//
417// TODO - make a better guess (how?)
418//
419Function V_DetFitGuessButtonProc(ba) : ButtonControl
420        STRUCT WMButtonAction &ba
421
422        switch( ba.eventCode )
423                case 2: // mouse up
424                        // click code here
425                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
426                        Wave coefW=root:coef_PeakPix2D
427                       
428                        WaveStats/Q dispW
429                        coefW[2] = V_max
430                        coefW[0] = 1                   
431                       
432                        break
433                case -1: // control being killed
434                        break
435        endswitch
436
437        return 0
438End
439
440//
441// TODO -- currently hard-wired for coefficients from the only fit function
442//
443// -- will need to recalc mm center AND q-values
444Function V_WriteCtrButtonProc(ba) : ButtonControl
445        STRUCT WMButtonAction &ba
446
447        switch( ba.eventCode )
448                case 2: // mouse up
449                        // click code here
450                        String detStr,fname
451                        Wave coefW=root:coef_PeakPix2D
452                       
453                        ControlInfo popup_0
454                        detStr = S_Value
455                        ControlInfo popup_2
456                        fname = S_Value
457                       
458                        V_putDet_beam_center_x(fname,detStr,coefW[9])
459                        V_putDet_beam_center_y(fname,detStr,coefW[10])
460
461                        DoAlert 0, "-- will need to recalc mm center AND q-values"
462                       
463                        break
464                case -1: // control being killed
465                        break
466        endswitch
467
468        return 0
469End
470
471
472
473// TODO
474// -- there is only a single fitting function available, and it's hard-wired
475// -- what values are held during the fitting are hard-wired
476//
477//
478// function to call the fit function (2D)
479//
480Function V_DetFitButtonProc(ba) : ButtonControl
481        STRUCT WMButtonAction &ba
482
483        switch( ba.eventCode )
484                case 2: // mouse up
485                        // click code here
486                       
487                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
488                        Wave coefW=root:coef_PeakPix2D
489                       
490                        FuncFitMD/H="11000111100"/NTHR=0 V_BroadPeak_Pix2D coefW  dispW /D                     
491                       
492                        Wave ws=W_sigma
493                        AppendtoTable/W=PanelFit#T0 ws
494                       
495                        break
496                case -1: // control being killed
497                        break
498        endswitch
499
500        return 0
501End
502
503Function V_DetFitHelpButtonProc(ba) : ButtonControl
504        STRUCT WMButtonAction &ba
505
506        switch( ba.eventCode )
507                case 2: // mouse up
508                        // click code here
509                       
510                        DoAlert 0,"Help file not written yet..."
511                       
512                        break
513                case -1: // control being killed
514                        break
515        endswitch
516
517        return 0
518End
519
520Function V_CtrTableButtonProc(ba) : ButtonControl
521        STRUCT WMButtonAction &ba
522
523        switch( ba.eventCode )
524                case 2: // mouse up
525                        // click code here
526                       
527                        V_BCtrTable()
528                       
529                        break
530                case -1: // control being killed
531                        break
532        endswitch
533
534        return 0
535End
536
537Function V_WriteCtrTableButtonProc(ba) : ButtonControl
538        STRUCT WMButtonAction &ba
539
540        switch( ba.eventCode )
541                case 2: // mouse up
542                        // click code here
543                       
544                        V_BeamCtr_WriteTable()
545                       
546                        break
547                case -1: // control being killed
548                        break
549        endswitch
550
551        return 0
552End
553
554//
555// This sets the scale of the data panels to an approximate detector coordinate system with
556// zero at the center, only for display purposes. It is not exact, and has nothing to do with
557// the calculation of q-values.
558//
559// TODO
560// -- some of this is hard-wired in
561// -- this is still all in terms of pixels, which still may not be what I want
562// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
563//
564Function V_RescaleToBeamCenter(folderStr,detStr,xCtr,yCtr)
565        String folderStr,detStr
566        Variable xCtr,yCtr
567       
568        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
569       
570        Variable nPix = 128
571        Variable nTubes = 48
572       
573        strswitch(detStr)       // string switch
574                case "MT":              // top panels
575                case "FT":
576//                      SetScale/I x -xCtr,npix-xCtr,"",w
577                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
578                        SetScale/I y -yCtr,nTubes-yCtr,"",w
579                        break                                           // exit from switch
580                case "MB":              // bottom panels
581                case "FB":
582//                      SetScale/I x -xCtr,npix-xCtr,"",w
583                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
584                        SetScale/I y -yCtr,nTubes-yCtr,"",w
585                        break                                           // exit from switch
586                case "ML":              // left panels
587                case "FL":
588                        SetScale/I x -xCtr,nTubes-xCtr,"",w
589                        SetScale/I y -yCtr,npix-yCtr,"",w
590                        break                                           // exit from switch
591                case "MR":              // Right panels
592                case "FR":
593                        SetScale/I x -xCtr,nTubes-xCtr,"",w
594                        SetScale/I y -yCtr,npix-yCtr,"",w
595                        break                                           // exit from switch
596                                       
597                default:                                                        // optional default expression executed
598                        Print "Error in V_RescaleToBeamCenter()"
599        endswitch
600       
601        return(0)
602end
603
604// TODO
605// these are "nominal" beam center values in pixels for the default VCALC configuration
606// This function "restores" the data display to the "instrument" conditions where the panels overlap
607// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
608// the view should be symmetric (if the real data is symmetric)
609//
610// -- this is currently linked to the Vdata panel
611// -- will need to remove the hard-wired values and get the proper values from the data
612// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
613// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
614//
615//
616//
617//•print xCtr_pix
618//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
619//•print yCtr_pix
620//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
621//
622Function V_RestorePanels()
623
624        String fname=""
625        String detStr=""
626        Variable ii,xCtr,yCtr
627
628// this works if the proper centers are in the file - otherwise, it's a mess   
629// "B" is skipped here, as it should be...
630
631// TODO --?? is this a problem??
632        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
633
634        fname = type
635        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
636                detStr = StringFromList(ii, ksDetectorListNoB, ";")
637                xCtr = V_getDet_beam_center_x(fname,detStr)
638                yCtr = V_getDet_beam_center_y(fname,detStr)
639                V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
640        endfor
641               
642
643        return(0)
644end
645
646// TODO
647// these are "spread out" values for the data panels
648// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
649// viewed a bit easier. Isolation may still be preferred for detailed work.
650//
651// -- this is currently linked to the Vdata panel
652// -- will need to remove the hard-wired values and get the proper values from the data
653// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
654//
655Function V_SpreadOutPanels()
656
657// TODO ?? is this a problem??
658        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
659
660        V_RescaleToBeamCenter(type,"MB",64,78)
661        V_RescaleToBeamCenter(type,"MT",64,-30)
662        V_RescaleToBeamCenter(type,"MR",-30,64)
663        V_RescaleToBeamCenter(type,"ML",78,64)
664        V_RescaleToBeamCenter(type,"FB",64,78)
665        V_RescaleToBeamCenter(type,"FT",64,-30)
666        V_RescaleToBeamCenter(type,"FR",-30,64)
667        V_RescaleToBeamCenter(type,"FL",78,64)
668        return(0)
669end
670
671// function to display the beam center values for all of the detectors
672// opens a separate table with the detector label, and the XY values
673// ? Maybe list the XY pair in pixels and in real distance in the table
674//
675// TODO:
676// -- need a way to use this or another table? as input to put the new/fitted/derived
677//    beam center values into the data folders, and ultimately into the data files on disk
678// -- need read/Write for the XY in pixels, and in real-distance
679// -- where are the temporary waves to be located? root?
680// -- need way to access the Ctr_mm values
681Function V_BCtrTable()
682       
683        // order of the panel names will match the constant string
684        //FT;FB;FL;FR;MT;MB;ML;MR;B;
685        Make/O/T/N=9 panelW
686        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
687        DoWindow/F BCtrTable
688        if(V_flag == 0)
689                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
690        endif
691       
692        Variable ii
693        String detStr,fname
694       
695        fname = "RAW"
696        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
697                detStr = StringFromList(ii, ksDetectorListAll, ";")
698                panelW[ii] = detStr
699                xCtr_pix[ii] = V_getDet_beam_center_x(fname,detStr)
700                yCtr_pix[ii] = V_getDet_beam_center_y(fname,detStr)
701                // TODO
702                // and now the mm values
703                xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
704                yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
705               
706        endfor
707        return(0)
708End
709
710//
711// to write the new beam center values to a file on disk:
712// V_writeDet_beam_center_x(fname,detStr,val)
713//
714// to write to a local WORK folder
715// V_putDet_beam_center_x(fname,detStr,val)
716//
717Function V_BeamCtr_WriteTable()
718
719        DoAlert 0,"this currently only writes pix values locally, not mm, and not to files on disk"
720       
721        String folder
722       
723        Variable ii
724        String detStr,fname
725       
726        Wave xCtr_pix = root:xCtr_pix
727        Wave yCtr_pix = root:yCtr_pix
728        Wave/T panelW = root:PanelW
729       
730        ControlInfo popup_2
731        folder = S_Value
732       
733        fname = folder
734        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
735//              detStr = StringFromList(ii, ksDetectorListAll, ";")
736                detStr = panelW[ii]
737                V_putDet_beam_center_x(fname,detStr,xCtr_pix[ii])
738                V_putDet_beam_center_y(fname,detStr,yCtr_pix[ii])
739               
740                // TODO
741                // and now the mm values
742               
743        endfor
744        return(0)
745       
746End
Note: See TracBrowser for help on using the repository browser.