g4tools  5.4.0
fit2plot
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_fit2plot
5 #define tools_sg_fit2plot
6 
7 #include "plottables"
8 
9 #include "../words"
10 #include "../num2s"
11 
12 #ifdef TOOLS_MEM
13 #include "../mem"
14 #endif
15 
16 namespace tools {
17 namespace sg {
18 
19 class fit2plot : public virtual plottable {
20  static const std::string& s_empty() {
21  static const std::string s_v("");
22  return s_v;
23  }
24 public:
25  static const std::string& s_class() {
26  static const std::string s_v(s_tools_sg_fit2plot());
27  return s_v;
28  }
29 public:
30  virtual void* cast(const std::string& a_class) const {
31  if(void* p = cmp_cast<fit2plot>(this,a_class)) {return p;}
32  return plottable::cast(a_class);
33  }
34 public: //plottable
35  virtual plottable* copy() const {return new fit2plot(*this);}
36  virtual bool is_valid() const {return true;}
37  virtual const std::string& name() const {return m_name;}
38  virtual void set_name(const std::string& a_s) {m_name = a_s;}
39  virtual const std::string& title() const {return s_empty();}
40  virtual const std::string& legend() const {return m_legend;}
41  virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
42 
43  virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
44  a_sinfos.clear();
45  std::string f_lf("\n");
46  std::vector<std::string> ws;
47  words(a_opts," ",false,ws);
48  std::vector<std::string>::const_iterator it;
49 
50  bool show_fit_ndf = false;
51  {for(it=ws.begin();it!=ws.end();++it) {
52  if((*it)=="fit_ndf") {show_fit_ndf = true;break;}
53  }}
54  bool show_fit_errors = false;
55  {for(it=ws.begin();it!=ws.end();++it) {
56  if((*it)=="fit_errors") {show_fit_errors = true;break;}
57  }}
58 
59  for(it=ws.begin();it!=ws.end();++it) {
60  if(((*it)=="name") && m_name.size()) {
61  if(a_sinfos.size()) a_sinfos += f_lf;
62  a_sinfos += "Name";
63  a_sinfos += f_lf;
64  a_sinfos += m_name;
65 
66  } else if((*it)=="fit_quality") {
67  if(show_fit_ndf) {
68  if(a_sinfos.size()) a_sinfos += f_lf;
69  a_sinfos += "[h]^2! / ndf";
70  a_sinfos += f_lf;
71  if(!numas<double>(m_output[0],a_sinfos)){}
72  a_sinfos += " / ";
73  if(!numas<double>(m_output[1],a_sinfos)){}
74  } else { //show chi2 only.
75  if(a_sinfos.size()) a_sinfos += f_lf;
76  a_sinfos += "[h]^2!";
77  a_sinfos += f_lf;
78  if(!numas<double>(m_output[0],a_sinfos)){}
79  }
80 
81  } else if((*it)=="fit_parameters") {
82  size_t nparam = m_names.size();
83  for(size_t iparam=0;iparam<nparam;iparam++) {
84  if(show_fit_errors) {
85  if(a_sinfos.size()) a_sinfos += f_lf;
86  a_sinfos += m_names[iparam];
87  a_sinfos += f_lf;
88  if(!numas<double>(m_output[2+4*iparam+0],a_sinfos)){} //value
89  a_sinfos += " +&_ ";
90  if(!numas<double>(m_output[2+4*iparam+1],a_sinfos)){} //error
91  } else {
92  if(a_sinfos.size()) a_sinfos += f_lf;
93  a_sinfos += m_names[iparam];
94  a_sinfos += f_lf;
95  if(!numas<double>(m_output[2+4*iparam+0],a_sinfos)){}
96  }
97  }
98  }
99  }
100  }
101 public:
102  fit2plot(const std::vector<std::string>& a_names,
103  const std::vector<double>& a_output)
104  :m_names(a_names)
105  ,m_output(a_output)
106  {
107 #ifdef TOOLS_MEM
108  mem::increment(s_class().c_str());
109 #endif
110  size_t nparam = (m_output.size()-2)/4;
111  if(m_names.size()!=nparam) {
112  //should issue a warning.
113  m_names.clear();
114  m_output.clear();
115  }
116  }
117  virtual ~fit2plot(){
118 #ifdef TOOLS_MEM
119  mem::decrement(s_class().c_str());
120 #endif
121  }
122 public:
123  fit2plot(const fit2plot& a_from)
124  : plottable(a_from)
125  ,m_names(a_from.m_names)
126  ,m_output(a_from.m_output)
127  ,m_name(a_from.m_name)
128  ,m_legend(a_from.m_legend)
129  {
130 #ifdef TOOLS_MEM
131  mem::increment(s_class().c_str());
132 #endif
133  }
134  fit2plot& operator=(const fit2plot& a_from){
135  m_names = a_from.m_names;
136  m_output = a_from.m_output;
137  m_name = a_from.m_name;
138  m_legend = a_from.m_legend;
139  return *this;
140  }
141 protected:
142  std::vector<std::string> m_names;
143  std::vector<double> m_output;
144  std::string m_name;
145  std::string m_legend;
146 };
147 
148 }}
149 
150 #endif
tools::sg::fit2plot::name
virtual const std::string & name() const
Definition: fit2plot:37
tools::sg::plottable::cast
virtual void * cast(const std::string &a_class) const
Definition: plottable:19
tools::sg::fit2plot::m_output
std::vector< double > m_output
Definition: fit2plot:143
tools::sg::fit2plot::~fit2plot
virtual ~fit2plot()
Definition: fit2plot:117
tools::sg::fit2plot::title
virtual const std::string & title() const
Definition: fit2plot:39
tools::sg::fit2plot::fit2plot
fit2plot(const std::vector< std::string > &a_names, const std::vector< double > &a_output)
Definition: fit2plot:102
tools::sg::plottable
Definition: plottable:15
tools::sg::s_tools_sg_fit2plot
const std::string & s_tools_sg_fit2plot()
Definition: plottables:162
tools::sg::fit2plot::m_names
std::vector< std::string > m_names
Definition: fit2plot:142
tools::sg::fit2plot::operator=
fit2plot & operator=(const fit2plot &a_from)
Definition: fit2plot:134
tools::sg::fit2plot::legend
virtual const std::string & legend() const
Definition: fit2plot:40
tools::sg::fit2plot::set_name
virtual void set_name(const std::string &a_s)
Definition: fit2plot:38
tools::sg::fit2plot::s_class
static const std::string & s_class()
Definition: fit2plot:25
plottables
tools::sg::fit2plot::copy
virtual plottable * copy() const
Definition: fit2plot:35
tools::sg::fit2plot::cast
virtual void * cast(const std::string &a_class) const
Definition: fit2plot:30
tools::sg::fit2plot::infos
virtual void infos(const std::string &a_opts, std::string &a_sinfos) const
Definition: fit2plot:43
tools::sg::fit2plot::set_legend
virtual void set_legend(const std::string &a_s)
Definition: fit2plot:41
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
tools::sg::fit2plot
Definition: fit2plot:19
tools::sg::fit2plot::is_valid
virtual bool is_valid() const
Definition: fit2plot:36
tools::sg::fit2plot::m_name
std::string m_name
Definition: fit2plot:144
tools::sg::fit2plot::m_legend
std::string m_legend
Definition: fit2plot:145
tools::sg::fit2plot::fit2plot
fit2plot(const fit2plot &a_from)
Definition: fit2plot:123