-
Notifications
You must be signed in to change notification settings - Fork 16
/
simple_fullpfalgo_test.cpp
145 lines (124 loc) · 6.47 KB
/
simple_fullpfalgo_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <cstdio>
#include "firmware/simple_fullpfalgo.h"
#include "utils/random_inputs.h"
#include "utils/DiscretePFInputs_IO.h"
#include "utils/pattern_serializer.h"
#include "utils/test_utils.h"
#define NTEST 500
int main() {
// input format: could be random or coming from simulation
//RandomPFInputs inputs(37); // 37 is a good random number
DiscretePFInputs inputs("regions_TTbar_PU140.dump");
// input TP objects
HadCaloObj calo[NCALO]; EmCaloObj emcalo[NEMCALO]; TkObj track[NTRACK]; z0_t hwZPV;
HadCaloObj calo_subem[NCALO], calo_subem_ref[NCALO];
MuObj mu[NMU];
// output PF objects
PFChargedObj outch[NTRACK], outch_ref[NTRACK];
PFNeutralObj outpho[NPHOTON], outpho_ref[NPHOTON];
PFNeutralObj outne[NSELCALO], outne_ref[NSELCALO];
PFChargedObj outmupf[NMU], outmupf_ref[NMU];
#if defined(TESTMP7)
MP7PatternSerializer serInPatterns( "mp7_input_patterns.txt", HLS_pipeline_II,HLS_pipeline_II-1); // mux each event into HLS_pipeline_II frames
MP7PatternSerializer serOutPatterns("mp7_output_patterns.txt",HLS_pipeline_II,HLS_pipeline_II-1); // assume only one PF core running per chip,
MP7PatternSerializer serInPatterns2( "mp7_input_patterns_magic.txt", HLS_pipeline_II,-HLS_pipeline_II+1); // mux each event into HLS_pipeline_II frames
MP7PatternSerializer serOutPatterns2("mp7_output_patterns_magic.txt",HLS_pipeline_II,-HLS_pipeline_II+1); // assume only one PF core running per chip,
MP7PatternSerializer serInPatterns3( "mp7_input_patterns_nomux.txt"); //
MP7PatternSerializer serOutPatterns3("mp7_output_patterns_nomux.txt"); // ,
#endif
#if defined(TESTCTP7)
CTP7PatternSerializer serInPatterns4( "ctp7_input_patterns_nomux.txt",CTP7_NCHANN_IN, true); //
CTP7PatternSerializer serOutPatterns4("ctp7_output_patterns_nomux.txt",CTP7_NCHANN_OUT, false); // fill the rest of the lines with empty events for now
#endif
HumanReadablePatternSerializer serHR("human_readable_patterns.txt");
HumanReadablePatternSerializer debugHR("-"); // this will print on stdout, we'll use it for errors
// -----------------------------------------
// run multiple tests
for (int test = 1; test <= NTEST; ++test) {
// initialize TP objects
for (int i = 0; i < NTRACK; ++i) {
track[i].hwPt = 0; track[i].hwPtErr = 0; track[i].hwEta = 0; track[i].hwPhi = 0; track[i].hwZ0 = 0;
}
for (int i = 0; i < NCALO; ++i) {
calo[i].hwPt = 0; calo[i].hwEmPt = 0; calo[i].hwEta = 0; calo[i].hwPhi = 0; calo[i].hwIsEM = 0;
}
for (int i = 0; i < NEMCALO; ++i) {
emcalo[i].hwPt = 0; emcalo[i].hwPtErr = 0; emcalo[i].hwEta = 0; emcalo[i].hwPhi = 0;
}
for (int i = 0; i < NMU; ++i) {
mu[i].hwPt = 0; mu[i].hwPtErr = 0; mu[i].hwEta = 0; mu[i].hwPhi = 0;
}
// get the inputs from the input object
if (!inputs.nextRegion(calo, emcalo, track, mu, hwZPV)) break;
#if defined(TESTMP7) // Full PF, with MP7 wrapping
MP7DataWord data_in[MP7_NCHANN], data_out[MP7_NCHANN];
// initialize
for (int i = 0; i < MP7_NCHANN; ++i) {
data_in[i] = 0;
data_out[i] = 0;
}
mp7wrapped_pack_in(emcalo, calo, track, mu, data_in);
MP7_TOP_FUNC(data_in, data_out);
mp7wrapped_unpack_out(data_out, outch, outpho, outne, outmupf);
// for (int ii = 0; ii < 72; ++ii){ std::cout << ii << ", " << data_in[ii] << std::endl; }
MP7_REF_FUNC(emcalo, calo, track, mu, outch_ref, outpho_ref, outne_ref, outmupf_ref);
// write out patterns for MP7 board hardware or simulator test
serInPatterns(data_in); serOutPatterns(data_out);
serInPatterns2(data_in); serOutPatterns2(data_out);
serInPatterns3(data_in); serOutPatterns3(data_out);
#elif defined(TESTCTP7) // Full PF, with CTP7 wrapping
MP7DataWord data_in[CTP7_NCHANN_IN], data_out[CTP7_NCHANN_OUT];
// initialize
for (int i = 0; i < CTP7_NCHANN_IN; ++i) { data_in[i] = 0; }
for (int i = 0; i < CTP7_NCHANN_OUT; ++i) { data_out[i] = 0; }
mp7wrapped_pack_in(emcalo, calo, track, mu, data_in);
MP7_TOP_FUNC(data_in, data_out);
mp7wrapped_unpack_out(data_out, outch, outpho, outne, outmupf);
MP7_REF_FUNC(emcalo, calo, track, mu, outch_ref, outpho_ref, outne_ref, outmupf_ref);
// write out patterns for CTP7 board hardware or simulator test
serInPatterns4(data_in,CTP7_NCHANN_IN); serOutPatterns4(data_out,CTP7_NCHANN_OUT);
#else // standard PFAlgo test without MP7 packing
pfalgo3_full_ref(emcalo, calo, track, mu, outch_ref, outpho_ref, outne_ref, outmupf_ref);
pfalgo3_full(emcalo, calo, track, mu, outch, outpho, outne, outmupf);
#endif
// write out human-readable patterns
serHR(emcalo, calo, track, mu, outch, outpho, outne, outmupf);
#ifdef TESTMP7
if (!MP7_VALIDATE) continue;
#endif
#ifdef TESTCTP7
if (!CTP7_VALIDATE) continue;
#endif
// -----------------------------------------
// validation against the reference algorithm
int errors = 0; int ntot = 0, npho = 0, nch = 0, nneu = 0, nmu = 0;
// check charged hadrons
for (int i = 0; i < NTRACK; ++i) {
if (!pf_equals(outch_ref[i], outch[i], "PF Charged", i)) errors++;
if (outch_ref[i].hwPt > 0) { ntot++; nch++; }
}
// check photon
for (int i = 0; i < NPHOTON; ++i) {
if (!pf_equals(outpho_ref[i], outpho[i], "Photon", i)) errors++;
if (outpho_ref[i].hwPt > 0) { ntot++; npho++; }
}
for (int i = 0; i < NSELCALO; ++i) {
if (!pf_equals(outne_ref[i], outne[i], "PF Neutral", i)) errors++;
if (outne_ref[i].hwPt > 0) { ntot++; nneu++; }
}
for (int i = 0; i < NMU; ++i) {
if (!pf_equals(outmupf_ref[i], outmupf[i], "PF Muon", i)) errors++;
if (outmupf_ref[i].hwPt > 0) { ntot++; nmu++; }
}
if (errors != 0) {
printf("Error in computing test %d (%d)\n", test, errors);
printf("Inputs: \n"); debugHR.dump_inputs(emcalo, calo, track, mu);
printf("Reference output: \n"); debugHR.dump_outputs(outch_ref, outpho_ref, outne_ref, outmupf_ref);
printf("Current output: \n"); debugHR.dump_outputs(outch, outpho, outne, outmupf);
return 1;
} else {
printf("Passed test %d (%d, %d, %d, %d)\n", test, ntot, nch, npho, nneu);
}
}
return 0;
}