00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "AIDAAxis.h"
00011 #include <assert.h>
00012 #include "CHBook/CHBook.h"
00013 #include "Interfaces/IHistogram.h"
00014
00015 using Anaphe::AIDA_HBook::AIDAAxis;
00016
00017
00019
00020
00021
00023
00024 AIDAAxis::AIDAAxis(const CHBookHistogram* h, const int& axnum,
00025 const int& nb, const double& lower_edge,
00026 const double& upper_edge)
00027 : histo (h),
00028 axisNumber(axnum),
00029 varbins (false),
00030 loedge (0.0),
00031 hiedge (0.0),
00032 nbins (0),
00033 binEdges (0)
00034 {
00035 if (lower_edge == 0.0 &&
00036 upper_edge == 0.0 &&
00037 nbins == 0 ) return;
00038 else if (upper_edge > lower_edge && nb > 0) {
00039 loedge = lower_edge;
00040 hiedge = upper_edge;
00041 nbins = nb;
00042 }
00043 else badConstructorMessage();
00044 }
00045
00046
00047
00048
00049 AIDAAxis::AIDAAxis(const CHBookHistogram* h, const int& axnum,
00050 const std::vector<float>& be)
00051 : histo (h),
00052 axisNumber(axnum),
00053 varbins (true),
00054 loedge (0.0),
00055 hiedge (0.0),
00056 nbins (0),
00057 binEdges (0)
00058 {
00059 int ne = be.size();
00060 if (ne < 2) { badConstructorMessage(); return; }
00061 nbins = ne - 1;
00062 loedge = be[0];
00063 hiedge = be[nbins];
00064 binEdges = new std::vector<float>(ne);
00065 assert(binEdges);
00066 for(int i = 0; i < ne; ++i) (*binEdges)[i] = be[i];
00067 }
00068
00069
00070
00071
00072 AIDAAxis::~AIDAAxis(void)
00073 {
00074 if (binEdges) {
00075 binEdges->clear();
00076 delete binEdges;
00077 }
00078 }
00079
00080
00081
00082
00084
00085
00086
00088
00090
00091 {
00092 return loedge;
00093 }
00094
00095
00096
00097
00099 double AIDAAxis::upperEdge(void) const
00100 {
00101 return hiedge;
00102 }
00103
00104
00105
00106
00108 int AIDAAxis::bins(void) const
00109 {
00110 return nbins;
00111 }
00112
00113
00114
00115
00117 double AIDAAxis::binLowerEdge(int index) const
00118 {
00119 return _bininfo(0,index);
00120 }
00121
00122
00123
00124
00126 double AIDAAxis::binUpperEdge(int index) const
00127 {
00128 return _bininfo(1,index);
00129 }
00130
00131
00132
00133
00135 double AIDAAxis::binWidth(int index) const
00136 {
00137 return _bininfo(2,index);
00138 }
00139
00140
00141
00142
00144 double AIDAAxis::binCentre(int index) const
00145 {
00146 return _bininfo(3,index);
00147 }
00148
00149
00150
00151
00155 int AIDAAxis::coordToIndex(double coord) const
00156 {
00157 if (nbins == 0) return IHistogram::UNDERFLOW_BIN;
00158 else if (coord < loedge) return IHistogram::UNDERFLOW_BIN;
00159 else if (coord > hiedge) return IHistogram::OVERFLOW_BIN;
00160 else if (!varbins) {
00161
00162
00163
00164 double bw = (hiedge - loedge) / static_cast<double>(nbins);
00165 double next = loedge;
00166 int i = 0;
00167 for (i = 0; i < nbins; ++i) {
00168 next += bw * static_cast<double>(i);
00169 if (next >= coord) break;
00170 }
00171 return i;
00172 }
00173 else {
00174
00175 if (!binEdges) return IHistogram::UNDERFLOW_BIN;
00176 for (int i = 1; i <= nbins; ++i)
00177 if (coord <= (*binEdges)[i]) return (i-1);
00178 return IHistogram::OVERFLOW_BIN;
00179 }
00180 }
00181
00182
00183
00184
00187 int AIDAAxis::checkIndex(int index) const
00188 {
00189 if (index >= 0 && index < nbins)
00190 return index;
00191 else if ((index!=IHistogram::OVERFLOW_BIN) &&
00192 (index<0 || index>=nbins) )
00193 return IHistogram::UNDERFLOW_BIN;
00194 else
00195 return IHistogram::OVERFLOW_BIN;
00196 }
00197
00198
00199
00200
00202
00203
00204
00206
00207 double AIDAAxis::_bininfo(const int& choice, const int& index) const
00208 {
00209
00210
00211
00212
00213
00214
00215
00216 double bad = -999.0;
00217 if (index<0 || index>=nbins || loedge==hiedge || nbins==0) return bad;
00218 else if (!varbins) {
00219 double width = (hiedge - loedge) / static_cast<double>(nbins);
00220 switch (choice) {
00221 case 0: return (loedge + (width * static_cast<double>(index)));
00222 case 1: return (loedge + (width * static_cast<double>(index+1)));
00223 case 2: return (width);
00224 case 3: return (loedge + (width * (0.5 + static_cast<double>(index))));
00225 default: return bad;
00226 }
00227 }
00228 else if (varbins && binEdges) {
00229 double lo = (*binEdges)[index];
00230 double hi = (*binEdges)[index+1];
00231 switch (choice) {
00232 case 0: return lo;
00233 case 1: return hi;
00234 case 2: return (hi - lo);
00235 case 3: return (lo + ((hi - lo)/2.0));
00236 default: return bad;
00237 }
00238 }
00239 else return bad;
00240 }
00241
00242
00243
00244
00245 void AIDAAxis::badConstructorMessage(void) const
00246 {
00247 std::cerr << "AIDAAxis ERROR: Bad constructor arguments!"
00248 << std::endl;
00249 }