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

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

added procedures to output QxQy_ASCII data. Each panel is output into its own file. Output format is the same as for 2D SANS data, including the 2D resolution function. However, reading the data back in with the SANS analysis macros currently does not redimension the data back to the matrix correctly as it assumes a square detector.

I will need to add the X and Y dimensions of each panel into the header, and then make use of these values when they are read in. Also, writing the QxQy? data is quick for the M and F panels ( 0.8 s) but is extremely slow for the back, High-res panel (120 s) since there are 1.1.E6 points there vs. 6144 pts. I'll need to find a way to speed this operation up.

File size: 30.7 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//
642// Nominal center is 0,0
643//
644Function V_RescaleToNominalCenter(folderStr,detStr,xCtr,yCtr)
645        String folderStr,detStr
646        Variable xCtr,yCtr
647       
648//      xCtr = 0
649//      yCtr = 0
650       
651        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
652       
653        Variable nPix = 128
654        Variable nTubes = 48
655        Variable offset = 0
656        Variable pixSizeX,pixSizeY
657       
658        strswitch(detStr)       // string switch
659                case "MT":              // top panels
660                case "FT":
661//                      SetScale/I x -xCtr,npix-xCtr,"",w
662                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
663                        pixSizeY = 0.84
664                        yCtr = -(offset/pixSizeY)
665                       
666                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
667                        SetScale/I y -yCtr,nTubes-yCtr,"",w
668                        break                                           // exit from switch
669                case "MB":              // bottom panels
670                case "FB":
671//                      SetScale/I x -xCtr,npix-xCtr,"",w
672
673                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
674                        pixSizeY = 0.84
675                        yCtr = nTubes-(offset/pixSizeY)
676                       
677                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
678                        SetScale/I y -yCtr,nTubes-yCtr,"",w
679                        break                                           // exit from switch
680                       
681                case "ML":              // left panels
682                case "FL":
683                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
684                        pixSizeX = 0.84
685                        xCtr = nTubes-(offset/pixSizeX)
686                       
687                        SetScale/I x -xCtr,nTubes-xCtr,"",w
688                        SetScale/I y -yCtr,npix-yCtr,"",w
689                        break                                           // exit from switch
690                case "MR":              // Right panels
691                case "FR":
692                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
693                        pixSizeX = 0.84
694                        xCtr = -(offset/pixSizeX)
695               
696                        SetScale/I x -xCtr,nTubes-xCtr,"",w
697                        SetScale/I y -yCtr,npix-yCtr,"",w
698                        break                                           // exit from switch
699                                       
700                default:                                                        // optional default expression executed
701                        Print "Error in V_RescaleToBeamCenter()"
702        endswitch
703       
704        return(0)
705end
706
707
708// TODO
709// these are "nominal" beam center values in pixels for the default VCALC configuration
710// This function "restores" the data display to the "instrument" conditions where the panels overlap
711// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
712// the view should be symmetric (if the real data is symmetric)
713//
714// -- this is currently linked to the Vdata panel
715// -- will need to remove the hard-wired values and get the proper values from the data
716// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
717// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
718//
719//
720//
721//•print xCtr_pix
722//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
723//•print yCtr_pix
724//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
725//
726Function V_RestorePanels()
727
728        String fname=""
729        String detStr=""
730        Variable ii,xCtr,yCtr
731
732// this works if the proper centers are in the file - otherwise, it's a mess   
733// "B" is skipped here, as it should be...
734
735// TODO --?? is this a problem??
736        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
737
738        fname = type
739        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
740                detStr = StringFromList(ii, ksDetectorListNoB, ";")
741                xCtr = V_getDet_beam_center_x_pix(fname,detStr)
742                yCtr = V_getDet_beam_center_y_pix(fname,detStr)
743//              V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
744                V_RescaleToNominalCenter(type,detStr,xCtr,yCtr)         // xCtr or yCtr value in direction of offset are dummy values here
745        endfor
746               
747
748        return(0)
749end
750
751// TODO
752// these are "spread out" values for the data panels
753// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
754// viewed a bit easier. Isolation may still be preferred for detailed work.
755//
756// -- this is currently linked to the Vdata panel
757// -- will need to remove the hard-wired values and get the proper values from the data
758// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
759//
760Function V_SpreadOutPanels()
761
762// TODO ?? is this a problem??
763        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
764
765        V_RescaleToBeamCenter(type,"MB",64,78)
766        V_RescaleToBeamCenter(type,"MT",64,-30)
767        V_RescaleToBeamCenter(type,"MR",-30,64)
768        V_RescaleToBeamCenter(type,"ML",78,64)
769        V_RescaleToBeamCenter(type,"FB",64,78)
770        V_RescaleToBeamCenter(type,"FT",64,-30)
771        V_RescaleToBeamCenter(type,"FR",-30,64)
772        V_RescaleToBeamCenter(type,"FL",78,64)
773        return(0)
774end
775
776// function to display the beam center values for all of the detectors
777// opens a separate table with the detector label, and the XY values
778// ? Maybe list the XY pair in pixels and in real distance in the table
779//
780// TODO:
781// -- need a way to use this or another table? as input to put the new/fitted/derived
782//    beam center values into the data folders, and ultimately into the data files on disk
783// -- need read/Write for the XY in pixels, and in real-distance
784// -- where are the temporary waves to be located? root?
785// -- need way to access the Ctr_mm values
786Function V_BCtrTable()
787       
788        // order of the panel names will match the constant string
789        //FT;FB;FL;FR;MT;MB;ML;MR;B;
790        Make/O/T/N=9 panelW
791        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
792        DoWindow/F BCtrTable
793        if(V_flag == 0)
794                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
795        endif
796       
797        Variable ii
798        String detStr,fname
799       
800        fname = "RAW"
801        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
802                detStr = StringFromList(ii, ksDetectorListAll, ";")
803                panelW[ii] = detStr
804
805        endfor
806       
807//              xCtr_pix[ii] = V_getDet_beam_center_x_pix(fname,detStr)
808//              yCtr_pix[ii] = V_getDet_beam_center_y_pix(fname,detStr)
809//              // TODO
810//              // and now the mm values
811//              xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
812//              yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
813        return(0)
814End
815
816//
817// to write the new beam center values to a file on disk:
818// V_writeDet_beam_center_x(fname,detStr,val)
819//
820// to write to a local WORK folder
821// V_putDet_beam_center_x(fname,detStr,val)
822//
823Function V_BeamCtr_WriteTable()
824
825        Variable runNumber
826        Prompt runNumber, "enter the run number:"
827        DoPrompt "Pick file to write to",runNumber
828        If(V_flag==1)
829                return(0)
830        endif   
831       
832        String folder
833       
834        Variable ii
835        String detStr,fname
836       
837        Wave xCtr_pix = root:xCtr_pix
838        Wave yCtr_pix = root:yCtr_pix
839        Wave/T panelW = root:PanelW
840       
841
842        fname = V_FindFileFromRunNumber(runNumber)
843
844        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
845//              detStr = StringFromList(ii, ksDetectorListAll, ";")
846                detStr = panelW[ii]
847                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
848                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])
849               
850                // TODO
851                // and now the mm values
852               
853        endfor
854        return(0)
855       
856End
857
858
859
860
861//////////////////
862//
863// Simple utility to calculate beam centers [cm] based on a single measurement
864//  and empirical relations between the panel zero positions
865//
866// Empirical relations are derived from beam center measurements using 6A data and WB data (9/10/17)
867// only measurements on L, R, and x-coordinate of B were used. T panel cannot be translated down far enough
868// to reach the direct beam.
869//
870// Start with the (default) case of a beam center measured on R (MR or FR)
871//
872// Empirical values are averaged as noted
873//
874
875Proc V_DeriveBeamCenters_VelSel()
876
877        Make/O/T panelWave = {"FL","FR","FT","FB","ML","MR","MT","MB","B"}
878        Make/O/D/N=9 newXCtr_cm,newYCtr_cm
879       
880        Edit panelWave,newXCtr_cm,newYCtr_cm
881       
882        DoAlert 0, "enter the measured beam center reference for Front and Middle panels"
883        V_fDeriveBeamCenters_VelSel()
884       
885End
886
887// TODO:
888// if I change any of these values, I need to also change them in the V_FindCentroid function
889// in V_Marquee_Operation.ipf
890//
891// ** updated these values for the FRONT only with fitted arcs of AgBeh (Dec 2018 data, multiple runs)
892//
893Proc V_fDeriveBeamCenters_VelSel(x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference)
894        Variable x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference
895       
896        // start with the front
897        // FR
898        newXCtr_cm[1] = x_FrontReference
899        newYCtr_cm[1] = y_FrontReference
900        // FL
901//      newXCtr_cm[0] = x_FrontReference - (0.03 + 0.03)/2              //OLD, pre Dec 2018
902//      newYCtr_cm[0] = y_FrontReference + (0.34 + 0.32)/2
903        newXCtr_cm[0] = x_FrontReference + 0.13                         //NEW Dec 2018
904        newYCtr_cm[0] = y_FrontReference + 0.35
905        // FB
906//      newXCtr_cm[3] = x_FrontReference - (2.02 + 2.06)/2              // OLD, pre Dec 2018
907//      newYCtr_cm[3] = y_FrontReference - (0.12 + 0.19)/2              // (-) is correct here
908        newXCtr_cm[3] = x_FrontReference + 0.95                                 // NEW Dec 2018
909        newYCtr_cm[3] = y_FrontReference + 0.77
910        // FT
911//      newXCtr_cm[2] = newXCtr_cm[3]                           // OLD, pre Dec 2018
912//      newYCtr_cm[2] = newYCtr_cm[3]
913        newXCtr_cm[2] = x_FrontReference + 1.59                         // NEW Dec 2018 (not a duplicate of FB anymore)
914        newYCtr_cm[2] = y_FrontReference + 0.09
915       
916        // MR
917        newXCtr_cm[5] = x_MiddleReference
918        newYCtr_cm[5] = y_MiddleReference
919        // ML
920//      newXCtr_cm[4] = x_MiddleReference - (0.06 + 0.05)/2
921//      newYCtr_cm[4] = y_MiddleReference + (0.14 + 0.01)/2
922        newXCtr_cm[4] = x_MiddleReference + 0.26
923        newYCtr_cm[4] = y_MiddleReference - 0.16
924        // MB
925//      newXCtr_cm[7] = x_MiddleReference - (0.51 + 0.62)/2
926//      newYCtr_cm[7] = y_MiddleReference + (0.79 + 0.74)/2
927        newXCtr_cm[7] = x_MiddleReference - 0.89
928        newYCtr_cm[7] = y_MiddleReference + 0.96
929        // MT
930        newXCtr_cm[6] = x_MiddleReference - 0.28
931        newYCtr_cm[6] = y_MiddleReference + 0.60
932       
933       
934        // default value for B
935        newXCtr_cm[8] = 50
936        newYCtr_cm[8] = 50
937
938               
939        return
940End
941
942//
943// these values for FRONT use improved, fitted arcs from AgBeh. Data was fitted in pixels and converted to cm
944// data from Sept 2018 (run 17994)
945Proc V_DeriveBeamCenters_Graphite()
946
947        Make/O/T panelWave = {"FL","FR","FT","FB","ML","MR","MT","MB","B"}
948        Make/O/D/N=9 newXCtr_cm,newYCtr_cm
949       
950        Edit panelWave,newXCtr_cm,newYCtr_cm
951       
952        DoAlert 0, "enter the measured beam center reference for Front and Middle panels"
953        V_fDeriveBeamCenters_Graphite()
954       
955End
956
957// units are in [cm]
958Proc V_fDeriveBeamCenters_Graphite(x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference)
959        Variable x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference
960       
961        // start with the front
962        // FR
963        newXCtr_cm[1] = x_FrontReference - 0.08
964        newYCtr_cm[1] = y_FrontReference - 0.08
965        // FL
966        newXCtr_cm[0] = x_FrontReference - 0.03
967        newYCtr_cm[0] = y_FrontReference + 0.28
968        // FB
969        newXCtr_cm[3] = x_FrontReference + 1.42
970        newYCtr_cm[3] = y_FrontReference + 0.55
971        // FT
972        newXCtr_cm[2] = x_FrontReference + 1.92
973        newYCtr_cm[2] = y_FrontReference + 0.05
974       
975        // no new data for the middle detector + graphite, so these values don't change
976        // MR
977        newXCtr_cm[5] = x_MiddleReference
978        newYCtr_cm[5] = y_MiddleReference
979        // ML
980        newXCtr_cm[4] = x_MiddleReference - (0.06 + 0.05)/2
981        newYCtr_cm[4] = y_MiddleReference + (0.14 + 0.01)/2
982        // MB
983        newXCtr_cm[7] = x_MiddleReference - (0.51 + 0.62)/2
984        newYCtr_cm[7] = y_MiddleReference + (0.79 + 0.74)/2
985        // MT (duplicate MB)
986        newXCtr_cm[6] = newXCtr_cm[7]
987        newYCtr_cm[6] = newYCtr_cm[7]   
988       
989       
990        // default value for B
991        newXCtr_cm[8] = 50
992        newYCtr_cm[8] = 50
993
994               
995        return
996End
997
998
999
1000
1001
1002Window V_Gizmo_PeakFit() : GizmoPlot
1003        PauseUpdate; Silent 1           // building window...
1004        // Building Gizmo 7 window...
1005        NewGizmo/W=(35,45,550,505)
1006        ModifyGizmo startRecMacro=700
1007        ModifyGizmo scalingOption=63
1008        AppendToGizmo Surface=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel,name=surface0
1009        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ srcMode,0}
1010        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ surfaceCTab,Rainbow}
1011        AppendToGizmo Axes=boxAxes,name=axes0
1012        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisScalingMode,1}
1013        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisColor,0,0,0,1}
1014        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,ticks,3}
1015        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,ticks,3}
1016        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,ticks,3}
1017        ModifyGizmo modifyObject=axes0,objectType=Axes,property={-1,Clipped,0}
1018        AppendToGizmo Surface=root:PeakPix2D_mat,name=surface1
1019        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ srcMode,0}
1020        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ surfaceCTab,Grays}
1021        ModifyGizmo setDisplayList=0, object=surface0
1022        ModifyGizmo setDisplayList=1, object=axes0
1023        ModifyGizmo setDisplayList=2, object=surface1
1024        ModifyGizmo autoscaling=1
1025        ModifyGizmo currentGroupObject=""
1026        ModifyGizmo showInfo
1027        ModifyGizmo infoWindow={551,23,1368,322}
1028        ModifyGizmo endRecMacro
1029        ModifyGizmo idleEventQuaternion={1.38005e-05,-1.48789e-05,-6.11841e-06,1}
1030EndMacro
1031
1032
1033Proc V_NaN_BeforeFit(x1,x2,y1,y2)
1034        Variable x1,x2,y1,y2
1035       
1036        root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel[x1,x2][y1,y2] = NaN
1037End
1038
1039
1040Function V_Convert_FittedPix_2_cm(panel,xPix,yPix)
1041        String panel
1042        Variable xPix,yPix
1043       
1044        Make/O/D/N=128 tmpTube
1045       
1046        String pathStr = "root:Packages:NIST:VSANS:RAW:entry:instrument:detector_"
1047        Variable x_cm,y_cm
1048       
1049       
1050        Wave xW = $(pathStr+panel+":data_realDistX")
1051        Wave yW = $(pathStr+panel+":data_realDistY")
1052
1053        strswitch(panel)        // string switch
1054                case "FL":
1055                case "ML":
1056                        // for Left/Right
1057                        tmpTube = yW[0][p]                     
1058                        // for left
1059                        x_cm = (xW[47][0] + (xPix-47)*8.4)/10
1060                        y_cm = tmpTube[yPix]/10
1061       
1062                        break           
1063                case "FR":     
1064                case "MR":
1065                        // for Left/Right
1066                        tmpTube = yW[0][p]                     
1067                        // for right
1068                        x_cm = (xW[0][0] + xPix*8.4)/10
1069                        y_cm = tmpTube[yPix]/10
1070                       
1071                        break
1072                case "FT":     
1073                case "MT":
1074                        // for Top/Bottom
1075                        tmpTube = xW[p][0]
1076                       
1077                        x_cm = tmpTube[xPix]/10
1078                        y_cm = (yW[0][0] + yPix*8.4)/10
1079                       
1080                        break           
1081                case "FB":     
1082                case "MB":
1083                        // for Top/Bottom
1084                        tmpTube = xW[p][0]
1085                       
1086                        x_cm = tmpTube[xPix]/10
1087                        y_cm = (yW[0][47] + (yPix-47)*8.4)/10
1088                                               
1089                        break
1090                default:                        // optional default expression executed
1091                        Print "No case matched in V_Convert_FittedPix_2_cm"
1092                        return(1)
1093        endswitch
1094
1095       
1096        Print "Converted Center = ",x_cm,y_cm
1097        return(0)
1098end
1099
1100Function V_MakeCorrelationMatrix()
1101       
1102        Wave M_Covar=M_Covar
1103        Duplicate M_Covar, CorMat        // You can use any name instead of CorMat
1104        CorMat = M_Covar[p][q]/sqrt(M_Covar[p][p]*M_Covar[q][q])
1105        Edit/K=0 root:CorMat
1106
1107        return(0)
1108End
Note: See TracBrowser for help on using the repository browser.