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

Last change on this file since 1101 was 1101, checked in by srkline, 4 years ago

bug fixes for the back detector dimensions and beam center (pixels)

File size: 26.5 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//
564// TODO
565// -- some of this is hard-wired in
566// -- this is still all in terms of pixels, which still may not be what I want
567// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
568//
569Function V_RescaleToBeamCenter(folderStr,detStr,xCtr,yCtr)
570        String folderStr,detStr
571        Variable xCtr,yCtr
572       
573        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
574       
575        Variable nPix = 128
576        Variable nTubes = 48
577       
578        strswitch(detStr)       // string switch
579                case "MT":              // top panels
580                case "FT":
581//                      SetScale/I x -xCtr,npix-xCtr,"",w
582                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
583                        SetScale/I y -yCtr,nTubes-yCtr,"",w
584                        break                                           // exit from switch
585                case "MB":              // bottom panels
586                case "FB":
587//                      SetScale/I x -xCtr,npix-xCtr,"",w
588                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
589                        SetScale/I y -yCtr,nTubes-yCtr,"",w
590                        break                                           // exit from switch
591                case "ML":              // left panels
592                case "FL":
593                        SetScale/I x -xCtr,nTubes-xCtr,"",w
594                        SetScale/I y -yCtr,npix-yCtr,"",w
595                        break                                           // exit from switch
596                case "MR":              // Right panels
597                case "FR":
598                        SetScale/I x -xCtr,nTubes-xCtr,"",w
599                        SetScale/I y -yCtr,npix-yCtr,"",w
600                        break                                           // exit from switch
601                                       
602                default:                                                        // optional default expression executed
603                        Print "Error in V_RescaleToBeamCenter()"
604        endswitch
605       
606        return(0)
607end
608
609// This sets the scale of the data panels to an approximate detector coordinate system with
610// zero at the center, only for display purposes. It is not exact, and has nothing to do with
611// the calculation of q-values.
612//
613// ****For the panel display, the scaling MUST be in PIXELS for the readout and calculations to be correct.
614// the read out needs pixels, and the calculations use the pixels as the indexes for the real-space (mm) values
615//
616//  Since I'll only know the beam center in mm, and I'll need the relative panel positions to convert to pixels,
617// can I display the panels in their pixel locations relative to each other, based on a zero center and
618// the panel offset values?
619//
620//
621// TODO
622// -- some of this is hard-wired in
623// -- this is still all in terms of pixels, which still may not be what I want
624// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
625//
626// Nominal center is 0,0
627//
628Function V_RescaleToNominalCenter(folderStr,detStr,xCtr,yCtr)
629        String folderStr,detStr
630        Variable xCtr,yCtr
631       
632//      xCtr = 0
633//      yCtr = 0
634       
635        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
636       
637        Variable nPix = 128
638        Variable nTubes = 48
639        Variable offset = 0
640        Variable pixSizeX,pixSizeY
641       
642        strswitch(detStr)       // string switch
643                case "MT":              // top panels
644                case "FT":
645//                      SetScale/I x -xCtr,npix-xCtr,"",w
646                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
647                        pixSizeY = 0.84
648                        yCtr = -(offset/pixSizeY)
649                       
650                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
651                        SetScale/I y -yCtr,nTubes-yCtr,"",w
652                        break                                           // exit from switch
653                case "MB":              // bottom panels
654                case "FB":
655//                      SetScale/I x -xCtr,npix-xCtr,"",w
656
657                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
658                        pixSizeY = 0.84
659                        yCtr = nTubes-(offset/pixSizeY)
660                       
661                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
662                        SetScale/I y -yCtr,nTubes-yCtr,"",w
663                        break                                           // exit from switch
664                       
665                case "ML":              // left panels
666                case "FL":
667                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
668                        pixSizeX = 0.84
669                        xCtr = nTubes-(offset/pixSizeX)
670                       
671                        SetScale/I x -xCtr,nTubes-xCtr,"",w
672                        SetScale/I y -yCtr,npix-yCtr,"",w
673                        break                                           // exit from switch
674                case "MR":              // Right panels
675                case "FR":
676                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
677                        pixSizeX = 0.84
678                        xCtr = -(offset/pixSizeX)
679               
680                        SetScale/I x -xCtr,nTubes-xCtr,"",w
681                        SetScale/I y -yCtr,npix-yCtr,"",w
682                        break                                           // exit from switch
683                                       
684                default:                                                        // optional default expression executed
685                        Print "Error in V_RescaleToBeamCenter()"
686        endswitch
687       
688        return(0)
689end
690
691
692// TODO
693// these are "nominal" beam center values in pixels for the default VCALC configuration
694// This function "restores" the data display to the "instrument" conditions where the panels overlap
695// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
696// the view should be symmetric (if the real data is symmetric)
697//
698// -- this is currently linked to the Vdata panel
699// -- will need to remove the hard-wired values and get the proper values from the data
700// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
701// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
702//
703//
704//
705//•print xCtr_pix
706//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
707//•print yCtr_pix
708//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
709//
710Function V_RestorePanels()
711
712        String fname=""
713        String detStr=""
714        Variable ii,xCtr,yCtr
715
716// this works if the proper centers are in the file - otherwise, it's a mess   
717// "B" is skipped here, as it should be...
718
719// TODO --?? is this a problem??
720        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
721
722        fname = type
723        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
724                detStr = StringFromList(ii, ksDetectorListNoB, ";")
725                xCtr = V_getDet_beam_center_x_pix(fname,detStr)
726                yCtr = V_getDet_beam_center_y_pix(fname,detStr)
727//              V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
728                V_RescaleToNominalCenter(type,detStr,xCtr,yCtr)         // xCtr or yCtr value in direction of offset are dummy values here
729        endfor
730               
731
732        return(0)
733end
734
735// TODO
736// these are "spread out" values for the data panels
737// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
738// viewed a bit easier. Isolation may still be preferred for detailed work.
739//
740// -- this is currently linked to the Vdata panel
741// -- will need to remove the hard-wired values and get the proper values from the data
742// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
743//
744Function V_SpreadOutPanels()
745
746// TODO ?? is this a problem??
747        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
748
749        V_RescaleToBeamCenter(type,"MB",64,78)
750        V_RescaleToBeamCenter(type,"MT",64,-30)
751        V_RescaleToBeamCenter(type,"MR",-30,64)
752        V_RescaleToBeamCenter(type,"ML",78,64)
753        V_RescaleToBeamCenter(type,"FB",64,78)
754        V_RescaleToBeamCenter(type,"FT",64,-30)
755        V_RescaleToBeamCenter(type,"FR",-30,64)
756        V_RescaleToBeamCenter(type,"FL",78,64)
757        return(0)
758end
759
760// function to display the beam center values for all of the detectors
761// opens a separate table with the detector label, and the XY values
762// ? Maybe list the XY pair in pixels and in real distance in the table
763//
764// TODO:
765// -- need a way to use this or another table? as input to put the new/fitted/derived
766//    beam center values into the data folders, and ultimately into the data files on disk
767// -- need read/Write for the XY in pixels, and in real-distance
768// -- where are the temporary waves to be located? root?
769// -- need way to access the Ctr_mm values
770Function V_BCtrTable()
771       
772        // order of the panel names will match the constant string
773        //FT;FB;FL;FR;MT;MB;ML;MR;B;
774        Make/O/T/N=9 panelW
775        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
776        DoWindow/F BCtrTable
777        if(V_flag == 0)
778                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_mm,yCtr_mm
779        endif
780       
781        Variable ii
782        String detStr,fname
783       
784        fname = "RAW"
785        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
786                detStr = StringFromList(ii, ksDetectorListAll, ";")
787                panelW[ii] = detStr
788                xCtr_pix[ii] = V_getDet_beam_center_x_pix(fname,detStr)
789                yCtr_pix[ii] = V_getDet_beam_center_y_pix(fname,detStr)
790                // TODO
791                // and now the mm values
792                xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
793                yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
794               
795        endfor
796        return(0)
797End
798
799//
800// to write the new beam center values to a file on disk:
801// V_writeDet_beam_center_x(fname,detStr,val)
802//
803// to write to a local WORK folder
804// V_putDet_beam_center_x(fname,detStr,val)
805//
806Function V_BeamCtr_WriteTable()
807
808        Variable runNumber
809        Prompt runNumber, "enter the run number:"
810        DoPrompt "Pick file to write to",runNumber
811        If(V_flag==1)
812                return(0)
813        endif   
814       
815        String folder
816       
817        Variable ii
818        String detStr,fname
819       
820        Wave xCtr_pix = root:xCtr_pix
821        Wave yCtr_pix = root:yCtr_pix
822        Wave/T panelW = root:PanelW
823       
824
825        fname = V_FindFileFromRunNumber(runNumber)
826
827        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
828//              detStr = StringFromList(ii, ksDetectorListAll, ";")
829                detStr = panelW[ii]
830                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
831                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])
832               
833                // TODO
834                // and now the mm values
835               
836        endfor
837        return(0)
838       
839End
840
841
842
843
844//////////////////
845//
846// Simple utility to calculate beam centers [cm] based on a single measurement
847//  and empirical relations between the panel zero positions
848//
849// Empirical relations are derived from beam center measurements using 6A data and WB data (9/10/17)
850// only measurements on L, R, and x-coordinate of B were used. T panel cannot be translated down far enough
851// to reach the direct beam.
852//
853// Start with the (default) case of a beam center measured on R (MR or FR)
854//
855// Empirical values are averaged as noted
856//
857
858Proc V_DeriveBeamCenters()
859
860        Make/O/T panelWave = {"FL","FR","FT","FB","ML","MR","MT","MB","B"}
861        Make/O/D/N=9 newXCtr_cm,newYCtr_cm
862       
863        Edit panelWave,newXCtr_cm,newYCtr_cm
864       
865        DoAlert 0, "enter the measured beam center reference for Front and Middle panels"
866        V_fDeriveBeamCenters()
867       
868End
869
870
871Proc V_fDeriveBeamCenters(xFR,yFR,xMR,yMR)
872        Variable xFR,yFR,xMR,yMR
873       
874        // start with the front
875        // FR
876        newXCtr_cm[1] = xFR
877        newYCtr_cm[1] = yFR
878        // FL
879        newXCtr_cm[0] = xFR - (0.03 + 0.03)/2
880        newYCtr_cm[0] = yFR + (0.34 + 0.32)/2
881        // FB
882        newXCtr_cm[3] = xFR - (2.02 + 2.06)/2
883        newYCtr_cm[3] = yFR - (0.12 + 0.19)/2           // (-) is correct here
884        // FT (duplicate FB)
885        newXCtr_cm[2] = newXCtr_cm[3]
886        newYCtr_cm[2] = newYCtr_cm[3]
887       
888        // MR
889        newXCtr_cm[5] = xMR
890        newYCtr_cm[5] = yMR
891        // ML
892        newXCtr_cm[4] = xMR - (0.06 + 0.05)/2
893        newYCtr_cm[4] = yMR + (0.14 + 0.01)/2
894        // MB
895        newXCtr_cm[7] = xMR - (0.51 + 0.62)/2
896        newYCtr_cm[7] = yMR + (0.79 + 0.74)/2
897        // MT (duplicate MB)
898        newXCtr_cm[6] = newXCtr_cm[7]
899        newYCtr_cm[6] = newYCtr_cm[7]   
900       
901       
902        // default value for B
903        newXCtr_cm[8] = 0
904        newYCtr_cm[8] = 0
905
906               
907        return
908End
909
Note: See TracBrowser for help on using the repository browser.