CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

XF.cc

Go to the documentation of this file.
00001 #include "CLHEP/Fields/XF.h"
00002 #include <assert.h>
00003 #include <iostream>
00004 namespace XF
00005 {
00006 
00007 
00008 
00009   //------------------------------------------------------------------//
00010   //                                                                  //
00011   //  Implementation of Function                                      //
00012   //                                                                  //
00013   //------------------------------------------------------------------//
00014 
00015   Function::Function ()
00016   {
00017   }
00018 
00019   Function::~Function ()
00020   {
00021   }
00022 
00023   Product operator * (const Function & a, const Function & b)
00024   {
00025     return Product (&a, &b);
00026   }
00027 
00028   PreMult operator * (const HepGeom::Transform3D & xf, const Function & b)
00029   {
00030     return PreMult (xf, &b);
00031   }
00032 
00033   PostMult operator * (const Function & a, const HepGeom::Transform3D & xf)
00034   {
00035     return PostMult (&a, xf);
00036   }
00037 
00038   unsigned int Function::dimensionality () const
00039   {
00040     return 1;
00041   }
00042 
00043   //------------------------------------------------------------------//
00044   //                                                                  //
00045   //  Implementation of Product                                       //
00046   //                                                                  //
00047   //------------------------------------------------------------------//
00048 
00049   Product::Product (const Function * arg1,
00050                     const Function * arg2):_arg1 (arg1->clone ()),
00051     _arg2 (arg2->clone ())
00052   {
00053     if (arg1->dimensionality () != arg2->dimensionality ())
00054       {
00055         std::cout <<"Warning:  dimension mismatch in XF::Product" << std::endl;
00056         assert(0);
00057       }
00058   }
00059 
00060 
00061   // Every function must override this:
00062   Product *Product::clone () const
00063   {
00064     return new Product (*this);
00065   }
00066 
00067   // Copy constructor:
00068   Product::Product (const Product & right):Function (),
00069     _arg1 (right._arg1->clone ()), _arg2 (right._arg2->clone ())
00070   {
00071   }
00072 
00073 
00074   Product::~Product ()
00075   {
00076     delete _arg1;
00077     delete _arg2;
00078   }
00079 
00080   unsigned int Product::dimensionality () const
00081   {
00082     return _arg1->dimensionality ();
00083   }
00084 
00085   HepGeom::Transform3D Product::operator        () (double x) const
00086   {
00087     return (*_arg1) (x) * (*_arg2) (x);
00088   }
00089 
00090   HepGeom::Transform3D Product::operator        () (const Genfun::Argument & x) const
00091   {
00092     return (*_arg1) (x) * (*_arg2) (x);
00093   }
00094 
00095 
00096 
00097   //------------------------------------------------------------------//
00098   //                                                                  //
00099   //  Implementation of PreMult                                       //
00100   //                                                                  //
00101   //------------------------------------------------------------------//
00102 
00103   PreMult::PreMult (const HepGeom::Transform3D & arg1,
00104                     const Function * arg2):_arg1 (arg1),
00105     _arg2 (arg2->clone ())
00106   {
00107   }
00108 
00109 
00110   // Every function must override this:
00111   PreMult *PreMult::clone () const
00112   {
00113     return new PreMult (*this);
00114   }
00115 
00116   // Copy constructor:
00117   PreMult::PreMult (const PreMult & right):Function (), _arg1 (right._arg1),
00118     _arg2 (right._arg2->clone ())
00119   {
00120   }
00121 
00122 
00123   PreMult::~PreMult ()
00124   {
00125     delete _arg2;
00126   }
00127 
00128   unsigned int PreMult::dimensionality () const
00129   {
00130     return _arg2->dimensionality ();
00131   }
00132 
00133   HepGeom::Transform3D PreMult::operator        () (double x) const
00134   {
00135     return _arg1 * (*_arg2) (x);
00136   }
00137 
00138   HepGeom::Transform3D PreMult::operator        () (const Genfun::Argument & x) const
00139   {
00140     return _arg1 * (*_arg2) (x);
00141   }
00142 
00143 
00144   //------------------------------------------------------------------//
00145   //                                                                  //
00146   //  Implementation of PostMult                                      //
00147   //                                                                  //
00148   //------------------------------------------------------------------//
00149 
00150   PostMult::PostMult (const Function * arg1,
00151                       const HepGeom::Transform3D & arg2):_arg1 (arg1->clone ()),
00152     _arg2 (arg2)
00153   {
00154   }
00155 
00156 
00157   // Every function must override this:
00158   PostMult *PostMult::clone () const
00159   {
00160     return new PostMult (*this);
00161   }
00162 
00163   // Copy constructor:
00164   PostMult::PostMult (const PostMult & right):Function (),
00165     _arg1 (right._arg1->clone ()), _arg2 (right._arg2)
00166   {
00167   }
00168 
00169 
00170   PostMult::~PostMult ()
00171   {
00172     delete _arg1;
00173   }
00174 
00175   unsigned int PostMult::dimensionality () const
00176   {
00177     return _arg1->dimensionality ();
00178   }
00179 
00180   HepGeom::Transform3D PostMult::operator        () (double x) const
00181   {
00182     return (*_arg1) (x) * _arg2;
00183   }
00184 
00185   HepGeom::Transform3D PostMult::operator        () (const Genfun::Argument & x) const
00186   {
00187     return (*_arg1) (x) * _arg2;
00188   }
00189 
00190 
00191   Pow::Pow (const HepGeom::Transform3D & xform, Genfun::GENFUNCTION f):xf (xform),
00192     function (f.clone ())
00193   {
00194   }
00195 
00196   Pow::~Pow ()
00197   {
00198     delete function;
00199   }
00200 
00201   HepGeom::Transform3D Pow::operator        () (double x) const
00202   {
00203     //
00204     // Get the translation part and the rotation part:
00205     //
00206     CLHEP::HepRotation rotate = xf.getRotation ();
00207     CLHEP::Hep3Vector translate = xf.getTranslation ();
00208     CLHEP::HepAxisAngle aa = rotate.axisAngle ();
00209     //
00210     // Evaluate the function
00211     //
00212     double nTimes = (*function) (x);
00213     //
00214     // Modify:
00215     //
00216       translate *= nTimes;
00217       aa.setDelta (aa.delta () * nTimes);
00218     //
00219     // Now compose these and return a result:
00220     //
00221       return HepGeom::Translate3D (translate) * HepGeom::Rotate3D (aa.delta (),
00222                                                        aa.axis ());
00223   }
00224 
00225   HepGeom::Transform3D Pow::operator        () (const Genfun::Argument & argument) const
00226   {
00227     return operator        () (argument[0]);
00228   }
00229 
00230   Pow *Pow::clone () const
00231   {
00232     return new Pow (*this);
00233   }
00234 
00235   Pow::Pow (const Pow & right):Function (), xf (right.xf),
00236     function (right.function->clone ())
00237   {
00238   }
00239 
00240 }

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7