CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/MagneticField/Interpolation/src/Trapezoid2RectangleMappingX.h

Go to the documentation of this file.
00001 #ifndef Trapezoid2RectangleMappingX_h
00002 #define Trapezoid2RectangleMappingX_h
00003 
00016 //#define DEBUG_GRID_TRM
00017 
00018 #ifdef DEBUG_GRID_TRM
00019 #include <iostream>
00020 #endif
00021 
00022 class Trapezoid2RectangleMappingX {
00023 public:
00024 
00025   Trapezoid2RectangleMappingX() {}
00026 
00028   Trapezoid2RectangleMappingX( double x0, double y0, double bovera, double h) :
00029     x0_(x0), y0_(y0), parallel_(false)
00030   {
00031     k_ = 2/h * (bovera-1.) / (bovera+1.);
00032 
00033 #ifdef DEBUG_GRID_TRM
00034     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 
00035          << " b/a= " << bovera << " h= " << h << std::endl;
00036 #endif
00037   }
00038 
00040   Trapezoid2RectangleMappingX( double x0, double y0, double k) :
00041     x0_(x0), y0_(y0), k_(k), parallel_(true)
00042   {
00043 #ifdef DEBUG_GRID_TRM
00044     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 
00045          << " k= " << k << std::endl;
00046 #endif
00047   }
00048 
00049   void rectangle( double xtrap, double ytrap, 
00050                   double& xrec, double& yrec) const {
00051 
00052     yrec = ytrap - y0_;
00053     if (!parallel_) xrec = (xtrap - x0_) / (1.+ yrec*k_);
00054     else            xrec = xtrap - x0_ + k_*yrec;
00055 
00056 #ifdef DEBUG_GRID
00057     std::cout << xtrap << " " << ytrap << " transformed to rectangle " << xrec << " " << yrec << std::endl;
00058 #endif
00059   }
00060 
00061   void trapezoid( double xrec, double yrec, 
00062                   double& xtrap, double& ytrap) const {
00063     if (!parallel_) xtrap = x0_ + xrec * (1.+ yrec*k_);
00064     else            xtrap = x0_ + xrec - k_*yrec;
00065     ytrap = y0_ + yrec;
00066 
00067 #ifdef DEBUG_GRID
00068     std::cout << xrec << " " << yrec << " transformed to trapezoid " << xtrap << " " << ytrap << std::endl;
00069 #endif
00070   }
00071 
00072 private:
00073   double x0_;
00074   double y0_;
00075   double k_;
00076   bool parallel_;
00077 };
00078 
00079 #endif