Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

"""Statistics handling.""" 

 

from warnings import warn 

from collections import namedtuple 

 

CLOCK_TICK = 320e-9 

 

Stats = namedtuple( 

'Stats', 

'realtime livetime triggers events icr ocr deadtime') 

 

 

def stats_from_normal_mode(array): 

realtime = float(array[0]) 

livetime = float(array[1]) 

triggers = int(array[3]) 

events = int(array[4]) 

icr = float(array[5]) 

ocr = float(array[6]) 

underflows = int(array[7]) 

overflows = int(array[8]) 

total_events = events + underflows + overflows 

 

# Double check the ICR computation 

expected_icr = triggers / livetime if livetime != 0 else 0. 

if expected_icr != icr: 

msg = 'ICR buffer inconsistency: {} != {} (expected)' 

warn(msg.format(icr, expected_icr)) 

 

# Double check the OCR computation 

expected_ocr = total_events / realtime if realtime != 0 else 0. 

if expected_ocr != ocr: 

msg = 'OCR buffer inconsistency: {} != {} (expected)' 

warn(msg.format(ocr, expected_ocr)) 

 

# Note that the OCR reported by handel include underflows and overflows, 

# while the computed OCR in the returned statistics does not. 

return make_stats(realtime, livetime, triggers, events) 

 

 

def stats_from_mapping_mode(array): 

realtime = array[0] * CLOCK_TICK 

livetime = array[1] * CLOCK_TICK 

triggers = int(array[2]) 

events = int(array[3]) 

return make_stats(realtime, livetime, triggers, events) 

 

 

def make_stats(realtime, livetime, triggers, events): 

# ICR/OCR computation 

icr = triggers / livetime if livetime != 0 else 0. 

ocr = events / realtime if realtime != 0 else 0. 

# Deadtime computation 

# It's unclear whether icr=ocr=0 should result in a 0.0 or 1.0 deadtime 

# Prospect uses 0% so 0. it is. 

deadtime = 1 - float(ocr) / icr if icr != 0 else 0. 

return Stats(realtime, livetime, triggers, events, icr, ocr, deadtime)