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

Last change on this file since 1176 was 1176, checked in by srkline, 3 years ago

corrected how the raw data panels are displayed in terms of pixels. only a cosmetic fix, especially in the case where the graphite is used and the beam axis is translated. All underlying q-calculations are unchanged, as these use the real space distance which is correct.

File size: 30.3 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;BroadPeak_constrained;PowerLaw;\""
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",disable=2
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",disable=2
59
60
61        Button button_6,pos={615,470},size={110,20},proc=V_MaskBeforeFitButtonProc,title="Mask Panel"
62        Button button_7,pos={730,470},size={110,20},proc=V_ConvertFitPix2cmButtonProc,title="Convert Pix2Cm"
63        Button button_8,pos={615,500},size={110,20},proc=V_GizmoFitButtonProc,title="Gizmo"
64
65
66        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
67
68        duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
69        SetScale/P x 0,1, curDispPanel
70        SetScale/P y 0,1, curDispPanel
71
72        SetDataFolder root:
73       
74        // draw the correct images
75        V_DrawDetPanel("FL")
76
77       
78////draw the detector panel
79//      Display/W=(20,80,200,600)/HOST=#
80//      AppendImage curDispPanel
81//      ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
82////    ModifyGraph height={Aspect,2.67}               
83//      Label left "Y pixels"
84//      Label bottom "X pixels"
85//      RenameWindow #,DetData
86//      SetActiveSubwindow ##   
87//     
88////draw the model calculation
89//      Display/W=(220,80,400,600)/HOST=#
90//      AppendImage PeakPix2D_mat
91//      ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
92////    ModifyGraph height={Aspect,2.67}               
93////    ModifyGraph width={Aspect,0.375}               
94//      Label left "Y pixels"
95//      Label bottom "X pixels"
96//      RenameWindow #,ModelData
97//      SetActiveSubwindow ##           
98
99
100
101
102// edit the fit coefficients   
103        Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
104        ModifyTable width(Point)=0
105        ModifyTable width(parameters_PeakPix2D)=120
106        ModifyTable width(coef_PeakPix2D)=100
107        RenameWindow #,T0
108        SetActiveSubwindow ##
109
110       
111EndMacro
112
113
114//
115// function to choose which detector panel to display, and then to actually display it
116//
117Function V_SetDetPanelPopMenuProc(pa) : PopupMenuControl
118        STRUCT WMPopupAction &pa
119
120        switch( pa.eventCode )
121                case 2: // mouse up
122                        Variable popNum = pa.popNum
123                        String popStr = pa.popStr
124                                               
125                        // remove the old image (it may not be the right shape)
126                        // -- but make sure it exists first...
127                        String childList = ChildWindowList("PanelFit")
128                        Variable flag
129                       
130                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
131                        if(flag != -1)
132                                KillWindow PanelFit#DetData
133                        endif
134                       
135                        flag = WhichListItem("ModelData", ChildList)
136                        if(flag != -1)
137                                KillWindow PanelFit#ModelData
138                        endif
139       
140                        // draw the correct images
141                        V_DrawDetPanel(popStr)
142                       
143                        break
144                case -1: // control being killed
145                        break
146        endswitch
147
148        return 0
149End
150
151
152// TODO - currently is hard-wired for the simulation path!
153//     need to make it more generic, especially for RAW data
154//
155// -- need to adjust the size of the image subwindows to keep the model
156//    calculation from spilling over onto the table (maybe just move the table)
157// -- need to do something for panel "B". currently ignored
158// -- currently the pixel sizes for "real" data is incorrect in the file
159//     and this is why the plots are incorrectly sized
160//
161// draw the selected panel and the model calculation, adjusting for the
162// orientation of the panel and the number of pixels, and pixel sizes
163Function V_DrawDetPanel(str)
164        String str
165       
166        // from the selection, find the path to the data
167
168
169        Variable xDim,yDim
170        Variable left,top,right,bottom
171        Variable height, width
172        Variable left2,top2,right2,bottom2
173        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
174
175
176        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
177        Wave cw = root:coef_PeakPix2D
178
179        Wave xwave_PeakPix2D=root:xwave_PeakPix2D
180        Wave ywave_PeakPix2D=root:ywave_PeakPix2D
181        Wave zwave_PeakPix2D=root:zwave_PeakPix2D
182
183        //plot it in the subwindow with the proper aspect and positioning
184        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
185        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
186       
187       
188        // using two switches -- one to set the panel-specific dimensions
189        // and the other to set the "common" values, some of which are based on the panel dimensions
190
191// set the source of the data. not always VCALC anymore
192        String folder
193        ControlInfo popup_2
194        folder = S_Value
195
196// error checking -- if the VCALC folder is the target & does not exist, exit now
197        if( cmpstr(folder,"VCALC") == 0 && DataFolderExists("root:Packages:NIST:VSANS:VCALC") == 0)
198                return(0)
199        endif
200
201// error checking -- if the RAW folder is the target & does not exist, exit now
202        if( cmpstr(folder,"RAW") == 0 && DataFolderExists("root:Packages:NIST:VSANS:RAW:entry") == 0)
203                return(0)
204        endif
205
206// error checking -- if the SAM folder is the target & does not exist, exit now
207        if( cmpstr(folder,"SAM") == 0 && DataFolderExists("root:Packages:NIST:VSANS:SAM:entry") == 0)
208                return(0)
209        endif
210               
211        // TODO -- fix all of this mess
212        if(cmpstr(folder,"VCALC") == 0)
213                // panel-specific values
214                Variable VC_nPix_X = VCALC_get_nPix_X(str)
215                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
216                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
217                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
218
219       
220        // if VCALC declare this way   
221                wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
222                nPix_X = VC_nPix_X
223                nPix_Y = VC_nPix_Y
224                pixSize_X = VC_pixSize_X
225                pixSize_Y = VC_pixSize_Y
226       
227        else
228        // TODO: if real data, need new declaration w/ data as the wave name
229                wave newW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
230
231                nPix_X = V_getDet_pixel_num_x(folder,str)
232                nPix_Y = V_getDet_pixel_num_Y(folder,str)
233                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
234                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
235        endif
236       
237
238        Variable scale = 5
239       
240        // common values (panel position, etc)
241        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
242        strswitch(str)
243                case "FL":
244                case "FR":
245                case "ML":
246                case "MR":
247                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
248                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
249                       
250                        left = 20
251                        top = 80
252                        right = left+width
253                        bottom = top+height
254                       
255                        left2 = right + 20
256                        right2 = left2 + width
257                        top2 = top
258                        bottom2 = bottom
259                       
260                        break                   
261                case "FT":
262                case "FB":
263                case "MT":
264                case "MB":
265                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
266                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
267                                               
268                        left = 20
269                        top = 80
270                        right = left+width
271                        bottom = top+height
272                       
273                        left2 = left
274                        right2 = right
275                        top2 = top + height + 20
276                        bottom2 = bottom + height + 20
277                       
278                        break
279                case "B":
280                        return(0)               //just exit
281                        break                                           
282                default:
283                        return(0)               //just exit
284        endswitch
285
286        // set from the detector-specific strswitch
287        cw[7] = pixSize_X*10
288        cw[8] = pixSize_Y*10           
289
290        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
291        // generate the new panel display
292        duplicate/O newW curDispPanel
293        SetScale/P x 0,1, curDispPanel
294        SetScale/P y 0,1, curDispPanel
295       
296        //draw the detector panel
297        Display/W=(left,top,right,bottom)/HOST=#
298        AppendImage curDispPanel
299        ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
300        Label left "Y pixels"
301        Label bottom "X pixels"
302        RenameWindow #,DetData
303        SetActiveSubwindow ##   
304       
305        SetDataFolder root:
306       
307       
308               
309        // re-dimension the model calculation to be the proper dimensions       
310        Redimension/N=(nPix_X*nPix_Y) xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D 
311        V_FillPixTriplet(xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D,nPix_X,nPix_Y)
312        Make/O/D/N=(nPix_X,nPix_Y) PeakPix2D_mat                // use the point scaling of the matrix (=pixels)
313
314        Duplicate/O $"PeakPix2D_mat",$"PeakPix2D_lin"           //keep a linear-scaled version of the data
315
316        //draw the model calculation
317        Display/W=(left2,top2,right2,bottom2)/HOST=#
318        AppendImage PeakPix2D_mat
319        ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
320        Label left "Y pixels"
321        Label bottom "X pixels"
322        RenameWindow #,ModelData
323        SetActiveSubwindow ##   
324               
325        DoUpdate
326       
327        return(0)
328End
329
330
331
332
333// TODO:
334// -- allow other model functions as needed.
335//
336// Function to plot the specified 2D model for the detector
337//
338Function V_DetModelPopMenuProc(pa) : PopupMenuControl
339        STRUCT WMPopupAction &pa
340
341        switch( pa.eventCode )
342                case 2: // mouse up
343                        Variable popNum = pa.popNum
344                        String popStr = pa.popStr
345                       
346                        Execute "V_PlotBroadPeak_Pix2D()"
347                       
348                        break
349                case -1: // control being killed
350                        break
351        endswitch
352
353        return 0
354End
355
356
357//
358// TODO - make a better guess (how?)
359// TODO - make the guess appropriate for the fitted model
360//
361Function V_DetFitGuessButtonProc(ba) : ButtonControl
362        STRUCT WMButtonAction &ba
363
364        switch( ba.eventCode )
365                case 2: // mouse up
366                        // click code here
367                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
368                        Wave coefW=root:coef_PeakPix2D
369                       
370                        WaveStats/Q dispW
371                        coefW[2] = V_max                //approx peak height
372                        coefW[6] = V_avg                //approx background
373                        coefW[0] = 0                    // remove the porod scale
374                        coefW[3] = 0.9          //peak width, first guess
375                       
376                        break
377                case -1: // control being killed
378                        break
379        endswitch
380
381        return 0
382End
383
384
385Function V_GizmoFitButtonProc(ba) : ButtonControl
386        STRUCT WMButtonAction &ba
387
388        switch( ba.eventCode )
389                case 2: // mouse up
390                        // click code here
391
392                        Execute "V_Gizmo_PeakFit()"
393                       
394                        break
395                case -1: // control being killed
396                        break
397        endswitch
398
399        return 0
400End
401
402
403Function V_MaskBeforeFitButtonProc(ba) : ButtonControl
404        STRUCT WMButtonAction &ba
405
406        switch( ba.eventCode )
407                case 2: // mouse up
408                        // click code here
409
410                        Execute "V_NaN_BeforeFit()"
411                       
412                        break
413                case -1: // control being killed
414                        break
415        endswitch
416
417        return 0
418End
419
420
421// TODO - read from the popup for the panel string
422// TODO - read the appropriate coeffients for xy, depending on the model selected
423//
424Function V_ConvertFitPix2cmButtonProc(ba) : ButtonControl
425        STRUCT WMButtonAction &ba
426
427        switch( ba.eventCode )
428                case 2: // mouse up
429                        // click code here
430
431                        String detStr
432                        Variable xPix,yPix
433//                      Prompt detStr, "enter the panel string"
434//                      Prompt xPix, "enter the x pixel center"
435//                      Prompt yPix, "enter the y pixel center"
436//                      DoPrompt "enter the values",detStr,xPix,yPix
437
438                        ControlInfo popup_0
439                        detStr = S_Value
440                        Wave coefW=root:coef_PeakPix2D
441       
442                        xPix = coefW[9]
443                        yPix = coefW[10]
444                       
445                        V_Convert_FittedPix_2_cm(detStr,xPix,yPix)
446                       
447                        break
448                case -1: // control being killed
449                        break
450        endswitch
451
452        return 0
453End
454
455
456//
457// TODO -- currently hard-wired for coefficients from the only fit function
458//
459// only copies the center values to the local folder (then read back in by clicking  "Ctr Table")
460//
461// -- will need to recalc mm center AND q-values
462Function V_CopyCtrButtonProc(ba) : ButtonControl
463        STRUCT WMButtonAction &ba
464
465        switch( ba.eventCode )
466                case 2: // mouse up
467                        // click code here
468                        String detStr,fname
469                        Wave coefW=root:coef_PeakPix2D
470                       
471                        ControlInfo popup_0
472                        detStr = S_Value
473                        ControlInfo popup_2
474                        fname = S_Value
475                       
476                        V_putDet_beam_center_x(fname,detStr,coefW[9])
477                        V_putDet_beam_center_y(fname,detStr,coefW[10])
478
479//                      DoAlert 0, "-- will need to recalc mm center AND q-values"
480                       
481                        V_BCtrTable()           //reads the values back in
482                       
483                        break
484                case -1: // control being killed
485                        break
486        endswitch
487
488        return 0
489End
490
491
492
493// TODO
494// -- there is only a single fitting function available, and it's hard-wired
495// -- what values are held during the fitting are hard-wired
496//
497//
498// function to call the fit function (2D)
499//
500Function V_DetFitButtonProc(ba) : ButtonControl
501        STRUCT WMButtonAction &ba
502
503        switch( ba.eventCode )
504                case 2: // mouse up
505                        // click code here
506                       
507                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
508                        Wave coefW=root:coef_PeakPix2D
509                       
510                        FuncFitMD/H="11000101100"/NTHR=0/M=2 V_BroadPeak_Pix2D coefW  dispW /D                 
511                       
512                        Wave ws=W_sigma
513                        AppendtoTable/W=PanelFit#T0 ws
514                       
515                        break
516                case -1: // control being killed
517                        break
518        endswitch
519
520        return 0
521End
522
523Function V_DetFitHelpButtonProc(ba) : ButtonControl
524        STRUCT WMButtonAction &ba
525
526        switch( ba.eventCode )
527                case 2: // mouse up
528                        // click code here
529                       
530                        DoAlert 0,"Help file not written yet..."
531                       
532                        break
533                case -1: // control being killed
534                        break
535        endswitch
536
537        return 0
538End
539
540Function V_CtrTableButtonProc(ba) : ButtonControl
541        STRUCT WMButtonAction &ba
542
543        switch( ba.eventCode )
544                case 2: // mouse up
545                        // click code here
546                       
547                        V_BCtrTable()
548                       
549                        break
550                case -1: // control being killed
551                        break
552        endswitch
553
554        return 0
555End
556
557Function V_WriteCtrTableButtonProc(ba) : ButtonControl
558        STRUCT WMButtonAction &ba
559
560        switch( ba.eventCode )
561                case 2: // mouse up
562                        // click code here
563                       
564                        V_BeamCtr_WriteTable()
565                       
566                        break
567                case -1: // control being killed
568                        break
569        endswitch
570
571        return 0
572End
573
574//
575// This sets the scale of the data panels to an approximate detector coordinate system with
576// zero at the center, only for display purposes. It is not exact, and has nothing to do with
577// the calculation of q-values.
578//
579//
580// TODO
581// -- some of this is hard-wired in
582// -- this is still all in terms of pixels, which still may not be what I want
583// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
584//
585Function V_RescaleToBeamCenter(folderStr,detStr,xCtr,yCtr)
586        String folderStr,detStr
587        Variable xCtr,yCtr
588       
589        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
590       
591        Variable nPix = 128
592        Variable nTubes = 48
593       
594        strswitch(detStr)       // string switch
595                case "MT":              // top panels
596                case "FT":
597//                      SetScale/I x -xCtr,npix-xCtr,"",w
598                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
599                        SetScale/I y -yCtr,nTubes-yCtr,"",w
600                        break                                           // exit from switch
601                case "MB":              // bottom panels
602                case "FB":
603//                      SetScale/I x -xCtr,npix-xCtr,"",w
604                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
605                        SetScale/I y -yCtr,nTubes-yCtr,"",w
606                        break                                           // exit from switch
607                case "ML":              // left panels
608                case "FL":
609                        SetScale/I x -xCtr,nTubes-xCtr,"",w
610                        SetScale/I y -yCtr,npix-yCtr,"",w
611                        break                                           // exit from switch
612                case "MR":              // Right panels
613                case "FR":
614                        SetScale/I x -xCtr,nTubes-xCtr,"",w
615                        SetScale/I y -yCtr,npix-yCtr,"",w
616                        break                                           // exit from switch
617                                       
618                default:                                                        // optional default expression executed
619                        Print "Error in V_RescaleToBeamCenter()"
620        endswitch
621       
622        return(0)
623end
624
625// This sets the scale of the data panels to an approximate detector coordinate system with
626// zero at the center, only for display purposes. It is not exact, and has nothing to do with
627// the calculation of q-values.
628//
629// ****For the panel display, the scaling MUST be in PIXELS for the readout and calculations to be correct.
630// the read out needs pixels, and the calculations use the pixels as the indexes for the real-space (mm) values
631//
632//  Since I'll only know the beam center in mm, and I'll need the relative panel positions to convert to pixels,
633// can I display the panels in their pixel locations relative to each other, based on a zero center and
634// the panel offset values?
635//
636//
637// TODO
638// -- some of this is hard-wired in
639// -- this is still all in terms of pixels, which still may not be what I want
640// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
641//
642Function V_RescaleToNominalCenter(folderStr,detStr,xCtr,yCtr)
643        String folderStr,detStr
644        Variable xCtr,yCtr
645
646       
647        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
648       
649        Variable nPix = 128
650        Variable nTubes = 48
651        Variable offset = 0
652        Variable pixSizeX,pixSizeY,yOff,xOff
653       
654        strswitch(detStr)       // string switch
655                case "MT":              // top panels
656                case "FT":
657//                      offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
658//                      pixSizeY = 0.84
659//                      yOff = -(offset/pixSizeY)               // offset is already taken into account with the beam center
660                       
661                        SetScale/I x -xCtr/2,(nPix-xCtr)/2,"",w         // fake 4mm by compressing the scale
662                        SetScale/I y -yCtr,nTubes-yCtr,"",w
663                        break                                           // exit from switch
664                case "MB":              // bottom panels
665                case "FB":
666//                      offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
667//                      pixSizeY = 0.84
668//                      yOff = nTubes-(offset/pixSizeY)
669                       
670                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
671                        SetScale/I y -yCtr,nTubes-yCtr,"",w
672                        break                                           // exit from switch
673                       
674                case "ML":              // left panels
675                case "FL":
676//                      offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
677//                      pixSizeX = 0.84
678//                      xOff = nTubes-(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                case "MR":              // Right panels
684                case "FR":
685//                      offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
686//                      pixSizeX = 0.84
687//                      xOff = -(offset/pixSizeX)
688               
689                        SetScale/I x -xCtr,nTubes-xCtr,"",w
690                        SetScale/I y -yCtr,npix-yCtr,"",w
691                        break                                           // exit from switch
692                                       
693                default:                                                        // optional default expression executed
694                        Print "Error in V_RescaleToNominalCenter()"
695        endswitch
696       
697        return(0)
698end
699
700
701// TODO
702// these are "nominal" beam center values in pixels for the default VCALC configuration
703// This function "restores" the data display to the "instrument" conditions where the panels overlap
704// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
705// the view should be symmetric (if the real data is symmetric)
706//
707// -- this is currently linked to the Vdata panel
708// -- will need to remove the hard-wired values and get the proper values from the data
709// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
710// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
711//
712//
713//
714//•print xCtr_pix
715//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
716//•print yCtr_pix
717//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
718//
719Function V_RestorePanels()
720
721        String fname=""
722        String detStr=""
723        Variable ii,xCtr,yCtr
724
725// this works if the proper centers are in the file - otherwise, it's a mess   
726// "B" is skipped here, as it should be...
727
728// TODO --?? is this a problem??
729        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
730
731        fname = type
732        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
733                detStr = StringFromList(ii, ksDetectorListNoB, ";")
734                xCtr = V_getDet_beam_center_x_pix(fname,detStr)
735                yCtr = V_getDet_beam_center_y_pix(fname,detStr)
736//              V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
737                V_RescaleToNominalCenter(type,detStr,xCtr,yCtr)         // xCtr or yCtr value in direction of offset are dummy values here
738        endfor
739               
740
741        return(0)
742end
743
744// TODO
745// these are "spread out" values for the data panels
746// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
747// viewed a bit easier. Isolation may still be preferred for detailed work.
748//
749// -- this is currently linked to the Vdata panel
750// -- will need to remove the hard-wired values and get the proper values from the data
751// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
752//
753Function V_SpreadOutPanels()
754
755// TODO ?? is this a problem??
756        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
757
758        V_RescaleToBeamCenter(type,"MB",64,78)
759        V_RescaleToBeamCenter(type,"MT",64,-30)
760        V_RescaleToBeamCenter(type,"MR",-30,64)
761        V_RescaleToBeamCenter(type,"ML",78,64)
762        V_RescaleToBeamCenter(type,"FB",64,78)
763        V_RescaleToBeamCenter(type,"FT",64,-30)
764        V_RescaleToBeamCenter(type,"FR",-30,64)
765        V_RescaleToBeamCenter(type,"FL",78,64)
766        return(0)
767end
768
769// function to display the beam center values for all of the detectors
770// opens a separate table with the detector label, and the XY values
771// ? Maybe list the XY pair in pixels and in real distance in the table
772//
773// TODO:
774// -- need a way to use this or another table? as input to put the new/fitted/derived
775//    beam center values into the data folders, and ultimately into the data files on disk
776// -- need read/Write for the XY in pixels, and in real-distance
777// -- where are the temporary waves to be located? root?
778// -- need way to access the Ctr_mm values
779Function V_BCtrTable()
780       
781        // order of the panel names will match the constant string
782        //FT;FB;FL;FR;MT;MB;ML;MR;B;
783        Make/O/T/N=9 panelW
784        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
785        DoWindow/F BCtrTable
786        if(V_flag == 0)
787                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
788        endif
789       
790        Variable ii
791        String detStr,fname
792       
793        fname = "RAW"
794        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
795                detStr = StringFromList(ii, ksDetectorListAll, ";")
796                panelW[ii] = detStr
797
798        endfor
799       
800//              xCtr_pix[ii] = V_getDet_beam_center_x_pix(fname,detStr)
801//              yCtr_pix[ii] = V_getDet_beam_center_y_pix(fname,detStr)
802//              // TODO
803//              // and now the mm values
804//              xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
805//              yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
806        return(0)
807End
808
809//
810// to write the new beam center values to a file on disk:
811// V_writeDet_beam_center_x(fname,detStr,val)
812//
813// to write to a local WORK folder
814// V_putDet_beam_center_x(fname,detStr,val)
815//
816Function V_BeamCtr_WriteTable()
817
818        Variable runNumber
819        Prompt runNumber, "enter the run number:"
820        DoPrompt "Pick file to write to",runNumber
821        If(V_flag==1)
822                return(0)
823        endif   
824       
825        String folder
826       
827        Variable ii
828        String detStr,fname
829       
830        Wave xCtr_pix = root:xCtr_pix
831        Wave yCtr_pix = root:yCtr_pix
832        Wave/T panelW = root:PanelW
833       
834
835        fname = V_FindFileFromRunNumber(runNumber)
836
837        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
838//              detStr = StringFromList(ii, ksDetectorListAll, ";")
839                detStr = panelW[ii]
840                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
841                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])
842               
843                // TODO
844                // and now the mm values
845               
846        endfor
847        return(0)
848       
849End
850
851
852
853
854//////////////////
855//
856// Simple utility to calculate beam centers [cm] based on a single measurement
857//  and empirical relations between the panel zero positions
858//
859// Empirical relations are derived from beam center measurements using 6A data and WB data (9/10/17)
860// only measurements on L, R, and x-coordinate of B were used. T panel cannot be translated down far enough
861// to reach the direct beam.
862//
863// Start with the (default) case of a beam center measured on R (MR or FR)
864//
865// Empirical values are averaged as noted
866//
867
868Proc V_DeriveBeamCenters()
869
870        Make/O/T panelWave = {"FL","FR","FT","FB","ML","MR","MT","MB","B"}
871        Make/O/D/N=9 newXCtr_cm,newYCtr_cm
872       
873        Edit panelWave,newXCtr_cm,newYCtr_cm
874       
875        DoAlert 0, "enter the measured beam center reference for Front and Middle panels"
876        V_fDeriveBeamCenters()
877       
878End
879
880//these are values from Dec 2018 data and the CENTROID on FR or MR
881Constant kBCtrOffset_FL_x = 0.13
882Constant kBCtrOffset_FL_y = 0.35
883Constant kBCtrOffset_FB_x = 0.95
884Constant kBCtrOffset_FB_y = 0.77
885Constant kBCtrOffset_FT_x = 1.59
886Constant kBCtrOffset_FT_y = 0.09
887Constant kBCtrOffset_ML_x = 0.26
888Constant kBCtrOffset_ML_y = -0.16
889Constant kBCtrOffset_MB_x = -0.89
890Constant kBCtrOffset_MB_y = 0.96
891Constant kBCtrOffset_MT_x = -0.28
892Constant kBCtrOffset_MT_y = 0.60
893
894////these are values from Dec 2018 data and the FITTED ARC on FR or MR
895// don't use these - the values from the centroid are superior) FEB 2019
896//Constant kBCtrOffset_FL_x = 0.49
897//Constant kBCtrOffset_FL_y = 0.48
898//Constant kBCtrOffset_FB_x = 1.31
899//Constant kBCtrOffset_FB_y = 0.90
900//Constant kBCtrOffset_FT_x = 1.95
901//Constant kBCtrOffset_FT_y = 0.22
902//Constant kBCtrOffset_ML_x = 0.44
903//Constant kBCtrOffset_ML_y = -0.32
904//Constant kBCtrOffset_MB_x = -0.71
905//Constant kBCtrOffset_MB_y = 0.80
906//Constant kBCtrOffset_MT_x = -0.10
907//Constant kBCtrOffset_MT_y = 0.44
908
909// (DONE):
910// if I change any of these values, I need to also change them in the V_FindCentroid function
911// in V_Marquee_Operation.ipf (FEB 2019, this is done automatically with the defined constants)
912//
913// ** updated these values with fitted arcs of AgBeh (Dec 2018 data, multiple runs)
914//
915Proc V_fDeriveBeamCenters(x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference)
916        Variable x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference
917       
918        // start with the front
919        // FR
920        newXCtr_cm[1] = x_FrontReference
921        newYCtr_cm[1] = y_FrontReference
922        // FL
923//      newXCtr_cm[0] = x_FrontReference - (0.03 + 0.03)/2              //OLD, pre Dec 2018
924//      newYCtr_cm[0] = y_FrontReference + (0.34 + 0.32)/2
925        newXCtr_cm[0] = x_FrontReference + kBCtrOffset_FL_x                             //NEW Dec 2018
926        newYCtr_cm[0] = y_FrontReference + kBCtrOffset_FL_y
927        // FB
928//      newXCtr_cm[3] = x_FrontReference - (2.02 + 2.06)/2              // OLD, pre Dec 2018
929//      newYCtr_cm[3] = y_FrontReference - (0.12 + 0.19)/2              // (-) is correct here
930        newXCtr_cm[3] = x_FrontReference + kBCtrOffset_FB_x                                     // NEW Dec 2018
931        newYCtr_cm[3] = y_FrontReference + kBCtrOffset_FB_y
932        // FT
933//      newXCtr_cm[2] = newXCtr_cm[3]                           // OLD, pre Dec 2018
934//      newYCtr_cm[2] = newYCtr_cm[3]
935        newXCtr_cm[2] = x_FrontReference + kBCtrOffset_FT_x                             // NEW Dec 2018 (not a duplicate of FB anymore)
936        newYCtr_cm[2] = y_FrontReference + kBCtrOffset_FT_y
937       
938        // MR
939        newXCtr_cm[5] = x_MiddleReference
940        newYCtr_cm[5] = y_MiddleReference
941        // ML
942//      newXCtr_cm[4] = x_MiddleReference - (0.06 + 0.05)/2
943//      newYCtr_cm[4] = y_MiddleReference + (0.14 + 0.01)/2
944        newXCtr_cm[4] = x_MiddleReference + kBCtrOffset_ML_x
945        newYCtr_cm[4] = y_MiddleReference + kBCtrOffset_ML_y
946        // MB
947//      newXCtr_cm[7] = x_MiddleReference - (0.51 + 0.62)/2
948//      newYCtr_cm[7] = y_MiddleReference + (0.79 + 0.74)/2
949        newXCtr_cm[7] = x_MiddleReference + kBCtrOffset_MB_x
950        newYCtr_cm[7] = y_MiddleReference + kBCtrOffset_MB_y
951        // MT
952        newXCtr_cm[6] = x_MiddleReference + kBCtrOffset_MT_x
953        newYCtr_cm[6] = y_MiddleReference + kBCtrOffset_MT_y
954       
955       
956        // default value for B (approx center) in pixels
957        newXCtr_cm[8] = 340
958        newYCtr_cm[8] = 828
959
960               
961        return
962End
963
964
965Window V_Gizmo_PeakFit() : GizmoPlot
966        PauseUpdate; Silent 1           // building window...
967        // Building Gizmo 7 window...
968        NewGizmo/W=(35,45,550,505)
969        ModifyGizmo startRecMacro=700
970        ModifyGizmo scalingOption=63
971        AppendToGizmo Surface=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel,name=surface0
972        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ srcMode,0}
973        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ surfaceCTab,Rainbow}
974        AppendToGizmo Axes=boxAxes,name=axes0
975        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisScalingMode,1}
976        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisColor,0,0,0,1}
977        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,ticks,3}
978        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,ticks,3}
979        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,ticks,3}
980        ModifyGizmo modifyObject=axes0,objectType=Axes,property={-1,Clipped,0}
981        AppendToGizmo Surface=root:PeakPix2D_mat,name=surface1
982        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ srcMode,0}
983        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ surfaceCTab,Grays}
984        ModifyGizmo setDisplayList=0, object=surface0
985        ModifyGizmo setDisplayList=1, object=axes0
986        ModifyGizmo setDisplayList=2, object=surface1
987        ModifyGizmo autoscaling=1
988        ModifyGizmo currentGroupObject=""
989        ModifyGizmo showInfo
990        ModifyGizmo infoWindow={551,23,1368,322}
991        ModifyGizmo endRecMacro
992        ModifyGizmo idleEventQuaternion={1.38005e-05,-1.48789e-05,-6.11841e-06,1}
993EndMacro
994
995
996Proc V_NaN_BeforeFit(x1,x2,y1,y2)
997        Variable x1,x2,y1,y2
998       
999        root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel[x1,x2][y1,y2] = NaN
1000End
1001
1002
1003Function V_Convert_FittedPix_2_cm(panel,xPix,yPix)
1004        String panel
1005        Variable xPix,yPix
1006       
1007        Make/O/D/N=128 tmpTube
1008       
1009        String pathStr = "root:Packages:NIST:VSANS:RAW:entry:instrument:detector_"
1010        Variable x_cm,y_cm
1011       
1012       
1013        Wave xW = $(pathStr+panel+":data_realDistX")
1014        Wave yW = $(pathStr+panel+":data_realDistY")
1015
1016        strswitch(panel)        // string switch
1017                case "FL":
1018                case "ML":
1019                        // for Left/Right
1020                        tmpTube = yW[0][p]                     
1021                        // for left
1022                        x_cm = (xW[47][0] + (xPix-47)*8.4)/10
1023                        y_cm = tmpTube[yPix]/10
1024       
1025                        break           
1026                case "FR":     
1027                case "MR":
1028                        // for Left/Right
1029                        tmpTube = yW[0][p]                     
1030                        // for right
1031                        x_cm = (xW[0][0] + xPix*8.4)/10
1032                        y_cm = tmpTube[yPix]/10
1033                       
1034                        break
1035                case "FT":     
1036                case "MT":
1037                        // for Top/Bottom
1038                        tmpTube = xW[p][0]
1039                       
1040                        x_cm = tmpTube[xPix]/10
1041                        y_cm = (yW[0][0] + yPix*8.4)/10
1042                       
1043                        break           
1044                case "FB":     
1045                case "MB":
1046                        // for Top/Bottom
1047                        tmpTube = xW[p][0]
1048                       
1049                        x_cm = tmpTube[xPix]/10
1050                        y_cm = (yW[0][47] + (yPix-47)*8.4)/10
1051                                               
1052                        break
1053                default:                        // optional default expression executed
1054                        Print "No case matched in V_Convert_FittedPix_2_cm"
1055                        return(1)
1056        endswitch
1057
1058       
1059        Print "Converted Center = ",x_cm,y_cm
1060        return(0)
1061end
1062
1063Function V_MakeCorrelationMatrix()
1064       
1065        Wave M_Covar=M_Covar
1066        Duplicate M_Covar, CorMat        // You can use any name instead of CorMat
1067        CorMat = M_Covar[p][q]/sqrt(M_Covar[p][p]*M_Covar[q][q])
1068        Edit/K=0 root:CorMat
1069
1070        return(0)
1071End
Note: See TracBrowser for help on using the repository browser.