-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
53 lines (44 loc) · 1.78 KB
/
model.py
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
from parameter_handler import ParameterHandler
from block import *
from utils import timeit
def combine_sequential_blocks():
pass
class Model():
def __init__(self, par_handler : ParameterHandler, active_blocks=[]):
self.blocks = {}
for block, args, kwargs in active_blocks:
self.blocks[block.__name__] = block(par_handler, *args, **kwargs)
@timeit
def __call__(self, *args, **kwargs):
return self.simulate(*args, **kwargs)
def get_network_edges(self):
edges = []
for edge_name in self.blocks:
_input = self.blocks[edge_name].input
_output = self.blocks[edge_name].output
for i in _input:
for o in _output:
edges.append([i, o, edge_name])
return edges
def update_parameter_from_handler(self, par_handler : ParameterHandler):
for key in self.blocks:
self.blocks[key].update_parameter_from_handler(par_handler)
def simulate(self, *args, **kwargs):
pass
class XENON1T_ERmTIModel(Model):
def __init__(self, par_handler : ParameterHandler, lower_e, upper_e):
active_blocks = [
(EnergySpec, (), dict(lower=lower_e, upper=upper_e)),
(QuenchingFano, (), dict()),
(Ionization, (), dict()),
(mTI, (), dict()),
(Recomb, (), dict()),
]
super().__init__(par_handler, active_blocks)
def simulate(self, sim_size):
energy = self.blocks['EnergySpec'](sim_size)
Nq = self.blocks['QuenchingFano'](energy)
Ni = self.blocks['Ionization'](Nq)
recomb = self.blocks['mTI'](energy)
Nph, Ne = self.blocks['Recomb'](Nq, Ni, recomb)
return Nph, Ne