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

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

LOTS of changes to accommodate the beam center being reported in cm rather than pixels. Required a lot of changes to VCALC (to fill in simulated data), and in the reading and interpreting of data for display, and most importantly, the calculation of q.

There may still be a few residual bugs with this. I am still re-testing with new sample data sets.

File size: 22.2 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={730,400},size={110,20},proc=V_CopyCtrButtonProc,title="Copy Centers"
57        Button button_4,pos={615,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// only copies the center values to the local folder (then read back in by clicking  "Ctr Table")
444//
445// -- will need to recalc mm center AND q-values
446Function V_CopyCtrButtonProc(ba) : ButtonControl
447        STRUCT WMButtonAction &ba
448
449        switch( ba.eventCode )
450                case 2: // mouse up
451                        // click code here
452                        String detStr,fname
453                        Wave coefW=root:coef_PeakPix2D
454                       
455                        ControlInfo popup_0
456                        detStr = S_Value
457                        ControlInfo popup_2
458                        fname = S_Value
459                       
460                        V_putDet_beam_center_x(fname,detStr,coefW[9])
461                        V_putDet_beam_center_y(fname,detStr,coefW[10])
462
463//                      DoAlert 0, "-- will need to recalc mm center AND q-values"
464                       
465                        V_BCtrTable()           //reads the values back in
466                       
467                        break
468                case -1: // control being killed
469                        break
470        endswitch
471
472        return 0
473End
474
475
476
477// TODO
478// -- there is only a single fitting function available, and it's hard-wired
479// -- what values are held during the fitting are hard-wired
480//
481//
482// function to call the fit function (2D)
483//
484Function V_DetFitButtonProc(ba) : ButtonControl
485        STRUCT WMButtonAction &ba
486
487        switch( ba.eventCode )
488                case 2: // mouse up
489                        // click code here
490                       
491                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
492                        Wave coefW=root:coef_PeakPix2D
493                       
494                        FuncFitMD/H="11000111100"/NTHR=0 V_BroadPeak_Pix2D coefW  dispW /D                     
495                       
496                        Wave ws=W_sigma
497                        AppendtoTable/W=PanelFit#T0 ws
498                       
499                        break
500                case -1: // control being killed
501                        break
502        endswitch
503
504        return 0
505End
506
507Function V_DetFitHelpButtonProc(ba) : ButtonControl
508        STRUCT WMButtonAction &ba
509
510        switch( ba.eventCode )
511                case 2: // mouse up
512                        // click code here
513                       
514                        DoAlert 0,"Help file not written yet..."
515                       
516                        break
517                case -1: // control being killed
518                        break
519        endswitch
520
521        return 0
522End
523
524Function V_CtrTableButtonProc(ba) : ButtonControl
525        STRUCT WMButtonAction &ba
526
527        switch( ba.eventCode )
528                case 2: // mouse up
529                        // click code here
530                       
531                        V_BCtrTable()
532                       
533                        break
534                case -1: // control being killed
535                        break
536        endswitch
537
538        return 0
539End
540
541Function V_WriteCtrTableButtonProc(ba) : ButtonControl
542        STRUCT WMButtonAction &ba
543
544        switch( ba.eventCode )
545                case 2: // mouse up
546                        // click code here
547                       
548                        V_BeamCtr_WriteTable()
549                       
550                        break
551                case -1: // control being killed
552                        break
553        endswitch
554
555        return 0
556End
557
558//
559// This sets the scale of the data panels to an approximate detector coordinate system with
560// zero at the center, only for display purposes. It is not exact, and has nothing to do with
561// the calculation of q-values.
562//
563// TODO
564// -- some of this is hard-wired in
565// -- this is still all in terms of pixels, which still may not be what I want
566// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
567//
568Function V_RescaleToBeamCenter(folderStr,detStr,xCtr,yCtr)
569        String folderStr,detStr
570        Variable xCtr,yCtr
571       
572        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
573       
574        Variable nPix = 128
575        Variable nTubes = 48
576       
577        strswitch(detStr)       // string switch
578                case "MT":              // top panels
579                case "FT":
580//                      SetScale/I x -xCtr,npix-xCtr,"",w
581                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
582                        SetScale/I y -yCtr,nTubes-yCtr,"",w
583                        break                                           // exit from switch
584                case "MB":              // bottom panels
585                case "FB":
586//                      SetScale/I x -xCtr,npix-xCtr,"",w
587                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
588                        SetScale/I y -yCtr,nTubes-yCtr,"",w
589                        break                                           // exit from switch
590                case "ML":              // left panels
591                case "FL":
592                        SetScale/I x -xCtr,nTubes-xCtr,"",w
593                        SetScale/I y -yCtr,npix-yCtr,"",w
594                        break                                           // exit from switch
595                case "MR":              // Right panels
596                case "FR":
597                        SetScale/I x -xCtr,nTubes-xCtr,"",w
598                        SetScale/I y -yCtr,npix-yCtr,"",w
599                        break                                           // exit from switch
600                                       
601                default:                                                        // optional default expression executed
602                        Print "Error in V_RescaleToBeamCenter()"
603        endswitch
604       
605        return(0)
606end
607
608// TODO
609// these are "nominal" beam center values in pixels for the default VCALC configuration
610// This function "restores" the data display to the "instrument" conditions where the panels overlap
611// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
612// the view should be symmetric (if the real data is symmetric)
613//
614// -- this is currently linked to the Vdata panel
615// -- will need to remove the hard-wired values and get the proper values from the data
616// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
617// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
618//
619//
620//
621//•print xCtr_pix
622//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
623//•print yCtr_pix
624//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
625//
626Function V_RestorePanels()
627
628        String fname=""
629        String detStr=""
630        Variable ii,xCtr,yCtr
631
632// this works if the proper centers are in the file - otherwise, it's a mess   
633// "B" is skipped here, as it should be...
634
635// TODO --?? is this a problem??
636        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
637
638        fname = type
639        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
640                detStr = StringFromList(ii, ksDetectorListNoB, ";")
641                xCtr = V_getDet_beam_center_x_pix(fname,detStr)
642                yCtr = V_getDet_beam_center_y_pix(fname,detStr)
643                V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
644        endfor
645               
646
647        return(0)
648end
649
650// TODO
651// these are "spread out" values for the data panels
652// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
653// viewed a bit easier. Isolation may still be preferred for detailed work.
654//
655// -- this is currently linked to the Vdata panel
656// -- will need to remove the hard-wired values and get the proper values from the data
657// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
658//
659Function V_SpreadOutPanels()
660
661// TODO ?? is this a problem??
662        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
663
664        V_RescaleToBeamCenter(type,"MB",64,78)
665        V_RescaleToBeamCenter(type,"MT",64,-30)
666        V_RescaleToBeamCenter(type,"MR",-30,64)
667        V_RescaleToBeamCenter(type,"ML",78,64)
668        V_RescaleToBeamCenter(type,"FB",64,78)
669        V_RescaleToBeamCenter(type,"FT",64,-30)
670        V_RescaleToBeamCenter(type,"FR",-30,64)
671        V_RescaleToBeamCenter(type,"FL",78,64)
672        return(0)
673end
674
675// function to display the beam center values for all of the detectors
676// opens a separate table with the detector label, and the XY values
677// ? Maybe list the XY pair in pixels and in real distance in the table
678//
679// TODO:
680// -- need a way to use this or another table? as input to put the new/fitted/derived
681//    beam center values into the data folders, and ultimately into the data files on disk
682// -- need read/Write for the XY in pixels, and in real-distance
683// -- where are the temporary waves to be located? root?
684// -- need way to access the Ctr_mm values
685Function V_BCtrTable()
686       
687        // order of the panel names will match the constant string
688        //FT;FB;FL;FR;MT;MB;ML;MR;B;
689        Make/O/T/N=9 panelW
690        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
691        DoWindow/F BCtrTable
692        if(V_flag == 0)
693                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
694        endif
695       
696        Variable ii
697        String detStr,fname
698       
699        fname = "RAW"
700        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
701                detStr = StringFromList(ii, ksDetectorListAll, ";")
702                panelW[ii] = detStr
703                xCtr_pix[ii] = V_getDet_beam_center_x_pix(fname,detStr)
704                yCtr_pix[ii] = V_getDet_beam_center_y_pix(fname,detStr)
705                // TODO
706                // and now the mm values
707                xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
708                yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
709               
710        endfor
711        return(0)
712End
713
714//
715// to write the new beam center values to a file on disk:
716// V_writeDet_beam_center_x(fname,detStr,val)
717//
718// to write to a local WORK folder
719// V_putDet_beam_center_x(fname,detStr,val)
720//
721Function V_BeamCtr_WriteTable()
722
723        Variable runNumber
724        Prompt runNumber, "enter the run number:"
725        DoPrompt "Pick file to write to",runNumber
726        If(V_flag==1)
727                return(0)
728        endif   
729       
730        String folder
731       
732        Variable ii
733        String detStr,fname
734       
735        Wave xCtr_pix = root:xCtr_pix
736        Wave yCtr_pix = root:yCtr_pix
737        Wave/T panelW = root:PanelW
738       
739
740        fname = V_FindFileFromRunNumber(runNumber)
741
742        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
743//              detStr = StringFromList(ii, ksDetectorListAll, ";")
744                detStr = panelW[ii]
745                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
746                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])
747               
748                // TODO
749                // and now the mm values
750               
751        endfor
752        return(0)
753       
754End
Note: See TracBrowser for help on using the repository browser.