def printTree(particle, indentation=0, momenta=True, positions=False, omit_stable=False, index=False, heading=True, labels={}, output=sys.stdout): """Print the decay tree for 'particle'. 'particle' -- A 'Paritcle' object. 'indentation' -- The number of spaces to indent the output. 'momenta' -- If true, print particles' four-momentum components in the lab frame. 'positions' -- If true, print particles' four-position components in the lab frame. 'omit_stable' -- If true, don't show decays of particles categorized as stable in the particle data table. 'index -- If true, show the table row index for each particle. Each 'Particle' object must have an 'index' attribute. 'heading' -- If true, print a heading on the decay tree.""" line = "" head_line = "" if index: line += "%5d " % particle.index head_line += "index " line += indent(particle.species, indentation, 20) head_line += center("species", 20) if momenta: e, px, py, pz = lab.coordinatesOf(particle.momentum) line += " %7.3f %7.3f %7.3f %7.3f" % (e, px, py, pz) head_line += center(" lab momentum", 32) if positions: t, x, y, z = lab.coordinatesOf(particle.position) line += " %7.3f %7.3f %7.3f %7.3f" % (t, x, y, z) head_line += center(" lab position", 32) label_list = [] if hasattr(particle, "label"): label_list.append(particle.label) for key, value in labels.items(): if value == particle: label_list.append(key) line += " " + ",".join(label_list) head_line += center(" labels", 12) if heading: print >> output, head_line print >> output, "-" * len(head_line) print >> output, line # Recursively print children too. if (not omit_stable or not pdt_info.is_stable) \ and particle.decay_products: for child in particle.decay_products: printTree(child, indentation + 1, momenta, positions, omit_stable, index, heading=False, labels=labels, output=output)
def printParticleTree(particle, depth=0): indentation = depth * " " name = "%-12s" % particle.species pad = (8 - depth) * " " momentum = "%5.2f %5.2f %5.2f %5.2f" % lab.coordinatesOf(particle.momentum) print indentation + name + pad + momentum for child in particle.decay_products: printParticleTree(child, depth + 1)
from hep import test from hep.lorentz import lab from math import sqrt x4 = lab.Vector(5.0, 3.0, 2.0, 1.0) t, x, y, z = lab.coordinatesOf(x4) test.compare(t, 5.0) test.compare(x, 3.0) test.compare(y, 2.0) test.compare(z, 1.0) test.compare(x4.norm, sqrt(11.0)) y4 = 2 * lab.Vector(4.0, -2.0, -1.0, 0.0) t, x, y, z = lab.coordinatesOf(x4 + y4) test.compare(t, 13.0) test.compare(x, -1.0) test.compare(y, 0.0) test.compare(z, 1.0) test.compare(x4 ^ y4, 56.0)
def __str__(self): e, px, py, pz = lab.coordinatesOf(self.momentum) return "STDHEP particle %s, momentum=(%.1f, %.1f, %.1f, %.1f)" \ % (self.species, e, px, py, pz)
from hep import test import hep.lorentz from hep.lorentz import lab from math import sqrt cm_frame = hep.lorentz.Frame(lab.Boost(0, 0, 0.5)) p4 = cm_frame.Momentum( 4.0, 1.0, 0.0, -1.0) q4 = cm_frame.Momentum( 4.0, -1.0, 0.0, 1.0) t, x, y, z = cm_frame.coordinatesOf(p4 + q4) test.compare(t, 8.0) test.compare(x, 0.0) test.compare(y, 0.0) test.compare(z, 0.0) test.compare(p4.mass, sqrt(14.0), precision=1e-8) test.compare(q4.mass, sqrt(14.0), precision=1e-8) test.compare(p4 ^ q4, 18.0, precision=1e-8) tl, xl, yl, zl = lab.coordinatesOf(p4 + q4) test.assert_(tl > t) test.compare(xl, 0.0) test.compare(yl, 0.0)
import hep.lorentz from hep.lorentz import lab from hep.test import compare boost = lab.Boost(0.0, 0.0, 0.5) moving_frame = hep.lorentz.Frame(boost) momentum = lab.Momentum(5.0, 1.0, 0.0, -2.0) boosted_momentum = boost ^ momentum compare(lab.coordinatesOf(momentum), moving_frame.coordinatesOf(boosted_momentum), precision=1e-8)
from hep import test import hep.lorentz from hep.lorentz import lab from math import sqrt, pi x = lab.Vector(4.0, 0.0, 0.0, 2.0) x1 = lab.Rotation(pi / 2, 0.0, 0.0) ^ x test.compare(lab.coordinatesOf(x1), (4.0, 0.0, 0.0, 2.0)) test.compare(x1.norm, sqrt(12.0)) print lab.Rotation(0.0, pi / 2, 0.0).matrix x2 = lab.Rotation(0.0, pi / 2, 0.0) ^ x test.compare(lab.coordinatesOf(x2), (4.0, 2.0, 0.0, 0.0), precision=1e-8) test.compare(x2.norm, sqrt(12.0)) x3 = lab.Rotation(pi / 2, pi / 2, 0.0) ^ x test.compare(lab.coordinatesOf(x3), (4.0, 0.0, 2.0, 0.0), precision=1e-8) test.compare(x3.norm, sqrt(12.0))