31 const string myname =
"test_StickyCodeMetrics: ";
33 cout << myname <<
"NDEBUG must be off." <<
endl;
36 string line =
"-----------------------------";
38 cout << myname << line <<
endl;
40 cout << myname << line <<
endl;
41 cout << myname <<
"Create data." <<
endl;
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);
63 for ( BinCounter::value_type icnt : counts ) {
65 Index nval = icnt.second;
67 for (
Index ival=0; ival<nval; ++ival ) {
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 );
81 cout << myname << line <<
endl;
82 cout << myname <<
"Bin Counter evaluation." <<
endl;
85 assert( scm.getHist() == nullptr );
86 assert( ! scm.getSharedHist() );
88 cout << myname << line <<
endl;
89 cout << myname <<
"ADC samples evaluation." <<
endl;
93 cout << myname << line <<
endl;
94 cout << myname <<
"Histogram evaluation." <<
endl;
98 cout << myname << line <<
endl;
99 cout << myname <<
"Limited-range histogram evaluation." <<
endl;
103 cout << myname << line <<
endl;
104 cout << myname <<
"Bin Counter data map." <<
endl;
105 scm.getMetrics().print();
107 TCanvas* pcan =
new TCanvas;
110 cout << myname << line <<
endl;
111 cout << myname <<
"Evaluation creating histogram." <<
endl;
113 assert( scmh.
evaluate(counts) == 0 );
116 assert( scmh.
getHist() != nullptr );
118 cout << myname <<
"Histogram integral: " << scmh.
getHist()->Integral() <<
endl;
120 pcan->Print(
"test.png");
121 assert(
int(scmh.
getHist()->Integral()+0.1) ==
int(nadc) );
123 cout << myname << line <<
endl;
124 cout << myname <<
"Evaluation creating wide histogram." <<
endl;
126 assert( scmhw.
evaluate(counts) == 0 );
129 assert( scmhw.
getHist() != nullptr );
131 cout << myname <<
"Histogram integral: " << scmhw.
getHist()->Integral() <<
endl;
133 pcan->Print(
"testw.png");
134 assert(
int(scmhw.
getHist()->Integral()+0.1) ==
int(nadc) );
136 cout << myname << line <<
endl;
137 cout << myname <<
"Evaluation creating narrow histogram." <<
endl;
139 assert( scmh2.
evaluate(counts) == 0 );
142 assert( scmh2.
getHist() != nullptr );
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;
148 pcan->Print(
"test2.png");
152 for (
int iadc=110; iadc<125; ++iadc ) {
153 if ( counts.find(iadc) != counts.end() ) nadc2 += counts[iadc];
155 for (
int iadc=100; iadc<110; ++iadc ) {
156 if ( counts.find(iadc) != counts.end() ) nadc2u += counts[iadc];
158 for (
int iadc=125; iadc<135; ++iadc ) {
159 if ( counts.find(iadc) != counts.end() ) nadc2o += counts[iadc];
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) );
168 cout << myname << line <<
endl;
169 cout << myname <<
"Done." <<
endl;
177 string sarg(argv[1]);
178 if ( sarg ==
"-h" ) {
179 cout <<
"Usage: " << argv[0] <<
endl;
std::vector< AdcCount > AdcCountVector
DataMap getMetrics(std::string prefix="scm") const
void print(std::ostream *pout) const
counts_as<> counts
Number of ADC counts, represented by signed short int.
int main(int argc, char *argv[])
int test_StickyCodeMetrics()
void line(double t, double *p, double &x, double &y, double &z)
std::map< Index, double > BinCounter
void print(std::string prefix="") const
int evaluate(const BinCounter &counts)
StickyCodeMetrics::BinCounter BinCounter
QTextStream & endl(QTextStream &s)