2 #include "TClonesArray.h"
3 #include "TDirectory.h"
4 #include "TGeoManager.h"
9 #include <TGraph2DErrors.h>
16 #include "FairEventManager.h"
17 #include "FairLogger.h"
18 #include "FairRootManager.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 #include "TEveManager.h"
33 #include "CbmTofHit.h"
58 , fMaxTofTimeDifference(0.)
79 , fMaxTofTimeDifference(0.)
109 FairRunAna* ana = FairRunAna::Instance();
110 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
114 <<
"CbmTofTrackFinderNN::Init => Could not obtain the CbmTofDigiPar ";
117 LOG(info) << Form(
" CbmTofTrackFinderNN::Init : Fitter at 0x%p",
fFitter);
122 " CbmTofTrackFinderNN::Init : no FindTracks instance found");
140 const TVector3 hitPos(0., 0., 0.);
141 const TVector3 hitPosErr(0.5, 0.5, 0.5);
142 const Double_t dTime0 = 0.;
144 Int_t iNbHits =
fHits->GetEntries();
154 <<
"CbmTofTrackFinderNN::DoFind: Fake Hit at origin added at position "
155 << iNbHits << Form(
", DetId 0x%08x", iDetId);
160 LOG(debug2) <<
"<I> TrkMap/Vec resized for " <<
fHits->GetEntries()
163 for (Int_t iHit = 0; iHit <
fHits->GetEntries(); iHit++) {
180 for (Int_t iHit = 0; iHit <
fHits->GetEntries();
188 "<I> TofTracklet Chkseed St0 %2d, St1 %2d, Mul %2d, Hit %2d, addr = "
189 "0x%08x - X %6.2f, Y %6.2f Z %6.2f R %6.2f T %6.2f TM %lu",
205 "<I> TofTracklet seed St0 %2d, St1 %2d, Mul %2d, Hit %2d, addr = "
206 "0x%08x - X %6.2f, Y %6.2f Z %6.2f T %6.2f TM %lu",
221 Double_t hitpos[3] = {3 * 0.};
222 Double_t hitpos_local[3] = {3 * 0.};
223 Double_t dSizey = 1.;
226 if (NULL == fChannelInfo) {
227 LOG(fatal) <<
"<D> CbmTofTrackFinderNN::DoFind0: Invalid Channel "
229 << Form(
" 0x%08x ", iChId) <<
", Ch " << iCh;
233 gGeoManager->FindNode(fChannelInfo->
GetX(),
234 fChannelInfo->
GetY(),
235 fChannelInfo->
GetZ());
238 hitpos[0] = pHit->
GetX();
239 hitpos[1] = pHit->
GetY();
240 hitpos[2] = pHit->
GetZ();
241 gGeoManager->GetCurrentNode();
242 gGeoManager->MasterToLocal(hitpos, hitpos_local);
246 "<D> TofTracklet start %d, Hit %d - yloc %6.2f, dy %6.2f, Scal "
247 "%6.2f -> stations 0x%08x, 0x%08x,",
258 if (TMath::Abs(hitpos_local[1]) < dSizey *
fPosYMaxScal)
259 for (Int_t iHit1 = 0; iHit1 <
fHits->GetEntries();
262 if (
HitUsed(iHit1) == 1)
continue;
273 Double_t hitpos1[3] = {3 * 0.};
274 Double_t hitpos1_local[3] = {3 * 0.};
275 Double_t dSizey1 = 1.;
276 if (NULL == fChannelInfo1) {
277 LOG(debug) <<
"CbmTofTrackFinderNN::DoFindi: Invalid Channel "
279 << Form(
" 0x%08x ", iChId1) <<
", Ch " << iCh1;
283 gGeoManager->FindNode(fChannelInfo1->
GetX(),
284 fChannelInfo1->
GetY(),
285 fChannelInfo1->
GetZ());
286 hitpos1[0] = pHit1->
GetX();
287 hitpos1[1] = pHit1->
GetY();
288 hitpos1[2] = pHit1->
GetZ();
289 gGeoManager->GetCurrentNode();
290 gGeoManager->MasterToLocal(hitpos1, hitpos1_local);
291 dSizey1 = fChannelInfo1->
GetSizey();
296 Double_t dLz = pHit1->
GetZ() - pHit->
GetZ();
297 Double_t dTx = (pHit1->
GetX() - pHit->
GetX()) / dLz;
298 Double_t dTy = (pHit1->
GetY() - pHit->
GetY()) / dLz;
299 Double_t dDist = TMath::Sqrt(
300 TMath::Power((pHit->
GetX() - pHit1->
GetX()), 2)
301 + TMath::Power((pHit->
GetY() - pHit1->
GetY()), 2)
302 + TMath::Power((pHit->
GetZ() - pHit1->
GetZ()), 2));
304 "<I> TofTracklet %d, Hits %d, %d, add = 0x%08x,0x%08x - DT "
305 "%6.2f, Tx %6.2f Ty %6.2f Tt %6.2f pos %6.2f %6.2f %6.2f ",
319 << Form(
" selection: y %6.2f < %6.2f, T %6.2f < %6.2f, "
320 "dTpos %6.2f < %6.2f, Abs(%6.2f - %6.2f) < %6.2f",
331 if (TMath::Abs(hitpos1_local[1]) < dSizey1 *
fPosYMaxScal)
333 && TMath::Abs(dDT / dDist)
342 iHit1, iAddr1, pHit1);
351 Double_t dR = pTrk->
Dist3D(pHit1, pHit);
356 Double_t T0Fake = pHit->
GetTime();
359 (T0Fake * (w - 1.) + (pHit1->
GetTime() - dTt * dR)) / w;
361 "<I> TofTracklet %d, Fake T0, old %8.0f -> new %8.0f",
368 if (pHit1->
GetZ() < pHit->
GetZ()) dSign = -1.;
369 dTt = dSign * dDT / dR;
381 << Form(
"<I> TofTracklet %d, Hits %d, %d initialized, "
382 "add 0x%08x,0x%08x, DT %6.3f, Sgn %2.0f, DR "
383 "%6.3f, T0 %6.2f, Tt %6.4f ",
402 if (iNTrks >= 0 &&
static_cast<size_t>(iNTrks) ==
fTracks.size())
406 "after seeds of St0 %d, St1 %d, Mul %d", iSt0, iSt1, iNTrks));
408 const Int_t MAXNCAND =
413 Int_t iHitInd[MAXNCAND];
415 Double_t dChi2[MAXNCAND];
416 for (
size_t iTrk = 0; iTrk <
fTracks.size();
419 LOG(debug3) <<
" Propagate Loop " << iTrk <<
" pTrk " << pTrk
420 << Form(
" to station %d, addr: 0x%08x ",
423 if (NULL == pTrk)
continue;
425 for (Int_t iHit = 0; iHit <
fHits->GetEntries();
427 if (
HitUsed(iHit) == 1)
continue;
436 Double_t hitpos[3] = {3 * 0.};
437 Double_t hitpos_local[3] = {3 * 0.};
438 Double_t dSizey = 1.;
440 if (NULL == fChannelInfo) {
441 LOG(debug) <<
"CbmTofTrackFinderNN::DoFind: Invalid Channel "
443 << iHit <<
" for ChId " << Form(
" 0x%08x ", iChId)
448 gGeoManager->FindNode(fChannelInfo->
GetX(),
449 fChannelInfo->
GetY(),
450 fChannelInfo->
GetZ());
451 hitpos[0] = pHit->
GetX();
452 hitpos[1] = pHit->
GetY();
453 hitpos[2] = pHit->
GetZ();
454 gGeoManager->GetCurrentNode();
455 gGeoManager->MasterToLocal(hitpos, hitpos_local);
458 if (TMath::Abs(hitpos_local[1])
468 if (iHit0 < 0 || iHit0 >=
fHits->GetEntries())
469 LOG(fatal) <<
"CbmTofTrackFinderNN::DoFind Invalid Hit Index "
470 << iHit0 <<
" for Track " << iTrk <<
"("
472 Double_t dDz = pHit->
GetZ() - tPar->
GetZ();
475 + tPar->
GetTx() * dDz;
478 + tPar->
GetTy() * dDz;
483 Double_t dTex = pTrk->
GetTex(pHit);
487 TMath::Sqrt((TMath::Power(TMath::Abs(dTex - pHit->
GetTime())
490 + TMath::Power(TMath::Abs(dXex - pHit->
GetX())
493 + TMath::Power(TMath::Abs(dYex - pHit->
GetY())
499 "<IP> TofTracklet %lu, HMul %d, Hits %d, %d check %d, Station "
500 "0x%08x: DT %f, DX %f, DY %f, Chi %f",
516 LOG(debug) << Form(
"<IP> TofTracklet %lu, HMul %d, Hits %d, %d "
517 "mark for extension by %d, add = 0x%08x, DT "
518 "%6.2f, DX %6.2f, DY=%6.2f ",
531 LOG(debug) << Form(
"CbmTofTrackFinderNN::DoFind new match %d "
532 "of Hit %d, Trk %lu, chi2 = %f",
538 if (iNCand == MAXNCAND) iNCand--;
540 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
541 if (dChi < dChi2[iCand]) {
542 for (Int_t iCC = iNCand; iCC > iCand; iCC--) {
543 pTrkInd[iCC] = pTrkInd[iCC - 1];
544 iHitInd[iCC] = iHitInd[iCC - 1];
545 dChi2[iCC] = dChi2[iCC - 1];
547 pTrkInd[iCand] = pTrk;
548 iHitInd[iCand] = iHit;
550 dChi2[iNCand] = 1.E8;
552 << Form(
" <D> candidate inserted at pos %d", iCand);
557 LOG(debug) << Form(
"CbmTofTrackFinderNN::DoFind first match "
558 "%d of Hit %d, Trk %p, chi2 = %f",
563 pTrkInd[iNCand] = pTrk;
564 iHitInd[iNCand] = iHit;
565 dChi2[iNCand] = dChi;
567 dChi2[iNCand] = 1.E8;
577 if (NULL == pTrk)
continue;
579 "%d hit match candidates in station %d to %lu TofTracklets",
583 for (Int_t iM = 0; iM < iNCand; iM++) {
585 if (NULL == pTrk)
break;
586 std::vector<CbmTofTracklet*>::iterator it =
588 if (it ==
fTracks.end())
break;
591 << Form(
"Hit %d, Trk %p with chi2 %f (%f)",
603 for (; iTr <
fTracks.size(); iTr++) {
605 LOG(debug) <<
"Track " << pTrk <<
" active at pos " << iTr;
611 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
612 pTrkInd[iCand] = pTrkInd[iCand + 1];
613 iHitInd[iCand] = iHitInd[iCand + 1];
614 dChi2[iCand] = dChi2[iCand + 1];
624 LOG(fatal) <<
" No or more Tracklet hits than stations ! Stop ";
626 Int_t iHit = iHitInd[0];
629 if (Double_t dLastChi2 =
632 " -D- Add hit %d at %p, Addr 0x%08x, Chi2 %6.2f to size %u",
646 Bool_t bkeep = kFALSE;
648 LOG(debug) << Form(
"Add hit %d invalidates tracklet with Chi "
649 "%6.2f > %6.2f -> undo ",
661 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
662 pTrkInd[iCand] = pTrkInd[iCand + 1];
663 iHitInd[iCand] = iHitInd[iCand + 1];
664 dChi2[iCand] = dChi2[iCand + 1];
670 for (Int_t iCand = 0; iCand < iNCand; iCand++) {
671 if (pTrk != pTrkInd[iCand] && iHit != iHitInd[iCand]) {
672 pTrkInd[iNCandNew] = pTrkInd[iCand];
673 iHitInd[iNCandNew] = iHitInd[iCand];
674 dChi2[iNCandNew] = dChi2[iCand];
681 if (dChi2[0] < dLastChi2) {
683 "-D- Replace %d, Addr 0x%08x, at %p, Chi2 %6.2f",
693 " -D- Ignore %d, Det %d, Addr 0x%08x, at 0x%p, Chi2 %6.2f",
726 Double_t dTt = pTrk->
GetTt();
728 LOG(debug) << Form(
"<Res> TofTracklet %p, HMul %d, Hits %d, %d, %d, "
729 "NDF %d, Chi2 %6.2f, T0 %6.2f, Tt %6.4f ",
740 LOG(debug1) <<
" Match loop status: NCand " << iNCand <<
", iDet "
773 for (
size_t iTr = 0; iTr <
fTracks.size(); iTr++) {
774 if (
fTracks[iTr] == NULL)
continue;
775 if (
fTracks[iTr]->GetNofHits() < 3)
782 if (gLogger->IsLogNeeded(fair::Severity::debug)) {
783 LOG(info) <<
"Found Trkl " << iTr <<
", ";
786 for (Int_t iHit = 0; iHit < pTrk->
GetNofHits(); iHit++) {
789 LOG(debug) << Form(
" hit %d at %d flagged to %d ",
797 for (
size_t iTr = 0; iTr <
fTracks.size(); iTr++) {
798 if (
fTracks[iTr] == NULL)
continue;
801 LOG(debug) << Form(
"<I> TofTracklet %lu, %p deleted", iTr,
fTracks[iTr]);
816 for (Int_t iDet1 = 0; iDet1 < iDet; iDet1++) {
817 for (Int_t iHit1 = 0; iHit1 <
fHits->GetEntries();
822 if (iAddr1 == iAddr)
continue;
830 Double_t hitpos1[3] = {3 * 0.};
831 Double_t hitpos1_local[3] = {3 * 0.};
832 Double_t dSizey1 = 1.;
834 if (NULL == fChannelInfo1) {
836 <<
"CbmTofTrackFinderNN::DoFindp: Invalid Channel Pointer for ChId "
837 << Form(
" 0x%08x ", iChId1) <<
", Ch " << iCh1;
841 gGeoManager->FindNode(fChannelInfo1->
GetX(),
842 fChannelInfo1->
GetY(),
843 fChannelInfo1->
GetZ());
844 hitpos1[0] = pHit1->
GetX();
845 hitpos1[1] = pHit1->
GetY();
846 hitpos1[2] = pHit1->
GetZ();
847 gGeoManager->GetCurrentNode();
848 gGeoManager->MasterToLocal(hitpos1, hitpos1_local);
849 dSizey1 = fChannelInfo1->
GetSizey();
852 Double_t dLz = pHit->
GetZ() - pHit1->
GetZ();
853 Double_t dTx = (pHit->
GetX() - pHit1->
GetX()) / dLz;
854 Double_t dTy = (pHit->
GetY() - pHit1->
GetY()) / dLz;
857 "<ISeed> TofTracklet %d, Hits %d, %d, used %d check, add = "
858 "0x%08x,0x%08x - DT %6.2f, Tx %6.2f Ty %6.2f ",
868 if (TMath::Abs(hitpos1_local[1]) < dSizey1 *
fPosYMaxScal)
888 Double_t dR = pHit->
GetR() - pHit1->
GetR();
889 Double_t dTt = 1. / 30.;
902 LOG(debug) << Form(
"<DSeed> TofTracklet %d, Hits %d, %d add "
903 "initialized, add = 0x%08x,0x%08x ",
923 LOG(DEBUG4) <<
"CbmTofTrackFinderNN::HitUsed of Hind " << iHit
924 <<
", TrkVec.size " <<
fvTrkVec[iHit].size();
931 if (
fvTrkVec[iHit][0]->GetNofHits() > 2) iUsed = 1;
942 for (Int_t iHit = 0; iHit < pTrk->
GetNofHits();
956 LOG(fatal) <<
"UpdateTrackList NTrks=0 for event "
958 <<
", iHit " << iHit;
962 while (iterClean > 0) {
963 LOG(debug2) <<
" <D1> UpdateTrackList for Trk " << pTrk
965 ", %d.Hit(%d) at ind %d with %d(%d) registered tracks",
972 for (std::vector<CbmTofTracklet*>::iterator iT =
978 LOG(debug2) <<
" <D2> process Trk " << *iT <<
" with "
979 << (*iT)->GetNofHits() <<
" hits";
981 for (Int_t iH = 0; iH < (*iT)->GetNofHits(); iH++) {
983 Int_t iHi = (*iT)->GetTofHitIndex(iH);
984 LOG(debug2) <<
" <D3> process Hit " << iH <<
" at index " << iHi;
986 ((*iT)->GetTofHitPointer(iH)->GetAddress() &
DetMask);
988 <<
" --- iHitInd " << iHitInd <<
"(" <<
fvTrkVec.size()
989 <<
"), size " <<
fvTrkVec[iHitInd].size() <<
" - iH " << iH <<
"("
990 << (*iT)->GetNofHits() <<
"), iHi " << iHi <<
" Hi vec size "
992 << Form(
" poi %p, iTpoi %p, SmAddr 0x%08x, 0x%08x, 0x%08x ",
1000 LOG(debug2) <<
" Hit in beam counter, continue ...";
1004 LOG(fatal) <<
"CbmTofTrackFinderNN::UpdateTrackList no track "
1005 <<
" for hit " << iH <<
", Hind " << iHi <<
", size "
1009 for (std::vector<CbmTofTracklet*>::iterator it =
1014 <<
" UpdateTrackList for pTrk " << pTrk <<
" <-> " << *iT
1015 <<
" <-> " << *it <<
", clean " << iterClean <<
", hit "
1016 << iHi <<
", size " <<
fvTrkVec[iHi].size();
1020 for (iTr = 0; iTr <
fTracks.size(); iTr++) {
1022 LOG(debug2) << Form(
" found track entry %p(%d) at %lu "
1023 "of iHi %d, pTrk %p",
1034 LOG(fatal) <<
"CbmTofTrackFinderNN::UpdateTrackList: "
1035 "Invalid iTr for pTrk "
1036 << pTrk <<
", iTr " << iTr <<
", size "
1041 LOG(debug2) << Form(
"<D4> number of registered hits %3d at "
1042 "%p while keeping iHi = %d, pTrk at %p",
1043 (*it)->GetNofHits(),
1050 for (Int_t iht = 0; iht < pKill->
GetNofHits(); iht++) {
1052 LOG(debug2) << Form(
"<D5> remove track link %p for hit iHi "
1053 "= %d, loop index %d: iHI = %3d ",
1059 for (std::vector<CbmTofTracklet*>::iterator itt =
1063 if ((*itt) == pTrk)
continue;
1064 if ((*itt) == pKill) {
1065 LOG(debug2) << Form(
"<D6> remove track link %p for hit "
1066 "iHi = %d, iHI = %3d, #Trks %3d",
1073 <<
"<D6a> clear vector fvTrkVec for " << iHI;
1079 LOG(debug2) <<
"<D6b> reduce fvTrkVec size of " << iHI
1085 LOG(debug2) << Form(
"<D7> removed track link %p for hit "
1086 "iHi = %d, loop %d: iHI = %3d ",
1095 LOG(debug2) <<
"<D8> remove tracklet at pos " << iTr;
1100 <<
"Erase1 for pTrk " << pTrk <<
", at " << iTr <<
", hit "
1101 << iHi <<
", size " <<
fvTrkVec[iHi].size();
1125 if (
fvTrkVec[iHi].size() < 2)
break;
1139 "<PS %s> for fiNtrks = %d tracks out of %d fTracks.size() ",
1144 for (
size_t it = 0; it <
fTracks.size(); it++) {
1146 if (NULL == pTrk)
continue;
1147 if (pTrk->
GetNofHits() < 2) { LOG(fatal) <<
"Invalid track found"; }
1150 sTrk += Form(
" Track %lu at %p, Hits: ", it, pTrk);
1151 for (Int_t ih = 0; ih < pTrk->
GetNofHits(); ih++) {
1154 sTrk += Form(
", ChiSq %7.1f", pTrk->
GetChiSq());
1155 sTrk += Form(
", Tt %6.4f", pTrk->
GetTt());
1159 for (
size_t ih = 0; ih <
fvTrkVec.size(); ih++) {
1164 sTrk += Form(
" Hit %lu, A 0x%08x, St %d, T %6.2f, Tracks(%d): ",
1170 if (iSt < fFindTracks->GetNStations()) {
1171 for (
size_t it = 0; it <
fvTrkVec[ih].size(); it++) {
1173 sTrk += Form(
" %p ", pTrk);
1181 for (
size_t it = 0; it <
fTracks.size(); it++) {
1183 if (NULL == pTrk)
continue;
1184 if (pCheck == pTrk)
return kTRUE;
1190 TGraph2DErrors*
gr =
new TGraph2DErrors();
1194 for (Int_t N = 0; N < pTrk->
GetNofHits(); N++) {
1199 gr->SetPoint(N,
x,
y, z);
1200 double dx, dy, dz = 0.;
1204 gr->SetPointError(N, dx, dy, dz);
1205 LOG(debug) <<
"Line3Dfit add N = " << N <<
",\t" << pTrk->
GetTofHitIndex(N)
1206 <<
",\t" <<
x <<
",\t" <<
y <<
",\t" << z <<
",\t" << dx <<
",\t"
1207 << dy <<
",\t" << dz;
1210 Double_t pStart[4] = {0., 0., 0., 0.};
1211 pStart[0] = pTrk->
GetFitX(0.);
1213 pStart[2] = pTrk->
GetFitY(0.);
1215 LOG(debug) <<
"Line3Dfit init: X0 " << pStart[0] <<
", TX " << pStart[1]
1216 <<
", Y0 " << pStart[2] <<
", TY " << pStart[3];
1223 LOG(debug) <<
"Line3Dfit result: " << gMinuit->fCstatu <<
" : X0 " << dRes[0]
1224 <<
", TX " << dRes[1] <<
", Y0 " << dRes[2] <<
", TY " << dRes[3]