source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_TubeAdjustments.ipf @ 1048

Last change on this file since 1048 was 1048, checked in by srkline, 5 years ago

routines to make it easy to fit the nonlinear spatial coeficients to data from the tube detectors. Assumes that there will be 5 peaks, but this can be adjusted.

File size: 27.4 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3//
4// functions for testing and then actually applying the nonlinear corrections to the
5// tube detectors. These routines are for a test bank of 8 tubes (vertical) that were
6// run at a subdivision of 1024. VSANS will be different in practice
7//
8// but the fundamental process is the same, and can be translated into proper functions as needed
9//
10//
11
12
13//
14// TODO
15// -- need a way to generate the known, physical dimensions of the slots
16// Make/O/D/N=5 peak_spacing_mm_ctr
17// peak_spacing_mm_ctr = {-350,-190,0,190,350} (to be filled in with the correct measurements,
18//   possibly different for each panel)
19//
20// -- a 128 point wave "tube_pixel" (=p) is made in V_ArrayToTubes(), and is needed for the WM
21//   procedures to identify the peak positions.
22//
23// -- fit with either gauss or lor function to get non-integer pixel values for the peak locations
24//
25// -- do I fit each individually to "tweak" the located values, or fit all 5 at once with a
26//    custom fit function and guess some good starting values for peak height, location, etc.
27//
28//
29// -- find a way to display all of the results - in a way that can quickly identify any fits
30//    that may be incorrect
31//
32//
33
34
35
36// the main routines are:
37
38//(1)
39//
40// to get from an array to individual tubes
41// V_ArrayToTubes(detector)
42//
43// (not needed) to get from individual tubes to an array
44//      V_Tubes_to_Array()                     
45
46//(2)
47// then to locate all of the peak positions
48//      V_MakeTableForPeaks(numTube,numPeak)           
49//      V_Identify_AllPeaks()
50//              AutoFindPeaksCustom()           // if Identify_AllPeaks  doesn't work -try this, setting the "noise" to 1 and smoothing to 2
51
52// (3) Refine the fitted peak positions
53//
54
55//(4)
56// fit to find all of the quadratic coefficients
57//      MakeTableForFitCoefs(numTube,numCoef)
58//      PlotFit_AllPeaks()
59
60
61//(5)
62// then pick a display method
63//
64//      Make_mm_tubes()
65//      Append_Adjusted_mm()
66//
67//      MakeMatrix_PixCenter()
68//      FillMatrix_Pix_Center(ind)
69//
70//
71// -or- (note that the pack_image wave that is generated here is for display ONLY)
72// --since it is interpolated
73//
74// Interpolate_mm_tubes()
75
76
77// The function most used externally is:
78// V_TubePix_to_mm(c0,c1,c2,pix)
79//
80// which will return the real space distance (in mm?) for a given pixel
81// and the tube's coefficients. The distance is relative to the zero position on the
82// detector (which was defined when the coefficients were determined)
83
84
85
86//
87// (0) -- what I start with:
88// -- a table of the mm spacing of the slots (20 of them)
89// -- masked data from each of the (8) tubes
90// -- the table of slots may need to be corrected for parallax, depending on the geometry of the test
91// ** In the table of slots, pick a slot near the center, and SET that to ZERO. Then all of the other
92//   distances are relative to that zero point. This is a necessary reference point.
93//
94
95// TODO
96// -- need a routine to set up the actual measurements of the slot positions
97//
98//
99// TODO
100// -- the slot positioning may be different for the L/R and T/B detectors
101//
102Proc V_SetupSlotDimensions()
103        Make/O/D/N=5 peak_spacing_mm_ctr
104        peak_spacing_mm_ctr = {-350,-190,0,190,350}
105        DoWindow/F Real_mm_Table
106        if(V_Flag == 0)
107                Edit/N=Real_mm_Table peak_spacing_mm_ctr
108        endif
109End
110
111
112
113//
114// (1) -- get the individual tubes into an array
115//
116//
117Proc V_Tubes_to_Array()
118        Make/O/D/N=(8,1127) pack
119        edit pack
120        display;appendimage pack
121        pack[0][] = tube1[q]
122        pack[1][] = tube2[q]
123        pack[2][] = tube3[q]
124        pack[3][] = tube4[q]
125        pack[4][] = tube5[q]
126        pack[5][] = tube6[q]
127        pack[6][] = tube7[q]
128        pack[7][] = tube8[q]
129        ModifyImage pack ctab= {*,*,ColdWarm,0}
130End
131
132// or the other way around
133Proc V_ArrayToTubes(wStr)
134        String wStr
135       
136        Variable ii,numTubes=48
137        String str="tube"
138       
139        Variable dim0,dim1
140        dim0 = DimSize($wStr,0)
141        dim1 = DimSize($wStr,1)
142
143       
144        Make/O/D/N=128 tube_pixel
145        tube_pixel = p
146       
147       
148        ii=0
149        do
150                Make/O/D/N=128 $(str+num2str(ii))
151               
152                if(dim0 == 128)
153                        $(str+num2str(ii)) = $(wStr)[p][ii]
154                else
155                        $(str+num2str(ii)) = $(wStr)[ii][p]
156                endif
157               
158                ii+=1
159        while(ii < numTubes)
160
161End
162
163
164// (2) -- for each of the tubes, find the x-position (in pixels) of each of the (20) peaks
165// -- load the Analysis Package "MultiPeakFit 2"
166//
167// automatically find the peaks (after including MultiPeakFit 2)
168//              AutomaticallyFindPeaks()
169//
170//-- or if having difficulty
171//              AutoFindPeaksCustom()           // try this, setting the "noise" to 1 and smoothing to 2
172//
173// -- if really having difficulty, you can do the "full" MultiPeak Fit
174//
175// -- If (hopefully) using the easy way, the results are in:
176// root:WA_PeakCentersY,root:WA_PeakCentersX
177//
178// -- so to see the results:
179//¥Edit/K=0  root:WA_PeakCentersY,root:WA_PeakCentersX
180//
181// -- then sort the results - they seem to be in no real order...
182//¥Sort WA_PeakCentersX WA_PeakCentersY,WA_PeakCentersX
183//
184Proc V_MakeTableForPeaks(numTube,numPeak)
185        Variable numTube=48,numPeak=5
186       
187        Make/O/D/N=(numPeak,numTube) PeakTableX,PeakTableY              //*2 to store x-location and peak height (y)
188       
189        DoWindow/F Peak_Pixel_Loc
190        if(V_flag == 0)
191                Edit/N=Peak_Pixel_Loc peakTableX
192        endif
193        DoAlert 0, "Load the Package: Analysis->MultiPeak Fitting->MultiPeak Fitting 2"
194End
195
196Proc V_Identify_AllPeaks()
197
198        Variable ii,numTubes=48
199        String str="tube"
200       
201        ii=0
202        do
203                V_Identify_Peaks(str+num2str(ii),ii)
204                ii+=1
205        while(ii < numTubes)
206
207End
208
209Proc V_Identify_Peaks(tubeStr,ind)
210        String tubeStr
211        Variable ind
212       
213        // must use a wave of pixels rather than "calculated" -- if calculated is used it only
214        // returns integer values for the peak locations
215       
216//      AutomaticallyFindPeaks() //-- this is a function that doesn't take any parameters - so
217// I need to pull this from the WM function to call the worker directly
218        Variable pBegin=0, pEnd= numpnts($(tubeStr))-1
219        Variable/C estimates= EstPeakNoiseAndSmfact($(tubeStr),pBegin, pEnd)
220        Variable noiselevel=real(estimates)
221        Variable smoothingFactor=imag(estimates)
222        Variable maxPeaks = 20
223        Variable minPeakPercent = 10
224       
225        AutoFindPeaksWorker($(tubeStr), $("tube_pixel"), pBegin, pEnd, maxPeaks, minPeakPercent, noiseLevel, smoothingFactor)
226// end WM function call
227
228        Sort WA_PeakCentersX WA_PeakCentersY,WA_PeakCentersX
229       
230        peakTableX[][ind] = WA_PeakCentersX[p]          // the peak position
231        peakTableY[][ind] = WA_PeakCentersY[p]          // the peak height
232       
233End
234
235
236
237
238// ADD
239// a step to refine the peak positioning - currently an integer value
240//  fit with a gauss or lorentzian
241
242// CurveFit/M=2/W=0/TBOX=(0x310) lor, tube47[29,53]/X=tube_pixel[29,53]/D
243
244//CurveFit/M=2/W=0 lor, tube47[29,53]/X=tube_pixel[29,53]/D
245//fit_tube47= W_coef[0]+W_coef[1]/((x-W_coef[2])^2+W_coef[3])
246//W_coef={-20.37,876.94,40.078,0.5201}
247//W_sigma={6.52,47.3,0.0241,0.0308}
248
249Proc V_MakeTableForRefinedFit(numTube,numPeak)
250        Variable numTube=48,numPeak=5
251       
252        Make/O/D/N=(numPeak,numTube) position_refined,position_refined_err              //
253       
254        DoWindow/F Refined_Positions
255        if(V_flag == 0)
256                Edit/N=Refined_Positions position_refined
257        endif
258End
259
260Proc V_Refine_All_PeakPos()
261
262        Variable ii,numTubes=48
263       
264        ii=0
265        do
266                V_Refine_PeakPos(ii)
267                ii+=1
268        while(ii<numTubes)
269
270End
271
272
273//CurveFit/M=2/W=0 lor, tube47[29,53]/X=tube_pixel[29,53]/D
274//fit_tube47= W_coef[0]+W_coef[1]/((x-W_coef[2])^2+W_coef[3])
275
276Proc V_Refine_PeakPos(ind)
277        Variable ind
278       
279// TODO
280// -- hard-wired for 5 peaks
281
282        Variable ii,lo,hi
283       
284       
285        ii=0
286        do
287       
288                if(ii==0)
289                // 1st peak
290                // define fitting range pixels (integer)
291                        lo = 0
292                else
293                        lo = trunc(0.5*(peakTableX[ii-1][ind] + peakTableX[ii][ind]))
294                endif
295               
296                if(ii==4)
297                        hi = numpnts(tube_pixel)-1
298                else
299                        hi = trunc(0.5*(peakTableX[ii][ind] + peakTableX[ii+1][ind]))
300                endif
301               
302                // do I need initial guesses?
303                CurveFit/M=0/W=2 lor, $("tube"+num2str(ind))[lo,hi]/X=tube_pixel[lo,hi]/D
304               
305                position_refined[ii][ind] = W_coef[2]
306                position_refined_err[ii][ind] = W_sigma[2]
307
308                ii += 1
309
310        while(ii < 5)
311       
312End
313
314
315
316
317
318// -- save a copy of the root:WA_PeakCentersY,root:WA_PeakCentersX values
319//    for later in case the fitting failed, then you can go back and re-do
320//
321// -- then plot:
322//
323//      Display peak_spacing_mm_ctr vs WA_PeakCentersX
324//
325//      Then do a "QuickFit" of the peak position to the data using a polynomial of order 3 (= quadratic)
326//
327// result is in W_coef, W_sigma
328//
329// -- an example of the "quickFit" command is below, so it can be programmed rather than the menu every time
330//¥Display peak_spacing_mm_ctr vs WA_PeakCentersX3
331//¥CurveFit/M=2/W=0/TBOX=(0x310) poly 3, peak_spacing_mm_ctr/X=WA_PeakCentersX3/D
332//  fit_peak_spacing_mm_ctr= poly(W_coef,x)
333//  W_coef={-571.42,1.1135,-4.2444e-05}
334//  V_chisq= 8.5841;V_npnts= 20;V_numNaNs= 0;V_numINFs= 0;
335//  V_startRow= 0;V_endRow= 19;
336//  W_sigma={0.595,0.00246,2.15e-06}
337//  Coefficient values ± one standard deviation
338//      K0      =-571.42 ± 0.595
339//      K1      =1.1135 ± 0.00246
340//      K2      =-4.2444e-05 ± 2.15e-06
341//
342//
343//
344// for (8) tubes, keep all of the fit coefficients
345//
346//¥make/O/D/N=(3,8) fit_coef
347//¥edit fit_coef
348//¥make/O/D/N=(3,8) fit_sigma
349//¥edit fit_sigma
350//
351// -- copy and paste in the W_coef and W_sigma values (or by a command)
352//
353
354
355Proc V_MakeTableForFitCoefs(numTube,numCoef)
356        Variable numTube=48,numCoef=3
357       
358        Make/O/D/N=(numTube,numCoef) TubeCoefTable,TubeSigmaTable               //
359       
360        DoWindow/F Quad_Coefficients
361        if(V_flag == 0)
362                Edit/N=Quad_Coefficients TubeCoefTable
363        endif
364End
365
366Proc V_PlotFit_AllPeakPosition()
367
368        Variable ii,numTubes=48
369       
370        ii=0
371        do
372                V_PlotFit_PeakPosition(ii)
373                ii+=1
374        while(ii<numTubes)
375
376End
377
378Proc V_PlotFit_PeakPosition(ind)
379        Variable ind
380       
381        Duplicate/O WA_PeakCentersX, tmpX
382       
383//      tmpX = peakTableX[p][ind]
384        tmpX = position_refined[p][ind]
385//      Display peak_spacing_mm_ctr vs tmpX
386       
387//      CurveFit/M=2/W=0/TBOX=(0x310) poly 3, peak_spacing_mm_ctr/X=tmpX/D
388        CurveFit/M=0/W=2 poly 3, peak_spacing_mm_ctr/X=tmpX/D
389       
390        TubeCoefTable[ind][] = W_coef[q]
391        TubeSigmaTable[ind][] = W_sigma[q]
392       
393End
394
395
396
397
398
399//¥Duplicate tube1 tube1_mm
400//¥tube1_mm = V_TubePix_to_mm(fit_coef[0][0],fit_coef[1][0],fit_coef[2][0],p)
401
402
403
404
405////////
406// then there are various display options:
407
408// adjust the center (pixel) of the tube:
409// - measCtr is the pixel location of the DEFINED "zero" peak
410// nominal Ctr is the pixel number of this DEFINED zer0 position, nominally nPix/2-1
411//
412// ( be sure to pick better names, and use a loop...)
413//      adj_tube = raw_tube[p+(measCtr-nominalCtr)]
414//
415// then fill and display a new matrix. The center will be reasonably well aligned, and will
416// get worse towards the ends of the tubes
417// (this may be the "preferred" way of displaying the raw data if the centers are far off)
418// -- this also may be what I need to start with to fit the data to locate the beam center.
419
420
421// I can also display the fully corrected tubes, where the y-axis is now in real-space mm
422// rather than arbitrary pixels. The x-axis is still tube nubmer.
423// -- do this with the procedure"
424//   Append_Adjusted_mm()               // name may change...
425//
426// -- the point of the appending is that it allows each tube to be plotted on an image plot
427// with its own y-axis. Every one will be different and will be non-linear. These conditions
428// BOTH prevent using any of the "normal" image plotting or manipulation routines.
429// - the gist is below:
430//
431//      duplicate tube1_mm adjusted_mm_edge
432//      InsertPoints 0,1, adjusted_mm_edge
433//      // be sure to use the correct set of coefficients
434//      adjusted_mm_edge[0] = V_TubePix_to_mm(fit_coef[0][0],fit_coef[1][0],fit_coef[2][0],-1)
435//     
436//      Display;AppendImage adjusted_pack vs {*,adjusted_mm_edge}
437
438
439Proc V_Make_mm_tubes()
440
441        Variable ii,numTubes=8
442       
443        ii=1
444        do
445                Duplicate $("tube"+num2str(ii)) $("tube"+num2str(ii)+"_mm")
446                $("tube"+num2str(ii)+"_mm") = V_TubePix_to_mm(TubeCoefTable[ii-1][0],TubeCoefTable[ii-1][1],TubeCoefTable[ii-1][2],p)
447                ii+=1
448        while(ii<=numTubes)
449       
450End
451
452
453Proc V_Append_Adjusted_mm()
454
455// a blank base image
456        Duplicate/O pack junk
457        junk=0
458        SetScale/I y -600,600,"", junk          // -600,600 is tooo large and not general
459        Display;Appendimage junk
460
461        Variable ii
462       
463        ii=1
464        do
465                make/O/D/N=(1,1127) $("tube"+num2str(ii)+"_mm_mat")=0   
466       
467                $("tube"+num2str(ii)+"_mm_mat")[0][] = $("tube"+num2str(ii))
468                SetScale/I x (ii-1),ii,"", $("tube"+num2str(ii)+"_mm_mat")              //builds up the x-axis
469               
470                duplicate/O $("tube"+num2str(ii)+"_mm") $("edge"+num2str(ii)+"_mm")
471                InsertPoints 0,1, $("edge"+num2str(ii)+"_mm")           //needs to be one point longer
472        // be sure to use the correct set of coefficients
473                $("edge"+num2str(ii)+"_mm")[0] = V_TubePix_to_mm(TubeCoefTable[0][0],TubeCoefTable[0][1],TubeCoefTable[0][2],-1)
474       
475                AppendImage $("tube"+num2str(ii)+"_mm_mat") vs {*,$("edge"+num2str(ii)+"_mm")}
476                ModifyImage $("tube"+num2str(ii)+"_mm_mat") ctab= {*,*,ColdWarm,0}
477       
478                ii+=1
479        while(ii < 9)
480       
481end
482
483
484
485////////////////////////////////
486
487Proc V_MakeMatrix_PixCenter()
488        Duplicate/O pack pack_centered
489       
490        Variable ii,numTubes=8
491       
492        ii=1
493        do
494                V_FillMatrix_Pix_Center(ii)
495                ii+=1
496        while(ii<=numTubes)
497       
498        Display;AppendImage pack_centered
499        ModifyImage pack_centered ctab= {*,*,ColdWarm,0}
500
501end
502
503//
504// this fills a matrix with the tubes center aligned ONLY, with the y-axis in pixels
505//
506// adj_tube = raw_tube[p+(measCtr-nominalCtr)]
507// finds the center automatically from the tubeN_mm wave, where it crosses zero
508//
509// Tube #1 is the "base" ans others are shifted to match that one's "zero"
510//
511// FindRoots/P=W_coef           can also be used to find the roots (but which one?)
512//
513Function V_FillMatrix_Pix_Center(ind)
514        Variable ind
515       
516        Wave adj=root:pack_centered
517        Wave tube1_mm = $("root:tube1_mm")
518        Wave tube = $("root:tube"+num2str(ind))
519        wave tube_mm = $("root:tube"+num2str(ind)+"_mm")
520
521        Variable base,shift,ii,num,pt
522       
523        num=numpnts(tube)
524       
525        FindLevel tube1_mm 0
526        base = round(V_LevelX)
527       
528       
529        FindLevel tube_mm 0
530        shift = round(V_LevelX)
531       
532        for(ii=0;ii<num;ii+=1)
533                pt = ii + (shift-base)
534                if(pt >= 0 && pt < num)
535                        adj[ind-1][ii] = tube[pt]
536                endif
537        endfor
538       
539        return(0)
540End
541
542
543// this fills a matrix with the tubes center aligned ONLY, with the y-axis in mm
544// -- there seems to be little reason to do this --
545// -- either keep pixels and align centers
546// -- OR -- use mm and append each tube with its own y-axis
547//
548Function V_FillAdjusted(ind)
549        Variable ind
550       
551        Wave adj=root:adjusted_pack
552        Wave tube1_mm
553        Wave tube = $("root:tube"+num2str(ind))
554        wave tube_mm = $("root:tube"+num2str(ind)+"_mm")
555
556        Variable base,shift,ii,num,pt
557       
558        num=numpnts(tube1_mm)
559       
560        FindLevel tube1_mm 0
561        base = round(V_LevelX)
562       
563       
564        FindLevel tube_mm 0
565        shift = round(V_LevelX)
566       
567        for(ii=0;ii<num;ii+=1)
568                pt = ii + (shift-base)
569                if(pt >= 0 && pt < num)
570                        adj[ind-1][ii] = tube[pt]
571                endif
572        endfor
573       
574        return(0)
575End
576
577
578// c0,c1,c2,pix
579// c0-c2 are the fit coefficients
580// pix is the test pixel
581//
582// returns the distance in mm (relative to ctr pixel)
583// ctr is the center pixel, as defined when fitting to quadratic
584//
585Function V_TubePix_to_mm(c0,c1,c2,pix)
586        Variable c0,c1,c2,pix
587       
588        Variable dist
589        dist = c0 + c1*pix + c2*pix*pix
590       
591        return(dist)
592End
593
594////
595
596
597
598// set the (linear) range of the y-axis of the matrix to be the
599// range of the 1st tube. This is completely arbitrary
600//
601Proc V_Interpolate_mm_tubes()
602
603        Duplicate/O pack pack_image
604
605        Variable ii,numTubes=8
606        Variable p1,p2
607        p1 = tube1_mm[0]
608        p2 = tube1_mm[numpnts(tube1_mm)-1]
609       
610        SetScale/I y p1,p2,"", pack_image
611       
612        // then make a temporary 1D wave to help with the interpolation
613        Duplicate/O tube1_mm lin_mm,lin_val
614        SetScale/I x p1,p2,"", lin_mm
615        lin_mm = x                      //fill with the linear mm spacing
616        lin_val=0
617       
618        ii=1
619        do
620                lin_val = interp(lin_mm, $("tube"+num2str(ii)+"_mm"), $("tube"+num2str(ii)))
621                pack_image[ii-1][] = lin_val[q]
622               
623                ii+=1
624        while(ii<=numTubes)
625       
626        display;appendimage pack_image
627        ModifyImage pack_image ctab= {*,*,ColdWarm,0}
628       
629End
630
631
632
633
634
635
636
637
638
639
640
641
642
643// this doesn't work - the interpolation step doesn't do what I want
644// and the plot of the triplet with f(z) for color doesn't fill space like I want
645Proc V_AnotherExample()
646
647        Concatenate/O/NP {tube1_mm,tube2_mm,tube3_mm,tube4_mm,tube5_mm,tube6_mm,tube7_mm,tube8_mm},cat_mm
648        Concatenate/O/NP {tube1,tube2,tube3,tube4,tube5,tube6,tube7,tube8},cat_tubes
649        Duplicate/O cat_mm,cat_num
650        Variable num=1127
651        cat_num[0,num-1]=1
652        cat_num[num,2*num-1]=2
653        cat_num[2*num,3*num-1]=3
654        cat_num[3*num,4*num-1]=4
655        cat_num[4*num,5*num-1]=5
656        cat_num[5*num,6*num-1]=6
657        cat_num[6*num,7*num-1]=7
658        cat_num[7*num,8*num-1]=8
659
660        Display cat_mm vs cat_num
661        ModifyGraph mode=3,marker=9
662        ModifyGraph zColor(cat_mm)={cat_tubes,*,*,ColdWarm,0}
663
664        Concatenate/O {cat_num,cat_mm,cat_tubes}, tripletWave
665        ImageInterpolate Kriging tripletWave
666        AppendImage M_InterpolatedImage
667
668//      Make/O/N=20 xWave=enoise(4),yWave=enoise(5),zWave=enoise(6)  // Random points
669//      Display yWave vs xWave
670//      ModifyGraph mode=3,marker=19
671//      ModifyGraph zColor(yWave)={zWave,*,*,Rainbow,0}
672//
673//      Concatenate/O {xWave,yWave,zWave}, tripletWave
674//      ImageInterpolate/S={-5,0.1,5,-5,0.1,5} voronoi tripletWave
675//      AppendImage M_InterpolatedImage
676
677end
678
679// this desn't work either...
680// (same y-axis for the entire image, which is not the case for the tubes)
681//
682// from the WM help file:
683// Plotting a 2D Z Wave With 1D X and Y Center Data
684//
685Function V_MakeEdgesWave(centers, edgesWave)
686        Wave centers    // Input
687        Wave edgesWave  // Receives output
688       
689        Variable N=numpnts(centers)
690        Redimension/N=(N+1) edgesWave
691
692        edgesWave[0]=centers[0]-0.5*(centers[1]-centers[0])
693        edgesWave[N]=centers[N-1]+0.5*(centers[N-1]-centers[N-2])
694        edgesWave[1,N-1]=centers[p]-0.5*(centers[p]-centers[p-1])
695End
696
697//This function demonstrates the use of MakeEdgesWave:
698Function V_DemoPlotXYZAsImage()
699        Make/O mat={{0,1,2},{2,3,4},{3,4,5}}    // Matrix containing Z values
700        Make/O centersX = {1, 2.5, 5}           // X centers wave
701        Make/O centersY = {300, 400, 600}               // Y centers wave
702        Make/O edgesX; V_MakeEdgesWave(centersX, edgesX)        // Create X edges wave
703        Make/O edgesY; V_MakeEdgesWave(centersY, edgesY)        // Create Y edges wave
704        Display; AppendImage mat vs {edgesX,edgesY}
705End
706
707
708
709////////////////////////////
710
711Proc V_TubeCoefPanel() : Panel
712        PauseUpdate; Silent 1           // building window...
713        NewPanel /W=(973,45,1156,535)/K=1
714        DoWindow/C V_TubeCoefPanel
715//      ShowTools/A
716
717        SetDrawLayer UserBack
718        SetDrawEnv fsize= 14,fstyle= 1
719        DrawText 5,58,"(1)"
720        SetDrawEnv fsize= 14,fstyle= 1
721        DrawText 5,108,"(2)"
722        SetDrawEnv fsize= 14,fstyle= 1
723        DrawText 5,158,"(3)"
724        SetDrawEnv fsize= 14,fstyle= 1
725        DrawText 5,208,"(4)"
726        SetDrawEnv fsize= 14,fstyle= 1
727        DrawText 5,258,"(5)"
728        SetDrawEnv fsize= 14,fstyle= 1
729        DrawText 5,308,"(6)"
730        SetDrawEnv fsize= 14,fstyle= 1
731        DrawText 5,358,"(7)"
732        SetDrawEnv fsize= 14,fstyle= 1
733        DrawText 5,408,"(8)"
734        SetDrawEnv fsize= 14,fstyle= 1
735        DrawText 5,458,"(9)"
736                       
737        Button button_0,pos={30.00,40.00},size={120.00,20.00},proc=V_Setup_MasksButton,title="Setup"
738        Button button_1,pos={30.00,90.00},size={120.00,20.00},proc=V_ArrayToTubesButton,title="Array to Tubes"
739        Button button_2,pos={30.00,140.00},size={120.00,20.00},proc=V_TableForPeaksButton,title="Table for Peaks"
740        Button button_3,pos={30.00,190.00},size={120.00,20.00},proc=V_IdentifyPeaksButton,title="Identify Peaks"
741        Button button_4,pos={30.00,240.00},size={120.00,20.00},proc=V_RefineTableButton,title="Refine Peak Table"
742        Button button_5,pos={30.00,290.00},size={120.00,20.00},proc=V_RefinePeaksButton,title="Refine Peaks"
743
744        Button button_6,pos={30.00,340.00},size={120.00,20.00},proc=V_QuadFitTableButton,title="Table for Quad"
745        Button button_7,pos={30.00,390.00},size={120.00,20.00},proc=V_QuadFitButton,title="Fit to Quad"
746        Button button_8,pos={30.00,440},size={120.00,20.00},proc=V_PeakPlotButton,title="Plot Peaks"
747       
748EndMacro
749
750
751Function V_PeakPlotButton(ba) : ButtonControl
752        STRUCT WMButtonAction &ba
753
754        switch( ba.eventCode )
755                case 2: // mouse up
756                        // click code here
757                        Execute "V_OpenPeakResultsGraph()"
758                        break
759                case -1: // control being killed
760                        break
761        endswitch
762
763        return 0
764End
765
766
767Function V_TableForPeaksButton(ba) : ButtonControl
768        STRUCT WMButtonAction &ba
769
770        switch( ba.eventCode )
771                case 2: // mouse up
772                        // click code here
773                        Execute "V_MakeTableForPeaks()"
774                        break
775                case -1: // control being killed
776                        break
777        endswitch
778
779        return 0
780End
781
782
783Function V_IdentifyPeaksButton(ba) : ButtonControl
784        STRUCT WMButtonAction &ba
785
786        switch( ba.eventCode )
787                case 2: // mouse up
788                        // click code here
789                        Execute "V_Identify_AllPeaks()"
790                        break
791                case -1: // control being killed
792                        break
793        endswitch
794
795        return 0
796End
797
798Function V_RefineTableButton(ba) : ButtonControl
799        STRUCT WMButtonAction &ba
800
801        switch( ba.eventCode )
802                case 2: // mouse up
803                        // click code here
804                        Execute "V_MakeTableForRefinedFit()"
805                        break
806                case -1: // control being killed
807                        break
808        endswitch
809
810        return 0
811End
812
813Function V_RefinePeaksButton(ba) : ButtonControl
814        STRUCT WMButtonAction &ba
815
816        switch( ba.eventCode )
817                case 2: // mouse up
818                        // click code here
819                        Execute "V_Refine_All_PeakPos()"
820                        break
821                case -1: // control being killed
822                        break
823        endswitch
824
825        return 0
826End
827
828Function V_QuadFitTableButton(ba) : ButtonControl
829        STRUCT WMButtonAction &ba
830
831        switch( ba.eventCode )
832                case 2: // mouse up
833                        // click code here
834                        Execute "V_MakeTableForFitCoefs()"
835                        break
836                case -1: // control being killed
837                        break
838        endswitch
839
840        return 0
841End
842
843Function V_QuadFitButton(ba) : ButtonControl
844        STRUCT WMButtonAction &ba
845
846        switch( ba.eventCode )
847                case 2: // mouse up
848                        // click code here
849                        Execute "V_PlotFit_AllPeakPosition()"
850                        break
851                case -1: // control being killed
852                        break
853        endswitch
854
855        return 0
856End
857
858
859
860Function V_Setup_MasksButton(ba) : ButtonControl
861        STRUCT WMButtonAction &ba
862
863        switch( ba.eventCode )
864                case 2: // mouse up
865                        // click code here
866                        Execute "V_SetupSlotDimensions()"
867                        break
868                case -1: // control being killed
869                        break
870        endswitch
871
872        return 0
873End
874
875
876
877Function V_ArrayToTubesButton(ba) : ButtonControl
878        STRUCT WMButtonAction &ba
879
880        switch( ba.eventCode )
881                case 2: // mouse up
882                        // click code here
883                        Execute "V_ArrayToTubes()"
884                        break
885                case -1: // control being killed
886                        break
887        endswitch
888
889        return 0
890End
891
892
893///////////////////////////
894
895
896Window Gizmo_refinedPositions() : GizmoPlot
897        PauseUpdate; Silent 1           // building window...
898        // Building Gizmo 7 window...
899        NewGizmo/W=(232,448,747,908)
900        ModifyGizmo startRecMacro=700
901        ModifyGizmo scalingOption=63
902        AppendToGizmo Surface=root:position_refined,name=surface0
903        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ srcMode,0}
904        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ surfaceCTab,Rainbow}
905        AppendToGizmo Axes=boxAxes,name=axes0
906        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,axisRange,-1,-1,-1,1,-1,-1}
907        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,axisRange,-1,-1,-1,-1,1,-1}
908        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,axisRange,-1,-1,-1,-1,-1,1}
909        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={3,axisRange,-1,1,-1,-1,1,1}
910        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={4,axisRange,1,1,-1,1,1,1}
911        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={5,axisRange,1,-1,-1,1,-1,1}
912        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={6,axisRange,-1,-1,1,-1,1,1}
913        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={7,axisRange,1,-1,1,1,1,1}
914        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={8,axisRange,1,-1,-1,1,1,-1}
915        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={9,axisRange,-1,1,-1,1,1,-1}
916        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={10,axisRange,-1,1,1,1,1,1}
917        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={11,axisRange,-1,-1,1,1,-1,1}
918        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisScalingMode,1}
919        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisColor,0,0,0,1}
920        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,ticks,2}
921        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,ticks,2}
922        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,ticks,2}
923        ModifyGizmo modifyObject=axes0,objectType=Axes,property={-1,Clipped,0}
924        ModifyGizmo setDisplayList=0, object=surface0
925        ModifyGizmo setDisplayList=1, object=axes0
926        ModifyGizmo autoscaling=1
927        ModifyGizmo currentGroupObject=""
928        ModifyGizmo showInfo
929        ModifyGizmo infoWindow={651,303,1468,602}
930        ModifyGizmo endRecMacro
931        ModifyGizmo SETQUATERNION={0.573113,-0.115160,-0.275160,0.763255}
932EndMacro
933
934Window Gizmo_DetPanel() : GizmoPlot
935        PauseUpdate; Silent 1           // building window...
936        // Building Gizmo 7 window...
937        NewGizmo/W=(96,290,611,750)
938        ModifyGizmo startRecMacro=700
939        ModifyGizmo scalingOption=63
940        AppendToGizmo Surface=root:slices_L,name=surface0
941        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ srcMode,0}
942        ModifyGizmo ModifyObject=surface0,objectType=surface,property={ surfaceCTab,ColdWarm}
943        AppendToGizmo Axes=boxAxes,name=axes0
944        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,axisRange,-1,-1,-1,1,-1,-1}
945        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,axisRange,-1,-1,-1,-1,1,-1}
946        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,axisRange,-1,-1,-1,-1,-1,1}
947        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={3,axisRange,-1,1,-1,-1,1,1}
948        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={4,axisRange,1,1,-1,1,1,1}
949        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={5,axisRange,1,-1,-1,1,-1,1}
950        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={6,axisRange,-1,-1,1,-1,1,1}
951        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={7,axisRange,1,-1,1,1,1,1}
952        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={8,axisRange,1,-1,-1,1,1,-1}
953        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={9,axisRange,-1,1,-1,1,1,-1}
954        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={10,axisRange,-1,1,1,1,1,1}
955        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={11,axisRange,-1,-1,1,1,-1,1}
956        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisScalingMode,1}
957        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={-1,axisColor,0,0,0,1}
958        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={0,ticks,3}
959        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={1,ticks,3}
960        ModifyGizmo ModifyObject=axes0,objectType=Axes,property={2,ticks,3}
961        ModifyGizmo modifyObject=axes0,objectType=Axes,property={-1,Clipped,0}
962        AppendToGizmo Surface=root:position_refined,name=surface1
963        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ fillMode,4}
964        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ srcMode,0}
965        ModifyGizmo ModifyObject=surface1,objectType=surface,property={ surfaceCTab,Rainbow}
966        ModifyGizmo setDisplayList=0, object=axes0
967        ModifyGizmo setDisplayList=1, object=surface0
968        ModifyGizmo autoscaling=1
969        ModifyGizmo currentGroupObject=""
970        ModifyGizmo showInfo
971        ModifyGizmo infoWindow={550,23,1367,322}
972        ModifyGizmo endRecMacro
973        ModifyGizmo SETQUATERNION={0.499484,-0.278571,-0.448869,0.686609}
974EndMacro
975
976
977////////////////////////////////////
978//
979// An easy way to see the fit results to check if the peak locations all make sense.
980//
981Proc V_OpenPeakResultsGraph()
982
983        DoWindow/F V_PeakResultsGraph
984        if(V_flag == 0)
985                Make/O/D/N=5 tmpPeak,dummyLevel
986                Make/O/D/N=128 tmpTube
987               
988                tmpPeak = position_refined[p][0]
989                dummyLevel = WaveMax(tube0)
990                tmpTube = tube0
991               
992                V_PeakResultsGraph()
993        endif
994
995End
996
997Window V_PeakResultsGraph() : Graph
998        PauseUpdate; Silent 1           // building window...
999        Display /W=(750,45,1161,376)/K=1 tmpTube vs tube_pixel
1000       
1001        ControlBar 50
1002       
1003       
1004        AppendToGraph dummyLevel vs tmpPeak
1005        ModifyGraph mode(dummyLevel)=3
1006        ModifyGraph marker(dummyLevel)=19
1007        ModifyGraph rgb(dummyLevel)=(1,16019,65535)
1008       
1009        SetVariable setvar0,pos={10.00,10.00},size={120.00,14.00},proc=V_TubePeakSetVarProc,title="Tube"
1010        SetVariable setvar0,limits={0,47,1},value= _NUM:0
1011       
1012        Label left "Counts"
1013        Label bottom "Pixel Number"
1014EndMacro
1015
1016
1017Function V_TubePeakSetVarProc(sva) : SetVariableControl
1018        STRUCT WMSetVariableAction &sva
1019
1020        switch( sva.eventCode )
1021                case 1: // mouse up
1022                case 2: // Enter key
1023                case 3: // Live update
1024                        Variable dval = sva.dval
1025                        String sval = sva.sval
1026                       
1027                        Wave tmpPeak = tmpPeak
1028                        Wave dummyLevel = dummyLevel
1029                        Wave tmpTube = tmpTube
1030                       
1031                        Wave pos_ref = position_refined
1032                        Wave tube = $("tube"+num2str(dval))
1033                       
1034                        tmpPeak = pos_ref[p][dval]
1035                        dummyLevel = WaveMax(tube)
1036                        tmpTube = tube
1037               
1038                        break
1039                case -1: // control being killed
1040                        break
1041        endswitch
1042
1043        return 0
1044End
1045
1046////////////////////////////////////
1047
1048
Note: See TracBrowser for help on using the repository browser.