1 /** \class AliHLTTPCCATracker
3 //_____________________________________________________________
8 // Copyright © ALICE HLT Group
17 #include "AliHLTTPCRootTypes.h"
18 #include "AliHLTTPCSpacePointData.h"
19 #include "AliHLTTPCLogging.h"
20 #include "AliHLTTPCVertex.h"
21 #include "AliHLTTPCConfMapTrack.h"
22 #include "AliHLTTPCConfMapPoint.h"
23 #include "AliHLTTPCTrackArray.h"
24 #include "AliHLTTPCTransform.h"
25 #include "AliHLTTPCCATracker.h"
26 #include "AliHLTTPCTrackSegmentData.h"
28 #include "TApplication.h"
33 #include "TPaveText.h"
44 static TList *listHisto;
45 static TH1F *h_NClusters;
46 static TH2F *h_ClustersXY[10];
54 static TApplication *myapp;
55 static TCanvas *YX, *ZX;
57 static bool ask = false;
61 ClassImp(AliHLTTPCCATracker)
63 // ----------------------------------------------------------------------------------
64 AliHLTTPCCATracker::AliHLTTPCCATracker()
72 fBench = (Bool_t)true;
73 fVertexConstraint = (Bool_t)true;
82 // ----------------------------------------------------------------------------------
83 AliHLTTPCCATracker::~AliHLTTPCCATracker()
106 // ----------------------------------------------------------------------------------
107 void AliHLTTPCCATracker::CACreateHistos()
111 static bool first_call = true;
117 TDirectory *curdir = gDirectory;
118 TDirectory *histodir = gROOT->mkdir("histodir");
121 h_NClusters = new TH1F("h_NClusters", "Number of clusters in event", 100, 0.0, 1000.0);
123 h_ClustersXY[0] = new TH2F("h_ClustersXY_0", "Clusters in XY plane Ev 0", 100, 50.0, 300.0, 100, -100.0, 100.0);
124 h_ClustersXY[1] = new TH2F("h_ClustersXY_1", "Clusters in XY plane Ev 1", 100, 50.0, 300.0, 100, -100.0, 100.0);
125 h_ClustersXY[2] = new TH2F("h_ClustersXY_2", "Clusters in XY plane Ev 2", 100, 50.0, 300.0, 100, -100.0, 100.0);
126 h_ClustersXY[3] = new TH2F("h_ClustersXY_3", "Clusters in XY plane Ev 3", 100, 50.0, 300.0, 100, -100.0, 100.0);
127 h_ClustersXY[4] = new TH2F("h_ClustersXY_4", "Clusters in XY plane Ev 4", 100, 50.0, 300.0, 100, -100.0, 100.0);
128 h_ClustersXY[5] = new TH2F("h_ClustersXY_5", "Clusters in XY plane Ev 5", 100, 50.0, 300.0, 100, -100.0, 100.0);
129 h_ClustersXY[6] = new TH2F("h_ClustersXY_6", "Clusters in XY plane Ev 6", 100, 50.0, 300.0, 100, -100.0, 100.0);
130 h_ClustersXY[7] = new TH2F("h_ClustersXY_7", "Clusters in XY plane Ev 7", 100, 50.0, 300.0, 100, -100.0, 100.0);
131 h_ClustersXY[8] = new TH2F("h_ClustersXY_8", "Clusters in XY plane Ev 8", 100, 50.0, 300.0, 100, -100.0, 100.0);
132 h_ClustersXY[9] = new TH2F("h_ClustersXY_9", "Clusters in XY plane Ev 9", 100, 50.0, 300.0, 100, -100.0, 100.0);
134 listHisto = gDirectory->GetList();
139 myapp = new TApplication("myapp", 0, 0);
141 gStyle->SetCanvasBorderMode(0);
142 gStyle->SetCanvasBorderSize(1);
143 gStyle->SetCanvasColor(0);
146 YX = new TCanvas ("YX", "YX (Pad-Row) window", -10, 0, 680, 400);
147 YX->Range(-50.0, 80.0, 50.0, 250.0);
151 ZX = new TCanvas ("ZX", "ZX window", -700, 0, 680, 400);
152 ZX->Range(-250.0, 80.0, 250.0, 250.0);
160 std::cin.get(symbol);
163 } while (symbol != '\n');
172 // ----------------------------------------------------------------------------------
173 void AliHLTTPCCATracker::CAWriteHistos()
175 // IK Open the output file and write histogramms
177 TFile *outfile = new TFile("ConfMapper_histo.root", "RECREATE");
178 TIter hiter(listHisto);
179 while (TObject *obj = hiter()) obj->Write();
183 // ----------------------------------------------------------------------------------
184 Bool_t AliHLTTPCCATracker::ReadHits(UInt_t count, AliHLTTPCSpacePointData* hits )
188 Int_t nhit=(Int_t)count;
190 vector<CAHit> vec_hits;
193 for (Int_t i=0;i<nhit;i++)
195 fHit[i+fClustersUnused].Reset();
196 fHit[i+fClustersUnused].ReadHits(&(hits[i]));
199 fClustersUnused += nhit;
204 // ----------------------------------------------------------------------------------
205 void AliHLTTPCCATracker::CAInitialize()
208 vec_patch_tracks.clear();
209 vec_slice_tracks.clear();
214 // ----------------------------------------------------------------------------------
215 void AliHLTTPCCATracker::CAReadPatchHits(Int_t patch, UInt_t count, AliHLTTPCSpacePointData* hits )
218 Int_t nhit=(Int_t)count;
220 patch_first_hit_ind = vec_hits.size();
221 patch_last_hit_ind = patch_first_hit_ind + nhit - 1;
223 for (Int_t i=0;i<nhit;i++)
225 AliHLTTPCSpacePointData* pSP = &(hits[i]);
232 hit.errx = 1.0;//pSP->fSigmaY2;
234 hit.erry = 10.0;//1.0;//pSP->fSigmaY2;
236 hit.erry = 10.0;//pSP->fSigmaY2;
237 hit.errz = 1.0;//pSP->fSigmaZ2;
242 vec_hits.push_back(hit);
247 TMarker *mhit = new TMarker(0.0, 0.0, 6);
248 mhit->SetMarkerColor(kBlue);
250 for (Int_t i = patch_first_hit_ind; i <= patch_last_hit_ind; i++)
253 mhit->DrawMarker(vec_hits[i].y, vec_hits[i].x);
256 mhit->DrawMarker(vec_hits[i].z, vec_hits[i].x);
261 YX->cd(); YX->Update(); YX->Draw();
262 ZX->cd(); ZX->Update(); ZX->Draw();
269 // ----------------------------------------------------------------------------------
270 void AliHLTTPCCATracker::CAFindPatchTracks(Int_t patch)
275 TLine *line = new TLine();
276 line->SetLineColor(kBlack);
280 Double_t dist01, dist12, dist02, mindist, chi2, minchi2;
281 CAHit *ph0, *ph1, *ph2, *phbest, *next;
283 Double_t x, y, z, ty, tz, cov_y, cov_ty, cov_yty, cov_z, cov_tz, cov_ztz, ye, ze, dx, dy, dz, sy2, sz2;
285 for (Int_t i1 = patch_first_hit_ind; i1 < patch_last_hit_ind; i1++) // <nhit-1
287 ph1 = &(vec_hits[i1]);
288 next = &(vec_hits[i1+1]);
294 if (ph1->counter != 0){ // the previous hit exists
299 dx = (ph1->x-ph0->x); // assume different x !!!
300 if (abs(dx) < 0.0001) dx = 0.0001;
301 ty = (ph1->y-ph0->y)/dx;
302 tz = (ph1->z-ph0->z)/dx;
304 cov_y = ph1->erry*ph1->erry;
305 cov_ty = (ph0->erry*ph0->erry + ph1->erry*ph1->erry)/(dx*dx);
306 cov_yty = (ph1->erry*ph1->erry)/dx;
308 cov_z = ph1->errz*ph1->errz;
309 cov_tz = (ph0->errz*ph0->errz + ph1->errz*ph1->errz)/(dx*dx);
310 cov_ztz = (ph1->errz*ph1->errz)/dx;
314 for (Int_t i2 = i1+1; i2 <= patch_last_hit_ind; i2++)
316 ph2 = &(vec_hits[i2]);
317 if (ph2->x < ph1->x) continue; // no backward direction!
319 dist12 = sqrt((ph1->x-ph2->x)*(ph1->x-ph2->x) + (ph1->y-ph2->y)*(ph1->y-ph2->y) + (ph1->z-ph2->z)*(ph1->z-ph2->z));
320 if (dist12 < mindist){
321 if (ph1->counter == 0){
326 // calculate chi2 distance between the hit and the line
327 dx = (ph2->x-x); // assume different x !!!
328 if (abs(dx) < 0.0001) dx = 0.0001;
333 sy2 = cov_y + 2.0*cov_yty*dx + cov_ty*dx*dx;
334 sz2 = cov_z + 2.0*cov_ztz*dx + cov_tz*dx*dx;
339 chi2 = (dy*dy)/(sy2+ph2->erry*ph2->erry) + (dz*dz)/(sz2+ph2->errz*ph2->errz);
341 // check the straight line model
351 if (phbest != NULL){// closest hit found
353 // exchange jbest with the next hit
354 Double_t x_tmp = next->x;
355 Double_t y_tmp = next->y;
356 Double_t z_tmp = next->z;
358 Double_t errx_tmp = next->errx;
359 Double_t erry_tmp = next->erry;
360 Double_t errz_tmp = next->errz;
362 Int_t index_tmp = next->index;
363 Int_t counter_tmp = next->counter;
369 next->errx = phbest->errx;
370 next->erry = phbest->erry;
371 next->errz = phbest->errz;
373 next->index = phbest->index;
374 next->counter = phbest->counter;
380 phbest->errx = errx_tmp;
381 phbest->erry = erry_tmp;
382 phbest->errz = errz_tmp;
384 phbest->index = index_tmp;
385 phbest->counter = counter_tmp;
387 if (ph1->counter == 0)
389 next->counter = ph1->counter+1;
397 line->DrawLine(ph1->y, ph1->x, next->y, next->x);
400 line->DrawLine(ph1->z, ph1->x, next->z, next->x);
412 YX->cd(); YX->Update(); YX->Draw();
413 ZX->cd(); ZX->Update(); ZX->Draw();
421 tr.vec_ihits.clear();
423 patch_first_track_ind = vec_patch_tracks.size();
424 patch_last_track_ind = patch_first_track_ind - 1;
429 for (Int_t ihr = patch_last_hit_ind; ihr >= patch_first_hit_ind; ihr--){
431 CAHit* phit = &(vec_hits[ihr]);
433 if ((phit->counter < 5)&&(tr.nhits == 0))
434 continue; // do not collect short tracks
436 if ((phit->counter != 0)&&(tr.nhits == 0))// store the first hit
439 if (phit->counter != 0){//add hit to the track
441 tr.vec_ihits.push_back(ihr);
443 if (tr.nhits == 2){ // calculate initial track parameters
444 CAHit* phit0 = &(vec_hits[tr.vec_ihits[0]]);
445 CAHit* phit1 = &(vec_hits[tr.vec_ihits[1]]);
451 Double_t dx = (phit1->x-phit0->x); // assume different x !!!
452 if (abs(dx) < 0.0001) dx = 0.0001;
453 tr.ty = (phit1->y-phit0->y)/dx;
454 tr.tz = (phit1->z-phit0->z)/dx;
456 tr.cov_y = phit1->erry*phit1->erry;
457 tr.cov_ty = (phit0->erry*phit0->erry + phit1->erry*phit1->erry)/(dx*dx);
458 tr.cov_yty = (phit1->erry*phit1->erry)/dx;
460 tr.cov_z = phit1->errz*phit1->errz;
461 tr.cov_tz = (phit0->errz*phit0->errz + phit1->errz*phit1->errz)/(dx*dx);
462 tr.cov_ztz = (phit1->errz*phit1->errz)/dx;
466 // propagate the track
467 Double_t dx = (phit->x-tr.x); // assume different x !!!
468 if (abs(dx) < 0.0001) dx = 0.0001;
470 Double_t ye = tr.y + tr.ty*dx;
471 Double_t ze = tr.z + tr.tz*dx;
473 Double_t cov_y = tr.cov_y + 2.0*tr.cov_yty*dx + tr.cov_ty*dx*dx;
474 Double_t cov_yty = tr.cov_yty + tr.cov_ty*dx;
475 Double_t cov_ty = tr.cov_ty;
477 Double_t cov_z = tr.cov_z + 2.0*tr.cov_ztz*dx + tr.cov_tz*dx*dx;
478 Double_t cov_ztz = tr.cov_ztz + tr.cov_tz*dx;
479 Double_t cov_tz = tr.cov_tz;
482 Double_t dy = phit->y - ye;
483 Double_t dz = phit->z - ze;
485 // add the measurement
487 Double_t w = 1.0/(phit->erry*phit->erry + cov_y);
489 tr.y = ye + cov_y*dy*w;
490 tr.ty = tr.ty + cov_yty*dy*w;
492 tr.cov_y = cov_y - cov_y*cov_y*w;
493 tr.cov_yty = cov_yty - cov_y*cov_yty*w;
494 tr.cov_ty = cov_ty -cov_yty*cov_yty*w;
499 w = 1.0/(phit->errz*phit->errz + cov_z);
501 tr.z = ze + cov_z*dz*w;
502 tr.tz = tr.tz + cov_ztz*dz*w;
504 tr.cov_z = cov_z - cov_z*cov_z*w;
505 tr.cov_ztz = cov_ztz - cov_z*cov_ztz*w;
506 tr.cov_tz = cov_tz -cov_ztz*cov_ztz*w;
514 if (phit->counter == 1){// store the track
521 Double_t trdist = sqrt((my_phf->x-phit->x)*(my_phf->x-phit->x)+
522 (my_phf->y-phit->y)*(my_phf->y-phit->y)+
523 (my_phf->z-phit->z)*(my_phf->z-phit->z));
525 if ((trdist > 1.0)&&(tr.chi2/tr.ndf < 10.0)){
526 vec_patch_tracks.push_back(tr);
527 patch_last_track_ind++;
534 tr.vec_ihits.clear();
538 // sort tracks according (currently) to number of hits
539 //sort(vec_patch_tracks.begin(), vec_patch_tracks.end(), compareNhits); //don't need to sort here
544 TLine *trline = new TLine();
545 trline->SetLineColor(kGreen);
547 for (Int_t itr = patch_first_track_ind; itr <= patch_last_track_ind; itr++){
549 CATrack *ptr = &(vec_patch_tracks[itr]);
551 CAHit* phitf = &(vec_hits[ptr->vec_ihits.back()]);
552 CAHit* phitl = &(vec_hits[ptr->vec_ihits.front()]);
555 Double_t yf = ptr->y + ptr->ty*(phitf->x-ptr->x);
556 Double_t yl = ptr->y + ptr->ty*(phitl->x-ptr->x);
557 trline->DrawLine(yf, phitf->x, yl, phitl->x);
560 Double_t zf = ptr->z + ptr->tz*(phitf->x-ptr->x);
561 Double_t zl = ptr->z + ptr->tz*(phitl->x-ptr->x);
562 trline->DrawLine(zf, phitf->x, zl, phitl->x);
568 YX->cd(); YX->Update(); YX->Draw();
569 ZX->cd(); ZX->Update(); ZX->Draw();
576 // ----------------------------------------------------------------------------------
577 void AliHLTTPCCATracker::CAFindSliceTracks()
580 Int_t ntracks = vec_patch_tracks.size();
582 // merge patch tracks into slice tracks
583 // start with the longest tracks in the first patches
585 // sort tracks according (currently) to patch and within patch - number of hits
586 sort(vec_patch_tracks.begin(), vec_patch_tracks.end(), compareCATracks);
588 for (Int_t itr1 = 0; itr1 < ntracks-1; itr1++){
590 CATrack *ptr1 = &(vec_patch_tracks[itr1]);
592 Double_t maxdisty = 10.0;
593 Double_t maxdistz = 5.0;
595 Double_t mindist = 10.0;
599 for (Int_t itr2 = itr1+1; itr2 < ntracks; itr2++){
601 CATrack *ptr2 = &(vec_patch_tracks[itr2]);
603 if (ptr2->patch == ptr1->patch) continue; // the same patch - no prolongation
604 if (ptr2->patch > ptr1->patch+1) break; // sorted tracks - no prolongation skippeng over patches
606 if (ptr2->used == 1) continue; // already matched
608 CAHit* phitf2 = &(vec_hits[ptr2->vec_ihits.back()]);
609 CAHit* phitl2 = &(vec_hits[ptr2->vec_ihits.front()]);
611 // extrapolate tr1 to the both ends of tr2
613 Double_t dyf = ptr1->y + ptr1->ty*(phitf2->x-ptr1->x) - phitf2->y;
614 Double_t dyl = ptr1->y + ptr1->ty*(phitl2->x-ptr1->x) - phitl2->y;
616 Double_t dzf = ptr1->z + ptr1->tz*(phitf2->x-ptr1->x) - phitf2->z;
617 Double_t dzl = ptr1->z + ptr1->tz*(phitl2->x-ptr1->x) - phitl2->z;
619 // roughly similar tracks ?
620 if ((abs(dyf) > maxdisty)||(abs(dyl) > maxdisty)||(abs(dzf) > maxdistz)||(abs(dzl) > maxdistz)) continue;
622 // roughly parallel tracks ?
623 Double_t dist = sqrt((dyf-dyl)*(dyf-dyl)+(dzf-dzl)*(dzf-dzl));
624 if (dist > mindist) continue;
632 // found track prolongations?
634 CATrack *ptr2 = &(vec_patch_tracks[next]);
648 tr.vec_ihits.clear();
652 for (Int_t itr = 0; itr < ntracks; itr++){
654 CATrack *ptr = &(vec_patch_tracks[itr]);
655 if (ptr->used) continue; // start with a track not used in prolongations
663 ptr = &(vec_patch_tracks[ptr->next]);
666 for (Int_t ih = 0; ih < ptr->nhits; ih++){
667 tr.vec_ihits.push_back(ptr->vec_ihits[ih]);
670 }while(ptr->next != -1);
672 //sort hits according to increasing x
673 sort(tr.vec_ihits.begin(), tr.vec_ihits.end(), compareCAHitsX);
675 vec_slice_tracks.push_back(tr);
680 tr.vec_ihits.clear();
686 TLine *trline = new TLine();
687 trline->SetLineColor(kRed);
697 for (vector<CATrack>::iterator trIt = vec_slice_tracks.begin(); trIt != vec_slice_tracks.end(); trIt++){
699 CAHit* phit0 = &(vec_hits[trIt->vec_ihits[trIt->nhits-1]]);
700 CAHit* phit1 = &(vec_hits[trIt->vec_ihits[trIt->nhits-2]]);
706 Double_t dx = (phit1->x-phit0->x); // assume different x !!!
707 if (abs(dx) < 0.0001) dx = 0.0001;
708 trIt->ty = (phit1->y-phit0->y)/dx;
709 trIt->tz = (phit1->z-phit0->z)/dx;
711 trIt->cov_y = phit1->erry*phit1->erry;
712 trIt->cov_ty = (phit0->erry*phit0->erry + phit1->erry*phit1->erry)/(dx*dx);
713 trIt->cov_yty = (phit1->erry*phit1->erry)/dx;
715 trIt->cov_z = phit1->errz*phit1->errz;
716 trIt->cov_tz = (phit0->errz*phit0->errz + phit1->errz*phit1->errz)/(dx*dx);
717 trIt->cov_ztz = (phit1->errz*phit1->errz)/dx;
719 for (Int_t ih = trIt->nhits-3; ih >= 0; ih--){
721 CAHit* phit = &(vec_hits[trIt->vec_ihits[ih]]);
723 // propagate the track
724 Double_t dx = (phit->x-trIt->x); // assume different x !!!
725 if (abs(dx) < 0.0001) dx = 0.0001;
727 Double_t ye = trIt->y + trIt->ty*dx;
728 Double_t ze = trIt->z + trIt->tz*dx;
730 Double_t cov_y = trIt->cov_y + 2.0*trIt->cov_yty*dx + trIt->cov_ty*dx*dx;
731 Double_t cov_yty = trIt->cov_yty + trIt->cov_ty*dx;
732 Double_t cov_ty = trIt->cov_ty;
734 Double_t cov_z = trIt->cov_z + 2.0*trIt->cov_ztz*dx + trIt->cov_tz*dx*dx;
735 Double_t cov_ztz = trIt->cov_ztz + trIt->cov_tz*dx;
736 Double_t cov_tz = trIt->cov_tz;
738 Double_t dy = phit->y - ye;
739 Double_t dz = phit->z - ze;
741 // add the measurement
743 Double_t w = 1.0/(phit->erry*phit->erry + cov_y);
745 trIt->y = ye + cov_y*dy*w;
746 trIt->ty = trIt->ty + cov_yty*dy*w;
748 trIt->cov_y = cov_y - cov_y*cov_y*w;
749 trIt->cov_yty = cov_yty - cov_y*cov_yty*w;
750 trIt->cov_ty = cov_ty -cov_yty*cov_yty*w;
752 trIt->chi2 += dy*dy*w;
755 w = 1.0/(phit->errz*phit->errz + cov_z);
757 trIt->z = ze + cov_z*dz*w;
758 trIt->tz = trIt->tz + cov_ztz*dz*w;
760 trIt->cov_z = cov_z - cov_z*cov_z*w;
761 trIt->cov_ztz = cov_ztz - cov_z*cov_ztz*w;
762 trIt->cov_tz = cov_tz -cov_ztz*cov_ztz*w;
764 trIt->chi2 += dz*dz*w;
775 //if (trIt->chi2/trIt->ndf < 1.0)
779 // JMT 2006/11/13 Write Tracks to container
781 CAHit* firstHit = &(vec_hits[trIt->vec_ihits[0]]);
782 CAHit* lastHit = &(vec_hits[trIt->vec_ihits[trIt->nhits-1]]);
784 Float_t xFirst = (Float_t) firstHit->x;
785 Float_t yFirst = (Float_t) trIt->y + trIt->ty*(xFirst-trIt->x);
786 float_t zFirst = (Float_t) trIt->z + trIt->tz*(xFirst-trIt->x);
788 Float_t xLast = (Float_t) lastHit->x;
789 Float_t yLast = (Float_t) trIt->y + trIt->ty*(xLast-trIt->x);
790 Float_t zLast = (Float_t) trIt->z + trIt->tz*(xLast-trIt->x);
792 fOutputPtr->fX = xFirst;
793 fOutputPtr->fY = yFirst;
794 fOutputPtr->fZ = zFirst;
795 fOutputPtr->fPt = -9876.0;
796 fOutputPtr->fPterr = 1;
797 fOutputPtr->fLastX = xLast;
798 fOutputPtr->fLastY = yLast;
799 fOutputPtr->fLastZ = zLast;
800 fOutputPtr->fPsi = atan(trIt->ty);
801 fOutputPtr->fTgl = trIt->tz;
802 fOutputPtr->fPsierr = 1;
803 fOutputPtr->fTglerr = 1;
804 fOutputPtr->fCharge = 1;
805 fOutputPtr->fNPoints = 0;
807 Byte_t *tmpP = (Byte_t *)fOutputPtr;
809 tmpP += sizeof(AliHLTTPCTrackSegmentData); //+fOutputPtr->fNPoints*sizeof(UInt_t);
810 size += sizeof(AliHLTTPCTrackSegmentData); //+fOutputPtr->fNPoints*sizeof(UInt_t);
811 fOutputPtr = (AliHLTTPCTrackSegmentData*)tmpP;
816 CAHit* phitf = &(vec_hits[trIt->vec_ihits[0]]);
817 CAHit* phitl = &(vec_hits[trIt->vec_ihits[trIt->nhits-1]]);
819 Double_t xf = phitf->x;
820 Double_t yf = trIt->y + trIt->ty*(xf-trIt->x);
821 Double_t zf = trIt->z + trIt->tz*(xf-trIt->x);
823 Double_t xl = phitl->x;
824 Double_t yl = trIt->y + trIt->ty*(xl-trIt->x);
825 Double_t zl = trIt->z + trIt->tz*(xl-trIt->x);
828 trline->DrawLine(yf, xf, yl, xl);
831 trline->DrawLine(zf, xf, zl, xl);
838 fOutputNTracks = nTracks;
840 cout << "NTRACKS=" << nTracks << endl;
841 cout << "SIZEoF=" << sizeof(AliHLTTPCTrackSegmentData) << endl;
842 cout << "SIZE=" << fOutputSize << endl;
849 YX->cd(); YX->Update(); YX->Draw();
850 ZX->cd(); ZX->Update(); ZX->Draw();