def __init__(self, mc_hel): # information that we need to get to create a new grid self.oneFail = False # check if one splitted job fails to pass cuts self.mc_hel = mc_hel self.grid_base = collections.defaultdict(int) self.original_grid = collections.defaultdict(int) self.non_zero_grid = collections.defaultdict(int) self.ng = 0 self.maxinvar = 0 self.nonzero = 0 self.max_on_axis = collections.defaultdict(lambda: -1) self.min_on_axis = collections.defaultdict(lambda: 1) # information that we need to evaluate the cross-section/error self.sum_wgt = 0 self.sum_abs_wgt = 0 self.sum_wgt_square = 0 self.max_wgt = 0 self.nb_ps_point = 0 self.target_evt = 0 self.nb_sample = 0 self.force_max_wgt = [] # list of weight for the secondary unweighting # self.results = sum_html.Combine_results('combined') self.discrete_grid = ""
def sum_multichannel(self, channel): """Looks in channel to see if there are multiple runs that need to be combined. If so combines them into single run""" alphabet = "abcdefghijklmnopqrstuvwxyz" if os.path.exists(pjoin(channel, 'multijob.dat')): njobs = int(open(pjoin(channel, 'multijob.dat')).read()) else: return results = sum_html.Combine_results(channel) if njobs: logger.debug('find %s multijob in %s' % (njobs, channel)) else: return for i in range(njobs): if channel.endswith(os.path.pathsep): path = channel[:-1] + alphabet[i % 26] + str((i + 1) // 26) else: path = channel + alphabet[i % 26] + str((i + 1) // 26) results.add_results(name=alphabet[i % 26] + str((i + 1) // 26), filepath=pjoin(path, 'results.dat')) results.compute_average() if results.xsec: results.write_results_dat(pjoin(channel, 'results.dat')) else: return ### Adding information in the log file fsock = open(pjoin(channel, 'log.txt'), 'a') fsock.write( '--------------------- Multi run with %s jobs. ---------------------\n' % njobs) for r in results: fsock.write('job %s : %s %s +- %s %s\n' % (r.name, r.xsec, r.axsec,\ r.xerru, r.nunwgt)) #Now read in all of the events and write them #back out with the appropriate scaled weight fsock = open(pjoin(channel, 'events.lhe'), 'w') wgt = results.axsec / results.nunwgt tot_nevents, nb_file = 0, 0 for result in results: i = result.name if channel.endswith(os.path.pathsep): path = channel[:-1] + i else: path = channel + i nw = self.copy_events(fsock, pjoin(path, 'events.lhe'), wgt) tot_nevents += nw nb_file += 1 logger.debug("Combined %s file generating %s events for %s ", nb_file, tot_nevents, channel)