Exemple #1
0
 def __init__(self, mcpath, slc, options='00'):
     self.mcpath = mcpath
     self._rescale = int(options[0])
     self._scramble = int(options[1])
     self.num_files = float(mcpath.split('_')[-1][:-3]) / 5.
     self.slc = slc
     self.mcfg = PathGen(self.mcpath)
     self.h5f = h5py.File(mcpath, "r")
     self.set_mc_quantities()
Exemple #2
0
 def make_e_dtheta_list(self):
     e_dtheta_list = []
     for mcfile in self.mcfile_list:
         pg = PathGen(mcfile)
         for fluxtype in self.fluxtype_list:
             if not path.exists("%s_%s.npy" %
                                (pg.get_e_d_theta_path(fluxtype),
                                 self.edtheta_opts)) or self.recompute:
                 e_dtheta_list.append((mcfile, fluxtype, self.edtheta_opts))
     return e_dtheta_list
Exemple #3
0
 def compute_mc_fluxes(self):
     for mcfile in self.mcfile_list:
         pg = PathGen(mcfile)
         for fluxtype in self.fluxtype_list:
             if not path.exists(
                     pg.get_mc_dn_dz_path(fluxtype)) or self.recompute:
                 print(pg.get_mc_dn_dz_path(fluxtype))
                 fluxmaker = create_mc_fluxmaker(mcfile, fluxtype)
                 fluxmaker.initialize_nuSQuIDS()
                 fluxmaker.save_flux()
class BaseGamma():

    def __init__(self, mcpath, fluxtype, options, _skip, _test=False):

        self.mcpath     = mcpath
        self.fluxtype   = fluxtype
        self.options    = options
        self._skip      = _skip
        self._test      = _test
        if 'oscNext' in mcpath:
            self.e_bins = le_e_bins
        else:
            self.e_bins = e_bins
        self.gamma_hist = None
        self.slc        = slice(None, None, _skip)
        self.mcfg       = PathGen(self.mcpath)
        self._seed      = abs(hash(self.mcfg.get_mc_dn_dz_path(self.fluxtype))) % (2**32)
        self.mcr        = MCReader(self.mcpath, self.slc, options=options)
        self.flux       = self.load_flux()

    def make_hist(self):
        pass

    def load_flux(self):
        return np.load(self.mcfg.get_mc_dn_dz_path(self.fluxtype))[self.slc]

    def save_hist(self):
        if self.gamma_hist is None:
            print('Gamma hist is not yet defined. Did not save')
        else:
            if self._test:
                np.save('%s_%s_test' % (self.mcfg.get_e_d_theta_path(self.fluxtype), self.options), self.gamma_hist)
            else:
                np.save('%s_%s' % (self.mcfg.get_e_d_theta_path(self.fluxtype), self.options), self.gamma_hist)

    def do_calc(self):
        hist = np.zeros((len(gamma_bins)-1, len(self.e_bins)-1))
        for i, jd in enumerate(jds):
            x = sc.nParameter(jd)
            obl = sc.solarObliquity(x)
            L = sc.L(x)
            G = sc.g(x)
            lamb = sc.solarLambda(L,G)
            rad = sc.solarR(G)
            zenith = sc.equatorialZenith(obl, lamb)

            h = self.make_hist(rad, zenith, azimuths[i])
            hist += h[0]
            
        self.gamma_hist = hist*self._skip*delta_t
    def __init__(self, mcpath, fluxtype, options, _skip, _test=False):

        self.mcpath     = mcpath
        self.fluxtype   = fluxtype
        self.options    = options
        self._skip      = _skip
        self._test      = _test
        if 'oscNext' in mcpath:
            self.e_bins = le_e_bins
        else:
            self.e_bins = e_bins
        self.gamma_hist = None
        self.slc        = slice(None, None, _skip)
        self.mcfg       = PathGen(self.mcpath)
        self._seed      = abs(hash(self.mcfg.get_mc_dn_dz_path(self.fluxtype))) % (2**32)
        self.mcr        = MCReader(self.mcpath, self.slc, options=options)
        self.flux       = self.load_flux()
Exemple #6
0
class MCReader():
    def __init__(self, mcpath, slc, options='00'):
        self.mcpath = mcpath
        self._rescale = int(options[0])
        self._scramble = int(options[1])
        self.num_files = float(mcpath.split('_')[-1][:-3]) / 5.
        self.slc = slc
        self.mcfg = PathGen(self.mcpath)
        self.h5f = h5py.File(mcpath, "r")
        self.set_mc_quantities()

    def set_mc_quantities(self):
        self.nu_e = self.h5f["NuEnergy"]["value"][self.slc]
        if self._scramble:
            print('Scramble mode: activated')
            delta_az = np.random.rand(len(self.nu_e)) * 2 * np.pi
        else:
            delta_az = np.zeros(len(self.nu_e))
        self.nu_zen = self.h5f["NuZenith"]["value"][self.slc]
        self.nu_az = self.h5f["NuAzimuth"]["value"][self.slc]
        self.reco_e = self.h5f["MuExEnergy"]["value"][self.slc]
        if not self._rescale:
            self.reco_zen = self.h5f["MuExZenith"]["value"][self.slc]
            _ = self.h5f["MuExAzimuth"]["value"][self.slc]
            self.reco_az = np.mod(_ + delta_az, 2 * np.pi)
        else:
            print('Rescale mode: activated')
            reco_az, reco_zen = gen_new_zen_az(self.h5f["NuEnergy"]["value"])
            self.reco_az = np.mod(reco_az[self.slc] + delta_az, 2 * np.pi)
            self.reco_zen = reco_zen[self.slc]
        self.set_oneweight()

    def set_oneweight(self):
        if path.exists(self.mcfg.get_ow_path()):
            ow = np.load(self.mcfg.get_ow_path())[self.slc] / self.num_files
        else:
            ow = wmc.weight_mc(self.mcfg)[self.slc] / self.num_files
        self.oneweight = ow

    def set_compare():
        self.oneweight = np.where(self.nu_e > 3000, 0, self.oneweight)
Exemple #7
0
    def _make_initial_data(self):
        pg       = PathGen(self.mcpath)
        fluxfile = np.load('/data/user/jlazar/solar_WIMP/data/charon_fluxes/%s_1AU_BRW_dn_dz.npy' % (self.fluxtype))
            
        czens    = np.linspace(-1, 0.2, 100)
        energies = fluxfile['Energy']

        initial_flux = np.zeros((len(czens), len(energies), 2, 3), dtype=float)
        for ic in range(len(czens)):
            initial_flux[ic,:,0,0] = fluxfile['nu_e']
            initial_flux[ic,:,1,0] = fluxfile['nu_e_bar']
            initial_flux[ic,:,0,1] = fluxfile['nu_mu']
            initial_flux[ic,:,1,1] = fluxfile['nu_mu_bar']
            initial_flux[ic,:,0,2] = fluxfile['nu_tau']
            initial_flux[ic,:,1,2] = fluxfile['nu_tau_bar']
        del fluxfile
        return czens, energies, initial_flux
Exemple #8
0
        del pp_HG_nubar
        return czens, energies, initial_flux

    def get_flux(self, cz, e, ptype):
        if e>1e5:
            return 0
        elif ptype==14:
            return self.nsq_atm.EvalFlavor(1, cz, e*pc.GeV, 0)
        elif ptype==-14:
            return self.nsq_atm.EvalFlavor(1, cz, e*pc.GeV, 1)
        else:
            print('wrong ptype doggo')
            return 0


if __name__=='__main__':
    args      = initialize_args()
    print('bong')
    if args.fluxtype=='conv-numu':
        fluxmaker = ConvNumuMCFluxMaker(args.mcfile, args.fluxtype)
    elif args.fluxtype=='solar-atm':
        fluxmaker = SolarAtmMCFluxMaker(args.mcfile, args.fluxtype)
    else:
        fluxmaker = SignalMCFluxMaker(args.mcfile, args.fluxtype)
    print('bang')
    fluxmaker.initialize_nuSQuIDS()
    print('bloop')
    mcflux    = fluxmaker.interp_mc()
    pg        = PathGen(args.mcfile)
    np.save(pg.get_mc_dn_dz_path(args.fluxtype)+'test', mcflux)
Exemple #9
0
    #        LWevent.zenith                 = event[5]
    #        LWevent.energy                 = event[6]
    #        LWevent.primary_type           = LW.ParticleType(event[7])
    #        LWevent.total_column_depth     = event[8]
    #        LWevent.x                      = 0.
    #        LWevent.y                      = 0.
    #        LWevent.z                      = 0.
    #
    #        chunk_weights[i] = weighter.get_oneweight(LWevent)
    #        print(chunk_weights)
    #
    #    weights[chunk.start:chunk.stop] = chunk_weights

    if save:
        np.save(
            "/data/user/jlazar/solar_WIMP/data/mc_oneweight/%s" %
            mcgf.get_mcname(), weights)


#    mc.close()
    return weights

if __name__ == "__main__":
    args = initialize_argparse()
    savefilename = args.mcfile.split("/")[-1][:-3] + ".npy"
    mcgf = PathGen(args.mcfile)
    weights = weight_mc(mcgf)
    np.save(
        "/data/user/jlazar/solar_WIMP/data/mc_oneweight/%s" %
        mcgf.get_mcname(), weights)