00001 // -*- C++ -*- 00002 // 00003 // Axis.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef LWH_Axis_H 00010 #define LWH_Axis_H 00011 // 00012 // This is the declaration of the Axis class representing 00013 // 00014 00015 00016 #include <limits> 00017 #include <cmath> 00018 #include <algorithm> 00019 #include "AIAxis.h" 00020 00021 namespace LWH { 00022 00023 using namespace AIDA; 00024 00030 class Axis: public IAxis { 00031 00032 public: 00033 00037 Axis(int n, double lo, double up) 00038 : lower(lo), upper(up), nbins(n) {} 00039 00043 Axis(const Axis & a) 00044 : IAxis(a), lower(a.lower), upper(a.upper), nbins(a.nbins) {} 00045 00047 virtual ~Axis() { } 00048 00055 bool isFixedBinning() const {return true; } 00056 00062 double lowerEdge() const { return lower; } 00063 00069 double upperEdge() const { return upper; } 00070 00076 int bins() const { return nbins; } 00077 00086 double binLowerEdge(int index) const { 00087 return index < 0? -std::numeric_limits<double>::max(): 00088 lower + double(std::min(index, nbins))*binWidth(0); 00089 } 00090 00099 double binUpperEdge(int index) const { 00100 return index >= nbins? std::numeric_limits<double>::max(): 00101 lower + double(std::max(index, -1) + 1)*binWidth(0); 00102 } 00103 00111 double binWidth(int) const { 00112 return (upper - lower)/double(nbins); 00113 } 00114 00124 int coordToIndex(double coord) const { 00125 if ( coord >= upper ) return OVERFLOW_BIN; 00126 else if ( coord < lower ) return UNDERFLOW_BIN; 00127 else return int((coord - lower)/binWidth(0)); 00128 } 00129 00134 double binMidPoint(int index) const { 00135 return lower + (double(index) + 0.5)*binWidth(0); 00136 } 00137 00138 private: 00139 00141 double lower; 00142 00144 double upper; 00145 00147 int nbins; 00148 00149 }; 00150 00151 } 00152 00153 #endif /* LWH_Axis_H */