Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:32

0001 #ifndef Trapezoid2RectangleMappingX_h
0002 #define Trapezoid2RectangleMappingX_h
0003 
0004 /** \class Trapezoid2RectangleMappingX
0005  *
0006  *  Maps a trapezoidal coordinate system into a cartesian one.
0007  *  It is assumed that x is the coordinate along the trapezoid bases while y is along
0008  *  the trapezoid height.
0009  *
0010  *  \author T. Todorov
0011  */
0012 
0013 //#define DEBUG_GRID_TRM
0014 
0015 #ifdef DEBUG_GRID_TRM
0016 #include <iostream>
0017 #endif
0018 
0019 #include "FWCore/Utilities/interface/Visibility.h"
0020 
0021 class dso_internal Trapezoid2RectangleMappingX {
0022 public:
0023   Trapezoid2RectangleMappingX() {}
0024 
0025   /// normal trapezoid case, a != b
0026   Trapezoid2RectangleMappingX(double x0, double y0, double bovera, double h) : x0_(x0), y0_(y0), parallel_(false) {
0027     k_ = 2 / h * (bovera - 1.) / (bovera + 1.);
0028 
0029 #ifdef DEBUG_GRID_TRM
0030     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 << " b/a= " << bovera
0031               << " h= " << h << std::endl;
0032 #endif
0033   }
0034 
0035   /// special parallelogram case, a == b. The meaning of k changes.
0036   Trapezoid2RectangleMappingX(double x0, double y0, double k) : x0_(x0), y0_(y0), k_(k), parallel_(true) {
0037 #ifdef DEBUG_GRID_TRM
0038     std::cout << "Trapezoid2RectangleMappingX constructed with x0,y0 " << x0 << " " << y0 << " k= " << k << std::endl;
0039 #endif
0040   }
0041 
0042   void rectangle(double xtrap, double ytrap, double& xrec, double& yrec) const {
0043     yrec = ytrap - y0_;
0044     if (!parallel_)
0045       xrec = (xtrap - x0_) / (1. + yrec * k_);
0046     else
0047       xrec = xtrap - x0_ + k_ * yrec;
0048 
0049 #ifdef DEBUG_GRID
0050     std::cout << xtrap << " " << ytrap << " transformed to rectangle " << xrec << " " << yrec << std::endl;
0051 #endif
0052   }
0053 
0054   void trapezoid(double xrec, double yrec, double& xtrap, double& ytrap) const {
0055     if (!parallel_)
0056       xtrap = x0_ + xrec * (1. + yrec * k_);
0057     else
0058       xtrap = x0_ + xrec - k_ * yrec;
0059     ytrap = y0_ + yrec;
0060 
0061 #ifdef DEBUG_GRID
0062     std::cout << xrec << " " << yrec << " transformed to trapezoid " << xtrap << " " << ytrap << std::endl;
0063 #endif
0064   }
0065 
0066 private:
0067   double x0_;
0068   double y0_;
0069   double k_;
0070   bool parallel_;
0071 };
0072 
0073 #endif