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

Go to the source code of this file.

Typedefs

using FloatVector = SampleTailer::FloatVector
 
using Index = unsigned int
 
using IndexVector = std::vector< Index >
 

Functions

int test_SampleTailer (bool useVector)
 
int main (int argc, char **)
 

Typedef Documentation

Definition at line 26 of file test_SampleTailer.cxx.

using Index = unsigned int

Definition at line 27 of file test_SampleTailer.cxx.

Definition at line 28 of file test_SampleTailer.cxx.

Function Documentation

int main ( int  argc,
char **   
)

Definition at line 183 of file test_SampleTailer.cxx.

183  {
184  bool useVector = argc > 1;
185  return test_SampleTailer(useVector);
186 }
int test_SampleTailer(bool useVector)
int test_SampleTailer ( bool  useVector)

Definition at line 85 of file test_SampleTailer.cxx.

85  {
86  const string myname = "test_SampleTailer: ";
87  cout << myname << "Starting test" << endl;
88 #ifdef NDEBUG
89  cout << myname << "NDEBUG must be off." << endl;
90  abort();
91 #endif
92  string scfg;
93 
94  cout << myname << "Create signals." << endl;
95  Index nsam = 300;
96  FloatVector pulse = { 0.1, 4.5, 15.2, 66.4, 94.3, 100.0, 96.5, 88.4, 72.6, 58.4,
97  42.3, 35.1, 26.0, 18.6, 12.6, 8.8, 6.9, 4.4, 2.0, 0.3 };
98  Index npul = pulse.size();
99  FloatVector sigs1(nsam, 0.0);
100  IndexVector peakPoss = {10, 100, 115, 230};
101  FloatVector peakAmps = {0.5, 2.0, 0.7, 1.0};
102  Index npea = peakPoss.size();
103  for ( Index ipea=0; ipea<npea; ++ipea ) {
104  Index iposPeak = peakPoss[ipea];
105  float norm = peakAmps[ipea];
106  for ( Index ipul=0; ipul<npul; ++ipul ) {
107  Index isam = iposPeak + ipul;
108  if ( isam >= nsam ) break;
109  sigs1[isam] += norm*pulse[ipul];
110  }
111  }
112 
113  cout << myname << "Create utility." << endl;
114  SampleTailer sta(100.0);
115  FloatVector peds(nsam);
116  for ( unsigned int isam=0; isam<peds.size(); ++isam ) {
117  peds[isam] = 5.0 + 0.1*isam;
118  }
119  if ( useVector ) {
120  sta.setPedestalVector(&peds);
121  } else {
122  sta.setPedestal(5.0);
123  }
124  sta.setTail0(-15.0);
125  sta.setUnit("ADC count");
126  cout << myname << " decayTime: " << sta.decayTime() << endl;
127  cout << myname << " beta: " << sta.beta() << endl;
128  cout << myname << " alpha: " << sta.alpha() << endl;
129  cout << myname << " pedestal: " << sta.pedestal() << endl;
130  cout << myname << " tail0: " << sta.tail0() << endl;
131 
132  cout << myname << line() << endl;
133  cout << myname << "Create data from signal." << endl;
134  assert( sta.setSignal(sigs1) == 0 );
135  assert( sta.data().size() == nsam );
136  assert( sta.signal().size() == nsam );
137  assert( sta.tail().size() == nsam );
138  FloatVector dats1 = sta.data();
139  sta.makeHists();
140  printResults(sta);
141  drawResults(sta, "Data, signal and tail from signal", "SampleTrailerFromSignal.png");
142 
143  cout << myname << line() << endl;
144  cout << myname << "Create signal from data." << endl;
145  sta.clear();
146  assert( sta.data().size() == 0 );
147  assert( sta.signal().size() == 0 );
148  assert( sta.tail().size() == 0 );
149  assert( sta.setData(dats1) == 0 );
150  assert( sta.data().size() == nsam );
151  assert( sta.signal().size() == nsam );
152  assert( sta.tail().size() == nsam );
153  FloatVector sigs2 = sta.signal();
154  sta.makeHists();
155  printResults(sta);
156  drawResults(sta, "Data, signal and tail from data", "SampleTrailerFromData.png");
157 
158  cout << myname << line() << endl;
159  cout << myname << "Compare new signal with original.";
160  cout << myname << " i sig1 sig2 diff" << endl;
161  assert( sigs1.size() == sigs2.size() );
162  Index nbad = 0;
163  for ( Index isam=0; isam<nsam; ++isam ) {
164  float dif = sigs2[isam] - sigs1[isam];
165  float adif = fabs(dif);
166  cout << myname << setw(5) << isam << ":";
167  cout << setw(10) << std::fixed << std::setprecision(2) << sigs1[isam];
168  cout << setw(10) << std::fixed << std::setprecision(2) << sigs2[isam];
169  cout << setw(10) << std::fixed << std::setprecision(2) << dif;
170  if ( adif > 1.e-3 ) {
171  ++nbad;
172  cout << " Bad";
173  }
174  cout << endl;
175  }
176  assert( nbad == 0 );
177 
178  return 0;
179 }
std::vector< Index > IndexVector
unsigned int Index
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const double e
auto norm(Vector const &v)
Return norm of the specified vector.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
void line(double t, double *p, double &x, double &y, double &z)
Dft::FloatVector FloatVector
QTextStream & endl(QTextStream &s)