29 #include <TObjArray.h>
30 #include <trg/cdc/dataobjects/CDCTriggerMLP.h>
37 main(
int argc,
char* argv[])
41 cout <<
"Program needs at least 3 arguments:" << endl
42 <<
" 1: MLP rootfile" << endl
43 <<
" 2: precision for MLP weights" << endl
44 <<
" 3: output filename" << endl;
47 string MLPFilename = argv[1];
48 unsigned precisionWeights = atoi(argv[2]);
50 TFile MLPFile(MLPFilename.c_str(),
"READ");
51 if (!MLPFile.IsOpen()) {
52 cout <<
"Could not open file " << MLPFilename << endl;
55 TObjArray* MLPs = (TObjArray*)MLPFile.Get(
"MLPs");
58 cout <<
"File " << MLPFilename <<
" does not contain key MLPs" << endl;
63 ofstream weightstream(argv[3]);
64 for (
int isector = 0; isector < MLPs->GetEntriesFast(); ++isector) {
67 cout <<
"Wrong type " << MLPs->At(isector)->ClassName()
68 <<
", ignoring this entry." << endl;
72 weightstream << isector << endl;
74 for (
unsigned isl = 0; isl < 9; ++isl) {
75 weightstream << expert->getIDRange(isl)[0] <<
" "
76 << expert->getIDRange(isl)[1] <<
" ";
80 unsigned pattern = expert->getSLpatternUnmasked();
81 weightstream << pattern <<
" " << expert->getSLpatternMask() << endl;
83 vector<unsigned> nNodes = {};
84 for (
unsigned il = 0; il < expert->nLayers(); ++il) {
85 nNodes.push_back(expert->nNodesLayer(il));
86 weightstream << nNodes.back() <<
" ";
90 vector<float> weights = expert->getWeights();
93 for (
unsigned iw = 0; iw < weights.size(); ++iw) {
94 double weight = weights[iw];
96 if (iw < ((nNodes[0] + 1) * nNodes[1])) {
97 unsigned isl = (iw % (nNodes[0] + 1)) / 3;
98 if (isl < 9 && !((pattern >> isl) & 1)) weight = 0;
100 if (weight < minWeight) minWeight = weight;
101 if (weight > maxWeight) maxWeight = weight;
102 weightstream << round(weight * (1 << precisionWeights)) <<
" ";
104 weightstream << endl;
105 cout << weights.size() <<
" weights in [" << minWeight <<
"," << maxWeight <<
"]" << endl;
110 weightstream.close();