#pragma rtGlobals=1 // Use modern global access method. // input panels to set and calculate polarization parameters necessary for the // matrix corrections to the cross sections // // // -3-Flipper efficiency // // TODO: // X- add a way to manually enter the P values into a "blank" condition, in case that the users // calculate the values in a different way. This should be as simple as a dialog to enter values and // change the wave note (and displayed strings). // // // Polarization parameters for each condition. Results are stored in a wave note for each condition // // // str = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf," // // two waves per condition "Cond_Name_Cell" and "CondCalc_Name_Cell" // Proc ShowFlipperPanel() // init folders // ASK before initializing cell constants // open the panel DoWindow/F FlipperPanel if(V_flag == 0) InitPolarizationFolders() InitFlipperGlobals() DrawFlipperPanel() endif end Function InitFlipperGlobals() SetDataFolder root:Packages:NIST:Polarization:Cells String/G gPsmPf = "Psm*Pf" String/G gPsm = "Psm" SetDataFolder root: return(0) End // // makes the panel for the calculation of flipper and supermirror efficiencies // Function DrawFlipperPanel() SetDataFolder root:Packages:NIST:Polarization:Cells PauseUpdate; Silent 1 // building window... NewPanel /W=(1023,44,1832,526)/N=FlipperPanel/K=1 as "Flipper and Supermirror" ModifyPanel cbRGB=(1,52428,26586) PopupMenu popup_0,pos={32,18},size={49,20},title="Field Condition",proc=FlipperPanelPopMenuProc PopupMenu popup_0,mode=1,value= #"D_ConditionNameList()" Button button_0,pos={42,310},size={100,20},proc=FlipperAverageButtonProc,title="Do Average" GroupBox group_0,pos={39,350},size={335,103},title="AVERAGED RESULTS",fSize=10 GroupBox group_0,fStyle=1 SetVariable setvar_0,pos={49,385},size={250,15},title="Sam_depol*Psm*Pf" SetVariable setvar_0,fStyle=1 SetVariable setvar_0,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsmPf SetVariable setvar_1,pos={49,417},size={250,15},title="Sam_depol*Psm",fStyle=1 SetVariable setvar_1,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gPsm // SetVariable setvar_2,pos={560,518},size={200,13},title="Gamma (h)",fStyle=1 // SetVariable setvar_2,limits={0,0,0},barmisc={0,1000} // SetVariable setvar_2,value= root:Packages:NIST:Polarization:Cells:gGamma // SetVariable setvar_3,pos={560,488},size={200,15},title="T0",fStyle=1 // SetVariable setvar_3,limits={0,0,0},value= root:Packages:NIST:Polarization:Cells:gT0 Button button_1,pos={320,17},size={120,20},proc=AddFlipperConditionButton,title="Add Condition" Button button_2,pos={403,295},size={110,20},proc=ClearAllFlipperWavesButton,title="Clear Table" Button button_3,pos={183,310},size={120,20},proc=ShowFlipperCalcButton,title="Show Calc" Button button_4,pos={540,295},size={110,20},proc=ClearFlipperRowButton,title="Clear Row" Button button_5,pos={620,18},size={30,20},proc=FlipperHelpParButtonProc,title="?" Button button_6,pos={488,418},size={100,20},proc=WindowSnapshotButton,title="Snapshot" Button button_7,pos={488,380},size={130,20},proc=ManualEnterPfPsmButton,title="Manual Entry" // table Edit/W=(14,55,794,275)/HOST=# ModifyTable format=1,width=0 RenameWindow #,T0 SetActiveSubwindow ## SetDataFolder root: return(0) End // now, this does not depend on the cell, just the condition Function AddFlipperConditionButton(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here String condStr//, cellStr Prompt condStr,"Condition, <12 characters, NO UNDERSCORES" // Prompt cellStr,"Cell",popup,D_CellNameList() DoPrompt "Add new condition",condStr//, cellStr if(V_Flag==1) return 0 // user canceled endif if(strlen(condStr) > 12) condStr = condStr[0,11] Print "Condition String trimmed to ",condStr endif condStr = ReplaceString("_", condStr, "", 0, inf) String popStr // popStr = condStr+"_"+cellStr popStr = condStr MakeFlipperResultWaves(popStr) break case -1: // control being killed break endswitch return 0 End Function FlipperPanelPopMenuProc(pa) : PopupMenuControl STRUCT WMPopupAction &pa switch( pa.eventCode ) case 2: // mouse up Variable popNum = pa.popNum String popStr = pa.popStr SetDataFolder root:Packages:NIST:Polarization:Cells // based on the selected string, display the right set of inputs // Print "now I need to display the right set of waves (2D text?) for ",popStr if(cmpstr(popStr,"no conditions defined") == 0) SetDataFolder root: return(0) endif // for the given cell name, if the wave(s) exist, declare them if(exists(popStr) == 1) WAVE cond = $(popStr) WAVE/T cellW = $("CondCell_"+popStr[5,strlen(popStr)-1]) else // if not, report an error DoAlert 0,"The Cond_ waves should exist, this is an error" SetDataFolder root: return(0) //MakeFlipperResultWaves(popStr) //WAVE cond = $("root:Packages:NIST:Polarization:Cells:Cond_"+popStr) endif // append matrix, clearing the old one first SetDataFolder root:Packages:NIST:Polarization:Cells KillWindow FlipperPanel#T0 Edit/W=(14,55,794,275)/HOST=FlipperPanel RenameWindow #,T0 AppendtoTable/W=FlipperPanel#T0 cellW // AppendtoTable/W=FlipperPanel#T0 cond.ld //show the labels ModifyTable width(Point)=0 ModifyTable width(cond.l)=20 SetActiveSubwindow ## SetDataFolder root: // update the globals that are displayed from the wave note String nStr=Note(cond) SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm sprintf gPsmPf, "%g +/- %g",NumberByKey("P_sm_f", nStr, "=",","),NumberByKey("err_P_sm_f", nStr, "=",",") sprintf gPsm, "%g +/- %g",NumberByKey("P_sm", nStr, "=",","),NumberByKey("err_P_sm", nStr, "=",",") break case -1: // control being killed break endswitch return 0 End // waves are: // "Cond_"+popStr // and "CondCalc_"+popStr // ... and now "CondCell"+popStr Function MakeFlipperResultWaves(popStr) String popStr SetDataFolder root:Packages:NIST:Polarization:Cells Make/O/T/N=1 $("CondCell_"+popStr) Make/O/D/N=(1,8) $("Cond_"+popStr) WAVE cond = $("Cond_"+popStr) // set the column labels SetDimLabel 1,0,UU_Trans,cond SetDimLabel 1,1,DU_Trans,cond SetDimLabel 1,2,DD_Trans,cond SetDimLabel 1,3,UD_Trans,cond SetDimLabel 1,4,Blocked,cond SetDimLabel 1,5,Pol_SM_FL,cond SetDimLabel 1,6,Pol_SM,cond //for a mask wave, non-zero is used in the fit SetDimLabel 1,7,Include,cond cond[0][7] = 1 //default to include the point // generate the dummy wave note now, change as needed String cellStr = StringFromList(1, popStr,"_") String testStr = "P_sm_f=0,err_P_sm_f=0,P_sm=0,err_P_sm=0,T0=undefined," // testStr = ReplaceStringByKey("Cell", testStr, cellStr ,"=", ",", 0) Note cond, testStr // to hold the results of the calculation Make/O/D/N=(1,14) $("CondCalc_"+popStr) WAVE CondCalc = $("CondCalc_"+popStr) SetDimLabel 1,0,CR_UU,CondCalc SetDimLabel 1,1,err_CR_UU,CondCalc SetDimLabel 1,2,CR_DU,CondCalc SetDimLabel 1,3,err_CR_DU,CondCalc SetDimLabel 1,4,CR_DD,CondCalc SetDimLabel 1,5,err_CR_DD,CondCalc SetDimLabel 1,6,CR_UD,CondCalc SetDimLabel 1,7,err_CR_UD,CondCalc SetDimLabel 1,8,CR_Blocked,CondCalc SetDimLabel 1,9,err_CR_Blocked,CondCalc SetDimLabel 1,10,P_sm_f,CondCalc SetDimLabel 1,11,err_P_sm_f,CondCalc SetDimLabel 1,12,P_sm,CondCalc SetDimLabel 1,13,err_P_sm,CondCalc SetDataFolder root: return(0) End // allows manual entry of Psm and Pf values // Function ManualEnterPfPsmButton(ba) : ButtonControl STRUCT WMButtonAction &ba Variable selRow,err=0 String fname, t0str, condStr,noteStr,t1Str,cellStr switch( ba.eventCode ) case 2: // mouse up // click code here Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5 Variable PsmPf, err_PsmPf, Psm, err_Psm ControlInfo/W=FlipperPanel popup_0 condStr = S_Value WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr) //the one that is displayed WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1]) //the one that holds results Prompt PsmPf, "Enter PsmPf: " Prompt err_PsmPf, "Enter err_PsmPf: " Prompt Psm, "Enter Psm: " Prompt err_Psm, "Enter err_Psm: " DoPrompt "Enter Supermirror and Flipper Parameters", PsmPf, err_PsmPf, Psm, err_Psm if (V_Flag) return -1 // User canceled endif // this is the format of the note that is attached to the "Cond_" wave // String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf,Cell=asdf," // the "Cell" value was filled in when the Condition was created // Put the average values into the wave note and display on the panel noteStr = note(w) noteStr = ReplaceNumberByKey("P_sm_f", noteStr, PsmPf ,"=", ",", 0) noteStr = ReplaceNumberByKey("P_sm", noteStr, Psm ,"=", ",", 0) noteStr = ReplaceNumberByKey("err_P_sm_f", noteStr, err_PsmPf ,"=", ",", 0) noteStr = ReplaceNumberByKey("err_P_sm", noteStr, err_Psm ,"=", ",", 0) // replace the string Note/K w Note w, noteStr //update the global values for display SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm sprintf gPsmPf, "%g +/- %g",PsmPf,err_PsmPf sprintf gPsm, "%g +/- %g",Psm,err_Psm break case -1: // control being killed break endswitch return 0 End // // just recalculate everything, every time // // -- now that the cell name is entered, I need to try to catch errors where the cell decay parameters are not // properly calculated -- right now, invalid cell names are caught, but valid cell names with no decay data // behind them just calculate Inf for the polarization values. This is hopefull enough to catch someone's attention... // Function FlipperAverageButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba Variable selRow,err=0 String fname, t0str, condStr,noteStr,t1Str,cellStr switch( ba.eventCode ) case 2: // mouse up // click code here Variable cr1,cr2,cr3,cr4,cr5,err_cr1,err_cr2,err_cr3,err_cr4,err_cr5 Variable PsmPf, err_PsmPf, Psm, err_Psm ControlInfo/W=FlipperPanel popup_0 condStr = S_Value WAVE w=$("root:Packages:NIST:Polarization:Cells:"+condStr) //the one that is displayed WAVE calc=$("root:Packages:NIST:Polarization:Cells:CondCalc_"+condStr[5,strlen(condStr)-1]) //the one that holds results WAVE/T CellW=$("root:Packages:NIST:Polarization:Cells:CondCell_"+condStr[5,strlen(condStr)-1]) //the textW with cell name Variable numRows,ncalc,diff numRows = DimSize(w,0) //rows in the displayed table ncalc = DimSize(calc,0) // add rows to the ConcCalc_ matrix as needed if(numRows != ncalc) if(ncalc > numRows) DoAlert 0,"The CondCalc_ is larger than displayed. Seek help." err = 1 return(err) else diff = numRows - ncalc InsertPoints/M=0 ncalc, diff, calc endif endif // noteStr=note(w) // cellStr = StringByKey("Cell", noteStr, "=", ",", 0) // Wave decay = $("root:Packages:NIST:Polarization:Cells:Decay_"+cellStr) // noteStr=note(decay) // t0Str = StringByKey("T0", noteStr, "=", ",", 0) // Print "CellStr, T0 = ",cellStr, t0Str Variable sum_PsmPf, err_sum_PsmPf, sum_Psm, err_sum_Psm,nRowsIncluded=0 sum_PsmPf = 0 err_sum_PsmPf = 0 sum_Psm = 0 err_sum_Psm = 0 for(selRow=0;selRow", so get list item 1 Wave cond = $("Cond_"+popStr) Wave calc = $("CondCalc_"+popStr) Wave/T cellW = $("CondCell_"+popStr) // Delete just those points GetSelection table, FlipperPanel#T0, 1 selRow = V_startRow DeletePoints selRow,1,cond,calc,cellW // clear the graph and the results SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf gPsm = "0" gPsmPf = "0" SetDataFolder root: break case -1: // control being killed break endswitch return 0 End // for this, do I want to clear everything, or just a selected row?? // // Function ClearAllFlipperWavesButton(ba) : ButtonControl STRUCT WMButtonAction &ba String popStr="" switch( ba.eventCode ) case 2: // mouse up // click code here DoAlert 1,"Clear all of the flipper waves for the selected cell?" if(V_flag !=1) return(0) endif SetDataFolder root:Packages:NIST:Polarization:Cells ControlInfo/W=FlipperPanel popup_0 popStr = StringFromList(1,S_Value,"_") //pop is "Cond_", so get list item 1 Wave cond = $("Cond_"+popStr) Wave calc = $("CondCalc_"+popStr) Wave/T cellW = $("CondCell_"+popStr) // re-initialize the flipper waves, so it appears as a blank, initialized table MakeFlipperResultWaves(popStr) cond = 0 calc = 0 cellW = "" cond[0][7] = 1 //default to include the point // clear the graph and the results? SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf gPsm = "0" gPsmPf = "0" SetDataFolder root: break case -1: // control being killed break endswitch return 0 End Function FlipperHelpParButtonProc(ba) : ButtonControl STRUCT WMButtonAction &ba switch( ba.eventCode ) case 2: // mouse up // click code here DisplayHelpTopic/Z/K=1 "Flipper States Panel" if(V_flag !=0) DoAlert 0,"The Flipper States Panel Help file could not be found" endif break case -1: // control being killed break endswitch return 0 End // null condition is not right. if the loop fails, then the // retStr will be ";;;;", not zero length. What's the proper test? // Does it matter? the list of default gCell_sss should already be there. // Function/S D_ConditionNameList() String listStr="" SetDataFolder root:Packages:NIST:Polarization:Cells // get a list of the Condition waves listStr=WaveList("Cond_*",";","") // print listStr if(strlen(listStr) == 0) listStr = "no conditions defined;" endif SetDataFolder root: return(listStr) End // parse the row to be sure that: // // - files are valid numbers // - files are all at same SDD // - files are all with same attenuation (just print a warning to cmd) // - files all use the same cell // - files are all within 20 minutes of each other // // // SetDimLabel 1,0,UU_Trans,cond // SetDimLabel 1,1,DU_Trans,cond // SetDimLabel 1,2,DD_Trans,cond // SetDimLabel 1,3,UD_Trans,cond // SetDimLabel 1,4,Blocked,cond // SetDimLabel 1,5,Pol_SM_FL,cond // SetDimLabel 1,6,Pol_SM,cond //for a mask wave, non-zero is used in the fit // SetDimLabel 1,7,Include,cond // // There are 5 separate files now // Function ParseFlipperRow(w,selRow) Wave w Variable selRow Variable err=0 Variable atten1,atten2,atten3,atten4,atten5 Variable sdd1,sdd2,sdd3,sdd4,sdd5 Variable t1,t2,t3,t4,t5 String cell1,cell2,cell3,cell4,cell5 String fname="" // are all file numbers valid? fname = FindFileFromRunNumber(w[selRow][%UU_Trans]) if(cmpstr(fname,"")==0) DoAlert 0,"UU_Trans run "+num2str(w[selRow][%UU_Trans])+" is not a valid run number" err = 1 else atten1 = getAttenNumber(fname) sdd1 = getSDD(fname) endif fname = FindFileFromRunNumber(w[selRow][%DU_Trans]) if(cmpstr(fname,"")==0) DoAlert 0,"DU_Trans run "+num2str(w[selRow][%DU_Trans])+" is not a valid run number" err = 1 else atten2 = getAttenNumber(fname) sdd2 = getSDD(fname) endif fname = FindFileFromRunNumber(w[selRow][%DD_Trans]) if(cmpstr(fname,"")==0) DoAlert 0,"DD_Trans run "+num2str(w[selRow][%DD_Trans])+" is not a valid run number" err = 1 else atten3 = getAttenNumber(fname) sdd3 = getSDD(fname) endif fname = FindFileFromRunNumber(w[selRow][%UD_Trans]) if(cmpstr(fname,"")==0) DoAlert 0,"UD_Trans run "+num2str(w[selRow][%UD_Trans])+" is not a valid run number" err = 1 else atten4 = getAttenNumber(fname) sdd4 = getSDD(fname) endif fname = FindFileFromRunNumber(w[selRow][%Blocked]) if(cmpstr(fname,"")==0) DoAlert 0,"Blocked run "+num2str(w[selRow][%Blocked])+" is not a valid run number" err = 1 else atten5 = getAttenNumber(fname) sdd5 = getSDD(fname) endif // do a check of the elapsed time from start to finish if( (sdd1 != sdd2) || (sdd2 != sdd3) || (sdd1 != sdd3) ) DoAlert 0,"Files in row "+num2str(selRow)+" are not all at the same detector distance" err = 1 endif if( (atten1 != atten2) || (atten2 != atten3) || (atten1 != atten3) ) DoAlert 0,"Files in row "+num2str(selRow)+" are not all collected with the same attenuation. Just so you know." err = 0 endif return(err) end ////////////////////////////////////////////