def convert_unfolding_histograms(file_name, histograms_to_load=[ 'truth', 'fake', 'measured', 'response', 'response_withoutFakes', 'response_without_fakes', 'EventCounter', ]): file_start = Timer() print 'Converting', file_name histograms = {} with File(file_name) as f: for path, _, objects in f.walk(): # keep only unfolding and EventFilter if path.startswith('unfolding_') or path == 'EventFilter': histograms[path] = {} for hist_name in objects: if hist_name in histograms_to_load: hist = f.Get(path + '/' + hist_name).Clone() hist.SetDirectory(0) histograms[path][hist_name] = hist new_histograms = {} # rebin for path, hists in histograms.iteritems(): new_histograms[path] = {} variable = '' if not path == 'EventFilter': variable = path.split('_')[1] for name, hist in hists.iteritems(): if name == 'EventCounter': new_histograms[path][name] = hist.Clone() else: new_hist = hist.rebinned(bin_edges_vis[variable]) if 'TH2' in new_hist.class_name(): new_hist = new_hist.rebinned(bin_edges_vis[variable], axis=1) new_histograms[path][name] = new_hist # save_to_file output = File(file_name.replace('.root', '_asymmetric.root'), 'recreate') for path, hists in new_histograms.iteritems(): directory = output.mkdir(path) directory.cd() for name, hist in hists.iteritems(): if name == 'response_withoutFakes': # fix this name hist.Write('response_without_fakes') else: hist.Write(name) output.close() secs = file_start.elapsed_time() print 'File %s converted in %d seconds' % (file_name, secs)
def convert_unfolding_histograms(file_name, histograms_to_load=['truth', 'fake', 'measured', 'response', 'response_withoutFakes', 'response_without_fakes', 'EventCounter', ]): file_start = Timer() print 'Converting', file_name histograms = {} with File(file_name) as f: for path, _, objects in f.walk(): # keep only unfolding and EventFilter if path.startswith('unfolding_') or path == 'EventFilter': histograms[path] = {} for hist_name in objects: if hist_name in histograms_to_load: hist = f.Get(path + '/' + hist_name).Clone() hist.SetDirectory(0) histograms[path][hist_name] = hist new_histograms = {} # rebin for path, hists in histograms.iteritems(): new_histograms[path] = {} variable = '' if not path == 'EventFilter': variable = path.split('_')[1] for name, hist in hists.iteritems(): if name == 'EventCounter': new_histograms[path][name] = hist.Clone() else: new_hist = hist.rebinned(bin_edges_vis[variable]) if 'TH2' in new_hist.class_name(): new_hist = new_hist.rebinned(bin_edges_vis[variable], axis=1) new_histograms[path][name] = new_hist # save_to_file output = File(file_name.replace('.root', '_asymmetric.root'), 'recreate') for path, hists in new_histograms.iteritems(): directory = output.mkdir(path) directory.cd() for name, hist in hists.iteritems(): if name == 'response_withoutFakes': # fix this name hist.Write('response_without_fakes') else: hist.Write(name) output.close() secs = file_start.elapsed_time() print 'File %s converted in %d seconds' % (file_name, secs)
def create_unfolding_pull_data(input_file_name, method, channel, centre_of_mass, variable, sample, responseFile, n_toy_data, output_folder, tau_value, run_matrix=None): ''' Sets up all variables for check_multiple_data_multiple_unfolding ''' set_root_defaults(msg_ignore_level=3001) timer = Timer() input_file = File(input_file_name, 'read') folder_template = '{path}/{centre_of_mass}TeV/{variable}/{sample}/' msg_template = 'Producing unfolding pull data for {variable},' msg_template += ' tau-value {value}' inputs = { 'path': output_folder, 'centre_of_mass': centre_of_mass, 'variable': variable, 'sample': sample, 'value': round(tau_value, 4), } h_response = get_response_histogram(responseFile, variable, channel) output_folder = folder_template.format(**inputs) make_folder_if_not_exists(output_folder) print(msg_template.format(**inputs)) print('Output folder: {0}'.format(output_folder)) print('Response here :', h_response) output_file_name = check_multiple_data_multiple_unfolding( input_file, method, channel, variable, h_response, n_toy_data, output_folder, tau_value, ) print('Runtime', timer.elapsed_time()) return output_file_name
def create_unfolding_pull_data(input_file_name, method, channel, centre_of_mass, variable, sample, responseFile, n_toy_data, output_folder, tau_value, run_matrix=None): ''' Sets up all variables for check_multiple_data_multiple_unfolding ''' set_root_defaults(msg_ignore_level=3001) timer = Timer() input_file = File(input_file_name, 'read') folder_template = '{path}/{centre_of_mass}TeV/{variable}/{sample}/' msg_template = 'Producing unfolding pull data for {variable},' msg_template += ' tau-value {value}' inputs = { 'path': output_folder, 'centre_of_mass': centre_of_mass, 'variable': variable, 'sample': sample, 'value': round(tau_value,4), } h_response = get_response_histogram(responseFile, variable, channel) output_folder = folder_template.format(**inputs) make_folder_if_not_exists(output_folder) print(msg_template.format(**inputs)) print('Output folder: {0}'.format(output_folder)) print ('Response here :',h_response) output_file_name = check_multiple_data_multiple_unfolding( input_file, method, channel, variable, h_response, n_toy_data, output_folder, tau_value, ) print('Runtime', timer.elapsed_time()) return output_file_name