Last active
March 23, 2020 16:04
-
-
Save arnobaer/c9e5f8fbe298c48cc56a9f92f7969500 to your computer and use it in GitHub Desktop.
A quest digging into level-1 menu details...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
import tmGrammar | |
import tmTable | |
def parse(expression): | |
tmGrammar.Algorithm_Logic.clear() | |
if not tmGrammar.Algorithm_parser(expression): | |
raise ValueError("Failed to parse algorithm expression") | |
return list(tmGrammar.Algorithm_Logic.getTokens()) | |
for filename in sys.argv[1:]: | |
print("processing:", filename) | |
menu = tmTable.Menu() | |
scale = tmTable.Scale() | |
extsignal = tmTable.ExtSignal() | |
tmTable.xml2menu(filename, menu, scale, extsignal) | |
needles = set() | |
for seed, cuts in menu.cuts.items(): | |
for cut in cuts: | |
if cut['type'] == 'MASS': | |
needles.add((cut['name'], cut['minimum'], cut['maximum'])) | |
for seed in menu.algorithms: | |
matches = {} | |
for token in parse(seed['expression']): | |
if tmGrammar.isFunction(token): | |
for needle in needles: | |
if needle[0] in token: | |
matches[token] = needle | |
if matches: | |
print(" *** in {}: {}".format(seed['name'], seed['expression'])) | |
for token, needle in matches.items(): | |
print(" - {} = [{:G} Gev, {:G} GeV]".format(token, float(needle[1]), float(needle[2]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import tmTable | |
def query(item): | |
return item['type'] == 'MU' and item['bx_offset'] != '0' # str! | |
for filename in sys.argv[1:]: | |
print("processing:", filename) | |
menu = tmTable.Menu() | |
scale = tmTable.Scale() | |
extsignal = tmTable.ExtSignal() | |
tmTable.xml2menu(filename, menu, scale, extsignal) | |
for seed, objects in menu.objects.items(): | |
for match in filter(query, objects): | |
print(" ***", seed, "found match:", match['name']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import tmTable | |
def query(item): | |
pattern = 'MU' | |
# split 'MU0 AND (NOT MU16)' into ['MU0', 'AND', '(', 'NOT', 'MU16', ')'] | |
tokens = item['expression'].replace('(', ' ( ').replace(')', ' ) ').split() | |
if len([token.startswith(pattern) for token in tokens]) >= 2: | |
while len(tokens): | |
token = tokens.pop(0) | |
if token == 'NOT': | |
while token in ['NOT', '(']: | |
token = tokens.pop(0) | |
if token.startswith(pattern): | |
return True | |
return False | |
for filename in sys.argv[1:]: | |
print("processing:", filename) | |
menu = tmTable.Menu() | |
scale = tmTable.Scale() | |
extsignal = tmTable.ExtSignal() | |
tmTable.xml2menu(filename, menu, scale, extsignal) | |
seeds = list(menu.algorithms) | |
for match in filter(query, seeds): | |
print(" *** {} found match: '{}'".format(match['name'], match['expression'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment