00001
00002
00003
00004
00005 #ifndef SCALA_RANGE
00006 #define SCALA_RANGE
00007
00008 #include "clipper/clipper.h"
00009
00010 #include "util.hh"
00011
00012 typedef std::pair<float,float> RPair;
00013
00014 namespace scala
00015 {
00016
00017 class Range
00018 {
00019 public:
00020
00021
00022 Range();
00023
00024
00025 Range(const double& Rfirst, const double& Rlast,
00026 const bool& Ascending=true, const int& Nbin=0);
00027
00028
00029 void AllowDescending();
00030
00031
00032
00033 void SetRange(const double& Rfirst, const double& Rlast,
00034 const bool& Ascending=true, const int& Nbin=0);
00035 void SetNbin(const int& Nbin);
00036
00037
00038 void clear();
00039
00040 virtual void update(const double& value);
00041
00042
00043 double& first() {return first_;}
00044 double first() const {return first_;}
00045 double& last() {return last_;}
00046 double last() const {return last_;}
00047
00048 double min() const {return Min(first_, last_);}
00049 double max() const {return Max(first_, last_);}
00050
00051
00052 double AbsRange() const {return std::abs(last_ - first_);}
00053
00054
00055 int bin(const double& value) const;
00056
00057 int tbin(const double& value) const;
00058
00059
00060 int Nbins() const {return Nbin_;}
00061
00062 RPair bounds(const int& bin) const;
00063
00064 float middle(const int& bin) const;
00065
00066
00067 std::string format() const;
00068
00069 private:
00070 double first_, last_;
00071 mutable int Nbin_;
00072 mutable double width;
00073 mutable double tolerance;
00074 bool ascending;
00075
00076 void init();
00077 void CheckWidth() const;
00078 };
00079
00080
00081
00082 class ResoRange : public Range
00083 {
00084 public:
00085 ResoRange();
00086
00087
00088 ResoRange(const float& lowreso, const float& hireso,
00089 const int& Nobs=0);
00090
00091 ResoRange(const Range& range);
00092
00093 void init_range(const Range& range);
00094
00095
00096 bool isSet() const {return set;}
00097
00098 void Set();
00099
00100
00101 void SetRange(const float& lowreso, const float& hireso);
00102 void SetRange(const float& lowreso, const float& hireso,
00103 const int& Nobs);
00104 void SetRange(const int& Nobs);
00105
00106
00107 void SetNbins(const int& NumBin);
00108 int Nbins() const {return Nbin;}
00109
00110
00111 void SetWidth(const float& width);
00112
00113
00114 float ResLow() const;
00115 float ResHigh() const;
00116 float SResLow() const;
00117 float SResHigh() const;
00118 Range RRange() const;
00119 Range SRange() const;
00120
00121
00122 float middleA(const int& bin) const;
00123
00124 RPair boundsA(const int& bin) const;
00125
00126 RPair boundsS(const int& bin) const;
00127
00128 ResoRange BinRange(const int& bin) const;
00129
00130 ResoRange MaxRange(const ResoRange& other) const;
00131
00132 ResoRange MinRange(const ResoRange& other) const;
00133
00134 private:
00135 static const float LowDef;
00136 static const float HiDef;
00137
00138 bool set;
00139
00140 int Nbin;
00141
00142 float LowReso, HiReso;
00143 float sSqrmin, sSqrmax;
00144
00145 int MinNbin, MaxNbin;
00146 int MinNrefBin, MaxNrefBin;
00147 int Nobservations;
00148 float delta_sSqr;
00149
00150 void init();
00151 void init_reso();
00152 void init_bins();
00153
00154 };
00155
00156 class IntRange
00157 {
00158
00159
00160 public:
00161
00162
00163 IntRange();
00164
00165 IntRange(const int& Imin, const int& Imax);
00166
00167
00168 void SetRange(const int& Imin, const int& Imax);
00169
00170
00171 void clear();
00172
00173 void update(const int& value);
00174
00175
00176 int min() const;
00177 int max() const;
00178
00179
00180 bool InRange(const int& value) const;
00181
00182 private:
00183 int min_, max_;
00184
00185 void init();
00186 };
00187
00188 }
00189 #endif