00001
00002 #include "Rivet/Tools/BinnedHistogram.hh"
00003 #include "Rivet/RivetBoost.hh"
00004 #include "Rivet/RivetAIDA.hh"
00005 #include "Rivet/Analysis.hh"
00006
00007 namespace Rivet {
00008
00009
00010 template<typename T>
00011 const BinnedHistogram<T>& BinnedHistogram<T>::addHistogram(const T& binMin,
00012 const T& binMax,
00013 AIDA::IHistogram1D *histo){
00014 if (binMin > binMax) {
00015 throw Error
00016 ("Cannot add a binned histogram where the lower bin edge is above the upper edge");
00017 }
00018 _histosByUpperBound[binMax] = histo;
00019 _histosByLowerBound[binMin] = histo;
00020 bool found = false;
00021 foreach (AIDA::IHistogram1D* hist, _histos) {
00022 if (hist == histo) {
00023 found = true;
00024 break;
00025 }
00026 }
00027
00028 if (!found){
00029 _histos.push_back(histo);
00030 _binWidths[histo]=binMax-binMin;
00031 }
00032
00033 return *this;
00034 }
00035
00036
00037
00038 template<typename T>
00039 AIDA::IHistogram1D* BinnedHistogram<T>::fill(const T& bin,
00040 const T& val,
00041 double weight) {
00042
00043 typename map<T, AIDA::IHistogram1D*>::iterator histIt =
00044 _histosByUpperBound.upper_bound(bin);
00045
00046 if (histIt == _histosByUpperBound.end()) {
00047 return 0;
00048 }
00049
00050 AIDA::IHistogram1D* histo = histIt->second;
00051 histIt = _histosByLowerBound.lower_bound(bin);
00052
00053
00054
00055
00056 if (histIt == _histosByLowerBound.begin()) {
00057 return 0;
00058 }
00059
00060
00061 --histIt;
00062
00063 if (histo != histIt->second) {
00064 return 0;
00065 }
00066
00067 histo->fill(val, weight);
00068
00069 return histo;
00070 }
00071
00072
00073 template<typename T>
00074 void BinnedHistogram<T>::scale(const T& scale, Analysis* ana) {
00075 foreach (AIDA::IHistogram1D* hist, getHistograms()) {
00076 ana->scale(hist, scale/_binWidths[hist]);
00077 }
00078 }
00079
00080
00081
00082
00083 template class BinnedHistogram<double>;
00084 template class BinnedHistogram<int>;
00085 template class BinnedHistogram<float>;
00086
00087
00088 }