IBSimu 1.0.4
trajectorydiagnostics.hpp
Go to the documentation of this file.
00001 
00005 /* Copyright (c) 2005-2010 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 
00054 class TrajectoryDiagnosticColumn 
00055 {
00056 
00057     trajectory_diagnostic_e _diag; 
00058     std::vector<double>     _data; 
00060 public:
00061 
00062     TrajectoryDiagnosticColumn( trajectory_diagnostic_e diag ) 
00063         : _diag(diag) {}
00064 
00072     void mirror( coordinate_axis_e axis, double level );
00073 
00074     void add_data( double x ) {
00075         _data.push_back( x );
00076     }
00077 
00078     std::vector<double> &data( void ) { return( _data ); }
00079 
00080     const std::vector<double> &data( void ) const { return( _data ); }
00081 
00082     size_t size( void ) const { return( _data.size() ); }
00083 
00084     trajectory_diagnostic_e diagnostic( void ) const { return( _diag ); }
00085 
00086     const double &operator()( size_t i ) const { return( _data[i] ); }
00087 
00088     double &operator()( size_t i ) { return( _data[i] ); }
00089 
00090     const double &operator[]( size_t i ) const { return( _data[i] ); }
00091 
00092     double &operator[]( size_t i ) { return( _data[i] ); }
00093 
00094 };
00095 
00096 
00099 class TrajectoryDiagnosticData 
00100 {
00101 
00102     std::vector<TrajectoryDiagnosticColumn> _column; 
00104 public:
00105 
00106     TrajectoryDiagnosticData() {}
00107 
00108     TrajectoryDiagnosticData( std::vector<trajectory_diagnostic_e> diag ) {
00109         for( size_t a = 0; a < diag.size(); a++ )
00110             _column.push_back( TrajectoryDiagnosticColumn( diag[a] ) );
00111     }
00112 
00113     void mirror( coordinate_axis_e axis, double level ) {
00114         for( size_t a = 0; a < _column.size(); a++ )
00115             _column[a].mirror( axis, level );
00116     }
00117 
00118     void clear() {
00119         _column.clear();
00120     }
00121     
00122     void add_data_column( trajectory_diagnostic_e diag ) {
00123         _column.push_back( TrajectoryDiagnosticColumn( diag ) );
00124     }
00125 
00126     size_t diag_size() const {
00127         return( _column.size() );
00128     }
00129 
00130     size_t traj_size() const {
00131         if( _column.size() > 0 )
00132             return( _column[0].size() );
00133         return( 0 );
00134     }
00135 
00136     trajectory_diagnostic_e diagnostic( size_t diag ) const {
00137         return( _column[diag].diagnostic() ); 
00138     }
00139 
00140     const TrajectoryDiagnosticColumn &operator()( size_t diag ) const {
00141         return( _column[diag] );
00142     }
00143 
00144     TrajectoryDiagnosticColumn &operator()( size_t diag ) {
00145         return( _column[diag] );
00146     }
00147 
00148     const double &operator()( size_t traj, size_t diag ) const {
00149         return( _column[diag](traj) );
00150     }
00151 
00152     double &operator()( size_t traj, size_t diag ) {
00153         return( _column[diag](traj) );
00154     }
00155 
00156     void add_data( size_t diag, double x ) {
00157         _column[diag].add_data( x );
00158     }
00159 };
00160 
00161 
00181 class Emittance
00182 {
00183 protected:
00184 
00185     double _Isum;
00186 
00187     double _xave;
00188     double _xpave;
00189 
00190     double _x2;
00191     double _xp2;
00192     double _xxp;
00193 
00194     double _alpha;
00195     double _beta;
00196     double _gamma;
00197     double _epsilon;
00198 
00199     double _angle;
00200     double _rmajor;
00201     double _rminor;
00202 
00203 public:
00204 
00207     Emittance();
00208 
00212     Emittance( const std::vector<double> &x,
00213                const std::vector<double> &xp,
00214                const std::vector<double> &I );
00215 
00219     Emittance( const std::vector<double> &x,
00220                const std::vector<double> &xp );
00221 
00222     double xave( void ) { return( _xave ); }
00223     double xpave( void ) { return( _xpave ); }
00224 
00225     double alpha( void ) { return( _alpha ); }
00226     double beta( void ) { return( _beta ); }
00227     double gamma( void ) { return( _gamma ); }
00228     double epsilon( void ) { return( _epsilon ); }
00229 
00230     double angle( void ) { return( _angle ); }
00231     double rmajor( void ) { return( _rmajor ); }
00232     double rminor( void ) { return( _rminor ); } 
00233 };
00234 
00235 
00236 
00241 class EmittanceConv : public Emittance
00242 {
00243 
00244     Histogram2D *_grid;
00245 
00246 public:
00247 
00263     EmittanceConv( int n, int m,
00264                    const std::vector<double> &r,
00265                    const std::vector<double> &rp,
00266                    const std::vector<double> &ap,
00267                    const std::vector<double> &I );
00268 
00271     ~EmittanceConv();
00272 
00275     const Histogram2D &histogram( void ) const { return( *_grid ); }
00276 
00279     void free_histogram( void ) { delete _grid; _grid = NULL; }
00280 };
00281 
00282 
00283 #endif
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301