17 #include "FairEventHeader.h"
18 #include "FairField.h"
19 #include "FairLogger.h"
20 #include "FairRootManager.h"
22 #include <TClonesArray.h>
23 #include <TGeoManager.h>
26 #include <TMatrixFLazy.h>
43 : FairTask(
"MuchMergeVectors")
58 for (Int_t
i = 0;
i < 9; ++
i)
69 for (map<Int_t, TMatrixDSym*>::iterator it =
fMatr.begin(); it !=
fMatr.end();
79 FairRootManager* ioman = FairRootManager::Instance();
80 if (ioman == NULL) Fatal(
"Init",
"RootManager not instantiated!");
83 fTrackArray =
new TClonesArray(
"CbmMuchTrack", 100);
84 ioman->Register(
"MuchVectorTrack",
"Much",
fTrackArray, kTRUE);
86 CbmMuchFindHitsStraws* hitFinder =
87 (CbmMuchFindHitsStraws*) FairRun::Instance()->GetTask(
88 "CbmMuchFindHitsStraws");
92 fGemHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPixelHit"));
93 fPoints =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPoint"));
94 fVecArray =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchVector"));
95 fTracksSts =
static_cast<TClonesArray*
>(ioman->GetObject(
"StsTrack"));
96 fTrStsMatch =
static_cast<TClonesArray*
>(ioman->GetObject(
"StsTrackMatch"));
97 fTracksLit =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchTrack"));
101 for (Int_t
i = 0;
i < nSt; ++
i) {
112 for (Int_t lay = 0; lay < nLays; ++lay) {
114 Double_t phi = hitFinder->GetPhi(lay);
115 for (Int_t iside = 0; iside < 2; ++iside) {
117 Int_t plane = lay * 2 + iside;
119 fCosa[plane] = TMath::Cos(phi);
120 fSina[plane] = TMath::Sin(phi);
133 FairTask* vecFinder = FairRun::Instance()->GetTask(
"VectorFinder");
134 vecFinder->GetListOfTasks()->ls();
137 "MuchFindVectorsGem");
138 if (gemFinder == NULL) Fatal(
"Init",
"CbmMuchFindVectorsGem not run!");
142 cout <<
" \n !!! MUCH Absorbers: " << nAbs <<
"\n Zbeg, Zend, X0:";
143 for (Int_t j = 0; j < nAbs; ++j)
144 cout <<
" " << std::setprecision(4) <<
fZabs0[j][0] <<
", " <<
fZabs0[j][1]
145 <<
", " <<
fX0abs[j] <<
";";
146 cout << endl << endl;
161 gLogger->SetLogScreenLevel(
"INFO");
189 for (map<Int_t, TMatrixDSym*>::iterator it =
fMatr.begin(); it !=
fMatr.end();
199 std::map<Int_t, CbmMuchTrack*>::iterator it;
200 for (Int_t ista = 0; ista <
fgkStat; ++ista) {
204 if (it->first >= 0)
delete it->second;
209 Int_t nVecs =
fVecArray->GetEntriesFast(), sel = 0;
210 for (Int_t
i = 0;
i < nVecs; ++
i) {
218 Int_t ista = vec->GetUniqueID() + 1;
219 fVectors[ista].insert(pair<Int_t, CbmMuchTrack*>(
i, vec));
224 Int_t nSts =
fTracksSts->GetEntriesFast(), ista = 0;
225 FairTrackParam param, parRear;
226 Double_t pMin = 0.25;
229 for (Int_t
i = 0;
i < nSts; ++
i) {
232 Double_t ppp = 1. / TMath::Abs(tr->
GetParamLast()->GetQp());
234 if (ppp < pMin + 0.05)
continue;
242 Double_t r2 = param.GetX() * param.GetX() + param.GetY() * param.GetY();
243 if (TMath::Sqrt(r2) >
fRmax[0])
continue;
246 1.0 + param.GetTx() * param.GetTx() + param.GetTy() * param.GetTy();
248 if (ppp / TMath::Sqrt(cos2th) < pMin + 0.05)
continue;
250 param.SetQp(1.0 / ppp);
254 parRear.SetQp(TMath::Abs(parRear.GetQp()));
267 fVectors[ista].insert(pair<Int_t, CbmMuchTrack*>(
i + nVecs, vec));
272 TMatrixF matr = TMatrixF(5, 5);
273 TMatrixF unit(TMatrixF::kUnit, matr);
280 parFirst.CovMatrix(cov);
303 parFirst.SetCovMatrix(cov);
332 const Double_t window0 = 7.0;
333 TMatrixF matr = TMatrixF(5, 5);
334 TMatrixF unit(TMatrixF::kUnit, matr);
335 map<Int_t, CbmMuchTrack*>::iterator it, it1;
336 multimap<Double_t, pair<Int_t, CbmMuchTrack*>> xMap[2];
337 multimap<Double_t, pair<Int_t, CbmMuchTrack*>>::iterator mit, mit1, mitb,
339 map<CbmMuchTrack*, Int_t> matchOK[2];
343 for (Int_t iabs = 3; iabs >= 0;
345 Double_t window = window0;
346 if (iabs ==
fgkStat - 2) window = window0 * 2.0;
353 for (Int_t ist = 0; ist < 2; ++ist) {
355 Int_t ista = iabs - 1 + ist + 1;
360 parFirst.CovMatrix(cov);
363 Double_t zbeg = parFirst.GetZ();
364 Double_t dz =
fZabs0[iabs][1] - zbeg;
366 parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx());
367 parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy());
368 parFirst.SetZ(parFirst.GetZ() + dz);
370 ff(2, 0) = ff(3, 1) = dz;
372 TMatrixF cf(cov, TMatrixF::kMult, ff);
373 TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf);
374 cov.SetMatrixArray(fcf.GetMatrixArray());
375 if (ist == 0 && iabs > 0)
377 ist + iabs * 2,
fZabs0[iabs],
fX0abs[iabs], parFirst, cov, 0);
381 parFirst.SetCovMatrix(cov);
385 pair<Double_t, pair<Int_t, CbmMuchTrack*>>(parFirst.GetX(), *it));
386 matchOK[ist][tr] = -1;
390 Int_t ista0 = iabs - 1 + 1, ista1 = iabs + 1;
392 for (mit = xMap[0].begin(); mit != xMap[0].end(); ++mit) {
398 Float_t pars1[5] = {(Float_t) par1.GetX(),
399 (Float_t) par1.GetY(),
400 (Float_t) par1.GetTx(),
401 (Float_t) par1.GetTy(),
403 TMatrixF p1(5, 1, pars1);
404 TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1);
405 Double_t x0 = parOk.GetX(), y0 = parOk.GetY();
406 mitb = xMap[1].lower_bound(x0 - window);
407 mite = xMap[1].upper_bound(x0 + window);
409 for (mit1 = mitb; mit1 != mite; ++mit1) {
412 if (par2.GetY() - y0 < -window)
continue;
413 if (par2.GetY() - y0 > window)
continue;
416 TMatrixFSym w20 = w2;
417 Float_t pars2[5] = {(Float_t) par2.GetX(),
418 (Float_t) par2.GetY(),
419 (Float_t) par2.GetTx(),
420 (Float_t) par2.GetTy(),
422 TMatrixF p2(5, 1, pars2);
423 TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2);
427 TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2);
431 TMatrixF pMerge = p12;
433 TMatrixF wDp1(w1, TMatrixF::kMult, p12);
434 TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1);
436 TMatrixF wDp2(w20, TMatrixF::kMult, p122);
437 TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2);
438 Double_t c2 = chi21(0, 0) + chi22(0, 0);
440 if (c2 < 0 || c2 >
fCutChi2[iabs])
continue;
456 for (Int_t ist = 0; ist < 2; ++ist) {
457 Int_t ista = iabs - 1 + ist + 1;
461 if (matchOK[ist][tr] > 0)
continue;
462 if (ista == 0)
delete tr;
465 cout <<
" MergeVectors: vectors after matching in station " << ista
466 <<
": " <<
fVectors[ista].size() << endl;
476 const Double_t window0 = 5.0;
477 TMatrixF matr = TMatrixF(5, 5);
478 TMatrixF unit(TMatrixF::kUnit, matr);
479 map<Int_t, CbmMuchTrack*>::iterator it, it1;
480 multimap<Double_t, pair<Int_t, CbmMuchTrack*>> xMap[2];
481 multimap<Double_t, pair<Int_t, CbmMuchTrack*>>::iterator mit, mit1;
483 for (Int_t iabs = 0; iabs <= 3; ++iabs) {
488 for (Int_t ist = 0; ist < 2; ++ist) {
490 Int_t ista = iabs - 1 + ist + 1;
492 Int_t imerged = (
fVectors[ista].begin()->first < 0)
496 if (imerged && it->first >= 0)
501 Double_t zbeg = parFirst.GetZ();
503 Double_t dz =
fZabs0[iabs][1] - zbeg;
507 parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx());
508 parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy());
509 parFirst.SetZ(parFirst.GetZ() + dz);
511 parFirst.CovMatrix(cov);
517 ff(2, 0) = ff(3, 1) = dz;
519 TMatrixF cf(cov, TMatrixF::kMult, ff);
520 TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf);
521 cov.SetMatrixArray(fcf.GetMatrixArray());
526 if (ist == 0 && iabs > 0) {
536 ist + iabs * 2,
fZabs0[iabs],
fX0abs[iabs], parFirst, cov, 1);
540 parFirst.SetCovMatrix(cov);
544 pair<Double_t, pair<Int_t, CbmMuchTrack*>>(parFirst.GetX(), *it));
552 Int_t ista0 = iabs - 1 + 1, ista1 = iabs + 1;
554 map<Int_t, CbmMuchTrack*> mapMerged;
555 Double_t window = window0;
556 if (iabs == 3) window *= 2;
558 for (mit = xMap[0].begin(); mit != xMap[0].end(); ++mit) {
566 if (1. / parOk.GetQp() < 0.05)
continue;
570 Float_t pars1[5] = {(Float_t) par1.GetX(),
571 (Float_t) par1.GetY(),
572 (Float_t) par1.GetTx(),
573 (Float_t) par1.GetTy(),
575 TMatrixF p1(5, 1, pars1);
576 TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1);
577 Double_t x0 = parOk.GetX(), y0 = parOk.GetY();
579 for (mit1 = xMap[1].begin(); mit1 != xMap[1].end(); ++mit1) {
585 if (par2.GetX() - x0 < -window)
continue;
586 if (par2.GetX() - x0 > window)
break;
587 if (par2.GetY() - y0 < -window)
continue;
588 if (par2.GetY() - y0 > window)
continue;
591 TMatrixFSym w20 = w2;
592 Float_t pars2[5] = {(Float_t) par2.GetX(),
593 (Float_t) par2.GetY(),
594 (Float_t) par2.GetTx(),
595 (Float_t) par2.GetTy(),
597 TMatrixF p2(5, 1, pars2);
598 TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2);
602 TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2);
607 TMatrixF pMerge = p12;
609 TMatrixF wDp1(w1, TMatrixF::kMult, p12);
610 TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1);
612 TMatrixF wDp2(w20, TMatrixF::kMult, p122);
613 TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2);
614 Double_t c2 = chi21(0, 0) + chi22(0, 0);
616 if (c2 < 0 || c2 >
fCutChi2[iabs])
continue;
618 parOk.SetX(pMerge(0, 0));
619 parOk.SetY(pMerge(1, 0));
620 parOk.SetZ(par2.GetZ());
621 parOk.SetTx(pMerge(2, 0));
622 parOk.SetTy(pMerge(3, 0));
623 parOk.SetCovMatrix(w2);
631 Int_t evNo = FairRun::Instance()->GetEventHeader()->GetMCEntryNumber();
646 if (mapMerged.size() == 0)
break;
649 for (it = mapMerged.begin(); it != mapMerged.end(); ++it) {
650 fVectors[ista1][it->first] = it->second;
661 FairTrackParam& parFirst,
666 Double_t
x = parFirst.GetX();
667 Double_t
y = parFirst.GetY();
668 Double_t z = parFirst.GetZ();
669 Double_t tx = parFirst.GetTx();
670 Double_t ty = parFirst.GetTy();
672 Double_t dz = (zabs[0] - zabs[1]) / 1;
680 Double_t aaa = 1.0 + tx * tx + ty * ty;
681 dz *= TMath::Sqrt(aaa);
682 Double_t l = TMath::Abs(dz);
684 Double_t l3 = l2 * l;
686 TMatrixFSym covMS(5);
691 covMS(0, 0) = l2 / 3 * (1.0 + tx * tx);
692 covMS(1, 1) = l2 / 3 * (1.0 + ty * ty);
693 covMS(2, 2) = 1 * (1.0 + tx * tx);
694 covMS(3, 3) = 1 * (1.0 + ty * ty);
697 covMS(0, 1) = covMS(1, 0) = l2 / 3 * tx * ty;
699 Int_t icor = (ist % 2 == 0) ? 1 : -1;
704 covMS(0, 2) = covMS(2, 0) = icor * l / 2 * (1.0 + tx * tx);
705 covMS(1, 2) = covMS(2, 1) = icor * l / 2 * tx * ty;
710 covMS(0, 3) = covMS(3, 0) = icor * l / 2 * tx * ty;
711 covMS(1, 3) = covMS(3, 1) = icor * l / 2 * (1.0 + ty * ty);
712 covMS(2, 3) = covMS(3, 2) = 1 * tx * ty;
716 Double_t dxx0 = l / x0, angle = 0.0;
720 * (1. + 0.038 * TMath::Log(dxx0));
723 Double_t pmom = 1.0 / TMath::Abs(parFirst.GetQp());
724 Double_t beta = pmom / TMath::Sqrt(pmom * pmom + 0.106 * 0.106);
725 angle = 0.0136 / beta / pmom * (1. + 0.038 * TMath::Log(dxx0));
728 covMS *= (angle * angle * dxx0);
730 if (pFlag == 0)
return;
733 Double_t pLoss[6] = {0.25, 0.25, 0.25, 0.37, 0, 0};
734 Double_t ppp = 1. / parFirst.GetQp();
735 ppp -= (pLoss[ist / 2] * TMath::Sqrt(aaa));
736 parFirst.SetQp(1. / ppp);
746 FairTrackParam& parOk,
755 if (tr1->GetUniqueID() == -9) {
763 track->SetUniqueID(tr2->GetUniqueID());
775 for (Int_t j = 0; j < nmerged; ++j)
786 for (Int_t j = 0; j < nmerged; ++j)
796 gLogger->Info(MESSAGE_ORIGIN,
797 "CbmMuchMergeVectors::AddTrack: ista=%i, trID1=%i, trID2=%i, "
798 "chi2=%f, merged vectors %i",
810 map<Int_t, CbmMuchTrack*>& mapMerged) {
816 multimap<Double_t, Int_t> c2merge;
817 for (Int_t i1 = ibeg; i1 < ntrs; ++i1) {
828 + (499 - TMath::Min(tr1->
GetChiSq() / tr1->
GetNDF(), 499.0)) / 500;
829 c2merge.insert(pair<Double_t, Int_t>(-qual, i1));
832 multimap<Double_t, Int_t>::iterator it, it1;
833 for (it = c2merge.begin(); it != c2merge.end(); ++it) {
835 if (tr1 == NULL)
continue;
839 for (++it1; it1 != c2merge.end(); ++it1) {
842 if (tr2 == NULL)
continue;
844 if (tr2->GetUniqueID() != tr1->GetUniqueID())
continue;
846 Bool_t over = kFALSE;
847 for (Int_t iv1 = 0; iv1 < nvecs1; ++iv1) {
848 for (Int_t iv2 = iv1; iv2 < nvecs2; ++iv2) {
851 if (iv2 != iv1)
continue;
861 if (clones == 0) ++clones;
864 gLogger->Info(MESSAGE_ORIGIN,
865 "CbmMuchMergeVectors:RemoveClones: qual1 %f, qual2 "
866 "%f, trID1 %i, trID2 %i, ista %i, p1 %f, p2 %f",
887 for (Int_t i1 = ibeg; i1 < ntrs; ++i1) {
889 mapMerged[-i1 - 1] = tr1;
898 const Int_t nMax[2] = {2, 2}, nPl = 40;
901 Int_t planes[nPl], ntrs =
fTrackArray->GetEntriesFast();
903 multimap<Double_t, Int_t> c2merge;
904 for (Int_t
i = 0;
i < ntrs; ++
i) {
917 c2merge.insert(pair<Double_t, Int_t>(-qual,
i));
919 if (c2merge.size() < 2)
return;
921 multimap<Double_t, Int_t>::iterator it, it1;
922 for (it = c2merge.begin(); it != c2merge.end(); ++it) {
924 if (tr1 == NULL)
continue;
926 for (Int_t j = 0; j < nPl; ++j)
929 for (Int_t iv = 0; iv < nvecs1; ++iv) {
940 for (Int_t ih = 0; ih < nh; ++ih) {
948 for (++it1; it1 != c2merge.end(); ++it1) {
950 if (tr2 == NULL)
continue;
952 Int_t nvecs2 = tr2->
GetNofHits(), nover[2] = {0};
953 Bool_t over = kFALSE;
955 for (Int_t iv = 0; iv < nvecs2; ++iv) {
958 if (planes[nPl - 1] >= 0 && planes[nPl - 1] == tr2->
GetHitIndex(iv)) {
960 gLogger->Info(MESSAGE_ORIGIN,
961 "Track quality: qual1 %f, qual2 %f, trID1 %i, trID2 "
962 "%i, the same STS track: %i",
971 if (tr2->GetUniqueID() != tr1->GetUniqueID())
break;
979 for (Int_t ih = 0; ih < nh; ++ih) {
982 if (planes[ipl] < 0)
continue;
988 if (nover[0] >= nMax[0] || nover[1] >= nMax[1]) {
990 gLogger->Info(MESSAGE_ORIGIN,
991 "Track quality: qual1 %f, qual2 %f, trID1 %i, "
992 "trID2 %i, overlaps: %i, %i",
1018 const Int_t nVecsMin = 4;
1019 map<Int_t, CbmMuchTrack*>::iterator it, it1;
1020 TMatrixF matr = TMatrixF(5, 5);
1021 TMatrixF unit(TMatrixF::kUnit, matr);
1023 if (
fVectors[0].size() == 0)
return;
1025 if (
fVectors[0].begin()->second->GetNofHits() != nVecsMin)
1028 for (Int_t ist = 0; ist < 1; ++ist) {
1031 Int_t iabs = 0, ista = 1;
1037 Double_t zbeg = parFirst.GetZ();
1038 Double_t dz =
fZabs0[iabs][1] - zbeg;
1040 parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx());
1041 parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy());
1042 parFirst.SetZ(parFirst.GetZ() + dz);
1044 parFirst.CovMatrix(cov);
1047 ff(2, 0) = ff(3, 1) = dz;
1048 TMatrixF cf(cov, TMatrixF::kMult, ff);
1049 TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf);
1050 cov.SetMatrixArray(fcf.GetMatrixArray());
1052 parFirst.SetCovMatrix(cov);
1058 Int_t nvecs =
fVecArray->GetEntriesFast();
1060 if (it->first >= 0)
break;
1061 Int_t indSts = (it->second)->GetHitIndex(0);
1071 Float_t pars1[5] = {(Float_t) par1.GetX(),
1072 (Float_t) par1.GetY(),
1073 (Float_t) par1.GetTx(),
1074 (Float_t) par1.GetTy(),
1076 TMatrixF p1(5, 1, pars1);
1077 TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1);
1078 Double_t c2min = 999999.0;
1083 Int_t iabs = 0, ista1 = 1;
1093 TMatrixFSym w20 = w2;
1094 Float_t pars2[5] = {(Float_t) par2.GetX(),
1095 (Float_t) par2.GetY(),
1096 (Float_t) par2.GetTx(),
1097 (Float_t) par2.GetTy(),
1099 TMatrixF p2(5, 1, pars2);
1100 TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2);
1104 TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2);
1108 TMatrixF p122 = p12;
1110 TMatrixF wDp1(w1, TMatrixF::kMult, p12);
1111 TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1);
1113 TMatrixF wDp2(w20, TMatrixF::kMult, p122);
1114 TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2);
1115 Double_t c2 = chi21(0, 0) + chi22(0, 0);
1117 if (c2 < 0 || c2 >
fCutChi2[iabs])
continue;
1119 if (c2 < c2min) c2min = c2;
1122 if (c2min / 4 > 5) {
1124 MESSAGE_ORIGIN,
"Stat.1: removed track: c2min %f", c2min / 4);
1127 cout <<
" Chi2: " << c2min / 4 << endl;
1139 FairTrackParam& parOk,
1149 track->SetUniqueID(tr1->GetUniqueID());
1154 for (Int_t j = 0; j < nmerged; ++j) {
1168 "trID1=%i, trID2=%i, chi2=%f, merged vectors %i",