Typedefs | Functions
test_RootParFormula.cxx File Reference
#include "../RootParFormula.h"
#include <string>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include "TH1F.h"
#include "TCanvas.h"

Go to the source code of this file.

Typedefs

using Index = unsigned int
 
using DVec = std::vector< double >
 

Functions

bool floatcheck (double x1, double x2)
 
int test_RootParFormula ()
 
int main ()
 

Typedef Documentation

using DVec = std::vector<double>

Definition at line 26 of file test_RootParFormula.cxx.

using Index = unsigned int

Definition at line 25 of file test_RootParFormula.cxx.

Function Documentation

bool floatcheck ( double  x1,
double  x2 
)

Definition at line 30 of file test_RootParFormula.cxx.

30  {
31  return fabs(x1-x2) < 1.e-4;
32 }
int main ( void  )

Definition at line 142 of file test_RootParFormula.cxx.

142  {
143  return test_RootParFormula();
144 }
int test_RootParFormula()
int test_RootParFormula ( )

Definition at line 36 of file test_RootParFormula.cxx.

36  {
37  const string myname = "test_RootParFormula: ";
38  cout << myname << "Starting test" << endl;
39 #ifdef NDEBUG
40  cout << myname << "NDEBUG must be off." << endl;
41  abort();
42 #endif
43  string line = "-----------------------------";
44  string scfg;
45 
46  cout << myname << line << endl;
47  cout << myname << "Create formula and check." << endl;
48  string snam = "myform";
49  string sform = "[offset] + [scale]*x";
50  RootParFormula rpf(snam, sform);
51  cout << myname << "Name: " << rpf.name() << endl;
52  assert( rpf.name() == snam );
53  cout << myname << "Formula: " << rpf.formulaString() << endl;
54  assert( rpf.formulaString() == sform );
55  cout << myname << "# params: " << rpf.npar() << endl;
56  assert( rpf.npar() == 2 );
57  cout << myname << "Params: [";
58  bool first = true;
59  for ( string nam : rpf.pars() ) {
60  if ( first ) first = false;
61  else cout << ", ";
62  cout << nam;
63  }
64  cout << "]" << endl;
65  assert( rpf.pars().size() == 2 );
66  assert( rpf.pars()[0] == "offset" );
67  assert( rpf.pars()[1] == "scale" );
68  cout << myname << "# vars: " << rpf.nvar() << endl;
69  assert( rpf.nvar() == 1 );
70  assert( rpf.setPars().size() == 0 );
71  assert( rpf.unsetPars().size() == 2 );
72  assert( rpf.resetPars().size() == 0 );
73  assert( rpf.pars().size() == 2 );
74  assert( ! rpf.ready() );
75 
76  cout << myname << line << endl;
77  cout << myname << "Check par names" << endl;
78  assert( rpf.isPar("offset") );
79  assert( rpf.isPar("scale") );
80  assert( ! rpf.isPar("nosuch") );
81 
82  cout << myname << line << endl;
83  cout << myname << "Set parameters." << endl;
84  assert( rpf.unsetPars().size() == 2 );
85  assert( rpf.resetPars().size() == 0 );
86  assert( ! rpf.ready() );
87  rpf.setParValue("offset", 10.0);
88  assert( rpf.unsetPars().size() == 1 );
89  assert( rpf.resetPars().size() == 0 );
90  assert( ! rpf.ready() );
91  rpf.setParValue("scale", 3.0);
92  assert( rpf.unsetPars().size() == 0 );
93  assert( rpf.resetPars().size() == 0 );
94  assert( rpf.ready() );
95  rpf.setParValue("scale", 2.0);
96  assert( rpf.unsetPars().size() == 0 );
97  assert( rpf.resetPars().size() == 1 );
98  assert( rpf.ready() );
99 
100  cout << myname << line << endl;
101  cout << myname << "Check eval." << endl;
102  DVec vals = { 0.0, 1.0, 2.0 };
103  DVec evcs = { 10.0, 12.0, 14.0 };
104  for ( Index ival=0; ival<vals.size(); ++ival ) {
105  double eval = rpf.eval(vals[ival]);
106  cout << myname << " " << vals[ival] << ": " << eval << endl;
107  assert( floatcheck(eval, evcs[ival]) );
108  DVec vars = { vals[ival] };
109  double eval2 = rpf.eval(vars);
110  assert( floatcheck(eval2, evcs[ival]) );
111  }
112 
113  cout << myname << line << endl;
114  cout << myname << "Set default eval." << endl;
115  double def = rpf.defaultEval();
116  assert( floatcheck(def, 0.0 ) );
117  assert( rpf.setDefaultEval(99.0) == 0 );
118  def = rpf.defaultEval();
119  assert( floatcheck(def, 99.0) );
120 
121  cout << myname << line << endl;
122  cout << myname << "Reset pars." << endl;
123  assert( rpf.ready() );
124  assert( floatcheck(rpf.eval(0.0), 10.0) );
125  assert( rpf.unsetParValues() == 0 );
126  assert( ! rpf.ready() );
127  assert( floatcheck(rpf.eval(0.0), 99.0) );
128  rpf.setParValue("offset", 10.0);
129  assert( ! rpf.ready() );
130  rpf.setParValue("scale", 3.0);
131  assert( rpf.ready() );
132  assert( floatcheck(rpf.eval(0.0), 10.0) );
133 
134  cout << myname << line << endl;
135  cout << myname << "Done." << endl;
136 
137  return 0;
138 }
unsigned int Index
bool floatcheck(double x1, double x2)
std::vector< double > DVec
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)