Changeset 890 for sans


Ignore:
Timestamp:
Jan 28, 2013 4:43:50 PM (10 years ago)
Author:
srkline
Message:

Added a procedure file to allow "scripting" of the MonteCarlo? simulation: MC_SimulationScripting.ipf. See the beginning of the file for instructions, and then the examples for numbered instructions of what needs to be edited to write your own script. Not casual-user-friendly, but makes it easire for more advanced users to simulate an entire experiment.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Includes_v520.ipf

    r871 r890  
    8787#include "EventModeProcessing" 
    8888 
     89// SRK JAN 2013 - to make simulation easier 
     90#include "MC_SimulationScripting" 
    8991 
    9092// a simple list of items to add to the Beta menu 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/MultScatter_MonteCarlo_2D.ipf

    r888 r890  
    13561356 
    13571357/// called in SASCALC:ReCalculateInten() 
    1358 Function Simulate_2D_MC(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs) 
     1358Function Simulate_2D_MC(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs,estimateOnly) 
    13591359        String funcStr 
    13601360        WAVE aveint,qval,sigave,sigmaq,qbar,fsubs 
    1361  
     1361        Variable estimateOnly 
     1362         
    13621363        NVAR doMonteCarlo = root:Packages:NIST:SAS:gDoMonteCarlo                // == 1 if 2D MonteCarlo set by hidden flag 
    13631364        WAVE rw=root:Packages:NIST:SAS:realsRead 
     
    14691470        t0 *= 2         //empirical correction, since processor count returns 8 for (4 real + 4 virtual) 
    14701471        Print "Estimated Simulation time (s) = ",t0 
     1472         
     1473         
     1474        if(estimateOnly) 
     1475                return(t0) 
     1476        endif 
     1477         
    14711478         
    14721479// to correct for detector efficiency, send only the fraction of neutrons that are actually counted      
     
    16091616                                 
    16101617        // simulate the empty cell scattering, only in 1D 
    1611         Simulate_1D_EmptyCell("TwoLevel_EC",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     1618//      Simulate_1D_EmptyCell("TwoLevel_EC",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     1619        Simulate_1D_EmptyCell("EC_Empirical",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     1620         
    16121621        Print "Sample Simulation (2D) CR = ",results[9]/ctTime 
     1622         
    16131623        // check, so that RT simulation won't display SAS data type 
    16141624        NVAR/Z gFakeUpdate = root:myGlobals:gFakeUpdate 
     
    20002010                                 
    20012011         
    2002         Simulate_1D_EmptyCell("TwoLevel_EC",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     2012//      Simulate_1D_EmptyCell("TwoLevel_EC",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     2013        Simulate_1D_EmptyCell("EC_Empirical",aveint,qval,sigave,sigmaq,qbar,fsubs) 
     2014         
     2015         
    20032016        Print "Sample Simulation (1D) CR = ",estDetCR 
    20042017         
     
    20442057// - there is little difference vs. the empty cell alone. 
    20452058// 
    2046 // - data was fit to the TwoLevel model, which fits rather nicely 
     2059// - data was fit to the TwoLevel model, which fits rather nicely, or an empirical function EC_Empirical 
    20472060// 
    20482061Function Simulate_1D_EmptyCell(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs) 
     
    20502063        WAVE aveint,qval,sigave,sigmaq,qbar,fsubs 
    20512064 
    2052         Variable r1,xCtr,yCtr,sdd,pixSize,wavelength 
     2065        Variable r1,xCtr,yCtr,sdd,pixSize,wavelength,thick 
    20532066        String coefStr,abortStr,str      
    20542067 
     
    20562069        FUNCREF SANSModelAAO_MCproto funcUnsmeared=$(funcStr)           //unsmeared 
    20572070         
    2058         Make/O/D root:Packages:NIST:SAS:coef_Empty = {1,1.84594,714.625,5e-08,2.63775,0.0223493,3.94009,0.0153754,1.72127,0} 
    2059         WAVE coefW = root:Packages:NIST:SAS:coef_Empty 
    2060          
     2071 
    20612072        Wave samInten=$"root:Simulation:Simulation_i"           // this will exist and send the smeared calculation to the corect DF 
    20622073        Duplicate/O samInten, root:Simulation:Simulation_EC_i 
    20632074        Wave inten_EC=$"root:Simulation:Simulation_EC_i" 
    20642075 
     2076        if(cmpstr(funcStr,"EC_Empirical") == 0) 
     2077                make/O/D root:Packages:NIST:SAS:coef_ECEmp = {2.2e-8,3.346,0.0065,9.0,0.016} 
     2078                WAVE coefW = root:Packages:NIST:SAS:coef_ECEmp 
     2079                thick = 0.1             //this works for the empirical model 
     2080        else 
     2081                //use the "TwoLevel" model 
     2082                Make/O/D root:Packages:NIST:SAS:coef_Empty = {1,1.84594,714.625,5e-08,2.63775,0.0223493,3.94009,0.0153754,1.72127,0} 
     2083                WAVE coefW = root:Packages:NIST:SAS:coef_Empty 
     2084                // for two 1/16" quartz windows, thick = 0.32 cm 
     2085                thick = 0.32 
     2086        endif 
     2087 
    20652088        // the resolution-smeared intensity of the empty cell 
    20662089        func(coefW,inten_EC,qval) 
     2090 
    20672091 
    20682092        NVAR imon = root:Packages:NIST:SAS:gImon 
     
    20792103//      use local variables here for the Empty cell - maybe use globals later, if I really want to save them 
    20802104// - here, just print them out for now 
    2081         Variable SimDetCts,estDetCR,fracScat,estTrans,mScat,thick 
    2082          
    2083 // for two 1/16" quartz windows, thick = 0.32 cm 
    2084         thick = 0.32 
     2105        Variable SimDetCts,estDetCR,fracScat,estTrans,mScat 
     2106         
     2107 
    20852108         
    20862109        WAVE rw=root:Packages:NIST:SAS:realsRead 
     
    21132136        mscat *= (estTrans)/(1-estTrans) 
    21142137 
    2115          
    21162138        Duplicate/O qval prob_i_EC,countsInAnnulus_EC 
    21172139         
     
    23822404 
    23832405 
    2384 //// this is a very simple example of how to script the MC simulation to run unattended 
    2385 // 
    2386 //  you need to supply for each "run":  the run index (you increment manually) 
    2387 //                                                                                              the sample label (as a string) 
    2388 // 
    2389 // changing the various configuration paramters will have to be done on a case-by-case basis 
    2390 // looking into SASCALC to see what is really changed, 
    2391 // or the configuration parameters of the MC_SASCALC panel  
    2392 // 
    2393 // 
    2394 Function Script_2DMC() 
    2395  
    2396  
    2397         NVAR SimTimeWarn = root:Packages:NIST:SAS:g_SimTimeWarn 
    2398         SimTimeWarn = 36000                     //sets the threshold for the warning dialog to 10 hours 
    2399         STRUCT WMButtonAction ba 
    2400         ba.eventCode = 2                        //fake mouse click on button 
    2401          
    2402         NVAR detDist = root:Packages:NIST:SAS:gDetDist 
    2403  
    2404         detDist = 200           //set directly in cm 
    2405         MC_DoItButtonProc(ba) 
    2406         SaveAsVAXButtonProc("",runIndex=105,simLabel="this is run 105, SDD = 200") 
    2407          
    2408         detDist = 300           //set directly in cm 
    2409         MC_DoItButtonProc(ba) 
    2410         SaveAsVAXButtonProc("",runIndex=106,simLabel="this is run 106, SDD = 300") 
    2411  
    2412         detDist = 400           //set directly in cm 
    2413         MC_DoItButtonProc(ba) 
    2414         SaveAsVAXButtonProc("",runIndex=107,simLabel="this is run 107, SDD = 400") 
    2415          
    2416  
    2417  SimTimeWarn = 10               //back to 10 seconds for manual operation 
    2418         return(0) 
    2419 end 
     2406////// this is a very simple example of how to script the MC simulation to run unattended 
     2407//// 
     2408////  you need to supply for each "run":        the run index (you increment manually) 
     2409////                                                                                            the sample label (as a string) 
     2410//// 
     2411//// changing the various configuration paramters will have to be done on a case-by-case basis 
     2412//// looking into SASCALC to see what is really changed, 
     2413//// or the configuration parameters of the MC_SASCALC panel  
     2414//// 
     2415//// 
     2416//Function Script_2DMC() 
     2417// 
     2418// 
     2419//      NVAR SimTimeWarn = root:Packages:NIST:SAS:g_SimTimeWarn 
     2420//      SimTimeWarn = 36000                     //sets the threshold for the warning dialog to 10 hours 
     2421//      STRUCT WMButtonAction ba 
     2422//      ba.eventCode = 2                        //fake mouse click on button 
     2423//       
     2424//      NVAR detDist = root:Packages:NIST:SAS:gDetDist 
     2425// 
     2426//      detDist = 200           //set directly in cm 
     2427//      MC_DoItButtonProc(ba) 
     2428//      SaveAsVAXButtonProc("",runIndex=105,simLabel="this is run 105, SDD = 200") 
     2429//       
     2430//      detDist = 300           //set directly in cm 
     2431//      MC_DoItButtonProc(ba) 
     2432//      SaveAsVAXButtonProc("",runIndex=106,simLabel="this is run 106, SDD = 300") 
     2433// 
     2434//      detDist = 400           //set directly in cm 
     2435//      MC_DoItButtonProc(ba) 
     2436//      SaveAsVAXButtonProc("",runIndex=107,simLabel="this is run 107, SDD = 400") 
     2437//       
     2438// 
     2439// SimTimeWarn = 10             //back to 10 seconds for manual operation 
     2440//      return(0) 
     2441//end 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/NCNR_Utils.ipf

    r889 r890  
    18141814                        break 
    18151815                case "NGA": 
    1816                         Print "Using the NG7 table for NGA *** this needs to be updated ***" 
     1816//                      Print "Using the NG7 table for NGA *** this needs to be updated ***" 
    18171817                        attenFactor = LookupAttenNGA(lam,attenNo,atten_err) 
    18181818                        break 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/ProtocolAsPanel.ipf

    r857 r890  
    20732073                String tempName = S_Path + FindValidFilename(filename) 
    20742074                err = GetXYBoxFromFile(tempName,x1,x2,y1,y2)            //xy's are passed/returned by reference 
    2075                 Print x1,x2,y1,y2 
     2075//              Print x1,x2,y1,y2 
    20762076 
    20772077                if( ((x1-x2)==0) || ((y1-y2)==0) )      //need to re-select the box 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/SASCALC.ipf

    r889 r890  
    162162        Variable/G root:Packages:NIST:SAS:g_actSimTime = 0                              //for the save 
    163163        Variable/G root:Packages:NIST:SAS:g_SimTimeWarn = 10                    //manually set to a very large value for scripted operation 
    164          
     164        Variable/G root:Packages:NIST:SAS:g_estimateOnly = 0                    // == 1 for just a time estimate, == 0 (default) to do the simulation 
     165        Variable/G root:Packages:NIST:SAS:g_estimatedMCTime             // estimated MC sim time 
     166         
     167        PlotEC_Empirical(100,0.001,0.7)         // plot an empirical empty cell, only used for the simulation, not needed for SASCALC 
     168        KillTopGraphAndTable(1)                                 // then kill the graph and table that the macro generates 
    165169         
    166170        //tick labels for SDD slider 
     
    12141218        NVAR doMonteCarlo = root:Packages:NIST:SAS:gDoMonteCarlo                // == 1 if 2D MonteCarlo set by hidden flag 
    12151219        NVAR doSimulation = root:Packages:NIST:SAS:doSimulation         // == 1 if 1D simulated data, 0 if other from the checkbox 
     1220        NVAR g_estimateOnly = root:Packages:NIST:SAS:g_estimateOnly             // == 1 for just a time estimate, == 0 (default) to do the simulation 
     1221        NVAR g_estimatedMCTime = root:Packages:NIST:SAS:g_estimatedMCTime               // estimated MC sim time 
    12161222        SVAR funcStr = root:Packages:NIST:SAS:gFuncStr          //set by the popup 
    12171223 
     
    12201226                        //2D simulation (in MultiScatter_MonteCarlo_2D.ipf) 
    12211227                         
    1222                         Simulate_2D_MC(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs) 
     1228                        g_estimatedMCTime = Simulate_2D_MC(funcStr,aveint,qval,sigave,sigmaq,qbar,fsubs,g_estimateOnly) 
    12231229                         
    12241230                        //end 2D simulation 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/WorkFileUtils.ipf

    r836 r890  
    535535                        ratio = domega^3 
    536536                        xy = xx[ii]*yy[jj] 
     537                         
    537538                        data[ii][jj] *= xy*ratio 
     539                         
    538540                        solidAngle[ii][jj] = xy*ratio           //testing only   
    539541                        data_err[ii][jj] *= xy*ratio                    //error propagation assumes that SA and Jacobian are exact, so simply scale error 
     
    583585                                data_err[ii][jj] = tmp_err 
    584586                                 
    585                                 solidAngle[ii][jj] = lat_err 
     587//                              solidAngle[ii][jj] = lat_err 
    586588 
    587589                                 
Note: See TracChangeset for help on using the changeset viewer.