Belle II Software development
__init__.py
1#!/usr/bin/env python3
2
3
10
11"""
12Functions related to building or using the simulation/reconstruction geometry
13"""
14
15import basf2
16
17
18ALLOWED_COMPONENTS = ['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM', 'TRG']
19
20
21def check_components(components):
22 """
23 Check list of geometry components. This function is used by the standard
24 scripts, for example `simulation.add_simulation()`. Thus, only the detector
25 components corresponding to subdetectors are allowed. In addition, TRG is
26 included. Trigger is not a geometry component, but it is used as an
27 additional component in raw-data and DQM scripts.
28
29 If there is a unsupported component in the list the function will raise a
30 FATAL error and is guaranteed to not return.
31
32 Parameters:
33 components (list(str)): List of geometry components.
34 """
35
36 if components is None:
37 return
38 for component in components:
39 if not (component in ALLOWED_COMPONENTS):
40 basf2.B2FATAL(f'Geometry component {component} is unknown or it cannot be used in standard scripts.')
41
42
43def is_detector_present(component: str, components: list[str] | None = None) -> bool:
44 """
45 Check whether a detector component is contained in the list of components AND if it is an allowed component,
46 or if components is None.
47
48 Returns True, if components is None, or if the component is contained in the list of components and if the component is allowed,
49 else, returns False.
50
51 Parameters:
52 :param component (str): Detector componet
53 :param components (list(str)): List of geometry components present in the current setting.
54 :returns Bool indicating whether the detector component is contained and valid.
55 Returning True if the components list is None.
56 """
57
58 if (components is None) or ((component in components) and (component in ALLOWED_COMPONENTS)):
59 return True
60
61 return False
62
63
64def are_detectors_present(components_to_check: list[str], components: list[str] | None = None) -> bool:
65 """
66 Check whether all detectors in the list "components_to_check" are present in the list of components,
67 or if components is None.
68
69 Returns True if all detector components in "components_to_check are contained in components, else, returns False.
70
71 Parameters:
72 :param components_to_check (list(str)): List of detector componets to be checked
73 :param components (list(str)): List of geometry components present in the current setting.
74 :returns Bool indicating whether all the detectors are contained
75 """
76
77 if components is None:
78 return True
79
80 for component in components_to_check:
81 if not is_detector_present(component, components):
82 return False
83
84 return True
85
86
87def is_any_detector_present(components_to_check: list[str], components: list[str] | None = None) -> bool:
88 """
89 Check whether any detector in the list "components_to_check" is present in the list of components,
90 or if components is None.
91
92 Returns True if any detector components in "components_to_check is contained in components, else, returns False.
93
94 Parameters:
95 :param components_to_check (list(str)): List of detector componets to be checked
96 :param components (list(str)): List of geometry components present in the current setting.
97 :returns Bool indicating whether all the detectors are contained
98 """
99
100 if components is None:
101 return True
102
103 for component in components_to_check:
104 if is_detector_present(component, components):
105 return True
106
107 return False