Typedefs | Functions
test_StickyCodeMetrics.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "dunedataprep/DataPrep/Utility/StickyCodeMetrics.h"
#include "TH1F.h"
#include "TCanvas.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 
using BinCounter = StickyCodeMetrics::BinCounter
 

Functions

int test_StickyCodeMetrics ()
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 26 of file test_StickyCodeMetrics.cxx.

using Index = unsigned int

Definition at line 25 of file test_StickyCodeMetrics.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 175 of file test_StickyCodeMetrics.cxx.

175  {
176  if ( argc > 1 ) {
177  string sarg(argv[1]);
178  if ( sarg == "-h" ) {
179  cout << "Usage: " << argv[0] << endl;
180  return 0;
181  }
182  }
183  return test_StickyCodeMetrics();
184 }
int test_StickyCodeMetrics()
QTextStream & endl(QTextStream &s)
int test_StickyCodeMetrics ( )

Definition at line 30 of file test_StickyCodeMetrics.cxx.

30  {
31  const string myname = "test_StickyCodeMetrics: ";
32 #ifdef NDEBUG
33  cout << myname << "NDEBUG must be off." << endl;
34  abort();
35 #endif
36  string line = "-----------------------------";
37 
38  cout << myname << line << endl;
39 
40  cout << myname << line << endl;
41  cout << myname << "Create data." << endl;
43  counts[111] = 3;
44  counts[112] = 6;
45  counts[113] = 20;
46  counts[114] = 72;
47  counts[115] = 85;
48  counts[116] = 90;
49  counts[117] = 86;
50  counts[118] = 77;
51  counts[119] = 35;
52  counts[120] = 18;
53  counts[121] = 7;
54  counts[122] = 4;
55  counts[123] = 1;
56  counts[127] = 20;
57  counts[128] = 40;
58  counts[129] = 4;
59  AdcCountVector vals;
60  TH1F* ph = new TH1F("hraw", "Input ADC distribution; ADC count; # entries", 4096, 0, 4096);
61  TH1F* ph2 = new TH1F("hraw2", "Input ADC distribution; ADC count; # entries", 30, 100, 130);
62  Index nadc = 0;
63  for ( BinCounter::value_type icnt : counts ) {
64  AdcCount iadc = icnt.first;
65  Index nval = icnt.second;
66  nadc += nval;
67  for ( Index ival=0; ival<nval; ++ival ) {
68  vals.push_back(iadc);
69  ph->Fill(iadc);
70  ph2->Fill(iadc);
71  }
72  }
73  cout << myname << " Bin counter count: " << nadc << endl;
74  cout << myname << " Vector count: " << vals.size() << endl;
75  cout << myname << " Histogram count: " << ph->GetEntries() << endl;
76  assert( vals.size() == nadc );
77  assert( ph->GetEntries() == nadc );
78 
80 
81  cout << myname << line << endl;
82  cout << myname << "Bin Counter evaluation." << endl;
83  scm.evaluate(counts);
84  scm.print();
85  assert( scm.getHist() == nullptr );
86  assert( ! scm.getSharedHist() );
87 
88  cout << myname << line << endl;
89  cout << myname << "ADC samples evaluation." << endl;
90  scm.evaluate(vals);
91  scm.print();
92 
93  cout << myname << line << endl;
94  cout << myname << "Histogram evaluation." << endl;
95  scm.evaluate(ph);
96  scm.print();
97 
98  cout << myname << line << endl;
99  cout << myname << "Limited-range histogram evaluation." << endl;
100  scm.evaluate(ph2);
101  scm.print();
102 
103  cout << myname << line << endl;
104  cout << myname << "Bin Counter data map." << endl;
105  scm.getMetrics().print();
106 
107  TCanvas* pcan = new TCanvas;
108  pcan->SetGridx();
109 
110  cout << myname << line << endl;
111  cout << myname << "Evaluation creating histogram." << endl;
112  StickyCodeMetrics scmh("hadctest", "ADC spectrum for test", 50, 10, 1, 20);
113  assert( scmh.evaluate(counts) == 0 );
114  scmh.print();
115  scmh.getMetrics().print();
116  assert( scmh.getHist() != nullptr );
117  scmh.getHist()->Print();
118  cout << myname << "Histogram integral: " << scmh.getHist()->Integral() << endl;
119  scmh.getHist()->Draw();
120  pcan->Print("test.png");
121  assert( int(scmh.getHist()->Integral()+0.1) == int(nadc) );
122 
123  cout << myname << line << endl;
124  cout << myname << "Evaluation creating wide histogram." << endl;
125  StickyCodeMetrics scmhw("hadctest", "ADC spectrum for test", 100, 10, 1, 20);
126  assert( scmhw.evaluate(counts) == 0 );
127  scmhw.print();
128  scmhw.getMetrics().print();
129  assert( scmhw.getHist() != nullptr );
130  scmhw.getHist()->Print();
131  cout << myname << "Histogram integral: " << scmhw.getHist()->Integral() << endl;
132  scmhw.getHist()->Draw();
133  pcan->Print("testw.png");
134  assert( int(scmhw.getHist()->Integral()+0.1) == int(nadc) );
135 
136  cout << myname << line << endl;
137  cout << myname << "Evaluation creating narrow histogram." << endl;
138  StickyCodeMetrics scmh2("hadctest", "ADC spectrum for test", 15, 5, 1, 20);
139  assert( scmh2.evaluate(counts) == 0 );
140  scmh2.print();
141  scmh2.getMetrics().print();
142  assert( scmh2.getHist() != nullptr );
143  scmh2.getHist()->Print();
144  cout << myname << "Histogram integral: " << scmh2.getHist()->Integral() << endl;
145  cout << myname << "Histogram undrflow: " << scmh2.getHist()->GetBinContent(16) << endl;
146  cout << myname << "Histogram overflow: " << scmh2.getHist()->GetBinContent(0) << endl;
147  scmh2.getHist()->Draw();
148  pcan->Print("test2.png");
149  Index nadc2 = 0;
150  Index nadc2u = 0;
151  Index nadc2o = 0;
152  for ( int iadc=110; iadc<125; ++iadc ) {
153  if ( counts.find(iadc) != counts.end() ) nadc2 += counts[iadc];
154  }
155  for ( int iadc=100; iadc<110; ++iadc ) {
156  if ( counts.find(iadc) != counts.end() ) nadc2u += counts[iadc];
157  }
158  for ( int iadc=125; iadc<135; ++iadc ) {
159  if ( counts.find(iadc) != counts.end() ) nadc2o += counts[iadc];
160  }
161  cout << myname << "Expect integral: " << nadc2 << endl;
162  cout << myname << "Expect undrflow: " << nadc2u << endl;
163  cout << myname << "Expect overflow: " << nadc2o << endl;
164  assert( int(scmh2.getHist()->Integral()+0.1) == int(nadc2) );
165 
166  delete pcan;
167 
168  cout << myname << line << endl;
169  cout << myname << "Done." << endl;
170  return 0;
171 }
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
unsigned int Index
counts_as<> counts
Number of ADC counts, represented by signed short int.
Definition: electronics.h:116
void line(double t, double *p, double &x, double &y, double &z)
std::map< Index, double > BinCounter
short AdcCount
Definition: AdcTypes.h:18
QTextStream & endl(QTextStream &s)