Project CMSSW displayed by LXR

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

```0001 #ifndef NPSTAT_UNIFORMAXIS_HH_
0002 #define NPSTAT_UNIFORMAXIS_HH_
0003
0004 /*!
0005 // \file UniformAxis.h
0006 //
0007 // \brief Uniformly spaced coordinate sets for use in constructing
0008 //        rectangular grids
0009 //
0010 // Author: I. Volobouev
0011 //
0012 // June 2012
0013 */
0014
0015 #include <vector>
0016 #include <utility>
0017 #include <string>
0018 #include <iostream>
0019
0020 #include "Alignment/Geners/interface/ClassId.hh"
0021
0022 namespace npstat {
0023   /**
0024     // This class contains the info needed to define an axis of a rectangular
0025     // grid. The distance between grid points is uniform.
0026     */
0027   class UniformAxis {
0028   public:
0029     // The number of coordinates must be at least 2
0030     UniformAxis(unsigned nCoords, double min, double max, const char* label = nullptr);
0031
0032     // Basic accessors
0033     inline unsigned nCoords() const { return npt_; }
0034     inline double min() const { return min_; }
0035     inline double max() const { return max_; }
0036     inline const std::string& label() const { return label_; }
0037     inline bool usesLogSpace() const { return false; }
0038
0039     // The following function returns the grid interval number and
0040     // the weight of the point at the left side of the interval.
0041     // The weight will be set to 1 if the given coordinate coincides
0042     // with the grid point and will decay to 0 linearly as the
0043     // coordinate moves towards the next point on the right.
0044     //
0045     // The coordinates below the leftmost grid point are mapped
0046     // into the 0th interval with weight 1. The coordinates above
0047     // the rightmost grid point are mapped into the last interval
0048     // with weight 0 for the left point (it is expected that weight 1
0049     // will then be assigned to the right point).
0050     std::pair<unsigned, double> getInterval(double coordinate) const;
0051
0052     // Similar function which calculates the weights including
0053     // the points outside of the axis boundaries
0054     std::pair<unsigned, double> linearInterval(double coordinate) const;
0055
0056     // Convenience methods
0057     std::vector<double> coords() const;
0058     double coordinate(unsigned i) const;
0059     inline double length() const { return max_ - min_; }
0060     inline bool isUniform() const { return true; }
0061     inline unsigned nIntervals() const { return npt_ - 1; }
0062     inline double intervalWidth(unsigned) const { return bw_; }
0063
0064     bool operator==(const UniformAxis& r) const;
0065     inline bool operator!=(const UniformAxis& r) const { return !(*this == r); }
0066
0067     // Closeness within tolerance
0068     bool isClose(const UniformAxis& r, double tol) const;
0069
0070     // Modify the label
0071     inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
0072
0073     // Methods related to I/O
0074     inline gs::ClassId classId() const { return gs::ClassId(*this); }
0075     bool write(std::ostream& of) const;
0076
0077     static inline const char* classname() { return "npstat::UniformAxis"; }
0078     static inline unsigned version() { return 1; }
0079     static UniformAxis* read(const gs::ClassId& id, std::istream& in);
0080
0081   private:
0082     double min_;
0083     double max_;
0084     double bw_;
0085     std::string label_;
0086     unsigned npt_;
0087
0088     inline UniformAxis() : min_(0.), max_(0.), bw_(0.), npt_(0) {}
0089   };
0090 }  // namespace npstat
0091
0092 #endif  // NPSTAT_UNIFORMAXIS_HH_```