8 from .constants
import EventCode, EventCode_CrossSection, EventCodes
10 from basf2
import B2FATAL, Module
11 from generators
import add_aafh_generator, add_koralw_generator, add_phokhara_generator, add_treps_generator
14 def add_low_multiplicity_generator(path, event_code):
16 Add dedicated generator based on EventCode.
17 Module name is also changed to avoid conflicts
20 path (basf2.Path): path where generators should be added
21 event_code (EventCode): EventCode integer to identify a channel
24 if event_code
not in EventCodes:
25 B2FATAL(f
'The event code {event_code} is unknown.')
26 if event_code
is EventCode.eetautau:
27 add_aafh_generator(path,
'e+e-tau+tau-', enableTauDecays=
False, eventType=
'eetautau')
28 rename_module_in_path(path,
'AafhInput',
'AAFH_eetautau')
29 elif event_code
is EventCode.mumumumu:
30 add_aafh_generator(path,
'mu+mu-mu+mu-', eventType=
'mumumumu')
31 rename_module_in_path(path,
'AafhInput',
'AAFH_mumumumu')
32 elif event_code
is EventCode.mumutautau:
33 add_aafh_generator(path,
'mu+mu-tau+tau-', enableTauDecays=
False, eventType=
'mumutautau')
34 rename_module_in_path(path,
'AafhInput',
'AAFH_mumutautau')
35 elif event_code
is EventCode.tautautautau:
36 add_koralw_generator(path,
'tau+tau-tau+tau-', enableTauDecays=
False, eventType=
'tautautautau')
37 rename_module_in_path(path,
'KoralWInput',
'KoralW_tautautautau')
38 elif event_code
is EventCode.eepipi:
39 add_treps_generator(path,
'e+e-pi+pi-', eventType=
'eepipi')
40 rename_module_in_path(path,
'TrepsInput',
'TREPS_eepipi')
41 elif event_code
is EventCode.eeKK:
42 add_treps_generator(path,
'e+e-K+K-', eventType=
'eeKK')
43 rename_module_in_path(path,
'TrepsInput',
'TREPS_eeKK')
44 elif event_code
is EventCode.eepp:
45 add_treps_generator(path,
'e+e-ppbar', eventType=
'eeppbar')
46 rename_module_in_path(path,
'TrepsInput',
'TREPS_eepp')
47 elif event_code
is EventCode.pipiISR:
48 add_phokhara_generator(path,
'pi+pi-', eventType=
'pipiISR')
49 elif event_code
is EventCode.pipipi0ISR:
50 add_phokhara_generator(path,
'pi+pi-pi0', eventType=
'pipipi0ISR')
51 elif event_code
is EventCode.pipipipiISR:
52 add_phokhara_generator(path,
'pi+pi-pi+pi-', eventType=
'pipipipiISR')
53 elif event_code
is EventCode.pipipi0pi0ISR:
54 add_phokhara_generator(path,
'pi+pi-pi0pi0', eventType=
'pipipi0pi0ISR')
55 elif event_code
is EventCode.pipietaISR:
56 add_phokhara_generator(path,
'pi+pi-eta', eventType=
'pipietaISR')
57 elif event_code
is EventCode.KKISR:
58 add_phokhara_generator(path,
'K+K-', eventType=
'KKISR')
59 elif event_code
is EventCode.K0K0barISR:
60 add_phokhara_generator(path,
'K0K0bar', eventType=
'K0K0barISR')
61 elif event_code
is EventCode.ppbarISR:
62 add_phokhara_generator(path,
'ppbar', eventType=
'ppbarISR')
65 def get_event_ranges(events, event_codes=None):
67 Get event range for channels to be generated. The number of events of each channel is determined by:
68 channel cross-section / total cross-section of all channels assigned to the same basf2 job.
71 events (int): Total number of events
72 event_codes (Iterable): tuple or list of EventCode.
74 a dictionary with EvenCode as the key and tuple of event range as value.
76 total_cross_section = sum(EventCode_CrossSection[e]
for e
in event_codes)
77 lower_range_delimiter = 0
80 weight = EventCode_CrossSection[e] / total_cross_section
82 if e == event_codes[len(event_codes) - 1]:
83 return_dict[e] = (lower_range_delimiter, events + 1)
85 events_in_range = round(events * weight)
86 return_dict[e] = (lower_range_delimiter, lower_range_delimiter + events_in_range)
87 lower_range_delimiter += events_in_range
90 def rename_module_in_path(path, module_type, new_module_name):
92 Helper function to rename a module named with its type.
94 path (basf2.Path): path where a module to be renamed
95 module_type (str): default module name which is also module.type()
96 new_module_name (str): new module name
98 for module
in path.modules():
99 if module.type() == module_type:
100 module.set_name(new_module_name)
105 Module to set ``eventExtraInfo(EventCode)`` according to event range
109 event_codes (Iterable): tuple or list of EventCode.
116 event_codes (Iterable): tuple or list of EventCode.
119 super(EventRangePathSplitter, self).
__init__()
131 Initialize module before any events are processed
134 self.
event_rangesevent_ranges = get_event_ranges(ROOT.Belle2.Environment.Instance().getNumberOfEvents(), self.
event_codesevent_codes)
138 """Begin run method of the module"""
142 """Event method of the module"""
147 B2FATAL(
'The EventExtraInfo object has already an EventCode field registered.')
148 for event_code, event_range
in self.
event_rangesevent_ranges.items():
149 if (event_range[0] <= self.
event_numberevent_number < event_range[1]):
150 self.
event_extra_infoevent_extra_info.setExtraInfo(
'EventCode', event_code.value)
151 self.return_value(event_code.value)
159 Helper module to return True if the value from ``eventExtraInfo(EventCode)``
160 is included in the event_codes parameter.
163 event_codes (Iterable): tuple or list of EventCode.
170 event_codes (Iterable): tuple or list of EventCode.
173 super(ExtraInfoPathSplitter, self).
__init__()
181 Initialize module before any events are processed
186 """Event method of the module"""
188 B2FATAL(
'The EventExtraInfo object has no EventCode field registered.')
event_codes
tuple or list of event codes
event_ranges
Dictionary to get number of events for each event code.
def __init__(self, event_codes)
event_extra_info
PyStoreObj off EventExtraInfo.
event_number
Event number.