SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Public Member Functions | Private Member Functions | Private Attributes
Beam::Bunch Class Reference

Holds a bunch of particles at a specific position along the beam line. More...

#include <Bunch.hh>

Public Member Functions

 Bunch ()
 Default constructor, initilizes everything to 0. More...
 
 Bunch (const BunchMap &samples, const double pos=0, const std::string &name="", const double mass=105.66)
 Map constructor, sets the particle sample from maps (no measurement errors) More...
 
 Bunch (const BunchMap &samples, const BunchMap &errors, const double pos=0, const std::string &name="", const double mass=105.66)
 Map constructor, sets the particle sample from maps. More...
 
 Bunch (const Bunch &bunch)
 Copy constructor. More...
 
Bunch & operator= (const Bunch &bunch)
 Equality operator. More...
 
 ~Bunch ()
 Destructor. More...
 
const std::string & Name () const
 Returns the name of the bunch. More...
 
void SetName (const std::string &name)
 Sets the name of the bunch. More...
 
const size_t & Dimension () const
 Returns the dimension of space in which the bunch lives. More...
 
const double & Position () const
 Returns the z position at which the bunch was sampled [mm]. More...
 
const double & Mass () const
 Returns the mass of the particles that make up the beam [MeV/c^2]. More...
 
void SetPosition (const double &pos)
 Sets the position of the bunch. More...
 
const size_t Size () const
 Returns the size of the whole sample. More...
 
const size_t CoreSize () const
 Returns the size of the core sample. More...
 
const std::vector< double > & Samples (const std::string var) const
 Returns the array of samples of variable var. More...
 
const std::vector< double > & Errors (const std::string var) const
 Returns the array of errors on the samples of variable var. More...
 
double Radius (const size_t i) const
 Returns the radius of the i^th sample. More...
 
std::vector< double > Radii () const
 Returns the array of radii of the samples. More...
 
Variable Mean (const std::string &var) const
 Returns the mean of the requested quantity. More...
 
const Matrix< double > & CovarianceMatrix () const
 Returns the covariance matrix of the bunch. More...
 
const Variable & Alpha () const
 Returns the Twiss parameter alpha of the bunch. More...
 
Variable Alpha (const std::string axis) const
 Returns the Twiss parameter alpha of the bunch in one 2D projection. More...
 
const Variable & Beta () const
 Returns the Twiss parameter beta of the bunch. More...
 
Variable Beta (const std::string axis) const
 Returns the Twiss parameter beta of the bunch in one 2D projection. More...
 
const Variable Gamma () const
 Returns the Twiss parameter gamma of the bunch. More...
 
Variable Gamma (const std::string axis) const
 Returns the Twiss parameter gamma of the bunch in one 2D projection. More...
 
const Variable & MechanicalL () const
 Returns the mechanical angular momentum of the bunch. More...
 
const Variable & Emittance () const
 Returns the RMS normalised emittance of the bunch. More...
 
const Variable & NormEmittance () const
 Returns the RMS geometric emittance of the bunch. More...
 
const Variable & SubEmittance () const
 Returns the subemittance of the core. More...
 
const Variable & FracEmittance () const
 Returns the volume of the core. More...
 
const Variable & AmplitudeQuantile () const
 Returns the maximum amplitude in the core. More...
 
Variable NormEmittanceEstimate (const SumStat &stat) const
 Returns the estimated normalised emittance from the measured fractional quantity. More...
 
Variable SummaryStatistic (const SumStat &stat) const
 Returns the requested summary statistic. More...
 
const std::vector< double > & Amplitudes () const
 Returns the array of amplitudes of the samples. More...
 
const std::vector< double > & VoronoiVolumes () const
 Returns the array of Voronoi volumes of the samples. More...
 
void SetFraction (const double frac)
 Defines the fraction the core represents (in case of transmission losses) More...
 
void SetCoreFraction (const double frac)
 Defines the fraction of the beam contained in the core. More...
 
void SetCoreSize (const size_t size)
 Assigns a certain amount of core particles. More...
 
void SetCoreVolume (const std::string algo="hull", const double norm=1.)
 Computes the volume of the fraction of the beam contained in the core. More...
 
void SetCorrectedAmplitudes ()
 Compute the corrected transverse amplitudes of every particle in the sample by only considering particles of lower amplitudes. More...
 
void SetMCDAmplitudes ()
 Compute the MCD transverse amplitude of every particle in the sample by selecting a subsample optimized based on its covariance determinant. More...
 
void SetGeneralisedAmplitudes (const double norm=1.)
 Compute the generalised transverse amplitude of every particle in the sample by basing it on density estimation and contour volume rather than covariance. More...
 
void SetVoronoiVolumes ()
 Compute the Voronoi volumes around each particle. More...
 
TEllipse * Ellipse (const std::string &vara, const std::string &varb, const double p=.39347) const
 Returns the n-RMS ellipse of a sample of two variables. More...
 
TEllipse * RobustEllipse (const std::string &vara, const std::string &varb, const double p=.39347) const
 Returns the n-RMS robust ellipse of a sample of two variables. More...
 
TH1F * Histogram (const std::string &var, double min=0, double max=0) const
 Returns the 1D distrubution of the requested variable. More...
 
TH2F * Histogram (const std::string &vara, const std::string &varb, double mina=0, double maxa=0, double minb=0, double maxb=0) const
 Returns the 2D distrubution of the requested variable. More...
 
ScatterGraph * AmplitudeScatter (const std::string &vara, const std::string &varb) const
 Returns the 2D scatter plot of particle amplitudes. More...
 

Private Member Functions

void Initialize (const BunchMap &samples, const BunchMap &errors)
 Normal initializer, sets the particle sample and bunch variables. More...
 
bool Contains (const std::string &var) const
 Checks if the variable is provided. More...
 
void AssertContains (const std::string &var) const
 Checks if the variable is provided, throws if not. More...
 
void Arrays (const std::string &var, std::vector< double > &samples, std::vector< double > &errors) const
 Returns the value and unertainty arrays corresponding to the requested variable. More...
 
double TotalMomentum (const size_t i) const
 Returns the total momentum of a given sample. More...
 
std::vector< double > TotalMomenta () const
 Returns the total momentum of all the samples. More...
 
double TotalMomentumError (const size_t i) const
 Returns the error on the total momentum of a given sample. More...
 
std::vector< double > TotalMomentumErrors () const
 Returns the error on the total momentum of all the samples. More...
 
void SetTwiss ()
 Computes the Twiss parameter alpha of the bunch. More...
 
double TwissMError (const std::string &name, std::map< std::string, double > &means, const double &detr, const Matrix< double > &C) const
 Computes the measurement error on the requested Twiss parameter. More...
 
double TwissSError (const double &twiss) const
 Computes the statistical error on the provided Twiss parameter. More...
 
void SetEmittance ()
 Computes the RMS geometric emittance of the bunch. More...
 
void SetNormEmittance ()
 Computes the RMS normalised emittance of the bunch. More...
 
void SetSubEmittance ()
 Computes the subemittance of the core. More...
 
void SetAmplitudeQuantile (const double &qamp)
 Sets the amplitude quantile and its uncertainty. More...
 
double NormEmittanceValue (const Matrix< double > &covmat) const
 Computes the RMS emittance provided with the covariance matrix. More...
 
void SetAmplitudes ()
 Compute the transverse amplitudes of every particle in the sample. More...
 
double AmplitudeValue (const Matrix< double > &invcovmat, const std::vector< double > &means, const std::vector< double > &vec, const double &neps) const
 Compute the transverse amplitude provided with S^-1 and the PS vector. More...
 

Private Attributes

std::string _name
 Name of the bunch. More...
 
size_t _dim
 Dimension of the transverse phase space. More...
 
double _pos
 Position at which the bunch was sampled. More...
 
double _mass
 Mass of the particles. More...
 
double _fraction
 Fraction contained in the beam core. More...
 
BunchData _data
 Underlying phase space vectors. More...
 
BunchData _core
 Core fraction of beam. More...
 
Variable _alpha
 Twiss parameter alpha. More...
 
Variable _beta
 Twiss parameter beta. More...
 
Variable _gamma
 Twiss parameter gamma. More...
 
Variable _mecl
 Normalised mechanical angular momentum. More...
 
Variable _eps
 Geometric RMS emittance. More...
 
Variable _neps
 Normalised RMS emittance. More...
 
Variable _seps
 Subemittance. More...
 
Variable _feps
 Fractional emittance. More...
 
Variable _qamp
 Lagest amplitude in the core. More...
 
std::vector< double > _amps
 Amplitudes of the particles. More...
 
std::vector< double > _vols
 Voronoi cell volumes of the particles. More...
 
DensityEstimator _de
 Density estimation of the bunch. More...
 

Detailed Description

Holds a bunch of particles at a specific position along the beam line.

Quantities associated with the bunch such as Twiss parameters, amplitudes, emittance, volume, etc. may be computed and stored here. This avoids unnecessarily repeating operations such as computing the particle amplitudes.

It is designed to hold a single species of particles.

Constructor & Destructor Documentation

Beam::Bunch::Bunch ( )

Default constructor, initilizes everything to 0.

Beam::Bunch::Bunch ( const BunchMap &  samples,
const double  pos = 0,
const std::string &  name = "",
const double  mass = 105.66 
)

Map constructor, sets the particle sample from maps (no measurement errors)

Parameters
samplesDictionary that maps each variable onto a vector of values
nameName of the bunch
posz position of the bunch [mm]
massMass of the particles that compose the bunch $[\textrm{MeV}/c^2]$
Beam::Bunch::Bunch ( const BunchMap &  samples,
const BunchMap &  errors,
const double  pos = 0,
const std::string &  name = "",
const double  mass = 105.66 
)

Map constructor, sets the particle sample from maps.

Parameters
samplesDictionary that maps each variable onto a vector of values
errorsDictionary that maps each variable onto a vector of uncertainties
posz position of the bunch [mm]
nameName of the bunch
massMass of the particles that compose the bunch $[\textrm{MeV}/c^2]$
Beam::Bunch::Bunch ( const Bunch &  bunch)

Copy constructor.

Beam::Bunch::~Bunch ( )

Destructor.

Member Function Documentation

const Variable& Beam::Bunch::Alpha ( ) const
inline

Returns the Twiss parameter alpha of the bunch.

Variable Beam::Bunch::Alpha ( const std::string  axis) const

Returns the Twiss parameter alpha of the bunch in one 2D projection.

const Variable& Beam::Bunch::AmplitudeQuantile ( ) const
inline

Returns the maximum amplitude in the core.

const std::vector<double>& Beam::Bunch::Amplitudes ( ) const
inline

Returns the array of amplitudes of the samples.

ScatterGraph * Beam::Bunch::AmplitudeScatter ( const std::string &  vara,
const std::string &  varb 
) const

Returns the 2D scatter plot of particle amplitudes.

Parameters
varaFirst variable of which to draw the amplitude scatter plot
varbSecond variable of which to draw the amplitude scatter plot
Returns
ScatterGraph pointer
double Beam::Bunch::AmplitudeValue ( const Matrix< double > &  invcovmat,
const std::vector< double > &  means,
const std::vector< double > &  vec,
const double &  neps 
) const
private

Compute the transverse amplitude provided with S^-1 and the PS vector.

Parameters
invcovmatInverse of the covariance matrix
meansMap of the means of each variables
vecPhase space vector of the particle
nepsNormalised emittance of the bunch
void Beam::Bunch::Arrays ( const std::string &  var,
std::vector< double > &  samples,
std::vector< double > &  errors 
) const
private

Returns the value and unertainty arrays corresponding to the requested variable.

Parameters
varVariable of which to return the arrays
samplesArray of values
errorsArray of uncertainties
void Beam::Bunch::AssertContains ( const std::string &  var) const
inlineprivate

Checks if the variable is provided, throws if not.

const Variable& Beam::Bunch::Beta ( ) const
inline

Returns the Twiss parameter beta of the bunch.

Variable Beam::Bunch::Beta ( const std::string  axis) const

Returns the Twiss parameter beta of the bunch in one 2D projection.

bool Beam::Bunch::Contains ( const std::string &  var) const
inlineprivate

Checks if the variable is provided.

const size_t Beam::Bunch::CoreSize ( ) const
inline

Returns the size of the core sample.

const Matrix<double>& Beam::Bunch::CovarianceMatrix ( ) const
inline

Returns the covariance matrix of the bunch.

const size_t& Beam::Bunch::Dimension ( ) const
inline

Returns the dimension of space in which the bunch lives.

TEllipse * Beam::Bunch::Ellipse ( const std::string &  vara,
const std::string &  varb,
const double  p = .39347 
) const

Returns the n-RMS ellipse of a sample of two variables.

The default probability corresponds to the $1\sigma$ contour.

Parameters
varaFirst variable in which to compute the RMS ellipse
varbSecond variable in which to compute the RMS ellipse
pP-value of the distribution (probability content)
Returns
n-RMS TEllipse pointer
const Variable& Beam::Bunch::Emittance ( ) const
inline

Returns the RMS normalised emittance of the bunch.

const std::vector< double > & Beam::Bunch::Errors ( const std::string  var) const

Returns the array of errors on the samples of variable var.

const Variable& Beam::Bunch::FracEmittance ( ) const
inline

Returns the volume of the core.

const Variable Beam::Bunch::Gamma ( ) const
inline

Returns the Twiss parameter gamma of the bunch.

Variable Beam::Bunch::Gamma ( const std::string  axis) const

Returns the Twiss parameter gamma of the bunch in one 2D projection.

TH1F * Beam::Bunch::Histogram ( const std::string &  var,
double  min = 0,
double  max = 0 
) const

Returns the 1D distrubution of the requested variable.

Parameters
varName of the variable of which to draw the distribution
minMinimum of the range of var
maxMaximum of the range of var
Returns
TH1F pointer
TH2F * Beam::Bunch::Histogram ( const std::string &  vara,
const std::string &  varb,
double  mina = 0,
double  maxa = 0,
double  minb = 0,
double  maxb = 0 
) const

Returns the 2D distrubution of the requested variable.

Parameters
varaFirst variable of which to draw the distribution
varbSecond variable of which to draw the distribution
minaMinimum of the range of vara
maxaMaximum of the range of vara
minbMinimum of the range of varb
maxbMaximum of the range of varb
Returns
ROOT TH2F pointer
void Beam::Bunch::Initialize ( const BunchMap &  samples,
const BunchMap &  errors 
)
private

Normal initializer, sets the particle sample and bunch variables.

Parameters
samplesDictionary that maps each variable onto a vector of values
errorsDictionary that maps each variable onto a vector of errors
const double& Beam::Bunch::Mass ( ) const
inline

Returns the mass of the particles that make up the beam [MeV/c^2].

Variable Beam::Bunch::Mean ( const std::string &  var) const

Returns the mean of the requested quantity.

const Variable& Beam::Bunch::MechanicalL ( ) const
inline

Returns the mechanical angular momentum of the bunch.

const std::string& Beam::Bunch::Name ( ) const
inline

Returns the name of the bunch.

const Variable& Beam::Bunch::NormEmittance ( ) const
inline

Returns the RMS geometric emittance of the bunch.

Variable Beam::Bunch::NormEmittanceEstimate ( const SumStat &  stat) const

Returns the estimated normalised emittance from the measured fractional quantity.

double Beam::Bunch::NormEmittanceValue ( const Matrix< double > &  covmat) const
private

Computes the RMS emittance provided with the covariance matrix.

Bunch & Beam::Bunch::operator= ( const Bunch &  bunch)

Equality operator.

const double& Beam::Bunch::Position ( ) const
inline

Returns the z position at which the bunch was sampled [mm].

std::vector< double > Beam::Bunch::Radii ( ) const

Returns the array of radii of the samples.

double Beam::Bunch::Radius ( const size_t  i) const

Returns the radius of the i^th sample.

TEllipse * Beam::Bunch::RobustEllipse ( const std::string &  vara,
const std::string &  varb,
const double  p = .39347 
) const

Returns the n-RMS robust ellipse of a sample of two variables.

Parameters
varaFirst variable in which to compute the RMS ellipse
varbSecond variable in which to compute the RMS ellipse
pP-value of the distribution (probability content)
Returns
Robust n-RMS TEllipse pointer
const std::vector< double > & Beam::Bunch::Samples ( const std::string  var) const

Returns the array of samples of variable var.

void Beam::Bunch::SetAmplitudeQuantile ( const double &  qamp)
private

Sets the amplitude quantile and its uncertainty.

void Beam::Bunch::SetAmplitudes ( )
private

Compute the transverse amplitudes of every particle in the sample.

void Beam::Bunch::SetCoreFraction ( const double  frac)

Defines the fraction of the beam contained in the core.

Parameters
fracFraction of the initial bunch to be kept
void Beam::Bunch::SetCoreSize ( const size_t  size)

Assigns a certain amount of core particles.

Parameters
sizeNumber of particles to be kept
void Beam::Bunch::SetCoreVolume ( const std::string  algo = "hull",
const double  norm = 1. 
)

Computes the volume of the fraction of the beam contained in the core.

Parameters
algoVolume reconstruction algorithm
normNormalisation constant if the bunch has scraped
void Beam::Bunch::SetCorrectedAmplitudes ( )

Compute the corrected transverse amplitudes of every particle in the sample by only considering particles of lower amplitudes.

void Beam::Bunch::SetEmittance ( )
private

Computes the RMS geometric emittance of the bunch.

void Beam::Bunch::SetFraction ( const double  frac)
inline

Defines the fraction the core represents (in case of transmission losses)

void Beam::Bunch::SetGeneralisedAmplitudes ( const double  norm = 1.)

Compute the generalised transverse amplitude of every particle in the sample by basing it on density estimation and contour volume rather than covariance.

Parameters
normNormalisation constant (if the distribution is truncated)
void Beam::Bunch::SetMCDAmplitudes ( )

Compute the MCD transverse amplitude of every particle in the sample by selecting a subsample optimized based on its covariance determinant.

void Beam::Bunch::SetName ( const std::string &  name)
inline

Sets the name of the bunch.

void Beam::Bunch::SetNormEmittance ( )
private

Computes the RMS normalised emittance of the bunch.

void Beam::Bunch::SetPosition ( const double &  pos)
inline

Sets the position of the bunch.

void Beam::Bunch::SetSubEmittance ( )
private

Computes the subemittance of the core.

void Beam::Bunch::SetTwiss ( )
private

Computes the Twiss parameter alpha of the bunch.

void Beam::Bunch::SetVoronoiVolumes ( )

Compute the Voronoi volumes around each particle.

This is not done by default as it takes a long time (need to tesselate the 4D space).

Does not do anything if it has already been called.

const size_t Beam::Bunch::Size ( ) const
inline

Returns the size of the whole sample.

const Variable& Beam::Bunch::SubEmittance ( ) const
inline

Returns the subemittance of the core.

Variable Beam::Bunch::SummaryStatistic ( const SumStat &  stat) const

Returns the requested summary statistic.

std::vector< double > Beam::Bunch::TotalMomenta ( ) const
private

Returns the total momentum of all the samples.

double Beam::Bunch::TotalMomentum ( const size_t  i) const
private

Returns the total momentum of a given sample.

double Beam::Bunch::TotalMomentumError ( const size_t  i) const
private

Returns the error on the total momentum of a given sample.

std::vector< double > Beam::Bunch::TotalMomentumErrors ( ) const
private

Returns the error on the total momentum of all the samples.

double Beam::Bunch::TwissMError ( const std::string &  name,
std::map< std::string, double > &  means,
const double &  detr,
const Matrix< double > &  C 
) const
private

Computes the measurement error on the requested Twiss parameter.

Parameters
nameName of the Twiss parameter
meansMap of the means for each variables
detrErrors on the determinant of the optical covariance matrix
CCofactor matrix of the optical covariance matrix
double Beam::Bunch::TwissSError ( const double &  twiss) const
private

Computes the statistical error on the provided Twiss parameter.

Parameters
twissValue of the twiss parameter
const std::vector<double>& Beam::Bunch::VoronoiVolumes ( ) const
inline

Returns the array of Voronoi volumes of the samples.

Field Documentation

Variable Beam::Bunch::_alpha
private

Twiss parameter alpha.

std::vector<double> Beam::Bunch::_amps
private

Amplitudes of the particles.

Variable Beam::Bunch::_beta
private

Twiss parameter beta.

BunchData Beam::Bunch::_core
private

Core fraction of beam.

BunchData Beam::Bunch::_data
private

Underlying phase space vectors.

DensityEstimator Beam::Bunch::_de
private

Density estimation of the bunch.

size_t Beam::Bunch::_dim
private

Dimension of the transverse phase space.

Variable Beam::Bunch::_eps
private

Geometric RMS emittance.

Variable Beam::Bunch::_feps
private

Fractional emittance.

double Beam::Bunch::_fraction
private

Fraction contained in the beam core.

Variable Beam::Bunch::_gamma
private

Twiss parameter gamma.

double Beam::Bunch::_mass
private

Mass of the particles.

Variable Beam::Bunch::_mecl
private

Normalised mechanical angular momentum.

std::string Beam::Bunch::_name
private

Name of the bunch.

Variable Beam::Bunch::_neps
private

Normalised RMS emittance.

double Beam::Bunch::_pos
private

Position at which the bunch was sampled.

Variable Beam::Bunch::_qamp
private

Lagest amplitude in the core.

Variable Beam::Bunch::_seps
private

Subemittance.

std::vector<double> Beam::Bunch::_vols
private

Voronoi cell volumes of the particles.


The documentation for this class was generated from the following files: