- Timestamp:
- Feb 3, 2009 3:57:08 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/SASCALC.ipf
r465 r472 17 17 // Lens flux, trans is not corrected for lens/prism transmission 18 18 // Lenses can still be inserted in incorrect cases, and are not automatically taken out 19 // 27 JAN 2009 SRK - Changed behavior of Lens checkbox. Now, it SETS parameters as needed for proper 20 // configuration. 17.2 can be typed in for lens/prism on NG3. Invalid conditions 21 // will automatically uncheck the box 19 22 // 20 23 // calculate what q-values you get based on the instruments settings … … 25 28 // 26 29 // To Do: 27 // - add in instrument conditions for lens/(lens+prism) configurations28 // - proper resolution calculation for lens/prism29 //30 30 // 31 31 // Optional: … … 61 61 ReCalculateInten(1) //will use defaults 62 62 Endif 63 64 DoWindow/F MC_SASCALC 65 if(V_flag==0) 66 MC_SASCALC() 67 endif 63 64 // now a checkbox as needed 65 // DoWindow/F MC_SASCALC 66 // if(V_flag==0) 67 // MC_SASCALC() 68 // endif 68 69 End 69 70 … … 108 109 109 110 // for the MC simulation 111 Variable/G root:Packages:NIST:SAS:gRanDateTime=datetime 110 112 Variable/G root:Packages:NIST:SAS:gImon = 10000 111 113 Variable/G root:Packages:NIST:SAS:gThick = 0.1 … … 115 117 Variable/G root:Packages:NIST:SAS:gCntTime = 1 116 118 Variable/G root:Packages:NIST:SAS:gDoMonteCarlo = 0 119 Variable/G root:Packages:NIST:SAS:gRawCounts = 0 120 Variable/G root:Packages:NIST:SAS:gSaveIndex = 100 121 String/G root:Packages:NIST:SAS:gSavePrefix = "SIMUL" 117 122 Make/O/D/N=10 root:Packages:NIST:SAS:results = 0 118 Make/O/T/N=10 root:Packages:NIST:SAS:results_desc = {"total X-section (1/cm)","SAS X-section (1/cm)","number that scatter","number that reach detector","avg # times scattered","fraction single coherent","fraction double coherent","fraction multiple scattered","fraction transmitted","detector counts w/ beamstop"}123 Make/O/T/N=10 root:Packages:NIST:SAS:results_desc = {"total X-section (1/cm)","SAS X-section (1/cm)","number that scatter","number that reach detector","avg # times scattered","fraction single coherent","fraction double coherent","fraction multiple scattered","fraction transmitted","detector counts w/o beamstop"} 119 124 120 125 //tick labels for SDD slider … … 132 137 //for plotting 133 138 Variable/G root:Packages:NIST:SAS:gFreezeCount=1 //start the count at 1 to keep Jeff happy 139 Variable/G root:Packages:NIST:SAS:gDoTraceOffset=1 // (1==Yes, offset 2^n), 0==turn off the offset 140 134 141 End 135 142 … … 283 290 284 291 PauseUpdate; Silent 1 // building window... 292 293 // if I make the graph a subwindow in a panel, it breaks the "append 1d" from the wrapper 294 // NewPanel/W=(5,44,463,570)/K=1 as "SASCALC" 295 // DoWindow/C SASCALC 296 // ModifyPanel cbRGB=(49151,53155,65535) 297 // 298 // 299 // String fldrSav0= GetDataFolder(1) 300 // SetDataFolder root:Packages:NIST:SAS: 301 // 302 // Display/HOST=#/W=(5,200,463,570) aveint vs qval 303 // ModifyGraph mode=3 304 // ModifyGraph marker=19 305 // ModifyGraph rgb=(0,0,0) 306 // Modifygraph log=1 307 // Modifygraph grid=1 308 // Modifygraph mirror=2 309 // ModifyGraph msize(aveint)=2 310 // ErrorBars/T=0 aveint Y,wave=(sigave,sigave) 311 // Label bottom, "Q (1/A)" 312 // Label left, "Relative Intensity" 313 // legend 314 // 315 // RenameWindow #,G_aveint 316 // SetActiveSubwindow ## 317 318 //// end panel commands 319 320 /// draw as a graph 285 321 String fldrSav0= GetDataFolder(1) 286 322 SetDataFolder root:Packages:NIST:SAS: 287 Display /W=(5,44,463,570)/K=1 aveint vs qval as "SASCALC" 323 324 Display/W=(5,44,463,570)/K=1 aveint vs qval as "SASCALC" 288 325 DoWindow/C SASCALC 289 326 ModifyGraph cbRGB=(49151,53155,65535) … … 299 336 Label left, "Relative Intensity" 300 337 legend 338 339 ControlBar/T 200 340 301 341 SetDataFolder fldrSav0 302 303 304 ControlBar 200305 342 306 343 Slider SC_Slider,pos={11,46},size={150,45},proc=GuideSliderProc,live=0 … … 344 381 CheckBox checkLens,value=root:Packages:NIST:SAS:gUsingLenses 345 382 346 // CheckBox checkSim,pos={20,165},size={44,14},proc=SimCheckProc,title="Simulation?"347 //CheckBox checkSim,value=0383 CheckBox checkSim,pos={6,175},size={44,14},proc=SimCheckProc,title="MC Simulation?" 384 CheckBox checkSim,value=0 348 385 349 386 // set up a fake dependency to trigger recalculation … … 431 468 Variable event // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved 432 469 470 Variable recalc=0 471 433 472 if(event %& 0x1) // bit 0, value set 434 if(sliderValue != 0) 435 LensCheckProc("",0) //make sure lenses are deselected 473 if(cmpstr(ctrlName,"") != 0) //here by direct action, so do LensCheck and recalculate 474 recalc=1 475 LensCheckProc("",2) //make sure lenses are deselected 436 476 endif 437 477 sourceToSampleDist() //updates the SSD global and wave 438 478 //change the sourceAp popup, SDD range, etc 439 479 UpdateControls() 440 ReCalculateInten( 1)480 ReCalculateInten(recalc) 441 481 endif 442 482 return 0 … … 450 490 Variable event // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved 451 491 492 Variable recalc=0 452 493 if(event %& 0x1) // bit 0, value set 453 if(sliderValue < 1300) 454 LensCheckProc("",0) //make sure lenses are deselected 494 if(cmpstr(ctrlName,"") != 0) 495 recalc=1 496 LensCheckProc("",2) //make sure lenses are only selected for valid configurations 455 497 endif 456 498 sampleToDetectorDist() //changes the SDD and wave (DetDist is the global) 457 ReCalculateInten( 1)499 ReCalculateInten(recalc) 458 500 endif 459 501 … … 493 535 initNG7() 494 536 endif 537 LensCheckProc("",2) //check if lenses are still valid (they won't be) 495 538 UpdateControls() 496 539 ReCalculateInten(1) … … 520 563 521 564 //lenses (or prisms) in/out changes resolution 565 // 566 // passing in a checked == 2 will do a check of the configuration without 567 // affecting the box state 568 // 569 // if an invalid configuration is detected, the box is unchecked 570 // and the lens flag is set to zero (=out). 571 // 572 // When necessary controls are "popped", a ctrlName="" is passed to signal the control 573 // to NOT recalculate the intensity, and to NOT (recursively) call LensCheckProc again 574 // 575 // currently, the 17.2 A for lens/prism @ ng3 must be typed in 576 // 522 577 Function LensCheckProc(ctrlName,checked) : CheckBoxControl 523 578 String ctrlName … … 531 586 NVAR lam = root:Packages:NIST:SAS:gLambda 532 587 NVAR dist = root:Packages:NIST:SAS:gDetDist 533 534 if( (Ng != 0) || (lam < 8) || (dist < 1300) ) 588 NVAR instrument = root:Packages:NIST:SAS:instrument 589 Wave rw=root:Packages:NIST:SAS:realsRead 590 591 // directly uncheck the box, just set the flag and get out 592 if(checked == 0) 535 593 lens = 0 536 594 CheckBox checkLens,value=0 595 rw[28]=0 //flag for lenses out 596 ReCalculateInten(1) 537 597 return(0) 538 598 endif 539 lens = checked 540 541 ReCalculateInten(1) 542 End 543 544 ////simulation control panel 545 //Function SimCheckProc(ctrlName,checked) : CheckBoxControl 546 // String ctrlName 547 // Variable checked 548 // 549 // if(checked) 550 // DoWindow/F MC_SASCALC 551 // if(V_flag==0) 552 // Execute "MC_SASCALC()" 553 // endif 554 // endif 555 // return(0) 556 //End 599 600 // check the box, enforce the proper conditions 601 if(checked == 1) 602 lens = checked 603 if(instrument == 3) 604 dist = 1317 605 DetDistSliderProc("",1317,1) 606 607 lam = 8.4 608 LambdaSetVarProc("",8.4,"8.4","") 609 610 ng=0 611 GuideSliderProc("",0,1) //this updates the controls to the new # of guides 612 613 PopupMenu popup0,mode=1,popvalue="1.43 cm" //first item in source aperture menu 614 615 PopupMenu popup0_2,mode=2 //deltaLambda 616 ControlInfo popup0_2 617 DeltaLambdaPopMenuProc("",0,S_value) //zero as 2nd param skips recalculation 618 else 619 dist = 1531 620 DetDistSliderProc("",1531,1) 621 622 lam = 8.09 623 LambdaSetVarProc("",8.09,"8.09","") 624 625 ng=0 626 GuideSliderProc("",0,1) 627 PopupMenu popup0,mode=1,popvalue="1.43 cm" //first item 628 629 PopupMenu popup0_2,mode=2 //deltaLambda 630 ControlInfo popup0_2 631 DeltaLambdaPopMenuProc("",0,S_value) //zero as 2nd param skips recalculation 632 endif 633 rw[28]=1 //flag for lenses in (not the true number, but OK) 634 ReCalculateInten(1) 635 endif 636 637 // this is my internal check to see if conditions are still valid 638 // I'll uncheck as needed 639 if(checked == 2) 640 641 // source aperture must be 1.43 cm diameter 642 // number of guides must be zero 643 Variable a1 = sourceApertureDiam() 644 if(a1 != 1.43 || Ng !=0) 645 lens = 0 646 CheckBox checkLens,value=0 647 rw[28]=0 //flag for lenses out 648 return(0) 649 endif 650 651 // instrument specific distance requirements 652 if(instrument == 3 && dist != 1317) 653 lens = 0 654 CheckBox checkLens,value=0 655 rw[28]=0 //flag for lenses out 656 return(0) 657 endif 658 659 if(instrument == 7 && dist != 1531) 660 lens = 0 661 CheckBox checkLens,value=0 662 rw[28]=0 //flag for lenses out 663 return(0) 664 endif 665 666 // instrument specific wavelength requirements 667 if(instrument == 3 && !(lam == 8.4 || lam == 17.2) ) 668 lens = 0 669 CheckBox checkLens,value=0 670 rw[28]=0 //flag for lenses out 671 return(0) 672 endif 673 674 if(instrument == 7 && lam != 8.09 ) 675 lens = 0 676 CheckBox checkLens,value=0 677 rw[28]=0 //flag for lenses out 678 return(0) 679 endif 680 681 endif 682 683 return(1) //return value not used 684 End 685 686 //simulation ccontrols as a control bar that toggles on/off to the right 687 Function SimCheckProc(ctrlName,checked) : CheckBoxControl 688 String ctrlName 689 Variable checked 690 691 if(checked) 692 //MoveWindow/W=SASCALC 5,44,763,570 //to resize 693 // draw the controls 694 DoWindow/F MC_SASCALC 695 if(V_flag==0) 696 Execute "MC_SASCALC()" 697 AutoPositionWindow/M=1/R=SASCALC MC_SASCALC 698 endif 699 else 700 //get rid of the controls 701 DoWindow MC_SASCALC 702 if(V_flag!=0) 703 KillWindow MC_SASCALC 704 endif 705 //MoveWindow/W=SASCALC 5,44,463,570 //to resize 706 //KillWindow SASCALC#T_results 707 endif 708 709 return(0) 710 End 557 711 558 712 // change the source aperture … … 565 719 Variable a1 = sourceApertureDiam() //sets the new value in the wave 566 720 721 // if LensCheckProc is calling this, don't call it again. 722 // if this is called by a direct pop, then check 723 if(cmpstr(ctrlName,"") != 0) 724 LensCheckProc("",2) //make sure lenses are only selected for valid configurations 725 endif 726 567 727 ReCalculateInten(popnum) //skip the recalculation if I pass in a zero 568 728 End … … 588 748 589 749 sampleToDetectorDist() 590 750 if(cmpstr(ctrlName,"") != 0) 751 LensCheckProc("",2) //make sure lenses are only selected for valid configurations 752 endif 591 753 ReCalculateInten(1) 592 754 End … … 615 777 616 778 WAVE rw=root:Packages:NIST:SAS:realsRead 779 Variable recalc=0 780 617 781 rw[26] = str2num(varStr) 618 ReCalculateInten(1) 782 if(cmpstr(ctrlName,"") != 0) 783 recalc=1 784 LensCheckProc("",2) //make sure lenses are only selected for valid configurations 785 endif 786 ReCalculateInten(recalc) 619 787 return(0) 620 788 End … … 663 831 return(0) 664 832 endif 833 // Print "recalculate" 665 834 666 835 // update the wave with the beamstop diameter here, since I don't know what … … 784 953 785 954 t0 = (stopMSTimer(-2) - t0)*1e-6 786 Printf "MC sim time = %g seconds\r \r",t0955 Printf "MC sim time = %g seconds\r",t0 787 956 788 957 trans = results[8] //(n1-n2)/n1 … … 794 963 795 964 linear_data[xCtr][yCtr] = 0 //snip out the transmitted spike 796 Print "counts on detector not transmitted = ",sum(linear_data,-inf,inf)965 // Print "counts on detector not transmitted = ",sum(linear_data,-inf,inf) 797 966 798 967 // or simulate a beamstop … … 805 974 806 975 linear_data *= tmp_mask 807 Print "counts on detector not behind beamstop = ",sum(linear_data,-inf,inf)808 976 results[9] = sum(linear_data,-inf,inf) 977 // Print "counts on detector not behind beamstop = ",results[9] 809 978 810 979 // convert to absolute scale … … 812 981 // kappa = beamInten*pi*r1*r1*thick*(pixSize/sdd)^2*trans*(iMon/beaminten) 813 982 kappa = thick*(pixSize/sdd)^2*trans*iMon 814 815 linear_data = linear_data / kappa 816 983 984 //use kappa to get back to counts => linear_data = round(linear_data*kappa) 985 Note/K linear_data ,"KAPPA="+num2str(kappa)+";" 986 987 NVAR rawCts = root:Packages:NIST:SAS:gRawCounts 988 if(!rawCts) //go ahead and do the linear scaling 989 linear_data = linear_data / kappa 990 endif 817 991 data = linear_data 818 992 819 993 // re-average the 2D data 820 994 S_CircularAverageTo1D("SAS") 821 // multiply either estimate by beamstop shadowing 822 823 // aveint *= fSubS 824 995 825 996 // put the new result into the simulation folder 826 997 Fake1DDataFolder(qval,aveint,sigave,sigmaQ,qbar,fSubs,"Simulation") … … 873 1044 Duplicate/O sigave,$("sigave_"+num2str(ct)) 874 1045 Appendtograph $("aveint_"+num2str(ct)) vs $("qval_"+num2str(ct)) 875 ModifyGraph mode =3876 ModifyGraph marker =191046 ModifyGraph mode($("aveint_"+num2str(ct)))=3 1047 ModifyGraph marker($("aveint_"+num2str(ct)))=19 877 1048 ModifyGraph msize($("aveint_"+num2str(ct)))=2 878 1049 ErrorBars/T=0 $("aveint_"+num2str(ct)) Y,wave=($("sigave_"+num2str(ct)),$("sigave_"+num2str(ct))) … … 911 1082 endswitch 912 1083 1084 NVAR doTraceOffset = root:Packages:NIST:SAS:gDoTraceOffset 913 1085 NVAR offset = root:Packages:NIST:SAS:gModelOffsetFactor 914 offset = 2^ct 915 //multiply by current offset (>=1) 916 Wave inten = $("aveint_"+num2str(ct)) 917 inten *= offset 918 // Print "new offset = ",offset 1086 if(doTraceOffset) 1087 offset = 2^ct 1088 //multiply by current offset (>=1) 1089 Wave inten = $("aveint_"+num2str(ct)) 1090 inten *= offset 1091 // Print "new offset = ",offset 1092 endif 919 1093 920 1094 ct +=1
Note: See TracChangeset
for help on using the changeset viewer.