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