forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtgeo_aux.py.in
More file actions
101 lines (87 loc) · 3.35 KB
/
tgeo_aux.py.in
File metadata and controls
101 lines (87 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This is deprecated code for Gen-1
import inspect
from acts._adapter import _patchKwargsConstructor
from .ActsExamplesPythonBindingsTGeo import TGeoDetector
def _makeLayerTriplet(*args, **kwargs):
if len(args) == 1:
_type = type(args[0])
negative = central = positive = args[0]
else:
negative = kwargs.get("negative")
central = kwargs.get("central")
positive = kwargs.get("positive")
types = []
if negative is not None:
types.append(type(negative))
if central is not None:
types.append(type(central))
if positive is not None:
types.append(type(positive))
assert all(types[0] == t for t in types), "Inconsistent types"
_type = types[0]
def fill(obj):
if negative is not None:
obj.negative = negative
if central is not None:
obj.central = central
if positive is not None:
obj.positive = positive
return obj
if _type == bool:
return fill(TGeoDetector.Config.LayerTripletBool())
elif _type == list:
if all(
all(isinstance(v, str) for v in vv)
for vv in (negative, central, positive)
if vv is not None
):
return fill(TGeoDetector.Config.LayerTripletVectorString())
elif all(
all(
(isinstance(v, tuple) or isinstance(v, list))
and isinstance(v[0], int)
and isinstance(v[1], inspect.unwrap(TGeoDetector.Config.BinningType))
for v in vv
)
for vv in (negative, central, positive)
if vv is not None
):
return fill(TGeoDetector.Config.LayerTripletVectorBinning())
else:
raise TypeError("Invalid types for list input")
elif _type == tuple:
if all(
all(isinstance(v, float) for v in vv)
for vv in (negative, central, positive)
if vv is not None
):
negative = Interval(*negative) if negative is not None else None
central = Interval(*central) if central is not None else None
positive = Interval(*positive) if positive is not None else None
return fill(TGeoDetector.Config.LayerTripletInterval())
else:
raise TypeError("Invalid types for tuple input")
elif _type == Interval:
return fill(TGeoDetector.Config.LayerTripletInterval())
elif _type == str:
return fill(TGeoDetector.Config.LayerTripletString())
elif _type == float:
return fill(TGeoDetector.Config.LayerTripletDouble())
else:
raise TypeError("Unknown type given")
TGeoDetector.Config.LayerTriplet = _makeLayerTriplet
def _process_volume_intervals(kwargs):
if len(kwargs) == 0:
return kwargs # prevent infinite recursion
_kwargs = kwargs.copy()
v = TGeoDetector.Config.Volume()
for name, value in inspect.getmembers(inspect.unwrap(TGeoDetector.Config.Volume)):
if not isinstance(getattr(v, name), inspect.unwrap(Interval)):
continue
if not name in _kwargs:
continue
if not isinstance(_kwargs[name], tuple):
continue
_kwargs[name] = Interval(*_kwargs[name])
return _kwargs
_patchKwargsConstructor(TGeoDetector.Config.Volume, proc=_process_volume_intervals)