source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_FlipperPanel.ipf @ 817

Last change on this file since 817 was 817, checked in by srkline, 12 years ago

more changes and addtions to the polarization reduction. basic functionality is now present, with a really large panel to gather all of the input. Lots of testing is needed.

File size: 24.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3// input panels to set and calculate polarization parameters necessary for the
4// matrix corrections to the cross sections
5//
6//
7// -3-Flipper efficiency
8
9
10//
11// TODO:
12// X- add a way to manually enter the P values into a "blank" condition, in case that the users
13// calculate the values in a different way. This should be as simple as a dialog to enter values and
14// change the wave note (and displayed strings).
15//
16//
17// Polarization parameters for each condition. Results are stored in a wave note for each condition
18//
19//
20// str = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
21//
22// two waves per condition "Cond_Name_Cell" and "CondCalc_Name_Cell"
23//
24Macro ShowFlipperPanel()
25       
26        // init folders
27        // ASK before initializing cell constants
28        // open the panel
29        DoWindow/F FlipperPanel
30        if(V_flag == 0)
31                InitPolarizationFolders()
32                InitFlipperGlobals()
33                DrawFlipperPanel()
34        endif
35end
36
37Function InitFlipperGlobals()
38
39        SetDataFolder root:Packages:NIST:Polarization:Cells
40       
41        String/G gPsmPf = "Psm*Pf"
42        String/G gPsm = "Psm"
43       
44        SetDataFolder root:
45        return(0)
46End
47
48
49//
50// makes the panel for the calculation of flipper and supermirror efficiencies
51//
52Function DrawFlipperPanel()
53
54        SetDataFolder root:Packages:NIST:Polarization:Cells
55       
56        PauseUpdate; Silent 1           // building window...
57        NewPanel /W=(1023,44,1832,526)/N=FlipperPanel/K=1 as "Flipper and Supermirror"
58        ModifyPanel cbRGB=(1,52428,26586)
59       
60        PopupMenu popup_0,pos={32,18},size={49,20},title="Field Condition",proc=FlipperPanelPopMenuProc
61        PopupMenu popup_0,mode=1,value= #"D_ConditionNameList()"
62       
63        Button button_0,pos={42,310},size={100,20},proc=FlipperAverageButtonProc,title="Do Average"
64       
65        GroupBox group_0,pos={39,350},size={335,103},title="AVERAGED RESULTS",fSize=10
66        GroupBox group_0,fStyle=1
67        SetVariable setvar_0,pos={49,385},size={250,15},title="Sam_depol*Psm*Pf"
68        SetVariable setvar_0,fStyle=1
69        SetVariable setvar_0,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsmPf
70        SetVariable setvar_1,pos={49,417},size={250,15},title="Sam_depol*Psm",fStyle=1
71        SetVariable setvar_1,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsm
72//      SetVariable setvar_2,pos={560,518},size={200,13},title="Gamma (h)",fStyle=1
73//      SetVariable setvar_2,limits={0,0,0},barmisc={0,1000}
74//      SetVariable setvar_2,value= root:Packages:NIST:Polarization:Cells:gGamma
75//      SetVariable setvar_3,pos={560,488},size={200,15},title="T0",fStyle=1
76//      SetVariable setvar_3,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gT0
77       
78
79        Button button_1,pos={320,17},size={120,20},proc=AddFlipperConditionButton,title="Add Condition"
80        Button button_2,pos={403,295},size={110,20},proc=ClearAllFlipperWavesButton,title="Clear Table"
81        Button button_3,pos={183,310},size={120,20},proc=ShowFlipperCalcButton,title="Show Calc"
82        Button button_4,pos={540,295},size={110,20},proc=ClearFlipperRowButton,title="Clear Row"
83        Button button_5,pos={620,18},size={30,20},proc=FlipperHelpParButtonProc,title="?"
84        Button button_6,pos={488,418},size={100,20},proc=WindowSnapshotButton,title="Snapshot"
85        Button button_7,pos={488,380},size={130,20},proc=ManualEnterPfPsmButton,title="Manual Entry"
86
87        // table
88        Edit/W=(14,55,794,275)/HOST=#
89        ModifyTable format=1,width=0
90        RenameWindow #,T0
91        SetActiveSubwindow ##
92
93        SetDataFolder root:
94        return(0)
95End
96
97Function AddFlipperConditionButton(ba) : ButtonControl
98        STRUCT WMButtonAction &ba
99
100        switch( ba.eventCode )
101                case 2: // mouse up
102                        // click code here
103                       
104                        // get the new name for the condition and the name of the cell used
105                        // the cell must already be defined
106                        String condStr, cellStr
107                        Prompt condStr,"Condition, <12 characters"
108                        Prompt cellStr,"Cell",popup,D_CellNameList()
109                        DoPrompt "Add new condition",condStr, cellStr
110                        if(V_Flag==1)
111                                return 0                                                                        // user canceled
112                        endif
113                       
114                        if(strlen(condStr) > 12)
115                                condStr = condStr[0,11]
116                                Print "Condition String trimmed to ",condStr
117                        endif
118                       
119                        String popStr
120                        popStr = condStr+"_"+cellStr
121                       
122                        MakeFlipperResultWaves(popStr)
123                       
124                        break
125                case -1: // control being killed
126                        break
127        endswitch
128
129        return 0
130End
131
132Function FlipperPanelPopMenuProc(pa) : PopupMenuControl
133        STRUCT WMPopupAction &pa
134
135        switch( pa.eventCode )
136                case 2: // mouse up
137                        Variable popNum = pa.popNum
138                        String popStr = pa.popStr
139                       
140                        SetDataFolder root:Packages:NIST:Polarization:Cells
141
142                        // based on the selected string, display the right set of inputs
143//                      Print "now I need to display the right set of waves (2D text?) for ",popStr
144                       
145                        if(cmpstr(popStr,"no conditions defined") == 0)
146                                SetDataFolder root:
147                                return(0)
148                        endif
149                       
150                       
151                        // for the given cell name, if the wave(s) exist, declare them
152                        if(exists(popStr) == 1)
153                                WAVE cond = $(popStr)
154                        else
155                                // if not, report an error                             
156                                DoAlert 0,"The Cond_ waves should exist, this is an error"
157                               
158                                SetDataFolder root:
159                                return(0)
160                                //MakeFlipperResultWaves(popStr)
161                                //WAVE cond = $("root:Packages:NIST:Polarization:Cells:Cond_"+popStr)
162                        endif                   
163                        // append matrix, clearing the old one first
164                        SetDataFolder root:Packages:NIST:Polarization:Cells
165
166                        KillWindow FlipperPanel#T0
167                        Edit/W=(14,55,794,275)/HOST=FlipperPanel
168                        RenameWindow #,T0
169                        AppendtoTable/W=FlipperPanel#T0 cond.ld                 //show the labels
170                        ModifyTable width(Point)=0
171                        ModifyTable width(cond.l)=20
172                       
173                        SetActiveSubwindow ##
174       
175                        SetDataFolder root:
176                       
177                        break
178                case -1: // control being killed
179                        break
180        endswitch
181
182        return 0
183End
184
185// waves are:
186// "Cond_"+popStr
187// and "CondCalc_"+popStr
188
189Function MakeFlipperResultWaves(popStr)
190        String popStr
191
192        SetDataFolder root:Packages:NIST:Polarization:Cells
193
194        Make/O/D/N=(1,8) $("Cond_"+popStr)
195        WAVE cond = $("Cond_"+popStr)
196        // set the column labels
197        SetDimLabel 1,0,UU_Trans,cond
198        SetDimLabel 1,1,DU_Trans,cond
199        SetDimLabel 1,2,DD_Trans,cond
200        SetDimLabel 1,3,UD_Trans,cond
201        SetDimLabel 1,4,Blocked,cond
202        SetDimLabel 1,5,Pol_SM_FL,cond
203        SetDimLabel 1,6,Pol_SM,cond                     //for a mask wave, non-zero is used in the fit
204        SetDimLabel 1,7,Include,cond
205        cond[0][7] = 1                  //default to include the point
206       
207        // generate the dummy wave note now, change as needed
208        String cellStr = StringFromList(1, popStr,"_")
209        String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
210        testStr = ReplaceStringByKey("Cell", testStr, cellStr ,"=", ",", 0)
211        Note cond, testStr
212
213        // to hold the results of the calculation
214        Make/O/D/N=(1,14) $("CondCalc_"+popStr)
215        WAVE CondCalc = $("CondCalc_"+popStr)
216        SetDimLabel 1,0,CR_UU,CondCalc
217        SetDimLabel 1,1,err_CR_UU,CondCalc
218        SetDimLabel 1,2,CR_DU,CondCalc
219        SetDimLabel 1,3,err_CR_DU,CondCalc
220        SetDimLabel 1,4,CR_DD,CondCalc
221        SetDimLabel 1,5,err_CR_DD,CondCalc
222        SetDimLabel 1,6,CR_UD,CondCalc
223        SetDimLabel 1,7,err_CR_UD,CondCalc
224        SetDimLabel 1,8,CR_Blocked,CondCalc
225        SetDimLabel 1,9,err_CR_Blocked,CondCalc
226        SetDimLabel 1,10,P_sm_f,CondCalc
227        SetDimLabel 1,11,err_P_sm_f,CondCalc
228        SetDimLabel 1,12,P_sm,CondCalc
229        SetDimLabel 1,13,err_P_sm,CondCalc     
230
231        SetDataFolder root:
232
233        return(0)
234End
235
236
237// allows manual entry of Psm and Pf values
238//
239Function ManualEnterPfPsmButton(ba) : ButtonControl
240        STRUCT WMButtonAction &ba
241
242        Variable selRow,err=0
243        String fname, t0str, condStr,noteStr,t1Str,cellStr
244
245        switch( ba.eventCode )
246                case 2: // mouse up
247                        // click code here
248                        Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5
249                        Variable PsmPf, err_PsmPf, Psm, err_Psm
250                               
251                        ControlInfo/W=FlipperPanel popup_0
252                        condStr = S_Value
253                        WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr)              //the one that is displayed
254                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1])             //the one that holds results
255                       
256
257                        Prompt PsmPf, "Enter PsmPf: "           
258                        Prompt err_PsmPf, "Enter err_PsmPf: "           
259                        Prompt Psm, "Enter Psm: "               
260                        Prompt err_Psm, "Enter err_Psm: "               
261                        DoPrompt "Enter Supermirror and Flipper Parameters", PsmPf, err_PsmPf, Psm, err_Psm
262                        if (V_Flag)
263                                return -1                                                               // User canceled
264                        endif
265                       
266//      this is the format of the note that is attached to the "Cond_" wave             
267//      String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
268// the "Cell" value was filled in when the Condition was created
269       
270       
271// Put the average values into the wave note and display on the panel
272                        noteStr = note(w)
273                        noteStr = ReplaceNumberByKey("P_sm_f", noteStr, PsmPf ,"=", ",", 0)
274                        noteStr = ReplaceNumberByKey("P_sm", noteStr, Psm ,"=", ",", 0)
275                        noteStr = ReplaceNumberByKey("err_P_sm_f", noteStr, err_PsmPf ,"=", ",", 0)
276                        noteStr = ReplaceNumberByKey("err_P_sm", noteStr, err_Psm ,"=", ",", 0)
277                       
278                        // replace the string
279                        Note/K w
280                        Note w, noteStr
281                                       
282                        //update the global values for display 
283                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf
284                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
285                        sprintf gPsmPf, "%g +/- %g",PsmPf,err_PsmPf
286                        sprintf gPsm, "%g +/- %g",Psm,err_Psm
287                       
288                        break
289                case -1: // control being killed
290                        break
291        endswitch
292
293        return 0
294End
295
296
297
298
299// just recalculate everything, every time
300//
301Function FlipperAverageButtonProc(ba) : ButtonControl
302        STRUCT WMButtonAction &ba
303
304        Variable selRow,err=0
305        String fname, t0str, condStr,noteStr,t1Str,cellStr
306
307        switch( ba.eventCode )
308                case 2: // mouse up
309                        // click code here
310                        Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5
311                        Variable PsmPf, err_PsmPf, Psm, err_Psm
312                               
313                        ControlInfo/W=FlipperPanel popup_0
314                        condStr = S_Value
315                        WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr)              //the one that is displayed
316                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1])             //the one that holds results
317                       
318                        Variable numRows,ncalc,diff
319                        numRows = DimSize(w,0)          //rows in the displayed table
320                        ncalc = DimSize(calc,0)
321                       
322                        // add rows to the ConcCalc_ matrix as needed
323                        if(numRows != ncalc)
324                                if(ncalc > numRows)
325                                        DoAlert 0,"The DecayCalc_ is larger than displayed. Seek help."
326                                        err = 1
327                                        return(err)
328                                else
329                                        diff = numRows - ncalc
330                                        InsertPoints/M=0 ncalc, diff, calc
331                                endif
332                        endif
333                       
334                        noteStr=note(w)
335                        cellStr = StringByKey("Cell", noteStr, "=", ",", 0)
336                        Wave decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr) 
337                        noteStr=note(decay)
338                        t0Str = StringByKey("T0", noteStr, "=", ",", 0)
339//                      Print "CellStr, T0 = ",cellStr, t0Str
340
341                        Variable sum_PsmPf, err_sum_PsmPf, sum_Psm, err_sum_Psm
342                        sum_PsmPf = 0
343                        err_sum_PsmPf = 0
344                        sum_Psm = 0
345                        err_sum_Psm = 0
346                       
347                        for(selRow=0;selRow<numRows;selRow+=1)
348                                Print "calculate the row ",selRow
349
350                                // parse the rows, report errors (there, not here), exit if any found
351                                err = ParseFlipperRow(w,selRow)
352                                if(err)
353                                        return 0
354                                endif
355                               
356                                // do the calculations:
357       
358                                Print "The Blocked CR is not rescaled to zero attenuators"
359                                cr1 = TotalCR_FromRun(w[selRow][%UU_Trans],err_cr1,0)
360                                cr2 = TotalCR_FromRun(w[selRow][%DU_Trans],err_cr2,0)
361                                cr3 = TotalCR_FromRun(w[selRow][%DD_Trans],err_cr3,0)   
362                                cr4 = TotalCR_FromRun(w[selRow][%UD_Trans],err_cr4,0)
363                                cr5 = TotalCR_FromRun(w[selRow][%Blocked],err_cr5,1)            //blocked beam is NOT normalized to zero attenuators
364
365                                calc[selRow][%cr_UU] = cr1
366                                calc[selRow][%cr_DU] = cr2
367                                calc[selRow][%cr_DD] = cr3
368                                calc[selRow][%cr_UD] = cr4
369                                calc[selRow][%cr_Blocked] = cr5
370                                calc[selRow][%err_cr_UU] = err_cr1
371                                calc[selRow][%err_cr_DU] = err_cr2
372                                calc[selRow][%err_cr_DD] = err_cr3
373                                calc[selRow][%err_cr_UD] = err_cr4
374                                calc[selRow][%err_cr_Blocked] = err_cr5
375       
376                                // Calc PsmPf, and assign the values
377                                PsmPf = Calc_PsmPf(w,calc,noteStr,selRow,err_PsmPf)
378                                calc[selRow][%P_sm_f] = PsmPf
379                                calc[selRow][%err_P_sm_f] = err_PsmPf
380                                w[selRow][%Pol_SM_FL] = PsmPf
381                               
382                                // Calc Psm, and assign the values
383                                Psm = Calc_Psm(w,calc,noteStr,selRow,err_Psm)
384                                calc[selRow][%P_sm] = Psm
385                                calc[selRow][%err_P_sm] = err_Psm
386                                w[selRow][%Pol_SM] = Psm
387
388                                // running average of PsmPf and Psm
389                                sum_PsmPf += PsmPf
390                                err_sum_PsmPf += err_PsmPf^2
391                                sum_Psm += Psm
392                                err_sum_Psm += err_Psm^2
393                               
394                        endfor          //loop over rows
395                       
396                        // now get a running average of muP, Po, and the errors
397                        PsmPf = sum_PsmPf/numRows
398                        Psm = sum_Psm/numRows
399                        err_PsmPf = sqrt(err_sum_PsmPf) / numRows
400                        err_Psm = sqrt(err_sum_Psm) / numRows
401                       
402//      this is the format of the note that is attached to the "Cond_" wave             
403//      String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf,"
404// the "Cell" value was filled in when the Condition was created
405       
406       
407// Put the average values into the wave note and display on the panel
408                        noteStr = note(w)
409                        noteStr = ReplaceNumberByKey("P_sm_f", noteStr, PsmPf ,"=", ",", 0)
410                        noteStr = ReplaceNumberByKey("P_sm", noteStr, Psm ,"=", ",", 0)
411                        noteStr = ReplaceNumberByKey("err_P_sm_f", noteStr, err_PsmPf ,"=", ",", 0)
412                        noteStr = ReplaceNumberByKey("err_P_sm", noteStr, err_Psm ,"=", ",", 0)
413                       
414                        // replace the string
415                        Note/K w
416                        Note w, noteStr
417                                       
418                        //update the global values for display 
419                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf
420                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm
421                        sprintf gPsmPf, "%g +/- %g",PsmPf,err_PsmPf
422                        sprintf gPsm, "%g +/- %g",Psm,err_Psm
423                       
424                        break
425                case -1: // control being killed
426                        break
427        endswitch
428
429        return 0
430End
431
432// gCellKW passed in has gamma, muPo, etc. needed for PCell(t) calculation
433//
434// these are not the equations that Kaythrn gave to me, but rather
435// equations 14 and 15 from the SS handout. These replacement equations
436// are in terms of relative transmissions, so I can use count rates
437// otherwise, I don't know how to calculate a transmission -- I don't know what
438// the "empty beam" condition is...
439//
440//  this is only using the measurement at t1 for the calculation!
441//
442Function Calc_PsmPf(w,calc,gCellKW,selRow,err_PsmPf)
443        WAVE w,calc
444        String gCellKW
445        Variable selRow,&err_PsmPf
446       
447        // DD is cr3, DU is cr2, Blocked is cr5
448        String t0Str,t1Str,t2Str,fname
449        Variable PsmPf,t1,t2,PCell_t1,PCell_t2,err_PCell_t1,err_PCell_t2
450        Variable muPo,err_muPo,gam,err_gam
451        Variable crDD, crDU,err_crDD,err_crDU,crBB, err_crBB
452       
453        t0Str = StringByKey("T0", gCellKW, "=", ",", 0)
454        muPo = NumberByKey("muP", gCellKW, "=", ",", 0)
455        err_muPo = NumberByKey("err_muP", gCellKW, "=", ",", 0)
456        gam = NumberByKey("gamma", gCellKW, "=", ",", 0)
457        err_gam = NumberByKey("err_gamma", gCellKW, "=", ",", 0)
458
459        fname = FindFileFromRunNumber(w[selRow][%UU_Trans])
460        t1str = getFileCreationDate(fname)
461        t1 = ElapsedHours(t0Str,t1Str)
462       
463        fname = FindFileFromRunNumber(w[selRow][%DU_Trans])
464        t2str = getFileCreationDate(fname)
465        t2 = ElapsedHours(t0Str,t2Str)
466
467        PCell_t1 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t1,err_PCell_t1)
468        PCell_t2 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell_t2)
469       
470        // DD is cr3, DU is cr2, Blocked is cr5
471        crDD = calc[selRow][%cr_DD]
472        crDU = calc[selRow][%cr_DU]
473        crBB = calc[selRow][%cr_Blocked]
474        err_crDD = calc[selRow][%err_cr_DD]
475        err_crDU = calc[selRow][%err_cr_DU]
476        err_crBB = calc[selRow][%err_cr_Blocked]
477       
478        // this really needs transmissions
479//      PsmPf = (crDD - crDU)/(PCell_t1 + PCell_t2)
480       
481        // eqn (15) from the SS handout
482        Variable tmp,dfdx
483        tmp = (crDD - crBB)/(crDU - crBB)
484       
485        PsmPf = (tmp - 1)/(Pcell_t1*(1+tmp))
486       
487        dfdx = 1/(Pcell_t1*(1+tmp)) - (tmp-1)*Pcell_t1/(Pcell_t1^2*(1+tmp)^2)
488       
489        err_PsmPf = ( (tmp-1)/((1+tmp)*Pcell_t1^2) *err_Pcell_t1 )^2
490        err_PsmPf += ( dfdx / (crDU-crBB) * err_crDD)^2
491        err_PsmPf += ( dfdx*(crDD-crBB)/(crDU-crBB)^2 * err_crDU)^2
492        err_PsmPf += ( dfdx*(-tmp/(crDD-crBB) + tmp/(crDU-crBB)) * err_crBB)^2
493       
494        err_PsmPf = sqrt(err_PsmPf)
495        Printf "At t1=%g  PsmPf = %g +/- %g (%g%)\r",t1,PsmPf,err_PsmPf,err_PsmPf/PsmPf*100
496
497
498        return(PsmPf)
499end
500
501
502// gCellKW passed in has gamma, muPo, etc. needed for PCell(t) calculation
503//
504// these are not the equations that Kaythrn gave to me, but rather
505// equations 14 and 15 from the SS handout. These replacement equations
506// are in terms of relative transmissions, so I can use count rates
507// otherwise, I don't know how to calculate a transmission -- I don't know what
508// the "empty beam" condition is...
509//
510//  this is only using the measurement at t1 for the calculation!
511//
512Function Calc_Psm(w,calc,gCellKW,selRow,err_Psm)
513        WAVE w,calc
514        String gCellKW
515        Variable selRow,&err_Psm
516       
517        // UU is cr1, UD is cr4, Blocked is cr5
518        String t0Str,t1Str,t2Str,fname
519        Variable Psm,t1,t2,PCell_t1,PCell_t2,err_PCell_t1,err_PCell_t2
520        Variable muPo,err_muPo,gam,err_gam
521        Variable crUU, crUD,err_crUU,err_crUD,crBB, err_crBB
522       
523        t0Str = StringByKey("T0", gCellKW, "=", ",", 0)
524        muPo = NumberByKey("muP", gCellKW, "=", ",", 0)
525        err_muPo = NumberByKey("err_muP", gCellKW, "=", ",", 0)
526        gam = NumberByKey("gamma", gCellKW, "=", ",", 0)
527        err_gam = NumberByKey("err_gamma", gCellKW, "=", ",", 0)
528
529        fname = FindFileFromRunNumber(w[selRow][%UU_Trans])
530        t1str = getFileCreationDate(fname)
531        t1 = ElapsedHours(t0Str,t1Str)
532       
533        fname = FindFileFromRunNumber(w[selRow][%DU_Trans])
534        t2str = getFileCreationDate(fname)
535        t2 = ElapsedHours(t0Str,t2Str)
536
537        PCell_t1 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t1,err_PCell_t1)
538        PCell_t2 = Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell_t2)
539       
540        // UU is cr1, UD is cr4, Blocked is cr5
541        crUU = calc[selRow][%cr_UU]
542        crUD = calc[selRow][%cr_UD]
543        crBB = calc[selRow][%cr_Blocked]
544        err_crUU = calc[selRow][%err_cr_UU]
545        err_crUD = calc[selRow][%err_cr_UD]
546        err_crBB = calc[selRow][%err_cr_Blocked]
547       
548        // this really needs transmissions
549       
550        // eqn (14) from the SS handout
551        Variable tmp,dfdx
552        tmp = (crUU - crBB)/(crUD - crBB)
553       
554        Psm = (tmp - 1)/(Pcell_t1*(1+tmp))
555       
556        dfdx = 1/(Pcell_t1*(1+tmp)) - (tmp-1)*Pcell_t1/(Pcell_t1^2*(1+tmp)^2)
557       
558        err_Psm = ( (tmp-1)/((1+tmp)*Pcell_t1^2) *err_Pcell_t1 )^2
559        err_Psm += ( dfdx / (crUD-crBB) * err_crUU)^2
560        err_Psm += ( dfdx*(crUU-crBB)/(crUD-crBB)^2 * err_crUD)^2
561        err_Psm += ( dfdx*(-tmp/(crUU-crBB) + tmp/(crUD-crBB)) * err_crBB)^2
562       
563        err_Psm = sqrt(err_Psm)
564        Printf "At t1=%g  Psm = %g +/- %g (%g%)\r",t1,Psm,err_Psm,err_Psm/Psm*100
565
566
567        return(Psm)
568end
569
570
571
572// t2 is in hours, muP0 is at t0
573//
574Function Calc_PCell_atT(muPo,err_muPo,gam,err_gam,t2,err_PCell)
575        Variable muPo,err_muPo,gam,err_gam,t2,&err_PCell
576
577
578        Variable Pcell
579
580
581        PCell = tanh(muPo * exp(-t2/gam))
582       
583        Variable arg,tmp2
584        arg = PCell
585        tmp2 = (1-tanh(arg)^2)^2
586        err_PCell = tmp2 * (exp(-t2/gam) * err_muPo)^2                  //dominant term (10x larger)
587        err_PCell += tmp2 * (arg*t2/gam/gam * err_gam)^2
588       
589        err_PCell = sqrt(err_Pcell)
590       
591        Printf "At t=%g  Pcell = %g +/- %g (%g%)\r",t2,Pcell,err_Pcell,err_Pcell/PCell*100
592
593
594
595        return(PCell)
596End
597
598// bring up a table with the calculation results
599Function ShowFlipperCalcButton(ba) : ButtonControl
600        STRUCT WMButtonAction &ba
601
602        switch( ba.eventCode )
603                case 2: // mouse up
604                        // click code here
605                        ControlInfo/W=FlipperPanel popup_0
606                        String condStr = S_Value
607                        condStr = condStr[5,strlen(condStr)-1]          // trim off "Calc_" from the beginning of the string
608                        WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr)         
609                        edit calc.ld
610                                               
611                        break
612                case -1: // control being killed
613                        break
614        endswitch
615
616        return 0
617End
618
619
620
621// clear just the row
622//
623Function ClearFlipperRowButton(ba) : ButtonControl
624        STRUCT WMButtonAction &ba
625
626        String popStr=""
627        Variable selRow
628       
629        switch( ba.eventCode )
630                case 2: // mouse up
631                        // click code here
632                        DoAlert 1,"Clear the selected row?"
633                        if(V_flag !=1)
634                                return(0)
635                        endif
636                       
637                        SetDataFolder root:Packages:NIST:Polarization:Cells
638
639                        ControlInfo/W=FlipperPanel popup_0
640                        popStr = S_Value
641                       
642                        Wave decay = $("Decay_"+popStr)
643                        Wave calc = $("DecayCalc_"+popStr)
644
645                        // Delete just those points
646                                               
647                        GetSelection table, FlipperPanel#T0, 1
648                        selRow = V_startRow
649                        DeletePoints selRow,1,decay,calc                       
650                       
651                        // clear the graph and the results                     
652                        NVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
653                        NVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
654                        NVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
655                        SVAR gT0  = root:Packages:NIST:Polarization:Cells:gT0
656                        gMuPo = 0
657                        gPo = 0
658                        gGamma = 0
659                        gT0 = "recalculate"
660                       
661                       
662                        SetDataFolder root:
663                        break
664                case -1: // control being killed
665                        break
666        endswitch
667
668        return 0
669End
670
671
672
673// for this, do I want to clear everything, or just a selected row??
674//
675//
676Function ClearAllFlipperWavesButton(ba) : ButtonControl
677        STRUCT WMButtonAction &ba
678
679        String popStr=""
680       
681        switch( ba.eventCode )
682                case 2: // mouse up
683                        // click code here
684                        DoAlert 1,"Clear all of the decay waves for the selected cell?"
685                        if(V_flag !=1)
686                                return(0)
687                        endif
688                       
689                        SetDataFolder root:Packages:NIST:Polarization:Cells
690
691                        ControlInfo/W=FlipperPanel popup_0
692                        popStr = S_Value
693                       
694                        Wave decay = $("Decay_"+popStr)
695                        Wave calc = $("DecayCalc_"+popStr)
696                       
697//                      re-initialize the decay waves, so it appears as a blank, initialized table
698
699                        MakeFlipperResultWaves(popStr)
700                        decay = 0
701                        calc = 0
702       
703                        // clear the graph and the results?     
704                       
705                       
706                                       
707                        NVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo
708                        NVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo
709                        NVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma
710                        SVAR gT0  = root:Packages:NIST:Polarization:Cells:gT0
711                        gMuPo = 0
712                        gPo = 0
713                        gGamma = 0
714                        gT0 = "recalculate"
715                       
716                       
717                        SetDataFolder root:
718                        break
719                case -1: // control being killed
720                        break
721        endswitch
722
723        return 0
724End
725
726
727Function FlipperHelpParButtonProc(ba) : ButtonControl
728        STRUCT WMButtonAction &ba
729
730        switch( ba.eventCode )
731                case 2: // mouse up
732                        // click code here
733                        DoAlert 0,"Help for Flipper Panel not written yet"
734                        break
735                case -1: // control being killed
736                        break
737        endswitch
738
739        return 0
740End
741
742
743
744// null condition is not right. if the loop fails, then the
745// retStr will be ";;;;", not zero length. What's the proper test?
746// Does it matter? the list of default gCell_sss should already be there.
747//
748Function/S D_ConditionNameList()
749
750        String listStr=""
751       
752        SetDataFolder root:Packages:NIST:Polarization:Cells
753
754        // get a list of the Condition waves
755        listStr=WaveList("Cond_*",";","")
756//      print listStr
757       
758        if(strlen(listStr) == 0)
759                listStr = "no conditions defined;"
760        endif
761       
762        SetDataFolder root:             
763        return(listStr)
764End
765
766
767// parse the row to be sure that:
768//
769// - files are valid numbers
770// - files are all at same SDD
771// - files are all with same attenuation (just print a warning to cmd)
772// - files all use the same cell
773// - files are all within 20 minutes of each other
774//
775//
776//      SetDimLabel 1,0,UU_Trans,cond
777//      SetDimLabel 1,1,DU_Trans,cond
778//      SetDimLabel 1,2,DD_Trans,cond
779//      SetDimLabel 1,3,UD_Trans,cond
780//      SetDimLabel 1,4,Blocked,cond
781//      SetDimLabel 1,5,Pol_SM_FL,cond
782//      SetDimLabel 1,6,Pol_SM,cond                     //for a mask wave, non-zero is used in the fit
783//      SetDimLabel 1,7,Include,cond
784//
785// There are 5 separate files now
786//
787Function ParseFlipperRow(w,selRow)
788        Wave w
789        Variable selRow
790       
791        Variable err=0
792        Variable atten1,atten2,atten3,atten4,atten5
793        Variable sdd1,sdd2,sdd3,sdd4,sdd5
794        Variable t1,t2,t3,t4,t5
795        String cell1,cell2,cell3,cell4,cell5
796       
797       
798        String fname=""
799       
800       
801        // are all file numbers valid?
802        fname = FindFileFromRunNumber(w[selRow][%UU_Trans])
803        if(cmpstr(fname,"")==0)
804                DoAlert 0,"UU_Trans run "+num2str(w[selRow][%UU_Trans])+" is not a valid run number"
805                err = 1
806        else
807                atten1 = getAttenNumber(fname)
808                sdd1 = getSDD(fname)
809        endif
810       
811        fname = FindFileFromRunNumber(w[selRow][%DU_Trans])
812        if(cmpstr(fname,"")==0)
813                DoAlert 0,"DU_Trans run "+num2str(w[selRow][%DU_Trans])+" is not a valid run number"
814                err = 1
815        else
816                atten2 = getAttenNumber(fname)
817                sdd2 = getSDD(fname)
818        endif
819       
820        fname = FindFileFromRunNumber(w[selRow][%DD_Trans])
821        if(cmpstr(fname,"")==0)
822                DoAlert 0,"DD_Trans run "+num2str(w[selRow][%DD_Trans])+" is not a valid run number"
823                err = 1
824        else
825                atten3 = getAttenNumber(fname)
826                sdd3 = getSDD(fname)
827        endif
828       
829        fname = FindFileFromRunNumber(w[selRow][%UD_Trans])
830        if(cmpstr(fname,"")==0)
831                DoAlert 0,"UD_Trans run "+num2str(w[selRow][%UD_Trans])+" is not a valid run number"
832                err = 1
833        else
834                atten4 = getAttenNumber(fname)
835                sdd4 = getSDD(fname)
836        endif
837       
838        fname = FindFileFromRunNumber(w[selRow][%Blocked])
839        if(cmpstr(fname,"")==0)
840                DoAlert 0,"Blocked run "+num2str(w[selRow][%Blocked])+" is not a valid run number"
841                err = 1
842        else
843                atten5 = getAttenNumber(fname)
844                sdd5 = getSDD(fname)
845        endif
846       
847       
848       
849        // do a check of the elapsed time from start to finish
850       
851       
852       
853       
854        if( (sdd1 != sdd2) || (sdd2 != sdd3) || (sdd1 != sdd3) )
855                DoAlert 0,"Files in row "+num2str(selRow)+" are not all at the same detector distance"
856                err = 1
857        endif
858       
859       
860       
861       
862       
863        if( (atten1 != atten2) || (atten2 != atten3) || (atten1 != atten3) )
864                DoAlert 0,"Files in row "+num2str(selRow)+" are not all collected with the same attenuation. Just so you know."
865                err = 0
866        endif
867       
868        return(err)
869end
870
871
872////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.