trajectorydiagnostics.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef TRAJECTORYDIAGNOSTICS_HPP
44 #define TRAJECTORYDIAGNOSTICS_HPP 1
45 
46 
47 #include <vector>
48 #include "histogram.hpp"
49 #include "types.hpp"
50 
51 
61 {
62 
64  std::vector<double> _data;
66 public:
67 
71  : _diag(diag) {}
72 
80  void mirror( coordinate_axis_e axis, double level );
81 
84  void add_data( double x ) {
85  _data.push_back( x );
86  }
87 
90  std::vector<double> &data( void ) { return( _data ); }
91 
94  const std::vector<double> &data( void ) const { return( _data ); }
95 
98  size_t size( void ) const { return( _data.size() ); }
99 
102  trajectory_diagnostic_e diagnostic( void ) const { return( _diag ); }
103 
106  const double &operator()( size_t i ) const { return( _data[i] ); }
107 
110  double &operator()( size_t i ) { return( _data[i] ); }
111 
114  const double &operator[]( size_t i ) const { return( _data[i] ); }
115 
118  double &operator[]( size_t i ) { return( _data[i] ); }
119 };
120 
121 
127 {
128 
129  std::vector<TrajectoryDiagnosticColumn> _column;
131 public:
132 
136 
139  TrajectoryDiagnosticData( std::vector<trajectory_diagnostic_e> diag ) {
140  for( size_t a = 0; a < diag.size(); a++ )
141  _column.push_back( TrajectoryDiagnosticColumn( diag[a] ) );
142  }
143 
146  void mirror( coordinate_axis_e axis, double level ) {
147  for( size_t a = 0; a < _column.size(); a++ )
148  _column[a].mirror( axis, level );
149  }
150 
153  void clear() {
154  _column.clear();
155  }
156 
160  _column.push_back( TrajectoryDiagnosticColumn( diag ) );
161  }
162 
165  size_t diag_size() const {
166  return( _column.size() );
167  }
168 
171  size_t traj_size() const {
172  if( _column.size() > 0 )
173  return( _column[0].size() );
174  return( 0 );
175  }
176 
180  return( _column[i].diagnostic() );
181  }
182 
185  const TrajectoryDiagnosticColumn &operator()( size_t i ) const {
186  return( _column[i] );
187  }
188 
192  return( _column[i] );
193  }
194 
198  const double &operator()( size_t j, size_t i ) const {
199  return( _column[i](j) );
200  }
201 
205  double &operator()( size_t j, size_t i ) {
206  return( _column[i](j) );
207  }
208 
211  void add_data( size_t i, double x ) {
212  _column[i].add_data( x );
213  }
214 };
215 
216 
237 {
238 protected:
239 
240  double _Isum;
241 
242  double _xave;
243  double _xpave;
244 
245  double _x2;
246  double _xp2;
247  double _xxp;
248 
249  double _alpha;
250  double _beta;
251  double _gamma;
252  double _epsilon;
253 
254  double _angle;
255  double _rmajor;
256  double _rminor;
257 
258 public:
259 
262  Emittance();
263 
267  Emittance( const std::vector<double> &x,
268  const std::vector<double> &xp,
269  const std::vector<double> &I );
270 
274  Emittance( const std::vector<double> &x,
275  const std::vector<double> &xp );
276 
286  Emittance( size_t xsize, size_t xpsize, const double range[4],
287  const std::vector<double> &I );
288 
291  double xave( void ) const { return( _xave ); }
292 
295  double xpave( void ) const { return( _xpave ); }
296 
299  double alpha( void ) const { return( _alpha ); }
300 
303  double beta( void ) const { return( _beta ); }
304 
307  double gamma( void ) const { return( _gamma ); }
308 
311  double epsilon( void ) const { return( _epsilon ); }
312 
315  double angle( void ) const { return( _angle ); }
316 
319  double rmajor( void ) const { return( _rmajor ); }
320 
323  double rminor( void ) const { return( _rminor ); }
324 
327  void debug_print( std::ostream &os ) const;
328 };
329 
330 
331 
336 class EmittanceConv : public Emittance
337 {
338 
339  Histogram2D *_grid;
340 
341 public:
342 
358  EmittanceConv( int n, int m,
359  const std::vector<double> &r,
360  const std::vector<double> &rp,
361  const std::vector<double> &ap,
362  const std::vector<double> &I );
363 
366  ~EmittanceConv();
367 
370  const Histogram2D &histogram( void ) const { return( *_grid ); }
371 
374  void free_histogram( void ) { delete _grid; _grid = NULL; }
375 };
376 
377 
378 #endif
379 
double xave(void) const
Return average position (center location) of emittance distribution.
Definition: trajectorydiagnostics.hpp:291
trajectory_diagnostic_e
Type of diagnostic for trajectories.
Definition: types.hpp:165
double _xave
Definition: trajectorydiagnostics.hpp:242
TrajectoryDiagnosticData()
Create new empty diagnostic data object.
Definition: trajectorydiagnostics.hpp:135
size_t size(void) const
Get size of diagnostic data vector.
Definition: trajectorydiagnostics.hpp:98
double epsilon(void) const
Return rms emittance.
Definition: trajectorydiagnostics.hpp:311
double _xp2
Definition: trajectorydiagnostics.hpp:246
void mirror(coordinate_axis_e axis, double level)
Mirror data columns along plane at axis = level.
Definition: trajectorydiagnostics.hpp:146
Histogram data handling for 1D and 2D
double beta(void) const
Return of emittance distribution.
Definition: trajectorydiagnostics.hpp:303
Class for trajectory diagnostic data column.
Definition: trajectorydiagnostics.hpp:60
void clear()
Clear all data and diagnostic types.
Definition: trajectorydiagnostics.hpp:153
trajectory_diagnostic_e diagnostic(void) const
Get diagnostic type.
Definition: trajectorydiagnostics.hpp:102
void free_histogram(void)
Free emittance histogram.
Definition: trajectorydiagnostics.hpp:374
Base types.
double _angle
Definition: trajectorydiagnostics.hpp:254
double _xpave
Definition: trajectorydiagnostics.hpp:243
void add_data(size_t i, double x)
Add data point to i:th diagnostic column.
Definition: trajectorydiagnostics.hpp:211
void mirror(coordinate_axis_e axis, double level)
Add mirrored trajectory diagnostic data to the column.
Emittance()
Default constructor for emittance statistics.
size_t diag_size() const
Return number of data columns.
Definition: trajectorydiagnostics.hpp:165
Class for emittance statistics.
Definition: trajectorydiagnostics.hpp:236
void debug_print(std::ostream &os) const
Print debugging information to os.
Class for trajectory diagnostic data.
Definition: trajectorydiagnostics.hpp:126
const double & operator()(size_t j, size_t i) const
Return const reference to j:th trajectory data in i:th diagnostic column.
Definition: trajectorydiagnostics.hpp:198
double rminor(void) const
Return minor radius of fitted rms ellipse.
Definition: trajectorydiagnostics.hpp:323
std::vector< double > & data(void)
Get a reference to diagnostic data vector.
Definition: trajectorydiagnostics.hpp:90
TrajectoryDiagnosticData(std::vector< trajectory_diagnostic_e > diag)
Create diagnostic data object with diagnostic types defined in vector diag.
Definition: trajectorydiagnostics.hpp:139
size_t traj_size() const
Return number of trajectories in data.
Definition: trajectorydiagnostics.hpp:171
double _beta
Definition: trajectorydiagnostics.hpp:250
void add_data(double x)
Add diagnostic data point to column.
Definition: trajectorydiagnostics.hpp:84
void add_data_column(trajectory_diagnostic_e diag)
Add data column with type diag.
Definition: trajectorydiagnostics.hpp:159
double _x2
Definition: trajectorydiagnostics.hpp:245
double _gamma
Definition: trajectorydiagnostics.hpp:251
double xpave(void) const
Return average angle (center location) of emittance distribution.
Definition: trajectorydiagnostics.hpp:295
double & operator[](size_t i)
Get reference to data element i.
Definition: trajectorydiagnostics.hpp:118
Class for 2d histogram type representation of data.
Definition: histogram.hpp:186
double gamma(void) const
Return of emittance distribution.
Definition: trajectorydiagnostics.hpp:307
coordinate_axis_e
Coordinate axis identifier.
Definition: types.hpp:139
double _alpha
Definition: trajectorydiagnostics.hpp:249
double angle(void) const
Return angle of fitted rms ellipse.
Definition: trajectorydiagnostics.hpp:315
double alpha(void) const
Return of emittance distribution.
Definition: trajectorydiagnostics.hpp:299
Class for emittance conversion from (r,r') to (x,x')
Definition: trajectorydiagnostics.hpp:336
const double & operator()(size_t i) const
Get const reference to data element i.
Definition: trajectorydiagnostics.hpp:106
double _epsilon
Definition: trajectorydiagnostics.hpp:252
EmittanceConv(int n, int m, const std::vector< double > &r, const std::vector< double > &rp, const std::vector< double > &ap, const std::vector< double > &I)
Constructor for (x,x') emittance data and statistics from (r,r') data.
const double & operator[](size_t i) const
Get const reference to data element i.
Definition: trajectorydiagnostics.hpp:114
double _rmajor
Definition: trajectorydiagnostics.hpp:255
const TrajectoryDiagnosticColumn & operator()(size_t i) const
Return i:th diagnostic type.
Definition: trajectorydiagnostics.hpp:185
~EmittanceConv()
Destructor for emittance converter.
trajectory_diagnostic_e diagnostic(size_t i) const
Return i:th diagnostic type.
Definition: trajectorydiagnostics.hpp:179
double _xxp
Definition: trajectorydiagnostics.hpp:247
double _rminor
Definition: trajectorydiagnostics.hpp:256
const Histogram2D & histogram(void) const
Get a const reference to histogram built.
Definition: trajectorydiagnostics.hpp:370
const std::vector< double > & data(void) const
Get a const reference to diagnostic data vector.
Definition: trajectorydiagnostics.hpp:94
TrajectoryDiagnosticColumn & operator()(size_t i)
Return i:th diagnostic column.
Definition: trajectorydiagnostics.hpp:191
double rmajor(void) const
Return major radius of fitted rms ellipse.
Definition: trajectorydiagnostics.hpp:319
double & operator()(size_t j, size_t i)
Return reference to j:th trajectory data in i:th diagnostic column.
Definition: trajectorydiagnostics.hpp:205
double & operator()(size_t i)
Get reference to data element i.
Definition: trajectorydiagnostics.hpp:110
double _Isum
Definition: trajectorydiagnostics.hpp:240
TrajectoryDiagnosticColumn(trajectory_diagnostic_e diag)
Create new diagnostic data column with type diag.
Definition: trajectorydiagnostics.hpp:70