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