3 from collections
import OrderedDict
4 from AthenaCommon.Logging
import logging
7 log = logging.getLogger( __name__ )
16 the_signature_grouping = OrderedDict([
17 (
'Electron',
'AllTag'),
18 (
'Photon' ,
'AllTag'),
20 (
'Bphysics',
'AllTag'),
24 (
'UnconventionalTracking',
'JetMET'),
26 (
'MinBias',
'MinBias'),
27 (
'Beamspot',
'Beamspot'),
28 (
'MuonnoL1',
'MuonnoL1'),
29 (
'Electronprobe',
'AllProbe'),
30 (
'Photonprobe' ,
'AllProbe'),
31 (
'Tauprobe',
'AllProbe'),
32 (
'Muonprobe' ,
'AllProbe'),
33 (
'HeavyIon' ,
'MinBias'),
39 return [v
for v
in the_signature_grouping.values()
if not (v
in seen
or seen.add(v))]
43 signature_for_alignment = signature + extra
45 log.debug(
"[get_alignment_group_from_pattern] Searching for alignment group for %s",signature_for_alignment)
47 if signature_for_alignment
in the_signature_grouping.keys():
48 return the_signature_grouping[signature_for_alignment]
49 elif signature
in the_signature_grouping.keys():
50 log.debug(
"[get_alignment_group_from_pattern] Falling back to signature alignment grouping for %s (%s)",signature, extra)
51 return the_signature_grouping[signature]
53 log.debug(
"[get_alignment_group_from_pattern] No dedicated alignment grouping for signature %s (%s)",signature, extra)
60 list_of_groups = [x[1]
for x
in config_tuples]
62 if len(list_of_groups) == len(
set(list_of_groups)):
66 unique_list = OrderedDict()
67 for ag_length, ag
in config_tuples:
69 if ag_length > unique_list[ag]:
70 unique_list[ag] = ag_length
72 unique_list[ag] = ag_length
74 unique_config_tuples = []
75 for ag, ag_length
in unique_list.items():
76 unique_config_tuples += [(ag_length, ag)]
77 return unique_config_tuples
80 """ Class to hold/calculate chain alignment """
81 def __init__(self, combinations_in_menu, groups_to_align, length_of_configs):
95 for value
in the_signature_grouping.values():
131 for comb_pair
in list(itertools.combinations(comb,2)):
135 _,eigenvecs = np.linalg.eig(the_matrix)
139 eigenvecs = np.transpose(eigenvecs)
142 pre_unique_sets =
list(
set([tuple(np.nonzero(eigenvec)[0])
for eigenvec
in eigenvecs]))
147 for aset
in pre_unique_sets:
148 if len(unique_sets) == 0 :
152 for ibset,bset
in enumerate(unique_sets):
156 elif set(aset).issubset(
set(bset)):
159 elif set(bset).issubset(
set(aset)):
160 unique_sets.pop(ibset)
161 unique_sets += [aset]
170 unique_by_sig = [[ self.
inverse_sig_dict[sig_int]
for sig_int
in setlist ]
for setlist
in unique_sets]
174 for aset
in unique_by_sig:
176 sig_to_set[sig] = aset
206 return all_groups_to_align[:index_of_chain_group]
211 if len(
set(chainDict[
'alignmentGroups'])) != 1:
212 log.error(
"Cannot call single_align on chain %s with alignment groups %s",
213 chainDict[
'chainName'],
",".
join(chainDict[
'alignmentGroups']))
214 raise Exception(
"Will not proceed, the chain is not suitable for single alignment.")
216 alignment_grp = chainDict[
'alignmentGroups'][0]
219 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
220 chainConfig.numberAllSteps()
224 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
225 chainConfig.numberAllSteps()
230 aligngroups_set.reverse()
232 for align_grp_to_align
in aligngroups_set:
233 chainConfig.insertEmptySteps(
'Empty'+align_grp_to_align+
'Align',self.
length_of_configs[align_grp_to_align],0)
234 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
235 chainConfig.numberAllSteps()
239 def multi_align(self, chainDict, chainConfig, lengthOfChainConfigs):
243 alignment_grps = chainDict[
'alignmentGroups']
247 log.error(
" one of the alignmentGroups in %s is not available in the sets to align dictionary!", alignment_grps)
248 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
250 log.error(
" the alignmentGroups %s point to different sets in the sets to align dictionary", alignment_grps)
251 for x
in alignment_grps:
253 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
268 for config_length,config_grp
in lengthOfChainConfigs:
270 length_firstgrp = config_length
272 if length_firstgrp < max_length_firstgrp:
274 needed_steps = max_length_firstgrp - length_firstgrp
275 chainConfig.insertEmptySteps(
'Empty'+self.
sets_to_align[alignment_grps[0]][0]+
'Align',needed_steps,length_firstgrp)
277 elif length_firstgrp > max_length_firstgrp:
278 log.error(
"%s first signature length %d is greater than the max calculated, %d",chainDict.name,length_firstgrp, max_length_firstgrp)
279 raise Exception(
"Probably something went wrong in GenerateMenuMT.generateChains()!")
285 log.error(
" one of the alignmentGroups in %s is not available in the sets to align dictionary!", alignment_grps)
286 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
288 log.error(
" the alignmentGroups %s point to different sets in the sets to align dictionary", alignment_grps)
289 for x
in alignment_grps:
291 raise Exception(
"MenuAlignment.analyse_combinations() needs checking, this should never happen.")
301 alignment_grps_ordered = [x
for x
in alignment_grp_ordering
if x
in alignment_grps]
309 aligngroups_set.reverse()
310 grp_masks = [x
in alignment_grps_ordered
for x
in aligngroups_set]
312 for align_grp,grp_in_chain
in zip(aligngroups_set,grp_masks):
314 for config_length,config_grp
in lengthOfChainConfigs:
315 if config_grp == align_grp:
316 grp_lengths += [config_length]
320 for istep,(align_grp,grp_in_chain,length_in_chain)
in enumerate(zip(aligngroups_set,grp_masks,grp_lengths)):
323 n_steps_before_grp = 0
324 if istep < len(grp_lengths)-1:
325 n_steps_before_grp =
sum(grp_lengths[istep+1:])
328 if length_in_chain < max_length_grp:
330 needed_steps = max_length_grp - length_in_chain
331 start_step = n_steps_before_grp + length_in_chain
332 chainConfig.insertEmptySteps(
'Empty'+align_grp+
'Align',needed_steps,start_step)
336 chainConfig.insertEmptySteps(
'Empty'+align_grp+
'Align',self.
length_of_configs[align_grp],n_steps_before_grp)
338 log.error(
"Should never reach this point. Ordered alignmentGroups: %s, sets_to_align: %s",alignment_grps_ordered,self.
sets_to_align)
339 raise Exception(
"MenuAlignment.multi_align() needs checking, this should never happen.")
341 log.debug(
"Finished with retrieving chain configuration for chain %s", chainDict[
'chainName'])
342 chainConfig.numberAllSteps()