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