def get_llh_hypothesis( data_tag, asimov_data, ntrials, template_maker, template_params, minimizer_settings, save_steps, check_octant): """ Runs the llh fitter ntrials number of times, pulling pseudo data sets from asimov_data. \Params: * data_tag - hierarchy type running for assumed true. * asimov_data - asimov (unfluctuated) data from which to generate poisson fluctuated pseudo data * ntrials - number of trials to run for each hierarchy hypothesis * template_maker - instance of TemplateMaker class, from which to fit pseudo data to * template_params - dictionary of parameters at which to test the pseudo data and find the best match llh * minimizer_settings - settings for bfgs minimizer in llh fit * save_steps - flag to save the optimizer steps * check_octant - boolean to check both octants of theta23 \returns - trials list that holds the dictionaries of llh results. """ trials = [] for itrial in xrange(1,ntrials+1): results = {} # one trial of results tprofile.info("start trial %d"%itrial) logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10) results['seed'] = get_seed() logging.info(" RNG seed: %ld"%results['seed']) # Get random map generated from asimov data (or from data_tag). fmap = get_random_map(asimov_data, seed=results['seed']) 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)) with Timer() as t: llh_data = find_max_llh_bfgs( fmap, template_maker, template_params, minimizer_settings, save_steps, normal_hierarchy=hypo_normal, check_octant=check_octant) tprofile.info("==> elapsed time for optimizer: %s sec"%t.secs) # Store the LLH data results[hypo_tag] = llh_data trials += [results] tprofile.info("stop trial %d"%itrial) return trials
def get_pseudo_data_fmap(template_maker,fiducial_params,seed=None): ''' Creates a true template from fiducial_params, then uses Poisson statistics to vary the expected counts per bin to create a pseudo data set. If seed is provided, the random state is seeded with seed before the map is created. IMPORTANT: returns a SINGLE flattened map of trck/cscd combined ''' true_template = template_maker.get_template(fiducial_params) true_fmap = flatten_map(true_template) fmap = get_random_map(true_fmap, seed=seed) return fmap
def get_pseudo_data_fmap(template_maker, fiducial_params, channel, seed=None): """ Creates a true template from fiducial_params, then uses Poisson statistics to vary the expected counts per bin to create a pseudo data set. If seed is provided, the random state is seeded with seed before the map is created. IMPORTANT: returns a SINGLE flattened map of trck/cscd combined \params: * channel = channel of flattened fmap to use. if 'all': returns a single flattened map of trck/cscd combined. if 'cscd' or 'trck' only returns the channel requested. """ true_template = template_maker.get_template(fiducial_params) true_fmap = flatten_map(true_template, channel=channel) fmap = get_random_map(true_fmap, seed=seed) return fmap
output[dkey][hkey][key] = 0 if key not in ['theta23','deltam31','llh']: names.append(key) for AtmOscBin in all_data[dkey][hkey]: if AtmOscBin['theta23'][0] == theta23tocheck and AtmOscBin['deltam31'][0] == deltam31tocheck: for key in AtmOscBin.keys(): output[dkey][hkey][key] = AtmOscBin[key][0] asimov_data = getAsimovData(template_maker, template_settings['params'], data_normal) if output['seed'] is not None: fmap = get_random_map(asimov_data, seed=output['seed']) else: print "Using Asimov Data" fmap = asimov_data for itrial in xrange(1,2): results = {} results[dkey] = {} tprofile.info("start trial %d"%itrial) logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10) results[dkey][hkey] = {} for Tname in names: for key in output[dkey][hkey].keys():
alt_mh_expectation = get_asimov_fmap( template_maker, null_settings, channel=null_settings['channel'] ) else: alt_mh_expectation = asimov_data_null trials = [] for itrial in xrange(1,args.ntrials+1): results = {} # one trial of results tprofile.info("start trial %d"%itrial) logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10) results['seed'] = get_seed() logging.info(" RNG seed: %ld"%results['seed']) fmap = get_random_map(alt_mh_expectation, seed=results['seed']) 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)) with Timer() as t: llh_data = find_opt_bfgs( fmap, template_maker, template_settings['params'], minimizer_settings, args.save_steps, normal_hierarchy=hypo_normal, check_octant=check_octant) tprofile.info("==> elapsed time for optimizer: %s sec"%t.secs) # Store the LLH data results[hypo_tag] = llh_data
# later comparison asimov_data = getAsimovData( template_maker, template_settings['params'], data_normal) output[data_tag]['asimov_data'] = asimov_data trials = [] for itrial in xrange(1,args.ntrials+1): results = {} # one trial of results tprofile.info("start trial %d"%itrial) logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10) results['seed'] = get_seed() logging.info(" RNG seed: %ld"%results['seed']) # Get random map generated from asimov data (or from data_tag). fmap = get_random_map(asimov_data, seed=results['seed']) 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)) with Timer() as t: llh_data = find_opt_bfgs( fmap, template_maker, template_settings['params'], minimizer_settings, args.save_steps, normal_hierarchy=hypo_normal, check_octant=check_octant) tprofile.info("==> elapsed time for optimizer: %s sec"%t.secs) # Store the LLH data results[hypo_tag] = llh_data
alt_mh_expectation = get_asimov_fmap(template_maker, null_settings, channel=null_settings['channel']) else: alt_mh_expectation = asimov_data_null trials = [] for itrial in xrange(1, args.ntrials + 1): results = {} # one trial of results tprofile.info("start trial %d" % itrial) logging.info(">" * 10 + "Running trial: %05d" % itrial + "<" * 10) results['seed'] = get_seed() logging.info(" RNG seed: %ld" % results['seed']) fmap = get_random_map(alt_mh_expectation, seed=results['seed']) 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)) with Timer() as t: llh_data = find_opt_bfgs(fmap, template_maker, template_settings['params'], minimizer_settings, args.save_steps, normal_hierarchy=hypo_normal, check_octant=check_octant) tprofile.info("==> elapsed time for optimizer: %s sec" % t.secs)