|
10 | 10 |
|
11 | 11 |
|
12 | 12 | class _ModelConfig(object):
|
13 |
| - @classmethod |
14 |
| - def from_spec(cls,spec,poiname = 'mu', qualify_names = False): |
15 |
| - channels = [] |
16 |
| - samples = [] |
17 |
| - modifiers = [] |
| 13 | + def __init__(self, spec, poiname = 'mu', qualify_names = False): |
| 14 | + self.poi_index = None |
| 15 | + self.par_map = {} |
| 16 | + self.par_order = [] |
| 17 | + self.auxdata = [] |
| 18 | + self.auxdata_order = [] |
| 19 | + self.next_index = 0 |
| 20 | + |
| 21 | + self.channels = [] |
| 22 | + self.samples = [] |
| 23 | + self.parameters = [] |
| 24 | + self.modifiers = [] |
| 25 | + self.channel_nbins = {} |
18 | 26 | # hacky, need to keep track in which order we added the constraints
|
19 | 27 | # so that we can generate correctly-ordered data
|
20 |
| - instance = cls() |
21 | 28 | for channel in spec['channels']:
|
22 |
| - channels.append(channel['name']) |
| 29 | + self.channels.append(channel['name']) |
| 30 | + self.channel_nbins[channel['name']] = len(channel['samples'][0]['data']) |
23 | 31 | for sample in channel['samples']:
|
24 |
| - samples.append(sample['name']) |
| 32 | + self.samples.append(sample['name']) |
25 | 33 | # we need to bookkeep a list of modifiers by type so that we
|
26 | 34 | # can loop over them on a type-by-type basis
|
27 | 35 | # types like histosys, normsys, etc...
|
28 | 36 | sample['modifiers_by_type'] = {}
|
29 | 37 | for modifier_def in sample['modifiers']:
|
| 38 | + self.parameters.append(modifier_def['name']) |
30 | 39 | if qualify_names:
|
31 | 40 | fullname = '{}/{}'.format(modifier_def['type'],modifier_def['name'])
|
32 | 41 | if modifier_def['name'] == poiname:
|
33 | 42 | poiname = fullname
|
34 | 43 | modifier_def['name'] = fullname
|
35 |
| - modifier = instance.add_or_get_modifier(channel, sample, modifier_def) |
| 44 | + modifier = self.add_or_get_modifier(channel, sample, modifier_def) |
36 | 45 | modifier.add_sample(channel, sample, modifier_def)
|
37 |
| - modifiers.append(modifier_def['name']) |
| 46 | + self.modifiers.append(modifier_def['name']) |
38 | 47 | sample['modifiers_by_type'].setdefault(modifier_def['type'],[]).append(modifier_def['name'])
|
39 |
| - instance.channels = list(set(channels)) |
40 |
| - instance.samples = list(set(samples)) |
41 |
| - instance.modifiers = list(set(modifiers)) |
42 |
| - instance.set_poi(poiname) |
43 |
| - return instance |
44 |
| - |
45 |
| - def __init__(self): |
46 |
| - # set up all other bookkeeping variables |
47 |
| - self.poi_index = None |
48 |
| - self.par_map = {} |
49 |
| - self.par_order = [] |
50 |
| - self.auxdata = [] |
51 |
| - self.auxdata_order = [] |
52 |
| - self.next_index = 0 |
| 48 | + self.channels = list(set(self.channels)) |
| 49 | + self.samples = list(set(self.samples)) |
| 50 | + self.parameters = list(set(self.parameters)) |
| 51 | + self.modifiers = list(set(self.modifiers)) |
| 52 | + self.channel_nbins = self.channel_nbins |
| 53 | + self.set_poi(poiname) |
53 | 54 |
|
54 | 55 | def suggested_init(self):
|
55 | 56 | init = []
|
@@ -135,13 +136,12 @@ def add_or_get_modifier(self, channel, sample, modifier_def):
|
135 | 136 | class Model(object):
|
136 | 137 | def __init__(self, spec, **config_kwargs):
|
137 | 138 | self.spec = copy.deepcopy(spec) #may get modified by config
|
138 |
| - self.schema = config_kwargs.get('schema', utils.get_default_schema()) |
| 139 | + self.schema = config_kwargs.pop('schema', utils.get_default_schema()) |
139 | 140 | # run jsonschema validation of input specification against the (provided) schema
|
140 | 141 | log.info("Validating spec against schema: {0:s}".format(self.schema))
|
141 | 142 | utils.validate(self.spec, self.schema)
|
142 | 143 | # build up our representation of the specification
|
143 |
| - self.config = _ModelConfig.from_spec(self.spec,**config_kwargs) |
144 |
| - |
| 144 | + self.config = _ModelConfig(self.spec, **config_kwargs) |
145 | 145 |
|
146 | 146 | for m in self.config.modifiers:
|
147 | 147 | mod = self.config.modifier(m)
|
|
0 commit comments