def clear(self, color: Vec4): for y in range(self.size.y): for x in range(self.size.x): self.pixels[y][x] = Pixel(Vec2(x, y), color.copy()) self.surface.fill(color.as_tuple()) self.changed_pixels.clear()
def generate_point(pa, pb, rans): # The final momenta # MOM = [ -rans[-1]*pa, -rans[-2]*pb ] MOM = [-pa, -pb] # NOTE this fixes the incoming momenta _Q = -MOM[0] - MOM[1] # Storage of intermediate Masses, Qs M = [_Q.M()] ALLQ = [_Q] U, R = [], [] # Store the u and random numbers r for i in range(2, NP + 1): # print("now i = {}".format(i)) if i < NP: # print("Solving for u_{}, M_{}".format(i, i)) r = rans[3 * (i - 2) + 2] u = get_u(NP + 1 - i, r) U.append(u) R.append(r) # Simon's paper must be wrong here, check _M = np.sqrt(u * _Q.M2()) # M_i^2 else: _M = 0 # print("Got M_{}={}".format(i, _M)) M.append(_M) q = 4 * M[-2] * rho_massless(M[-2], M[-1]) # Random numbers for costheta and phi costheta = 2 * rans[3 * (i - 2)] - 1 phi = 2. * np.pi * rans[3 * (i - 2) + 1] # Generated 4 Vectors # p_(i-1) sintheta = np.sqrt(1. - costheta * costheta) p = q * Vec4(1, np.cos(phi) * sintheta, np.sin(phi) * sintheta, costheta) # print("p_{} = {} {}".format(i+1, p, np.sqrt(abs(p.M2())))) # now Q_i _Q = Vec4(np.sqrt(q * q + M[-1] * M[-1]), -p.px, -p.py, -p.pz) # print("Q_{} = {} {}".format(i, _Q, np.sqrt(abs(_Q.M2())))) p = ALLQ[i - 2].BoostBack(p) _Q = ALLQ[i - 2].BoostBack(_Q) # print ALLQ[i-2]-_Q-p # print "p boosted ",p,p.M2() # print "Q boosted ",_Q,np.sqrt(abs(_Q.M2())) # print "sum p+Q ",(p+_Q),(p+_Q).M() MOM.append(p) ALLQ.append(_Q) MOM.append(_Q) return MOM
def GeneratePoint(self): ct = 2.*r.random()-1. st = m.sqrt(1.-ct*ct) phi = 2.*m.pi*r.random() p1 = Vec4(1,st*m.cos(phi),st*m.sin(phi),ct)*self.ecms/2. p2 = Vec4(p1.E,-p1.px,-p1.py,-p1.pz) pa = Vec4(self.ecms/2,0,0,self.ecms/2.) pb = Vec4(self.ecms/2,0,0,-self.ecms/2.) fl = r.randint(1,5) lome = self.ME2(fl,(pa+pb).M2(),(pa-p1).M2()) dxs = 5.*lome*3.89379656e8/(8.*m.pi)/(2.*pow(self.ecms,2)) return ( [ Particle(-11,-pa), Particle(11,-pb), Particle(fl,p1,[1,0]), Particle(-fl,p2,[0,1]) ], dxs, lome )
def MakeKinematics(self, z, y, phi, pijt, pkt): Q = pijt + pkt rkt = m.sqrt(Q.M2() * y * z * (1. - z)) kt1 = pijt.Cross(pkt) if kt1.P() < 1.e-6: kt1 = pijt.Cross(Vec4(0., 1., 0., 0.)) kt1 *= rkt * m.cos(phi) / kt1.P() kt2cms = Q.Boost(pijt).Cross(kt1) kt2cms *= rkt * m.sin(phi) / kt2cms.P() kt2 = Q.BoostBack(kt2cms) pi = z * pijt + (1. - z) * y * pkt + kt1 + kt2 pj = (1. - z) * pijt + z * y * pkt - kt1 - kt2 pk = (1. - y) * pkt return [pi, pj, pk]
def CheckEvent(event): psum = Vec4() csum = {} for p in event: psum += p.mom if p.col[0] > 0: csum[p.col[0]] = csum.get(p.col[0], 0) + 1 if csum[p.col[0]] == 0: del csum[p.col[0]] if p.col[1] > 0: csum[p.col[1]] = csum.get(p.col[1], 0) - 1 if csum[p.col[1]] == 0: del csum[p.col[1]] return (m.fabs(psum.E)<1.e-12 and \ m.fabs(psum.px)<1.e-12 and \ m.fabs(psum.py)<1.e-12 and \ m.fabs(psum.pz)<1.e-12 and \ len(csum) == 0)
def __init__(self, pos: Vec2, color: Vec4): self.pos = pos.copy() self.color = color.copy()
TMP = np.sqrt(1. - CT_2 * CT_2) # 4-mom vectors as array MOM = np.empty((NSAMPLES, 4)) MOM[:, 0] = q_2 MOM[:, 1] = q_2 * COSPHI_2 * TMP MOM[:, 2] = q_2 * SINPHI_2 * TMP MOM[:, 3] = q_2 * CT_2 # Q_2 4-vectors Q_2 = np.empty((NSAMPLES, 4)) Q_2[:, 0] = np.sqrt(q_2 * q_2 + M_2 * M_2) Q_2[:, (1, 2, 3)] = -MOM[:, (1, 2, 3)] t1 = time.time() vP1 = [Vec4(*m) for m in MOM] # p1 --- but in CMS vQ2 = [Vec4(*q) for q in Q_2] # Q2 --- but in CMS t2 = time.time() print("Conversion took {} s".format(t2 - t1)) # TODO understand boost --- also if n>3 there is also a boost of Q_2 required to proceed correctly # # NOTE in the final step, i.e. no more intermediate steps, M_i becomes 0 # and the final 4-momenta are (in the correponding CMS) simply +/- MOM q_3 = 4 * M_2 * rho_massless(M_2, 0) # in the n=3 case, we are done with intermediate steps and only need to draw two more random numbers R_4 = np.random.rand(NSAMPLES) R_5 = np.random.rand(NSAMPLES) CT_3 = 2. * R_4 - 1. PHI_3 = 2. * np.pi * R_5
def fill_line(self, start_pos: Vec2, end_pos: Vec2, color: Vec4): line_pixels = get_line_pixels(start_pos, end_pos) for vec in line_pixels: self.fill_pixel(Pixel(Vec2(vec.x, vec.y), color.copy()))
C = 1 for i in range(5): for j in range(5): if i < j: # print("i={}, j={}: {} * {} = {}".format(i, j, P[i], P[j], P[i]*P[j])) C *= P[i] * P[j] return A * B / C if __name__ == "__main__": import sys np.random.seed(1) pa = Vec4(7000, 0, 0, 7000) pb = Vec4(7000, 0, 0, -7000) if len(sys.argv) < 2: print("Please specify the number of external particles, exiting") sys.exit(1) NP = int(sys.argv[1]) # Number of external particles if NP < 3: print("NP should be >=3 for the whole thing to make sense, exiting") sys.exit(1) rans = [np.random.rand() for i in range(0, 3 * NP - 4 + 2)] moms = generate_point(pa, pb, rans)
from vector import Vec4 WHITE = Vec4(255, 255, 255, 255) BLACK = Vec4(0, 0, 0, 255) GRAY = Vec4(128, 128, 128, 255) RED = Vec4(255, 0, 0, 255) GREEN = Vec4(0, 255, 0, 255) BLUE = Vec4(0, 0, 255, 255)