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