示例#1
0
    def __call__(self, graph_view):
        from mcviz.jet import cluster_jets, JetAlgorithms
        from math import hypot
        track_jets = self.options["tracks"]
        if track_jets:
            raise Exception("Unimplemented!")
        def pselect(p):
            return p.final_state and not p.invisible and (p.charge != 0 if track_jets else True)
        final_state_particles = [p for p in graph_view.particles if pselect(p)]
        jets = cluster_jets(final_state_particles, getattr(JetAlgorithms, self.options["algorithm"]))
        print "Converted %i final state particles into %i jets" % (len(final_state_particles), len(jets))

        def pt(jet):
            return hypot(*jet.p[:2])
        for i, jet in enumerate(sorted(jets, key=pt, reverse=True)):
            print "Created jet: np=%2i, %r, %r" % (len(jet.particles), jet.p, jet.e)
            if i >= self.options["n_max"]:
                break
            jet_start_vertices = set(p.start_vertex for p in jet.particles)
            jet_end_vertices = set(p.end_vertex for p in jet.particles)
            vs_summary = graph_view.summarize_vertices(jet_start_vertices)
            ve_summary = graph_view.summarize_vertices(jet_end_vertices)
            p_summary = graph_view.summarize_particles(jet.particles)
            vs_summary.tag("jet")
            ve_summary.tag("jet")
            p_summary.tag("jet")
            p_summary.tag("jet_{0:d}".format(i))
示例#2
0
    def __call__(self, graph_view):
        from mcviz.jet import cluster_jets, JetAlgorithms
        from math import hypot
        track_jets = self.options["tracks"]
        if track_jets:
            raise Exception("Unimplemented!")

        def pselect(p):
            return p.final_state and not p.invisible and (p.charge != 0 if
                                                          track_jets else True)

        final_state_particles = [p for p in graph_view.particles if pselect(p)]
        jets = cluster_jets(final_state_particles,
                            getattr(JetAlgorithms, self.options["algorithm"]))
        print "Converted %i final state particles into %i jets" % (
            len(final_state_particles), len(jets))

        def pt(jet):
            return hypot(*jet.p[:2])

        for i, jet in enumerate(sorted(jets, key=pt, reverse=True)):
            print "Created jet: np=%2i, %r, %r" % (len(
                jet.particles), jet.p, jet.e)
            if i >= self.options["n_max"]:
                break
            jet_start_vertices = set(p.start_vertex for p in jet.particles)
            jet_end_vertices = set(p.end_vertex for p in jet.particles)
            vs_summary = graph_view.summarize_vertices(jet_start_vertices)
            ve_summary = graph_view.summarize_vertices(jet_end_vertices)
            p_summary = graph_view.summarize_particles(jet.particles)
            vs_summary.tag("jet")
            ve_summary.tag("jet")
            p_summary.tag("jet")
            p_summary.tag("jet_{0:d}".format(i))
示例#3
0
def test_jet_algorithm():
    """
    Performing a basic test of cluster_jets
    """
    final_particles = get_final_state_particles()
    
    jets = cluster_jets(final_particles)
    print len(final_particles)
    print len(jets)
示例#4
0
def test_jet_algorithm():
    """
    Performing a basic test of cluster_jets
    """
    final_particles = get_final_state_particles()

    jets = cluster_jets(final_particles)
    print len(final_particles)
    print len(jets)
示例#5
0
def test_all_algorithms():
    
    final_particles = get_final_state_particles()
    
    from mcviz.jet import JetAlgorithms
    for algname, alg in zip(JetAlgorithms._fields, JetAlgorithms):
        try:
            jets = cluster_jets(final_particles, alg)
        except RuntimeError:
            log.exception("Caught RuntimeError for algname=%s, continuing..", algname)
            raise
示例#6
0
def test_all_algorithms():

    final_particles = get_final_state_particles()

    from mcviz.jet import JetAlgorithms
    for algname, alg in zip(JetAlgorithms._fields, JetAlgorithms):
        try:
            jets = cluster_jets(final_particles, alg)
        except RuntimeError:
            log.exception("Caught RuntimeError for algname=%s, continuing..",
                          algname)
            raise
示例#7
0
文件: tagging.py 项目: brookst/mcviz
def tag_by_jet(graph_view):
    from mcviz.jet import cluster_jets, JetAlgorithms
    final_state_particles = [p for p in graph_view.particles if p.final_state]
    jets = cluster_jets(final_state_particles, JetAlgorithms.antikt)
    print "Converted %i final state particles into %i jets" % (len(final_state_particles), len(jets))
    tagged = []
    def pt(jet):
        return hypot(*jet.p[:2])
    for i, jet in enumerate(sorted(jets, key=pt, reverse=True)):
        print "Created jet: np=%2i, %r, %r" % (len(jet.particles), jet.p, jet.e)
        if i >= 5:
            break

        for particle in jet.particles:
            particle.tags.add("jet%i" % i)
            tagged.append(particle)
    log.info("Tagged %i particles in %i jets" % (len(tagged), min(5, len(jets))))
示例#8
0
def test_for_leaks():
    """
    Leak testing cluster_jets
    """
    final_particles = get_final_state_particles()

    def get_refstate():
        return getrefcount(final_particles), map(getrefcount, final_particles)

    first_refstate = get_refstate()

    for i in xrange(100):
        jets = cluster_jets(final_particles)
        # Two because getrefcount() has a reference.
        assert getrefcount(jets) == 2
        # If this list goes away the refcounts should be back to
        # where they started.
        del jets
        # Check that we're not obviously leaking.
        assert get_refstate() == first_refstate, "Leaking objects!"
示例#9
0
def test_for_leaks():
    """
    Leak testing cluster_jets
    """
    final_particles = get_final_state_particles()
    
    def get_refstate():
        return getrefcount(final_particles), map(getrefcount, final_particles)
    
    first_refstate = get_refstate()
    
    for i in xrange(100):
        jets = cluster_jets(final_particles)
        # Two because getrefcount() has a reference.
        assert getrefcount(jets) == 2
        # If this list goes away the refcounts should be back to 
        # where they started.
        del jets
        # Check that we're not obviously leaking.
        assert get_refstate() == first_refstate, "Leaking objects!"
示例#10
0
def tag_by_jet(graph_view):
    from mcviz.jet import cluster_jets, JetAlgorithms
    final_state_particles = [p for p in graph_view.particles if p.final_state]
    jets = cluster_jets(final_state_particles, JetAlgorithms.antikt)
    print "Converted %i final state particles into %i jets" % (
        len(final_state_particles), len(jets))
    tagged = []

    def pt(jet):
        return hypot(*jet.p[:2])

    for i, jet in enumerate(sorted(jets, key=pt, reverse=True)):
        print "Created jet: np=%2i, %r, %r" % (len(
            jet.particles), jet.p, jet.e)
        if i >= 5:
            break

        for particle in jet.particles:
            particle.tags.add("jet%i" % i)
            tagged.append(particle)
    log.info("Tagged %i particles in %i jets" %
             (len(tagged), min(5, len(jets))))
示例#11
0
def test_minimal():
    cluster_jets([])
示例#12
0
def test_minimal():
    cluster_jets([])