14Create a left/right LUT from a table of true left/right counts for each pattern.
15(see generateTrueLRTable.py)
17Condition for left/right:
19left: nBkg <= b * nTotal and nLeft > p * nMC + 3 * sqrt(p * (1 - p) * nMC)
20right: nBkg <= b * nTotal
and nRight > p * nMC + 3 * sqrt(p * (1 - p) * nMC)
24# load table with true left/right
25# shape: [[nTrueRight, nTrueLeft, nTrueBkg], ...]
26innerTrueLRTable = np.loadtxt('innerTrueLRTable_Bkg1.0_1.dat')
27outerTrueLRTable = np.loadtxt('outerTrueLRTable_Bkg1.0_1.dat')
29 innerTrueLRTable += np.loadtxt(f'innerTrueLRTable_Bkg1.0_{int(i)}.dat')
30 outerTrueLRTable += np.loadtxt(f
'outerTrueLRTable_Bkg1.0_{int(i)}.dat')
37innerLUTFilename = f
"innerLUT_Bkg_p{p:.2f}_b{p:.2f}.coe"
38outerLUTFilename = f
"outerLUT_Bkg_p{p:.2f}_b{b:.2f}.coe"
41def isValidInnerPattern(pattern):
44 (1 << 4) + (1 << 5) + (1 << 6),
45 (1 << 7) + (1 << 8) + (1 << 9) + (1 << 10),
46 (1 << 11) + (1 << 12) + (1 << 13) + (1 << 14) + (1 << 15)]
49 if pattern & masks[i]:
54def isValidOuterPattern(pattern):
55 masks = [(1 << 1) + (1 << 2) + (1 << 3),
59 (1 << 9) + (1 << 10) + (1 << 11)]
62 if pattern & masks[i]:
67def createLUT(TrueLRTable, inner):
68 LUT = np.zeros(len(TrueLRTable))
70 for pattern, trueLR
in enumerate(TrueLRTable):
73 if not isValidInnerPattern(pattern):
76 if not isValidOuterPattern(pattern):
78 if trueLR[2] > b * np.sum(trueLR):
81 threshold = p * np.sum(trueLR[:2]) + 3 * np.sqrt(p * (1 - p) * np.sum(trueLR[:2]))
82 if trueLR[0] > threshold:
84 elif trueLR[1] > threshold:
91innerLUT = createLUT(innerTrueLRTable, inner=
True)
92outerLUT = createLUT(outerTrueLRTable, inner=
False)
95innerLUTFile = open(innerLUTFilename,
'w')
96innerLUTFile.write(
"memory_initialization_radix=10;\n")
97innerLUTFile.write(
"memory_initialization_vector=\n")
98innerLUTFile.write(
",\n".join(f
"{int(i)}" for i
in innerLUT))
99innerLUTFile.write(
";\n\n")
101outerLUTFile = open(outerLUTFilename,
'w')
102outerLUTFile.write(
"memory_initialization_radix=10;\n")
103outerLUTFile.write(
"memory_initialization_vector=\n")
104outerLUTFile.write(
",\n".join(f
"{int(i)}" for i
in outerLUT))
105outerLUTFile.write(
";\n\n")