Example #1
0
def create_nuSQuIDS(mutauBins,tautauBins):
  global numuSQUIDSDict, numubarSQUIDSDict, nueSQUIDSDict, nuebarSQUIDSDict
  for mutau in mutauBins:
#    print 'MT: ',etau 
    for tautau in tautauBins: 
#      print 'TT: ',tautau 
#TODO: Currently taking bin edges, probably want bin centers, oh well
      nuSQBar = nsq.nuSQUIDS(beg_ene,end_ene,200,3,nsq.NeutrinoType.antineutrino,True,False)
      nuSQ = nsq.nuSQUIDS(beg_ene,end_ene,200,3,nsq.NeutrinoType.neutrino,True,False)
#Muon neutrinos
      SetNSQParams(this_zen,nuSQ,1)
      SetNSQParams(this_zen,nuSQBar,1)
#      filename = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/HD5Files/Squid-Zen%.3f.hdf5" % (this_zen)
      filename = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/NewTest.hdf5"
      groupname = "/NuMu%.4fET%.3fEM" % (mutau, tautau)
      print filename,groupname
      nuSQ.WriteStateHDF5(filename,groupname,False,"/")
      #nuSQ.WriteStateHDF5(filename)
      groupname = "/NuMuBar%.4fET%.3fEM" % (mutau, tautau)
#      print groupname
      nuSQBar.WriteStateHDF5(filename,groupname,False,"/")
#Electron neutrinos
      SetNSQParams(this_zen,nuSQ,0)
      SetNSQParams(this_zen,nuSQBar,0)

      groupname = "/NuE%.4fET%.3fEM" % (mutau, tautau)
      nuSQ.WriteStateHDF5(filename,groupname,False,"/")
      groupname = "/NuEBar%.4fET%.3fEM" % (mutau, tautau)
      nuSQBar.WriteStateHDF5(filename,groupname,False,"/")
Example #2
0
def create_nuSQuIDS(mutauBins, tautauBins):
    global numuSQUIDSDict, numubarSQUIDSDict, nueSQUIDSDict, nuebarSQUIDSDict
    for mutau in mutauBins:
        #    print 'MT: ',etau
        for tautau in tautauBins:
            #      print 'TT: ',tautau
            #TODO: Currently taking bin edges, probably want bin centers, oh well
            nuSQBar = nsq.nuSQUIDS(beg_ene, end_ene, 200, 3,
                                   nsq.NeutrinoType.antineutrino, True, False)
            nuSQ = nsq.nuSQUIDS(beg_ene, end_ene, 200, 3,
                                nsq.NeutrinoType.neutrino, True, False)
            #Muon neutrinos
            SetNSQParams(this_zen, nuSQ, 1)
            SetNSQParams(this_zen, nuSQBar, 1)
            #      filename = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/HD5Files/Squid-Zen%.3f.hdf5" % (this_zen)
            filename = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/NewTest.hdf5"
            groupname = "/NuMu%.4fET%.3fEM" % (mutau, tautau)
            print filename, groupname
            nuSQ.WriteStateHDF5(filename, groupname, False, "/")
            #nuSQ.WriteStateHDF5(filename)
            groupname = "/NuMuBar%.4fET%.3fEM" % (mutau, tautau)
            #      print groupname
            nuSQBar.WriteStateHDF5(filename, groupname, False, "/")
            #Electron neutrinos
            SetNSQParams(this_zen, nuSQ, 0)
            SetNSQParams(this_zen, nuSQBar, 0)

            groupname = "/NuE%.4fET%.3fEM" % (mutau, tautau)
            nuSQ.WriteStateHDF5(filename, groupname, False, "/")
            groupname = "/NuEBar%.4fET%.3fEM" % (mutau, tautau)
            nuSQBar.WriteStateHDF5(filename, groupname, False, "/")
Example #3
0
def makenuSQuIDS(ene,zen,flav,n_type,mutau=0.0,tautau=0.0,mode=0,e_SQuIDS=None,m_SQuIDS=None):
  if(mode==0):
    if(n_type>0):
      nuSQ = nsq.nuSQUIDSNSI(mutau,0.0,tautau,0.0,0.0,math.floor(ene),math.ceil(ene),2,3,nsq.NeutrinoType.neutrino,True,False)
    if(n_type<0):
      nuSQ = nsq.nuSQUIDSNSI(mutau,0.0,tautau,0.0,0.0,math.floor(ene),math.ceil(ene),2,3,nsq.NeutrinoType.antineutrino,True,False)
    if(flav=='e'):
      SetNSQParams(numpy.cos(zen),nuSQ,0)
    if(flav=='mu'):
      SetNSQParams(numpy.cos(zen),nuSQ,1)
    return nuSQ.EvalFlavor(0,ene*nuSQ.units.GeV,0),nuSQ.EvalFlavor(1,ene*nuSQ.units.GeV,0),nuSQ.EvalFlavor(2,ene*nuSQ.units.GeV,0)
  if(mode==1):
    pytpe = None
    if(n_type>0):
      if(flav=='e'):
        ptype = 'NuE' 
      if(flav=='mu'):
        ptype = 'NuMu' 
    if(n_type<0):
      if(flav=='e'):
        ptype = 'NuEBar' 
      if(flav=='mu'):
        ptype = 'NuMuBar' 
    file_name = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/ZenWeights/Switch%s%.4fET%.3fEM.hd5" % (ptype,mutau,tautau)
    e_vals = []
    m_vals = []
    t_vals = []
    zen_val = round(2*numpy.cos(zen),2)/2 
    if(zen_val<-0.995):
      zen_val=-0.995
    if(zen_val==0):
      zen_val=0.005
    group_name = "%s%.4fET%.3fEM%.3f" % (ptype,mutau,tautau,zen_val)
    nuSQ = None
    if(flav=='e'):
      if(not((ptype,mutau,tautau,zen_val) in e_SQuIDS.keys())):
        e_SQuIDS[(ptype,mutau,tautau,zen_val)] = nsq.nuSQUIDS(file_name,group_name)
      nuSQ = e_SQuIDS[(ptype,mutau,tautau,zen_val)]
    if(flav=='mu'):
      if(not((ptype,mutau,tautau,zen_val) in m_SQuIDS.keys())):
        m_SQuIDS[(ptype,mutau,tautau,zen_val)] = nsq.nuSQUIDS(file_name,group_name)
      nuSQ = m_SQuIDS[(ptype,mutau,tautau,zen_val)]
    eWeight = nuSQ.EvalFlavor(0,ene*nuSQ.units.GeV,0)
    mWeight = nuSQ.EvalFlavor(1,ene*nuSQ.units.GeV,0)
    tWeight = nuSQ.EvalFlavor(2,ene*nuSQ.units.GeV,0)
    return eWeight,mWeight,tWeight
Example #4
0
def make_squids(mutauBins,tautauBins,zenBins):
  #print mutauBins,tautauBins,zenBins
  for this_zen in zenBins:
    for mutau in mutauBins:
      for tautau in tautauBins:
        ind_tup = (mutau,tautau,this_zen)
        file_name = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/HD5Files/Squid-Zen%.3f.hdf5" % (this_zen)
        groupname = "NuMu%.4fET%.3fEM" % (mutau, tautau)
        #print file_name,groupname
        nuSQ = nsq.nuSQUIDS(file_name,groupname)
        hmSQUIDDict[ind_tup] = nuSQ
        groupname = "NuE%.4fET%.3fEM" % (mutau, tautau)
        #print groupname
        nuSQ = nsq.nuSQUIDS(file_name,groupname)
        heSQUIDDict[ind_tup] = nuSQ
        groupname = "NuMuBar%.4fET%.3fEM" % (mutau, tautau)
        #print groupname
        nuSQBar = nsq.nuSQUIDS(file_name,groupname)
        hmbSQUIDDict[ind_tup] = nuSQBar
        groupname = "NuEBar%.4fET%.3fEM" % (mutau, tautau)
        #print groupname
        nuSQBar = nsq.nuSQUIDS(file_name,groupname)
        hebSQUIDDict[ind_tup] = nuSQBar
Example #5
0
def make_squids(mutauBins, tautauBins, zenBins):
    #print mutauBins,tautauBins,zenBins
    for this_zen in zenBins:
        for mutau in mutauBins:
            for tautau in tautauBins:
                ind_tup = (mutau, tautau, this_zen)
                file_name = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/HD5Files/Squid-Zen%.3f.hdf5" % (
                    this_zen)
                groupname = "NuMu%.4fET%.3fEM" % (mutau, tautau)
                #print file_name,groupname
                nuSQ = nsq.nuSQUIDS(file_name, groupname)
                hmSQUIDDict[ind_tup] = nuSQ
                groupname = "NuE%.4fET%.3fEM" % (mutau, tautau)
                #print groupname
                nuSQ = nsq.nuSQUIDS(file_name, groupname)
                heSQUIDDict[ind_tup] = nuSQ
                groupname = "NuMuBar%.4fET%.3fEM" % (mutau, tautau)
                #print groupname
                nuSQBar = nsq.nuSQUIDS(file_name, groupname)
                hmbSQUIDDict[ind_tup] = nuSQBar
                groupname = "NuEBar%.4fET%.3fEM" % (mutau, tautau)
                #print groupname
                nuSQBar = nsq.nuSQUIDS(file_name, groupname)
                hebSQUIDDict[ind_tup] = nuSQBar
Example #6
0
import numpy as np
mpl.rc('font', family='serif', size=20)
plt.style.use('./paper.mplstyle')


# Welcome to the $\nu$-SQuIDS demo. In 
# this notebook we will demostrate some of the functionalities of the $\nu$-SQuIDS' python bindings. All of the calculations performed here can also be done in the C++ interface. Enjoy :)! Carlos, Jordi & Chris.

# # The Basics: single energy mode

# #### Basic definitions

# To start, like in the C++ case, we need to create a $\nu$-SQuIDS object. To begin this demonstration we will create a simple single energy three flavor neutrino oscillation calculator. Thus we just need to specify the number of neutrinos (3) and if we are dealing with neutrinos or antineutrinos.


nuSQ = nsq.nuSQUIDS(3,nsq.NeutrinoType.neutrino)


# nuSQuIDS inputs should be given in natural units. In order to make this convenient we have define a units class called *Const*. We can instanciate it as follows


units = nsq.Const()


# As in the C++ $\nu$-SQuIDS interface one can propagate the neutrinos in various environments (see the documentation for further details), and the user can create and include their own environments. To start a simple case, lets consider oscillactions in <strong> Vacuum </strong>


nuSQ.Set_Body(nsq.Vacuum())


# Since we have specify that we are considering vacuum propagation, we must construct - as in the C++ interface - a *trayectory* inside that object. This can be done using the `Track` property of the given `Body`. Each `Body` will have its on `Track` subclass and its constructors. We can set and construct a <strong>vacuum trayectory</strong> in the following way:
Example #7
0
def makenuSQuIDS(ene,
                 zen,
                 flav,
                 n_type,
                 mutau=0.0,
                 tautau=0.0,
                 mode=0,
                 e_SQuIDS=None,
                 m_SQuIDS=None):
    if (mode == 0):
        if (n_type > 0):
            nuSQ = nsq.nuSQUIDSNSI(mutau, 0.0, tautau, 0.0, 0.0,
                                   math.floor(ene), math.ceil(ene), 2, 3,
                                   nsq.NeutrinoType.neutrino, True, False)
        if (n_type < 0):
            nuSQ = nsq.nuSQUIDSNSI(mutau, 0.0, tautau, 0.0, 0.0,
                                   math.floor(ene), math.ceil(ene), 2, 3,
                                   nsq.NeutrinoType.antineutrino, True, False)
        if (flav == 'e'):
            SetNSQParams(numpy.cos(zen), nuSQ, 0)
        if (flav == 'mu'):
            SetNSQParams(numpy.cos(zen), nuSQ, 1)
        return nuSQ.EvalFlavor(0, ene * nuSQ.units.GeV, 0), nuSQ.EvalFlavor(
            1, ene * nuSQ.units.GeV,
            0), nuSQ.EvalFlavor(2, ene * nuSQ.units.GeV, 0)
    if (mode == 1):
        pytpe = None
        if (n_type > 0):
            if (flav == 'e'):
                ptype = 'NuE'
            if (flav == 'mu'):
                ptype = 'NuMu'
        if (n_type < 0):
            if (flav == 'e'):
                ptype = 'NuEBar'
            if (flav == 'mu'):
                ptype = 'NuMuBar'
        file_name = "/data/user/mamday/newSQuIDS/nuSQuIDS/resources/python/bindings/ZenWeights/Switch%s%.4fET%.3fEM.hd5" % (
            ptype, mutau, tautau)
        e_vals = []
        m_vals = []
        t_vals = []
        zen_val = round(2 * numpy.cos(zen), 2) / 2
        if (zen_val < -0.995):
            zen_val = -0.995
        if (zen_val == 0):
            zen_val = 0.005
        group_name = "%s%.4fET%.3fEM%.3f" % (ptype, mutau, tautau, zen_val)
        nuSQ = None
        if (flav == 'e'):
            if (not ((ptype, mutau, tautau, zen_val) in e_SQuIDS.keys())):
                e_SQuIDS[(ptype, mutau, tautau,
                          zen_val)] = nsq.nuSQUIDS(file_name, group_name)
            nuSQ = e_SQuIDS[(ptype, mutau, tautau, zen_val)]
        if (flav == 'mu'):
            if (not ((ptype, mutau, tautau, zen_val) in m_SQuIDS.keys())):
                m_SQuIDS[(ptype, mutau, tautau,
                          zen_val)] = nsq.nuSQUIDS(file_name, group_name)
            nuSQ = m_SQuIDS[(ptype, mutau, tautau, zen_val)]
        eWeight = nuSQ.EvalFlavor(0, ene * nuSQ.units.GeV, 0)
        mWeight = nuSQ.EvalFlavor(1, ene * nuSQ.units.GeV, 0)
        tWeight = nuSQ.EvalFlavor(2, ene * nuSQ.units.GeV, 0)
        return eWeight, mWeight, tWeight
Example #8
0
def NuFlux_Earth(proflux,Enu_min,Enu_max,nodes,ch,DMm,param,theta_12=33.82,theta_23=48.6,theta_13=8.60,delta_m_12=7.39e-5,delta_m_13=2.528e-3,delta=0.,logscale=False,interactions=True,location = 'Earth',time=57754.,angle=None,latitude=-90.,xsec=None):
	''' calculate neutrino flux after propagation for solar wimp (multiple energy mode with interactions)
	@type  proflux  :       str
	@param proflux  :       name of the production flux, e.g. Pythia 
	@type  Enu_min	:	float
	@param Enu_min	:	GeV	
	@type  Enu_max	:	float
	@param Enu_max	:	GeV	
	@type  nodes	:       int	
	@param nodes	:       number of nodes 	
	@type  ch	:       str	
	@param ch	:       channel of the production 	
	@type  DMm	:	float
	@param DMm	:	GeV
	@type  location :       str 
	@param location :       Sunsfc or Earth 
	@type  time     :       float
	@parm  time     :       MJD of the detection time (input can be either the angle or the time) 
	@type  angle    :       float
	@param  angle   :       Zenith angle of the detection in degree (input can be either the angle or the time) 
	@parm  time     :       MJD of the detection time
        @type  latitude :       float
        @param latitude :       latitude of the detector
	@type xsec      :       str
	@param xsec     :       path to neutrino xsec files.  
	@return 	:	flux per annihilation 
	'''
	#Oscillation parameters are from NuFIT 4.1 (2019) normal ordering with delta_cp=0. Adjust according to your need. 
	#default cross section is based on isoscalar target from arXiv: 1106.3723v2. I have also run nusigma which is a neutrino-nucleon cross section writen by J. Edsjo assuming isoscalar target. There files are in `./xsec/`. The choice of the cross sections makes difference.  
	#TODO: implement full MC
	
	#DM_annihilation_rate_Sun = float(np.sum(DM.DMSunAnnihilationRate(DMm*param.GeV,DMsig,param)))*param.sec
	DM_annihilation_rate_Sun = 1.
	E_nodes = nodes
	Enu_min = Enu_min*param.GeV
	Enu_max = Enu_max*param.GeV
	#e_range = np.linspace(Enu_min*pc.GeV,Enu_max*pc.GeV,100)
	if logscale is True:
		e_vector = np.logspace(np.log10(Enu_min),np.log10(Enu_max),E_nodes)
	else:
		e_vector = np.linspace(Enu_min,Enu_max,E_nodes)
	

	
	if proflux == 'Pythia':
	    production = pythiaflux
	elif proflux == 'Herwig':
            production = herwigflux
	elif proflux == 'WimpSim':
	    production = DMSweFluxEarth
   	else:	
            print('No Such Production')

	flux = {}
	if xsec == None:
		print(xsec)
		nuSQ = nsq.nuSQUIDS(e_vector,3,nsq.NeutrinoType.both,interactions)
	else:
		print(xsec)
		xsec = nsq.NeutrinoDISCrossSectionsFromTables(xsec+'nusigma_')
		nuSQ = nsq.nuSQUIDS(e_vector,3,nsq.NeutrinoType.both,interactions,xsec)
	energy = nuSQ.GetERange()
	for i in range(3):
		flux[str(i)+'_nu'] = np.array(map(lambda E_nu: production(E_nu/param.GeV,i*2,ch,DMm,wimp_loc='Earth'),energy))
		flux[str(i)+'_nubar'] = np.array(map(lambda E_nu: production(E_nu/param.GeV,i*2+1,ch,DMm,wimp_loc='Earth'),energy))
	nuSQ.Set_Body(nsq.Earth())
	nuSQ.Set_Track(nsq.Earth.Track(param.EARTHRADIUS*param.km))
	#nuSQ.Set_Track(nsq.ConstantDensity.Track(param.SUNRADIUS*param.km))
	nuSQ.Set_MixingAngle(0,1,np.deg2rad(theta_12))
	nuSQ.Set_MixingAngle(0,2,np.deg2rad(theta_13))
	nuSQ.Set_MixingAngle(1,2,np.deg2rad(theta_23))
	nuSQ.Set_SquareMassDifference(1,delta_m_12)
	nuSQ.Set_SquareMassDifference(2,delta_m_13)
	nuSQ.Set_abs_error(1.e-5)
	nuSQ.Set_rel_error(1.e-5)
	nuSQ.Set_CPPhase(0,2,delta)
	nuSQ.Set_ProgressBar(True)
	initial_flux = np.zeros((E_nodes,2,3))
	for j in range(len(flux['0_nu'])):
		for k in range(3):
			initial_flux[j][0][k] = flux[str(k)+'_nu'][j]
			initial_flux[j][1][k] = flux[str(k)+'_nubar'][j]
	nuSQ.Set_initial_state(initial_flux,nsq.Basis.flavor)
	nuSQ.Set_TauRegeneration(True)
	nuSQ.EvolveState()
	
	e_range = np.linspace(Enu_min,Enu_max,nodes)
	flux_surface = np.zeros(len(e_range),dtype = [('Energy','float'),('nu_e','float'),('nu_mu','float'),('nu_tau','float'),('nu_e_bar','float'),('nu_mu_bar','float'),('nu_tau_bar','float'),('zenith','float')]) 
	

	factor = 1. 
	flux_surface['Energy'] = e_range 
	flux_surface['nu_e'] = factor*np.array([nuSQ.EvalFlavor(0,e,0) for e in   e_range])
	flux_surface['nu_mu'] = factor*np.array([nuSQ.EvalFlavor(1,e,0) for e in  e_range])
	flux_surface['nu_tau'] = factor*np.array([nuSQ.EvalFlavor(2,e,0) for e in e_range])
	flux_surface['nu_e_bar'] = factor*np.array([nuSQ.EvalFlavor(0,e,1) for e in e_range])
	flux_surface['nu_mu_bar'] = factor*np.array([nuSQ.EvalFlavor(1,e,1) for e in e_range])
	flux_surface['nu_tau_bar'] = factor*np.array([nuSQ.EvalFlavor(2,e,1) for e in e_range])

	return flux_surface
Example #9
0
def NuFlux_GC(proflux,
              Enu_min,
              Enu_max,
              nodes,
              ch,
              DMm,
              param,
              theta_12=33.82,
              theta_23=48.6,
              theta_13=8.60,
              delta_m_12=7.39e-5,
              delta_m_13=2.528e-3,
              delta=0.,
              logscale=False,
              interactions=True,
              location='Detector',
              xsec=None,
              zenith=180.):

    if logscale is True:
        e_vector = np.logspace(np.log10(Enu_min), np.log10(Enu_max), nodes)
    else:
        e_vector = np.linspace(Enu_min, Enu_max, nodes)

    if proflux == 'Pythia':
        production = pythiaflux
    elif proflux == 'Herwig':
        production = herwigflux
    elif proflux == 'WimpSim':
        production = DMSweFluxEarth
    else:
        print 'No Such Production'

    flux = {}
    energy = nuSQ.GetERange()
    for i in range(3):
        flux[str(i) + '_nu'] = np.array(
            map(lambda E_nu: production(E_nu, i * 2, ch, DMm, wimp_loc='GC'),
                e_vector))
        flux[str(i) + '_nubar'] = np.array(
            map(
                lambda E_nu: production(
                    E_nu, i * 2 + 1, ch, DMm, wimp_loc='GC'), e_vector))

    osc_matrix = angles_to_u(theta_12, theta_13, theta_23, delta)
    flux_surface = np.zeros(len(e_vector),
                            dtype=[('Energy', 'float'), ('nu_e', 'float'),
                                   ('nu_mu', 'float'), ('nu_tau', 'float'),
                                   ('nu_e_bar', 'float'),
                                   ('nu_mu_bar', 'float'),
                                   ('nu_tau_bar', 'float')])

    flux_surface['Energy'] = e_vector
    composition_nu = np.array([
        u_to_fr([flux['0_nu'][j], flux['1_nu'][j], flux['2_nu'][j]],
                osc_matrix) for j in range(len(e_vector))
    ])
    composition_nubar = np.array([
        u_to_fr([flux['0_nubar'][j], flux['1_nubar'][j], flux['2_nubar'][j]],
                osc_matrix) for j in range(len(e_vector))
    ])

    flux_surface['nu_e'] = composition_nu[:, 0]
    flux_surface['nu_mu'] = composition_nu[:, 1]
    flux_surface['nu_tau'] = composition_nu[:, 2]
    flux_surface['nu_e_bar'] = composition_nubar[:, 0]
    flux_surface['nu_mu_bar'] = composition_nubar[:, 1]
    flux_surface['nu_tau_bar'] = composition_nubar[:, 2]
    if location == 'EarthSurface':
        return flux_surface

    elif location == 'Detector':
        e_vector = e_vector * param.GeV
        if xsec == None:
            xsec = nsq.NeutrinoDISCrossSectionsFromTables('../xsec/nusigma_')
            nuSQ = nsq.nuSQUIDS(e_vector, 3, nsq.NeutrinoType.both,
                                interactions, xsec)
        else:
            xsec = nsq.NeutrinoDISCrossSectionsFromTables(xsec)
            nuSQ = nsq.nuSQUIDS(e_vector, 3, nsq.NeutrinoType.both,
                                interactions, xsec)

        nuSQ.Set_Body(nsq.Earth())
        nuSQ.Set_Track(
            nsq.Earth.Track(2 * abs(np.cos(np.deg2rad(zenith))) *
                            param.EARTHRADIUS * param.km))
        nuSQ.Set_MixingAngle(0, 1, np.deg2rad(theta_12))
        nuSQ.Set_MixingAngle(0, 2, np.deg2rad(theta_13))
        nuSQ.Set_MixingAngle(1, 2, np.deg2rad(theta_23))
        nuSQ.Set_SquareMassDifference(1, delta_m_12)
        nuSQ.Set_SquareMassDifference(2, delta_m_13)
        nuSQ.Set_abs_error(1.e-5)
        nuSQ.Set_rel_error(1.e-5)
        nuSQ.Set_CPPhase(0, 2, delta)
        nuSQ.Set_ProgressBar(True)
        initial_flux = np.zeros((nodes, 2, 3))
        for i in range(3):
            initial_flux[:, 0, i] = composition_nu[:, i]
            initial_flux[:, 1, i] = composition_nubar[:, i]
        #composition =np.array([[[composition_nu[i,0],composition_nu[i,1],composition_nu[i,2]],[composition_nubar[i,0],composition_nubar[i,1],composition_nubar[i,2]]] for i in range(len(composition_nu))])
        nuSQ.Set_initial_state(initial_flux, nsq.Basis.flavor)
        nuSQ.Set_TauRegeneration(True)
        nuSQ.EvolveState()
        flux_surface = np.zeros(len(e_vector),
                                dtype=[('Energy', 'float'), ('nu_e', 'float'),
                                       ('nu_mu', 'float'), ('nu_tau', 'float'),
                                       ('nu_e_bar', 'float'),
                                       ('nu_mu_bar', 'float'),
                                       ('nu_tau_bar', 'float'),
                                       ('zenith', 'float')])
        energy = nuSQ.GetERange()
        print energy
        flux_surface['Energy'] = energy / param.GeV
        flux_surface['nu_e'] = np.array(
            [nuSQ.EvalFlavor(0, e, 0) for e in energy])
        flux_surface['nu_mu'] = np.array(
            [nuSQ.EvalFlavor(1, e, 0) for e in energy])
        flux_surface['nu_tau'] = np.array(
            [nuSQ.EvalFlavor(2, e, 0) for e in energy])
        flux_surface['nu_e_bar'] = np.array(
            [nuSQ.EvalFlavor(0, e, 1) for e in energy])
        flux_surface['nu_mu_bar'] = np.array(
            [nuSQ.EvalFlavor(1, e, 1) for e in energy])
        flux_surface['nu_tau_bar'] = np.array(
            [nuSQ.EvalFlavor(2, e, 1) for e in energy])
        flux_surface['zenith'] = np.array([zenith] * len(e_vector))

        return flux_surface
Example #10
0
def NuFlux_Solar(proflux,
                 Enu_min,
                 Enu_max,
                 nodes,
                 ch,
                 DMm,
                 param,
                 theta_12=33.82,
                 theta_23=48.6,
                 theta_13=8.60,
                 delta_m_12=7.39e-5,
                 delta_m_13=2.528e-3,
                 delta=0.,
                 logscale=False,
                 interactions=True,
                 location='detector',
                 time=57754.,
                 angle=None,
                 latitude=-90.,
                 xsec=None):
    ''' calculate neutrino flux after propagation for solar wimp (multiple energy mode with interactions)
	@type  proflux  :       str
	@param proflux  :       name of the production flux, e.g. Pythia 
	@type  Enu_min	:	float
	@param Enu_min	:	GeV	
	@type  Enu_max	:	float
	@param Enu_max	:	GeV	
	@type  nodes	:       int	
	@param nodes	:       number of nodes 	
	@type  ch	:       str	
	@param ch	:       channel of the production 	
	@type  DMm	:	float
	@param DMm	:	GeV
	@type  location :       str 
	@param location :       Sunsfc or detector 
	@type  time     :       float
	@parm  time     :       MJD of the detection time (input can be either the angle or the time) 
	@type  angle    :       float
	@param  angle   :       Zenith angle of the detection in degree (input can be either the angle or the time) 
	@parm  time     :       MJD of the detection time
        @type  latitude :       float
        @param latitude :       latitude of the detector
	@type xsec      :       str
	@param xsec     :       path to neutrino xsec files.  
	@return 	:	flux per annihilation 
	'''
    #Oscillation parameters are from NuFIT 4.1 (2019) normal ordering with delta_cp=0. Adjust according to your need.
    #default cross section is based on isoscalar target from arXiv: 1106.3723v2. I have also run nusigma which is a neutrino-nucleon cross section writen by J. Edsjo assuming isoscalar target. There files are in `./xsec/`. The choice of the cross sections makes difference.
    #TODO: implement full MC

    #DM_annihilation_rate_Sun = float(np.sum(DM.DMSunAnnihilationRate(DMm*param.GeV,DMsig,param)))*param.sec
    DM_annihilation_rate_Sun = 1.
    Enu_min = Enu_min * param.GeV
    Enu_max = Enu_max * param.GeV
    #e_range = np.linspace(Enu_min*pc.GeV,Enu_max*pc.GeV,100)
    if logscale is True:
        e_vector = np.logspace(np.log10(Enu_min), np.log10(Enu_max), nodes)
        print(e_vector[:100] / 1.e9)
        print(nodes)
    else:
        e_vector = np.linspace(Enu_min, Enu_max, nodes)

    if proflux == 'Pythia':
        production = pythiaflux
    elif proflux == 'Herwig':
        production = herwigflux
    elif proflux == 'WimpSim':
        production = DMSweFluxSun
    else:
        print "No Such Production."
        quit()

    flux = {}
    if xsec == None:
        xsec = nsq.NeutrinoDISCrossSectionsFromTables(
            '/data/user/qliu/DM/GOLEMTools/sources/nuSQuIDS/data/xsections/nusigma_'
        )
        nuSQ = nsq.nuSQUIDS(e_vector, 3, nsq.NeutrinoType.both, interactions,
                            xsec)
    else:
        xsec = nsq.NeutrinoDISCrossSectionsFromTables(
            "/data/user/qliu/DM/GOLEMTools/sources/nuSQuIDS/data/xsections/nusigma_"
        )
        nuSQ = nsq.nuSQUIDS(e_vector, 3, nsq.NeutrinoType.both, interactions,
                            xsec)
    energy = nuSQ.GetERange()
    for i in range(3):
        flux[str(i) + '_nu'] = np.array(
            map(
                lambda E_nu: production(
                    E_nu / param.GeV, i * 2, ch, DMm, wimp_loc='Sun'), energy))
        flux[str(i) + '_nubar'] = np.array(
            map(
                lambda E_nu: production(
                    E_nu / param.GeV, i * 2 + 1, ch, DMm, wimp_loc='Sun'),
                energy))
    nuSQ.Set_Body(nsq.Sun())
    nuSQ.Set_Track(nsq.Sun.Track(0., param.SUNRADIUS * param.km))
    nuSQ.Set_MixingAngle(0, 1, np.deg2rad(theta_12))
    nuSQ.Set_MixingAngle(0, 2, np.deg2rad(theta_13))
    nuSQ.Set_MixingAngle(1, 2, np.deg2rad(theta_23))
    nuSQ.Set_SquareMassDifference(1, delta_m_12)
    nuSQ.Set_SquareMassDifference(2, delta_m_13)
    nuSQ.Set_abs_error(1.e-5)
    nuSQ.Set_rel_error(1.e-5)
    nuSQ.Set_CPPhase(0, 2, delta)
    nuSQ.Set_ProgressBar(True)
    initial_flux = np.zeros((nodes, 2, 3))
    for j in range(len(flux['0_nu'])):
        for k in range(3):
            initial_flux[j][0][k] = flux[str(k) + '_nu'][j]
            initial_flux[j][1][k] = flux[str(k) + '_nubar'][j]
    nuSQ.Set_initial_state(initial_flux, nsq.Basis.flavor)
    nuSQ.Set_TauRegeneration(True)
    nuSQ.EvolveState()

    #e_range = np.linspace(Enu_min,Enu_max,nodes)
    flux_surface = np.zeros(len(energy),
                            dtype=[('Energy', 'float'), ('nu_e', 'float'),
                                   ('nu_mu', 'float'), ('nu_tau', 'float'),
                                   ('nu_e_bar', 'float'),
                                   ('nu_mu_bar', 'float'),
                                   ('nu_tau_bar', 'float'),
                                   ('zenith', 'float')])

    if location == 'Sunsfc':
        #factor = DM_annihilation_rate_Sun/(4.0*PI*(param.SUNRADIUS*param.km/param.cm)**2*DMm)
        flux_surface['Energy'] = energy / param.GeV
        flux_surface['nu_e'] = np.array(
            [nuSQ.EvalFlavor(0, e, 0) for e in energy])
        flux_surface['nu_mu'] = np.array(
            [nuSQ.EvalFlavor(1, e, 0) for e in energy])
        flux_surface['nu_tau'] = np.array(
            [nuSQ.EvalFlavor(2, e, 0) for e in energy])
        flux_surface['nu_e_bar'] = np.array(
            [nuSQ.EvalFlavor(0, e, 1) for e in energy])
        flux_surface['nu_mu_bar'] = np.array(
            [nuSQ.EvalFlavor(1, e, 1) for e in energy])
        flux_surface['nu_tau_bar'] = np.array(
            [nuSQ.EvalFlavor(2, e, 1) for e in energy])

        return flux_surface

    elif location == 'detector':
        flux_earth = flux_surface
        if angle == None:
            zenith = SunZenith(time, latitude)
        else:
            zenith = np.deg2rad(angle)
        d_tot, d_vacuum, d_earthatm = Distance(zenith, param)

        composition_new = np.zeros((len(e_vector), 2, 3))
        for i in range(3):
            for j in range(2):
                composition_new[:, j, i] = np.array(
                    [nuSQ.EvalFlavor(i, e, j) for e in energy])
        #composition_new =np.array([[[nuSQ.EvalFlavor(0,e,0),nuSQ.EvalFlavor(1,e,0),nuSQ.EvalFlavor(2,e,0)],[nuSQ.EvalFlavor(0,e,1),nuSQ.EvalFlavor(1,e,1),nuSQ.EvalFlavor(2,e,1)]] for e in e_vector])
    #print composition_new

        nuSQ.Set_Body(nsq.Vacuum())

        nuSQ.Set_Track(nsq.Vacuum.Track(float(d_vacuum) * param.km))
        nuSQ.Set_ProgressBar(True)

        nuSQ.Set_initial_state(composition_new, nsq.Basis.flavor)
        nuSQ.Set_TauRegeneration(True)
        nuSQ.EvolveState()
        composition_new = np.zeros((len(e_vector), 2, 3))
        for i in range(3):
            for j in range(2):
                composition_new[:, j, i] = np.array(
                    [nuSQ.EvalFlavor(i, e, j) for e in energy])

        #composition_new =np.array([[[nuSQ.EvalFlavor(0,e,0),nuSQ.EvalFlavor(1,e,0),nuSQ.EvalFlavor(2,e,0)],[nuSQ.EvalFlavor(0,e,1),nuSQ.EvalFlavor(1,e,1),nuSQ.EvalFlavor(2,e,1)]] for e in e_vector])

        nuSQ.Set_Body(nsq.EarthAtm())
        nuSQ.Set_Track(nsq.EarthAtm.Track(zenith))
        nuSQ.Set_ProgressBar(True)

        nuSQ.Set_initial_state(composition_new, nsq.Basis.flavor)
        nuSQ.Set_TauRegeneration(True)
        nuSQ.EvolveState()
        flux_earth['Energy'] = energy / param.GeV
        flux_earth['nu_e'] = np.array(
            [nuSQ.EvalFlavor(0, e, 0) for e in energy])
        flux_earth['nu_mu'] = np.array(
            [nuSQ.EvalFlavor(1, e, 0) for e in energy])
        flux_earth['nu_tau'] = np.array(
            [nuSQ.EvalFlavor(2, e, 0) for e in energy])
        flux_earth['nu_e_bar'] = np.array(
            [nuSQ.EvalFlavor(0, e, 1) for e in energy])
        flux_earth['nu_mu_bar'] = np.array(
            [nuSQ.EvalFlavor(1, e, 1) for e in energy])
        flux_earth['nu_tau_bar'] = np.array(
            [nuSQ.EvalFlavor(2, e, 1) for e in energy])
        flux_earth['zenith'] = np.array([zenith] * len(e_vector))

        return flux_earth
Example #11
0
def propagate(
    iniflux,
    Ein,
    Eout,
    location_ini,
    location_end,
    theta_12=33.82,
    theta_23=48.6,
    theta_13=8.60,
    delta_m_12=7.39e-5,
    delta_m_13=2.528e-3,
    delta=0.0,
    interactions=True,
    xsec=None,
    secluded=False,
    r=0.0,
    mass_v=0.0,
    zenith=0.0,
    avg=True,
    pathSunModel=None,
    pathEarthModel=None,
):
    r"""propagate neutrino flux

    Parameters
    ----------
    iniflux         :  array
                       initial flux for propagation
    Ein             :  array
                       energies of the initial flux
    Eout            :  array
                       energies of the output flux
    location_ini    :  str
                       location of neutrino production
    location_end    :  str
                       location that the flux propagates to
    pathSunModel    :  str
                       path to the Sun profile
    pathEarthModel  :  str
                       path to the Earth profile
    theta_12        :  float
                       theta_12 in degree
    theta_23        :  float
                       theta_23 in degree
    theta_13        :  float
                       theta_13 in degree
    delta_m_12      :  float
                       delta_m_12 square in eV^2
    delta_m_13      :  float
                       delta_m_13 square in eV^2
    delta           :  float
                       cp phase in degree
    interactions    :  bool
                       whether to included interactions between nodes
    xsec            :  str
                       Use default cross sections if None. Or can use external table of cross section with names    `n(p)_sigma_CC(NC).dat`,`n(p)_dsde_CC(NC).dat`.
    secluded        :  bool
                       standard or secluded
    r               :  float or list
                       if secluded, the distance picked
    mass_v          :   float
                        mediator_mass in GeV
    zenith          :  float
                       zenith angle in radian
    avg             :  bool
                       whether to average out flux
    Returns
    -------
    flux     :  array
                averaged flux of a specific flavor.
    """

    flavor_list = {
        0: "nu_e",
        1: "nu_e_bar",
        2: "nu_mu",
        3: "nu_mu_bar",
        4: "nu_tau",
        5: "nu_tau_bar",
    }
    if xsec == None:
        xsec = nsq.NeutrinoDISCrossSectionsFromTables(dirpath + "/xsec/nusigma_")
        nuSQ = nsq.nuSQUIDS(Ein * pc.GeV, 3, nsq.NeutrinoType.both, interactions, xsec)
    else:
        xsec = nsq.NeutrinoDISCrossSectionsFromTables(xsec)
        nuSQ = nsq.nuSQUIDS(Ein * pc.GeV, 3, nsq.NeutrinoType.both, interactions, xsec)

    nuSQ.Set_MixingAngle(0, 1, np.deg2rad(theta_12))
    nuSQ.Set_MixingAngle(0, 2, np.deg2rad(theta_13))
    nuSQ.Set_MixingAngle(1, 2, np.deg2rad(theta_23))
    nuSQ.Set_SquareMassDifference(1, delta_m_12)
    nuSQ.Set_SquareMassDifference(2, delta_m_13)
    nuSQ.Set_abs_error(1.0e-10)
    nuSQ.Set_rel_error(1.0e-10)
    nuSQ.Set_CPPhase(0, 2, np.deg2rad(delta))
    nuSQ.Set_ProgressBar(True)
    nuSQ.Set_TauRegeneration(True)
    flux_output = np.zeros(
        len(Eout),
        dtype=[
            ("Energy", "float"),
            ("nu_e", "float"),
            ("nu_mu", "float"),
            ("nu_tau", "float"),
            ("nu_e_bar", "float"),
            ("nu_mu_bar", "float"),
            ("nu_tau_bar", "float"),
            ("zenith", "float"),
        ],
    )
    # Standard case
    if not secluded:
        # from Sun
        if location_ini == "Sun":
            if pathSunModel == None:
                nuSQ.Set_Body(nsq.Sun(dirpath + "/models/struct_b16_agss09.dat"))
            else:
                nuSQ.Set_Body(nsq.Sun(pathSunModel))
            nuSQ.Set_Track(nsq.Sun.Track(0.0, pc.SUNRADIUS * pc.km))
            nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
            nuSQ.EvolveState()

            # flux at sun surface
            if location_end == "SunSurface":
                zenith = None

            # flux at 1AU
            elif location_end == "1AU":
                nuSQ.Set_Body(nsq.Vacuum())
                nuSQ.Set_Track(nsq.Vacuum.Track(pc.AU - pc.SUNRADIUS * pc.km))
                nuSQ.EvolveState()

            # flux at detector
            elif location_end == "detector":
                nuSQ.Set_Body(nsq.Vacuum())
                d_vacuum = float(Distance(zenith)[1])
                nuSQ.Set_Track(nsq.Vacuum.Track(d_vacuum * pc.km))
                nuSQ.EvolveState()
                if pathEarthModel == None:
                    nuSQ.Set_Body(nsq.EarthAtm())
                else:
                    nuSQ.Set_Body(nsq.EarthAtm(pathEarthModel))
                nuSQ.Set_Track(nsq.EarthAtm.Track(zenith))
                nuSQ.EvolveState()

        # from Earth
        elif location_ini == "Earth":

            # flux at detector
            if location_end == "detector":
                if pathEarthModel == None:
                    nuSQ.Set_Body(nsq.Earth())
                else:
                    nuSQ.Set_Body(nsq.Earth(pathEarthModel))
                # nuSQ.Set_Body(nsq.Earth())
                nuSQ.Set_Track(
                    nsq.Earth.Track(
                        pc.EARTHRADIUS * pc.km,
                        2 * pc.EARTHRADIUS * pc.km,
                        2 * pc.EARTHRADIUS * pc.km,
                    )
                )
                nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
                nuSQ.EvolveState()

        # from Halo
        elif location_ini == "Halo":

            osc_matrix = angles_to_u(theta_12, theta_13, theta_23, delta)
            composition_nu = np.array(
                [
                    u_to_fr(
                        [iniflux[j, 0, 0], iniflux[j, 0, 1], iniflux[j, 0, 2]],
                        osc_matrix,
                    )
                    for j in range(len(Ein))
                ]
            )
            composition_nubar = np.array(
                [
                    u_to_fr(
                        [iniflux[j, 1, 0], iniflux[j, 1, 1], iniflux[j, 1, 2]],
                        osc_matrix,
                    )
                    for j in range(len(Ein))
                ]
            )

            # flux at Earth surface before entering matter
            if location_end == "Earth" or zenith <= np.pi / 2.0:
                for i in range(3):
                    inter_nu = interp1d(Ein, composition_nu[:, i])
                    inter_nubar = interp1d(Ein, composition_nubar[:, i])
                    flux_output[flavor_list[2 * i]] = inter_nu(Eout)
                    flux_output[flavor_list[2 * i + 1]] = inter_nubar(Eout)

                flux_output["Energy"] = Eout
                flux_output["zenith"] = np.array([zenith] * len(Eout))
                return flux_output

            # flux at detector
            elif location_end == "detector":
                if pathEarthModel == None:
                    nuSQ.Set_Body(nsq.Earth())
                else:
                    nuSQ.Set_Body(nsq.Earth(pathEarthModel))
                # nuSQ.Set_Body(nsq.Earth())
                nuSQ.Set_Track(
                    nsq.Earth.Track(2 * abs(np.cos(zenith)) * pc.EARTHRADIUS * pc.km)
                )
                surface_flux = np.zeros((len(composition_nu), 2, 3))
                for i in range(3):
                    surface_flux[:, 0, i] = composition_nu[:, i]
                    surface_flux[:, 1, i] = composition_nubar[:, i]
                nuSQ.Set_initial_state(surface_flux, nsq.Basis.flavor)
                nuSQ.EvolveState()

    # Secluded case
    elif secluded:

        theta = 0.0
        # from Sun
        if location_ini == "Sun":
            b_impact = np.sin(theta) * r
            if r < pc.SUNRADIUS:
                if theta <= np.pi / 2.0:
                    xini = xini_Sun(b_impact, r, zenith)[0][1]
                else:
                    xini = xini_Sun(b_impact, r, zenith)[0][0]

                if b_impact != 0:
                    l = 2 * np.sqrt(pc.SUNRADIUS ** 2 - b_impact ** 2)
                    if pathSunModel == None:
                        nuSQ.Set_Body(
                            nsq.SunASnu(dirpath + "/models/struct_b16_agss09.dat")
                        )
                    else:
                        nuSQ.Set_Body(nsq.SunASnu(pathSunModel))
                    nuSQ.Set_Track(
                        nsq.SunASnu.Track(l * pc.km, xini * pc.km, b_impact * pc.km)
                    )

                elif b_impact == 0:
                    if pathSunModel == None:
                        nuSQ.Set_Body(
                            nsq.Sun(dirpath + "/models/struct_b16_agss09.dat")
                        )
                    else:
                        nuSQ.Set_Body(nsq.Sun(pathSunModel))
                    nuSQ.Set_Track(nsq.Sun.Track(xini * pc.km, pc.SUNRADIUS * pc.km))

                nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
                nuSQ.EvolveState()

            # flux at sun surface
            if location_end == "SunSurface":
                pass

            # flux at 1AU
            elif location_end == "1AU":
                if r < pc.SUNRADIUS:
                    nuSQ.Set_Body(nsq.Vacuum())
                    nuSQ.Set_Track(nsq.Vacuum.Track(pc.AU - pc.SUNRADIUS * pc.km))
                elif r >= pc.SUNRADIUS and r < pc.AU / pc.km - pc.EARTHRADIUS:
                    nuSQ.Set_Body(nsq.Vacuum())
                    nuSQ.Set_Track(nsq.Vacuum.Track(pc.AU - r * pc.km))
                    nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
                nuSQ.EvolveState()

            # flux at detector
            elif location_end == "detector":
                nuSQ.Set_Body(nsq.Vacuum())
                if r < pc.SUNRADIUS:
                    nuSQ.Set_Track(
                        nsq.Vacuum.Track(xini_Sun(b_impact, r, zenith)[1] * pc.km)
                    )
                elif r >= pc.SUNRADIUS and r < pc.AU / pc.km - pc.EARTHRADIUS:
                    nuSQ.Set_Track(
                        nsq.Vacuum.Track(xini_Sun(b_impact, r, zenith)[0][1] * pc.km)
                    )
                    nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
                nuSQ.EvolveState()
                if pathEarthModel == None:
                    nuSQ.Set_Body(nsq.EarthAtm())
                else:
                    nuSQ.Set_Body(nsq.EarthAtm(pathEarthModel))
                nuSQ.Set_Track(nsq.EarthAtm.Track(zenith))
                nuSQ.EvolveState()

        # from the Earth
        elif location_ini == "Earth" and location_end == "detector":
            xini = xini_Earth(np.pi, r)[0][1]
            if pathEarthModel == None:
                nuSQ.Set_Body(nsq.Earth())
            else:
                nuSQ.Set_Body(nsq.Earth(pathEarthModel))
            nuSQ.Set_Track(
                nsq.Earth.Track(
                    xini * pc.km, 2 * pc.EARTHRADIUS * pc.km, 2 * pc.EARTHRADIUS * pc.km
                )
            )
            nuSQ.Set_initial_state(iniflux, nsq.Basis.flavor)
            nuSQ.EvolveState()

    flux_output["Energy"] = Eout
    flux_output["zenith"] = np.array([zenith] * len(Eout))
    Eout = Eout * pc.GeV
    if avg:
        flux_output["nu_e"] = average(nuSQ, Eout, [0, 0])
        flux_output["nu_mu"] = average(nuSQ, Eout, [1, 0])
        flux_output["nu_tau"] = average(nuSQ, Eout, [2, 0])
        flux_output["nu_e_bar"] = average(nuSQ, Eout, [0, 1])
        flux_output["nu_mu_bar"] = average(nuSQ, Eout, [1, 1])
        flux_output["nu_tau_bar"] = average(nuSQ, Eout, [2, 1])
    else:
        flux_output["nu_e"] = np.array([nuSQ.EvalFlavor(0, e, 0) for e in Eout])
        flux_output["nu_mu"] = np.array([nuSQ.EvalFlavor(1, e, 0) for e in Eout])
        flux_output["nu_tau"] = np.array([nuSQ.EvalFlavor(2, e, 0) for e in Eout])
        flux_output["nu_e_bar"] = np.array([nuSQ.EvalFlavor(0, e, 1) for e in Eout])
        flux_output["nu_mu_bar"] = np.array([nuSQ.EvalFlavor(1, e, 1) for e in Eout])
        flux_output["nu_tau_bar"] = np.array([nuSQ.EvalFlavor(2, e, 1) for e in Eout])

    return flux_output