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