# Project CMSSW displayed by LXR

File indexing completed on 2024-04-06 12:19:19

```0001 #ifndef NPSTAT_CIRCULARMAPPER1D_HH_
0002 #define NPSTAT_CIRCULARMAPPER1D_HH_
0003
0004 /*!
0005 // \file CircularMapper1d.h
0006 //
0007 // \brief Linear transformation for circular topology
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // June 2012
0012 */
0013
0014 #include <cmath>
0015
0016 #include "JetMETCorrections/InterpolationTables/interface/LinearMapper1d.h"
0017
0018 namespace npstat {
0019   /**
0020     // 1-d linear transformation functor followed by the shift of
0021     // the result into the interval [-T/2, T/2], where T is the period
0022     */
0023   class CircularMapper1d {
0024   public:
0025     inline CircularMapper1d() : a_(1.0), b_(0.0), period_(2.0 * M_PI) {}
0026
0027     inline CircularMapper1d(const double ca, const double cb, const double cperiod)
0028         : a_(ca), b_(cb), period_(std::abs(cperiod)) {
0029       check();
0030     }
0031
0032     inline CircularMapper1d(const LinearMapper1d& mapper, const double cperiod)
0033         : a_(mapper.a()), b_(mapper.b()), period_(std::abs(cperiod)) {
0034       check();
0035     }
0036
0037     inline double operator()(const double& x) const {
0038       double value = a_ * x + b_;
0039       value -= period_ * floor(value / period_);
0040       if (value > period_ / 2.0)
0041         value -= period_;
0042       return value;
0043     }
0044
0045     inline double a() const { return a_; }
0046     inline double b() const { return b_; }
0047     inline double period() const { return period_; }
0048     inline LinearMapper1d linearMapper() const { return LinearMapper1d(a_, b_); }
0049
0050   private:
0051     inline void check() {
0052       if (!period_)
0053         throw npstat::NpstatInvalidArgument(
0054             "In npstat::CircularMapper1d constructor: "
0055             "invalid period argument (can not be 0)");
0056     }
0057
0058     double a_;
0059     double b_;
0060     double period_;
0061   };
0062 }  // namespace npstat
0063
0064 #endif  // NPSTAT_CIRCULARMAPPER1D_HH_```