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

Last change on this file since 1242 was 1242, checked in by srkline, 2 years ago

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

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