コード例 #1
0
ファイル: transforms.py プロジェクト: pwaller/mcviz
    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
ファイル: transforms.py プロジェクト: lukasheinrich/mcviz
    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
ファイル: test_jet.py プロジェクト: mcviz/mcviz.jet
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
ファイル: test_jet.py プロジェクト: mcviz/mcviz.jet
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
ファイル: test_jet.py プロジェクト: mcviz/mcviz.jet
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
ファイル: tagging.py プロジェクト: lukasheinrich/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))))
コード例 #11
0
def test_minimal():
    cluster_jets([])
コード例 #12
0
ファイル: test_jet.py プロジェクト: mcviz/mcviz.jet
def test_minimal():
    cluster_jets([])