Example #1
0
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
Example #2
0
for itrial in xrange(1,args.ntrials+1):
    profile.info("start trial %d"%itrial)
    logging.info(">"*10 + "Running trial: %05d"%itrial + "<"*10)


    # //////////////////////////////////////////////////////////////////////
    # For each trial, generate two pseudo-data experiemnts (one for each
    # hierarchy), and for each find the best matching template in each of the
    # hierarchy hypothesis.
    # //////////////////////////////////////////////////////////////////////
    results = {}
    for data_tag, data_normal in [('data_NMH',True),('data_IMH',False)]:

        results[data_tag] = {}
        # 0) get a random seed and store with the data
        results[data_tag]['seed'] = get_seed()
        # 1) get a pseudo data fmap from fiducial model (best fit vals of params).
        fmap = get_pseudo_data_fmap(template_maker,
                                    get_values(select_hierarchy(params,
                                                                normal_hierarchy=data_normal)),
                                    seed=results[data_tag]['seed'])

        # 2) find max llh (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))
            profile.info("start optimizer")
            llh_data = find_max_llh_bfgs(fmap,template_maker,params,
                                        minimizer_settings,args.save_steps,normal_hierarchy=hypo_normal)
            profile.info("stop optimizer")
Example #3
0
            select_hierarchy(template_settings['params'],
                             normal_hierarchy= (not data_normal)))
        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
Example #4
0
try:
    for itrial in xrange(1, args.ntrials + 1):
        profile.info("start trial %d" % itrial)
        logging.info(">" * 10 + "Running trial: %05d" % itrial + "<" * 10)

        # //////////////////////////////////////////////////////////////////////
        # For each trial, generate two pseudo-data experiemnts (one for each
        # hierarchy), and for each 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] = {}
            # 0) get a random seed and store with the data
            results[data_tag]['seed'] = get_seed()
            logging.info("  RNG seed: %ld" % results[data_tag]['seed'])
            # 1) get a pseudo data fmap from fiducial model (best fit vals of params).
            fmap = get_pseudo_data_fmap(pseudo_data_template_maker,
                                        get_values(
                                            select_hierarchy(
                                                pseudo_data_settings['params'],
                                                normal_hierarchy=data_normal)),
                                        seed=results[data_tag]['seed'],
                                        chan=channel)

            # 2) find max llh (and best fit free params) from matching pseudo data
            #    to templates.
            for hypo_tag, hypo_normal in [('hypo_NMH', True),
                                          ('hypo_IMH', False)]:
Example #5
0
    output[data_tag] = {}

    # Get Asimov data set for assuming true: data_tag, and store for
    # 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)