Ignore:
Timestamp:
Jun 20, 2017 3:17:19 PM (6 years ago)
Author:
srkline
Message:

event mode processing - splitting the binned data into 4 panels, speedup of binning, display of split panels.

fitting routines for fitting 5 peaks for nonlinear corrections.

all needs to documented, then expanded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_EventModeProcessing.ipf

    r1046 r1047  
    22#pragma IgorVersion=6.22 
    33 
    4 // vers 7.13e 
     4// 
     5// Event mode prcessing for VSANS 
     6// 
     7// First pass, getting the basics to work 
     8// 
     9// -- need TOF processing for wavelength calibration 
     10//  -- document this so it can be done quickly and easily. 
     11// 
     12 
     13 
     14 
    515 
    616// TODO: 
     
    3949 
    4050 
    41 // TODO -- these dimensions are hard-wired and will be wrong half of the time 
    42 // 
    43 Static Constant XBINS=48 
    44 Static Constant YBINS=128 
     51// TODO  
     52// x- these dimensions are hard-wired (OK) 
     53// 
     54Constant XBINS=48 
     55Constant NTUBES=192 
     56Constant YBINS=128 
    4557 
    4658Static Constant MODE_STREAM = 0 
     
    6072 
    6173// TODO: 
    62 //  -- need an index table with the tube <-> panel correspondence 
     74//  x- need an index table with the tube <-> panel correspondence 
     75//    NO, per Phil, the tube numbering is sequential: 
     76// 
     77// Based on the numbering 0-191: 
     78// group 1 = R (0,47)                   MatrixOp out = ReverseRows(in) 
     79// group 2 = T (48,95)          output = slices_T[q][p][r] 
     80// group 3 = B (96,143)                 output = slices_B[XBINS-q-1][YBINS-p-1][r]              (reverses rows and columns) 
     81// group 4 = L (144,191)        MatrixOp out = ReverseCols(in) 
     82// 
     83// There is a separate function that does the proper flipping to get the panels into the correct orientation 
    6384// 
    6485Function V_Init_Event() 
     
    169190        PopupMenu popup0,mode=1,popvalue="Equal",value= #"\"Equal;Fibonacci;Custom;\"" 
    170191        Button button1,pos={389,103},size={120,20},fSize=12,proc=V_ProcessEventLog_Button,title="Bin Event Data" 
     192 
     193 
     194        Button button21,pos={580,70},size={120,20},proc=V_SplitToPanels_Button,title="Split to Panels" 
     195        Button button22,pos={580,90},size={120,20},proc=V_GraphPanels_Button,title="Show Panels" 
    171196 
    172197        Button button10,pos={488,305},size={100,20},proc=V_SplitFileButtonProc,title="Split Big File",disable=2 
     
    216241 
    217242 
    218  
     243Function V_SplitToPanels_Button(ba) : ButtonControl 
     244        STRUCT WMButtonAction &ba 
     245 
     246        switch( ba.eventCode ) 
     247                case 2: // mouse up 
     248                        // click code here 
     249                        V_SplitBinnedToPanels() 
     250                        // 
     251                        break 
     252                case -1: // control being killed 
     253                        break 
     254        endswitch 
     255 
     256        return 0 
     257End 
     258 
     259Function V_GraphPanels_Button(ba) : ButtonControl 
     260        STRUCT WMButtonAction &ba 
     261 
     262        switch( ba.eventCode ) 
     263                case 2: // mouse up 
     264                        // click code here 
     265                        Execute "VSANS_EventPanels()" 
     266                        // 
     267                        break 
     268                case -1: // control being killed 
     269                        break 
     270        endswitch 
     271 
     272        return 0 
     273End 
    219274 
    220275// mode selector 
     
    427482        String ctrlName 
    428483 
    429         Make/O/D/N=(XBINS,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
     484//      Make/O/D/N=(XBINS,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
     485        Make/O/D/N=(NTUBES,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
    430486         
    431487        Wave binnedData = root:Packages:NIST:VSANS:Event:binnedData 
     
    440496        SetDataFolder root:Packages:NIST:VSANS:Event            //don't count on the folder remaining here 
    441497         
    442         Make/D/O/N=(XBINS,YBINS,nslices) slicedData 
     498//      Make/D/O/N=(XBINS,YBINS,nslices) slicedData 
     499        Make/D/O/N=(NTUBES,YBINS,nslices) slicedData 
    443500                 
    444501        Wave slicedData = slicedData 
    445502        Wave rescaledTime = rescaledTime 
    446503        Wave timePt = timePt 
    447         Make/O/D/N=(XBINS,YBINS) tmpData 
     504//      Make/O/D/N=(XBINS,YBINS) tmpData 
     505        Make/O/D/N=(NTUBES,YBINS) tmpData 
    448506        Make/O/D/N=(nslices+1) binEndTime,binCount 
    449507        Make/O/D/N=(nslices) timeWidth 
     
    490548        SetDataFolder root:Packages:NIST:VSANS:Event: 
    491549 
     550s_tic() 
    492551        if(WaveExists($"root:Packages:NIST:VSANS:Event:OscSortIndex") == 0 ) 
    493552                Duplicate/O rescaledTime OscSortIndex 
     
    499558        Endif 
    500559         
     560printf "sort time = " 
     561s_toc() 
     562 
    501563        Wave index = root:Packages:NIST:VSANS:Event:SavedIndex          //this is the histogram index 
    502564 
     565s_tic() 
    503566        for(ii=0;ii<nslices;ii+=1) 
    504567                if(ii==0) 
     
    534597                binCount[ii] = sum(tmpData,-inf,inf) 
    535598        endfor 
     599printf "histogram time = " 
     600s_toc() 
    536601 
    537602        Duplicate/O slicedData,root:Packages:NIST:VSANS:Event:dispsliceData,root:Packages:NIST:VSANS:Event:logSlicedData 
     
    556621 
    557622         
    558         Make/O/D/N=(XBINS,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
     623//      Make/O/D/N=(XBINS,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
     624        Make/O/D/N=(NTUBES,YBINS) root:Packages:NIST:VSANS:Event:binnedData 
    559625         
    560626        Wave binnedData = root:Packages:NIST:VSANS:Event:binnedData 
     
    570636        SetDataFolder root:Packages:NIST:VSANS:Event            //don't count on the folder remaining here 
    571637         
    572         Make/D/O/N=(XBINS,YBINS,nslices) slicedData 
     638//      Make/D/O/N=(XBINS,YBINS,nslices) slicedData 
     639        Make/D/O/N=(NTUBES,YBINS,nslices) slicedData 
    573640                 
    574641        Wave slicedData = slicedData 
    575642        Wave rescaledTime = rescaledTime 
    576         Make/O/D/N=(XBINS,YBINS) tmpData 
     643//      Make/O/D/N=(XBINS,YBINS) tmpData 
     644        Make/O/D/N=(NTUBES,YBINS) tmpData 
    577645        Make/O/D/N=(nslices+1) binEndTime,binCount//,binStartTime 
    578646        Make/O/D/N=(nslices) timeWidth 
     
    865933        SetDataFolder root:Packages:NIST:VSANS:Event:                   //GBLoadWave in V_LoadEvents sets back to root: 
    866934 
    867  
    868935// Now, I have tube, location, and timePt (no units yet) 
    869936// assign to the proper panels 
    870937 
    871 s_tic() 
    872         V_SortAndSplitEvents() 
    873  
    874 Printf "File sort and split time (s) = " 
    875 s_toc() 
    876  
    877 // TODO -- currently, nothing is assigned, and nothing is assigned properly - just a  
    878 // fake assignment to get the TOF to use all of the data 
    879 // 
     938// TODO: 
     939// x- (YES - this is MUCH faster) what if I do the JointHistogram first, then break out the blocks of the  
     940//  3D sliced data into the individual panels. Then the sort operation could be skipped, 
     941//  since it would implicitly be done during the histogram operation 
     942// x- go back and redimension as needed to get the 128 x 192 histogram to work 
     943// x- MatrixOp or a wave assignemt should be able to break up the 3D 
     944// 
     945 
     946                KillWaves/Z timePt,xLoc,yLoc 
     947                Duplicate/O eventTime timePt 
     948 
     949// TODO: 
     950// x- for processing, initially treat all of the tubes along x, and 128 pixels along y 
     951//   panels can be transposed later as needed to get the orientation correct 
     952 
     953                Duplicate/O tube xLoc 
     954                Duplicate/O location yLoc 
     955                 
     956                Redimension/D xLoc,yLoc,timePt   
     957                 
     958//s_tic() 
     959//      V_SortAndSplitEvents() 
     960// 
     961//Printf "File sort and split time (s) = " 
     962//s_toc() 
     963 
    880964 
    881965// 
     
    886970// 
    887971 
    888         V_SwitchTubeGroup(1) 
     972//      V_SwitchTubeGroup(1) 
    889973 
    890974//       
     
    10501134// for the bit shifts, see the decimal-binary conversion 
    10511135// http://www.binaryconvert.com/convert_unsigned_int.html 
    1052 // and for 64-bit values: 
     1136// 
     1137//  for 64-bit values: 
    10531138// http://calc.penjee.com 
    10541139// 
     
    11631248        Make/O/L/U/N=(num) eventTime                    //64 bit unsigned 
    11641249        Make/O/U/B/N=(num) tube,location                //8 bit unsigned 
    1165          
    1166         for(ii=0;ii<num;ii+=1) 
    1167                 val = V_Events[ii] 
    1168                  
    1169 //              b1 = (val >> 56 ) & 0xFF                        // = 255, last two bytes, after shifting 
    1170 //              b2 = (val >> 48 ) & 0xFF         
    1171 //              btime = val & 0xFFFFFFFFFFFF    // = really big number, last 6 bytes 
    1172  
    1173                 b1 = val & 0xFF 
    1174                 b2 = (val >> 8) & 0xFF 
    1175                 btime = (val >> 16) 
    1176  
    1177  
    1178                 tube[ii] = b1 
    1179                 location[ii] = b2 
    1180                 eventTime[ii] = btime 
    1181                  
    1182         endfor 
     1250 
     1251// MultiThread is about 10x faster than the for loop 
     1252 MultiThread tube = (V_Events[p]) & 0xFF         
     1253 MultiThread location = (V_Events[p] >> 8 ) & 0xFF       
     1254 MultiThread eventTime = (V_Events[p] >> 16) 
     1255         
     1256//      for(ii=0;ii<num;ii+=1) 
     1257//              val = V_Events[ii] 
     1258//               
     1259////            b1 = (val >> 56 ) & 0xFF                        // = 255, last two bytes, after shifting 
     1260////            b2 = (val >> 48 ) & 0xFF         
     1261////            btime = val & 0xFFFFFFFFFFFF    // = really big number, last 6 bytes 
     1262// 
     1263//              b1 = val & 0xFF 
     1264//              b2 = (val >> 8) & 0xFF 
     1265//              btime = (val >> 16) 
     1266// 
     1267// 
     1268//              tube[ii] = b1 
     1269//              location[ii] = b2 
     1270//              eventTime[ii] = btime 
     1271//               
     1272//      endfor 
    11831273 
    11841274Printf "File decode time (s) = " 
     
    16021692 
    16031693 
     1694// this is not used - it now conflicts with the name of a built-in function in Igor 7 
     1695// 
    16041696Function xJointHistogram(w0,w1,hist,index) 
    16051697        wave w0,w1,hist,index 
     
    16861778 
    16871779////////////// Post-processing of the event mode data 
     1780// 
     1781// 
     1782// TODO: 
     1783// -- this is ALL geared towards ordela event mode data and the 6.7s errors, and bad signal 
     1784//   I don't know if I'll need any of this for the VSANS event data. 
     1785// 
     1786// 
    16881787Proc V_ShowEventCorrectionPanel() 
    16891788        DoWindow/F V_EventCorrectionPanel 
Note: See TracChangeset for help on using the changeset viewer.