def getAsimovData(template_maker, params, data_normal): """ Generates the asimov data set (expected counts distribution) at parameters assuming hierarchy of data_normal \Params: * template_maker - instance of class TemplateMaker service. * params - parameters with values, fixed, range, etc. of systematics * data_normal - bool for Mass hierarchy being Normal (True) or inverted (False) """ fiducial_params = get_values(select_hierarchy( params, normal_hierarchy=data_normal)) return get_asimov_fmap(template_maker, fiducial_params, channel=fiducial_params['channel'])
# loop and the LLR distributions will be interpreted as the # ability to discriminate between hierarchies, without fitting for # the false hierarchy parameters that match best to the True # hierarchy fiducial model. if not args.no_alt_fit: logging.info("Running false hierarchy best fit...") output[data_tag]["false_h_best_fit"] = {} false_h_params = fix_non_atm_params(template_settings['params']) false_h_settings, llh_data = getAltHierarchyBestFit( asimov_data, template_maker, false_h_params, minimizer_settings, (not data_normal), check_octant) asimov_data_null = get_asimov_fmap( template_maker=template_maker, fiducial_params=false_h_settings, channel=false_h_settings['channel']) # Store all data tag related inputs: output[data_tag]['false_h_best_fit']['false_h_settings'] = false_h_settings output[data_tag]['false_h_best_fit']['llh_null'] = llh_data trials = get_llh_hypothesis( data_tag, asimov_data_null, args.ntrials, template_maker, template_settings["params"], minimizer_settings, args.save_steps, check_octant) output[data_tag]["false_h_best_fit"] = trials to_json(output,args.outfile)
normal_hierarchy=true_normal) # Set up the arrays to store the true/fit values in: for key in free_params.keys(): result['true_' + key] = [] result['fit_' + key] = [] result['asimov_data'] = [] # This will actually only iterate over theta23 (for now), changing # the asimov data set: for step in steplist: print "Running at asimov parameters: %s" % step asimov_params = get_values(getAsimovParams(params, true_normal, step)) asimov_data_set = get_asimov_fmap(template_maker, asimov_params, channel=asimov_params['channel']) # Store injected true values in result: for key in free_params.keys(): if 'theta23' in key: continue result['true_' + key].append(asimov_params[key]) result['true_theta23'].append(step) result['asimov_data'].append(asimov_data_set) # now get fitted values of opposite hierarchy: hypo_normal = False if true_normal else True hypo_tag = 'hypo_IMH' if true_normal else 'hypo_NMH' llh_data = find_alt_hierarchy_fit(asimov_data_set, template_maker,
for data_tag, data_normal in [('true_NMH',True),('true_IMH',False)]: tprofile.info("Assuming: %s"%data_tag) output[data_tag] = {} # Get Asimov data set for assuming true: data_tag asimov_data = getAsimovData( template_maker, template_settings['params'], data_normal) alt_params = fix_non_atm_params(template_settings['params']) alt_mh_settings, llh_data = getAltHierarchyBestFit( asimov_data, template_maker, alt_params, minimizer_settings, (not data_normal), check_octant) asimov_data_null = get_asimov_fmap( template_maker=template_maker, fiducial_params=alt_mh_settings, channel=alt_mh_settings['channel']) # Store all data tag related inputs: output[data_tag]['asimov_data'] = asimov_data output[data_tag]['asimov_data_null'] = asimov_data_null output[data_tag]['alt_mh_settings'] = alt_mh_settings output[data_tag]['llh_null'] = llh_data # If we are not taking the best fit of the asimov data to the # alternative hierarchy as the "null hypothesis", then we will use # the parameters of the alternative hierarchy in the settings # file, which correspond to the world best fit values. if args.no_alt_fit: null_settings = get_values( select_hierarchy(template_settings['params'],
else: pseudo_data_template_maker = template_maker # ////////////////////////////////////////////////////////////////////// # Generate two pseudo-data experiments (one for each hierarchy), # and for each experiment, find the best matching template in each # of the hierarchy hypotheses. # ////////////////////////////////////////////////////////////////////// results = {} for data_tag, data_normal in [('data_NMH',True),('data_IMH',False)]: results[data_tag] = {} # 1) get "Asimov" average fiducial template: asimov_fmap = get_asimov_fmap(pseudo_data_template_maker, get_values(select_hierarchy(pseudo_data_settings['params'], normal_hierarchy=data_normal)), channel=channel) # 2) find max llh or min chisquare (and best fit free params) from matching pseudo data # to templates. for hypo_tag, hypo_normal in [('hypo_NMH',True),('hypo_IMH',False)]: physics.info("Finding best fit for %s under %s assumption"%(data_tag,hypo_tag)) tprofile.info("start optimizer") tprofile.info("Using %s"%metric_name) opt_data = find_opt_bfgs(asimov_fmap,template_maker,template_settings['params'], minimizer_settings,args.save_steps, normal_hierarchy=hypo_normal, check_octant=args.check_octant, metric_name=metric_name) tprofile.info("stop optimizer")
#data_types = [('data_NMH',True),('data_IMH',False)] data_types = [('data_NMH',True)] results = {} # Store for future checking: results['template_settings'] = template_settings results['minimizer_settings'] = minimizer_settings results['grid_settings'] = grid_settings try: for data_tag, data_normal in data_types: results[data_tag] = {} data_params = select_hierarchy(params,normal_hierarchy=data_normal) asimov_data_set = get_asimov_fmap(template_maker,get_values(data_params), chan=channel) results[data_tag]['asimov_data'] = asimov_data_set hypo_types = [('hypo_NMH',True)] #hypo_types = [('hypo_NMH',True),('hypo_IMH',False)] for hypo_tag, hypo_normal in hypo_types: hypo_params = select_hierarchy(params,normal_hierarchy=hypo_normal) # Now scan over theta23,deltam31 values and fix params to # these values: # Calculate steps for all free parameters atm_params = get_atm_params(hypo_params) calc_steps(atm_params, grid_settings['steps']) # Build a list from all parameters that holds a list of (name, step) tuples steplist = [ [(name,step) for step in param['steps']] for name, param in sorted(atm_params.items())]
else: pseudo_data_template_maker = template_maker # ////////////////////////////////////////////////////////////////////// # Generate two pseudo-data experiments (one for each hierarchy), # and for each experiment, find the best matching template in each # of the hierarchy hypotheses. # ////////////////////////////////////////////////////////////////////// results = {} for data_tag, data_normal in [('data_NMH', True), ('data_IMH', False)]: results[data_tag] = {} # 1) get "Asimov" average fiducial template: asimov_fmap = get_asimov_fmap(pseudo_data_template_maker, get_values( select_hierarchy( pseudo_data_settings['params'], normal_hierarchy=data_normal)), channel=channel) # 2) find max llh or min chisquare (and best fit free params) from matching pseudo data # to templates. for hypo_tag, hypo_normal in [('hypo_NMH', True), ('hypo_IMH', False)]: physics.info("Finding best fit for %s under %s assumption" % (data_tag, hypo_tag)) tprofile.info("start optimizer") tprofile.info("Using %s" % metric_name) opt_data = find_opt_bfgs(asimov_fmap, template_maker, template_settings['params'], minimizer_settings,
normal_hierarchy=true_normal) # Set up the arrays to store the true/fit values in: for key in free_params.keys(): result['true_'+key] = [] result['fit_'+key] = [] result['asimov_data'] = [] # This will actually only iterate over theta23 (for now), changing # the asimov data set: for step in steplist: print "Running at asimov parameters: %s"%step asimov_params = get_values(getAsimovParams(params,true_normal,step)) asimov_data_set = get_asimov_fmap( template_maker, asimov_params, chan=asimov_params['channel']) # Store injected true values in result: for key in free_params.keys(): if 'theta23' in key: continue result['true_'+key].append(asimov_params[key]) result['true_theta23'].append(step) result['asimov_data'].append(asimov_data_set) # now get fitted values of opposite hierarchy: hypo_normal = False if true_normal else True hypo_tag = 'hypo_IMH' if true_normal else 'hypo_NMH' llh_data = find_alt_hierarchy_fit( asimov_data_set,template_maker, params, hypo_normal,
for data_tag, data_normal in [('true_NMH', True), ('true_IMH', False)]: tprofile.info("Assuming: %s" % data_tag) output[data_tag] = {} # Get Asimov data set for assuming true: data_tag asimov_data = getAsimovData(template_maker, template_settings['params'], data_normal) alt_params = fix_non_atm_params(template_settings['params']) alt_mh_settings, llh_data = getAltHierarchyBestFit( asimov_data, template_maker, alt_params, minimizer_settings, (not data_normal), check_octant) asimov_data_null = get_asimov_fmap(template_maker=template_maker, fiducial_params=alt_mh_settings, channel=alt_mh_settings['channel']) # Store all data tag related inputs: output[data_tag]['asimov_data'] = asimov_data output[data_tag]['asimov_data_null'] = asimov_data_null output[data_tag]['alt_mh_settings'] = alt_mh_settings output[data_tag]['llh_null'] = llh_data # If we are not taking the best fit of the asimov data to the # alternative hierarchy as the "null hypothesis", then we will use # the parameters of the alternative hierarchy in the settings # file, which correspond to the world best fit values. if args.no_alt_fit: null_settings = get_values( select_hierarchy(template_settings['params'],