Detectors (aka EMs)
On Time
EM A and EM B on times are determined by summing the on times for all scans, and then looking for any time when the EMs were constantly on outside of scanning.
CTL sequences are examined to determine the on time for individual scans. In order to avoid double-counting scans, only sum packet scans are examined when in EI mode, and only science packet scans are examined when in LDI mode.
Additionally, outside of science scans, the total time that the EMs are on are summed. This is determined by summing the amount of time that EM A and EM B are below -1900 V.
Bradley Tse pointed out a flaw in this algorithm:
There is a corner case where that may introduce its own problems. If the user stops the script after the Sequence was dumped but before scanning started (maybe because they noticed one of the parameters was incorrect), then that means the SebSequences will be duplicated.
And so EM on time for all scans after that (until the next Sequence Dump) will have 2x the amount (or however many times the script was stopped before scans occurred)
Full Cycles and Soft Cycles
EM Cycles are determined through two passes of the data.
The first pass of EM Cycles are counted from the scan status packets. The cycles are calculated differently depending on the type of mode the test is in.
If in LDI mode [1], if HKID 222 (SCN_EM1) or HKID 223 (SCN_EM2) is below the -1900V threshold, then a full cycle is added to the corresponding detector's count. If in Dark Counts mode [2], no full cycles are added here, as typically a Dark Counts run contains only 1 full cycle total. If in EI mode [3], soft counts are added to EM1 if HKID17 (IS_EMON_A) is greater than 9, and the same procedure for EM2 and HKID18 (EMON_B).
The timestamps of the scan packets are used to determine gaps in time when scans are not occurring during the test. A second pass through but looking specifically in the gaps and the binned HK data is necessary to avoid missing any full or soft cycles.
Here, HKID47 (SEB: EM_1_DAC0_SET) and HKID48 (SEB: EM_2_DAC1_SET) are looked through individually. If the HK value is > -50V, the detector is OFF. If the HK value is < -1900 the detector is ON. Full cycles are added for each occurrence where a detector changes from the OFF state to the ON state within a gap.
[1] - LDI Mode is when Filaments are OFF ([HKIDs 17/18] < 9), and the RF (HKID 235) is ON (End Amplitude >= 500A)
[2] - Dark Counts Mode is when Filaments are OFF ([HKIDs 17/18] < 9), and the RF (HKID 235) is OFF (End Amplitude < 500A)
[3] - EI Mode is when a Filament is ON ([HKIDs 17 or 18] > 9)
EM Counts
EM 1 and EM 2 counts are calculated according to the logic below. If the most recent DAC value (HKIDs 222 and 223) is zero, then ions are not counted against the multiplier.
# dummy variable to help when counting ions in science packet (packet 26) scans
temp_counts = 0
#
for each packet in the tm.drams file:
if the packet indicates that filament A or filament B is on (HKIDs 105 and 102):
set the current scan type to EI
else:
set the current scan type to LDI
#
else if the packet type is a scan status packet (type 25):
if we're in LDI mode:
count temp_counts against whichever EM is on (or both, if they're both on)
set temp_counts back to 0
#
else if the current mode is LDI mode and the current packet type is a science packet (type 26):
temp_counts += packet.total_ion_count()
#
else if the current mode is EI mode and the current packet type is a sum packet (type 27):
count packet.total_ion_count() against whichever EM is on (or both, if they're both on)
#
# special-case code for handling dark count scans:
else if the current mode is LDI, and the current packet is a sum packet (type 27), and the packet's RF DAC value (HKID 405) < 50:
count packet.total_ion_count() against whichver EM is on (or both, if they're both on)