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

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

extensive changes to accomodate 1x1 binning of the HighRes? detector. It is implemented as a global flag. Currently only 4x4 and 1x1 are allowed. 1x1 has never been tested in reality, only simulated data - so my assumed dimensions may not be correct. look for TODOHIGHRES in the file for places that may need to be updated for different file dimensions. Testing of the simulated data is proving to be excruciatingly slow, but passable for a test. Speed optimization will be needed if this is the final solution. Memory management will also be an issue since every "copy" of the highRes matrix is enormous. Carry as few of these around as possible in the future to keep the experiment size to something reasonable.

File size: 23.8 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3
4// TODO
5// -- adjust the guesses to some better starting conditions
6// -- multiple fit options with different things held
7// x- when selecting the detector, set the x/y pixel sizes
8// -- figure out how to re-plot the images when swapping between LR and TB panels
9// -- Modify to accept mm (real space dimensions) rather than pixels
10//    -- or be able to swap the answer to mm for a more natural definition of the beam center
11// -- add method to be able to write the values to the local folder / or better, to file on disk
12// -- graphically show the beam center / radius of where it is in relation to the panel
13//
14// x- error checking, if data is selected from a folder that does not exist (like VCALC). Otherwise
15//    the user is caught in a long loop of open file dialogs looking for something...
16//
17// -- move everything into it's own folder, rather than root:
18//
19// -- am I working in detector coordinates (1->n) or in array coordinates (0->n-1)??
20
21
22Function V_FindBeamCenter()
23        DoWindow/F PanelFit
24        if(V_flag==0)
25       
26                NewDataFolder/O root:Packages:NIST:VSANS:Globals:BeamCenter
27
28                Execute "V_DetectorPanelFit()"
29        endif
30End
31//
32// TODO - may need to adjust the display for the different pixel dimensions
33//      ModifyGraph width={Plan,1,bottom,left}
34//
35Proc V_DetectorPanelFit() : Panel
36        PauseUpdate; Silent 1           // building window...
37
38// plot the default model to be sure some data is present
39        if(exists("xwave_PeakPix2D") == 0)
40                V_PlotBroadPeak_Pix2D()
41        endif
42
43        NewPanel /W=(662,418,1586,960)/N=PanelFit/K=1
44//      ShowTools/A
45       
46        PopupMenu popup_0,pos={20,50},size={109,20},proc=V_SetDetPanelPopMenuProc,title="Detector Panel"
47        PopupMenu popup_0,mode=1,popvalue="FL",value= #"\"FL;FR;FT;FB;ML;MR;MT;MB;B;\""
48        PopupMenu popup_1,pos={200,20},size={157,20},proc=V_DetModelPopMenuProc,title="Model Function"
49        PopupMenu popup_1,mode=1,popvalue="BroadPeak",value= #"\"BroadPeak;other;\""
50        PopupMenu popup_2,pos={20,20},size={109,20},title="Data Source"//,proc=SetFldrPopMenuProc
51        PopupMenu popup_2,mode=1,popvalue="RAW",value= #"\"RAW;SAM;VCALC;\""
52               
53        Button button_0,pos={486,20},size={80,20},proc=V_DetFitGuessButtonProc,title="Guess"
54        Button button_1,pos={615,20},size={80,20},proc=V_DetFitButtonProc,title="Do Fit"
55        Button button_2,pos={744,20},size={80,20},proc=V_DetFitHelpButtonProc,title="Help"
56        Button button_3,pos={730,400},size={110,20},proc=V_CopyCtrButtonProc,title="Copy Centers",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        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
62
63        duplicate/O root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:data curDispPanel
64        SetScale/P x 0,1, curDispPanel
65        SetScale/P y 0,1, curDispPanel
66
67        SetDataFolder root:
68       
69        // draw the correct images
70        V_DrawDetPanel("FL")
71
72       
73////draw the detector panel
74//      Display/W=(20,80,200,600)/HOST=#
75//      AppendImage curDispPanel
76//      ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
77////    ModifyGraph height={Aspect,2.67}               
78//      Label left "Y pixels"
79//      Label bottom "X pixels"
80//      RenameWindow #,DetData
81//      SetActiveSubwindow ##   
82//     
83////draw the model calculation
84//      Display/W=(220,80,400,600)/HOST=#
85//      AppendImage PeakPix2D_mat
86//      ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
87////    ModifyGraph height={Aspect,2.67}               
88////    ModifyGraph width={Aspect,0.375}               
89//      Label left "Y pixels"
90//      Label bottom "X pixels"
91//      RenameWindow #,ModelData
92//      SetActiveSubwindow ##           
93
94
95
96
97// edit the fit coefficients   
98        Edit/W=(550,80,880,370)/HOST=#  parameters_PeakPix2D,coef_PeakPix2D
99        ModifyTable width(Point)=0
100        ModifyTable width(parameters_PeakPix2D)=120
101        ModifyTable width(coef_PeakPix2D)=100
102        RenameWindow #,T0
103        SetActiveSubwindow ##
104
105       
106EndMacro
107
108
109//
110// function to choose which detector panel to display, and then to actually display it
111//
112Function V_SetDetPanelPopMenuProc(pa) : PopupMenuControl
113        STRUCT WMPopupAction &pa
114
115        switch( pa.eventCode )
116                case 2: // mouse up
117                        Variable popNum = pa.popNum
118                        String popStr = pa.popStr
119                                               
120                        // remove the old image (it may not be the right shape)
121                        // -- but make sure it exists first...
122                        String childList = ChildWindowList("PanelFit")
123                        Variable flag
124                       
125                        flag = WhichListItem("DetData", ChildList)              //returns -1 if not in list, 0+ otherwise
126                        if(flag != -1)
127                                KillWindow PanelFit#DetData
128                        endif
129                       
130                        flag = WhichListItem("ModelData", ChildList)
131                        if(flag != -1)
132                                KillWindow PanelFit#ModelData
133                        endif
134       
135                        // draw the correct images
136                        V_DrawDetPanel(popStr)
137                       
138                        break
139                case -1: // control being killed
140                        break
141        endswitch
142
143        return 0
144End
145
146
147// TODO - currently is hard-wired for the simulation path!
148//     need to make it more generic, especially for RAW data
149//
150// -- need to adjust the size of the image subwindows to keep the model
151//    calculation from spilling over onto the table (maybe just move the table)
152// -- need to do something for panel "B". currently ignored
153// -- currently the pixel sizes for "real" data is incorrect in the file
154//     and this is why the plots are incorrectly sized
155//
156// draw the selected panel and the model calculation, adjusting for the
157// orientation of the panel and the number of pixels, and pixel sizes
158Function V_DrawDetPanel(str)
159        String str
160       
161        // from the selection, find the path to the data
162
163
164        Variable xDim,yDim
165        Variable left,top,right,bottom
166        Variable height, width
167        Variable left2,top2,right2,bottom2
168        Variable nPix_X,nPix_Y,pixSize_X,pixSize_Y
169
170
171        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
172        Wave cw = root:coef_PeakPix2D
173
174        Wave xwave_PeakPix2D=root:xwave_PeakPix2D
175        Wave ywave_PeakPix2D=root:ywave_PeakPix2D
176        Wave zwave_PeakPix2D=root:zwave_PeakPix2D
177
178        //plot it in the subwindow with the proper aspect and positioning
179        // for 48x256 (8mm x 4mm), aspect = (256/2)/48 = 2.67 (LR panels)
180        // for 128x48 (4mm x 8 mm), aspect = 48/(128/2) = 0.75 (TB panels)
181       
182       
183        // using two switches -- one to set the panel-specific dimensions
184        // and the other to set the "common" values, some of which are based on the panel dimensions
185
186// set the source of the data. not always VCALC anymore
187        String folder
188        ControlInfo popup_2
189        folder = S_Value
190
191// error checking -- if the VCALC folder is the target & does not exist, exit now
192        if( cmpstr(folder,"VCALC") == 0 && DataFolderExists("root:Packages:NIST:VSANS:VCALC") == 0)
193                return(0)
194        endif
195
196// error checking -- if the RAW folder is the target & does not exist, exit now
197        if( cmpstr(folder,"RAW") == 0 && DataFolderExists("root:Packages:NIST:VSANS:RAW:entry") == 0)
198                return(0)
199        endif
200
201// error checking -- if the SAM folder is the target & does not exist, exit now
202        if( cmpstr(folder,"SAM") == 0 && DataFolderExists("root:Packages:NIST:VSANS:SAM:entry") == 0)
203                return(0)
204        endif
205               
206        // TODO -- fix all of this mess
207        if(cmpstr(folder,"VCALC") == 0)
208                // panel-specific values
209                Variable VC_nPix_X = VCALC_get_nPix_X(str)
210                Variable VC_nPix_Y = VCALC_get_nPix_Y(str)
211                Variable VC_pixSize_X = VCALC_getPixSizeX(str)
212                Variable VC_pixSize_Y = VCALC_getPixSizeY(str)
213
214       
215        // if VCALC declare this way   
216                wave newW = $("root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_"+str+":det_"+str)
217                nPix_X = VC_nPix_X
218                nPix_Y = VC_nPix_Y
219                pixSize_X = VC_pixSize_X
220                pixSize_Y = VC_pixSize_Y
221       
222        else
223        // TODO: if real data, need new declaration w/ data as the wave name
224                wave newW = $("root:Packages:NIST:VSANS:"+folder+":entry:instrument:detector_"+str+":data")
225
226                nPix_X = V_getDet_pixel_num_x(folder,str)
227                nPix_Y = V_getDet_pixel_num_Y(folder,str)
228                pixSize_X = V_getDet_x_pixel_size(folder,str)/10
229                pixSize_Y = V_getDet_y_pixel_size(folder,str)/10
230        endif
231       
232
233        Variable scale = 5
234       
235        // common values (panel position, etc)
236        // TODO -- units are absolute, based on pixels in cm. make sure this is always correct
237        strswitch(str)
238                case "FL":
239                case "FR":
240                case "ML":
241                case "MR":
242                        width = trunc(nPix_X*pixSize_X *scale*1.15)                     //48 tubes @ 8 mm
243                        height = trunc(nPix_Y*pixSize_Y *scale*0.8)                     //128 pixels @ 8 mm
244                       
245                        left = 20
246                        top = 80
247                        right = left+width
248                        bottom = top+height
249                       
250                        left2 = right + 20
251                        right2 = left2 + width
252                        top2 = top
253                        bottom2 = bottom
254                       
255                        break                   
256                case "FT":
257                case "FB":
258                case "MT":
259                case "MB":
260                        width = trunc(nPix_X*pixSize_X *scale*1.)                       //128 pix @ 4 mm
261                        height = trunc(nPix_Y*pixSize_Y *scale)                 // 48 tubes @ 8 mm
262                                               
263                        left = 20
264                        top = 80
265                        right = left+width
266                        bottom = top+height
267                       
268                        left2 = left
269                        right2 = right
270                        top2 = top + height + 20
271                        bottom2 = bottom + height + 20
272                       
273                        break
274                case "B":
275                        return(0)               //just exit
276                        break                                           
277                default:
278                        return(0)               //just exit
279        endswitch
280
281        // set from the detector-specific strswitch
282        cw[7] = pixSize_X*10
283        cw[8] = pixSize_Y*10           
284
285        SetDataFolder root:Packages:NIST:VSANS:Globals:BeamCenter
286        // generate the new panel display
287        duplicate/O newW curDispPanel
288        SetScale/P x 0,1, curDispPanel
289        SetScale/P y 0,1, curDispPanel
290       
291        //draw the detector panel
292        Display/W=(left,top,right,bottom)/HOST=#
293        AppendImage curDispPanel
294        ModifyImage curDispPanel ctab= {*,*,ColdWarm,0}
295        Label left "Y pixels"
296        Label bottom "X pixels"
297        RenameWindow #,DetData
298        SetActiveSubwindow ##   
299       
300        SetDataFolder root:
301       
302       
303               
304        // re-dimension the model calculation to be the proper dimensions       
305        Redimension/N=(nPix_X*nPix_Y) xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D 
306        V_FillPixTriplet(xwave_PeakPix2D, ywave_PeakPix2D,zwave_PeakPix2D,nPix_X,nPix_Y)
307        Make/O/D/N=(nPix_X,nPix_Y) PeakPix2D_mat                // use the point scaling of the matrix (=pixels)
308
309        Duplicate/O $"PeakPix2D_mat",$"PeakPix2D_lin"           //keep a linear-scaled version of the data
310
311        //draw the model calculation
312        Display/W=(left2,top2,right2,bottom2)/HOST=#
313        AppendImage PeakPix2D_mat
314        ModifyImage PeakPix2D_mat ctab= {*,*,ColdWarm,0}
315        Label left "Y pixels"
316        Label bottom "X pixels"
317        RenameWindow #,ModelData
318        SetActiveSubwindow ##   
319               
320        DoUpdate
321       
322        return(0)
323End
324
325
326
327
328// TODO:
329// -- allow other model functions as needed.
330//
331// Function to plot the specified 2D model for the detector
332//
333Function V_DetModelPopMenuProc(pa) : PopupMenuControl
334        STRUCT WMPopupAction &pa
335
336        switch( pa.eventCode )
337                case 2: // mouse up
338                        Variable popNum = pa.popNum
339                        String popStr = pa.popStr
340                       
341                        Execute "V_PlotBroadPeak_Pix2D()"
342                       
343                        break
344                case -1: // control being killed
345                        break
346        endswitch
347
348        return 0
349End
350
351
352//
353// TODO - make a better guess (how?)
354//
355Function V_DetFitGuessButtonProc(ba) : ButtonControl
356        STRUCT WMButtonAction &ba
357
358        switch( ba.eventCode )
359                case 2: // mouse up
360                        // click code here
361                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
362                        Wave coefW=root:coef_PeakPix2D
363                       
364                        WaveStats/Q dispW
365                        coefW[2] = V_max                //approx peak height
366                        coefW[6] = V_avg                //approx background
367                        coefW[0] = 0                    // remove the porod scale
368                        coefW[3] = 0.9          //peak width, first guess
369                       
370                        break
371                case -1: // control being killed
372                        break
373        endswitch
374
375        return 0
376End
377
378//
379// TODO -- currently hard-wired for coefficients from the only fit function
380//
381// only copies the center values to the local folder (then read back in by clicking  "Ctr Table")
382//
383// -- will need to recalc mm center AND q-values
384Function V_CopyCtrButtonProc(ba) : ButtonControl
385        STRUCT WMButtonAction &ba
386
387        switch( ba.eventCode )
388                case 2: // mouse up
389                        // click code here
390                        String detStr,fname
391                        Wave coefW=root:coef_PeakPix2D
392                       
393                        ControlInfo popup_0
394                        detStr = S_Value
395                        ControlInfo popup_2
396                        fname = S_Value
397                       
398                        V_putDet_beam_center_x(fname,detStr,coefW[9])
399                        V_putDet_beam_center_y(fname,detStr,coefW[10])
400
401//                      DoAlert 0, "-- will need to recalc mm center AND q-values"
402                       
403                        V_BCtrTable()           //reads the values back in
404                       
405                        break
406                case -1: // control being killed
407                        break
408        endswitch
409
410        return 0
411End
412
413
414
415// TODO
416// -- there is only a single fitting function available, and it's hard-wired
417// -- what values are held during the fitting are hard-wired
418//
419//
420// function to call the fit function (2D)
421//
422Function V_DetFitButtonProc(ba) : ButtonControl
423        STRUCT WMButtonAction &ba
424
425        switch( ba.eventCode )
426                case 2: // mouse up
427                        // click code here
428                       
429                        Wave dispW=root:Packages:NIST:VSANS:Globals:BeamCenter:curDispPanel
430                        Wave coefW=root:coef_PeakPix2D
431                       
432                        FuncFitMD/H="11000111100"/NTHR=0 V_BroadPeak_Pix2D coefW  dispW /D                     
433                       
434                        Wave ws=W_sigma
435                        AppendtoTable/W=PanelFit#T0 ws
436                       
437                        break
438                case -1: // control being killed
439                        break
440        endswitch
441
442        return 0
443End
444
445Function V_DetFitHelpButtonProc(ba) : ButtonControl
446        STRUCT WMButtonAction &ba
447
448        switch( ba.eventCode )
449                case 2: // mouse up
450                        // click code here
451                       
452                        DoAlert 0,"Help file not written yet..."
453                       
454                        break
455                case -1: // control being killed
456                        break
457        endswitch
458
459        return 0
460End
461
462Function V_CtrTableButtonProc(ba) : ButtonControl
463        STRUCT WMButtonAction &ba
464
465        switch( ba.eventCode )
466                case 2: // mouse up
467                        // click code here
468                       
469                        V_BCtrTable()
470                       
471                        break
472                case -1: // control being killed
473                        break
474        endswitch
475
476        return 0
477End
478
479Function V_WriteCtrTableButtonProc(ba) : ButtonControl
480        STRUCT WMButtonAction &ba
481
482        switch( ba.eventCode )
483                case 2: // mouse up
484                        // click code here
485                       
486                        V_BeamCtr_WriteTable()
487                       
488                        break
489                case -1: // control being killed
490                        break
491        endswitch
492
493        return 0
494End
495
496//
497// This sets the scale of the data panels to an approximate detector coordinate system with
498// zero at the center, only for display purposes. It is not exact, and has nothing to do with
499// the calculation of q-values.
500//
501//
502// TODO
503// -- some of this is hard-wired in
504// -- this is still all in terms of pixels, which still may not be what I want
505// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
506//
507Function V_RescaleToBeamCenter(folderStr,detStr,xCtr,yCtr)
508        String folderStr,detStr
509        Variable xCtr,yCtr
510       
511        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
512       
513        Variable nPix = 128
514        Variable nTubes = 48
515       
516        strswitch(detStr)       // string switch
517                case "MT":              // top panels
518                case "FT":
519//                      SetScale/I x -xCtr,npix-xCtr,"",w
520                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
521                        SetScale/I y -yCtr,nTubes-yCtr,"",w
522                        break                                           // exit from switch
523                case "MB":              // bottom panels
524                case "FB":
525//                      SetScale/I x -xCtr,npix-xCtr,"",w
526                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
527                        SetScale/I y -yCtr,nTubes-yCtr,"",w
528                        break                                           // exit from switch
529                case "ML":              // left panels
530                case "FL":
531                        SetScale/I x -xCtr,nTubes-xCtr,"",w
532                        SetScale/I y -yCtr,npix-yCtr,"",w
533                        break                                           // exit from switch
534                case "MR":              // Right panels
535                case "FR":
536                        SetScale/I x -xCtr,nTubes-xCtr,"",w
537                        SetScale/I y -yCtr,npix-yCtr,"",w
538                        break                                           // exit from switch
539                                       
540                default:                                                        // optional default expression executed
541                        Print "Error in V_RescaleToBeamCenter()"
542        endswitch
543       
544        return(0)
545end
546
547// This sets the scale of the data panels to an approximate detector coordinate system with
548// zero at the center, only for display purposes. It is not exact, and has nothing to do with
549// the calculation of q-values.
550//
551// ****For the panel display, the scaling MUST be in PIXELS for the readout and calculations to be correct.
552// the read out needs pixels, and the calculations use the pixels as the indexes for the real-space (mm) values
553//
554//  Since I'll only know the beam center in mm, and I'll need the relative panel positions to convert to pixels,
555// can I display the panels in their pixel locations relative to each other, based on a zero center and
556// the panel offset values?
557//
558//
559// TODO
560// -- some of this is hard-wired in
561// -- this is still all in terms of pixels, which still may not be what I want
562// -- the x-scale of the T/B panels is artificially compressed to "fake" 4mm per pixel in x-direction
563//
564// Nominal center is 0,0
565//
566Function V_RescaleToNominalCenter(folderStr,detStr,xCtr,yCtr)
567        String folderStr,detStr
568        Variable xCtr,yCtr
569       
570//      xCtr = 0
571//      yCtr = 0
572       
573        Wave w = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+detStr+":data")
574       
575        Variable nPix = 128
576        Variable nTubes = 48
577        Variable offset = 0
578        Variable pixSizeX,pixSizeY
579       
580        strswitch(detStr)       // string switch
581                case "MT":              // top panels
582                case "FT":
583//                      SetScale/I x -xCtr,npix-xCtr,"",w
584                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
585                        pixSizeY = 0.84
586                        yCtr = -(offset/pixSizeY)
587                       
588                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w         // fake 4mm by compressing the scale
589                        SetScale/I y -yCtr,nTubes-yCtr,"",w
590                        break                                           // exit from switch
591                case "MB":              // bottom panels
592                case "FB":
593//                      SetScale/I x -xCtr,npix-xCtr,"",w
594
595                        offset = V_getDet_VerticalOffset(folderStr,detStr)              //in cm
596                        pixSizeY = 0.84
597                        yCtr = nTubes-(offset/pixSizeY)
598                       
599                        SetScale/I x -xCtr/2,(npix-xCtr)/2,"",w
600                        SetScale/I y -yCtr,nTubes-yCtr,"",w
601                        break                                           // exit from switch
602                       
603                case "ML":              // left panels
604                case "FL":
605                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
606                        pixSizeX = 0.84
607                        xCtr = nTubes-(offset/pixSizeX)
608                       
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                        offset = V_getDet_LateralOffset(folderStr,detStr)               //in cm
615                        pixSizeX = 0.84
616                        xCtr = -(offset/pixSizeX)
617               
618                        SetScale/I x -xCtr,nTubes-xCtr,"",w
619                        SetScale/I y -yCtr,npix-yCtr,"",w
620                        break                                           // exit from switch
621                                       
622                default:                                                        // optional default expression executed
623                        Print "Error in V_RescaleToBeamCenter()"
624        endswitch
625       
626        return(0)
627end
628
629
630// TODO
631// these are "nominal" beam center values in pixels for the default VCALC configuration
632// This function "restores" the data display to the "instrument" conditions where the panels overlap
633// and is intended to be a TRUE view of what the detectors see - that is - the peaks should appear as rings,
634// the view should be symmetric (if the real data is symmetric)
635//
636// -- this is currently linked to the Vdata panel
637// -- will need to remove the hard-wired values and get the proper values from the data
638// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
639// -- may want to keep the nominal scaling values around in case the proper values aren't in the file
640//
641//
642//
643//•print xCtr_pix
644//  xCtr_pix[0]= {64,64,55,-8.1,64,64,55,-8.1,63.4}
645//•print yCtr_pix
646//  yCtr_pix[0]= {-8.7,55,64,64,-8.7,55,64,64,62.7}
647//
648Function V_RestorePanels()
649
650        String fname=""
651        String detStr=""
652        Variable ii,xCtr,yCtr
653
654// this works if the proper centers are in the file - otherwise, it's a mess   
655// "B" is skipped here, as it should be...
656
657// TODO --?? is this a problem??
658        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
659
660        fname = type
661        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1)
662                detStr = StringFromList(ii, ksDetectorListNoB, ";")
663                xCtr = V_getDet_beam_center_x_pix(fname,detStr)
664                yCtr = V_getDet_beam_center_y_pix(fname,detStr)
665//              V_RescaleToBeamCenter(type,detStr,xCtr,yCtr)
666                V_RescaleToNominalCenter(type,detStr,xCtr,yCtr)         // xCtr or yCtr value in direction of offset are dummy values here
667        endfor
668               
669
670        return(0)
671end
672
673// TODO
674// these are "spread out" values for the data panels
675// This view is meant to spread out the panels so there is (?Less) overlap so the panels can be
676// viewed a bit easier. Isolation may still be preferred for detailed work.
677//
678// -- this is currently linked to the Vdata panel
679// -- will need to remove the hard-wired values and get the proper values from the data
680// -- ?? will the "proper" values be in pixels or distance? All depends on how I display the data...
681//
682Function V_SpreadOutPanels()
683
684// TODO ?? is this a problem??
685        SVAR type = root:Packages:NIST:VSANS:Globals:gCurDispType
686
687        V_RescaleToBeamCenter(type,"MB",64,78)
688        V_RescaleToBeamCenter(type,"MT",64,-30)
689        V_RescaleToBeamCenter(type,"MR",-30,64)
690        V_RescaleToBeamCenter(type,"ML",78,64)
691        V_RescaleToBeamCenter(type,"FB",64,78)
692        V_RescaleToBeamCenter(type,"FT",64,-30)
693        V_RescaleToBeamCenter(type,"FR",-30,64)
694        V_RescaleToBeamCenter(type,"FL",78,64)
695        return(0)
696end
697
698// function to display the beam center values for all of the detectors
699// opens a separate table with the detector label, and the XY values
700// ? Maybe list the XY pair in pixels and in real distance in the table
701//
702// TODO:
703// -- need a way to use this or another table? as input to put the new/fitted/derived
704//    beam center values into the data folders, and ultimately into the data files on disk
705// -- need read/Write for the XY in pixels, and in real-distance
706// -- where are the temporary waves to be located? root?
707// -- need way to access the Ctr_mm values
708Function V_BCtrTable()
709       
710        // order of the panel names will match the constant string
711        //FT;FB;FL;FR;MT;MB;ML;MR;B;
712        Make/O/T/N=9 panelW
713        Make/O/D/N=9 xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
714        DoWindow/F BCtrTable
715        if(V_flag == 0)
716                Edit/W=(547,621,1076,943)/N=BCtrTable panelW,xCtr_pix,yCtr_pix,xCtr_cm,yCtr_cm
717        endif
718       
719        Variable ii
720        String detStr,fname
721       
722        fname = "RAW"
723        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
724                detStr = StringFromList(ii, ksDetectorListAll, ";")
725                panelW[ii] = detStr
726
727        endfor
728       
729//              xCtr_pix[ii] = V_getDet_beam_center_x_pix(fname,detStr)
730//              yCtr_pix[ii] = V_getDet_beam_center_y_pix(fname,detStr)
731//              // TODO
732//              // and now the mm values
733//              xCtr_mm[ii] = V_getDet_beam_center_x_mm(fname,detStr)
734//              yCtr_mm[ii] = V_getDet_beam_center_y_mm(fname,detStr)
735        return(0)
736End
737
738//
739// to write the new beam center values to a file on disk:
740// V_writeDet_beam_center_x(fname,detStr,val)
741//
742// to write to a local WORK folder
743// V_putDet_beam_center_x(fname,detStr,val)
744//
745Function V_BeamCtr_WriteTable()
746
747        Variable runNumber
748        Prompt runNumber, "enter the run number:"
749        DoPrompt "Pick file to write to",runNumber
750        If(V_flag==1)
751                return(0)
752        endif   
753       
754        String folder
755       
756        Variable ii
757        String detStr,fname
758       
759        Wave xCtr_pix = root:xCtr_pix
760        Wave yCtr_pix = root:yCtr_pix
761        Wave/T panelW = root:PanelW
762       
763
764        fname = V_FindFileFromRunNumber(runNumber)
765
766        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
767//              detStr = StringFromList(ii, ksDetectorListAll, ";")
768                detStr = panelW[ii]
769                V_writeDet_beam_center_x(fname,detStr,xCtr_pix[ii])
770                V_writeDet_beam_center_y(fname,detStr,yCtr_pix[ii])
771               
772                // TODO
773                // and now the mm values
774               
775        endfor
776        return(0)
777       
778End
779
780
781
782
783//////////////////
784//
785// Simple utility to calculate beam centers [cm] based on a single measurement
786//  and empirical relations between the panel zero positions
787//
788// Empirical relations are derived from beam center measurements using 6A data and WB data (9/10/17)
789// only measurements on L, R, and x-coordinate of B were used. T panel cannot be translated down far enough
790// to reach the direct beam.
791//
792// Start with the (default) case of a beam center measured on R (MR or FR)
793//
794// Empirical values are averaged as noted
795//
796
797Proc V_DeriveBeamCenters()
798
799        Make/O/T panelWave = {"FL","FR","FT","FB","ML","MR","MT","MB","B"}
800        Make/O/D/N=9 newXCtr_cm,newYCtr_cm
801       
802        Edit panelWave,newXCtr_cm,newYCtr_cm
803       
804        DoAlert 0, "enter the measured beam center reference for Front and Middle panels"
805        V_fDeriveBeamCenters()
806       
807End
808
809// TODO:
810// if I change any of these values, I need to also change them in the V_FindCentroid function
811// in V_Marquee_Operation.ipf
812Proc V_fDeriveBeamCenters(x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference)
813        Variable x_FrontReference,y_FrontReference,x_MiddleReference,y_MiddleReference
814       
815        // start with the front
816        // FR
817        newXCtr_cm[1] = x_FrontReference
818        newYCtr_cm[1] = y_FrontReference
819        // FL
820        newXCtr_cm[0] = x_FrontReference - (0.03 + 0.03)/2
821        newYCtr_cm[0] = y_FrontReference + (0.34 + 0.32)/2
822        // FB
823        newXCtr_cm[3] = x_FrontReference - (2.02 + 2.06)/2
824        newYCtr_cm[3] = y_FrontReference - (0.12 + 0.19)/2              // (-) is correct here
825        // FT (duplicate FB)
826        newXCtr_cm[2] = newXCtr_cm[3]
827        newYCtr_cm[2] = newYCtr_cm[3]
828       
829        // MR
830        newXCtr_cm[5] = x_MiddleReference
831        newYCtr_cm[5] = y_MiddleReference
832        // ML
833        newXCtr_cm[4] = x_MiddleReference - (0.06 + 0.05)/2
834        newYCtr_cm[4] = y_MiddleReference + (0.14 + 0.01)/2
835        // MB
836        newXCtr_cm[7] = x_MiddleReference - (0.51 + 0.62)/2
837        newYCtr_cm[7] = y_MiddleReference + (0.79 + 0.74)/2
838        // MT (duplicate MB)
839        newXCtr_cm[6] = newXCtr_cm[7]
840        newYCtr_cm[6] = newYCtr_cm[7]   
841       
842       
843        // default value for B
844        newXCtr_cm[8] = 0
845        newYCtr_cm[8] = 0
846
847               
848        return
849End
850
Note: See TracBrowser for help on using the repository browser.