CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/JetMETCorrections/InterpolationTables/interface/DualHistoAxis.h

Go to the documentation of this file.
00001 #ifndef NPSTAT_DUALHISTOAXIS_HH_
00002 #define NPSTAT_DUALHISTOAXIS_HH_
00003 
00014 #include "JetMETCorrections/InterpolationTables/interface/HistoAxis.h"
00015 #include "JetMETCorrections/InterpolationTables/interface/NUHistoAxis.h"
00016 
00017 namespace npstat {
00023     class DualHistoAxis
00024     {
00025     public:
00026         // Constructors
00027         inline DualHistoAxis(const NUHistoAxis& a)
00028             : a_(a), u_(1U, 0.0, 1.0), uniform_(false) {}
00029 
00030         inline DualHistoAxis(const HistoAxis& u)
00031             : a_(dummy_vec()), u_(u), uniform_(true) {}
00032 
00033         inline DualHistoAxis(const std::vector<double>& binEdges,
00034                              const char* label = 0)
00035             : a_(binEdges, label), u_(1U, 0.0, 1.0), uniform_(false) {}
00036 
00037         inline DualHistoAxis(unsigned nBins, double min, double max,
00038                              const char* label = 0)
00039             : a_(dummy_vec()), u_(nBins, min, max, label), uniform_(true) {}
00040 
00041         // Inspectors
00042         inline bool isUniform() const {return uniform_;}
00043 
00044         inline double min() const
00045             {return uniform_ ? u_.min() : a_.min();}
00046 
00047         inline double max() const
00048             {return uniform_ ? u_.max() : a_.max();}
00049 
00050         inline Interval<double> interval() const
00051             {return uniform_ ? u_.interval() : a_.interval();}
00052 
00053         inline double length() const
00054             {return uniform_ ? u_.length() : a_.length();}
00055 
00056         inline unsigned nBins() const
00057             {return uniform_ ? u_.nBins() : a_.nBins();}
00058 
00059         inline double binWidth(const int binNum) const
00060             {return uniform_ ? u_.binWidth(binNum) : a_.binWidth(binNum);}
00061 
00062         inline const std::string& label() const
00063             {return uniform_ ? u_.label() : a_.label();}
00064 
00065         inline double binCenter(const int binNum) const
00066             {return uniform_ ? u_.binCenter(binNum) : a_.binCenter(binNum);}
00067 
00068         inline double leftBinEdge(const int binNum) const
00069             {return uniform_ ? u_.leftBinEdge(binNum) : a_.leftBinEdge(binNum);}
00070 
00071         inline double rightBinEdge(const int binNum) const
00072             {return uniform_ ? u_.rightBinEdge(binNum) : a_.rightBinEdge(binNum);}
00073 
00074         inline Interval<double> binInterval(const int binNum) const
00075             {return uniform_ ? u_.binInterval(binNum) : a_.binInterval(binNum);}
00076 
00078 
00083         inline const NUHistoAxis* getNUHistoAxis() const
00084             {return uniform_ ? static_cast<const NUHistoAxis*>(0) : &a_;}
00085 
00086         inline const HistoAxis* getHistoAxis() const
00087             {return uniform_ ? &u_ : static_cast<const HistoAxis*>(0);}
00089 
00091         inline void setLabel(const char* newlabel)
00092             {uniform_ ? u_.setLabel(newlabel) : a_.setLabel(newlabel);}
00093 
00098         inline int binNumber(const double x) const
00099             {return uniform_ ? u_.binNumber(x) : a_.binNumber(x);}
00100 
00105         inline double fltBinNumber(const double x,
00106                                    const bool mapLeftEdgeTo0=true) const
00107         {
00108             return uniform_ ? u_.fltBinNumber(x, mapLeftEdgeTo0) :
00109                               a_.fltBinNumber(x, mapLeftEdgeTo0);
00110         }
00111 
00113         inline unsigned closestValidBin(const double x) const
00114             {return uniform_ ? u_.closestValidBin(x) : a_.closestValidBin(x);}
00115 
00116         inline bool operator==(const DualHistoAxis& r) const
00117             {return uniform_ == r.uniform_ && a_ == r.a_ && u_ == r.u_;}
00118 
00119         inline bool operator!=(const DualHistoAxis& r) const
00120             {return !(*this == r);}
00121 
00123         inline bool isClose(const DualHistoAxis& r, const double tol) const
00124         {
00125             return uniform_ == r.uniform_ &&
00126                    a_.isClose(r.a_, tol) && 
00127                    u_.isClose(r.u_, tol);
00128         }
00129 
00131         // Method related to "geners" I/O
00132         inline gs::ClassId classId() const {return gs::ClassId(*this);}
00133         bool write(std::ostream& of) const;
00135 
00136         static inline const char* classname() {return "npstat::DualHistoAxis";}
00137         static inline unsigned version() {return 1;}
00138         static DualHistoAxis* read(const gs::ClassId& id, std::istream& in);
00139 
00140     private:
00141         inline DualHistoAxis()
00142             : a_(dummy_vec()), u_(1U, 0.0, 1.0), uniform_(true) {}
00143 
00144         NUHistoAxis a_;
00145         HistoAxis u_;
00146         bool uniform_;
00147 
00148         template <typename Numeric, class Axis> friend class HistoND;
00149 
00150         inline unsigned overflowIndex(
00151             const double x, unsigned* binNumber) const
00152         {
00153             return uniform_ ? u_.overflowIndex(x, binNumber) : 
00154                               a_.overflowIndex(x, binNumber);
00155         }
00156 
00157         inline static std::vector<double> dummy_vec()
00158         {
00159             std::vector<double> vec(2, 0.0);
00160             vec[1] = 1.0;
00161             return vec;
00162         }
00163 
00164     };
00165 }
00166 
00167 #endif // NPSTAT_DUALHISTOAXIS_HH_
00168