00001
00011 #ifndef GRB_OBS_UTILITIES_H
00012 #define GRB_OBS_UTILITIES_H
00013
00014 #include <vector>
00015 #include <deque>
00016 #include <string>
00017 #include <functional>
00018
00019 #include "GRBobsConstants.h"
00020
00021 using namespace grbobstypes;
00022
00023 class HepRandomEngine;
00024
00025
00026
00027 class GRBobsUtilities
00028 {
00029 public:
00033 static double result(HepRandomEngine *engine, const double lo,
00034 const double hi, const double p);
00035
00039 static void sortVector(const long index, const std::vector<double> &in,
00040 const std::vector<double> &sorted, std::vector<double> &out);
00041
00045 struct multiplier : public std::unary_function<double, double>
00046 {
00047 multiplier(double value) : m_value(value) {}
00048 double operator() (double x);
00049
00050 double m_value;
00051 };
00052
00053
00057 struct randGen : public std::unary_function<double, double>
00058 {
00059 randGen(HepRandomEngine *engine) : m_engine(engine) {}
00060 double operator() (double x);
00061
00062 HepRandomEngine *m_engine;
00063 };
00064
00065
00069 template<class T>
00070 static void getSorter(const std::vector<T> &in,
00071 std::vector<long> &sorter)
00072 {
00073 std::vector<T> sorted(in);
00074 std::sort(sorted.begin(), sorted.end());
00075
00076 LongSize sz = in.size();
00077
00078 std::deque<bool> qused(sz, 0);
00079
00080 for (LongSize i=0; i<sz; ++i)
00081 {
00082 for (LongSize j=0; j<sz; ++j)
00083 {
00084 if ((!qused[j]) && (sorted[i] == in[j]))
00085 {
00086 sorter[i] = j;
00087 qused[j] = 1;
00088 break;
00089 }
00090 }
00091 }
00092 }
00093
00094
00098 template<class S, class T>
00099 static void cumulativeSum(const std::vector<S> &in, std::vector<T> &out)
00100 {
00101 out.clear();
00102
00103 out.reserve(in.size());
00104
00105 std::vector<S>::const_iterator it = in.begin();
00106 T value = *it;
00107 out.push_back(value);
00108
00109 ++it;
00110
00111 while (it != in.end())
00112 {
00113 value += *it;
00114 out.push_back(value);
00115 ++it;
00116 }
00117 }
00118 };
00119
00120 #endif