trajectorydiagnostics.hpp
Go to the documentation of this file.
00001 
00005 /* Copyright (c) 2005-2011 Taneli Kalvas. All rights reserved.
00006  *
00007  * You can redistribute this software and/or modify it under the terms
00008  * of the GNU General Public License as published by the Free Software
00009  * Foundation; either version 2 of the License, or (at your option)
00010  * any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this library (file "COPYING" included in the package);
00019  * if not, write to the Free Software Foundation, Inc., 51 Franklin
00020  * Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  * 
00022  * If you have questions about your rights to use or distribute this
00023  * software, please contact Berkeley Lab's Technology Transfer
00024  * Department at TTD@lbl.gov. Other questions, comments and bug
00025  * reports should be sent directly to the author via email at
00026  * taneli.kalvas@jyu.fi.
00027  * 
00028  * NOTICE. This software was developed under partial funding from the
00029  * U.S.  Department of Energy.  As such, the U.S. Government has been
00030  * granted for itself and others acting on its behalf a paid-up,
00031  * nonexclusive, irrevocable, worldwide license in the Software to
00032  * reproduce, prepare derivative works, and perform publicly and
00033  * display publicly.  Beginning five (5) years after the date
00034  * permission to assert copyright is obtained from the U.S. Department
00035  * of Energy, and subject to any subsequent five (5) year renewals,
00036  * the U.S. Government is granted for itself and others acting on its
00037  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
00038  * the Software to reproduce, prepare derivative works, distribute
00039  * copies to the public, perform publicly and display publicly, and to
00040  * permit others to do so.
00041  */
00042 
00043 #ifndef TRAJECTORYDIAGNOSTICS_HPP
00044 #define TRAJECTORYDIAGNOSTICS_HPP 1
00045 
00046 
00047 #include <vector>
00048 #include "histogram.hpp"
00049 #include "types.hpp"
00050 
00051 
00060 class TrajectoryDiagnosticColumn 
00061 {
00062 
00063     trajectory_diagnostic_e _diag; 
00064     std::vector<double>     _data; 
00066 public:
00067 
00070     TrajectoryDiagnosticColumn( trajectory_diagnostic_e diag ) 
00071         : _diag(diag) {}
00072 
00080     void mirror( coordinate_axis_e axis, double level );
00081 
00084     void add_data( double x ) {
00085         _data.push_back( x );
00086     }
00087 
00090     std::vector<double> &data( void ) { return( _data ); }
00091 
00094     const std::vector<double> &data( void ) const { return( _data ); }
00095 
00098     size_t size( void ) const { return( _data.size() ); }
00099 
00102     trajectory_diagnostic_e diagnostic( void ) const { return( _diag ); }
00103 
00106     const double &operator()( size_t i ) const { return( _data[i] ); }
00107 
00110     double &operator()( size_t i ) { return( _data[i] ); }
00111 
00114     const double &operator[]( size_t i ) const { return( _data[i] ); }
00115 
00118     double &operator[]( size_t i ) { return( _data[i] ); }
00119 };
00120 
00121 
00126 class TrajectoryDiagnosticData 
00127 {
00128 
00129     std::vector<TrajectoryDiagnosticColumn> _column; 
00131 public:
00132 
00135     TrajectoryDiagnosticData() {}
00136 
00139     TrajectoryDiagnosticData( std::vector<trajectory_diagnostic_e> diag ) {
00140         for( size_t a = 0; a < diag.size(); a++ )
00141             _column.push_back( TrajectoryDiagnosticColumn( diag[a] ) );
00142     }
00143 
00146     void mirror( coordinate_axis_e axis, double level ) {
00147         for( size_t a = 0; a < _column.size(); a++ )
00148             _column[a].mirror( axis, level );
00149     }
00150 
00153     void clear() {
00154         _column.clear();
00155     }
00156     
00159     void add_data_column( trajectory_diagnostic_e diag ) {
00160         _column.push_back( TrajectoryDiagnosticColumn( diag ) );
00161     }
00162 
00165     size_t diag_size() const {
00166         return( _column.size() );
00167     }
00168 
00171     size_t traj_size() const {
00172         if( _column.size() > 0 )
00173             return( _column[0].size() );
00174         return( 0 );
00175     }
00176 
00179     trajectory_diagnostic_e diagnostic( size_t i ) const {
00180         return( _column[i].diagnostic() ); 
00181     }
00182 
00185     const TrajectoryDiagnosticColumn &operator()( size_t i ) const {
00186         return( _column[i] );
00187     }
00188 
00191     TrajectoryDiagnosticColumn &operator()( size_t i ) {
00192         return( _column[i] );
00193     }
00194 
00198     const double &operator()( size_t j, size_t i ) const {
00199         return( _column[i](j) );
00200     }
00201 
00205     double &operator()( size_t j, size_t i ) {
00206         return( _column[i](j) );
00207     }
00208 
00211     void add_data( size_t i, double x ) {
00212         _column[i].add_data( x );
00213     }
00214 };
00215 
00216 
00236 class Emittance
00237 {
00238 protected:
00239 
00240     double _Isum;
00241 
00242     double _xave;
00243     double _xpave;
00244 
00245     double _x2;
00246     double _xp2;
00247     double _xxp;
00248 
00249     double _alpha;
00250     double _beta;
00251     double _gamma;
00252     double _epsilon;
00253 
00254     double _angle;
00255     double _rmajor;
00256     double _rminor;
00257 
00258 public:
00259 
00262     Emittance();
00263 
00267     Emittance( const std::vector<double> &x,
00268                const std::vector<double> &xp,
00269                const std::vector<double> &I );
00270 
00274     Emittance( const std::vector<double> &x,
00275                const std::vector<double> &xp );
00276 
00286     Emittance( size_t xsize, size_t xpsize, const double range[4],
00287                const std::vector<double> &I );
00288 
00291     double xave( void ) const { return( _xave ); }
00292 
00295     double xpave( void ) const { return( _xpave ); }
00296 
00299     double alpha( void ) const { return( _alpha ); }
00300 
00303     double beta( void ) const { return( _beta ); }
00304 
00307     double gamma( void ) const { return( _gamma ); }
00308 
00311     double epsilon( void ) const { return( _epsilon ); }
00312 
00315     double angle( void ) const { return( _angle ); }
00316 
00319     double rmajor( void ) const { return( _rmajor ); }
00320 
00323     double rminor( void ) const { return( _rminor ); } 
00324 
00327     void debug_print( std::ostream &os ) const;
00328 };
00329 
00330 
00331 
00336 class EmittanceConv : public Emittance
00337 {
00338 
00339     Histogram2D *_grid;
00340 
00341 public:
00342 
00358     EmittanceConv( int n, int m,
00359                    const std::vector<double> &r,
00360                    const std::vector<double> &rp,
00361                    const std::vector<double> &ap,
00362                    const std::vector<double> &I );
00363 
00366     ~EmittanceConv();
00367 
00370     const Histogram2D &histogram( void ) const { return( *_grid ); }
00371 
00374     void free_histogram( void ) { delete _grid; _grid = NULL; }
00375 };
00376 
00377 
00378 #endif
00379