test_offsetLine.cxx
Go to the documentation of this file.
1 // test_offsetLine.cxx
2 
3 // David Adams
4 // May 2018
5 //
6 // This is a test and demonstration for offsetLine.
7 
8 #undef NDEBUG
9 
11 #include <string>
12 #include <iostream>
13 #include <iomanip>
14 #include <vector>
15 #include <cassert>
16 
17 using std::string;
18 using std::cout;
19 using std::endl;
20 using std::setw;
21 using std::vector;
22 
23 using Index = unsigned int;
24 
25 //**********************************************************************
26 
28  const string myname = "test_offsetLine: ";
29  cout << myname << "Starting test" << endl;
30 #ifdef NDEBUG
31  cout << myname << "NDEBUG must be off." << endl;
32  abort();
33 #endif
34  string line = "-----------------------------";
35  string scfg;
36 
37  cout << myname << line << endl;
38  cout << "Testing TF1." << endl;
39 
40  cout << myname << line << endl;
41  cout << "Build waveforms." << endl;
42  vector<double> offs = {-3.5, -1.2, 4.4};
43  vector<double> slps = {-1.0, 1.0, 2.0};
44  vector<TF1*> pfs;
45  for ( double slp : slps ) {
46  for ( double off : offs ) {
47  pfs.push_back(offsetLineTF1(off, slp));
48  }
49  }
50 
51  cout << myname << line << endl;
52  cout << "Display waveforms." << endl;
53  cout.precision(2);
54  int w = 7;
55  TF1* pf0 = pfs[0];
56  for ( int ipar=0; ipar<pf0->GetNpar(); ++ipar ) {
57  string parName = pf0->GetParName(ipar);
58  cout << setw(10) << parName << ":";
59  for ( TF1* pf : pfs ) cout << setw(w) << std::fixed << pf->GetParameter(ipar);
60  cout << endl;
61  }
62  for ( double t=-8.0; t<8.0; t+=1.0 ) {
63  cout << setw(10) << t << ":";
64  for ( TF1* pf : pfs ) {
65  double wf = pf->Eval(t);
66  cout << setw(w) << std::fixed << wf;
67  }
68  cout << endl;
69  }
70 
71  cout << myname << line << endl;
72  cout << myname << "Done." << endl;
73  return 0;
74 }
75 
76 //**********************************************************************
77 
78 int main() {
79  return test_offsetLine();
80 }
81 
82 //**********************************************************************
TF1 * offsetLineTF1(double off=0.0, double slope=1.0, double xmin=-10.0, double xmax=10.0, std::string fname="offsetLine")
Definition: offsetLine.h:91
std::string string
Definition: nybbler.cc:12
struct vector vector
unsigned int Index
int test_offsetLine()
int precision() const
Definition: qtextstream.h:259
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int main()
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)