예제 #1
0
def fdelx(
    vpara, v, vi, B, e, Egg
):  # time the electron moves (De/v), angular vel (v/R), speed of el (v,vi) , mag field B, charge e (+/- 1)
    # w2,tau2=w,tau
    if gv.STODE == 1:
        w2 = gv.drawMFPe(Egg, gv.zE(gv.dS)) / v
    else:
        w2 = gv.De(gv.zE(gv.dS), gv.Ee(Egg, gv.zE(gv.dS))) / v
    tau2 = v * 1.0 / gv.R(gv.Ee(Egg, gv.zE(gv.dS)), gv.B0, gv.zE(gv.dS))
    return v * (vpara * (tau2 - np.sin(w2 * tau2) / w2) * B +
                vi * np.sin(w2 * tau2) / w2 + e *
                (np.cos(w2 * tau2) - 1.0) * np.cross(B, vi) / w2)
예제 #2
0
def drawens(N):
    countphoton = 0
    draw = []
    while countphoton < N:
        EggT = gv.drawEnergy()
        Eelini = gv.Ee(EggT, gv.zE(gv.dS)) / 1000.0  # Ee initial in TeV
        while EggT < gv.Emin or Eelini * 2 > gv.Esourcecutoff:
            EggT = gv.drawEnergy()
            Eelini = gv.Ee(EggT, gv.zE(gv.dS)) / 1000.0  # Ee initial in TeV
            # print(Egg,np.sqrt(Egg/77.0)*10)
        dg = gv.drawMFPg(EggT, gv.zE(gv.dS))
        Egg = EggT
        tau0 = 0
        if gv.STODE == 1:
            ind = len(edists[edists < Eelini]) - 1
            tau0, Egg = pd.drawLeptonICevent(dist[ind], pdf_E[ind])
            if tau0 == 0:
                print(edists[ind], Egg, pdf_E[ind], "kek", countphoton, ind)
        draw.append([Eelini, Egg, tau0, dg])
        countphoton += 1
    return np.array(draw)
예제 #3
0
 def F(angles):
     x, y, z = getxyzB(dg, dE, angles)
     fB = B(x, y, z)
     bnorm = np.sqrt(fB[0] * fB[0] + fB[1] * fB[1] + fB[2] * fB[2] + 1e-20)
     if RnB:
         w = bnorm / (RnB * 1e-14)
     else:
         w = 1.0 / gv.R(gv.Ee(Egg, gv.zE(gv.dS)), bnorm, gv.zE(gv.dS))
     wtau = w * tau
     cons1 = fLoS(angles[0], angles[2], dg, dE)
     cons2 = fvcBdphi(
         fBz(fB, angles[0], angles[1]),
         fBrho(fB, angles[0], angles[1]),
         angles[2],
         angles[0],
     )
     cons3 = fdeltaEqn(angles[2],
                       fvpara(fB / bnorm, angles[0], angles[1], angles[2]),
                       Egg, wtau)
     return (cons1, cons2, cons3)
예제 #4
0
import time, sys, os
import numpy as np

if not sys.version_info[0] < 3:
    from importlib import reload
import globalvars as gv

import matplotlib.pyplot as plt


def Eg(E, z=0.24):
    # return 77.0*4*E*E/100.0*1.24/(1+z)
    return E * E / (gv.me * gv.me) * 1e6 * gv.ECMB(z) * 4.0 / 3.0


Ecutoff = gv.Ee(gv.Emin, gv.zE(gv.dS)) / 1000
Eemax = (gv.Esourcecutoff + 0.5) / 2.0
Eini = 5
Nsim = 10000
nbins = 100

fourpialphasquare = 4 * np.pi / (137.036**2)
ncmb = 3.71 * 10**8
mtokpc = 3.24e-20
TeVtokpc = 8.065e17 / mtokpc
meTeV = 0.511e-6
n0 = 3.71e8 / (mtokpc**3)

NUMde = TeVtokpc**2 / (n0 * fourpialphasquare)

예제 #5
0
def SimEvent(ds, NumPhotons, cn=1, rmf_switch=False, B0=gv.B0):
    if rmf_switch:
        kmode = 0.05
        Nmodes = 10
        helicity = 0
        np.save("Btest", rmf.createB_one_K(kmode, Nmodes, hel=helicity))
        rmf.setB = np.load("Btest.npy")
        co.B = rmf.Banalytic
    countphoton = 0
    tol = 1e-12
    events = []
    evsangle = []
    tG, pG, deltaG = gv.tG, gv.pG, gv.deltaG
    while countphoton < NumPhotons:
        EggT = gv.drawEnergy()
        SignTheta = 0  # determining if the solution has theta positive or negative.
        tG, pG, deltaG = -gv.tG, gv.pG, -gv.deltaG
        # while(Egg<gv.Emin or Egg>gv.Emax):
        Eelini = gv.Ee(EggT, gv.zE(ds)) / 1000.0  # Ee initial in TeV
        while EggT < gv.Emin or Eelini * 2 > gv.Esourcecutoff:
            EggT = gv.drawEnergy()
            Eelini = gv.Ee(EggT, gv.zE(ds)) / 1000.0  # Ee initial in TeV
            # print(Egg,np.sqrt(Egg/77.0)*10)

        dg = gv.drawMFPg(EggT, gv.zE(ds))

        if gv.STODE == 1:
            ind = len(edists[edists < Eelini]) - 1
            tau0, Egg = pd.drawLeptonICevent(dist[ind], pdf_E[ind])
            # tau0=gv.drawMFPe(Egg,0.24)/10
            # if(ind!=len(edists)-1):
            # print(ind,Eelini,gv.Emin,EggT)
            # tau0,Egg=pd.dlice(dist[ind],pdf_E[ind],dist[ind+1],pdf_E[ind+1],Eelini,edists[ind],edists[ind+1])
            if len(RnoB[ind][RnoB[ind][:, 1] < Egg]) > 0:
                avgR = RnoB[ind][RnoB[ind][:, 1] < Egg][0, 0]
            else:
                avgR = RnoB[ind][-1, 0]
        else:
            Egg = EggT
            tau0 = gv.De(gv.zE(ds), gv.Ee(Egg, gv.zE(ds)))
            avgR = 0

        if np.random.uniform() > 0.5:
            SignTheta = 1
            tG, pG, deltaG = gv.tG, gv.pG, gv.deltaG
        # start=time.clock()
        sol, ier, charge = co.fsolvecsq(
            dg, ds, Egg, tG, pG, deltaG, SignTheta, xtol=tol, tau=tau0, RnB=avgR
        )
        # print(time.clock()-start)
        if (
            ier == 1 and np.absolute(sol[0]) < np.pi / 2.0
        ):  # ier=1 if a solution is found by fsolvecsq
            solcart = [
                dg * np.sin(sol[2] - sol[0]) * np.cos(sol[1]),
                dg * np.sin(sol[2] - sol[0]) * np.sin(sol[1]),
                -dg * np.cos(sol[2] - sol[0]),
            ]
            soleves = [sol[2] - sol[0], sol[1], Egg, sol[0]]
            events.append(solcart)
            evsangle.append(soleves)
            countphoton = countphoton + 1

    path = "sim_data/3devents/case" + str(cn) + "/"
    if not os.path.exists(path):
        os.makedirs(path)
    else:
        shutil.rmtree(path)
        os.makedirs(path)
    np.savetxt("sim_data/3devents/case" + str(cn) + "/3devents", events)
    np.savetxt("sim_data/3devents/case" + str(cn) + "/3deventsangle", evsangle)

    return events, evsangle
예제 #6
0
def drawE1():
    draw = dmax * 2
    while draw > dmax:
        draw = 2 * gv.Ee(gv.drawEnergy(), 0.24)
    return draw
예제 #7
0
import stochMorp as sM
import time, sys, os
import numpy as np
import EvSim as es
import UserInput as UI
import matplotlib.pyplot as plt

if not sys.version_info[0] < 3:
    from importlib import reload
import globalvars as gv

reload(UI)

EminTEV = 2 * gv.Ee(UI.Emin, 0.24)
from scipy.stats import pareto

dmax = 20000


def drawE2():
    a = 1.5
    draw = dmax * 2
    while draw > dmax:
        draw = pareto(a).rvs() * EminTEV
    return draw


def drawE3():
    a = 3
    draw = dmax * 2
    while draw > dmax:
예제 #8
0
def stomorp(ds,
            NumPhotons,
            alpha=0,
            phi=0,
            omega=np.pi,
            LeptonId=False,
            xtol=1e-10):
    B0 = gv.B0
    if LeptonId:
        gv.chargeanalyze = 1
    countphoton = 0
    events = []
    tcospsol = []
    tsinpsol = []
    tG, pG, deltaG = gv.tG, gv.pG, gv.deltaG
    solcount = 0
    while countphoton < NumPhotons:
        EggT = gv.drawEnergy()
        SignTheta = 0  # determining if the solution has theta positive or negative.
        tG, pG, deltaG = -gv.tG, gv.pG, -gv.deltaG
        # while(Egg<gv.Emin or Egg>gv.Emax):
        Eelini = gv.Ee(EggT, gv.zE(ds)) / 1000.0  # Ee initial in TeV
        while EggT < gv.Emin or Eelini * 2 > gv.Esourcecutoff:
            EggT = gv.drawEnergy()
            Eelini = gv.Ee(EggT, gv.zE(ds)) / 1000.0  # Ee initial in TeV
            # print(Egg,np.sqrt(Egg/77.0)*10)

        dg = gv.drawMFPg(EggT, gv.zE(ds))
        if gv.STODE == 1:
            ind = len(edists[edists < Eelini]) - 1
            tau0, Egg = pd.drawLeptonICevent(dist[ind], pdf_E[ind])
            # tau0=gv.drawMFPe(Egg,0.24)/10
            # if(ind!=len(edists)-1):
            # print(ind,Eelini,gv.Emin,EggT)
            # tau0,Egg=pd.dlice(dist[ind],pdf_E[ind],dist[ind+1],pdf_E[ind+1],Eelini,edists[ind],edists[ind+1])
            if len(RnoB[ind][RnoB[ind][:, 1] < Egg]) > 0:
                avgR = RnoB[ind][RnoB[ind][:, 1] < Egg][0, 0]
            else:
                avgR = RnoB[ind][-1, 0]
        else:
            Egg = EggT
            tau0 = gv.De(gv.zE(ds), gv.Ee(Egg, gv.zE(ds)))

        if np.random.uniform() > 0.5:
            SignTheta = 1
            tG, pG, deltaG = gv.tG, gv.pG, gv.deltaG
        # start=time.clock()
        sol, ier, charge = co.fsolvecsq(dg,
                                        ds,
                                        Egg,
                                        tG,
                                        pG,
                                        deltaG,
                                        SignTheta,
                                        xtol=tol,
                                        tau=tau0,
                                        RnB=avgR)
        # print(time.clock()-start)
        # if(ier!=1): print(solcount,countphoton)
        solcount = solcount + 1

        injet = True
        photonangle = sol[2] - sol[0]
        cosang = np.absolute(
            gv.angledotprod([photonangle, sol[1]], [alpha, phi]))
        if (gv.jetactivated == 1 and np.cos(omega) > cosang
            ):  # the second checks that the solution is part of the jet
            injet = False
            countphoton = countphoton + 1
        if (ier == 1 and np.absolute(sol[0]) < np.pi / 2.0
                and injet):  # ier=1 if a solution is found by fsolvecsq
            events.append([sol[0], sol[1]] + [Egg, charge])
            tcospsol.append(sol[0] * 1.0 / gv.degrad * np.cos(sol[1]))
            tsinpsol.append(sol[0] * 1.0 / gv.degrad * np.sin(sol[1]))
            countphoton = countphoton + 1
    return tcospsol, tsinpsol, events
예제 #9
0
def fsolvecsq_stable(
    dg,
    dE,
    Egg,
    tG,
    pG,
    deltaG,
    ranget,
    Morp=False,
    xtol=1e-10,
    tau=False,
    RnB=False
):  # Solves the Constraints - quite stable, but can jump to other branches
    anglesG = np.array([tG, pG, deltaG])

    x, y, z = getxyzB(dg, dE, anglesG)

    if not tau:
        if gv.STODE == 1 and not Morp:
            tau = gv.drawMFPe(Egg, gv.zE(gv.dS))
        else:
            tau = gv.De(gv.zE(gv.dS), gv.Ee(Egg, gv.zE(gv.dS)))
    w = 1.0 / gv.R(gv.Ee(Egg, gv.zE(gv.dS)), gv.B0, gv.zE(gv.dS))
    wtau = w * tau

    def F(angles):
        x, y, z = getxyzB(dg, dE, angles)
        fB = B(x, y, z)
        bnorm = np.sqrt(fB[0] * fB[0] + fB[1] * fB[1] + fB[2] * fB[2] + 1e-20)
        if RnB:
            w = bnorm / (RnB * 1e-14)
        else:
            w = 1.0 / gv.R(gv.Ee(Egg, gv.zE(gv.dS)), bnorm, gv.zE(gv.dS))
        wtau = w * tau
        cons1 = fLoS(angles[0], angles[2], dg, dE)
        cons2 = fvcBdphi(
            fBz(fB, angles[0], angles[1]),
            fBrho(fB, angles[0], angles[1]),
            angles[2],
            angles[0],
        )
        cons3 = fdeltaEqn(angles[2],
                          fvpara(fB / bnorm, angles[0], angles[1], angles[2]),
                          Egg, wtau)
        return (cons1, cons2, cons3)

    sol, o1, ier, o2 = opt.fsolve(F, anglesG, xtol=xtol, full_output=1)

    charge = 1  # initialize the charge variable, now look what charge this has to be.
    if gv.chargeanalyze == 1:
        xvec = getxyz(dg, dE, sol)
        Bvec = B(xvec[0], xvec[1], xvec[2] + dE)
        orientation = np.dot(xvec, np.cross(fvi(sol[0], sol[1], sol[2]), Bvec))
        temp = np.dot(Bvec, fvi(sol[0], sol[1], sol[2])) / np.linalg.norm(Bvec)
        r = int(np.floor(wtau / (np.pi * np.power(1 - temp * temp, 0.5)))) % 2
        if orientation >= 0:  # the electron initially moves towards us
            if r == 0:  # electron must be the lepton
                charge = -1
            else:  # positron must be the lepton
                charge = 1
        if orientation < 0:  # the electron initially moves away from us
            if r == 0:  # positron must be the lepton
                charge = 1
            else:  # electron must be the lepton
                charge = -1
    return sol, ier, charge