Belle II Software  release-08-01-10
evaluateTSLUT.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import numpy as np
13 
14 """
15 Compare a left/right LUT with a table of true left/right counts for each pattern.
16 (see generateTrueLRTable.py)
17 """
18 
19 # load LUTs to evaluate
20 innerLUT = np.loadtxt('trg/cdc/data/innerLUT_Bkg_p0.70_b0.80.coe',
21  skiprows=2, delimiter=',', usecols=[0], comments=';')
22 outerLUT = np.loadtxt('trg/cdc/data/outerLUT_Bkg_p0.70_b0.80.coe',
23  skiprows=2, delimiter=',', usecols=[0], comments=';')
24 
25 # load table with true left/right
26 # shape: [[nTrueRight, nTrueLeft, nTrueBkg], ...]
27 innerTrueLRTable = np.loadtxt('innerTrueLRTable_Bkg1.0_5.dat')
28 outerTrueLRTable = np.loadtxt('outerTrueLRTable_Bkg1.0_5.dat')
29 
30 
31 def check(LUT, TrueLRTable):
32  # loop over patterns and check fraction of correct left/right
33  nCorrectMC = 0
34  nWrongMC = 0
35  nUnknownMC = 0
36  nKnownBkg = 0
37  nUnknownBkg = 0
38  for pattern, trueLR in enumerate(TrueLRTable):
39  LUTLR = LUT[pattern]
40  if LUTLR < 3:
41  nCorrectMC += trueLR[LUTLR - 1]
42  nWrongMC += trueLR[2 - LUTLR]
43  nKnownBkg += trueLR[2]
44  else:
45  nUnknownMC += trueLR[0] + trueLR[1]
46  nUnknownBkg += trueLR[2]
47  return nCorrectMC, nWrongMC, nUnknownMC, nKnownBkg, nUnknownBkg
48 
49 
50 def printFractions(checkResults):
51  nCorrectMC, nWrongMC, nUnknownMC, nKnownBkg, nUnknownBkg = checkResults
52  nMC = nCorrectMC + nWrongMC + nUnknownMC
53  nBkg = nKnownBkg + nUnknownBkg
54  print(" %d TS with MC hit in priority wire" % nMC)
55  if nMC > 0:
56  print(" %d correct, %d wrong, %d unknown"
57  % (nCorrectMC, nWrongMC, nUnknownMC))
58  print(" correct fraction", 100. * nCorrectMC / (nCorrectMC + nWrongMC),
59  "+-", 100. * np.sqrt(nCorrectMC * nWrongMC / (nCorrectMC + nWrongMC) ** 3))
60  print(" unknown fraction", 100. * nUnknownMC / nMC,
61  "+-", 100. * np.sqrt(nUnknownMC * (nMC - nUnknownMC) / nMC ** 3))
62  print(" %d TS with Bkg hit in priority wire" % nBkg)
63  if nBkg > 0:
64  print(" %d known, %d unknown"
65  % (nKnownBkg, nUnknownBkg))
66  print(" unknown fraction", 100. * nUnknownBkg / nBkg,
67  "+-", 100. * np.sqrt(nUnknownBkg * (nBkg - nUnknownBkg) / nBkg ** 3))
68 
69 
70 innerCheck = check(innerLUT, innerTrueLRTable)
71 outerCheck = check(outerLUT, outerTrueLRTable)
72 
73 print("\ninnermost super layer:")
74 printFractions(innerCheck)
75 print("\nouter super layers:")
76 printFractions(outerCheck)
77 print("\nall super layers:")
78 printFractions(np.array(innerCheck) + np.array(outerCheck))