File indexing completed on 2026-08-06 09:38:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LWH_VariAxis_H
0010 #define LWH_VariAxis_H
0011
0012
0013
0014
0015
0016 #include <limits>
0017 #include <cmath>
0018 #include <algorithm>
0019 #include <map>
0020 #include "AIAxis.h"
0021
0022 namespace LWH {
0023
0024 using namespace AIDA;
0025
0026
0027
0028
0029
0030
0031 class VariAxis: public IAxis {
0032
0033 public:
0034
0035
0036
0037
0038 VariAxis(const std::vector<double> & edges) {
0039 for ( int i = 0, N = edges.size(); i < N; ++i ) binco[edges[i]] = 0;
0040 std::map<double,int>::iterator it = binco.begin();
0041 for ( int i = 0, N = edges.size(); i < N; ++i ) (it++)->second = i;
0042 }
0043
0044
0045
0046
0047 VariAxis(const VariAxis & a)
0048 : IAxis(a), binco(a.binco) {}
0049
0050
0051 virtual ~VariAxis() { }
0052
0053
0054
0055
0056
0057
0058
0059 bool isFixedBinning() const {return false; }
0060
0061
0062
0063
0064
0065
0066 double lowerEdge() const {
0067 if ( binco.size() ) return binco.begin()->first;
0068 return 0;
0069 }
0070
0071
0072
0073
0074
0075
0076 double upperEdge() const {
0077 if ( !binco.size() ) return 0;
0078 std::map<double,int>::const_iterator last = binco.end();
0079 return (--last)->first;
0080 }
0081
0082
0083
0084
0085
0086
0087 int bins() const { return binco.size() - 1; }
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 std::pair<double,double> binEdges(int index) const {
0098 std::pair<double,double> edges(0.0, 0.0);
0099 if ( !binco.size() ) return edges;
0100 std::map<double,int>::const_iterator lo = binco.end();
0101 std::map<double,int>::const_iterator up = binco.begin();
0102 if ( index >= 0 ) while ( index-- >= 0 && up != binco.end() ) lo = up++;
0103 edges.first = ( lo == binco.end() )? -std::numeric_limits<double>::max():
0104 lo->first;
0105 edges.second = ( up == binco.end() )? std::numeric_limits<double>::max():
0106 up->first;
0107 return edges;
0108 }
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 double binLowerEdge(int index) const {
0119 return binEdges(index).first;
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 double binUpperEdge(int index) const {
0131 return binEdges(index).second;
0132 }
0133
0134
0135
0136
0137
0138
0139
0140
0141 double binWidth(int index) const {
0142 std::pair<double,double> edges = binEdges(index);
0143 return edges.second - edges.first;
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 int coordToIndex(double coord) const {
0156 std::map<double,int>::const_iterator up = binco.upper_bound(coord);
0157 if ( up == binco.begin() ) return UNDERFLOW_BIN;
0158 else if ( up == binco.end() ) return OVERFLOW_BIN;
0159 else return up->second - 1;
0160 }
0161
0162
0163
0164
0165
0166 double binMidPoint(int index) const {
0167 std::pair<double,double> edges = binEdges(index);
0168 return (edges.second + edges.first)/2.0;
0169 }
0170
0171 private:
0172
0173
0174
0175
0176
0177 std::map<double,int> binco;
0178
0179 };
0180
0181 }
0182
0183 #endif