# Path: blond/trackers/utilities.py
# def is_in_separatrix(Ring, RFStation, Beam, dt, dE, 
#                      total_voltage = None):
#     r"""Function checking whether coordinate pair(s) are inside the separatrix. 
#     Uses the single-RF sinusoidal Hamiltonian.
#     
#     Parameters
#     ---------- 
#     Ring : class
#         A Ring type class
#     RFStation : class
#         An RFStation type class
#     Beam : class
#         A Beam type class
#     dt : float array
#         Time coordinates of the particles to be checked
#     dE : float array
#         Energy coordinates of the particles to be checked
#     total_voltage : float array
#         Total voltage to be used if not single-harmonic RF
#         
#     Returns
#     -------
#     bool array
#         True/False array for the given coordinates
#         
#     """
#      
#     warnings.filterwarnings("once")
#     
#     if Ring.n_sections > 1:
#         warnings.warn("WARNING: in is_in_separatrix(): the usage of several"+
#                       " sections is not yet implemented!")
#     if RFStation.n_rf > 1:
#         warnings.warn("WARNING in is_in_separatrix(): taking into account" +
#                       " the first harmonic only!")
#     
#          
#     counter = RFStation.counter[0]
#     dt_sep = (np.pi - RFStation.phi_s[counter] 
#               - RFStation.phi_rf_d[0,counter])/ \
#               RFStation.omega_rf[0,counter]
#      
#     Hsep = hamiltonian(Ring, RFStation, Beam, dt_sep, 0, 
#                        total_voltage = None) 
#     isin = np.fabs(hamiltonian(Ring, RFStation, Beam, 
#                                dt, dE, total_voltage = None)) < np.fabs(Hsep)
#      
#     return isin
# 
# Path: blond/utils/exceptions.py
# class MassError(Exception):
# class AllParticlesLost(Exception):
# class ParticleAdditionError(Exception):
# class DistributionError(Exception):
# class GenerationError(Exception):
# class CutError(Exception):
# class ProfileDerivativeError(Exception):
# class WakeLengthError(Exception):
# class FrequencyResolutionError(Exception):
# class ResonatorError(Exception):
# class WrongCalcError(Exception):
# class MissingParameterError(Exception):
# class MomentumError(Exception):
# class PhaseLoopError(Exception):
# class PhaseNoiseError(Exception):
# class FeedbackError(Exception):
# class ImpulseError(Exception):
# class PhaseSpaceError(Exception):
# class NoiseDiffusionError(Exception):
# class PotentialWellError(Exception):
# class SolverError(Exception):
# class PeriodicityError(Exception):
# class ProfileError(Exception):
# class SynchrotronMotionError(Exception):
# class ConvolutionError(Exception):
# class IntegrationError(Exception):
# class SortError(Exception):
# class InterpolationError(Exception):
# class InputDataError(Exception):
# 
# Path: blond/utils/bmath.py
# def use_mpi():
# def mpiMode():
# def use_fftw():
# def use_precision(_precision='double'):
# def update_active_dict(new_dict):


from builtins import object
from scipy.constants import m_p, m_e, e, c, epsilon_0, hbar
from ..trackers.utilities import is_in_separatrix
from ..utils import exceptions as blExcept
from ..utils import bmath as bm
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
import numpy as np
import itertools as itl
            import random

        Returns
        -------
        n_macroparticles_lost : int
            number of macroparticles lost.

        '''

        return len(np.where(self.id == 0)[0])

    @property
    def n_macroparticles_alive(self):
        '''Number of transmitted macro-particles, defined as @property.

        Returns
        -------
        n_macroparticles_alive : int
            number of macroparticles not lost.

        '''

        return self.n_macroparticles - self.n_macroparticles_lost

    def eliminate_lost_particles(self):
        """Eliminate lost particles from the beam coordinate arrays
        """

        indexalive = np.where(self.id != 0)[0]
        if len(indexalive) > 0:
            self.dt = np.ascontiguousarray(

# Path: blond/trackers/utilities.py
# def is_in_separatrix(Ring, RFStation, Beam, dt, dE, 
#                      total_voltage = None):
#     r"""Function checking whether coordinate pair(s) are inside the separatrix. 
#     Uses the single-RF sinusoidal Hamiltonian.
#     
#     Parameters
#     ---------- 
#     Ring : class
#         A Ring type class
#     RFStation : class
#         An RFStation type class
#     Beam : class
#         A Beam type class
#     dt : float array
#         Time coordinates of the particles to be checked
#     dE : float array
#         Energy coordinates of the particles to be checked
#     total_voltage : float array
#         Total voltage to be used if not single-harmonic RF
#         
#     Returns
#     -------
#     bool array
#         True/False array for the given coordinates
#         
#     """
#      
#     warnings.filterwarnings("once")
#     
#     if Ring.n_sections > 1:
#         warnings.warn("WARNING: in is_in_separatrix(): the usage of several"+
#                       " sections is not yet implemented!")
#     if RFStation.n_rf > 1:
#         warnings.warn("WARNING in is_in_separatrix(): taking into account" +
#                       " the first harmonic only!")
#     
#          
#     counter = RFStation.counter[0]
#     dt_sep = (np.pi - RFStation.phi_s[counter] 
#               - RFStation.phi_rf_d[0,counter])/ \
#               RFStation.omega_rf[0,counter]
#      
#     Hsep = hamiltonian(Ring, RFStation, Beam, dt_sep, 0, 
#                        total_voltage = None) 
#     isin = np.fabs(hamiltonian(Ring, RFStation, Beam, 
#                                dt, dE, total_voltage = None)) < np.fabs(Hsep)
#      
#     return isin
# 
# Path: blond/utils/exceptions.py
# class MassError(Exception):
# class AllParticlesLost(Exception):
# class ParticleAdditionError(Exception):
# class DistributionError(Exception):
# class GenerationError(Exception):
# class CutError(Exception):
# class ProfileDerivativeError(Exception):
# class WakeLengthError(Exception):
# class FrequencyResolutionError(Exception):
# class ResonatorError(Exception):
# class WrongCalcError(Exception):
# class MissingParameterError(Exception):
# class MomentumError(Exception):
# class PhaseLoopError(Exception):
# class PhaseNoiseError(Exception):
# class FeedbackError(Exception):
# class ImpulseError(Exception):
# class PhaseSpaceError(Exception):
# class NoiseDiffusionError(Exception):
# class PotentialWellError(Exception):
# class SolverError(Exception):
# class PeriodicityError(Exception):
# class ProfileError(Exception):
# class SynchrotronMotionError(Exception):
# class ConvolutionError(Exception):
# class IntegrationError(Exception):
# class SortError(Exception):
# class InterpolationError(Exception):
# class InputDataError(Exception):
# 
# Path: blond/utils/bmath.py
# def use_mpi():
# def mpiMode():
# def use_fftw():
# def use_precision(_precision='double'):
# def update_active_dict(new_dict):


# Path: blond/beam/beam.py
from builtins import object
from scipy.constants import m_p, m_e, e, c, epsilon_0, hbar
from ..trackers.utilities import is_in_separatrix
from ..utils import exceptions as blExcept
from ..utils import bmath as bm
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
        from ..utils.mpi_config import worker
import numpy as np
import itertools as itl
            import random


        Returns
        -------
        n_macroparticles_lost : int
            number of macroparticles lost.

        '''

        return len(np.where(self.id == 0)[0])

    @property
    def n_macroparticles_alive(self):
        '''Number of transmitted macro-particles, defined as @property.

        Returns
        -------
        n_macroparticles_alive : int
            number of macroparticles not lost.

        '''

        return self.n_macroparticles - self.n_macroparticles_lost

    def eliminate_lost_particles(self):
        """Eliminate lost particles from the beam coordinate arrays
        """

        indexalive = np.where(self.id != 0)[0]
        if len(indexalive) > 0:
            self.dt = np.ascontiguousarray(

                self.dt[indexalive], dtype=bm.precision.real_t)