inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/sg/fit2plot
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_sg_fit2plot
00005 #define inlib_sg_fit2plot
00006 
00007 // Inheritance :
00008 #include "plottable"
00009 
00010 #include "../smanip"
00011 
00012 namespace inlib {
00013 namespace sg {
00014 
00015 class fit2plot : public virtual plottable {
00016 public:
00017   static const std::string& s_class() {
00018     static const std::string s_v("inlib::sg::fit2plot");
00019     return s_v;
00020   }
00021 public:
00022   virtual void* cast(const std::string& a_class) const {
00023     if(void* p = inlib::cmp_cast<fit2plot>(this,a_class)) {return p;}
00024     return plottable::cast(a_class);
00025   }
00026 public: //plottable
00027   virtual plottable* copy() const {return new fit2plot(*this);}
00028   virtual bool is_valid() const {return true;}
00029   virtual std::string name(){return m_name;}
00030   virtual void set_name(const std::string& a_s) {m_name = a_s;}
00031   virtual std::string title(){return "";}
00032   virtual std::string legend(){return m_legend;}
00033   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
00034 
00035   virtual std::string infos(const std::string& a_opts){
00036     std::string f_lf("\n");
00037     std::string sinfos;
00038     std::vector<std::string> words;
00039     inlib::words(a_opts," ",false,words);
00040     std::vector<std::string>::const_iterator it;
00041   
00042     bool show_fit_ndf = false;
00043    {for(it=words.begin();it!=words.end();++it) {
00044       if((*it)=="fit_ndf") {show_fit_ndf = true;break;}
00045     }}
00046     bool show_fit_errors = false;
00047    {for(it=words.begin();it!=words.end();++it) {
00048       if((*it)=="fit_errors") {show_fit_errors = true;break;}
00049     }}
00050 
00051     for(it=words.begin();it!=words.end();++it) {
00052       if(((*it)=="name") && m_name.size()) {
00053         if(sinfos.size()) sinfos += f_lf;
00054         sinfos += "Name";
00055         sinfos += f_lf;
00056         sinfos += m_name;
00057   
00058       } else if((*it)=="fit_quality") {
00059         if(show_fit_ndf) {
00060           if(sinfos.size()) sinfos += f_lf;
00061           sinfos += "[h]^2! / ndf";
00062           sinfos += f_lf; 
00063           sinfos += to(m_output[0]);
00064           sinfos += " / "; 
00065           sinfos += to(m_output[1]);
00066         } else { //show chi2 only.
00067           if(sinfos.size()) sinfos += f_lf;
00068           sinfos += "[h]^2!";
00069           sinfos += f_lf;
00070           sinfos += to(m_output[0]);
00071         }
00072 
00073       } else if((*it)=="fit_parameters") {
00074         unsigned int nparam = m_names.size();
00075         for(unsigned int iparam=0;iparam<nparam;iparam++) {
00076           if(show_fit_errors) {
00077             if(sinfos.size()) sinfos += f_lf;
00078             sinfos += m_names[iparam];
00079             sinfos += f_lf;
00080             sinfos += to(m_output[2+4*iparam+0]); //value
00081             sinfos += " +&_ ";
00082             sinfos += to(m_output[2+4*iparam+1]); //error
00083           } else {
00084             if(sinfos.size()) sinfos += f_lf;
00085             sinfos += m_names[iparam];
00086             sinfos += f_lf;
00087             sinfos += to(m_output[2+4*iparam+0]);
00088           }
00089         }
00090       }
00091     }
00092   
00093     return sinfos;
00094   }
00095 public:
00096   fit2plot(const std::vector<std::string>& a_names,const std::vector<double>& a_output)
00097   :m_names(a_names)
00098   ,m_output(a_output)
00099   {
00100     unsigned int nparam = (m_output.size()-2)/4;
00101     if(m_names.size()!=nparam) {
00102       //should issue a warning.
00103       m_names.clear();
00104       m_output.clear();
00105     }
00106   }
00107   virtual ~fit2plot(){}
00108 protected:
00109   fit2plot(const fit2plot& a_from)
00110   : plottable(a_from)
00111   ,m_names(a_from.m_names)
00112   ,m_output(a_from.m_output)
00113   ,m_name(a_from.m_name)
00114   ,m_legend(a_from.m_legend)
00115   {}  
00116 private:
00117   fit2plot& operator=(const fit2plot&){return *this;}
00118 private:
00119   std::vector<std::string> m_names;
00120   std::vector<double> m_output;
00121   std::string m_name;
00122   std::string m_legend;
00123 };
00124 
00125 }}
00126 
00127 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines