3#include "BmnGemStripHit.h"
4#include "BmnKalmanFilter.h"
8#include "FairTrackParam.h"
23#define GCC_DIAGNOSTIC_AWARE 1
24#if GCC_DIAGNOSTIC_AWARE
25# pragma GCC diagnostic ignored "-Wunknown-pragmas"
29static Double_t workTime = 0.0;
30static Double_t createTime = 0.0;
31static Double_t stateTime = 0.0;
32static Double_t connectTime = 0.0;
33static Double_t sortTime = 0.0;
34static Double_t selectTime = 0.0;
41: fSteerFile(steerFile),
44 fInnerTrackerSetup[
kGEM] = kTRUE;
45 fInnerTrackerSetup[
kSILICON] = kTRUE;
46 fInnerTrackerSetup[
kSSD] = kFALSE;
51 Fatal(
"BmnCellAutoTracking()",
"Probably, run number has been changed manually in reco macro. Aborting ...");
57 isSRC = (
run == -2) ? kTRUE : kFALSE;
61 const Int_t runTransition = 3589;
62 isSRC = (
run < runTransition) ? kTRUE : kFALSE;
65 TString
setup = isSRC ?
"SRC" :
"BMN";
67 fSteering =
new BmnSteering(field ? TString(
setup +
"_run7_withField.dat") : TString(
setup +
"_run7_noField.dat"));
74 fNSiliconStations = 0;
75 fGemHitsArray =
nullptr;
76 fSilHitsArray =
nullptr;
77 fSsdHitsArray =
nullptr;
79 fRoughVertex = (fPeriodId == 7) ? TVector3(0.5, -4.6, -2.3) : (fPeriodId == 6) ? TVector3(0.0, -3.5, -21.9) : TVector3(0.0, 0.0, 0.0);
81 fGlobTracksArray =
nullptr;
82 fGemTracksArray =
nullptr;
83 fSilTracksArray =
nullptr;
84 fSsdTracksArray =
nullptr;
86 fGemHitsBranchName =
"BmnGemStripHit";
87 fSilHitsBranchName =
"BmnSiliconHit";
88 fSsdHitsBranchName =
"BmnSSDHit";
89 fGlobTracksBranchName =
"BmnGlobalTrack";
90 fGemTracksBranchName =
"BmnGemTrack";
91 fSilTracksBranchName =
"BmnSiliconTrack";
92 fSsdTracksBranchName =
"BmnSSDTrack";
94 fGemDetector =
nullptr;
95 fSilDetector =
nullptr;
96 fCellDistCut =
nullptr;
97 fCellSlopeXZCutMin =
nullptr;
98 fCellSlopeXZCutMax =
nullptr;
99 fCellSlopeYZCutMin =
nullptr;
100 fCellSlopeYZCutMax =
nullptr;
101 fHitXCutMin =
nullptr;
102 fHitXCutMax =
nullptr;
103 fHitYCutMin =
nullptr;
104 fHitYCutMax =
nullptr;
105 fCellDiffSlopeXZCut =
nullptr;
106 fCellDiffSlopeYZCut =
nullptr;
108 kCellsCut = 10000000000;
114 if (fInnerTrackerSetup[
kGEM])
delete fGemDetector;
115 if (fInnerTrackerSetup[
kSILICON])
delete fSilDetector;
121 delete fCellSlopeXZCutMin;
122 delete fCellSlopeXZCutMax;
123 delete fCellSlopeYZCutMin;
124 delete fCellSlopeYZCutMax;
125 delete fCellDiffSlopeXZCut;
126 delete fCellDiffSlopeYZCut;
130 if (fVerbose > 1) cout <<
"======================== GEM tracking init started ====================" << endl;
133 FairRootManager* ioman = FairRootManager::Instance();
135 Fatal(
"Init",
"FairRootManager is not instantiated");
138 fMCTracksArray = (TClonesArray*)ioman->GetObject(
"MCTrack");
141 if (fInnerTrackerSetup[
kGEM]) {
142 fGemPointsArray = (TClonesArray*)ioman->GetObject(
"StsPoint");
143 fGemHitsArray = (TClonesArray*)ioman->GetObject(fGemHitsBranchName);
144 fGemTracksArray =
new TClonesArray(
"BmnTrack", 100);
145 ioman->Register(fGemTracksBranchName,
"GEM", fGemTracksArray, kTRUE);
150 fSilPointsArray = (TClonesArray*)ioman->GetObject(
"SiliconPoint");
151 fSilHitsArray = (TClonesArray*)ioman->GetObject(fSilHitsBranchName);
152 fSilTracksArray =
new TClonesArray(
"BmnTrack", 100);
153 ioman->Register(fSilTracksBranchName,
"SILICON", fSilTracksArray, kTRUE);
157 if (fInnerTrackerSetup[
kSSD]) {
158 fSsdPointsArray = (TClonesArray*)ioman->GetObject(
"SSDPoint");
159 fSsdHitsArray = (TClonesArray*)ioman->GetObject(fSsdHitsBranchName);
160 fSsdTracksArray =
new TClonesArray(
"BmnTrack", 100);
161 ioman->Register(fSsdTracksBranchName,
"SSD", fSsdTracksArray, kTRUE);
164 if (!fGemHitsArray && !fSsdHitsArray && !fSilHitsArray) {
165 cout <<
"BmnCellAutoTracking::Init(): branch " << fGemHitsBranchName <<
" not found! Task will be deactivated" << endl;
170 fGlobTracksArray =
new TClonesArray(
"BmnGlobalTrack", 100);
171 ioman->Register(fGlobTracksBranchName,
"GLOBAL", fGlobTracksArray, kTRUE);
172 fHitsArray =
new TClonesArray(
"BmnHit", 100);
173 ioman->Register(
"BmnInnerHits",
"HITS", fHitsArray, kTRUE);
175 fField = FairRunAna::Instance()->GetField();
176 if (!fField) Fatal(
"Init",
"No Magnetic Field found");
178 TString gPathConfig = gSystem->Getenv(
"VMCWORKDIR");
180 if (fInnerTrackerSetup[
kGEM]) {
181 TString gPathGemConfig = gPathConfig +
"/parameters/gem/XMLConfigs/";
182 TString confGem = (fPeriodId == 7) ?
"GemRun" + TString(isSRC ?
"SRC" :
"") +
"Spring2018.xml" : (fPeriodId == 6) ?
"GemRunSpring2017.xml" :
"GemRunSpring2017.xml";
187 TString gPathSiConfig = gPathConfig +
"/parameters/silicon/XMLConfigs/";
188 TString confSi = (fPeriodId == 7) ?
"SiliconRun" + TString(isSRC ?
"SRC" :
"") +
"Spring2018.xml" :
"SiliconRunSpring2017.xml";
191 Int_t nGemStations = (fInnerTrackerSetup[
kGEM]) ? fGemDetector->
GetNStations() : 0;
193 Int_t nSsdStations = (fInnerTrackerSetup[
kSSD]) ? 4 : 0;
198 fNStations = nGemStations + nSilStations + nSsdStations;
200 fCellDistCut =
new Double_t[fNStations];
201 fHitXCutMin =
new Double_t[fNStations];
202 fHitXCutMax =
new Double_t[fNStations];
203 fHitYCutMin =
new Double_t[fNStations];
204 fHitYCutMax =
new Double_t[fNStations];
205 fCellSlopeXZCutMin =
new Double_t[fNStations];
206 fCellSlopeXZCutMax =
new Double_t[fNStations];
207 fCellSlopeYZCutMin =
new Double_t[fNStations];
208 fCellSlopeYZCutMax =
new Double_t[fNStations];
209 fCellDiffSlopeXZCut =
new Double_t[fNStations];
210 fCellDiffSlopeYZCut =
new Double_t[fNStations];
212 if (fVerbose > 1) cout <<
"======================== GEM tracking init finished ===================" << endl;
218 if (fVerbose > 1) cout <<
"\n======================== GEM tracking exec started ====================" << endl;
219 if (fVerbose > 1) cout <<
"\n Event number: " << fEventNo << endl;
221 if (!IsActive())
return;
223 clock_t tStart = clock();
225 if (fInnerTrackerSetup[
kSILICON]) fSilTracksArray->Delete();
226 if (fInnerTrackerSetup[
kSSD]) fSsdTracksArray->Delete();
227 if (fInnerTrackerSetup[
kGEM]) fGemTracksArray->Delete();
228 fGlobTracksArray->Delete();
229 fHitsArray->Delete();
236 Int_t nSsdStations = (fInnerTrackerSetup[
kSSD]) ? 4 : 0;
239 for (Int_t iHit = 0; iHit < fSilHitsArray->GetEntriesFast(); ++iHit) {
243 new ((*fHitsArray)[fHitsArray->GetEntriesFast()])
BmnHit(hit);
246 if (fInnerTrackerSetup[
kSSD]) {
247 for (Int_t iHit = 0; iHit < fSsdHitsArray->GetEntriesFast(); ++iHit) {
252 new ((*fHitsArray)[fHitsArray->GetEntriesFast()])
BmnHit(hit);
255 if (fInnerTrackerSetup[
kGEM]) {
256 for (Int_t iHit = 0; iHit < fGemHitsArray->GetEntriesFast(); ++iHit) {
261 new ((*fHitsArray)[fHitsArray->GetEntriesFast()])
BmnHit(hit);
265 if (fHitsArray->GetEntriesFast() > nHitsCut || fHitsArray->GetEntriesFast() == 0)
return;
267 for (Int_t iStat = 0; iStat < fNStations; iStat++) {
280 vector<BmnTrack> candidates;
281 vector<BmnTrack> sortedCandidates;
289 const Int_t nIter = fSteering->
GetNIter();
291 for (Int_t iter = 0; iter < nIter; ++iter) {
292 vector<BmnCellDuet> cells[fNStations];
294 for (Int_t iSt = 0; iSt < fNStations; ++iSt) {
295 fCellDiffSlopeXZCut[iSt] = diffSlopeXZ0 + iter * diffSlopeXZSlope;
296 fCellDiffSlopeYZCut[iSt] = diffSlopeYZ0 + iter * diffSlopeYZSlope;
299 clock_t t0 = clock();
300 CellsCreation(cells);
301 clock_t t1 = clock();
303 clock_t t2 = clock();
304 vector<BmnTrack> tmpVec = CellsConnection(cells);
306 candidates.push_back(tr);
307 clock_t t3 = clock();
309 TrackUpdateByKalman(candidates);
311 TrackUpdateByLine(candidates);
312 clock_t t4 = clock();
314 createTime += ((Double_t)(t1 - t0)) / CLOCKS_PER_SEC;
315 stateTime += ((Double_t)(t2 - t1)) / CLOCKS_PER_SEC;
316 connectTime += ((Double_t)(t3 - t2)) / CLOCKS_PER_SEC;
317 sortTime += ((Double_t)(t4 - t3)) / CLOCKS_PER_SEC;
320 clock_t t5 = clock();
321 SortTracks(candidates, sortedCandidates);
322 TrackSelection(sortedCandidates);
323 clock_t t6 = clock();
324 selectTime += ((Double_t)(t6 - t5)) / CLOCKS_PER_SEC;
327 clock_t tFinish = clock();
328 if (fVerbose > 0) cout <<
"BmnCellAutoTracking: " << fGlobTracksArray->GetEntriesFast() <<
" tracks" << endl;
330 workTime += ((Double_t)(tFinish - tStart)) / CLOCKS_PER_SEC;
332 if (fVerbose > 1) cout <<
"\n======================== GEM tracking exec finished ===================" << endl;
335BmnStatus BmnCellAutoTracking::SortTracks(vector<BmnTrack>& inTracks, vector<BmnTrack>& sortedTracks) {
336 const Int_t n = fNStations - fNHitsCut + 1;
337 multimap<Float_t, Int_t> sortedMap[n];
338 for (
size_t iTr = 0; iTr < inTracks.size(); ++iTr) {
339 if (inTracks.at(iTr).GetNHits() < fNHitsCut)
continue;
340 if (inTracks.at(iTr).GetChi2() / inTracks.at(iTr).GetNDF() > fChiSquareCut)
continue;
341 sortedMap[inTracks.at(iTr).GetNHits() - fNHitsCut].insert(pair<Float_t, Int_t>(inTracks.at(iTr).GetChi2() / inTracks.at(iTr).GetNDF(), iTr));
344 for (Int_t
i = n - 1;
i >= 0;
i--) {
345 for (
auto it : sortedMap[
i])
346 sortedTracks.push_back(inTracks.at(it.second));
347 sortedMap[
i].clear();
362 outFile.open(
"QA/timing.txt");
363 outFile <<
"Track Finder Time: " << workTime << endl;
365 cout <<
"Cells creation time: " << createTime << endl;
366 cout <<
"States calculation time: " << stateTime << endl;
367 cout <<
"Cells connection time: " << connectTime << endl;
368 cout <<
"Tracks sorting time: " << sortTime << endl;
369 cout <<
"Tracks selection time: " << selectTime << endl;
371 cout <<
"Work time of the GEM tracking: " << workTime << endl;
374BmnStatus BmnCellAutoTracking::CellsCreation(vector<BmnCellDuet>* cells) {
375 vector<Int_t> hitsOnStation[fNStations];
377 for (Int_t iHit = 0; iHit < fHitsArray->GetEntriesFast(); ++iHit) {
380 if (hit->
IsUsed())
continue;
382 if (hit->GetX() > fHitXCutMax[station] || hit->GetX() < fHitXCutMin[station])
continue;
383 if (hit->GetY() > fHitYCutMax[station] || hit->GetY() < fHitYCutMin[station])
continue;
384 hitsOnStation[station].push_back(iHit);
388 for (
size_t iHit = 0; iHit < hitsOnStation[0].size(); ++iHit)
390 BmnHit* hit = (
BmnHit*)fHitsArray->At(hitsOnStation[0].at(iHit));
392 Double_t x0 = fRoughVertex.X();
393 Double_t y0 = fRoughVertex.Y();
394 Double_t
z0 = fRoughVertex.Z();
395 Double_t x1 = hit->GetX();
396 Double_t y1 = hit->GetY();
397 Double_t z1 = hit->GetZ();
398 Double_t slopeXZ = (x1 - x0) / (z1 -
z0);
399 if (slopeXZ > fCellSlopeXZCutMax[0] || slopeXZ < fCellSlopeXZCutMin[0])
continue;
400 Double_t slopeYZ = (y1 - y0) / (z1 -
z0);
401 if (slopeYZ > fCellSlopeYZCutMax[0] || slopeYZ < fCellSlopeYZCutMin[0])
continue;
404 duetVirt.
SetLastIdx(hitsOnStation[0].at(iHit));
411 cells[0].push_back(duetVirt);
414 for (Int_t iSt = 1; iSt < fNStations; ++iSt)
415 for (
size_t iHit0 = 0; iHit0 < hitsOnStation[iSt - 1].size(); ++iHit0) {
416 BmnHit* hit0 = (
BmnHit*)fHitsArray->At(hitsOnStation[iSt - 1].at(iHit0));
417 Double_t x0 = hit0->GetX();
418 Double_t y0 = hit0->GetY();
419 Double_t
z0 = hit0->GetZ();
420 for (
size_t iHit1 = 0; iHit1 < hitsOnStation[iSt].size(); ++iHit1) {
421 BmnHit* hit1 = (
BmnHit*)fHitsArray->At(hitsOnStation[iSt].at(iHit1));
422 Double_t x1 = hit1->GetX();
423 Double_t y1 = hit1->GetY();
424 Double_t z1 = hit1->GetZ();
425 Double_t slopeXZ = (x1 - x0) / (z1 -
z0);
426 if (slopeXZ > fCellSlopeXZCutMax[iSt] || slopeXZ < fCellSlopeXZCutMin[iSt])
continue;
427 Double_t slopeYZ = (y1 - y0) / (z1 -
z0);
428 if (slopeYZ > fCellSlopeYZCutMax[iSt] || slopeYZ < fCellSlopeYZCutMin[iSt])
continue;
431 duet.
SetFirstIdx(hitsOnStation[iSt - 1].at(iHit0));
432 duet.
SetLastIdx(hitsOnStation[iSt].at(iHit1));
439 cells[iSt].push_back(duet);
446BmnStatus BmnCellAutoTracking::StateCalculation(vector<BmnCellDuet>* cells) {
447 for (Int_t iStartCell = 1; iStartCell < fNStations; ++iStartCell) {
448 for (Int_t iCell = iStartCell; iCell < fNStations; ++iCell) {
449 if (cells[iCell].size() > 10000)
continue;
454 if (state != leftNeigh.GetOldState())
continue;
455 if (idx != leftNeigh.GetLastIdx())
continue;
465 for (Int_t iCell = iStartCell; iCell < fNStations; ++iCell)
467 it.SetOldState(it.GetNewState());
478vector<BmnTrack> BmnCellAutoTracking::CellsConnection(vector<BmnCellDuet>* cells) {
479 vector<BmnTrack> cands;
484 omp_set_num_threads(nThreads);
486 vector<vector<BmnTrack>> candsThread(nThreads);
487 for (Int_t maxCell = fNStations - 1; maxCell > 0; maxCell--) {
489 if (cells[maxCell].size() > kCellsCut)
492#pragma omp parallel firstprivate(curDuet)
497 for (
size_t i = 0;
i < cells[maxCell].size(); ++
i) {
506 for (Int_t iCellLeft = maxCell - 1; iCellLeft >= 0; iCellLeft--) {
508 Double_t minSlopeDiff = 1e10;
511 if (curDuet.
GetFirstIdx() != itLeft.GetLastIdx())
continue;
512 Double_t slopeDiffYZ = Abs(curDuet.
GetSlopeYZ() - itLeft.GetSlopeYZ());
513 Double_t slopeDiffXZ = Abs(curDuet.
GetSlopeXZ() - itLeft.GetSlopeXZ());
514 if (slopeDiffYZ < minSlopeDiff && slopeDiffYZ < fCellDiffSlopeYZCut[iCellLeft] && slopeDiffXZ < fCellDiffSlopeXZCut[iCellLeft]) {
515 minSlopeDiff = slopeDiffYZ;
519 if (minLeft !=
nullptr) {
527 if (CalculateTrackParams(&trackCand) ==
kBMNERROR)
continue;
531 threadNum = omp_get_thread_num();
533 candsThread.at(threadNum).push_back(trackCand);
538 for (Int_t
i = 0;
i < nThreads; ++
i)
539 for (
size_t j = 0; j < candsThread[
i].size(); ++j)
540 cands.push_back(candsThread[
i][j]);
545BmnStatus BmnCellAutoTracking::TrackUpdateByLine(vector<BmnTrack>& cands) {
552 cand.SetChi2((chiX - chiY) > 0. ? chiX : chiY);
554 cand.GetParamFirst()->SetTx(Tx);
555 cand.GetParamFirst()->SetTy(Ty);
557 cand.GetParamLast()->SetTx(Tx);
558 cand.GetParamLast()->SetTy(Ty);
564BmnStatus BmnCellAutoTracking::TrackUpdateByKalman(vector<BmnTrack>& cands) {
566 FairTrackParam par = *(cand.GetParamFirst());
568 Double_t chiTot = 0.0;
569 for (Int_t iHit = 0; iHit < cand.GetNHits(); ++iHit) {
570 BmnHit* hit = (
BmnHit*)fHitsArray->At(cand.GetHitIndex(iHit));
573 fKalman->
Update(&par, hit, chi);
575 cand.SetParamLast(par);
576 for (Int_t iHit = cand.GetNHits() - 1; iHit >= 0; iHit--) {
577 BmnHit* hit = (
BmnHit*)fHitsArray->At(cand.GetHitIndex(iHit));
580 fKalman->
Update(&par, hit, chi);
583 cand.SetParamFirst(par);
584 cand.SetChi2(chiTot);
632BmnStatus BmnCellAutoTracking::TrackSelection(vector<BmnTrack>& sortedTracks) {
633 CheckSharedHits(sortedTracks);
634 for (
size_t iTr = 0; iTr < sortedTracks.size(); ++iTr) {
641 for (Int_t iHit = 0; iHit < tr.
GetNHits(); ++iHit) {
646 else if (detId ==
kSSD)
648 else if (detId ==
kGEM)
659 new ((*fSilTracksArray)[fSilTracksArray->GetEntriesFast()])
BmnTrack(silTr);
663 new ((*fSsdTracksArray)[fSsdTracksArray->GetEntriesFast()])
BmnTrack(ssdTr);
669 new ((*fGemTracksArray)[fGemTracksArray->GetEntriesFast()])
BmnTrack(gemTr);
678 new ((*fGlobTracksArray)[fGlobTracksArray->GetEntriesFast()])
BmnGlobalTrack(globTr);
679 SetHitsUsing(&tr, kTRUE);
680 if (!fIsTarget && iTr == 0)
break;
686void BmnCellAutoTracking::SetHitsUsing(
BmnTrack* tr, Bool_t use) {
694 const UInt_t nHits = tr->
GetNHits();
695 Double_t chi2circ = 0.0;
696 TVector3 CircParZX =
CircleFit(tr, fHitsArray, chi2circ);
698 Double_t Xc = CircParZX.Y();
699 Double_t Zc = CircParZX.X();
700 fField = FairRunAna::Instance()->GetField();
701 const Double_t B = (
LineFit(tr, fHitsArray,
"ZY")).X();
703 Double_t Q = (Xc > 0) ? +1 : -1;
705 Double_t sumX(0.0), sumY(0.0), sumTx(0.0), sumTy(0.0), sumQP(0.0);
706 Double_t sumXX(0.0), sumXY(0.0), sumXTx(0.0), sumXTy(0.0), sumXQP(0.0);
707 Double_t sumYY(0.0), sumYTx(0.0), sumYTy(0.0), sumYQP(0.0);
708 Double_t sumTxTx(0.0), sumTxTy(0.0), sumTxQP(0.0);
709 Double_t sumTyTy(0.0), sumTyQP(0.0);
710 Double_t sumQPQP(0.0);
712 for (UInt_t
i = 0;
i < nHits; ++
i) {
715 Double_t Xi = hit->GetX();
716 Double_t Yi = hit->GetY();
717 Double_t Zi = hit->GetZ();
719 Double_t Txi = -1.0 * (Zi - Zc) / (Xi - Xc);
721 Double_t Ri = Sqrt(Sq(Xi - Xc) + Sq(Zi - Zc));
722 Double_t QPi = Q / (0.0003 * Abs(fField->GetBy(Xi, Yi, Zi)) * Ri);
738 sumTxTx += Txi * Txi;
739 sumTxTy += Txi * Tyi;
740 sumTxQP += Txi * QPi;
741 sumTyTy += Tyi * Tyi;
742 sumTyQP += Tyi * QPi;
743 sumQPQP += QPi * QPi;
746 Double_t meanX = sumX / nHits;
747 Double_t meanY = sumY / nHits;
748 Double_t meanTx = sumTx / nHits;
749 Double_t meanTy = sumTy / nHits;
750 Double_t meanQP = sumQP / nHits;
752 Double_t Cov_X_X = sumXX / nHits - Sq(meanX);
753 Double_t Cov_X_Y = sumXY / nHits - meanX * meanY;
754 Double_t Cov_X_Tx = sumXTx / nHits - meanX * meanTx;
755 Double_t Cov_X_Ty = sumXTy / nHits - meanX * meanTy;
756 Double_t Cov_X_Qp = sumXQP / nHits - meanX * meanQP;
757 Double_t Cov_Y_Y = sumYY / nHits - Sq(meanY);
758 Double_t Cov_Y_Tx = sumYTx / nHits - meanY * meanTx;
759 Double_t Cov_Y_Ty = sumYTy / nHits - meanY * meanTy;
760 Double_t Cov_Y_Qp = sumYQP / nHits - meanY * meanQP;
761 Double_t Cov_Tx_Tx = sumTxTx / nHits - Sq(meanTx);
762 Double_t Cov_Tx_Ty = sumTxTy / nHits - meanTx * meanTy;
763 Double_t Cov_Tx_Qp = sumTxQP / nHits - meanTx * meanQP;
764 Double_t Cov_Ty_Ty = sumTyTy / nHits - Sq(meanTy);
765 Double_t Cov_Ty_Qp = sumTyQP / nHits - meanTy * meanQP;
766 Double_t Cov_Qp_Qp = sumQPQP / nHits - Sq(meanQP);
769 par.SetCovariance(0, 0, Cov_X_X);
770 par.SetCovariance(0, 1, Cov_X_Y);
771 par.SetCovariance(0, 2, Cov_X_Tx);
772 par.SetCovariance(0, 3, Cov_X_Ty);
773 par.SetCovariance(0, 4, Cov_X_Qp);
774 par.SetCovariance(1, 1, Cov_Y_Y);
775 par.SetCovariance(1, 2, Cov_Y_Tx);
776 par.SetCovariance(1, 3, Cov_Y_Ty);
777 par.SetCovariance(1, 4, Cov_Y_Qp);
778 par.SetCovariance(2, 2, Cov_Tx_Tx);
779 par.SetCovariance(2, 3, Cov_Tx_Ty);
780 par.SetCovariance(2, 4, Cov_Tx_Qp);
781 par.SetCovariance(3, 3, Cov_Ty_Ty);
782 par.SetCovariance(3, 4, Cov_Ty_Qp);
783 par.SetCovariance(4, 4, Cov_Qp_Qp);
793 const UInt_t nHits = tr->
GetNHits();
794 if ((Int_t)nHits < fNHitsCut)
return kBMNERROR;
795 TVector3 lineParZY =
LineFit(tr, fHitsArray,
"ZY");
796 tr->
SetNDF(nHits - (fIsField ? 3 : 2));
797 const Double_t B = lineParZY.X();
802 if (fIsField) CalcCovMatrix(tr);
813 Double_t QP = fIsField ? CalcQp(tr) : 0.0;
820TVector2 BmnCellAutoTracking::CalcMeanSigma(vector<Double_t> QpSegm) {
822 for (
size_t iSegm = 0; iSegm < QpSegm.size(); iSegm++)
823 QpSum += QpSegm[iSegm];
825 Double_t QpMean = QpSum / QpSegm.size();
827 Double_t sqSigmaSum = 0.;
828 for (
size_t iSegm = 0; iSegm < QpSegm.size(); iSegm++)
829 sqSigmaSum += Sq(QpSegm[iSegm] - QpMean);
831 return TVector2(QpMean, Sqrt(sqSigmaSum / QpSegm.size()));
834Double_t BmnCellAutoTracking::CalcQp(
BmnTrack* track) {
835 Bool_t fRobustRefit = kTRUE;
836 Bool_t fSimpleRefit = kFALSE;
837 vector<BmnHit*> hits;
839 for (Int_t iHit = 0; iHit < track->
GetNHits(); iHit++)
842 Int_t kNSegm = track->
GetNHits() - 2;
844 Double_t QpRefit = 0.;
845 vector<Double_t> QpSegmBefore;
848 for (Int_t iHit = 0; iHit < kNSegm; iHit++) {
849 BmnHit* first = hits[iHit];
850 BmnHit* second = hits[iHit + 1];
851 BmnHit* third = hits[iHit + 2];
853 TVector3 CircParZX =
CircleBy3Hit(first, second, third);
854 Double_t R = CircParZX.Z();
855 Double_t Xc = CircParZX.Y();
856 Double_t Zc = CircParZX.X();
858 Double_t Q = (Xc > 0) ? +1. : -1.;
859 Double_t S = 0.0003 * (Abs(fField->GetBy(third->GetX(), third->GetY(), third->GetZ())) + Abs(fField->GetBy(second->GetX(), second->GetY(), second->GetZ())) + Abs(fField->GetBy(first->GetX(), first->GetY(), first->GetZ()))) / 3.;
862 Double_t fX = first->GetX();
863 Double_t fZ = first->GetZ();
867 Double_t Tx_first = h * (fZ - Zc) / (fX - Xc);
868 TVector3 lineParZY =
LineFit(track, fHitsArray,
"ZY");
869 const Double_t B = lineParZY.X();
870 Double_t Ty_first = B;
872 Double_t Pz = Pt / Sqrt(1 + Sq(Tx_first));
873 Double_t Px = Tx_first * Pz;
874 Double_t Py = Ty_first * Pz;
875 Double_t P = Sqrt(Sq(Px) + Sq(Py) + Sq(Pz));
878 QpSegmBefore.push_back(QP);
883 vector<Double_t> QpSegmAfter;
885 TVector2 meanSig = CalcMeanSigma(QpSegmBefore);
886 Double_t mean = meanSig.X();
887 Double_t sigma = meanSig.Y();
888 if (std::isnan(sigma) && fVerbose == 3) {
889 cout <<
"Bad refit convergence for track segment!!" << endl;
893 for (
size_t iSegm = 0; iSegm < QpSegmBefore.size(); iSegm++)
894 if (Abs(QpSegmBefore[iSegm] - mean) - sigma <= 0.001)
895 QpSegmAfter.push_back(QpSegmBefore[iSegm]);
897 if (QpSegmAfter.size() == QpSegmBefore.size()) {
901 QpSegmBefore.clear();
902 QpSegmBefore.resize(0);
904 for (
size_t iSegm = 0; iSegm < QpSegmAfter.size(); iSegm++)
905 QpSegmBefore.push_back(QpSegmAfter[iSegm]);
908 QpSegmAfter.resize(0);
915 for (
size_t iEle = 0; iEle < QpSegmBefore.size(); iEle++)
916 QpRefit += QpSegmBefore[iEle];
918 QpRefit /= QpSegmBefore.size();
920 vector<Double_t>
d =
dist(QpSegmBefore, QpRefit);
923 for (
size_t i = 0;
i < QpSegmBefore.size();
i++)
924 sigma += (QpSegmBefore[
i] - QpRefit) * (QpSegmBefore[
i] - QpRefit);
925 sigma = Sqrt(sigma / QpSegmBefore.size());
927 vector<Double_t> w =
W(
d, sigma);
930 const Int_t kNIter = 20;
931 for (Int_t iIter = 1; iIter < kNIter; iIter++) {
932 QpRefit =
Mu(QpSegmBefore, w);
933 d =
dist(QpSegmBefore, QpRefit);
942Double_t BmnCellAutoTracking::CalculateLength(
BmnTrack* tr) {
945 vector<Double_t> X, Y, Z;
946 for (Int_t iGem = 0; iGem < tr->
GetNHits(); iGem++) {
949 X.push_back(hit->GetX());
950 Y.push_back(hit->GetY());
951 Z.push_back(hit->GetZ());
954 Double_t length = 0.;
955 for (
size_t i = 0;
i < X.size() - 1;
i++) {
956 Double_t dX = X[
i] - X[
i + 1];
957 Double_t dY = Y[
i] - Y[
i + 1];
958 Double_t dZ = Z[
i] - Z[
i + 1];
959 length += Sqrt(dX * dX + dY * dY + dZ * dZ);
965BmnStatus BmnCellAutoTracking::CheckSharedHits(vector<BmnTrack>& sortedTracks) {
968 const Int_t kNSharedHits = 0;
970 for (
size_t iTr = 0; iTr < sortedTracks.size(); ++iTr) {
971 BmnTrack* tr = &(sortedTracks.at(iTr));
972 if (tr->
GetFlag() == -1)
continue;
974 Int_t nofSharedHits = 0;
976 for (Int_t iHit = 0; iHit < nofHits; iHit++)
977 if (hitsId.find(tr->
GetHitIndex(iHit)) != hitsId.end()) {
979 if (nofSharedHits > kNSharedHits) {
984 if (tr->
GetFlag() == -1)
continue;
986 for (Int_t iHit = 0; iHit < nofHits; iHit++)
994BmnStatus BmnCellAutoTracking::DrawHits() {
995 TH2F* h_HitsZX =
new TH2F(
"h_HitsZX",
"h_HitsZX", 400, 0.0, 200.0, 400, -100.0, 100.0);
996 TH2F* h_HitsZY =
new TH2F(
"h_HitsZY",
"h_HitsZY", 400, 0.0, 200.0, 400, -10.0, 50.0);
997 for (Int_t
i = 0;
i < fHitsArray->GetEntriesFast(); ++
i) {
999 h_HitsZX->Fill(hit->GetZ(), hit->GetX());
1000 h_HitsZY->Fill(hit->GetZ(), hit->GetY());
1003 TCanvas* c =
new TCanvas(
"c",
"c", 1000, 1000);
1006 h_HitsZX->SetMarkerStyle(8);
1007 h_HitsZX->SetMarkerSize(0.7);
1008 h_HitsZX->SetMarkerColor(kRed);
1009 h_HitsZX->Draw(
"P");
1012 h_HitsZY->SetMarkerStyle(8);
1013 h_HitsZY->SetMarkerSize(0.7);
1014 h_HitsZY->SetMarkerColor(kRed);
1015 h_HitsZY->Draw(
"P");
1017 for (Int_t iTr = 0; iTr < fGlobTracksArray->GetEntriesFast(); ++iTr) {
1035 for (Int_t iHit = 1; iHit < silTr->
GetNHits(); iHit++) {
1037 Double_t x = hit->GetX();
1038 Double_t y = hit->GetY();
1039 Double_t z = hit->GetZ();
1040 TLine* lineZX =
new TLine(z, x, zPrev, xPrev);
1041 lineZX->SetLineColor(kRed);
1042 lineZX->SetLineWidth(2);
1043 TLine* lineZY =
new TLine(z, y, zPrev, yPrev);
1044 lineZY->SetLineColor(kRed);
1045 lineZY->SetLineWidth(2);
1047 lineZX->Draw(
"same");
1049 lineZY->Draw(
"same");
1062 for (Int_t iHit = 1; iHit < ssdTr->
GetNHits(); iHit++) {
1064 Double_t x = hit->GetX();
1065 Double_t y = hit->GetY();
1066 Double_t z = hit->GetZ();
1067 TLine* lineZX =
new TLine(z, x, zPrev, xPrev);
1068 lineZX->SetLineColor(kRed);
1069 lineZX->SetLineWidth(2);
1070 TLine* lineZY =
new TLine(z, y, zPrev, yPrev);
1071 lineZY->SetLineColor(kRed);
1072 lineZY->SetLineWidth(2);
1074 lineZX->Draw(
"same");
1076 lineZY->Draw(
"same");
1095 for (Int_t iHit = startIdx; iHit < gemTr->
GetNHits(); iHit++) {
1097 Double_t x = hit->GetX();
1098 Double_t y = hit->GetY();
1099 Double_t z = hit->GetZ();
1100 TLine* lineZX =
new TLine(z, x, zPrev, xPrev);
1101 lineZX->SetLineColor(kRed);
1102 lineZX->SetLineWidth(2);
1103 TLine* lineZY =
new TLine(z, y, zPrev, yPrev);
1104 lineZY->SetLineColor(kRed);
1105 lineZY->SetLineWidth(2);
1107 lineZX->Draw(
"same");
1109 lineZY->Draw(
"same");
1117 Int_t nMCtracks = 0;
1118 for (Int_t iTr = 0; iTr < fMCTracksArray->GetEntriesFast(); ++iTr) {
1121 vector<TLine*> vLineZX;
1122 vector<TLine*> vLineZY;
1126 Double_t x1, y1, z1;
1129 for (Int_t
i = 0;
i < fSilPointsArray->GetEntriesFast(); ++
i) {
1130 FairMCPoint* pnt = (FairMCPoint*)fSilPointsArray->At(
i);
1131 if (pnt->GetTrackID() == iTr) {
1137 vLineZX.push_back(
new TLine(
z0, x0, z1, x1));
1138 vLineZY.push_back(
new TLine(
z0, y0, z1, y1));
1161 if (fInnerTrackerSetup[
kGEM])
1162 for (Int_t
i = 0;
i < fGemPointsArray->GetEntriesFast(); ++
i) {
1163 FairMCPoint* pnt = (FairMCPoint*)fGemPointsArray->At(
i);
1164 if (pnt->GetTrackID() == iTr) {
1170 vLineZX.push_back(
new TLine(
z0, x0, z1, x1));
1171 vLineZY.push_back(
new TLine(
z0, y0, z1, y1));
1177 if (nPoints > 3 && vSt.size() > 3) {
1180 for (TLine* it : vLineZX) {
1181 it->SetLineColor(kBlue);
1182 it->SetLineStyle(9);
1186 for (TLine* it : vLineZY) {
1187 it->SetLineColor(kBlue);
1188 it->SetLineStyle(9);
1194 printf(
"NMCTracks = %d GlobTracks = %d\n", nMCtracks, fGlobTracksArray->GetEntriesFast());
1197 c->SaveAs(
"hits.png");
TVector3 LineFit(BmnTrack *track, const TClonesArray *arr, TString type)
TVector3 CircleBy3Hit(BmnTrack *track, const TClonesArray *arr)
Double_t Mu(vector< Double_t > qp, vector< Double_t > w)
TVector3 CircleFit(BmnTrack *track, const TClonesArray *arr, Double_t &chi2)
Double_t CalcTx(const BmnHit *h0, const BmnHit *h1, const BmnHit *h2)
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
Bool_t IsParCorrect(const FairTrackParam *par, const Bool_t isField)
Double_t Sigma(vector< Double_t > dist, vector< Double_t > w)
vector< Double_t > W(vector< Double_t > dist, Double_t sig)
const Float_t d
Z-ccordinate of the first GEM-station.
virtual void Exec(Option_t *opt)
virtual ~BmnCellAutoTracking()
virtual InitStatus Init()
void SetLastIdx(Int_t idx)
void SetSlopeXZ(Double_t s)
void SetOldState(Short_t st)
void SetFirstIdx(Int_t idx)
void SetStartPlane(Short_t p)
void SetNewState(Short_t st)
void SetSlopeYZ(Double_t s)
Int_t GetPointStationOwnership(Double_t zcoord)
void SetSilTrackIndex(Int_t iSil)
void SetGemTrackIndex(Int_t iGem)
Int_t GetSsdTrackIndex() const
void SetSsdTrackIndex(Int_t iSsd)
Int_t GetGemTrackIndex() const
Int_t GetSilTrackIndex() const
DetectorId GetDetId() const
void SetUsing(Bool_t use)
void SetDetId(DetectorId det)
void SetStation(Short_t st)
Short_t GetStation() const
BmnStatus TGeoTrackPropagate(FairTrackParam *par, Double_t zOut, Int_t pdg, vector< Double_t > *F, Double_t *length, Bool_t isField)
BmnStatus Update(FairTrackParam *par, const BmnHit *hit, Double_t &chiSq)
Int_t GetPointStationOwnership(Double_t zcoord)
Double_t * GetCellSlopeYZCutMin()
Double_t * GetCellSlopeXZCutMax()
Double_t * GetCellSlopeYZCutMax()
Double_t * GetHitXCutMax()
Double_t * GetHitYCutMin()
Double_t GetDiffSlopeYZ0()
Double_t GetDiffSlopeXZSlope()
Double_t GetDiffSlopeYZSlope()
Double_t GetDiffSlopeXZ0()
Double_t * GetHitYCutMax()
Double_t * GetCellSlopeXZCutMin()
Double_t * GetHitXCutMin()
Double_t GetChiSquareCut()
void SetChi2(Double_t chi2)
void SetParamLast(FairTrackParam &par)
FairTrackParam * GetParamFirst()
Int_t GetHitIndex(Int_t iHit) const
void AddHit(Int_t hitIndex, FairHit *Hit)
void SetParamFirst(FairTrackParam &par)
FairTrackParam * GetParamLast()
void SetLength(Double_t length)
Double_t GetStartZ() const
Double_t GetStartY() const
Double_t GetStartX() const