Changeset 877 for sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
- Timestamp:
- Nov 20, 2012 1:24:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/EventModeProcessing.ipf
r875 r877 1 1 #pragma rtGlobals=1 // Use modern global access method. 2 #pragma IgorVersion=6.1 3 4 //#include "TISANE" 5 2 #pragma IgorVersion=6.22 3 4 // vers 7.13d 6 5 7 6 // TODO: 8 7 // 8 // -- Need to make sure that the rescaledTime and the differentiated time graphs are 9 // being properly updated when the data is processed, modified, etc. 10 // 11 // -- I need better nomenclature other than "stream" for the "continuous" data set. 12 // It's all a stream, just sometimes it's not oscillatory 13 // 9 14 // -- fix the log/lin display - it's not working correctly 15 // I could use ModifyImage and log = 0|1 keyword for the log Z display 16 // rather than creating a duplicate wave of log(data) 17 // -- it's in the Function sliceSelectEvent_Proc() 18 // 19 // -- Do something withe the PP events. Currently, nothing is done (since I still need 20 // to find out what they realy mean) 21 // 22 // -- Add a switch to allow Sorting of the Stream data to remove the "time-reversed" data 23 // points. Maybe not kosher, but would clean things up. 24 // 25 // -- Is there any way to improve the speed of the loader? How could an XOP be structured 26 // for maximum flexibility? Leave the post processing to Igor, but how much for the XOP 27 // to do? And can it handle such large amounts of data to pass back and forth, or 28 // does it need to be written as an operation, rather than a function??? I'd really 29 // rather that Igor handles the memory management, not me, if I write the XOP. 30 // 10 31 // X- add controls to show the bar graph 11 32 // x- add popup for selecting the binning type … … 22 43 // 23 44 // 24 // -- for the 19 MB file - the max time is reported as 67.108s, but the max rescaled time = 61 s 25 // based on the last point... there are "spikes" in the time! -- look at the plot in the 26 // data browser... (so waveMax() gives a different answer than the end point, and BinarySearch() 27 // doesn't have a monotonic file to work with... ugh.) 28 // 29 // 30 // 31 // differentiate may be useful at some point, but not sure 32 //¥Differentiate rescaledTime/D=rescaledTime_DIF 33 //¥Display rescaledTime,rescaledTime_DIF 34 // 35 // 45 46 47 // 48 // These are currently defined in the TISANE procedure file. If that file becomes depricated 49 // or is not loaded in, then these lines should be activated, and those in TISANE should also 50 // be re-declared as Static, so they will be local to each procedure 51 // 52 //Static Constant ATXY = 0 53 //Static Constant ATXYM = 2 54 //Static Constant ATMIR = 1 55 //Static Constant ATMAR = 3 56 // 57 //Static Constant USECSPERTICK=0.1 // microseconds 58 //Static Constant TICKSPERUSEC=10 59 //Static Constant XBINS=128 60 //Static Constant YBINS=128 61 // 62 63 36 64 37 65 Proc Show_Event_Panel() … … 59 87 Variable/G root:Packages:NIST:gEvent_tsdisp //Displayed slice 60 88 Variable/G root:Packages:NIST:gEvent_nslices = 10 //Number of time slices 61 Variable/G root:Packages:NIST:gEvent_slicewidth = 1000 // slice width (us) 62 63 Variable/G root:Packages:NIST:gEvent_prescan // Do we prescan the file? 89 64 90 Variable/G root:Packages:NIST:gEvent_logint = 1 65 91 66 Variable/G root:Packages:NIST:gEvent_Mode = 0 // ==0 for "stream", ==1 for Oscillatory92 Variable/G root:Packages:NIST:gEvent_Mode = 0 // ==0 for "stream", ==1 for Oscillatory 67 93 Variable/G root:Packages:NIST:gRemoveBadEvents = 1 // ==1 to remove "bad" events, ==0 to read "as-is" 68 94 Variable/G root:Packages:NIST:gSortStreamEvents = 0 // ==1 to sort the event stream, a last resort for a stream of data 95 69 96 NVAR nslices = root:Packages:NIST:gEvent_nslices 70 97 … … 247 274 endif 248 275 276 249 277 return(0) 250 278 end … … 254 282 Function Osc_ProcessEventLog(ctrlName) 255 283 String ctrlName 256 257 284 258 285 Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData … … 262 289 Wave yLoc = root:Packages:NIST:Event:yLoc 263 290 264 SetDataFolder root:Packages:NIST:Event265 IndexForHistogram(xLoc,yLoc,binnedData)266 SetDataFolder root:267 Wave index = root:Packages:NIST:Event:SavedIndex268 269 JointHistogram(xLoc,yLoc,binnedData,index) // puts everything into one array270 271 272 291 // now with the number of slices and max time, process the events 273 Osc_ProcessEvents(xLoc,yLoc,index) 274 275 276 SetDataFolder root:Packages:NIST:Event: 277 278 SetDataFolder root: 279 280 return(0) 281 End 282 283 284 Function Stream_ProcessEventLog(ctrlName) 285 String ctrlName 286 287 // NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth 288 289 290 Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 291 292 Wave binnedData = root:Packages:NIST:Event:binnedData 293 Wave xLoc = root:Packages:NIST:Event:xLoc 294 Wave yLoc = root:Packages:NIST:Event:yLoc 295 296 SetDataFolder root:Packages:NIST:Event 297 IndexForHistogram(xLoc,yLoc,binnedData) 298 SetDataFolder root: 299 Wave index = root:Packages:NIST:Event:SavedIndex 300 301 JointHistogram(xLoc,yLoc,binnedData,index) // puts everything into one array 302 303 304 // now with the number of slices and max time, process the events 305 Stream_ProcessEvents(xLoc,yLoc,index) 306 307 308 SetDataFolder root:Packages:NIST:Event: 309 310 SetDataFolder root: 311 312 return(0) 313 End 314 315 316 Proc UndoTheSorting() 317 Osc_UndoSort() 318 End 319 320 // for oscillatory mode 321 // 322 // -- this takes the previously generated index, and un-sorts the data to restore to the 323 // "as-collected" state 324 // 325 Function Osc_UndoSort() 326 327 SetDataFolder root:Packages:NIST:Event //don't count on the folder remaining here 328 Wave rescaledTime = rescaledTime 329 Wave OscSortIndex = OscSortIndex 330 Wave yLoc = yLoc 331 Wave xLoc = xLoc 332 Wave timePt = timePt 333 334 Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 335 336 KillWaves/Z OscSortIndex 337 338 SetDataFolder root: 339 return(0) 340 End 341 342 // for oscillatory mode 343 // 344 //// use indexSort to be able to restore the original data 345 //¥Duplicate rescaledTime OscSortIndex 346 //¥MakeIndex rescaledTime OscSortIndex 347 //¥IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime 348 //¥Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 349 // 350 // sort the data by time, then do the binning 351 // save an index to be able to "undo" the sorting 352 // 353 Function Osc_ProcessEvents(xLoc,yLoc,index) 354 Wave xLoc,yLoc,index 355 292 293 356 294 NVAR t_longest = root:Packages:NIST:gEvent_t_longest 357 295 NVAR nslices = root:Packages:NIST:gEvent_nslices … … 408 346 MakeIndex rescaledTime OscSortIndex 409 347 IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime 348 //SetDataFolder root:Packages:NIST:Event 349 IndexForHistogram(xLoc,yLoc,binnedData) // index the events AFTER sorting 350 //SetDataFolder root: 410 351 Endif 411 352 353 Wave index = root:Packages:NIST:Event:SavedIndex //this is the histogram index 354 412 355 for(ii=0;ii<nslices;ii+=1) 413 356 if(ii==0) … … 452 395 End 453 396 454 455 // for the mode of "one continuous exposure" 456 // 457 Function Stream_ProcessEvents(xLoc,yLoc,index) 458 Wave xLoc,yLoc,index 459 397 // for a "continuous exposure" 398 // 399 // if there is a sort of these events, I need to re-index the events for the histogram 400 // - see the oscillatory mode - and sort the events here, then immediately re-index for the histogram 401 // - but with the added complication that I need to always remember to index for the histogram, every time 402 // - since I don't know if I've sorted or un-sorted. Osc mode always forces a re-sort and a re-index 403 // 404 Function Stream_ProcessEventLog(ctrlName) 405 String ctrlName 406 407 // NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth 408 409 410 Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 411 412 Wave binnedData = root:Packages:NIST:Event:binnedData 413 Wave xLoc = root:Packages:NIST:Event:xLoc 414 Wave yLoc = root:Packages:NIST:Event:yLoc 415 416 // now with the number of slices and max time, process the events 417 418 NVAR yesSortStream = root:Packages:NIST:gSortStreamEvents //do I sort the events? 460 419 NVAR t_longest = root:Packages:NIST:gEvent_t_longest 461 420 NVAR nslices = root:Packages:NIST:gEvent_nslices … … 498 457 SetLinearBins(binEndTime,nslices,t_longest) 499 458 endswitch 459 460 if(yesSortStream == 1) 461 SortTimeData() 462 endif 463 // index the events before binning 464 // if there is a sort of these events, I need to re-index the events for the histogram 465 // SetDataFolder root:Packages:NIST:Event 466 IndexForHistogram(xLoc,yLoc,binnedData) 467 // SetDataFolder root: 468 Wave index = root:Packages:NIST:Event:SavedIndex //the index for the histogram 469 500 470 501 471 for(ii=0;ii<nslices;ii+=1) … … 539 509 540 510 511 Proc UndoTheSorting() 512 Osc_UndoSort() 513 End 514 515 // for oscillatory mode 516 // 517 // -- this takes the previously generated index, and un-sorts the data to restore to the 518 // "as-collected" state 519 // 520 Function Osc_UndoSort() 521 522 SetDataFolder root:Packages:NIST:Event //don't count on the folder remaining here 523 Wave rescaledTime = rescaledTime 524 Wave OscSortIndex = OscSortIndex 525 Wave yLoc = yLoc 526 Wave xLoc = xLoc 527 Wave timePt = timePt 528 529 Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 530 531 KillWaves/Z OscSortIndex 532 533 SetDataFolder root: 534 return(0) 535 End 536 537 538 541 539 Function SortTimeData() 542 540 … … 660 658 Osc_LoadEventLog("") 661 659 endif 662 663 DifferentiatedTime() 664 660 661 STRUCT WMButtonAction ba 662 ba.eventCode = 2 663 ShowEventDataButtonProc(ba) 664 665 665 return(0) 666 666 End … … 674 674 675 675 SVAR filename = root:Packages:NIST:gEvent_logfile 676 NVAR prescan = root:Packages:NIST:gEvent_prescan677 // NVAR slicewidth = root:Packages:NIST:gEvent_slicewidth678 676 NVAR nslices = root:Packages:NIST:gEvent_nslices 679 677 NVAR t_longest = root:Packages:NIST:gEvent_t_longest … … 713 711 714 712 SVAR filename = root:Packages:NIST:gEvent_logfile 715 NVAR prescan = root:Packages:NIST:gEvent_prescan716 // NVAR slicewidth = root:Packages:NIST:gEvent_slicewidth717 713 NVAR nslices = root:Packages:NIST:gEvent_nslices 718 714 NVAR t_longest = root:Packages:NIST:gEvent_t_longest … … 734 730 Duplicate/O timePt rescaledTime 735 731 rescaledTime *= 1e-7 //convert to seconds and that's all 736 t_longest = waveMax(rescaledTime) // won't be the last point, so get it this way732 t_longest = waveMax(rescaledTime) //if oscillatory, won't be the last point, so get it this way 737 733 738 734 KillWaves/Z OscSortIndex //to make sure that there is no old index hanging around … … 778 774 779 775 780 776 // this "fails" for data sets that have 3 or 4 slices, as the ModifyImage command 777 // interprets the data as being RGB - and so does nothing. 778 // need to find a way around this 779 /// 780 // I could modify this procedure to use the log = 0|1 keyword for the log Z display 781 // rather than creating a duplicate wave of log(data) 782 // 781 783 Function sliceSelectEvent_Proc(ctrlName, varNum, varStr, varName) : SetVariableControl 782 784 String ctrlName … … 846 848 Variable dataval,timeval,type,numLines,verbose,verbose3 847 849 Variable xval,yval,rollBit,nRoll,roll_time,bit29,bit28,bit27 848 Variable ii,flaggedEvent,rolloverHappened,numBad=0,tmpPP=0 850 Variable ii,flaggedEvent,rolloverHappened,numBad=0,tmpPP=0,tmpT0=0 849 851 Variable Xmax, yMax 850 852 … … 852 854 yMax = 127 853 855 854 verbose3 = 1//prints out the rollover events (type==3)856 verbose3 = 0 //prints out the rollover events (type==3) 855 857 verbose = 0 856 858 numLines = 0 … … 859 861 // what I really need is the number of XY events 860 862 Variable numXYevents,num1,num2,num3,num0,totBytes,numPP,numT0,numDL,numFF,numZero 863 Variable numRemoved 861 864 numXYevents = 0 862 865 num0 = 0 … … 869 872 numFF = 0 870 873 numZero = 0 874 numRemoved = 0 871 875 872 876 //tic() … … 936 940 // done counting the number of XY events 937 941 toc() 938 942 943 Print "numT0 = ",numT0 939 944 940 945 // … … 975 980 // Make/O/U/N=(totBytes/4) xLoc,yLoc //too large, trim when done (bad idea) 976 981 // Make/O/D/N=(totBytes/4) timePt 977 Make/O/D/N=1000 badTimePt,badEventNum,PPTime,PPEventNum 982 Make/O/D/N=1000 badTimePt,badEventNum,PPTime,PPEventNum,T0Time,T0EventNum 978 983 badTimePt=0 979 984 badEventNum=0 980 985 PPTime=0 981 986 PPEventNum=0 987 T0Time=0 988 T0EventNum=0 982 989 xLoc=0 983 990 yLoc=0 … … 1035 1042 else 1036 1043 numBad += 1 1044 numRemoved += 1 1037 1045 endif 1038 1046 … … 1059 1067 type = (dataval & 0xC0000000)/1073741824 //right shift by 2^30 1060 1068 1061 // // if the first event, read the time_msw, since this is not always reset. if the first event is XYM, then it's OK,1062 // // but if the first event is XY, then the first few events will have msw=0 until an XYM forces a read of MSW in the1063 // // subsequent MIR event.1064 // // So do it now.1065 // if(ii==0 && RemoveBadEvents == 1)1066 // time_msw = (dataval & 536805376)/65536 //13 bits, 28-16, right shift by 2^161067 // endif1068 1069 1069 // 1070 1070 //Constant ATXY = 0 … … 1084 1084 endif 1085 1085 1086 // if the datavalue is == 0, just skip it now (it can only be interpreted as type 0, obviously 1086 // if the datavalue is == 0, just skip it now (it can only be interpreted as type 0, obviously) 1087 1087 if(dataval == 0 && RemoveBadEvents == 1) 1088 numRemoved += 1 1088 1089 break //don't increment ii 1089 1090 endif … … 1095 1096 PPEventNum[tmpPP] = ii 1096 1097 tmpPP += 1 1098 numRemoved += 1 1097 1099 break //don't increment ii 1098 1100 endif … … 1121 1123 badEventNum[numBad] = ii 1122 1124 numBad +=1 1125 numRemoved += 1 1123 1126 else 1124 1127 // time_msw has been reset, points are good now, so keep this one … … 1166 1169 // - but can I do this if this is an XY-time event? This will lead to a wrong time, and a time 1167 1170 // assigned to an XY (0,0)... 1168 bit29 = (dataval & 0x20000000)/536870912 //bit 29 only , shift by 2^291169 if(bit29 == 1 && RemoveBadEvents == 1)1170 Print "*****Bit 29 (PP) event set for Type==2, but not handled, ii = ",ii1171 // break //don't increment ii1172 endif1171 // bit29 = (dataval & 0x20000000)/536870912 //bit 29 only , shift by 2^29 1172 // if(bit29 == 1 && RemoveBadEvents == 1) 1173 // Print "*****Bit 29 (PP) event set for Type==2, but not handled, ii = ",ii 1174 //// break //don't increment ii 1175 // endif 1173 1176 1174 1177 // xval = ~(dataval & ~(2^32 - 2^8)) & 127 … … 1212 1215 timePt[ii] = timeval 1213 1216 1214 // bit29 = (dataval & 0x20000000)/536870912 //bit 29 only , shift by 2^29 1215 // if(bit29 != 0) 1216 // Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 1217 // endif 1217 bit29 = (dataval & 0x20000000)/536870912 //bit 29 only , shift by 2^29 1218 if(bit29 != 0) // bit 29 set is a T0 event 1219 //Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 1220 T0Time[tmpT0] = timeval 1221 T0EventNum[tmpT0] = ii 1222 tmpT0 += 1 1223 // reset nRoll = 0 for calcluating the time 1224 nRoll = 0 1225 endif 1218 1226 1219 1227 ii+=1 … … 1232 1240 bit29 = (dataval & 0x20000000)/536870912 //bit 29 only , shift by 2^29 1233 1241 nRoll += 1 1234 // not doing anything with these bits yet 1242 // not doing anything with these bits yet 1243 bit28 = (dataval & 0x10000000)/268435456 //bit 28 only, shift by 2^28 1235 1244 bit27 = (dataval & 0x08000000)/134217728 //bit 27 only, shift by 2^27 1236 bit28 = (dataval & 0x10000000)/268435456 //bit 28 only, shift by 2^281237 1245 1238 1246 if(verbose3) 1239 1247 printf "d=%u : b29=%u : b28=%u : b27=%u : #Roll=%u \r",dataval,bit29, bit28, bit27,nRoll 1248 endif 1249 1250 if(bit29 != 0) // bit 29 set is a T0 event 1251 //Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 1252 T0Time[tmpT0] = timeval 1253 T0EventNum[tmpT0] = ii 1254 tmpT0 += 1 1255 // reset nRoll = 0 for calcluating the time 1256 nRoll = 0 1240 1257 endif 1241 1258 … … 1255 1272 1256 1273 toc() 1274 1275 Print "Events removed = ",numRemoved 1257 1276 1258 1277 sPrintf tmpStr,"\rBad Events = numBad = %d (%g %% of events)",numBad,numBad/numXYevents*100
Note: See TracChangeset
for help on using the changeset viewer.