def choosePs(h5pDir, h5pStub, pC=80, Np=12, doMask=False): #Find Np particles above energy Kc at end of simulation h5pFile = h5pDir + "/" + h5pStub if (doMask): isIn = lfmpp.getIn(h5pFile) pIds, Ks = lfmpp.getH5pFin(h5pFile, "kev", Mask=isIn) else: pIds, Ks = lfmpp.getH5pFin(h5pFile, "kev") Kc = np.percentile(Ks, pC) Ind = (Ks > Kc) pIds = pIds[Ind] Ks = Ks[Ind] Ntot = len(pIds) print("Found %d particles w/ final energy above %3.2f keV" % (Ntot, Kc)) print("File = %s" % h5pFile) print("Maximum energy = %f" % Ks.max()) print("Mean (K > Kc) energy = %f" % Ks.mean()) print("\n\n") if (Ntot >= Np): IndR = np.random.choice(Ntot, Np, replace=False) pIds = pIds[IndR] else: print("Error, not enough matching particles found") return Kc, pIds
def getdMu(h5pFile): TINY = 1.0e-8 pIds, Muf = lfmpp.getH5pFin(h5pFile, "Mu") pIds, Mu0 = lfmpp.getH5pInit(h5pFile, "Mu") Ind = (Muf > TINY) & (Mu0 > TINY) Muf = Muf[Ind] Mu0 = Mu0[Ind] #dMu = np.abs(Muf-Mu0)/Mu0 dMu = (Muf - Mu0) / Mu0 print("\nCutting %d particles for undefined Mu" % (len(Ind) - Ind.sum())) print("Min dMu = %f" % (dMu.min())) print("Min Muf = %f, Min Mu0 = %f" % (Muf.min(), Mu0.min())) print("\n\n") return dMu, Ind
def mpxK(fIn): #Get energies at last/first MPX isOut = lfmpp.getOut(fIn, mp=True) t, kevPT = lfmpp.getH5p(fIn, "kev") #Last MP crossings pid, Tmpx = lfmpp.getH5pFin(fIn, "tCr", Mask=isOut) #First MP crossings R, Phi, Lambda, Tmpx0 = lfmpp.getSphLoss1st(fIn) Np = isOut.sum() #Number of out particles mpK = np.zeros(Np) mpK0 = np.zeros(Np) for n in range(Np): idn = np.int(pid[n] - 1) #Time slices of first/last MPX ts0 = np.argmin(Tmpx0[n] >= t) tsF = np.argmin(Tmpx[n] >= t) #print(n,idn,ts0,tsF) mpK[n] = kevPT[tsF, idn] mpK0[n] = kevPT[ts0, idn] return mpK0, mpK
def getTimes(fIn, doTail=False): isOut = lfmpp.getOut(fIn, mp=True, tl=doTail) t, mpF = lfmpp.getH5p(fIn, "mp") mp = mpF[:, isOut] #Last MP crossings pid, Tmpx = lfmpp.getH5pFin(fIn, "tCr", Mask=isOut) #First MP crossings R, Phi, Lambda, Tmpx0 = lfmpp.getSphLoss1st(fIn) #Time of loss from box, time slice index tsMP = np.argmax(mp, axis=0) #Convert to physical time Tbx = t[tsMP] if (doTail): #Remove particles that leave through tail but never cross MP DelT = Tbx - Tmpx Tbx = Tbx[DelT > 0] Tmpx = Tmpx[DelT > 0] pid = pid[DelT > 0] return Tmpx, Tmpx0, Tbx, pid
def lastPhi(fIn): isOut = lfmpp.getOut(fIn) ids, x = lfmpp.getH5pFin(fIn, "x", Mask=isOut) ids, y = lfmpp.getH5pFin(fIn, "y", Mask=isOut) pBX = np.arctan2(y, x) * 180.0 / np.pi return pBX
Stubs = ["p", "Hep", "Hepp", "O"] Labs = ["H+", "He+", "He++", "O+"] t**S = "Single Injection (10 keV)" N = len(Stubs) Ks = [] figName = "chK.png" figQ = 300 K0 = 1 K1 = 225 Nb = 60 for n in range(N): h5p = Root + Stubs[n] + Tail pIds, K = lfmpp.getH5pFin(h5p, "kev") Ks.append(K) bins = np.linspace(K0, K1, Nb) bc = 0.5 * (bins[1:] + bins[:-1]) for n in range(N): y, x = np.histogram(Ks[n], bins) plt.semilogy(bc, y + 1, 'o-', label=Labs[n], markersize=4) # plt.hist(Ks,bins,normed=False,log=True,stacked=True,histtype='step',fill=True) plt.legend(Labs) plt.xlabel("Final Energy [keV]") plt.ylabel("Count")
def lastK(fIn): isOut = lfmpp.getOut(fIn) ids, kev = lfmpp.getH5pFin(fIn, "kev", Mask=isOut) return ids, kev
def getLastEQX(fIn): isOut = lfmpp.getOut(fIn) ids, xeq = lfmpp.getH5pFin(fIn, "xeq", Mask=isOut) ids, yeq = lfmpp.getH5pFin(fIn, "yeq", Mask=isOut) return xeq, yeq
#Find particles whose last Teq is in range T0 = 2250 T1 = 2300 P0 = 80; P1 = 135 fOut = "khiSub.h5part" Out = lfmpp.getOut(fIn) t,x = lfmpp.getH5p(fIn,"x") t,y = lfmpp.getH5p(fIn,"y") t,z = lfmpp.getH5p(fIn,"z") t,Teq = lfmpp.getH5pFin(fIn,"Teq") t,ids = lfmpp.getH5p(fIn,"id") id0 = ids[0,:] R,Phi,Lambda = lfmpp.getSphLoss(fIn) Out[Out] = (Phi>=P0) & (Phi<=P1) Mask = (Teq>=T0) & (Teq<=T1) & Out Np = Mask.sum() t,xeq = lfmpp.getH5p(fIn,"xeq") t,yeq = lfmpp.getH5p(fIn,"yeq") xP = xeq[:,Mask] yP = yeq[:,Mask] id0 = id0[Mask]
def getAf(h5pFile): pIds, Af = lfmpp.getH5pFin(h5pFile, "alpheq") return Af
def getdK(h5pFile): pIds, Kf = lfmpp.getH5pFin(h5pFile, "kev") pIds, K0 = lfmpp.getH5pInit(h5pFile, "kev") dK = Kf / K0 return dK