thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
VariAxis.h
1// -*- C++ -*-
2//
3// VariAxis.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_VariAxis_H
10#define LWH_VariAxis_H
11//
12// This is the declaration of the VariAxis class representing
13//
14
15
16#include <limits>
17#include <cmath>
18#include <algorithm>
19#include <map>
20#include "AIAxis.h"
21
22namespace LWH {
23
24using namespace AIDA;
25
31class VariAxis: public IAxis {
32
33public:
34
38 VariAxis(const std::vector<double> & edges) {
39 for ( int i = 0, N = edges.size(); i < N; ++i ) binco[edges[i]] = 0;
40 std::map<double,int>::iterator it = binco.begin();
41 for ( int i = 0, N = edges.size(); i < N; ++i ) (it++)->second = i;
42 }
43
47 VariAxis(const VariAxis & a)
48 : IAxis(a), binco(a.binco) {}
49
51 virtual ~VariAxis() { }
52
59 bool isFixedBinning() const {return false; }
60
66 double lowerEdge() const {
67 if ( binco.size() ) return binco.begin()->first;
68 return 0;
69 }
70
76 double upperEdge() const {
77 if ( !binco.size() ) return 0;
78 std::map<double,int>::const_iterator last = binco.end();
79 return (--last)->first;
80 }
81
87 int bins() const { return binco.size() - 1; }
88
97 std::pair<double,double> binEdges(int index) const {
98 std::pair<double,double> edges(0.0, 0.0);
99 if ( !binco.size() ) return edges;
100 std::map<double,int>::const_iterator lo = binco.end();
101 std::map<double,int>::const_iterator up = binco.begin();
102 if ( index >= 0 ) while ( index-- >= 0 && up != binco.end() ) lo = up++;
103 edges.first = ( lo == binco.end() )? -std::numeric_limits<double>::max():
104 lo->first;
105 edges.second = ( up == binco.end() )? std::numeric_limits<double>::max():
106 up->first;
107 return edges;
108 }
109
118 double binLowerEdge(int index) const {
119 return binEdges(index).first;
120 }
121
130 double binUpperEdge(int index) const {
131 return binEdges(index).second;
132 }
133
141 double binWidth(int index) const {
142 std::pair<double,double> edges = binEdges(index);
143 return edges.second - edges.first;
144 }
145
155 int coordToIndex(double coord) const {
156 std::map<double,int>::const_iterator up = binco.upper_bound(coord);
157 if ( up == binco.begin() ) return UNDERFLOW_BIN;
158 else if ( up == binco.end() ) return OVERFLOW_BIN;
159 else return up->second - 1;
160 }
161
166 double binMidPoint(int index) const {
167 std::pair<double,double> edges = binEdges(index);
168 return (edges.second + edges.first)/2.0;
169 }
170
171private:
172
177 std::map<double,int> binco;
178
179};
180
181}
182
183#endif /* LWH_VariAxis_H */
An VariAxis represents a binned histogram axis.
Definition: VariAxis.h:31
double binUpperEdge(int index) const
Get the upper edge of the specified bin.
Definition: VariAxis.h:130
VariAxis(const std::vector< double > &edges)
Standard constructor.
Definition: VariAxis.h:38
double binWidth(int index) const
Get the width of the specified bin.
Definition: VariAxis.h:141
virtual ~VariAxis()
Destructor.
Definition: VariAxis.h:51
int bins() const
The number of bins (excluding underflow and overflow) on the IAxis.
Definition: VariAxis.h:87
bool isFixedBinning() const
Check if the IAxis has fixed binning, i.e.
Definition: VariAxis.h:59
double binLowerEdge(int index) const
Get the lower edge of the specified bin.
Definition: VariAxis.h:118
std::map< double, int > binco
A map relating the lower edge of a bin to the corresponding bin number.
Definition: VariAxis.h:177
double binMidPoint(int index) const
Return the midpoint of the specified bin.
Definition: VariAxis.h:166
double lowerEdge() const
Get the lower edge of the IAxis.
Definition: VariAxis.h:66
int coordToIndex(double coord) const
Convert a coordinate on the axis to a bin number.
Definition: VariAxis.h:155
std::pair< double, double > binEdges(int index) const
Get the lower edge of the specified bin.
Definition: VariAxis.h:97
double upperEdge() const
Get the upper edge of the IAxis.
Definition: VariAxis.h:76
VariAxis(const VariAxis &a)
Copy constructor.
Definition: VariAxis.h:47
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...