|
|
|||
File indexing completed on 2026-08-06 09:38:18
0001 // -*- C++ -*- 0002 // 0003 // Axis.h is a part of ThePEG - Toolkit for HEP Event Generation 0004 // Copyright (C) 1999-2019 Leif Lonnblad 0005 // 0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details. 0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 0008 // 0009 #ifndef LWH_Axis_H 0010 #define LWH_Axis_H 0011 // 0012 // This is the declaration of the Axis class representing 0013 // 0014 0015 0016 #include <limits> 0017 #include <cmath> 0018 #include <algorithm> 0019 #include "AIAxis.h" 0020 0021 namespace LWH { 0022 0023 using namespace AIDA; 0024 0025 /** 0026 * An Axis represents a binned histogram axis. A 1D Histogram would have 0027 * one Axis representing the X axis, while a 2D Histogram would have two 0028 * axes representing the X and Y Axis. 0029 */ 0030 class Axis: public IAxis { 0031 0032 public: 0033 0034 /** 0035 * Standard constructor. 0036 */ 0037 Axis(int n, double lo, double up) 0038 : lower(lo), upper(up), nbins(n) {} 0039 0040 /** 0041 * Copy constructor. 0042 */ 0043 Axis(const Axis & a) 0044 : IAxis(a), lower(a.lower), upper(a.upper), nbins(a.nbins) {} 0045 0046 /// Destructor. 0047 virtual ~Axis() { } 0048 0049 /** 0050 * Check if the IAxis has fixed binning, i.e. if all the bins have 0051 * the same width. @return <code>true</code> if the binning is 0052 * fixed, <code>false</code> otherwise. 0053 * 0054 */ 0055 bool isFixedBinning() const {return true; } 0056 0057 /** 0058 * Get the lower edge of the IAxis. 0059 * @return The IAxis's lower edge. 0060 * 0061 */ 0062 double lowerEdge() const { return lower; } 0063 0064 /** 0065 * Get the upper edge of the IAxis. 0066 * @return The IAxis's upper edge. 0067 * 0068 */ 0069 double upperEdge() const { return upper; } 0070 0071 /** 0072 * The number of bins (excluding underflow and overflow) on the IAxis. 0073 * @return The IAxis's number of bins. 0074 * 0075 */ 0076 int bins() const { return nbins; } 0077 0078 /** 0079 * Get the lower edge of the specified bin. 0080 * @param index The bin number: 0 to bins()-1 for the in-range bins 0081 * or OVERFLOW or UNDERFLOW. 0082 * @return The lower edge of the corresponding bin; for the 0083 * underflow bin this is <tt>Double.NEGATIVE_INFINITY</tt>. 0084 * 0085 */ 0086 double binLowerEdge(int index) const { 0087 return index < 0? -std::numeric_limits<double>::max(): 0088 lower + double(std::min(index, nbins))*binWidth(0); 0089 } 0090 0091 /** 0092 * Get the upper edge of the specified bin. 0093 * @param index The bin number: 0 to bins()-1 for the in-range bins 0094 * or OVERFLOW or UNDERFLOW. 0095 * @return The upper edge of the corresponding bin; for the overflow 0096 * bin this is <tt>Double.POSITIVE_INFINITY</tt>. 0097 * 0098 */ 0099 double binUpperEdge(int index) const { 0100 return index >= nbins? std::numeric_limits<double>::max(): 0101 lower + double(std::max(index, -1) + 1)*binWidth(0); 0102 } 0103 0104 /** 0105 * Get the width of the specified bin. 0106 * The argument gives the bin number: 0 to bins()-1) for the in-range bins 0107 * or OVERFLOW or UNDERFLOW. 0108 * @return The width of the corresponding bin. 0109 * 0110 */ 0111 double binWidth(int) const { 0112 return (upper - lower)/double(nbins); 0113 } 0114 0115 /** 0116 * Convert a coordinate on the axis to a bin number. If the 0117 * coordinate is less than the lowerEdge UNDERFLOW is returned; if 0118 * the coordinate is greater or equal to the upperEdge OVERFLOW is 0119 * returned. 0120 * @param coord The coordinate to be converted. 0121 * @return The corresponding bin number. 0122 * 0123 */ 0124 int coordToIndex(double coord) const { 0125 if ( coord >= upper ) return OVERFLOW_BIN; 0126 else if ( coord < lower ) return UNDERFLOW_BIN; 0127 else return int((coord - lower)/binWidth(0)); 0128 } 0129 0130 /** 0131 * Return the midpoint of the specified bin. No checking is 0132 * performed to ensure the argument is a valid bin. 0133 */ 0134 double binMidPoint(int index) const { 0135 return lower + (double(index) + 0.5)*binWidth(0); 0136 } 0137 0138 private: 0139 0140 /** The lower edge. */ 0141 double lower; 0142 0143 /** The upper edge. */ 0144 double upper; 0145 0146 /** The number of bins. */ 0147 int nbins; 0148 0149 }; 0150 0151 } 0152 0153 #endif /* LWH_Axis_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|