3 #include "kdtree++/kdtree.hpp"
23 for (list<LxTriplet*>::iterator
i = triplets.begin();
i != triplets.end();
28 for (list<LxSegment*>::iterator
i = segments.begin();
i != segments.end();
63 : points_handle(0), zCoord(0), station(Station), layerNumber(LayerNumber) {
78 for (KDTPointsStorageType::iterator
i =
points->begin();
i !=
points->end();
109 #ifdef OUT_DISP_BY_TRIPLET_DIR
112 , xOutDispTriplet2(0)
113 , yOutDispTriplet2(0)
131 , txInterStationBreak(0)
132 , tyInterStationBreak(0)
133 , txInterStationBreak2(0)
134 , tyInterStationBreak2(0)
137 txInterTripletBreak(0)
138 , tyInterTripletBreak(0)
139 , txInterTripletBreak2(0)
140 , tyInterTripletBreak2(0)
144 , errCoeffTripletRX2(errCoeffTripletRX * errCoeffTripletRX)
146 , errCoeffTripletRY2(errCoeffTripletRY * errCoeffTripletRY)
148 , errCoeffTripletRLX2(errCoeffTripletRLX * errCoeffTripletRLX)
150 , errCoeffTripletRLY2(errCoeffTripletRLY * errCoeffTripletRLY)
152 , errCoeffInterTripletX2(errCoeffInterTripletX * errCoeffInterTripletX)
154 , errCoeffInterTripletY2(errCoeffInterTripletY * errCoeffInterTripletY)
156 , errCoeffInterTripletTx2(errCoeffInterTripletTx * errCoeffInterTripletTx)
158 , errCoeffInterTripletTy2(errCoeffInterTripletTy * errCoeffInterTripletTy) {
188 Double_t lZCoord = lLayer->
zCoord;
189 Double_t rZCoord = rLayer->
zCoord;
191 UInt_t tripletCount = 0;
193 for (KDTPointsStorageType::iterator
i = cPoints->begin();
i != cPoints->end();
197 Double_t deltaZc = rZCoord - cPoint->
z;
198 Double_t cTx = cPoint->
x / cPoint->
z;
199 Double_t cTy = cPoint->
y / cPoint->
z;
200 Double_t rX = cPoint->
x + cTx * deltaZc;
201 Double_t rY = cPoint->
y + cTy * deltaZc;
211 KDTree::_Bracket_accessor<KDTPointWrap>,
212 std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>>
214 rRange.set_low_bound(rBoundsWrap, 0);
215 rRange.set_low_bound(rBoundsWrap, 1);
216 rBoundsWrap.
data[0] = rX + rXLimit;
217 rBoundsWrap.
data[1] = rY + rYLimit;
218 rRange.set_high_bound(rBoundsWrap, 0);
219 rRange.set_high_bound(rBoundsWrap, 1);
220 list<KDTPointWrap> rNeighbours;
221 rPoints->find_within_range(
222 rRange, back_insert_iterator<list<KDTPointWrap>>(rNeighbours));
224 for (list<KDTPointWrap>::iterator j = rNeighbours.begin();
225 j != rNeighbours.end();
229 Double_t rDeltaX = rPoint->
x - rX;
230 Double_t rDeltaY = rPoint->
y - rY;
236 Double_t deltaZr = rPoint->
z - cPoint->
z;
237 Double_t tx = (rPoint->
x - cPoint->
x) / deltaZr;
238 Double_t ty = (rPoint->
y - cPoint->
y) / deltaZr;
239 deltaZr = lZCoord - cPoint->
z;
240 Double_t lX = cPoint->
x + tx * deltaZr;
241 Double_t lY = cPoint->
y + ty * deltaZr;
251 KDTree::_Bracket_accessor<KDTPointWrap>,
252 std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>>
254 lRange.set_low_bound(lBoundsWrap, 0);
255 lRange.set_low_bound(lBoundsWrap, 1);
256 lBoundsWrap.
data[0] = lX + lXLimit;
257 lBoundsWrap.
data[1] = lY + lYLimit;
258 lRange.set_high_bound(lBoundsWrap, 0);
259 lRange.set_high_bound(lBoundsWrap, 1);
260 list<KDTPointWrap> lNeighbours;
261 lPoints->find_within_range(
262 lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours));
264 for (list<KDTPointWrap>::iterator k = lNeighbours.begin();
265 k != lNeighbours.end();
269 Double_t lDeltaX = lPoint->
x - lX;
270 Double_t lDeltaY = lPoint->
y - lY;
278 cPoint->
triplets.push_back(triplet);
289 void LxStation::BuildSegments() {
291 Double_t lZCoord = lStation->
zCoord;
297 UInt_t segmentCount = 0;
299 for (KDTPointsStorageType::iterator
i = rPoints->begin();
i != rPoints->end();
304 if (rPoint->
triplets.empty())
continue;
307 Double_t txVertex = rPoint->
x / rPoint->
z;
308 Double_t tyVertex = rPoint->
y / rPoint->
z;
309 Double_t deltaZ = lZCoord - rPoint->
z;
310 Double_t lX = rPoint->
x + txVertex * deltaZ;
311 Double_t lY = rPoint->
y + tyVertex * deltaZ;
319 KDTree::_Bracket_accessor<KDTPointWrap>,
320 std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>>
322 lRange.set_low_bound(lBoundsWrap, 0);
323 lRange.set_low_bound(lBoundsWrap, 1);
324 lBoundsWrap.data[0] = lX + lXLimit;
325 lBoundsWrap.data[1] = lY + lYLimit;
326 lRange.set_high_bound(lBoundsWrap, 0);
327 lRange.set_high_bound(lBoundsWrap, 1);
328 list<KDTPointWrap> lNeighbours;
329 lPoints->find_within_range(
330 lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours));
332 for (list<KDTPointWrap>::iterator k = lNeighbours.begin();
333 k != lNeighbours.end();
338 if (lPoint->
triplets.empty())
continue;
340 deltaZ = lPoint->
z - rPoint->
z;
341 Double_t deltaZ2 = deltaZ * deltaZ;
342 Double_t tx = (lPoint->
x - rPoint->
x) / deltaZ;
343 Double_t ty = (lPoint->
y - rPoint->
y) / deltaZ;
344 Double_t dtx2 = (lPoint->
dx2 + rPoint->
dx2) / deltaZ2;
345 Double_t dty2 = (lPoint->
dy2 + rPoint->
dy2) / deltaZ2;
346 LxSegment* segment = 0;
348 for (list<LxTriplet*>::iterator l = rPoint->
triplets.begin();
352 Double_t rDeltaTx = rTriplet->
tx - tx;
353 Double_t rDeltaTx2 = rDeltaTx * rDeltaTx;
355 if (rDeltaTx2 > errorTXcoeff2 * (txBreakLeft2 + dtx2 + rTriplet->
dtx2))
358 Double_t rDeltaTy = rTriplet->
ty - ty;
359 Double_t rDeltaTy2 = rDeltaTy * rDeltaTy;
361 if (rDeltaTy2 > errorTYcoeff2 * (tyBreakLeft2 + dty2 + rTriplet->
dty2))
364 for (list<LxTriplet*>::iterator
m = lPoint->
triplets.begin();
368 Double_t lDeltaTx = lTriplet->
tx - tx;
369 Double_t lDeltaTx2 = lDeltaTx * rDeltaTx;
372 > errorTXcoeff2 * (txBreakRight2 + dtx2 + lTriplet->
dtx2))
375 Double_t lDeltaTy = lTriplet->
ty - ty;
376 Double_t lDeltaTy2 = lDeltaTy * rDeltaTy;
379 > errorTYcoeff2 * (tyBreakRight2 + dty2 + lTriplet->
dty2))
383 Double_t lDeltaX = lPoint->
x - lX;
384 Double_t lDeltaY = lPoint->
y - lY;
389 segment =
new LxSegment(rPoint, lPoint, tx, ty, dtx2, dty2, chi2);
390 rPoint->segments.push_back(segment);
394 segment->neighbours.push_back(lTriplet);
406 #ifdef OUT_DISP_BY_TRIPLET_DIR
410 Double_t lZCoord = lStation->
zCoord;
416 for (KDTPointsStorageType::iterator
i = rPoints->begin();
i != rPoints->end();
421 for (list<LxTriplet*>::iterator j = rPoint->
triplets.begin();
425 Double_t deltaZ = lZCoord - rPoint->
z;
426 Double_t lX = rPoint->
x + rTriplet->
tx * deltaZ;
427 Double_t lY = rPoint->
y + rTriplet->
ty * deltaZ;
435 KDTree::_Bracket_accessor<KDTPointWrap>,
436 std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>>
438 lRange.set_low_bound(lBoundsWrap, 0);
439 lRange.set_low_bound(lBoundsWrap, 1);
440 lBoundsWrap.data[0] = lX + lXLimit;
441 lBoundsWrap.data[1] = lY + lYLimit;
442 lRange.set_high_bound(lBoundsWrap, 0);
443 lRange.set_high_bound(lBoundsWrap, 1);
444 list<KDTPointWrap> lNeighbours;
445 lPoints->find_within_range(
446 lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours));
448 for (list<KDTPointWrap>::iterator k = lNeighbours.begin();
449 k != lNeighbours.end();
454 for (list<LxTriplet*>::iterator l = lPoint->
triplets.begin();
458 Double_t txBreak = lTriplet->
tx - rTriplet->
tx;
459 Double_t txBreak2 = txBreak * txBreak;
466 Double_t tyBreak = lTriplet->
ty - rTriplet->
ty;
467 Double_t tyBreak2 = tyBreak * tyBreak;
474 Double_t lDeltaX = lPoint->
x - lX;
475 Double_t lDeltaX2 = lDeltaX * lDeltaX;
476 Double_t lDeltaY = lPoint->
y - lY;
477 Double_t lDeltaY2 = lDeltaY * lDeltaY;
479 lDeltaX2 / (xOutDispTriplet2 + lPoint->
dx2 + rPoint->
dx2)
480 + lDeltaY2 / (yOutDispTriplet2 + lPoint->
dy2 + rPoint->
dy2)
485 rTriplet->
neighbours.push_back(make_pair(lTriplet, chi2));
492 #else //OUT_DISP_BY_TRIPLET_DIR
496 Double_t lZCoord = lStation->
zCoord;
502 for (KDTPointsStorageType::iterator
i = rPoints->begin();
i != rPoints->end();
507 if (rPoint->
triplets.empty())
continue;
510 Double_t txVertex = rPoint->
x / rPoint->
z;
511 Double_t tyVertex = rPoint->
y / rPoint->
z;
512 Double_t deltaZ = lZCoord - rPoint->
z;
513 Double_t lX = rPoint->
x + txVertex * deltaZ;
514 Double_t lY = rPoint->
y + tyVertex * deltaZ;
527 KDTree::_Bracket_accessor<KDTPointWrap>,
528 std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>>
530 lRange.set_low_bound(lBoundsWrap, 0);
531 lRange.set_low_bound(lBoundsWrap, 1);
532 lBoundsWrap.
data[0] = lX + lXLimit;
533 lBoundsWrap.
data[1] = lY + lYLimit;
534 lRange.set_high_bound(lBoundsWrap, 0);
535 lRange.set_high_bound(lBoundsWrap, 1);
536 list<KDTPointWrap> lNeighbours;
537 lPoints->find_within_range(
538 lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours));
540 for (list<KDTPointWrap>::iterator k = lNeighbours.begin();
541 k != lNeighbours.end();
546 if (lPoint->
triplets.empty())
continue;
548 for (list<LxTriplet*>::iterator l = rPoint->
triplets.begin();
553 for (list<LxTriplet*>::iterator
m = lPoint->
triplets.begin();
557 Double_t txBreak = lTriplet->
tx - rTriplet->
tx;
558 Double_t txBreak2 = txBreak * txBreak;
565 Double_t tyBreak = lTriplet->
ty - rTriplet->
ty;
566 Double_t tyBreak2 = tyBreak * tyBreak;
573 Double_t lDeltaX = lPoint->
x - lX;
574 Double_t lDeltaX2 = lDeltaX * lDeltaX;
575 Double_t lDeltaY = lPoint->
y - lY;
576 Double_t lDeltaY2 = lDeltaY * lDeltaY;
587 rTriplet->
neighbours.push_back(make_pair(lTriplet, chi2));
594 #endif //OUT_DISP_BY_TRIPLET_DIR
596 #endif //USE_SEGMENTS
605 for (list<pair<LxExtTrack*, Double_t>>::iterator
i =
610 Double_t aChi2 =
i->second;
617 }
else if (aChi2 < extTrack->recoTrack.second) {
648 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i)
662 void LxSpace::BuildSegments() {
674 #endif //USE_SEGMENTS
679 pair<LxSegment*, LxTriplet*>* branches,
680 list<LxTrackCandidate*>& candidates,
683 for (list<LxSegment*>::iterator
i = triplet->
neighbours.begin();
686 LxSegment* segment = *
i;
689 Double_t dtx_1 = segment->tx - triplet->
tx;
690 Double_t dty_1 = segment->ty - triplet->
ty;
693 + dtx_1 * dtx_1 / (rStation->txBreakLeft2 + triplet->
dtx2 + segment->dtx2)
695 / (rStation->tyBreakLeft2 + triplet->
dty2 + segment->dty2);
698 LxSegment* rSegment = branches[level].first;
699 Double_t dtx_1_s = abs(segment->tx - rSegment->tx);
700 Double_t slopeCoeff2 =
701 1 + rSegment->tx * rSegment->tx + rSegment->ty * rSegment->ty;
702 Double_t segTxSigma2 = rStation->txInterStationBreak2 * slopeCoeff2
703 + segment->dtx2 + rSegment->dtx2;
705 if (dtx_1_s > errorTXcoeff *
sqrt(segTxSigma2))
continue;
707 Double_t dty_1_s = abs(segment->ty - rSegment->ty);
708 Double_t segTySigma2 = rStation->tyInterStationBreak2 * slopeCoeff2
709 + segment->dty2 + rSegment->dty2;
711 if (dty_1_s > errorTYcoeff *
sqrt(segTySigma2))
continue;
714 dtx_1_s * dtx_1_s / segTxSigma2 + dty_1_s * dty_1_s / segTySigma2;
717 for (list<LxTriplet*>::iterator j = segment->neighbours.begin();
718 j != segment->neighbours.end();
726 Double_t dtx_2 = triplet2->
tx - segment->tx;
727 Double_t dty_2 = triplet2->
ty - segment->ty;
729 chi2_1 + triplet2->
chi2
731 / (lStation->txBreakRight2 + segment->dtx2 + triplet2->
dtx2)
733 / (lStation->tyBreakRight2 + segment->dty2 + triplet2->
dty2);
734 branches[level - 1] = make_pair(segment, triplet2);
739 candidates.push_back(trackCandidate);
742 begin, triplet2, branches, candidates, level - 1, chi2_2);
750 list<LxTrackCandidate*>& candidates,
753 for (list<pair<LxTriplet*, Double_t>>::iterator
i =
757 pair<LxTriplet*, Double_t>& tc2 = *
i;
763 branches[level - 1] = triplet2;
767 endStNum, branches, chi2 + tc2.second + triplet2->
chi2);
768 candidates.push_back(trackCandidate);
775 chi2 + tc2.second + triplet2->
chi2);
778 #endif //USE_SEGMENTS
786 #endif //USE_SEGMENTS
792 startStation->
layers[1]->points_handle);
794 for (KDTPointsStorageType::iterator
i =
points->begin();
i !=
points->end();
798 list<LxTrackCandidate*> candidates;
801 for (list<LxTriplet*>::iterator j = point->
triplets.begin();
810 Double_t chi2 = triplet->
chi2;
812 pair<LxSegment*, LxTriplet*> branches[
LXSTATIONS - 1];
814 triplet, triplet, branches, candidates,
LXSTATIONS - 1, chi2);
817 branches[endStNum] = triplet;
819 endStNum, triplet, branches, candidates, endStNum, chi2);
820 #endif //USE_SEGMENTS
823 cout <<
"LxSpace::Reconstruct(): track candidate number: "
824 << candidates.size() << endl;
828 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
829 j != candidates.end();
833 if (0 == bestCandidate || candidate->
chi2 < bestCandidate->
chi2)
834 bestCandidate = candidate;
837 if (0 != bestCandidate) {
842 for (list<LxTrackCandidate*>::iterator j = candidates.begin();
843 j != candidates.end();
853 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
855 list<LxTrack*>::iterator i2 =
i;
858 for (; i2 !=
tracks.end(); ++i2) {
860 Int_t neighbourPoints = 0;
864 Int_t minPoints = minLen *
LXLAYERS;
867 if (j >= minPoints)
continue;
872 Double_t dx = point1->
dx > point2->
dx ? point1->
dx : point2->
dx;
873 Double_t dy = point1->
dy > point2->
dy ? point1->
dy : point2->
dy;
875 if (abs(point2->
x - point1->
x) < 5.0 * dx
876 && abs(point2->
y - point1->
y) < 5.0 * dy)
880 if (neighbourPoints < minPoints / 2)
continue;
883 secondTrack->
clone =
true;
885 firstTrack->
clone =
true;
886 else if (firstTrack->
chi2 < secondTrack->
chi2)
887 secondTrack->
clone =
true;
889 firstTrack->
clone =
true;
900 for (list<LxTrack*>::iterator
i =
tracks.begin();
i !=
tracks.end(); ++
i) {
903 if (track->
clone)
continue;
914 lastL1Param, &lastParam);
920 Double_t deltaX = abs(lastParam.
GetX() - muchPoint->
x);
921 Double_t deltaY = abs(lastParam.
GetY() - muchPoint->
y);
922 Double_t deltaTx = abs(lastParam.
GetTx() - leftTriplet->
tx);
923 Double_t deltaTy = abs(lastParam.
GetTy() - leftTriplet->
ty);
925 Double_t sigmaX =
sqrt(sigmaX2);
927 Double_t sigmaY =
sqrt(sigmaY2);
929 Double_t sigmaTx =
sqrt(sigmaTx2);
931 Double_t sigmaTy =
sqrt(sigmaTy2);
938 Double_t chi2 = deltaX * deltaX / sigmaX2 + deltaY * deltaY / sigmaY2
939 + deltaTx * deltaTx / sigmaTx2
940 + deltaTy * deltaTy / sigmaTy2;
942 list<pair<LxExtTrack*, Double_t>>::iterator k =
948 pair<LxExtTrack*, Double_t> linkDesc(extTrack, chi2);
952 for (list<pair<LxExtTrack*, Double_t>>::iterator j =
957 Double_t chi2 = j->second;
964 }
else if (chi2 < extTrack->recoTrack.second) {
992 points->insert(pointWrap);