Unpacker main function for upto version 136.
865{
866
867 int version_check = (rdat[0] >> 12) & 0xf;
868 if (version_check != 15) return;
869
870
871 unsigned char check_sum = (rdat[nnn - 1] >> 24) & 0xFF;
872 unsigned char data_sum = 0;
873 unsigned char kdat[4] = {0};
874 for (int j = nnn - 2; j > -1; j--) {
875 kdat[0] = rdat[j] & 0xff;
876 kdat[1] = (rdat[j] >> 8) & 0xff;
877 kdat[2] = (rdat[j] >> 16) & 0xff;
878 kdat[3] = (rdat[j] >> 24) & 0xff;
879 for (int k = 0; k < 4; k++) {
880 data_sum = data_sum + kdat[k];
881 }
882 }
883
884 int flag_checksum = 0;
885
886 if (check_sum == data_sum) {
887 flag_checksum = 0;
888 } else {
889 flag_checksum = 1;
890 }
891
892
893 int l1_revo = rdat[0] & 0x7ff;
894 int i = 0;
895 int window_num = 0;
896
897
898
899 int summary_data = 0;
900
901 int summary_revo = 0;
902
903 bool summary_trg = false;
904
905 int data_win = 0;
906
907
908
909 int ntc_win = 0;
910 bool tc_trg = false;
911
912 int tc_id = 0;
913 int tc_t = 0;
914 int tc_e = 0;
915 int conv_tc_t = 0;
916 int win3_revo = -9999;
917
918 vector<unsigned> sum_data;
919 vector<vector<unsigned>> sum_info;
920
921 vector<int> tc_data;
922 vector<vector<int>> tc_info;
923 vector<vector<int>> tc_info_FE1;
924 vector<vector<int>> tc_info_FE2;
925 vector<vector<int>> tc_info_BE1;
926 vector<vector<int>> tc_info_BE2;
927
928
929 while (i < nnn - 2) {
930 summary_data = rdat[i + 1];
931 summary_trg = (summary_data >> 23) & 0x1;
932 summary_revo = (summary_data >> 16) & 0x7f;
933 ntc_win = summary_data & 0x3ff;
934 if (ntc_win == 0) {
935 tc_trg = false;
936 } else {
937 tc_trg = true;
938 }
939 data_win = window_num;
940 if (window_num == 3) win3_revo = summary_revo;
941
942 if (summary_trg == true) {
943 sum_data.push_back(data_win);
944 sum_data.push_back(summary_revo);
945 for (int j = 0; j < 9; j++) {
946 sum_data.push_back(rdat[i + j + 2]);
947 }
948 sum_info.push_back(sum_data);
949 sum_data.clear();
950 i = i + 11;
951
952 if (tc_trg == true) {
953 for (int j = 0; j < ntc_win; j++) {
954 tc_id = (rdat[i + j] >> 20) & 0x3FF;
955 tc_t = (rdat[i + j] >> 12) & 0x7F;
956 tc_e = rdat[i + j] & 0xFFF;
957 conv_tc_t = (data_win - 3) * 128 + tc_t;
958
959
960 tc_data.push_back(tc_id);
961 tc_data.push_back(conv_tc_t);
962 tc_data.push_back(tc_e);
963 tc_data.push_back(data_win);
964 if (tc_id < 81) {
965 if (tc_id > 75) {
966 tc_info_FE1.push_back(tc_data);
967 } else {
968 tc_info_FE2.push_back(tc_data);
969 }
970 } else if (tc_id > 512) {
971 if (tc_id > 572) {
972 tc_info_BE1.push_back(tc_data);
973 } else {
974 tc_info_BE2.push_back(tc_data);
975 }
976 } else {
977 tc_info.push_back(tc_data);
978 }
979 tc_data.clear();
980 }
981 i = i + ntc_win - 1;
982 }
983
984 } else {
985 if (tc_trg == true) {
986 for (int j = 0; j < ntc_win; j++) {
987 tc_id = (rdat[i + j + 2] >> 20) & 0x3FF;
988 tc_t = (rdat[i + j + 2] >> 12) & 0x7F;
989 conv_tc_t = (data_win - 3) * 128 + tc_t;
990 tc_e = rdat[i + j + 2] & 0xFFF;
991
992
993 tc_data.push_back(tc_id);
994 tc_data.push_back(conv_tc_t);
995 tc_data.push_back(tc_e);
996 tc_data.push_back(data_win);
997 if (tc_id < 81) {
998 if (tc_id > 75) {
999 tc_info_FE1.push_back(tc_data);
1000 } else {
1001 tc_info_FE2.push_back(tc_data);
1002 }
1003 } else if (tc_id > 512) {
1004 if (tc_id > 572) {
1005 tc_info_BE1.push_back(tc_data);
1006 } else {
1007 tc_info_BE2.push_back(tc_data);
1008 }
1009 } else {
1010 tc_info.push_back(tc_data);
1011 }
1012 tc_data.clear();
1013 }
1014 i = i + ntc_win + 1;
1015 } else {
1016 i = i + 1;
1017 }
1018 }
1019 window_num++;
1020 }
1021
1022
1023
1024
1025
1026 int sum_num = 0;
1027
1028 int sum_revo = 0;
1029 int cl_theta[6] = {0};
1030 int cl_phi[6] = {0};
1031 int cl_time[6] = { -9999};
1032 int cl_energy[6] = {0};
1033 int ncl = 0;
1034 int low_multi = 0;
1035 int b2bhabha_v = 0;
1036 int b2bhabha_s = 0;
1037 int mumu = 0;
1038 int prescale = 0;
1039 int icn_over = 0;
1040 int bg_veto = 0;
1041 int icn = 0;
1042 int etot_type = 0;
1043 int etot = 0;
1044 int b1_type = 0;
1045 int b1bhabha = 0;
1046 int physics = 0;
1047 int time_type = 0;
1048 int time = 0;
1049 int ecl_bst = 0;
1050
1051 int m_sumNum = 0;
1052
1055
1056 vector<int> cl_1d;
1057 vector<vector<int>> cl_2d;
1058
1059 vector<int> evt_1d_vector;
1060 vector<vector<int>> evt_2d_vector;
1061
1062
1063 int sum_size = sum_info.size();
1064 if (sum_size != 0) {
1065 for (int j = 0; j < sum_size; j++) {
1066 sum_num = sum_info[j][0];
1067 sum_revo = sum_info[j][1];
1069 ecl_bst = (sum_info[j][2] >> 26) & 0x1;
1070 }
1072 cl_theta[5] = (sum_info[j][2] >> 19) & 0x7f;
1073 cl_phi[5] = (sum_info[j][2] >> 11) & 0xff;
1074 cl_time[5] = (sum_info[j][2] >> 3) & 0xff;
1075 cl_energy[5] = ((sum_info[j][2] & 0x7) << 9) + ((sum_info[j][3] >> 23) & 0x1ff);
1076
1077 cl_theta[4] = (sum_info[j][3] >> 16) & 0x7f;
1078 cl_phi[4] = (sum_info[j][3] >> 8) & 0xff;
1079 cl_time[4] = (sum_info[j][3]) & 0xff;
1080 cl_energy[4] = (sum_info[j][4] >> 20) & 0xfff;
1081
1082 cl_theta[3] = (sum_info[j][4] >> 13) & 0x7f;
1083 cl_phi[3] = (sum_info[j][4] >> 5) & 0xff;
1084 cl_time[3] = ((sum_info[j][4] & 0x1f) << 3) + ((sum_info[j][5] >> 29) & 0x7);
1085 cl_energy[3] = (sum_info[j][5] >> 17) & 0xfff;
1086
1087 cl_theta[2] = (sum_info[j][5] >> 10) & 0x7f;
1088 cl_phi[2] = (sum_info[j][5] >> 2) & 0xff;
1089 cl_time[2] = ((sum_info[j][5] & 0x3) << 6) + ((sum_info[j][6] >> 26) & 0x3f);
1090 cl_energy[2] = (sum_info[j][6] >> 14) & 0xfff;
1091
1092 cl_theta[1] = (sum_info[j][6] >> 7) & 0x7f;
1093 cl_phi[1] = ((sum_info[j][6] & 0x7f) << 1) + ((sum_info[j][7] >> 31) & 0x1);
1094 cl_time[1] = (sum_info[j][7] >> 23) & 0xff;
1095 cl_energy[1] = (sum_info[j][7] >> 11) & 0xfff;
1096
1097 cl_theta[0] = (sum_info[j][7] >> 4) & 0x7f;
1098 cl_phi[0] = ((sum_info[j][7] & 0xf) << 4) + ((sum_info[j][8] >> 28) & 0xf);
1099 cl_time[0] = (sum_info[j][8] >> 20) & 0xff;
1100 cl_energy[0] = (sum_info[j][8] >> 8) & 0xfff;
1101
1102 ncl = (sum_info[j][8] >> 5) & 0x7;
1103
1104 prescale = (sum_info[j][8] >> 4) & 0x1;
1105 mumu = (sum_info[j][8] >> 3) & 0x1;
1106 b2bhabha_s = (sum_info[j][8] >> 2) & 0x1;
1108 low_multi = (((sum_info[j][2] >> 27) & 0x3) << 12) + ((sum_info[j][8] & 0x3) << 10) + ((sum_info[j][9] >> 22) & 0x3ff);
1109 } else {
1110 low_multi = ((sum_info[j][8] & 0x3) << 10) + ((sum_info[j][9] >> 22) & 0x3ff);
1111 }
1112 b2bhabha_v = (sum_info[j][9] >> 21) & 0x1;
1113 icn_over = (sum_info[j][9] >> 20) & 0x1;
1114 bg_veto = (sum_info[j][9] >> 17) & 0x7;
1115 icn = (sum_info[j][9] >> 10) & 0x7f;
1116 etot_type = (sum_info[j][9] >> 7) & 0x7;
1117 etot = ((sum_info[j][9] & 0x7f) << 6) + ((sum_info[j][10] >> 26) & 0x3f);
1118 b1_type = (sum_info[j][10] >> 12) & 0x3fff;
1119 b1bhabha = (sum_info[j][10] >> 11) & 0x1;
1120 physics = (sum_info[j][10] >> 10) & 0x1;
1121 time_type = (sum_info[j][10] >> 7) & 0x7;
1122 time = (sum_info[j][10]) & 0x7f;
1123 } else {
1124 cl_theta[5] = (sum_info[j][2] >> 24) & 0x7f;
1125 cl_phi[5] = (sum_info[j][2] >> 16) & 0xff;
1126 cl_time[5] = (sum_info[j][2] >> 8) & 0xff;
1127 cl_energy[5] = ((sum_info[j][2] & 0xff) << 4) + ((sum_info[j][3] >> 28) & 0xf);
1128
1129 cl_theta[4] = (sum_info[j][3] >> 21) & 0x7f;
1130 cl_phi[4] = (sum_info[j][3] >> 13) & 0xff;
1131 cl_time[4] = (sum_info[j][3] >> 5) & 0xff;
1132 cl_energy[4] = ((sum_info[j][3] & 0x1f) << 7) + ((sum_info[j][4] >> 25) & 0x7f);
1133
1134 cl_theta[3] = (sum_info[j][4] >> 18) & 0x7f;
1135 cl_phi[3] = (sum_info[j][4] >> 10) & 0xff;
1136 cl_time[3] = (sum_info[j][4] >> 2) & 0xff;
1137 cl_energy[3] = ((sum_info[j][4] & 0x3) << 10) + ((sum_info[j][5] >> 22) & 0x3ff);
1138
1139 cl_theta[2] = (sum_info[j][5] >> 15) & 0x7f;
1140 cl_phi[2] = (sum_info[j][5] >> 7) & 0xff;
1141 cl_time[2] = ((sum_info[j][5] & 0x7f) << 1) + ((sum_info[j][6] >> 31) & 0x1);
1142 cl_energy[2] = (sum_info[j][6] >> 19) & 0xfff;
1143
1144 cl_theta[1] = (sum_info[j][6] >> 12) & 0x7f;
1145 cl_phi[1] = (sum_info[j][6] >> 4) & 0xff;
1146 cl_time[1] = ((sum_info[j][6] & 0xf) << 4) + ((sum_info[j][7] >> 28) & 0xf);
1147 cl_energy[1] = (sum_info[j][7] >> 16) & 0xfff;
1148
1149 cl_theta[0] = (sum_info[j][7] >> 9) & 0x7f;
1150 cl_phi[0] = (sum_info[j][7] >> 1) & 0xff;
1151 cl_time[0] = ((sum_info[j][7] & 0x1) << 7) + ((sum_info[j][8] >> 25) & 0x7f);
1152 cl_energy[0] = (sum_info[j][8] >> 13) & 0xfff;
1153
1154 ncl = (sum_info[j][8] >> 10) & 0x7;
1155
1156 low_multi = ((sum_info[j][8] & 0x3ff) << 2) + ((sum_info[j][9] >> 30) & 0x3);
1157 b2bhabha_v = (sum_info[j][9] >> 29) & 0x1;
1158 icn_over = (sum_info[j][9] >> 28) & 0x1;
1159 bg_veto = (sum_info[j][9] >> 25) & 0x7;
1160 icn = (sum_info[j][9] >> 18) & 0x7f;
1161 etot_type = (sum_info[j][9] >> 15) & 0x7;
1162 etot = (sum_info[j][9] >> 2) & 0x1fff;
1163
1164 b1_type = ((sum_info[j][9] & 0x3) << 12) + ((sum_info[j][10] >> 20) & 0xfff);
1165 b1bhabha = (sum_info[j][10] >> 19) & 0x1;
1166 physics = (sum_info[j][10] >> 18) & 0x1;
1167 time_type = (sum_info[j][10] >> 15) & 0x7;
1168 time = (sum_info[j][10] >> 8) & 0x7f;
1169
1170 b2bhabha_s = 0;
1171 mumu = 0;
1172 prescale = 0;
1173 }
1174
1201
1202 for (int k = 0; k < 6; k++) {
1203 cl_1d.push_back(cl_theta[k]);
1204 cl_1d.push_back(cl_phi[k]);
1205 cl_1d.push_back(cl_time[k]);
1206 cl_1d.push_back(cl_energy[k]);
1207 cl_2d.push_back(cl_1d);
1208 cl_1d.clear();
1209 }
1210 sort(cl_2d.begin(), cl_2d.end(),
1211 [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[3] > aa2[3];});
1212
1213 evt_1d_vector.push_back(abs(sum_num - 3));
1214 evt_1d_vector.push_back(sum_revo);
1215 evt_1d_vector.push_back(sum_num);
1216 evt_1d_vector.push_back(time);
1217 for (int k = 0; k < 6; k++) {
1218 evt_1d_vector.push_back(cl_2d[k][0]);
1219 evt_1d_vector.push_back(cl_2d[k][1]);
1220 evt_1d_vector.push_back(cl_2d[k][2]);
1221 evt_1d_vector.push_back(cl_2d[k][3]);
1222 }
1223 evt_1d_vector.push_back(ncl);
1224 evt_1d_vector.push_back(low_multi);
1225 evt_1d_vector.push_back(b2bhabha_v);
1226 evt_1d_vector.push_back(b2bhabha_s);
1227 evt_1d_vector.push_back(mumu);
1228 evt_1d_vector.push_back(prescale);
1229 evt_1d_vector.push_back(icn);
1230 evt_1d_vector.push_back(icn_over);
1231 evt_1d_vector.push_back(etot_type);
1232 evt_1d_vector.push_back(etot);
1233 evt_1d_vector.push_back(ecl_bst);
1234 evt_1d_vector.push_back(b1_type);
1235 evt_1d_vector.push_back(b1bhabha);
1236 evt_1d_vector.push_back(physics);
1237 evt_1d_vector.push_back(time_type);
1238 evt_2d_vector.push_back(evt_1d_vector);
1239 evt_1d_vector.clear();
1240 }
1241 } else {
1242
1243 for (int k = 0; k < 6; k++) {
1244 cl_theta[k] = 0;
1245 cl_phi[k] = 0;
1246 cl_time[k] = -9999;
1247 cl_energy[k] = 0;
1248 }
1249 ncl = 0;
1250 low_multi = 0;
1251 b2bhabha_v = 0;
1252 b2bhabha_s = 0;
1253 mumu = 0;
1254 prescale = 0;
1255 icn_over = 0;
1256 bg_veto = 0;
1257 icn = 0;
1258 etot_type = 0;
1259 etot = 0;
1260 ecl_bst = 0;
1261 b1_type = 0;
1262 b1bhabha = 0;
1263 physics = 0;
1264 time_type = 0;
1265 time = -9999;
1266
1292 }
1293
1294
1295 tc_info.insert(tc_info.end(), tc_info_FE1.begin(), tc_info_FE1.end());
1296 tc_info.insert(tc_info.end(), tc_info_FE2.begin(), tc_info_FE2.end());
1297 tc_info.insert(tc_info.end(), tc_info_BE1.begin(), tc_info_BE1.end());
1298 tc_info.insert(tc_info.end(), tc_info_BE2.begin(), tc_info_BE2.end());
1299
1300 int m_evtNum = 0;
1301
1302 int m_tcNum = 0;
1303
1304 int m_tcid = 0;
1305
1306 int m_time = -9999;
1307
1308 int m_energy = 0;
1309
1310 int m_win = 0;
1311
1312 int m_revo = 0;
1313
1314 int m_caltime = -9999;
1315
1316 int tot_ntc = tc_info.size();
1317
1318 int evt_ntc = 0;
1319
1320 int evt_revo = -9999;
1321
1322 int evt_win = 0;
1323
1324 int evt_timing = -9999;
1325 int evt_cl_theta[6] = {0};
1326 int evt_cl_phi[6] = {0};
1327 int evt_cl_time[6] = { -9999};
1328 int evt_cl_energy[6] = {0};
1329
1330 int evt_ncl = 0;
1331
1332 int evt_low_multi = 0;
1333
1334 int evt_b2bhabha_v = 0;
1335
1336 int evt_b2bhabha_s = 0;
1337
1338 int evt_mumu = 0;
1339
1340 int evt_prescale = 0;
1341
1342 int evt_icn = 0;
1343
1344 int evt_icn_over = 0;
1345
1346 int evt_etot_type = 0;
1347
1348 int evt_etot = 0;
1349
1350 int evt_ecl_bst = 0;
1351
1352 int evt_b1_type = 0;
1353
1354 int evt_b1bhabha = 0;
1355
1356 int evt_physics = 0;
1357
1358 int evt_time_type = 0;
1359
1360 int evt_etot_all = 0;
1361
1362 int evt_time_min = 0;
1363
1364 int evt_time_max = 0;
1365
1366 int evt_time_win = 0;
1367
1368 int etot_i = 0;
1369
1370 int etot_c = 0;
1371
1372 int etot_f = 0;
1373
1374 int cl_tcid = 0;
1375
1376 int cl_thetaid = 0;
1377
1378 int cl_phiid = 0;
1379
1380 int m_clNum = 0;
1381
1382
1383 int evt_v_size = evt_2d_vector.size();
1384 if (evt_v_size != 0) {
1385
1386 sort(evt_2d_vector.begin(), evt_2d_vector.end(),
1387 [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
1388 }
1389
1390 if (tot_ntc != 0 && flag_checksum == 0 && nnn > 7) {
1391 if (evt_v_size == 0) {
1392
1393 sort(tc_info.begin(), tc_info.end(),
1394 [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[2] > aa2[2];});
1395 evt_revo = win3_revo;
1396 evt_win = tc_info[0][3];
1397 evt_timing = tc_info[0][1];
1398 for (int k = 0; k < 6; k++) {
1399 evt_cl_theta[k] = 0;
1400 evt_cl_phi[k] = 0;
1401 evt_cl_time[k] = 0;
1402 evt_cl_energy[k] = 0;
1403 }
1404 evt_ncl = 0;
1405 evt_low_multi = 0;
1406 evt_b2bhabha_v = 0;
1407 evt_b2bhabha_s = 0;
1408 evt_mumu = 0;
1409 evt_prescale = 0;
1410 evt_icn = 0;
1411 evt_icn_over = 0;
1412 evt_etot_type = 0;
1413 evt_etot = 0;
1414 evt_ecl_bst = 0;
1415 evt_b1_type = 0;
1416 evt_b1bhabha = 0;
1417 evt_physics = 0;
1418 evt_time_type = 0;
1419 } else {
1420 evt_revo = evt_2d_vector[0][1];
1421 evt_win = evt_2d_vector[0][2];
1422 evt_timing = evt_2d_vector[0][3];
1423 for (int k = 0; k < 6; k++) {
1424 evt_cl_theta[k] = evt_2d_vector[0][4 + k * 4];
1425 evt_cl_phi[k] = evt_2d_vector[0][5 + k * 4];
1426 evt_cl_time[k] = evt_2d_vector[0][6 + k * 4];
1427 evt_cl_energy[k] = evt_2d_vector[0][7 + k * 4];
1428 }
1429 evt_ncl = evt_2d_vector[0][28];
1430 evt_low_multi = evt_2d_vector[0][29];
1431 evt_b2bhabha_v = evt_2d_vector[0][30];
1432 evt_b2bhabha_s = evt_2d_vector[0][31];
1433 evt_mumu = evt_2d_vector[0][32];
1434 evt_prescale = evt_2d_vector[0][33];
1435 evt_icn = evt_2d_vector[0][34];
1436 evt_icn_over = evt_2d_vector[0][35];
1437 evt_etot_type = evt_2d_vector[0][36];
1438 evt_etot = evt_2d_vector[0][37];
1439 evt_ecl_bst = evt_2d_vector[0][38];
1440 evt_b1_type = evt_2d_vector[0][39];
1441 evt_b1bhabha = evt_2d_vector[0][40];
1442 evt_physics = evt_2d_vector[0][41];
1443 evt_time_type = evt_2d_vector[0][42];
1444 }
1445
1446 sort(tc_info.begin(), tc_info.end(),
1447 [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
1448
1449 for (int ii = 0; ii < tot_ntc; ii++) {
1450 m_tcid = tc_info[ii][0];
1451 m_time = tc_info[ii][1];
1452 m_energy = tc_info[ii][2];
1453 m_win = tc_info[ii][3];
1454 m_revo = win3_revo;
1455 m_caltime = m_time - ((evt_win - 3) * 128 + evt_timing);
1466
1467 if (m_win == evt_win || m_win == evt_win + 1) evt_ntc++;
1468 if (m_win == evt_win - 1) {
1469 etot_i += m_energy;
1470 }
1471 if (m_win == evt_win) {
1472 etot_c += m_energy;
1473 }
1474 if (m_win == evt_win + 1) {
1475 etot_f += m_energy;
1476 }
1477 }
1478
1479 if (etot_i == 0 && etot_f == 0) {
1480 evt_etot_all = etot_c;
1481 evt_time_min = - evt_timing;
1482 evt_time_max = 256 - evt_timing;
1483 evt_time_win = 1;
1484 } else if (etot_i >= etot_f) {
1485 evt_etot_all = etot_c + etot_i;
1486 evt_time_min = -128 - evt_timing;
1487 evt_time_max = 128 - evt_timing;
1488 evt_time_win = -1;
1489 } else {
1490 evt_etot_all = etot_c + etot_f;
1491 evt_time_min = - evt_timing;
1492 evt_time_max = 256 - evt_timing;
1493 evt_time_win = 1;
1494 }
1495
1496 for (int icluster = 0; icluster < 6; icluster++) {
1497 if (evt_cl_energy[icluster] == 0 || evt_cl_theta[icluster] == 0 || evt_cl_phi[icluster] == 0) {continue;}
1499 if (cl_tcid == 0) {continue;}
1502
1508
1518 }
1554 } else {
1565
1575 for (int k = 0; k < 6; k++) {
1576 evt_cl_theta[k] = 0;
1577 evt_cl_phi[k] = 0;
1578 evt_cl_time[k] = -9999;
1579 evt_cl_energy[k] = 0;
1580 }
1607 }
1608
1609 return;
1610}