4 #pragma GCC diagnostic ignored "-Weffc++"
7 #include "kdtree++/kdtree.hpp"
11 #ifdef BEST_SIX_POINTS
13 #endif //BEST_SIX_POINTS
69 for (
int i = 0;
i < stationsInAlgo - 2; ++
i)
80 #include "immintrin.h"
82 #define vectype __m256
84 #define vec_load_ps _mm256_load_ps
85 #define vec_store_ps _mm256_store_ps
86 #define vec_set1_ps _mm256_set1_ps
87 #define vec_add_ps _mm256_add_ps
88 #define vec_sub_ps _mm256_sub_ps
89 #define vec_mul_ps _mm256_mul_ps
90 #define vec_div_ps _mm256_div_ps
91 #define vec_cmp_ps _mm256_cmp_ps
92 #define vec_or_ps _mm256_or_ps
93 #define vec_sqrt_ps _mm256_sqrt_ps
97 station_number >= stationsInAlgo - 1;
116 x_errs[station_number][2][j] *
x_errs[station_number][2][j];
119 scaltype deltaXSq = deltaX * deltaX;
127 y_errs[station_number][2][j] *
y_errs[station_number][2][j];
130 scaltype deltaYSq = deltaY * deltaY;
140 if (validC)
continue;
147 x_errs[station_number][0][j] *
x_errs[station_number][0][j];
150 scaltype deltaXSq = deltaX * deltaX;
158 y_errs[station_number][0][j] *
y_errs[station_number][0][j];
161 scaltype deltaYSq = deltaY * deltaY;
182 int l_station_number = station_number - 1;
188 if (!*
reinterpret_cast<unsigned long long*
>(
192 vectype
x = vec_load_ps(&
x_coords[station_number][1][
i]);
193 vectype
y = vec_load_ps(&
y_coords[station_number][1][
i]);
194 vectype z = vec_load_ps(&
z_coords[station_number][1][
i]);
195 vectype tx = vec_div_ps(
x, z);
196 vectype ty = vec_div_ps(
y, z);
197 vec_store_ps(&
tx_vals[l_station_number][
i], tx);
198 vec_store_ps(&
ty_vals[l_station_number][
i], ty);
202 if (!*
reinterpret_cast<unsigned long long*
>(
206 vectype
x = vec_load_ps(&
x_coords[station_number][1][
i]);
207 vectype
y = vec_load_ps(&
y_coords[station_number][1][
i]);
208 vectype z = vec_load_ps(&
z_coords[station_number][1][
i]);
209 vectype tx = vec_div_ps(
x, z);
210 vectype ty = vec_div_ps(
y, z);
211 vec_store_ps(&
tx_vals[l_station_number][
i], tx);
212 vec_store_ps(&
ty_vals[l_station_number][
i], ty);
238 vectype r_x = vec_set1_ps(
x_coords[
i][1][j]);
239 vectype r_dx = vec_set1_ps(
x_errs[
i][1][j]);
240 vectype r_y = vec_set1_ps(
y_coords[
i][1][j]);
241 vectype r_dy = vec_set1_ps(
y_errs[
i][1][j]);
242 vectype r_z = vec_set1_ps(
z_coords[
i][1][j]);
243 vectype tx0 = vec_set1_ps(
tx_vals[i2][j]);
244 vectype ty0 = vec_set1_ps(
ty_vals[i2][j]);
246 vectype r_dx_sq = vec_mul_ps(r_dx, r_dx);
247 vectype r_dy_sq = vec_mul_ps(r_dy, r_dy);
251 vectype l_x = vec_load_ps(&
x_coords[i2][1][k]);
252 vectype l_dx = vec_load_ps(&
x_errs[i2][1][k]);
253 vectype l_y = vec_load_ps(&
y_coords[i2][1][k]);
254 vectype l_dy = vec_load_ps(&
y_errs[i2][1][k]);
255 vectype l_z = vec_load_ps(&
z_coords[i2][1][k]);
257 vectype delta_x = vec_sub_ps(l_x, r_x);
258 vectype delta_y = vec_sub_ps(l_y, r_y);
259 vectype delta_z = vec_sub_ps(l_z, r_z);
260 vectype delta_z_sq = vec_mul_ps(delta_z, delta_z);
262 vectype tx = vec_div_ps(delta_x, delta_z);
263 vectype ty = vec_div_ps(delta_y, delta_z);
264 vectype l_dx_sq = vec_mul_ps(l_dx, l_dx);
265 vectype l_dy_sq = vec_mul_ps(l_dy, l_dy);
267 vectype dtx_sq = vec_add_ps(r_dx_sq, l_dx_sq);
268 dtx_sq = vec_div_ps(dtx_sq, delta_z_sq);
269 vectype dtx = vec_sqrt_ps(dtx_sq);
270 dtx_sq = vec_mul_ps(dtx_sq, tx_coeff_sq);
271 dtx_sq = vec_add_ps(dtx_sq, tx_limit_sq);
272 vectype dty_sq = vec_add_ps(r_dy_sq, l_dy_sq);
273 dty_sq = vec_div_ps(dty_sq, delta_z_sq);
274 vectype dty = vec_sqrt_ps(dty_sq);
275 dty_sq = vec_mul_ps(dty_sq, ty_coeff_sq);
276 dty_sq = vec_add_ps(dtx_sq, ty_limit_sq);
278 vectype diff_tx = vec_sub_ps(tx, tx0);
279 vectype diff_ty = vec_sub_ps(ty, ty0);
280 vectype diff_tx_sq = vec_mul_ps(diff_tx, diff_tx);
281 vectype diff_ty_sq = vec_mul_ps(diff_ty, diff_ty);
283 vectype res_tx = vec_cmp_ps(diff_tx_sq, dtx_sq, _CMP_GT_OS);
284 vectype res_ty = vec_cmp_ps(diff_ty_sq, dty_sq, _CMP_GT_OS);
285 vectype res = vec_or_ps(res_tx, res_ty);
286 vec_store_ps(res_buf, res);
287 vec_store_ps(tx_buf, tx);
288 vec_store_ps(ty_buf, ty);
289 vec_store_ps(dtx_buf, dtx);
290 vec_store_ps(dty_buf, dty);
293 for (
int l = 0; l < veclen; ++l) {
318 #define _mm_malloc(X, Y) malloc((X))
319 #define _mm_free free
333 int l_station_number = station_number - 1;
366 scaltype delta_z_sq = delta_z * delta_z;
373 scaltype dtx_sq = (r_dx_sq + l_dx_sq) / delta_z_sq;
376 dtx_sq += tx_limit_sq;
377 scaltype dty_sq = (r_dy_sq + l_dy_sq) / delta_z_sq;
380 dty_sq += ty_limit_sq;
384 scaltype diff_tx_sq = diff_tx * diff_tx;
385 scaltype diff_ty_sq = diff_ty * diff_ty;
387 if ((diff_tx_sq > dtx_sq) || (diff_ty_sq > dty_sq))
continue;
412 #endif //CLUSTER_MODE
435 for (
int i = 0;
i < len; ++
i)
459 #ifdef USE_KALMAN_FIT
481 for (list<LxPoint*>::iterator j = ray->clusterPoints.begin();
482 j != ray->clusterPoints.
end();
496 : externalTrack(NULL)
497 #ifdef LX_EXT_LINK_SOPH
498 , extTrackCandidates()
516 #ifdef USE_KALMAN_FIT
530 , triggering(false) {
546 for (
int j = 0; j <
LXLAYERS; ++j) {
552 if (0 != p && !p->
used) {
579 if (0 != p && !p->
used) {
588 #endif //CLUSTER_MODE
590 static inline void Ask() {
597 }
while (symbol !=
'\n');
602 #ifdef USE_KALMAN_FIT
604 scaltype coord, tg, C11, C12, C21, C22;
610 KFParams params[2] = {
611 {firstPoint->
x, firstRay->
tx, firstPoint->
dx, 0, 0, 1.0},
612 {firstPoint->
y, firstRay->
ty, firstPoint->
dy, 0, 0, 1.0}};
614 LxPoint* prevPoint = firstPoint;
623 KFParams pPrev[2] = {params[0], params[1]};
627 for (Int_t k = 0; k <= 1; ++k) {
629 params[k].coord += pPrev[k].tg * deltaZ;
632 params[k].C11 += pPrev[k].C12 * deltaZ + pPrev[k].C21 * deltaZ
633 + pPrev[k].C22 * deltaZ2 + station->MSNoise[k][0][0];
634 params[k].C12 += pPrev[k].C22 * deltaZ + station->MSNoise[k][0][1];
635 params[k].C21 += pPrev[k].C22 * deltaZ + station->MSNoise[k][1][0];
636 params[k].C22 += station->MSNoise[k][1][1];
638 scaltype S = 1.0 / (V[k] + params[k].C11);
639 scaltype Kcoord = params[k].C11 * S;
642 params[k].coord += Kcoord * dzeta;
643 params[k].tg += Ktg * dzeta;
644 params[k].C21 -= params[k].C11 * Ktg;
645 params[k].C22 -= params[k].C12 * Ktg;
646 params[k].C11 *= 1.0 - Kcoord;
647 params[k].C12 *= 1.0 - Kcoord;
648 aChi2 += dzeta * S * dzeta;
655 dx =
sqrt(params[0].C11);
657 dtx =
sqrt(params[0].C22);
659 dy =
sqrt(params[1].C11);
661 dty =
sqrt(params[1].C22);
664 #else //USE_KALMAN_FIT
697 #endif //USE_KALMAN_FIT
699 #ifdef LX_EXT_LINK_SOPH
703 for (list<pair<LxExtTrack*, scaltype>>::iterator
i =
715 }
else if (aChi2 < extTrack->recoTrack.second) {
725 #endif // LX_EXT_LINK_SOPH
732 for (list<LxRay*>::iterator
i =
rays.begin();
i !=
rays.end(); ++
i)
765 : tx((e->
x - s->
x) / (e->z - s->z))
766 , ty((e->
y - s->
y) / (e->z - s->z))
767 , dtx(
sqrt(e->dx * e->dx + s->dx * s->dx) / (s->z - e->z))
768 , dty(
sqrt(e->dy * e->dy + s->dy * s->dy) / (s->z - e->z))
771 , station(s->layer->station)
802 , station(s->layer->station)
822 : station(st), layerNumber(lNum), zCoord(0) {}
827 for (list<LxPoint*>::iterator
i =
points.begin();
i !=
points.end(); ++
i)
837 for (list<LxPoint*>::iterator
i =
points.begin();
i !=
points.end(); ++
i) {
840 if (point->
used)
continue;
845 if (diffX < 0) diffX = -diffX;
849 if (diffY < 0) diffY = -diffY;
853 scaltype r2 = diffX * diffX + diffY * diffY;
855 if (0 == result || r2 < minR2) {
883 for (list<LxPoint*>::iterator
i =
points.begin();
i !=
points.end(); ++
i) {
886 if (point->
x < xLBound || point->
x > xUBound || point->
y < yLBound
887 || point->
y > yUBound)
892 scaltype r2 = diffX * diffX + diffY * diffY;
894 if (0 == result || r2 < minR2) {
912 for (list<LxPoint*>::iterator
i =
points.begin();
i !=
points.end(); ++
i) {
915 if (xLBound < point->
x && point->
x < xUBound && yLBound < point->
y
916 && point->
y < yUBound)
951 static bool destroyRays;
977 value_type
operator[](
size_t n)
const {
return data[n]; }
980 bool KDRayWrap::destroyRays =
false;
982 typedef KDTree::KDTree<4, KDRayWrap> KDRaysStorageType;
983 #endif //CLUSTER_MODE
987 , stationNumber(stNum)
1005 , clusteredRaysHandle(0)
1011 , clusterTxLimit2(0)
1013 , clusterTyLimit2(0)
1020 raysHandle =
new KDRaysStorageType;
1021 clusteredRaysHandle =
new KDRaysStorageType;
1022 #endif //CLUSTER_MODE
1028 KDRaysStorageType* rays =
static_cast<KDRaysStorageType*
>(raysHandle);
1030 KDRaysStorageType* clusteredRays =
1031 static_cast<KDRaysStorageType*
>(clusteredRaysHandle);
1032 delete clusteredRays;
1033 #endif //CLUSTER_MODE
1037 for (vector<LxLayer*>::iterator
i =
layers.begin();
i !=
layers.end(); ++
i)
1041 KDRaysStorageType* rays =
static_cast<KDRaysStorageType*
>(raysHandle);
1042 KDRayWrap::destroyRays =
true;
1044 KDRaysStorageType* clusteredRays =
1045 static_cast<KDRaysStorageType*
>(clusteredRaysHandle);
1046 clusteredRays->clear();
1047 KDRayWrap::destroyRays =
false;
1049 for (list<LxPoint*>::iterator
i = clusteredPoints.begin();
1050 i != clusteredPoints.end();
1054 clusteredPoints.clear();
1057 for (vector<list<LxRay*>*>::iterator j = clusters[
i].begin();
1058 j != clusters[
i].end();
1062 clusters[
i].clear();
1064 #endif //CLUSTER_MODE
1071 list<LxPoint*>& mPoints = mLayer->
points;
1072 list<LxPoint*>& rPoints = rLayer->
points;
1075 for (list<LxPoint*>::iterator
i = mPoints.begin();
i != mPoints.end(); ++
i) {
1084 diffZ = rLayer->
zCoord - point->
z;
1085 x = point->
x + tx * diffZ;
1086 y = point->
y + tx * diffZ;
1089 point->
valid =
false;
1097 for (list<LxPoint*>::iterator
i = rPoints.begin();
i != rPoints.end(); ++
i) {
1107 diffZ = lLayer->
zCoord - rPoint->
z;
1108 x = rPoint->
x + tx * diffZ;
1109 y = rPoint->
y + ty * diffZ;
1114 if (0 == lPoint)
continue;
1116 x = (lPoint->
x + rPoint->
x) / 2;
1117 y = (lPoint->
y + rPoint->
y) / 2;
1119 -1,
x,
y, mLayer->
zCoord, rPoint->
dx, rPoint->
dy, rPoint->
dz,
true);
1133 for (list<LxPoint*>::iterator rIter = rLayer->
points.begin();
1134 rIter != rLayer->
points.end();
1138 if (!rPoint->
valid)
continue;
1143 for (list<LxPoint*>::iterator lIter = lLayer->
points.begin();
1144 lIter != lLayer->
points.end();
1148 if (!lPoint->
valid)
continue;
1151 scaltype tx = (lPoint->
x - rPoint->
x) / diffZ;
1152 scaltype ty = (lPoint->
y - rPoint->
y) / diffZ;
1154 -
sqrt(lPoint->
dx * lPoint->
dx + rPoint->
dx * rPoint->
dx) / diffZ;
1156 -
sqrt(lPoint->
dy * lPoint->
dy + rPoint->
dy * rPoint->
dy) / diffZ;
1160 if (diffTx < 0) diffTx = -diffTx;
1162 if (diffTy < 0) diffTy = -diffTy;
1168 rPoint->
CreateRay(lPoint, tx, ty, dtx, dty);
1174 static void AddRayData(
LxRay* ray,
1185 lX += lPoint->
x + ray->
tx * deltaZ;
1186 lY += lPoint->
y + ray->
ty * deltaZ;
1187 lDx2 += lPoint->
dx * lPoint->
dx;
1188 lDy2 += lPoint->
dy * lPoint->
dy;
1192 rX += rPoint->
x + ray->
tx * deltaZ;
1193 rY += rPoint->
y + ray->
ty * deltaZ;
1194 rDx2 += rPoint->
dx * rPoint->
dx;
1195 rDy2 += rPoint->
dy * rPoint->
dy;
1198 void LxStation::InsertClusterRay(Int_t levels,
1200 LxRay* clusterRay) {
1205 while (clusters[levels].size() < cardinality)
1206 clusters[levels].push_back(
new list<LxRay*>);
1208 clusters[levels][cardinality - 1]->push_back(clusterRay);
1211 #ifdef BEST_SIX_POINTS
1213 bool operator()(pair<LxPoint*, LxPoint*> lVal,
1214 pair<LxPoint*, LxPoint*> rVal)
const {
1215 if (lVal.first < rVal.first)
return true;
1217 return lVal.second < rVal.second;
1221 struct LxRaysCandidates {
1225 LxRaysCandidates() : chi2(-1.0) {
memset(data, 0,
sizeof(data)); }
1227 #endif //BEST_SIX_POINTS
1229 void LxStation::BuildRays2() {
1232 KDRaysStorageType* rays =
static_cast<KDRaysStorageType*
>(raysHandle);
1241 for (Int_t j = 0; j <
LXLAYERS; ++j) {
1244 for (list<LxPoint*>::iterator rIter = rLayer->
points.begin();
1245 rIter != rLayer->
points.end();
1252 for (list<LxPoint*>::iterator lIter = lLayer->
points.begin();
1253 lIter != lLayer->
points.end();
1257 scaltype tx = (lPoint->
x - rPoint->
x) / diffZ;
1258 scaltype ty = (lPoint->
y - rPoint->
y) / diffZ;
1260 -
sqrt(lPoint->
dx * lPoint->
dx + rPoint->
dx * rPoint->
dx) / diffZ;
1262 -
sqrt(lPoint->
dy * lPoint->
dy + rPoint->
dy * rPoint->
dy) / diffZ;
1273 KDRayWrap rayWrap(
x,
y, ray);
1274 rays->insert(rayWrap);
1275 rPoint->
rays.push_back(ray);
1281 timeval bTime, eTime;
1283 static Int_t maxExeDuration = 0;
1284 static Int_t goodClusters = 0;
1285 gettimeofday(&bTime, 0);
1287 for (KDRaysStorageType::iterator
i = rays->begin();
i != rays->end(); ++
i) {
1288 KDRayWrap& wrap =
const_cast<KDRayWrap&
>(*i);
1289 LxRay* ray = wrap.ray;
1294 KDTree::_Bracket_accessor<KDRayWrap>,
1295 std::less<KDTree::_Bracket_accessor<KDRayWrap>::result_type>>
1307 KDRayWrap boundsWrap(wrap.data[0] - limitX,
1308 wrap.data[1] - limitY,
1309 wrap.data[2] - limitTx,
1310 wrap.data[3] - limitTy);
1311 range.set_low_bound(boundsWrap, 0);
1312 range.set_low_bound(boundsWrap, 1);
1313 range.set_low_bound(boundsWrap, 2);
1314 range.set_low_bound(boundsWrap, 3);
1315 boundsWrap.data[0] = wrap.data[0] + limitX;
1316 boundsWrap.data[1] = wrap.data[1] + limitY;
1317 boundsWrap.data[2] = wrap.data[2] + limitTx;
1318 boundsWrap.data[3] = wrap.data[3] + limitTy;
1319 range.set_high_bound(boundsWrap, 0);
1320 range.set_high_bound(boundsWrap, 1);
1321 range.set_high_bound(boundsWrap, 2);
1322 range.set_high_bound(boundsWrap, 3);
1323 list<KDRayWrap> neighbours;
1324 rays->find_within_range(range,
1325 back_insert_iterator<list<KDRayWrap>>(neighbours));
1328 for (list<KDRayWrap>::iterator j = neighbours.begin();
1329 j != neighbours.end();
1333 level_occupancy[r->level] = 1;
1335 if (ray != r) ray->neighbourhood.push_back(r);
1341 levels += level_occupancy[j];
1343 InsertClusterRay(levels, ray->neighbourhood.size() + 1, ray);
1346 KDRaysStorageType* clusteredRays =
1347 static_cast<KDRaysStorageType*
>(clusteredRaysHandle);
1350 #ifdef DENSE_CLUSTERS_FIRST
1351 for (Int_t j = clusters[
i].size() - 1; j >= 0; --j)
1353 for (Int_t j = 0; j < clusters[
i].size(); ++j)
1356 list<LxRay*>* clusterRays = clusters[
i][j];
1358 for (list<LxRay*>::iterator k = clusterRays->begin();
1359 k != clusterRays->end();
1363 if (0 == ray)
continue;
1365 #ifdef BEST_SIX_POINTS
1369 #else //BEST_SIX_POINTS
1370 if (ray->used)
continue;
1371 #endif //BEST_SIX_POINTS
1386 AddRayData(ray, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2);
1387 level_occupancy[ray->level] = 1;
1390 #ifdef BEST_RAYS_ONLY
1391 pair<LxRay*, scaltype> bestNeighbours
1395 bestNeighbours[l].first = 0;
1396 bestNeighbours[l].second = 0;
1399 #ifdef BEST_SIX_POINTS
1400 set<LxPoint*> leftBestPoints[
LXLAYERS];
1401 set<LxPoint*> rightBestPoints[
LXLAYERS];
1402 map<pair<LxPoint*, LxPoint*>,
LxRay*, LxLess>
1406 leftBestPoints[rayLeftInd].insert(rayLeftPoint);
1409 rightBestPoints[rayRightInd].insert(rayRightPoint);
1410 bestRaysMap[ray->level][make_pair(rayLeftPoint, rayRightPoint)] = ray;
1412 for (list<LxRay*>::iterator l = ray->neighbourhood.begin();
1413 l != ray->neighbourhood.
end();
1426 if (rLeftPoint->
used)
continue;
1431 if (rRightPoint->
used)
continue;
1433 if (rLeftInd == rayLeftInd && rRightInd == rayRightInd)
continue;
1435 leftBestPoints[rLeftInd].insert(rLeftPoint);
1436 rightBestPoints[rRightInd].insert(rRightPoint);
1437 bestRaysMap[r->level][make_pair(rLeftPoint, rRightPoint)] = r;
1439 #endif //BEST_SIX_POINTS
1441 #endif //BEST_RAYS_ONLY
1443 #ifdef BEST_SIX_POINTS
1444 LxRaysCandidates bestRaysCandidates;
1446 for (set<LxPoint*>::iterator r0 = rightBestPoints[0].begin();
1447 r0 != rightBestPoints[0].end();
1449 for (set<LxPoint*>::iterator r1 = rightBestPoints[1].begin();
1450 r1 != rightBestPoints[1].end();
1452 for (set<LxPoint*>::iterator r2 = rightBestPoints[2].begin();
1453 r2 != rightBestPoints[2].end();
1455 for (set<LxPoint*>::iterator l0 = leftBestPoints[0].begin();
1456 l0 != leftBestPoints[0].end();
1458 for (set<LxPoint*>::iterator l1 = leftBestPoints[1].begin();
1459 l1 != leftBestPoints[1].end();
1461 for (set<LxPoint*>::iterator l2 = leftBestPoints[2].begin();
1462 l2 != leftBestPoints[2].end();
1464 LxRaysCandidates cand;
1466 for (Int_t rInd = 0; rInd <
LXLAYERS; ++rInd) {
1470 case 0: rPoint = *r0;
break;
1472 case 1: rPoint = *r1;
break;
1474 default: rPoint = *r2;
1477 for (Int_t lInd = 0; lInd <
LXLAYERS; ++lInd) {
1481 case 0: lPoint = *l0;
break;
1483 case 1: lPoint = *l1;
break;
1485 default: lPoint = *l2;
1490 map<pair<LxPoint*, LxPoint*>,
LxRay*, LxLess>::iterator
1492 bestRaysMap[level].find(make_pair(lPoint, rPoint));
1494 if (rIter == bestRaysMap[level].end())
continue;
1496 if (level == ray->level)
continue;
1498 cand.data[level] = rIter->second;
1502 Int_t candLevels = 0;
1506 if (0 == cand.data[l])
continue;
1509 LxRay* r = cand.data[l];
1518 diffTx * diffTx / (ray->
dtx * ray->
dtx)
1519 + diffTy * diffTy / (ray->
dty * ray->
dty)
1526 if (bestRaysCandidates.chi2 < 0
1527 || bestRaysCandidates.chi2 > cand.chi2)
1528 bestRaysCandidates = cand;
1536 if (bestRaysCandidates.chi2 < 0)
continue;
1541 bestNeighbours[l].first = bestRaysCandidates.data[l];
1542 bestNeighbours[l].second = 0;
1545 #else //BEST_SIX_POINTS
1546 for (list<LxRay*>::iterator l = ray->neighbourhood.begin();
1547 l != ray->neighbourhood.
end();
1551 if (r->used)
continue;
1553 #ifdef BEST_RAYS_ONLY
1554 if (r->level == ray->level)
continue;
1555 #endif //BEST_RAYS_ONLY
1563 diffTx * diffTx / (ray->
dtx * ray->
dtx)
1564 + diffTy * diffTy / (ray->
dty * ray->
dty)
1568 #ifdef BEST_RAYS_ONLY
1569 if (0 == bestNeighbours[r->level].first
1570 || aChi2 < bestNeighbours[r->level].second) {
1571 bestNeighbours[r->level].first = r;
1572 bestNeighbours[r->level].second = aChi2;
1574 #else //BEST_RAYS_ONLY
1575 AddRayData(r, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2);
1576 #endif //BEST_RAYS_ONLY
1578 level_occupancy[r->level] = 1;
1583 levels += level_occupancy[l];
1584 #endif //BEST_SIX_POINTS
1589 #
if defined(DENSE_CLUSTERS_FIRST) && !defined(BEST_RAYS_ONLY)
1600 #ifdef BEST_RAYS_ONLY
1604 LxRay* r = bestNeighbours[l].first;
1606 if (0 == r)
continue;
1608 AddRayData(r, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2);
1609 #ifdef BEST_SIX_POINTS
1612 #else //BEST_SIX_POINTS
1614 #endif //BEST_SIX_POINTS
1617 #endif //BEST_RAYS_ONLY
1630 clusteredPoints.push_back(lPoint);
1633 clusteredPoints.push_back(rPoint);
1635 clRay->clusterPoints.push_back(ray->
source);
1636 clRay->clusterPoints.push_back(ray->
end);
1637 #ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS
1638 ray->
source->leftClusteredRay = clRay;
1639 ray->
end->rightClusteredRay = clRay;
1640 #endif // REMEMBER_CLUSTERED_RAYS_IN_POINTS
1641 #ifdef BEST_SIX_POINTS
1645 #else //BEST_SIX_POINTS
1647 #endif //BEST_SIX_POINTS
1649 #ifdef BEST_RAYS_ONLY
1651 LxRay* r = bestNeighbours[l].first;
1653 if (0 == r)
continue;
1655 clRay->clusterPoints.push_back(r->
source);
1656 clRay->clusterPoints.push_back(r->
end);
1657 #ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS
1658 ray->
source->leftClusteredRay = clRay;
1659 ray->
end->rightClusteredRay = clRay;
1660 #endif // REMEMBER_CLUSTERED_RAYS_IN_POINTS
1663 #ifdef REMOVE_SUBCLUSTER
1664 for (list<LxRay*>::iterator l = ray->neighbourhood.begin();
1665 l != ray->neighbourhood.
end();
1669 #ifdef BEST_SIX_POINTS
1672 #else //BEST_SIX_POINTS
1673 if (r->used)
continue;
1674 #endif //BEST_SIX_POINTS
1709 clRay->clusterPoints.push_back(r->
source);
1710 clRay->clusterPoints.push_back(r->
end);
1711 #ifdef BEST_SIX_POINTS
1714 #else //BEST_SIX_POINTS
1716 #endif //BEST_SIX_POINTS
1718 #endif //REMOVE_SUBCLUSTER
1720 #else //BEST_RAYS_ONLY
1721 for (list<LxRay*>::iterator l = ray->neighbourhood.begin();
1722 l != ray->neighbourhood.
end();
1726 if (r->used)
continue;
1728 clRay->clusterPoints.push_back(r->
source);
1729 clRay->clusterPoints.push_back(r->
end);
1732 #endif //BEST_RAYS_ONLY
1734 KDRayWrap clRayWrap(rX, rY, clRay);
1735 clusteredRays->insert(clRayWrap);
1740 gettimeofday(&eTime, 0);
1742 (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec;
1744 if (exeDuration > maxExeDuration) maxExeDuration = exeDuration;
1746 cout <<
"Max execution duration was: " << maxExeDuration << endl;
1748 #endif //CLUSTER_MODE
1756 for (list<LxPoint*>::iterator
i = layer->
points.begin();
1761 if (!rPoint->
valid)
continue;
1763 for (list<LxRay*>::iterator j = rPoint->
rays.begin();
1764 j != rPoint->
rays.end();
1769 if (!ePoint->
valid)
continue;
1771 for (list<LxRay*>::iterator k = ePoint->
rays.begin();
1772 k != ePoint->
rays.end();
1778 if (diffTx < 0) diffTx = -diffTx;
1780 if (diffTy < 0) diffTy = -diffTy;
1839 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i)
1857 void LxSpace::BuildRays2() {
1863 for (Int_t j = 0; j <
LXLAYERS; ++j) {
1866 for (list<LxPoint*>::iterator k = layer->
points.begin();
1867 k != layer->
points.end();
1870 point->
used =
false;
1876 void LxSpace::ConnectNeighbours2() {
1878 KDRaysStorageType* leftRays =
1879 static_cast<KDRaysStorageType*
>(
stations[
i - 1]->clusteredRaysHandle);
1880 KDRaysStorageType* rightRays =
1881 static_cast<KDRaysStorageType*
>(
stations[
i]->clusteredRaysHandle);
1883 scaltype txSigma2 = txSigma * txSigma;
1885 scaltype tySigma2 = tySigma * tySigma;
1887 scaltype deltaZ2 = deltaZ * deltaZ;
1890 for (KDRaysStorageType::iterator j = rightRays->begin();
1891 j != rightRays->end();
1893 KDRayWrap& wrap =
const_cast<KDRayWrap&
>(*j);
1894 LxRay* ray = wrap.ray;
1899 KDTree::_Bracket_accessor<KDRayWrap>,
1900 std::less<KDTree::_Bracket_accessor<KDRayWrap>::result_type>>
1903 scaltype x = wrap.data[0] + wrap.data[2] * deltaZ;
1904 scaltype y = wrap.data[1] + wrap.data[3] * deltaZ;
1908 4 *
sqrt(2 * point->
dx * point->
dx + txSigma2 * deltaZ23);
1910 4 *
sqrt(2 * point->
dy * point->
dy + tySigma2 * deltaZ23);
1913 KDRayWrap boundsWrap(
x - xRange,
y - yRange, tx - txRange, ty - tyRange);
1914 range.set_low_bound(boundsWrap, 0);
1915 range.set_low_bound(boundsWrap, 1);
1916 range.set_low_bound(boundsWrap, 2);
1917 range.set_low_bound(boundsWrap, 3);
1918 boundsWrap.data[0] =
x + xRange;
1919 boundsWrap.data[1] =
y + yRange;
1920 boundsWrap.data[2] = tx + txRange;
1921 boundsWrap.data[3] = ty + tyRange;
1922 range.set_high_bound(boundsWrap, 0);
1923 range.set_high_bound(boundsWrap, 1);
1924 range.set_high_bound(boundsWrap, 2);
1925 range.set_high_bound(boundsWrap, 3);
1926 list<KDRayWrap> neighbours;
1927 leftRays->find_within_range(
1928 range, back_insert_iterator<list<KDRayWrap>>(neighbours));
1930 for (list<KDRayWrap>::iterator k = neighbours.begin();
1931 k != neighbours.end();
1941 void LxSpace::BuildCandidates2(
LxRay* ray,
1943 list<LxTrackCandidate*>& candidates,
1951 candidates.push_back(tc);
1957 for (list<LxRay*>::iterator
i = ray->
neighbours.begin();
1982 BuildCandidates2(lRay,
1985 chi2 + dx2 / sigmaX2 + dy2 / sigmaY2 + dtx2 / sigmaTx2
1990 void LxSpace::Reconstruct2() {
1992 KDRaysStorageType* startRays =
1993 static_cast<KDRaysStorageType*
>(startStation->clusteredRaysHandle);
1995 for (KDRaysStorageType::iterator
i = startRays->begin();
1996 i != startRays->end();
1998 KDRayWrap& wrap =
const_cast<KDRayWrap&
>(*i);
1999 LxRay* ray = wrap.ray;
2001 list<LxTrackCandidate*> candidates;
2003 BuildCandidates2(ray, rays, candidates, chi2);
2006 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
2007 j != candidates.end();
2011 if (0 == bestCandidate || candidate->
chi2 < bestCandidate->
chi2)
2012 bestCandidate = candidate;
2015 if (0 != bestCandidate) {
2020 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
2021 j != candidates.end();
2026 cout <<
"LxSpace::Reconstruct() found: " <<
tracks.size() <<
" tracks"
2029 #endif //CLUSTER_MODE
2039 list<LxTrackCandidate*>& candidates,
2051 candidates.push_back(tc);
2055 for (list<LxRay*>::iterator
i = ray->
neighbours.begin();
2078 LxKalmanParams& kPrev = ray->kalman;
2079 LxKalmanParams& kalman = lRay->kalman;
2080 kalman.
tx = kPrev.tx;
2081 kalman.ty = kPrev.ty;
2090 kalman.tx += K11 * zetaTx;
2091 kalman.ty += K22 * zetaTy;
2092 kalman.C11 = (1.0 - K11) * kalman.C11;
2093 kalman.C22 = (1.0 - K22) * kalman.C22;
2094 kalman.chi2 = kPrev.chi2 + zetaTx * S11 * zetaTx + zetaTy * S22 * zetaTy;
2103 chi2 + dtx2 / sigmaTx2 + dty2 / sigmaTy2);
2112 list<LxPoint*>& startPoints = startLayer->
points;
2114 for (list<LxPoint*>::iterator
i = startPoints.begin();
2115 i != startPoints.end();
2119 if (point->
used)
continue;
2121 if (!point->
valid)
continue;
2123 LxRay* rays[endStNum];
2124 list<LxTrackCandidate*> candidates;
2125 list<LxRay*>& startRays = point->
rays;
2127 for (list<LxRay*>::iterator j = startRays.begin(); j != startRays.end();
2133 LxKalmanParams& kalman = ray->kalman;
2134 kalman.
tx = ray->
tx;
2135 kalman.ty = ray->
ty;
2136 kalman.C11 = ray->
dtx * ray->
dtx;
2137 kalman.C22 = ray->
dty * ray->
dty;
2146 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
2147 j != candidates.end();
2151 if (0 == bestCandidate || candidate->
chi2 < bestCandidate->
chi2)
2152 bestCandidate = candidate;
2155 if (0 != bestCandidate) {
2160 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
2161 j != candidates.end();
2167 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
2187 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
2189 list<LxTrack*>::iterator i2 =
i;
2192 if (i2 ==
tracks.end())
break;
2195 Int_t neighbourPoints = 0;
2196 int minLength = firstTrack->
length < secondTrack->
length
2200 for (Int_t j = 0; j < minLength *
LXLAYERS; ++j) {
2204 if (0 == point1 || 0 == point2)
continue;
2209 if (abs(point2->
x - point1->
x) < 5.0 * dx
2210 && abs(point2->
y - point1->
y) < 5.0 * dy)
2214 if (neighbourPoints < minLength *
LXLAYERS / 2)
continue;
2217 secondTrack->
clone =
true;
2219 firstTrack->
clone =
true;
2220 else if (firstTrack->
chi2 < secondTrack->
chi2)
2221 secondTrack->
clone =
true;
2223 firstTrack->
clone =
true;
2228 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i)
2250 #ifdef USE_OLD_STS_LINKING_RULE
2255 #endif //USE_OLD_STS_LINKING_RULE
2260 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
2263 if (track->
clone)
continue;
2265 #ifdef USE_KALMAN_FIT
2275 #else //USE_KALMAN_FIT
2288 #endif //USE_KALMAN_FIT
2297 #ifndef USE_OLD_STS_LINKING_RULE
2300 lastParam, &litLastParam);
2325 scaltype chi2 = deltaX * deltaX / sigmaX2 + deltaY * deltaY / sigmaY2
2326 + deltaTx * deltaTx / sigmaTx2
2327 + deltaTy * deltaTy / sigmaTy2;
2328 #else //USE_OLD_STS_LINKING_RULE
2347 scaltype deltaZ = lastParam->GetZ() - z;
2348 scaltype deltaX = abs(lastParam->GetX() -
x - tx * deltaZ);
2349 scaltype dxSts2 = lastParam->GetCovariance(0, 0);
2350 scaltype dySts2 = lastParam->GetCovariance(1, 1);
2351 scaltype dtxSts2 = lastParam->GetCovariance(2, 2);
2352 scaltype dtySts2 = lastParam->GetCovariance(3, 3);
2355 dxMuch * dxMuch + dxSts2 + dtxMuch * dtxMuch * deltaZ * deltaZ;
2359 dyMuch * dyMuch + dySts2 + dtyMuch * dtyMuch * deltaZ * deltaZ;
2361 scaltype sigmaTxMeas2 = dtxMuch * dtxMuch + dtxSts2;
2363 scaltype sigmaTyMeas2 = dtyMuch * dtyMuch + dtySts2;
2369 scaltype deltaY = abs(lastParam->GetY() -
y - ty * deltaZ);
2374 scaltype deltaTx = abs(lastParam->GetTx() - tx);
2379 scaltype deltaTy = abs(lastParam->GetTy() - ty);
2394 scaltype chi2 = deltaX * deltaX / (sigmaX2 + sigmaXMeas2)
2395 + deltaY * deltaY / (sigmaY2 + sigmaYMeas2)
2396 + deltaTx * deltaTx / (sigmaTx2 + sigmaTxMeas2)
2397 + deltaTy * deltaTy / (sigmaTy2 + sigmaTyMeas2);
2398 #endif //USE_OLD_STS_LINKING_RULE
2400 #ifdef LX_EXT_LINK_SOPH
2401 list<pair<LxExtTrack*, scaltype>>::iterator k =
2407 pair<LxExtTrack*, scaltype> linkDesc(extTrack, chi2);
2409 #else //LX_EXT_LINK_SOPH
2414 #endif //LX_EXT_LINK_SOPH
2417 #ifdef LX_EXT_LINK_SOPH
2418 for (list<pair<LxExtTrack*, scaltype>>::iterator j =
2430 }
else if (chi2 < extTrack->recoTrack.second) {
2439 #endif // LX_EXT_LINK_SOPH
2456 scaltype dispXL = xs[
i][0] - tx * diffZ - xs[
i][1];
2457 scaltype dispYL = ys[
i][0] - ty * diffZ - ys[
i][1];
2459 if (dispXL < 0) dispXL = -dispXL;
2461 if (dispYL < 0) dispYL = -dispYL;
2463 diffZ = zs[
i][2] - zs[
i][1];
2464 scaltype dispXR = xs[
i][2] - tx * diffZ - xs[
i][1];
2465 scaltype dispYR = ys[
i][2] - ty * diffZ - ys[
i][1];
2467 if (dispXR < 0) dispXR = -dispXR;
2469 if (dispYR < 0) dispYR = -dispYR;
2471 scaltype dispX = dispXL < dispXR ? dispXL : dispXR;
2472 scaltype dispY = dispYL < dispYR ? dispYL : dispYR;
2474 if (
stations[
i]->disp01XBig - dispX < xDisp2Limits[
i])
2475 xDisp2Limits[
i] =
stations[
i]->disp01XBig - dispX;
2477 if (
stations[
i]->disp01YBig - dispY < yDisp2Limits[
i])
2478 yDisp2Limits[
i] =
stations[
i]->disp01YBig - dispY;
2481 diffZ = zs[
i][1] - zs[
i - 1][1];
2483 tx = (xs[
i][1] - xs[
i - 1][1]) / diffZ;
2486 if (dtx < 0) dtx = -dtx;
2489 ty = (ys[
i][1] - ys[
i - 1][1]) / diffZ;
2492 if (dty < 0) dty = -dty;
2494 if (
stations[
i]->txLimit - dtx < tx2Limits[
i])
2497 if (
stations[
i]->tyLimit - dty < ty2Limits[
i])
2501 diffZ = zs[
i + 1][1] - zs[
i][1];
2502 scaltype tx2 = (xs[
i + 1][1] - xs[
i][1]) / diffZ;
2503 scaltype ty2 = (ys[
i + 1][1] - ys[
i][1]) / diffZ;
2507 if (txBreak < 0) txBreak = -txBreak;
2509 if (tyBreak < 0) tyBreak = -tyBreak;
2511 if (
stations[
i]->txBreakLimit - txBreak < txBreak2Limits[
i])
2512 txBreak2Limits[
i] =
stations[
i]->txBreakLimit - txBreak;
2514 if (
stations[
i]->tyBreakLimit - tyBreak < tyBreak2Limits[
i])
2515 tyBreak2Limits[
i] =
stations[
i]->tyBreakLimit - tyBreak;
2547 list<LxPoint*>&
points = pts[stNum][lyNum];
2549 for (list<LxPoint*>::iterator
i =
points.begin();
i !=
points.end(); ++
i) {
2552 xs[stNum][lyNum] = point->
x;
2553 ys[stNum][lyNum] = point->
y;
2554 zs[stNum][lyNum] = point->
z;
2592 txBreak2Limits[
i] =
stations[
i]->txBreakLimit;
2593 tyBreak2Limits[
i] =
stations[
i]->tyBreakLimit;
2594 busyHits[
i] =
false;
2597 for (vector<LxMCPoint*>::iterator
i = track.
Points.begin();
2602 for (list<LxPoint*>::iterator j = point->
lxPoints.begin();
2618 ini = ini && 0 < inits[
i][j];
2622 out <<
"CheckArray: track does not contain all the points" << endl;
2639 out <<
"CheckArray on station " <<
i <<
": ";
2640 out <<
"dispX to limit: " << xDisp2Limits[
i];
2641 out <<
"; dispY to limit: " << yDisp2Limits[
i];
2644 out <<
"; Tx to limit: " << tx2Limits[
i];
2645 out <<
"; Ty to limit: " << ty2Limits[
i];
2648 out <<
"; tx break to limit: " << txBreak2Limits[
i];
2649 out <<
"; ty break to limit: " << tyBreak2Limits[
i];
2653 if (busyHits[
i]) out <<
"; have busy hits";