コード例 #1
0
ファイル: Flux.py プロジェクト: olivas/pisa
def get_flux_maps(flux_service, ebins, czbins, **params):
    '''Get a set of flux maps for the different primaries'''

    #Be verbose on input
    params = get_params()
    report_params(params, units = [])

    #Initialize return dict
    maps = {'params': params}

    for prim in primaries:

        #Get the flux for this primary
        maps[prim] = {'ebins': ebins,
                      'czbins': czbins,
                      'map': flux_service.get_flux(ebins,czbins,prim)}
    
        #be a bit verbose
        physics.trace("Total flux of %s is %u [s^-1 m^-2]"%
                                (prim,maps[prim]['map'].sum()))

    #return this map
    return maps
コード例 #2
0
ファイル: Reco.py プロジェクト: olivas/pisa
def get_reco_maps(true_event_maps,reco_service=None,e_reco_scale=None,
                  cz_reco_scale=None, **kwargs):
    '''
    Primary function for this module, which returns the reconstructed
    event rate maps from the true event rate maps, and from the
    smearing kernal obtained from simulations. The returned maps will
    be in the form of a dictionary with parameters:
    {'nue_cc':{'ebins':ebins,'czbins':czbins,'map':map},
     'numu_cc':{...},
     'nutau_cc':{...},
     'nuall_nc':{...}
    }
    Note that in this function, the nu<x> is now combined with nu_bar<x>.
    '''

    #Be verbose on input
    params = get_params()
    report_params(params, units = ['',''])
    
    #Initialize return dict
    reco_maps = {'params': add_params(params,true_event_maps['params'])}

    #Get kernels from reco service
    kernel_dict = reco_service.get_kernels()

    ebins, czbins = get_binning(true_event_maps)

    flavours = ['nue','numu','nutau']
    int_types = ['cc','nc']
    
    
    for int_type in int_types:
        for flavor in flavours:
            logging.info("Getting reco event rates for %s %s"%(flavor,int_type))
            reco_evt_rate = np.zeros((len(ebins)-1,len(czbins)-1),
                                     dtype=np.float32)
            for mID in ['','_bar']:
                flav = flavor+mID
                true_evt_rate = true_event_maps[flav][int_type]['map']
                
                kernels = kernel_dict[flav][int_type]
                    
                for ie,egy in enumerate(ebins[:-1]):
                    for icz,cz in enumerate(czbins[:-1]):
                        # Get kernel at these true parameters from 4D hist
                        kernel = kernels[ie,icz]
                        # normalize
                        if np.sum(kernel) > 0.0: kernel /= np.sum(kernel)
                        reco_evt_rate += true_evt_rate[ie,icz]*kernel

            reco_maps[flavor+'_'+int_type] = {'map':reco_evt_rate,
                                              'ebins':ebins,
                                              'czbins':czbins}
            physics.trace("Total counts for %s %s: %.2f"
                %(flavor,int_type,np.sum(reco_evt_rate)))

    #Finally sum up all the NC contributions
    logging.info("Summing up rates for %s %s"%('all',int_type))
    reco_evt_rate = np.sum([reco_maps.pop(key)['map'] for key in reco_maps.keys()
                            if key.endswith('_nc')], axis = 0)
    reco_maps['nuall_nc'] = {'map':reco_evt_rate,
                             'ebins':ebins,
                             'czbins':czbins}
    physics.trace("Total event counts: %.2f"%np.sum(reco_evt_rate))

    # Apply e_reco_scaling...
    # Apply cz_reco_scaling...
    
    return reco_maps