thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
Axis.h
1 // -*- C++ -*-
2 //
3 // Axis.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef LWH_Axis_H
10 #define LWH_Axis_H
11 //
12 // This is the declaration of the Axis class representing
13 //
14 
15 
16 #include <limits>
17 #include <cmath>
18 #include <algorithm>
19 #include "AIAxis.h"
20 
21 namespace LWH {
22 
23 using namespace AIDA;
24 
30 class Axis: public IAxis {
31 
32 public:
33 
37  Axis(int n, double lo, double up)
38  : lower(lo), upper(up), nbins(n) {}
39 
43  Axis(const Axis & a)
44  : IAxis(a), lower(a.lower), upper(a.upper), nbins(a.nbins) {}
45 
47  virtual ~Axis() { }
48 
55  bool isFixedBinning() const {return true; }
56 
62  double lowerEdge() const { return lower; }
63 
69  double upperEdge() const { return upper; }
70 
76  int bins() const { return nbins; }
77 
86  double binLowerEdge(int index) const {
87  return index < 0? -std::numeric_limits<double>::max():
88  lower + double(std::min(index, nbins))*binWidth(0);
89  }
90 
99  double binUpperEdge(int index) const {
100  return index >= nbins? std::numeric_limits<double>::max():
101  lower + double(std::max(index, -1) + 1)*binWidth(0);
102  }
103 
111  double binWidth(int) const {
112  return (upper - lower)/double(nbins);
113  }
114 
124  int coordToIndex(double coord) const {
125  if ( coord >= upper ) return OVERFLOW_BIN;
126  else if ( coord < lower ) return UNDERFLOW_BIN;
127  else return int((coord - lower)/binWidth(0));
128  }
129 
134  double binMidPoint(int index) const {
135  return lower + (double(index) + 0.5)*binWidth(0);
136  }
137 
138 private:
139 
141  double lower;
142 
144  double upper;
145 
147  int nbins;
148 
149 };
150 
151 }
152 
153 #endif /* LWH_Axis_H */
double upperEdge() const
Get the upper edge of the IAxis.
Definition: Axis.h:69
double lower
The lower edge.
Definition: Axis.h:141
double binMidPoint(int index) const
Return the midpoint of the specified bin.
Definition: Axis.h:134
int coordToIndex(double coord) const
Convert a coordinate on the axis to a bin number.
Definition: Axis.h:124
Axis(int n, double lo, double up)
Standard constructor.
Definition: Axis.h:37
double binWidth(int) const
Get the width of the specified bin.
Definition: Axis.h:111
double binLowerEdge(int index) const
Get the lower edge of the specified bin.
Definition: Axis.h:86
int bins() const
The number of bins (excluding underflow and overflow) on the IAxis.
Definition: Axis.h:76
int nbins
The number of bins.
Definition: Axis.h:147
virtual ~Axis()
Destructor.
Definition: Axis.h:47
double lowerEdge() const
Get the lower edge of the IAxis.
Definition: Axis.h:62
An Axis represents a binned histogram axis.
Definition: Axis.h:30
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...
double upper
The upper edge.
Definition: Axis.h:144
bool isFixedBinning() const
Check if the IAxis has fixed binning, i.e.
Definition: Axis.h:55
Axis(const Axis &a)
Copy constructor.
Definition: Axis.h:43
double binUpperEdge(int index) const
Get the upper edge of the specified bin.
Definition: Axis.h:99