Ejemplo n.º 1
0
def track(lattice,bunch,options):
    """
    Tracks a bunch of particles through the lattice using maps
    - lattice is a list of elements (class _Node)
    - bunch (class Bunch) is a list of particles (class Particle)
    - each particle in a bunch has a track=particle['track']
    - track (class Track) is a list of points (class Tpoint)
    
    Input: lattice , bunch
    """
    zeuge          = ('*\u007C*','**\u007C','*\u007C*','\u007C**')  # *|*
    tx4            = ' {}% done {}/{} lost/initial'.format(0,0,bunch.nbparticles())

    ndcnt  = 0
    lnode  = len(lattice.seq)
    lmod   = int(lnode*0.05)
    nlost  = 0
    nbpart = bunch.nbparticles()
    lbunch = Bunch()    # lost particles go into this bunch
    for node in iter(lattice):              # nodes
        ndcnt +=1
        for particle in iter(bunch):        # particles
            lost = track_node(node,particle,options)
            if lost:
                lbunch.addparticle(particle)
                bunch.removeparticle(particle)
                nlost += 1
            # showing track-loop progress
            if (ndcnt+1)%lmod == 0:
                tx4 = ' {}% done {}% lost'.format(int((ndcnt/lnode*100.)+1.), int(nlost/nbpart*100.))
                # tx = ('(track design)', '(track bunch)', zeuge[ndcnt%4], tx4)
                tx = ('(track design)', '(track bunch)', '', tx4)
                progress(tx)
                
    live = nbpart - lbunch.nbparticles()
    print('\nTRACKING DONE (live particles {}, lost particles {})               '.format(live,nlost))
    return (bunch,lbunch)