test_coldelecResponse.cxx
Go to the documentation of this file.
1 // test_coldelecResponse.cxx
2 
3 // David Adams
4 // May 2018
5 //
6 // This is a test and demonstration for coldelecResponse.
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_coldelecResponse: ";
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  double gain0 = 100.0;
43  double shap0 = 5.0;
44  double toff0 = 10.0;
45  vector<double> dtoffs = {0.0, 0.2, 0.4, 0.6, 0.8};
46  Index noff = dtoffs.size();
47  vector<TF1*> pfs;
48  for ( double fac : {1.0, 0.8, 0.5} ) {
49  double gain = gain0/fac;
50  double shap = fac*shap0;
51  for ( Index ioff=0; ioff<noff; ++ioff ) {
52  double toff = toff0 + dtoffs[ioff];
53  pfs.push_back(coldelecResponseTF1(gain, shap, toff));
54  }
55  }
56  vector<double> areas;
57  vector<double> arats;
58  for ( TF1* pf : pfs ) {
59  double a = pf->Integral(0,30);
60  areas.push_back(a);
61  double arat = a/pf->GetParameter(0)/pf->GetParameter(1);
62  arats.push_back(arat);
63  }
64 
65  cout << myname << line << endl;
66  cout << "Display waveforms." << endl;
67  cout.precision(2);
68  int w = 7;
69  TF1* pf0 = pfs[0];
70  for ( int ipar=0; ipar<pf0->GetNpar(); ++ipar ) {
71  string parName = pf0->GetParName(ipar);
72  cout << setw(10) << parName << ":";
73  for ( TF1* pf : pfs ) cout << setw(w) << std::fixed << pf->GetParameter(ipar);
74  cout << endl;
75  }
76  for ( double t=0.0; t<30.0; t+=1.0 ) {
77  cout << setw(10) << t << ":";
78  for ( TF1* pf : pfs ) {
79  double wf = pf->Eval(t);
80  cout << setw(w) << std::fixed << wf;
81  }
82  cout << endl;
83  }
84  cout << setw(10) << "area" << ":";
85  for ( double area : areas ) cout << setw(w) << std::fixed << area;
86  cout << endl;
87  cout.precision(4);
88  cout << setw(10) << "A/h/s" << ":";
89  for ( double arat : arats ) cout << setw(w) << std::fixed << arat;
90  cout << endl;
91 
92  cout << myname << line << endl;
93  cout << myname << "Done." << endl;
94  return 0;
95 }
96 
97 //**********************************************************************
98 
99 int main() {
100  return test_coldelecResponse();
101 }
102 
103 //**********************************************************************
std::string string
Definition: nybbler.cc:12
struct vector vector
unsigned int Index
int precision() const
Definition: qtextstream.h:259
const double a
size_t size
Definition: lodepng.cpp:55
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int main()
TF1 * coldelecResponseTF1(double gainIn, double shapingIn, double t0, std::string fname="ceresp")
void line(double t, double *p, double &x, double &y, double &z)
int test_coldelecResponse()
QTextStream & endl(QTextStream &s)