15 Create a left/right LUT from a table of true left/right counts for each pattern.
16 (see generateTrueLRTable.py)
18 Condition for left/right:
20 left: nBkg <= b * nTotal and nLeft > p * nMC + 3 * sqrt(p * (1 - p) * nMC)
21 right: nBkg <= b * nTotal and nRight > p * nMC + 3 * sqrt(p * (1 - p) * nMC)
27 innerTrueLRTable = np.loadtxt(
'innerTrueLRTable_Bkg1.0_1.dat')
28 outerTrueLRTable = np.loadtxt(
'outerTrueLRTable_Bkg1.0_1.dat')
30 innerTrueLRTable += np.loadtxt(
'innerTrueLRTable_Bkg1.0_%d.dat' % i)
31 outerTrueLRTable += np.loadtxt(
'outerTrueLRTable_Bkg1.0_%d.dat' % i)
38 innerLUTFilename =
"innerLUT_Bkg_p%.2f_b%.2f.coe" % (p, b)
39 outerLUTFilename =
"outerLUT_Bkg_p%.2f_b%.2f.coe" % (p, b)
42 def isValidInnerPattern(pattern):
45 (1 << 4) + (1 << 5) + (1 << 6),
46 (1 << 7) + (1 << 8) + (1 << 9) + (1 << 10),
47 (1 << 11) + (1 << 12) + (1 << 13) + (1 << 14) + (1 << 15)]
50 if pattern & masks[i]:
55 def isValidOuterPattern(pattern):
56 masks = [(1 << 1) + (1 << 2) + (1 << 3),
60 (1 << 9) + (1 << 10) + (1 << 11)]
63 if pattern & masks[i]:
68 def createLUT(TrueLRTable, inner):
69 LUT = np.zeros(len(TrueLRTable))
71 for pattern, trueLR
in enumerate(TrueLRTable):
74 if not isValidInnerPattern(pattern):
77 if not isValidOuterPattern(pattern):
79 if trueLR[2] > b * np.sum(trueLR):
82 threshold = p * np.sum(trueLR[:2]) + 3 * np.sqrt(p * (1 - p) * np.sum(trueLR[:2]))
83 if trueLR[0] > threshold:
85 elif trueLR[1] > threshold:
92 innerLUT = createLUT(innerTrueLRTable, inner=
True)
93 outerLUT = createLUT(outerTrueLRTable, inner=
False)
96 innerLUTFile = open(innerLUTFilename,
'w')
97 innerLUTFile.write(
"memory_initialization_radix=10;\n")
98 innerLUTFile.write(
"memory_initialization_vector=\n")
99 innerLUTFile.write(
",\n".join(
"%d" % i
for i
in innerLUT))
100 innerLUTFile.write(
";\n\n")
102 outerLUTFile = open(outerLUTFilename,
'w')
103 outerLUTFile.write(
"memory_initialization_radix=10;\n")
104 outerLUTFile.write(
"memory_initialization_vector=\n")
105 outerLUTFile.write(
",\n".join(
"%d" % i
for i
in outerLUT))
106 outerLUTFile.write(
";\n\n")