Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/histo/dps is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_histo_dps
0005 #define tools_histo_dps
0006 
0007 // data point set.
0008 
0009 #include <vector>
0010 #include <string>
0011 #include "../mnmx"
0012 
0013 #ifdef TOOLS_MEM
0014 #include "../mem"
0015 #endif
0016 
0017 namespace tools {
0018 namespace histo {
0019 
0020 class measurement {
0021   static const std::string& s_class() {
0022     static const std::string s_v("tools::histo::measurement");
0023     return s_v;
0024   }
0025 public:
0026   measurement():m_value(0),m_error_plus(0),m_error_minus(0){
0027 #ifdef TOOLS_MEM
0028     mem::increment(s_class().c_str());
0029 #endif
0030   }
0031   measurement(double a_value,double a_error_plus,double a_error_minus)
0032   :m_value(a_value)
0033   ,m_error_plus(a_error_plus)
0034   ,m_error_minus(a_error_minus)
0035   {
0036 #ifdef TOOLS_MEM
0037     mem::increment(s_class().c_str());
0038 #endif
0039   }
0040   virtual ~measurement(){
0041 #ifdef TOOLS_MEM
0042     mem::decrement(s_class().c_str());
0043 #endif
0044   }
0045 public:
0046   measurement(const measurement& a_from)
0047   :m_value(a_from.m_value)
0048   ,m_error_plus(a_from.m_error_plus)
0049   ,m_error_minus(a_from.m_error_minus)
0050   {
0051 #ifdef TOOLS_MEM
0052     mem::increment(s_class().c_str());
0053 #endif
0054   }
0055   measurement& operator=(const measurement& a_from) {
0056     if(&a_from==this) return *this;
0057     m_value = a_from.m_value;
0058     m_error_plus = a_from.m_error_plus;
0059     m_error_minus = a_from.m_error_minus;
0060     return *this;
0061   }
0062 public:
0063   double value() const {return m_value;}
0064   double error_plus() const {return m_error_plus;}
0065   double error_minus() const {return m_error_minus;}
0066   void set_value(double a_v) {m_value = a_v;}
0067   void set_error_plus(double a_v) {m_error_plus = a_v;}
0068   void set_error_minus(double a_v) {m_error_minus = a_v;}
0069 protected:
0070   double m_value;
0071   double m_error_plus;
0072   double m_error_minus;
0073 };
0074 
0075 class data_point {
0076   static const std::string& s_class() {
0077     static const std::string s_v("tools::histo::data_point");
0078     return s_v;
0079   }
0080 public:
0081   data_point(unsigned int a_dim):m_measurements(a_dim){
0082 #ifdef TOOLS_MEM
0083     mem::increment(s_class().c_str());
0084 #endif
0085   }
0086   virtual ~data_point() {
0087 #ifdef TOOLS_MEM
0088     mem::decrement(s_class().c_str());
0089 #endif
0090   }
0091 public:
0092   data_point(const data_point& a_from)
0093   :m_measurements(a_from.m_measurements)
0094   {
0095 #ifdef TOOLS_MEM
0096     mem::increment(s_class().c_str());
0097 #endif
0098   }
0099   data_point& operator=(const data_point& a_from) {
0100     if(&a_from==this) return *this;
0101     m_measurements = a_from.m_measurements;
0102     return *this;
0103   }
0104 public: //AIDA/Idata_point
0105   size_t dimension() const {return m_measurements.size();}
0106   measurement& coordinate(unsigned int a_coord) {
0107     //WARNING : no check done on a_coord vs m_dim.
0108     return m_measurements[a_coord];
0109   }
0110   const measurement& coordinate(unsigned int a_coord) const {
0111     //WARNING : no check done on a_coord vs m_dim.
0112     return m_measurements[a_coord];
0113   }
0114 protected:
0115   std::vector<measurement> m_measurements;
0116 };
0117 
0118 
0119 class dps {
0120 public:
0121   static const std::string& s_class() {
0122     static const std::string s_v("tools::histo::dps");
0123     return s_v;
0124   }
0125 public:
0126   dps():m_dim(0){}
0127 
0128   dps(const std::string& a_title,unsigned int a_dim)
0129   :m_title(a_title),m_dim(a_dim)
0130   {}
0131   virtual ~dps(){}
0132 public:
0133   dps(const dps& a_from)
0134   :m_title(a_from.m_title)
0135   ,m_dim(a_from.m_dim)
0136   ,m_points(a_from.m_points)
0137   {}
0138   dps& operator=(const dps& a_from) {
0139     if(&a_from==this) return *this;
0140     m_title = a_from.m_title;
0141     m_dim = a_from.m_dim;
0142     m_points = a_from.m_points;
0143     return *this;
0144   }
0145 
0146 public:
0147   const std::string& title() const {return m_title;}
0148 
0149   void set_title(const std::string& a_s) {m_title = a_s;}
0150 
0151   unsigned int dimension() const {return m_dim;}
0152   void clear() {m_points.clear();}
0153   size_t size() const {return m_points.size();}
0154 
0155   const data_point& point(size_t a_index) const {
0156     //WARNING : no check done on a_index.
0157     return m_points[a_index];
0158   }
0159   data_point& point(size_t a_index) {
0160     //WARNING : no check done on a_index.
0161     return m_points[a_index];
0162   }
0163 
0164   data_point& add_point() {
0165     m_points.push_back(data_point(m_dim));
0166     return m_points.back();
0167   }
0168 
0169   bool remove_point(size_t a_index) {
0170     bool done = false;
0171     if(a_index<m_points.size()){
0172       std::vector<data_point>::iterator it = m_points.begin();
0173       it += a_index;
0174       m_points.erase(it);
0175       done = true;
0176     }
0177     return done;
0178   }
0179 
0180   bool lower_extent(unsigned int a_coord,double& a_value) const {
0181     if(m_points.empty()||(a_coord>=m_dim)){
0182       a_value = 0;
0183       return false;
0184     }
0185     std::vector<data_point>::const_iterator it = m_points.begin();
0186     a_value = (*it).coordinate(a_coord).value();
0187     ++it;
0188     for(;it!=m_points.end();++it) {
0189       a_value = mn<double>(a_value,(*it).coordinate(a_coord).value());
0190     }
0191     return true;
0192   }
0193 
0194   bool upper_extent(unsigned int a_coord,double& a_value) const {
0195     if(m_points.empty()||(a_coord>=m_dim)){
0196       a_value = 0;
0197       return false;
0198     }
0199     std::vector<data_point>::const_iterator it = m_points.begin();
0200     a_value = (*it).coordinate(a_coord).value();
0201     ++it;
0202     for(;it!=m_points.end();++it) {
0203       a_value = mx<double>(a_value,(*it).coordinate(a_coord).value());
0204     }
0205     return true;
0206   }
0207 
0208   void scale(double a_scale) {
0209     std::vector<data_point>::iterator it;
0210     for(it=m_points.begin();it!=m_points.end();++it) {
0211       for(unsigned int coord=0;coord<m_dim;coord++) {
0212         measurement& _m = (*it).coordinate(coord);
0213         _m.set_value(_m.value() * a_scale);
0214         _m.set_error_plus(_m.error_plus() * a_scale);
0215         _m.set_error_minus(_m.error_minus() * a_scale);
0216       }
0217     }
0218   }
0219 
0220   void scale_value(double a_scale) {
0221     std::vector<data_point>::iterator it;
0222     for(it=m_points.begin();it!=m_points.end();++it) {
0223       for(unsigned int coord=0;coord<m_dim;coord++) {
0224         measurement& _m = (*it).coordinate(coord);
0225         _m.set_value(_m.value() * a_scale);
0226       }
0227     }
0228   }
0229 
0230   void scale_errors(double a_scale) {
0231     std::vector<data_point>::iterator it;
0232     for(it=m_points.begin();it!=m_points.end();++it) {
0233       for(unsigned int coord=0;coord<m_dim;coord++) {
0234         measurement& _m = (*it).coordinate(coord);
0235         _m.set_error_plus(_m.error_plus() * a_scale);
0236         _m.set_error_minus(_m.error_minus() * a_scale);
0237       }
0238     }
0239   }
0240 
0241 protected:
0242   std::string m_title;
0243   unsigned int m_dim;
0244   std::vector<data_point> m_points;
0245 };
0246 
0247 }}
0248 
0249 #endif