Warning, /include/Geant4/tools/sg/fit2plot 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_sg_fit2plot
0005 #define tools_sg_fit2plot
0006
0007 #include "plottables"
0008
0009 #include "../tokenize"
0010 #include "../num2s"
0011
0012 namespace tools {
0013 namespace sg {
0014
0015 class fit2plot : public virtual plottable {
0016 static const std::string& s_empty() {
0017 static const std::string s_v("");
0018 return s_v;
0019 }
0020 public:
0021 static const std::string& s_class() {
0022 static const std::string s_v(s_tools_sg_fit2plot());
0023 return s_v;
0024 }
0025 public:
0026 virtual void* cast(const std::string& a_class) const {
0027 if(void* p = cmp_cast<fit2plot>(this,a_class)) {return p;}
0028 return plottable::cast(a_class);
0029 }
0030 public: //plottable
0031 virtual plottable* copy() const {return new fit2plot(*this);}
0032 virtual bool is_valid() const {return true;}
0033 virtual const std::string& name() const {return m_name;}
0034 virtual void set_name(const std::string& a_s) {m_name = a_s;}
0035 virtual const std::string& title() const {return s_empty();}
0036 virtual const std::string& legend() const {return m_legend;}
0037 virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0038
0039 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0040 a_sinfos.clear();
0041 std::string f_lf("\n");
0042 std::vector<std::string> ws;
0043 words(a_opts," ",false,ws);
0044 std::vector<std::string>::const_iterator it;
0045
0046 bool show_fit_ndf = false;
0047 {for(it=ws.begin();it!=ws.end();++it) {
0048 if((*it)=="fit_ndf") {show_fit_ndf = true;break;}
0049 }}
0050 bool show_fit_errors = false;
0051 {for(it=ws.begin();it!=ws.end();++it) {
0052 if((*it)=="fit_errors") {show_fit_errors = true;break;}
0053 }}
0054
0055 for(it=ws.begin();it!=ws.end();++it) {
0056 if(((*it)=="name") && m_name.size()) {
0057 if(a_sinfos.size()) a_sinfos += f_lf;
0058 a_sinfos += "Name";
0059 a_sinfos += f_lf;
0060 a_sinfos += m_name;
0061
0062 } else if((*it)=="fit_quality") {
0063 if(show_fit_ndf) {
0064 if(a_sinfos.size()) a_sinfos += f_lf;
0065 a_sinfos += "[h]^2! / ndf";
0066 a_sinfos += f_lf;
0067 if(!numas<double>(m_output[0],a_sinfos)){}
0068 a_sinfos += " / ";
0069 if(!numas<double>(m_output[1],a_sinfos)){}
0070 } else { //show chi2 only.
0071 if(a_sinfos.size()) a_sinfos += f_lf;
0072 a_sinfos += "[h]^2!";
0073 a_sinfos += f_lf;
0074 if(!numas<double>(m_output[0],a_sinfos)){}
0075 }
0076
0077 } else if((*it)=="fit_parameters") {
0078 size_t nparam = m_names.size();
0079 for(size_t iparam=0;iparam<nparam;iparam++) {
0080 if(show_fit_errors) {
0081 if(a_sinfos.size()) a_sinfos += f_lf;
0082 a_sinfos += m_names[iparam];
0083 a_sinfos += f_lf;
0084 if(!numas<double>(m_output[2+4*iparam+0],a_sinfos)){} //value
0085 a_sinfos += " +&_ ";
0086 if(!numas<double>(m_output[2+4*iparam+1],a_sinfos)){} //error
0087 } else {
0088 if(a_sinfos.size()) a_sinfos += f_lf;
0089 a_sinfos += m_names[iparam];
0090 a_sinfos += f_lf;
0091 if(!numas<double>(m_output[2+4*iparam+0],a_sinfos)){}
0092 }
0093 }
0094 }
0095 }
0096 }
0097 public:
0098 fit2plot(const std::vector<std::string>& a_names,
0099 const std::vector<double>& a_output)
0100 :m_names(a_names)
0101 ,m_output(a_output)
0102 {
0103 size_t nparam = (m_output.size()-2)/4;
0104 if(m_names.size()!=nparam) {
0105 //should issue a warning.
0106 m_names.clear();
0107 m_output.clear();
0108 }
0109 }
0110 virtual ~fit2plot(){
0111 }
0112 public:
0113 fit2plot(const fit2plot& a_from)
0114 : plottable(a_from)
0115 ,m_names(a_from.m_names)
0116 ,m_output(a_from.m_output)
0117 ,m_name(a_from.m_name)
0118 ,m_legend(a_from.m_legend)
0119 {
0120 }
0121 fit2plot& operator=(const fit2plot& a_from){
0122 m_names = a_from.m_names;
0123 m_output = a_from.m_output;
0124 m_name = a_from.m_name;
0125 m_legend = a_from.m_legend;
0126 return *this;
0127 }
0128 protected:
0129 std::vector<std::string> m_names;
0130 std::vector<double> m_output;
0131 std::string m_name;
0132 std::string m_legend;
0133 };
0134
0135 }}
0136
0137 #endif