예제 #1
0
def test_cluster_recombination_schemes():
    recomb_schemes = {
        'E_scheme': (983.28, -0.8676, 36.46),
        'pt_scheme': (983.52, -0.8672, 0.00),
        'pt2_scheme': (983.52, -0.8679, 0.00),
        'Et_scheme': (983.55, -0.8672, 0.00),
        'Et2_scheme': (983.55, -0.8679, 0.00),
        'BIpt_scheme': (983.52, -0.8671, 0.00),
        'BIpt2_scheme': (983.52, -0.8679, 0.00),
        'WTA_pt_scheme': (983.52, -0.8684, 0.14),
        'WTA_modp_scheme': (983.03, -0.8684, 0.14),
    }

    for recomb_scheme, jet in recomb_schemes.items():
        sequence = cluster(get_event(),
                           R=0.6,
                           p=-1,
                           recomb_scheme=recomb_scheme)
        jets = sequence.inclusive_jets()

        assert jets[0].pt == approx(jet[0], abs=1e-2)
        assert jets[0].eta == approx(jet[1], abs=1e-4)
        assert jets[0].mass == approx(jet[2], abs=1e-2)

    with pytest.raises(ValueError):
        sequence = cluster(get_event(),
                           R=0.6,
                           p=-1,
                           recomb_scheme='invalid_scheme')
예제 #2
0
def test_cluster():
    sequence = cluster(get_event(), R=0.6, p=-1)
    jets = sequence.inclusive_jets()
    assert_equal(len(jets), 91)
    assert_almost_equal(jets[0].pt, 983.28, 2)
    assert_true(isinstance(jets[0].parents, tuple))
    assert_equal(len(jets[0].parents), 2)
    assert_equal(jets[0].parents[0].child.pt, jets[0].pt)
    assert_equal(jets[0].parents[0].child, jets[0])
    # too few parameters specified for jet definition
    assert_raises(RuntimeError, cluster, get_event())
    # hashable
    hash(sequence)
    hash(jets[0])
예제 #3
0
def test_jet_area():
    sequence = cluster(get_event(), R=0.6, p=-1, area='active')
    jets = sequence.inclusive_jets()
    for jet in jets:
        area, error = jet.area
        if len(jet) > 3:  # TODO: need better way to test this
            assert area > 0
예제 #4
0
def test_cluster():
    sequence = cluster(get_event(), R=0.6, p=-1)
    jets = sequence.inclusive_jets()
    assert len(jets) == 91
    assert jets[0].pt == approx(983.28, abs=2)
    assert isinstance(jets[0].parents, tuple)
    len(jets[0].parents) == 2
    jets[0].parents[0].child.pt == jets[0].pt
    jets[0].parents[0].child == jets[0]

    # too few parameters specified for jet definition
    with pytest.raises(RuntimeError):
        cluster(get_event())

    # hashable
    hash(sequence)
    hash(jets[0])
예제 #5
0
def test_jet_area():
    if not USING_EXTERNAL_FASTJET:
        raise SkipTest("using internal fastjet")
    sequence = cluster(get_event(), R=0.6, p=-1, area='active')
    jets = sequence.inclusive_jets()
    for jet in jets:
        area, error = jet.area
        if len(jet) > 3:  # TODO: need better way to test this
            assert_true(area > 0)
예제 #6
0
def test_userinfo():
    event = get_event()
    # add an 'id' field to each particle
    event = append_fields(event, 'id', data=np.arange(len(event)))
    sequence = cluster(event, R=0.6, p=-1)
    jets = sequence.inclusive_jets()
    ids = []
    for jet in jets:
        for constit in jet:
            ids.append(constit.id)
            assert_equal(constit.id, constit.info['id'])
    ids.extend([p.id for p in sequence.unclustered_particles()])
    # are all particles accounted for?
    assert_array_equal(sorted(ids), np.arange(len(event)))
예제 #7
0
def test_recluster():
    sequence = cluster(get_event(), R=0.6, p=-1)
    jets = sequence.inclusive_jets()
    assert jets[0].pt == cluster(jets[0], R=0.6, p=-1).inclusive_jets()[0].pt
예제 #8
0
from pyjet import cluster
from pyjet.testdata import get_event
from numpy.lib.recfunctions import append_fields
from numpy.testing import assert_array_equal
import numpy as np

# event's dtype=np.dtype([('E', 'f8'), ('px', 'f8'), ('py', 'f8'), ('pz', 'f8')])
# this is the sample event shipped with FastJet with E moved to the first column
event = get_event()

# You can associate arbitrary additional information to each particle
# and this information can be accessed as attributes of the PseudoJets
event = append_fields(event, 'id', data=np.arange(len(event)))

sequence = cluster(event, R=0.6, p=-1)
jets = sequence.inclusive_jets()

ids = []
for jet in jets:
    for constit in jet:
        ids.append(constit.id)
ids.extend([p.id for p in sequence.unclustered_particles()])
# Are all particles accounted for?
assert_array_equal(sorted(ids), np.arange(len(event)))

# Printing a few things here as a demonstration of the basic functionality
print("{0: <5} {1: >10} {2: >10} {3: >10} {4: >10} {5: >10}".format(
    "jet#", "pT", "eta", "phi", "mass", "#constit."))
for i, jet in enumerate(jets[:6]):
    print("{0: <5} {1: 10.3f} {2: 10.3f} {3: 10.3f} {4: 10.3f} {5: 10}".format(
        i + 1, jet.pt, jet.eta, jet.phi, jet.mass, len(jet)))
예제 #9
0
import numpy as np
from pyjet import cluster, DTYPE_PTEPM
from pyjet.testdata import get_event
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
from matplotlib.colors import LinearSegmentedColormap

# define eta and phi ranges and number of bins along each axis
eta_min, eta_max = -4., 4.
extent = eta_min, eta_max, -np.pi, np.pi
bins = 200

event = get_event()

# create regular grid of ghosts
eta_edges = np.linspace(eta_min, eta_max, bins + 1)
phi_edges = np.linspace(-np.pi, np.pi, bins + 1)
eta = np.linspace(eta_min, eta_max,
                  bins + 1)[:-1] + (eta_max - eta_min) / (2 * bins)
phi = np.linspace(-np.pi, np.pi, bins + 1)[:-1] + (np.pi / bins)
X, Y = np.meshgrid(eta, phi)
ghosts = np.zeros(eta.shape[0] * phi.shape[0], dtype=DTYPE_PTEPM)
ghosts['pT'] = 1e-8
ghosts['eta'] = X.ravel()
ghosts['phi'] = Y.ravel()

# add ghosts to the event
event = np.concatenate([event, ghosts], axis=0)

fig = plt.figure(figsize=(9, 3))
예제 #10
0
def test_vector_conversion():
    event = get_event(ep=True)
    assert_array_almost_equal(
        event.view(DTYPE),
        ptepm2ep(ep2ptepm(event)).view(DTYPE))