CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/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 #include "FWCore/Utilities/interface/Visibility.h"
00023 
00024 class dso_internal Trapezoid2RectangleMappingX {
00025 public:
00026 
00027   Trapezoid2RectangleMappingX() {}
00028 
00030   Trapezoid2RectangleMappingX( double x0, double y0, double bovera, double h) :
00031     x0_(x0), y0_(y0), parallel_(false)
00032   {
00033     k_ = 2/h * (bovera-1.) / (bovera+1.);
00034 
00035 #ifdef DEBUG_GRID_TRM
00036     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 
00037          << " b/a= " << bovera << " h= " << h << std::endl;
00038 #endif
00039   }
00040 
00042   Trapezoid2RectangleMappingX( double x0, double y0, double k) :
00043     x0_(x0), y0_(y0), k_(k), parallel_(true)
00044   {
00045 #ifdef DEBUG_GRID_TRM
00046     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 
00047          << " k= " << k << std::endl;
00048 #endif
00049   }
00050 
00051   void rectangle( double xtrap, double ytrap, 
00052                   double& xrec, double& yrec) const {
00053 
00054     yrec = ytrap - y0_;
00055     if (!parallel_) xrec = (xtrap - x0_) / (1.+ yrec*k_);
00056     else            xrec = xtrap - x0_ + k_*yrec;
00057 
00058 #ifdef DEBUG_GRID
00059     std::cout << xtrap << " " << ytrap << " transformed to rectangle " << xrec << " " << yrec << std::endl;
00060 #endif
00061   }
00062 
00063   void trapezoid( double xrec, double yrec, 
00064                   double& xtrap, double& ytrap) const {
00065     if (!parallel_) xtrap = x0_ + xrec * (1.+ yrec*k_);
00066     else            xtrap = x0_ + xrec - k_*yrec;
00067     ytrap = y0_ + yrec;
00068 
00069 #ifdef DEBUG_GRID
00070     std::cout << xrec << " " << yrec << " transformed to trapezoid " << xtrap << " " << ytrap << std::endl;
00071 #endif
00072   }
00073 
00074 private:
00075   double x0_;
00076   double y0_;
00077   double k_;
00078   bool parallel_;
00079 };
00080 
00081 #endif