23 #ifdef CBM_BINNED_DEBUG
25 #endif //CBM_BINNED_DEBUG
38 : fHits(new
CbmTBin::HitHolder*[length])
43 for (
int i = 0;
i < length; ++
i) {
47 fHits[fLength] =
hits[
i];
48 fHits[fLength++]->tracks.push_back(
this);
51 fParams[fLength - 1] = lastParam;
52 Double_t chiSq2 = chiSq;
56 for (
int i = fLength - 2;
i >= 0; --
i) {
58 fParams[
i + 1], fHits[
i]->hit->GetZ());
84 , fNofWrongSegments(0)
92 , fBeamDxSq(beamDx * beamDx)
94 , fBeamDySq(beamDy * beamDy)
96 , fVertexPseudoStation(0)
99 #ifdef CBM_BINNED_DEBUG
106 fVertex.SetDx(beamDx);
107 fVertex.SetDy(beamDy);
111 fVertex.SetTimeError(1000000000000);
120 fVertexPseudoStation =
122 fVertexPseudoStation->SetMinY(-0.1);
123 fVertexPseudoStation->SetMaxY(0.1);
124 fVertexPseudoStation->SetMinX(-0.1);
125 fVertexPseudoStation->SetMaxX(0.1);
126 fVertexPseudoStation->Init();
129 for (std::map<Double_t, CbmBinnedStation*>::const_iterator
i =
131 i != fStations.end();
133 fStationArray.push_back(
i->second);
134 std::cout <<
"Station min and max Zs: " <<
i->second->GetMinZ() <<
", "
135 <<
i->second->GetMaxZ() << std::endl;
138 if (fCanSkipHits < 0) fCanSkipHits = 0.3 * fStationArray.size();
150 fStations[station->
GetMinZ()] = station;
151 fNofStations = fStations.size();
152 fBeforeLastLevel = fNofStations - 2;
161 fVertexPseudoStation->SetStage(
v);
163 for (std::vector<CbmBinnedStation*>::iterator
i = fStationArray.begin();
164 i != fStationArray.end();
176 for (std::map<Double_t, CbmBinnedStation*>::iterator
i = fStations.begin();
177 i != fStations.end();
187 for (
int i = -1;
i <= fCanSkipHits; ++
i) {
190 for (
int j = 0; j <= (
i == fCanSkipHits ? 0 : 1); ++j)
191 SeedTracks(
i,
i + j + 1);
196 std::cout <<
"Reconstructed "
197 << count_if(fTracks.begin(),
199 [](
const Track* t) { return !t->fIsClone; })
200 <<
" tracks" << std::endl;
204 return fTracks.begin();
207 return fTracks.end();
212 fVertexPseudoStation->SetStage(0);
214 for (std::map<Double_t, CbmBinnedStation*>::iterator
i = fStations.begin();
215 i != fStations.end();
221 for (std::list<Track*>::iterator
i = fTracks.begin();
i != fTracks.end();
229 std::map<Double_t, CbmBinnedStation*>::iterator
i = fStations.begin();
230 i->second->CreateSegmentsFromHits();
236 if (
i == fStations.end())
break;
246 #if 0 //def CBM_BINNED_DEBUG
247 static int nofRefTracks = 0;
248 static int nofRecoRefHits[] = { 0, 0, 0, 0, 0, 0 };
253 for (
int i = 0;
i < fDebug.fMCTracks.size(); ++
i)
261 bool found[] = {
false,
false,
false,
false,
false,
false };
267 if (fDebug.TrackHasHit(stNo,
i, hitHolder->
index))
270 std::list<CbmBinnedStation::Segment*> tmp(segment.
children);
275 std::list<CbmBinnedStation::Segment*> tmp2;
277 for (std::list<CbmBinnedStation::Segment*>::const_iterator j = tmp.begin(); j != tmp.end(); ++j)
279 const CbmBinnedStation::Segment* s = *j;
280 tmp2.insert(tmp2.end(), s->children.begin(), s->children.end());
281 CbmTBin::HitHolder* hh = s->end;
283 if (fDebug.TrackHasHit(stNo, i, hh->index))
288 tmp.splice(tmp.end(), tmp2);
295 std::cout <<
"Reco hits: ";
297 for (
int j = 0; j <
sizeof(nofRecoRefHits) /
sizeof(
int); ++j)
302 double proc = 100 * nofRecoRefHits[j];
303 proc /= nofRefTracks;
304 std::cout <<
"[" << proc <<
"%=" << nofRecoRefHits[j] <<
"/" << nofRefTracks <<
"]";
307 std::cout << std::endl << std::endl << std::endl;
309 #endif //CBM_BINNED_DEBUG
329 Double_t x1 = hit1->
GetX();
330 Double_t y1 = hit1->
GetY();
331 Double_t
z1 = hit1->
GetZ();
333 Double_t dx1 = hit1->
GetDx();
334 Double_t dx1Sq = dx1 * dx1;
335 Double_t dy1 = hit1->
GetDy();
336 Double_t dy1Sq = dy1 * dy1;
340 Double_t x2 = hit2->
GetX();
341 Double_t y2 = hit2->
GetY();
342 Double_t
z2 = hit2->
GetZ();
344 Double_t dx2 = hit2->
GetDx();
345 Double_t dx2Sq = dx2 * dx2;
346 Double_t dy2 = hit2->
GetDy();
347 Double_t dy2Sq = dy2 * dy2;
351 Double_t
x = hit->
GetX();
352 Double_t
y = hit->
GetY();
353 Double_t z = hit->
GetZ();
355 Double_t dx = hit->
GetDx();
356 Double_t dxSq = dx * dx;
357 Double_t dy = hit->
GetDy();
358 Double_t dySq = dy * dy;
370 Double_t deltaZ12 =
z2 -
z1;
371 Double_t deltaZ = z - (
z1 +
z2) / 2;
372 Double_t coeff1 = (0.5 - deltaZ / deltaZ12);
373 Double_t coeff1Sq = coeff1 * coeff1;
374 Double_t coeff2 = (0.5 + deltaZ / deltaZ12);
375 Double_t coeff2Sq = coeff2 * coeff2;
377 Double_t x12 = coeff1 * x1 + coeff2 * x2;
378 Double_t dx12Sq = coeff1Sq * dx1Sq + coeff2Sq * dx2Sq;
379 Double_t y12 = coeff1 * y1 + coeff2 * y2;
380 Double_t dy12Sq = coeff1Sq * dy1Sq + coeff2Sq * dy2Sq;
401 return (
x - x12) * (
x - x12) / (dx12Sq + dxSq + scatXSq)
402 + (
y - y12) * (
y - y12) / (dy12Sq + dySq + scatYSq)
415 Double_t x1 = hit1->
GetX();
416 Double_t y1 = hit1->
GetY();
417 Double_t
z1 = hit1->
GetZ();
419 Double_t dx1 = hit1->
GetDx();
420 Double_t dx1Sq = dx1 * dx1;
421 Double_t dy1 = hit1->
GetDy();
422 Double_t dy1Sq = dy1 * dy1;
424 Double_t x2 = hit2->
GetX();
425 Double_t y2 = hit2->
GetY();
426 Double_t
z2 = hit2->
GetZ();
428 Double_t dx2 = hit2->
GetDx();
429 Double_t dx2Sq = dx2 * dx2;
430 Double_t dy2 = hit2->
GetDy();
431 Double_t dy2Sq = dy2 * dy2;
433 Double_t
x = hit->
GetX();
434 Double_t
y = hit->
GetY();
435 Double_t z = hit->
GetZ();
437 Double_t dx = hit->
GetDx();
438 Double_t dxSq = dx * dx;
439 Double_t dy = hit->
GetDy();
440 Double_t dySq = dy * dy;
442 Double_t deltaZ12 =
z2 -
z1;
443 Double_t deltaZ = z - (
z1 +
z2) / 2;
444 Double_t coeff1 = (0.5 - deltaZ / deltaZ12);
445 Double_t coeff1Sq = coeff1 * coeff1;
446 Double_t coeff2 = (0.5 + deltaZ / deltaZ12);
447 Double_t coeff2Sq = coeff2 * coeff2;
449 Double_t x12 = coeff1 * x1 + coeff2 * x2;
450 Double_t dx12Sq = coeff1Sq * dx1Sq + coeff2Sq * dx2Sq;
451 Double_t y12 = coeff1 * y1 + coeff2 * y2;
452 Double_t dy12Sq = coeff1Sq * dy1Sq + coeff2Sq * dy2Sq;
457 return (
x - x12) * (
x - x12) / (dx12Sq + dxSq)
458 + (
y - y12) * (
y - y12) / (dy12Sq + dySq);
591 std::list<Track*>& candidates,
593 Double_t chiSqPrev) {
597 fStationArray[level]->Extrapolate(kfParamsPrev, hit->
GetZ());
598 Double_t chiSq = chiSqPrev;
603 if (level == fNofStations - 1) {
604 Track* aCandidate =
new Track(hhs, fNofStations, kfParams, chiSq);
605 candidates.push_back(aCandidate);
609 for (std::list<CbmBinnedStation::Segment*>::iterator
i =
614 trackStart[level + 1] = childSegment;
615 hhs[level + 1] = childSegment->
end;
616 TraverseTrackCandidates(
617 level + 1, trackStart, hhs, hts, candidates, kfParams, chiSq);
622 std::map<Double_t, CbmBinnedStation*>::iterator startStationIter =
629 segments[0] = &segment;
632 trackHolders[0] = segment.
end;
634 std::list<Track*> candidates;
640 kfParams.SetX(p1->
GetX());
642 kfParams.SetY(p1->
GetY());
645 kfParams.SetZ(p1->
GetZ());
662 TraverseTrackCandidates(
663 0, segments, trackHolders, hitTypes, candidates, kfParams, chiSq);
664 Track* bestCandidate = 0;
666 for (std::list<Track*>::iterator
i = candidates.begin();
667 i != candidates.end();
669 Track* aCandidate = *i;
671 if (0 == bestCandidate
672 || aCandidate->fChiSq < bestCandidate->fChiSq) {
673 delete bestCandidate;
674 bestCandidate = aCandidate;
679 if (0 != bestCandidate) fTracks.push_back(bestCandidate);
682 #ifdef CBM_BINNED_DEBUG
683 static int nofRefTracks = 0;
684 static int nofRecoRefHits[] = {0, 0, 0, 0, 0, 0};
688 for (
int i = 0;
i < fDebug.fMCTracks.size(); ++
i) {
691 if (!mcTrack.
isRef)
continue;
693 for (std::list<Track*>::const_iterator j = fTracks.begin();
696 const Track* recoTrack = *j;
699 if (!fDebug.TrackHasHit(0,
i, firstHit->
index))
continue;
704 for (
int k = 1; k < 6; ++k) {
705 if (fDebug.TrackHasHit(k,
i, recoTrack->fHits[k]->index))
711 std::cout <<
"Reco hits: ";
713 for (
int j = 0; j <
sizeof(nofRecoRefHits) /
sizeof(
int); ++j) {
714 double proc = 100 * nofRecoRefHits[j];
715 proc /= nofRefTracks;
716 std::cout <<
"[" << proc <<
"%=" << nofRecoRefHits[j] <<
"/"
717 << nofRefTracks <<
"]";
720 std::cout << std::endl << std::endl << std::endl;
721 #endif //CBM_BINNED_DEBUG
725 int skippedHits = rightStationNo - leftStationNo - 1;
727 0 > leftStationNo ? fVertexPseudoStation : fStationArray[leftStationNo];
729 [
this, &leftStationNo, &rightStationNo, &skippedHits](
740 tmpTrackHolders[0] = &leftHitHolder;
743 kfParams.SetX(leftHit->
GetX());
745 kfParams.SetY(leftHit->
GetY());
747 kfParams.SetZ(leftHit->
GetZ());
772 tmpTrackHolders[1] = &rightHitHolder;
773 const CbmPixelHit* rightHit = rightHitHolder.hit;
774 CbmTrackParam2 updKfParams =
775 rightStation->Extrapolate(kfParams, rightHit->GetZ());
776 Double_t updChiSq = chiSq;
777 CbmBinnedStation::Update(updKfParams, rightHit, updChiSq);
779 if (updChiSq > fChiSqCut) return;
781 if (0 > leftStationNo)
783 bestChiSq = cbmBinnedCrazyChiSq;
785 bestKfParams = kfParams;
788 FollowTracks(0 > leftStationNo,
800 if (0 > leftStationNo)
802 if (bestLength - 1 >= fNofStations - fCanSkipHits) {
804 new Track(trackHolders, bestLength, bestKfParams, bestChiSq);
805 fTracks.push_back(aTrack);
811 if (0 <= leftStationNo)
813 if (bestLength >= fNofStations - fCanSkipHits) {
815 new Track(trackHolders, bestLength, bestKfParams, bestChiSq);
816 fTracks.push_back(aTrack);
832 Double_t& bestChiSq) {
833 Double_t prevZ = trackHolders[length - 2]->
hit->
GetZ();
835 for (
char i = 0;
i <= (prevStationNo < fNofStations - 2 ? 1 : 0)
836 && skippedHits +
i <= fCanSkipHits;
838 Int_t stationNo = prevStationNo +
i + 1;
859 trackHolders[length - 1] = &hitHolder;
863 Double_t updChiSq = chiSq;
866 Double_t chiSqCut = fChiSqCut;
868 if (length - (isPrimary ? 1 : 0) > fNofStations - fCanSkipHits)
870 (length - (isPrimary ? 1 : 0) - fNofStations + fCanSkipHits)
873 if (updChiSq > chiSqCut || updChiSq > bestChiSq)
878 if (stationNo < fNofStations - 1) {
879 FollowTracks(isPrimary,
891 if (length - (isPrimary ? 1 : 0) >= fNofStations - fCanSkipHits
892 && (length > bestLength
893 || (length == bestLength && updChiSq < bestChiSq))) {
894 for (
int j = 0; j < length; ++j)
895 bestTrackHolders[j] = trackHolders[j];
897 bestKfParams = updKfParams;
909 if (length - (isPrimary ? 1 : 0) >= fNofStations - fCanSkipHits
910 && (length > bestLength
911 || (length == bestLength && chiSq < bestChiSq))) {
912 for (
int j = 0; j < length; ++j)
913 bestTrackHolders[j] = trackHolders[j];
915 bestKfParams = kfParams;
924 for (std::list<Track*>::iterator
i = fTracks.begin();
i != fTracks.end();
930 std::map<Track*, int> cloneNofs;
932 for (
int j = 0; j < track->
fLength; ++j) {
934 std::set<Track*> neighbourTracks;
936 for (std::list<void*>::iterator k = hit->
tracks.begin();
941 if (track2 == track || track2->
fIsClone)
continue;
943 neighbourTracks.insert(track2);
946 for (std::set<Track*>::iterator k = neighbourTracks.begin();
947 k != neighbourTracks.end();
950 std::map<Track*, int>::iterator cni = cloneNofs.find(track2);
952 if (cni == cloneNofs.end())
953 cloneNofs[track2] = 1;
959 for (std::map<Track*, int>::iterator j = cloneNofs.begin();
960 j != cloneNofs.end();
962 Track* track2 = j->first;
966 if (j->second <
int(0.7 * minLength))
continue;
998 #ifdef CBM_BINNED_DEBUG