def model(self, ws, debug=0): if self.sModel not in self.items: if debug > 0: print self.legend, 'no Model section defined in the config file' print self.legend, 'no model will be created' return legend = '[' + self.sModel + ']:' # FIXME: find a better way to load custom PDFs #gROOT.ProcessLine(".L dijetQstarPdf.cxx+"); #gROOT.ProcessLine(".L Qstar_qg.cxx+"); #gROOT.ProcessLine(".L Qstar_qg_2.cxx+"); #gROOT.ProcessLine(".L Jacobian_mt.cxx+"); model_items = self.items[self.sModel] if (debug > 0): print 'Loading model to the workspace', ws.GetName() # using RooStats::HLFactory to parse the model # make a temp file with a card file card_file_name = 'hlfCardFile.rs' with open(card_file_name, 'w') as cardfile: for item in model_items: print >> cardfile, item[0], '=', item[1] hlfVerbosity = debug > 0 #hlf = ROOT.RooStats.HLFactory('HLFactoryExost', card_file_name, True) hlf = RooStats.HLFactory('HLFactoryExost', ws, hlfVerbosity) self.modelAutoImportWarningExplanation(legend, debug) current_messaging_level = RooMsgService.instance().globalKillBelow() if debug <= 0: RooMsgService.instance().setGlobalKillBelow(RooFit.ERROR) hlf.ProcessCard(card_file_name) print legend, 'importing nonstandard class code into the workspace...' ws.importClassCode() #ws.importClassCode('Qstar_qg', true); print legend, '...code import done' # return messaging to the original level RooMsgService.instance().setGlobalKillBelow(current_messaging_level)
def variables(self, ws, debug): var_items = self.items[self.sVariables] legend = '[' + self.sVariables + ']:' print legend, 'begin processing...' print legend, 'define variables, constants, categories, sets and lists' # dictionary of value lists for each item # this is more detailed than the original items object # because the multiple settings for a given item # are already split # NOTE: sets are special case and are not added here item_values = {} # using RooStats::HLFactory to parse the model # make a temp file with a card file card_file_name = 'hlfCardFile.rs' with open(card_file_name, 'w') as cardfile: vSets = {} for item in var_items: # # special case for sets # standard RooFactoryWSTool interface exists in newer versions # need to switch at some point # for now parsing and adding named sets by hand # if item[1].strip()[0:3] == 'set': set_arg_list = item[1].strip() set_arg_list = set_arg_list[3:len(set_arg_list)] set_arg_list = set_arg_list.strip(' ;()').split(',') set_args = [] for arg in set_arg_list: set_args.append(arg.strip()) vSets[item[0].strip()] = set_args if (debug > 2): print legend, 'Set arg value is ->' + item[1] + '<-' print legend, 'set args are', set_args else: # this is a way to handle multiple settings # for each item: they are separated by semicolon # in the value field of the config item item_values[item[0]] = self.split_values(item) #print >> cardfile, item[0], '=', item[1] print >> cardfile, item[0], '=', item_values[item[0]][0] # add variables using HLFactory cards hlfVerbosity = debug > 2 hlf = RooStats.HLFactory('HLFactoryExost', ws, hlfVerbosity) hlf.ProcessCard(card_file_name) # process the secondary options (fix/float etc.) for _key in item_values: n_values = len(item_values[_key]) for _index in range(0, n_values): self.process_value(ws, _key, item_values[_key][_index], debug) # now add sets by hand print legend, 'creating sets now...' # fixme experimental _sets = {} for set_args_key in vSets.keys(): arg_list = '' # fixme experimental _sets[set_args_key] = RooArgSet(set_args_key) for arg in vSets[set_args_key]: if len(arg_list) > 0: arg_list += ',' arg_list += arg # fixme experimental _sets[set_args_key].add(ws.var(arg)) #ws.defineSet(set_args_key, arg_list) print legend, 'set', set_args_key, 'created' print legend, 'done creating sets' return {'sets': _sets}