eicplot  trunk
EIC ROOT plotting utilities
/Users/thomasburton/Documents/projects/eic/Utilities/eicplot/trunk/include/eicplot/Utilities.h
00001 
00009 #ifndef _EICPLOT_UTILITIES_H_
00010 #define _EICPLOT_UTILITIES_H_
00011 
00012 #include <functional>
00013 #include <stdexcept>
00014 
00015 #include <TObject.h>
00016 #include <TVirtualPad.h>
00017 
00018 class TAxis;
00019 class TH1;
00020 
00021 namespace erhic {
00022 
00024    double toDegrees(const double& radians);
00025 
00027    double toRadians(const double& degrees);
00028    
00032    template<typename T>
00033    class Range : public TObject {
00034    public:
00035 
00036       typedef T Type;
00037 
00039       virtual ~Range() { }
00040 
00042       Range(const T& low = T(), const T& up = T()) : mRange(low, up) {
00043       }
00044 
00046       T lower() const { return mRange.first;}
00047 
00049       T middle() const { return 0.5 * (upper() + lower()); }
00050 
00052       T upper() const { return mRange.second; }
00053 
00055       T span() const { return upper() - lower(); }
00056 
00061       bool excludes(const T& t) const { return t >= upper() or t < lower(); }
00062 
00067       bool contains(const T& t) const { return not excludes(t); }
00068 
00072       std::ostream& print(std::ostream& os) const {
00073          return os << lower() << ' '<< upper();
00074       }
00075 
00080       bool operator<(const Range<T>& other) const {
00081          if(lower() < other.lower()) return true;
00082          if(other.lower() > lower()) return false;
00083          // Lower limit must be equal
00084          return upper() < other.upper();
00085       }
00086 
00087    protected:
00088 
00089       std::pair<T, T> mRange;
00090 
00091       ClassDef(Range, 1)
00092    };
00093 
00097    template<typename T>
00098    class Range2D {
00099    public:
00100 
00101       typedef T Type;
00103       virtual ~Range2D() { }
00104 
00106       Range2D(const Range<T>& inDimension1 = Range<T>(),
00107                const Range<T>& inDimension2 = Range<T>())
00108       : mDimension1(inDimension1), mDimension2(inDimension2) { }
00109 
00114       bool excludes(const std::pair<T, T>& test) const {
00115          return
00116          mDimension1.excludes(test.first)
00117          or
00118          mDimension2.excludes(test.second);
00119       }
00120 
00122       bool contains(const std::pair<T, T>& test) const {
00123          return not excludes(test);
00124       }
00125 
00127       bool operator<(const Range2D& other) const {
00128          if(mDimension1 < other.mDimension1) return true;
00129          if(other.mDimension1 < mDimension1) return false;
00130          if(mDimension2 < other.mDimension2) return true;
00131          return false;
00132       }
00133 
00135       std::ostream& print(std::ostream& os) const {
00136          mDimension1.print(os) << '\t';
00137          return mDimension2.print(os);
00138       }
00139 
00140    protected:
00141 
00142       Range<T> mDimension1;
00143       Range<T> mDimension2;
00144 
00145       ClassDef(Range2D, 1)
00146    };
00147 
00151    class LogPad
00152    : public TObject, std::unary_function<TVirtualPad*, TVirtualPad*> {
00153    public:
00154 
00156       LogPad(Int_t x = 1, Int_t y = 1, Int_t z = 1);
00157 
00159       virtual ~LogPad();
00160 
00165       TVirtualPad* operator()(TVirtualPad* pad) const;
00166 
00167    protected:
00168 
00169       Int_t mX;
00170       Int_t mY;
00171       Int_t mZ;
00172 
00173       ClassDef(erhic::LogPad, 1)
00174    };
00175 
00181    class BinLog10 : public std::unary_function<TAxis*, void> {
00182    public:
00183 
00185       BinLog10();
00186 
00188       virtual ~BinLog10();
00189 
00194       virtual TAxis* operator()(TAxis*) const;
00195 
00197       virtual TAxis* operator()(TAxis&) const;
00198 
00203       virtual TH1* operator()(TH1*) const;
00204 
00206       virtual TH1* operator()(TH1&) const;
00207 
00208       ClassDef(erhic::BinLog10, 1)
00209    };
00210 } // namespace erhic
00211 
00212 #endif