2 // Original: AliHLTConfMapper.cxx,v 1.26 2005/06/14 10:55:21 cvetan Exp $
4 //**************************************************************************
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
8 //* Primary Authors: Anders Vestbo, maintained by
9 //* Matthias Richter <Matthias.Richter@ift.uib.no> *
10 //* for The ALICE HLT Project. *
12 //* Permission to use, copy, modify and distribute this software and its *
13 //* documentation strictly for non-commercial purposes is hereby granted *
14 //* without fee, provided that the above copyright notice appears in all *
15 //* copies and that both the copyright notice and this permission notice *
16 //* appear in the supporting documentation. The authors make no claims *
17 //* about the suitability of this software for any purpose. It is *
18 //* provided "as is" without express or implied warranty. *
19 //**************************************************************************
21 /** @file AliHLTTPCConfMapper.cxx
22 @author Anders Vestbo, Matthias Richter
23 @date Conformal mapping base class.
30 #include "AliHLTTPCRootTypes.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCLogging.h"
33 #include "AliHLTTPCVertex.h"
34 #include "AliHLTTPCConfMapTrack.h"
35 #include "AliHLTTPCConfMapPoint.h"
36 #include "AliHLTTPCTrackArray.h"
37 #include "AliHLTTPCTransform.h"
38 #include "AliHLTTPCConfMapper.h"
44 ClassImp(AliHLTTPCConfMapper)
46 AliHLTTPCConfMapper::AliHLTTPCConfMapper()
51 fVertexFinder(kFALSE),
54 fMaxDca(0.0), // no clue whether this is reasonable, but at least better than without initialization
60 fNumRowSegmentPlusOne(0),
61 fNumPhiSegmentPlusOne(0),
62 fNumEtaSegmentPlusOne(0),
63 fNumPhiEtaSegmentPlusOne(0),
65 fPhiHitsOutOfRange(0),
66 fEtaHitsOutOfRange(0),
73 fVertexConstraint(kTRUE),
86 AliHLTTPCConfMapper::~AliHLTTPCConfMapper()
97 void AliHLTTPCConfMapper::InitVolumes()
100 //Allocate volumes, set conformal coordinates and pointers.
102 //Should be done after setting the track parameters
104 fNumRowSegmentPlusOne = AliHLTTPCTransform::GetNRows();//NumRows[0]; //Maximum 32.
105 fNumPhiSegmentPlusOne = fNumPhiSegment+1;
106 fNumEtaSegmentPlusOne = fNumEtaSegment+1;
107 fNumPhiEtaSegmentPlusOne = fNumPhiSegmentPlusOne*fNumEtaSegmentPlusOne;
108 fBounds = fNumRowSegmentPlusOne * fNumPhiSegmentPlusOne * fNumEtaSegmentPlusOne;
112 fTrack = new AliHLTTPCTrackArray("AliHLTTPCConfMapTrack",10);
115 void AliHLTTPCConfMapper::Reset()
117 if(fVolume) delete [] fVolume;
119 if(fRow) delete [] fRow;
126 void AliHLTTPCConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
127 { //sector means slice here
128 //Initialize tracker for tracking in a given sector.
129 //Resets track and hit arrays.
130 //Here it is also possible to specify a subsector, by defining
131 //rowrange[0]=innermost row;
132 //rowrange[1]=outermostrow;
133 //Finally you can specify etaslices to save time (assuming a good seed from TRD...)
135 //Define tracking area:
138 fRowMin = rowrange[0];
139 fRowMax = rowrange[1];
141 else //complete sector
144 fRowMax = AliHLTTPCTransform::GetNRows() - 1;
148 fEtaMin = etarange[0];
149 fEtaMax = sector < 18 ? etarange[1] : -etarange[1];
154 fEtaMax = sector < 18 ? 0.9 : -0.9;
157 //Set the angles to sector 2:
158 fPhiMin = -10*AliHLTTPCTransform::ToRad();//fParam->GetAngle(sector) - 10/todeg;
159 fPhiMax = 10*AliHLTTPCTransform::ToRad();//fParam->GetAngle(sector) + 10/todeg;
162 fMainVertexTracks = 0;
164 fEtaHitsOutOfRange=0;
165 fPhiHitsOutOfRange=0;
167 fNumRowSegment = fRowMax - fRowMin; //number of rows to be considered by tracker
168 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::InitSector","B-field")
169 <<"Tracker initializing with a magnetic field of "<<AliHLTTPCTransform::GetBField()<<ENDLOG;
174 Bool_t AliHLTTPCConfMapper::ReadHits(UInt_t count, AliHLTTPCSpacePointData* hits )
177 if(fClusterCutZ == -1){
178 if (fHit.size()<fClustersUnused+count) fHit.resize(fClustersUnused+count);
179 assert(fHit.size()>=fClustersUnused+count);
180 for (Int_t i=0;(UInt_t)i<count;i++)
182 fHit[i+fClustersUnused].Reset();
183 fHit[i+fClustersUnused].Read(hits[i]);
185 fClustersUnused += count;
188 //Skipping clusters with high Z.
191 if (fHit.size()<fClustersUnused+count) fHit.resize(fClustersUnused+count);
192 assert(fHit.size()>=fClustersUnused+count);
193 for (Int_t i=0;(UInt_t)i<count;i++)
195 if(hits[i].fZ > fClusterCutZ || hits[i].fZ < -1*fClusterCutZ){
199 fHit[i+fClustersUnused-skipped].Reset();
200 fHit[i+fClustersUnused-skipped].Read(hits[i]);
202 fClustersUnused += count - skipped;
203 fHit.resize(fClustersUnused);
206 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::ReadHits","#hits")
207 <<AliHLTTPCLog::kDec<<"#hits: "<<count<<" total: "<<fClustersUnused<<ENDLOG;
212 void AliHLTTPCConfMapper::SetPointers()
214 //Check if there are not enough clusters to make a track in this sector
215 //Can happen in pp events.
217 if(fClustersUnused < fMinPoints[fVertexConstraint])
220 //Allocate detector volumes
222 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::InitVolumes","Memory")<<AliHLTTPCLog::kDec<<
223 "Allocating "<<fBounds*sizeof(AliHLTTPCConfMapContainer)<<" Bytes to fVolume"<<ENDLOG;
224 fVolume = new AliHLTTPCConfMapContainer[fBounds];
228 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::InitVolumes","Memory")<<AliHLTTPCLog::kDec<<
229 "Allocating "<<fNumRowSegmentPlusOne*sizeof(AliHLTTPCConfMapContainer)<<" Bytes to fRow"<<ENDLOG;
230 fRow = new AliHLTTPCConfMapContainer[fNumRowSegmentPlusOne];
233 memset(fVolume,0,fBounds*sizeof(AliHLTTPCConfMapContainer));
234 memset(fRow,0,fNumRowSegmentPlusOne*sizeof(AliHLTTPCConfMapContainer));
236 Float_t phiSlice = (fPhiMax-fPhiMin)/fNumPhiSegment;
237 Float_t etaSlice = (fEtaMax-fEtaMin)/fNumEtaSegment;
240 Int_t localcounter=0;
241 assert((int)fHit.size()>=fClustersUnused);
242 for(Int_t j=0; j<fClustersUnused; j++)
244 AliHLTTPCConfMapPoint *thisHit = &(fHit[j]);
246 thisHit->Setup(fVertex);
248 Int_t localrow = thisHit->GetPadRow();
250 if(localrow < fRowMin || localrow > fRowMax)
254 thisHit->SetPhiIndex((Int_t)((thisHit->GetPhi()-fPhiMin)/phiSlice +1));
256 if(thisHit->GetPhiIndex()<1 || thisHit->GetPhiIndex()>fNumPhiSegment)
258 //cout << "Phiindex: " << thisHit->phiIndex << " " << thisHit->GetPhi() << endl;
259 fPhiHitsOutOfRange++;
263 thisHit->SetEtaIndex((Int_t)((thisHit->GetEta()-fEtaMin)/etaSlice + 1));
264 if(thisHit->GetEtaIndex()<1 || thisHit->GetEtaIndex()>fNumEtaSegment)
266 //cout << "Etaindex: " << thisHit->etaIndex << " " << thisHit->GetEta() << endl;
267 fEtaHitsOutOfRange++;
272 volumeIndex = (localrow-fRowMin)*fNumPhiEtaSegmentPlusOne +
273 thisHit->GetPhiIndex()*fNumEtaSegmentPlusOne+thisHit->GetEtaIndex();
275 if(fVolume[volumeIndex].first == NULL)
276 fVolume[volumeIndex].first = (void *)thisHit;
278 ((AliHLTTPCConfMapPoint *)fVolume[volumeIndex].last)->SetNextVolumeHit(thisHit);
279 fVolume[volumeIndex].last = (void *)thisHit;
283 if(fRow[(localrow-fRowMin)].first == NULL)
284 fRow[(localrow-fRowMin)].first = (void *)thisHit;
286 ((AliHLTTPCConfMapPoint *)(fRow[(localrow-fRowMin)].last))->SetNextRowHit(thisHit);
287 fRow[(localrow-fRowMin)].last = (void *)thisHit;
290 //If a cluster has an Eta outside the Eta or Phi range set in the Tracker, it will go in to
291 //the if here. This has been seen for high Eta clusters most likely from signal from the gating grid.
292 //These clusters are read in, but not used in the Tracking.
293 #ifdef PACKAGE_STRING
294 if(fClustersUnused>0 && localcounter==0)
295 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::SetPointers","Parameters")
296 <<AliHLTTPCLog::kDec<<"No points passed to track finder, hits out of range: "
297 <<fEtaHitsOutOfRange+fPhiHitsOutOfRange<<ENDLOG;
299 Int_t hits_accepted=fClustersUnused-(fEtaHitsOutOfRange+fPhiHitsOutOfRange);
300 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::SetPointers","Setup")
301 <<"Setup finished, hits out of range: "<<fEtaHitsOutOfRange+fPhiHitsOutOfRange
302 <<" hits accepted "<<hits_accepted<<ENDLOG;
303 #endif //PACKAGE_STRING
306 void AliHLTTPCConfMapper::MainVertexTrackingA()
308 //Tracking with vertex constraint.
310 if(!fParamSet[(Int_t)kTRUE])
312 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
313 "Tracking parameters not set!"<<ENDLOG;
317 Double_t initCpuTime,cpuTime;
318 initCpuTime = CpuTime();
321 SetVertexConstraint(true);
322 cpuTime = CpuTime() - initCpuTime;
324 LOG(AliHLTTPCLog::kBenchmark,"AliHLTTPCConfMapper::MainVertexTrackingA","Timing")
325 <<AliHLTTPCLog::kDec<<"Setup finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
329 void AliHLTTPCConfMapper::MainVertexTrackingB()
331 //Tracking with vertex constraint.
333 if(!fParamSet[(Int_t)kTRUE])
335 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
336 "Tracking parameters not set!"<<ENDLOG;
339 Double_t initCpuTime,cpuTime;
340 initCpuTime = CpuTime();
344 cpuTime = CpuTime() - initCpuTime;
346 LOG(AliHLTTPCLog::kBenchmark,"AliHLTTPCConfMapper::MainVertexTrackingB","Timing")
347 <<AliHLTTPCLog::kDec<<"Main Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
350 void AliHLTTPCConfMapper::MainVertexTracking()
352 //Tracking with vertex constraint.
354 if(!fParamSet[(Int_t)kTRUE])
356 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
357 "Tracking parameters not set!"<<ENDLOG;
361 Double_t initCpuTime,cpuTime;
362 initCpuTime = CpuTime();
366 SetVertexConstraint(true);
370 cpuTime = CpuTime() - initCpuTime;
372 LOG(AliHLTTPCLog::kBenchmark,"AliHLTTPCConfMapper::MainVertexTracking","Timing")<<AliHLTTPCLog::kDec<<
373 "Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
378 void AliHLTTPCConfMapper::NonVertexTracking()
380 //Tracking with no vertex constraint. This should be called after doing MainVertexTracking,
381 //in order to do tracking on the remaining clusters.
382 //The conformal mapping is now done with respect to the first cluster
383 //assosciated with this track.
385 if(!fParamSet[(Int_t)kFALSE])
387 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::NonVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
388 "Tracking parameters not set!"<<ENDLOG;
392 SetVertexConstraint(false);
394 SetPointers(); //To be able to do only nonvertextracking (more testing)
397 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::NonVertexTracking","ntracks")<<AliHLTTPCLog::kDec<<
398 "Number of nonvertex tracks found: "<<(fNTracks-fMainVertexTracks)<<ENDLOG;
402 void AliHLTTPCConfMapper::MainVertexSettings(Int_t trackletlength, Int_t tracklength,
403 Int_t rowscopetracklet, Int_t rowscopetrack,
404 Double_t maxphi,Double_t maxeta)
406 //Settings for main vertex tracking. The cuts are:
407 //TrackletLength: #hits on segment, before trying to build a track
408 //TrackLength: Minimum hits on a track
409 //RowScopeTracklet: Row search range for segments
410 //RowScopeTrack: Row search range for tracks
412 SetTrackletLength(trackletlength,(Bool_t)true);
413 SetRowScopeTracklet(rowscopetracklet, (Bool_t) true);
414 SetRowScopeTrack(rowscopetrack, (Bool_t) true);
415 SetMinPoints(tracklength,(Bool_t)true);
421 void AliHLTTPCConfMapper::NonVertexSettings(Int_t trackletlength, Int_t tracklength,
422 Int_t rowscopetracklet, Int_t rowscopetrack)
424 //set parameters for non-vertex tracking
425 SetTrackletLength(trackletlength,(Bool_t)false);
426 SetRowScopeTracklet(rowscopetracklet, (Bool_t)false);
427 SetRowScopeTrack(rowscopetrack, (Bool_t)false);
428 SetMinPoints(tracklength,(Bool_t)false);
429 SetParamDone(kFALSE);
432 void AliHLTTPCConfMapper::SetTrackCuts(Double_t hitChi2Cut, Double_t goodHitChi2, Double_t trackChi2Cut,Int_t maxdist,Bool_t vertexconstraint)
434 //Settings for tracks. The cuts are:
435 //HitChi2Cut: Maximum hit chi2
436 //goodHitChi2: Chi2 to stop look for next hit
437 //trackChi2Cut: Maximum track chi2
438 //maxdist: Maximum distance between two clusters when forming segments
440 SetHitChi2Cut(hitChi2Cut,vertexconstraint);
441 SetGoodHitChi2(goodHitChi2,vertexconstraint);
442 SetTrackChi2Cut(trackChi2Cut,vertexconstraint);
443 SetMaxDist(maxdist,vertexconstraint);
446 void AliHLTTPCConfMapper::SetTrackletCuts(Double_t maxangle,Double_t goodDist, Bool_t vc)
448 //Sets cuts of tracklets. Right now this is only:
449 //maxangle: Maximum angle when forming segments (if trackletlength > 2)
452 SetMaxAngleTracklet(maxangle, vc);
455 void AliHLTTPCConfMapper::ClusterLoop()
457 //Loop over hits, starting at outermost padrow, and trying to build segments.
459 //Check if there are not enough clusters to make a track in this sector
460 //Can happen in pp events.
461 if(fClustersUnused < fMinPoints[fVertexConstraint])
464 Int_t rowsegm,lastrow = fRowMin + fMinPoints[fVertexConstraint];
465 AliHLTTPCConfMapPoint *hit;
467 //Loop over rows, and try to create tracks from the hits.
468 //Starts at the outermost row, and loops as long as a track can be build, due to length.
470 for(rowsegm = fRowMax; rowsegm >= lastrow; rowsegm--)
472 if(fRow[(rowsegm-fRowMin)].first && ((AliHLTTPCConfMapPoint*)fRow[(rowsegm-fRowMin)].first)->GetPadRow() < fRowMin + 1)
475 for(hit = (AliHLTTPCConfMapPoint*)fRow[(rowsegm-fRowMin)].first; hit!=0; hit=hit->GetNextRowHit())
477 if(hit->GetUsage() == true)
488 void AliHLTTPCConfMapper::CreateTrack(AliHLTTPCConfMapPoint *hit)
490 //Tries to create a track from the initial hit given by ClusterLoop()
492 AliHLTTPCConfMapPoint *closesthit = NULL;
493 AliHLTTPCConfMapTrack *track = NULL;
496 Int_t tracks = fNTracks;
499 track = (AliHLTTPCConfMapTrack*)fTrack->NextTrack();
501 //reset hit parameters:
504 UInt_t *trackhitnumber = track->GetHitNumbers();
506 //set conformal coordinates if we are looking for non vertex tracks
507 if(!fVertexConstraint)
509 hit->SetAllCoord(hit);
512 //fill fit parameters of initial track:
513 track->UpdateParam(hit); //here the number of hits is incremented.
514 trackhitnumber[track->GetNumberOfPoints()-1] = hit->GetHitNumber();
519 for(point=1; point<fTrackletLength[fVertexConstraint]; point++)
521 if((closesthit = GetNextNeighbor(hit)))
524 // Calculate track length in sz plane
525 dx = ((AliHLTTPCConfMapPoint*)closesthit)->GetX() - ((AliHLTTPCConfMapPoint*)hit)->GetX();
526 dy = ((AliHLTTPCConfMapPoint*)closesthit)->GetY() - ((AliHLTTPCConfMapPoint*)hit)->GetY();
527 //track->fLength += (Double_t)sqrt ( dx * dx + dy * dy ) ;
528 Double_t length = track->GetLength()+(Double_t)sqrt ( dx * dx + dy * dy );
529 track->SetLength(length);
531 //closesthit->SetS(track->fLength);
532 closesthit->SetS(track->GetLength());
534 //update fit parameters
535 track->UpdateParam(closesthit);
536 trackhitnumber[track->GetNumberOfPoints()-1] = closesthit->GetHitNumber();
542 //closest hit does not exist:
543 track->DeleteCandidate();
544 fTrack->RemoveLast();
546 point = fTrackletLength[fVertexConstraint];
550 //tracklet is long enough to be extended to a track
551 if(track->GetNumberOfPoints() == fTrackletLength[fVertexConstraint])
554 track->SetProperties(true);
556 if(TrackletAngle(track) > fMaxAngleTracklet[fVertexConstraint])
557 {//proof if the first points seem to be a beginning of a track
558 track->SetProperties(false);
559 track->DeleteCandidate();
560 fTrack->RemoveLast();
564 else//good tracklet ->proceed, follow the trackfit
568 //define variables to keep the total chi:
569 Double_t xyChi2 = track->GetChiSq1();
570 Double_t szChi2 = track->GetChiSq2();
572 for(point = fTrackletLength[fVertexConstraint]; point <= fNumRowSegment; point++)
574 track->SetChiSq1(fHitChi2Cut[fVertexConstraint]);
575 closesthit = GetNextNeighbor((AliHLTTPCConfMapPoint*)track->GetLastHit(),track);
580 Double_t lxyChi2 = track->GetChiSq1()-track->GetChiSq2();
582 closesthit->SetXYChi2(lxyChi2);
584 //update track length:
585 track->SetLength(closesthit->GetS());
586 szChi2 += track->GetChiSq2();
587 closesthit->SetSZChi2(track->GetChiSq2());
589 track->UpdateParam(closesthit);
590 trackhitnumber[track->GetNumberOfPoints()-1] = closesthit->GetHitNumber();
592 //add closest hit to track
593 closesthit->SetUsage(true);
594 closesthit->SetTrackNumber(tracks-1);
600 //closest hit does not exist
601 point = fNumRowSegment; //continue with next hit in segment
607 track->SetChiSq1(xyChi2);
608 track->SetChiSq2(szChi2);
609 Double_t normalizedchi2 = (track->GetChiSq1()+track->GetChiSq2())/track->GetNumberOfPoints();
611 //remove tracks with not enough points already now
612 if(track->GetNumberOfPoints() < fMinPoints[fVertexConstraint] || normalizedchi2 > fTrackChi2Cut[fVertexConstraint])
614 track->SetProperties(false);
616 track->DeleteCandidate();
617 fTrack->RemoveLast();
623 fClustersUnused -= track->GetNumberOfPoints();
624 track->ComesFromMainVertex(fVertexConstraint);
625 //mark track as main vertex track or not
626 track->SetSector(2); //only needed for testing purposes.
627 track->SetRowRange(fRowMin,fRowMax);
629 if(fVertexConstraint)
640 AliHLTTPCConfMapPoint *AliHLTTPCConfMapper::GetNextNeighbor(AliHLTTPCConfMapPoint *starthit,
641 AliHLTTPCConfMapTrack *track)
643 //When forming segments: Finds closest hit to input hit
644 //When forming tracks: Find closest hit to track fit.
646 Double_t dist,closestdist = fMaxDist[fVertexConstraint];
648 AliHLTTPCConfMapPoint *hit = NULL;
649 AliHLTTPCConfMapPoint *closesthit = NULL;
657 Int_t maxrow = starthit->GetPadRow()-1;
660 if(track) //finding hit close to trackfit
662 minrow = starthit->GetPadRow()-fRowScopeTrack[fVertexConstraint];
666 minrow = starthit->GetPadRow()-fRowScopeTracklet[fVertexConstraint];
670 Int_t loopeta[25] = {0,0,0,-1,-1,-1,1,1,1, 0,0,-1,-1,1,1,-2,-2,-2,-2,-2,2,2,2,2,2};
671 Int_t loopphi[25] = {0,-1,1,0,-1,1,0,-1,1, -2,2,-2,2,-2,2,-2,-1,0,1,2,-2,-1,0,1,2};
676 return 0; //reached the last padrow under consideration
681 for(subrowsegm=maxrow; subrowsegm>=minrow; subrowsegm--)
683 //loop over subsegments, in the order defined above.
684 for(Int_t i=0; i<9; i++)
686 subphisegm = starthit->GetPhiIndex() + loopphi[i];
688 if(subphisegm < 0 || subphisegm >= fNumPhiSegment)
692 subphisegm += fNumPhiSegment;
694 else if(subphisegm >=fNumPhiSegment)
695 subphisegm -= fNumPhiSegment;
697 //loop over sub eta segments
699 subetasegm = starthit->GetEtaIndex() + loopeta[i];
701 if(subetasegm < 0 || subetasegm >=fNumEtaSegment)
702 continue;//segment exceeds bounds->skip it
704 //loop over hits in this sub segment:
705 volumeIndex=(subrowsegm-fRowMin)*fNumPhiEtaSegmentPlusOne +
706 subphisegm*fNumEtaSegmentPlusOne + subetasegm;
710 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::GetNextNeighbor","Memory")<<AliHLTTPCLog::kDec<<
711 "VolumeIndex error "<<volumeIndex<<ENDLOG;
714 assert(fVolume!=NULL);
715 for(hit = (AliHLTTPCConfMapPoint*)fVolume[volumeIndex].first;
716 hit!=0; hit = hit->GetNextVolumeHit())
720 {//hit was not used before
722 //set conformal mapping if looking for nonvertex tracks:
723 if(!fVertexConstraint)
725 hit->SetAllCoord(starthit);
728 if(track)//track search - look for nearest neighbor to extrapolated track
730 if (fVertexConstraint) {
731 if(!VerifyRange(starthit,hit))
734 testhit = EvaluateHit(starthit,hit,track);
736 if(testhit == 0)//chi2 not good enough, keep looking
738 else if(testhit==2)//chi2 good enough, return it
741 closesthit = hit;//chi2 acceptable, but keep looking
745 else //tracklet search, look for nearest neighbor
748 if((dist=CalcDistance(starthit,hit)) < closestdist)
750 if (fVertexConstraint) {
751 if(!VerifyRange(starthit,hit))
757 //if this hit is good enough, return it:
758 if(closestdist < fGoodDist)
762 continue;//sub hit was farther away than a hit before
766 }//hit not used before
768 else continue; //sub hit was used before
770 }//loop over hits in sub segment
772 }//loop over sub segments
779 if(closesthit)// && closestdist < mMaxDist)
785 Int_t AliHLTTPCConfMapper::EvaluateHit(AliHLTTPCConfMapPoint *starthit,AliHLTTPCConfMapPoint *hit,AliHLTTPCConfMapTrack *track)
787 //Check if space point gives a fit with acceptable chi2.
789 Double_t temp,dxy,lchi2,dx,dy,slocal,dsz,lszChi2;
790 temp = (track->GetA2Xy()*hit->GetXprime()-hit->GetYprime()+track->GetA1Xy());
791 dxy = temp*temp/(track->GetA2Xy()*track->GetA2Xy() + 1.);
794 lchi2 = (dxy*hit->GetXYWeight());
796 if(lchi2 > track->GetChiSq1())//chi2 was worse than before.
799 //calculate s and the distance hit-line
800 dx = starthit->GetX()-hit->GetX();
801 dy = starthit->GetY()-hit->GetY();
802 //slocal = track->fLength+sqrt(dx*dx+dy*dy);
803 slocal = track->GetLength()+sqrt(dx*dx+dy*dy);
805 temp = (track->GetA2Sz()*slocal-hit->GetZ()+track->GetA1Sz());
806 dsz = temp*temp/(track->GetA2Sz()*track->GetA2Sz()+1);
809 lszChi2 = dsz*hit->GetZWeight();
813 //check whether chi2 is better than previous one:
814 if(lchi2 < track->GetChiSq1())
816 track->SetChiSq1(lchi2);
817 track->SetChiSq2(lszChi2);
821 //if chi2 good enough, stop here:
822 if(lchi2 < fGoodHitChi2[fVertexConstraint])
832 Double_t AliHLTTPCConfMapper::CalcDistance(const AliHLTTPCConfMapPoint *hit1,const AliHLTTPCConfMapPoint *hit2) const
834 //Return distance between two clusters, defined by Pablo
836 Double_t phidiff = fabs( hit1->GetPhi() - hit2->GetPhi() );
837 if (phidiff > AliHLTTPCTransform::Pi()) phidiff = AliHLTTPCTransform::TwoPi() - phidiff;
839 return AliHLTTPCTransform::ToDeg()*fabs((Float_t)((hit1->GetPadRow() - hit2->GetPadRow()) *
840 (phidiff + fabs( hit1->GetEta() - hit2->GetEta()))));
843 Bool_t AliHLTTPCConfMapper::VerifyRange(const AliHLTTPCConfMapPoint *hit1,const AliHLTTPCConfMapPoint *hit2) const
845 //Check if the hit are within reasonable range in phi and eta
846 Double_t dphi,deta;//maxphi=0.1,maxeta=0.1;
847 dphi = fabs(hit1->GetPhi() - hit2->GetPhi());
848 if(dphi > AliHLTTPCTransform::Pi()) dphi = fabs(AliHLTTPCTransform::TwoPi() - dphi);
849 if(dphi > fMaxPhi) return false;
851 deta = fabs(hit1->GetEta() - hit2->GetEta());
852 if(deta > fMaxEta) return false;
858 Double_t AliHLTTPCConfMapper::TrackletAngle(AliHLTTPCConfMapTrack *track,Int_t n) const
860 // Returns the angle 'between' the last three points (started at point number n) on this track.
862 if(n > track->GetNumberOfPoints())
863 n = track->GetNumberOfPoints();
868 Double_t x1[2]={0,0};
869 Double_t x2[2]={0,0};
870 Double_t x3[2]={0,0};
871 Double_t angle1,angle2;
873 for(track->StartLoop(); track->LoopDone(); track->GetNextHit())
875 AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)track->GetCurrentHit();
876 if( (n-1) == counter)
881 else if( (n-2) == counter)
886 else if( (n-3) == counter)
894 angle1 = atan2(x2[1]-x3[1],x2[0]-x3[0]);
895 angle2 = atan2(x1[1]-x2[1],x1[0]-x2[0]);
897 return fabs(angle1-angle2);
902 Double_t angle1,angle2;
903 TObjArray *hits = track->GetHits();
905 if (n > track->GetNumberOfPoints()) {
906 n = track->GetNumberOfPoints();
913 x1[0] = ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetX() - ((AliHLTTPCConfMapPoint *)hits->At(n-3))->GetX();
914 x1[1] = ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetY() - ((AliHLTTPCConfMapPoint *)hits->At(n-3))->GetY();
916 x2[0] = ((AliHLTTPCConfMapPoint *)hits->At(n-1))->GetX() - ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetX();
917 x2[1] = ((AliHLTTPCConfMapPoint *)hits->At(n-1))->GetY() - ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetY();
919 angle1 = atan2(x1[1],x1[0]);
920 angle2 = atan2(x2[1],x1[0]);
921 return fabs(angle1-angle2);
925 Int_t AliHLTTPCConfMapper::FillTracks()
927 //Fill track parameters. Which basically means do a fit of helix in real space,
928 //which should be done in order to get nice tracks.
930 Int_t numoftracks = fNTracks;
933 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::FillTracks","fNTracks")<<AliHLTTPCLog::kDec<<
934 "No tracks found!!"<<ENDLOG;
938 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::FillTracks","fNTracks")<<AliHLTTPCLog::kDec<<
939 "Number of found tracks: "<<fNTracks<<ENDLOG;
942 for(Int_t i=0; i<numoftracks; i++)
944 AliHLTTPCConfMapTrack *track = (AliHLTTPCConfMapTrack*)fTrack->GetTrack(i);
945 track->Fill(fVertex,fMaxDca);
950 Double_t AliHLTTPCConfMapper::CpuTime()
952 //Return the Cputime in seconds.
954 gettimeofday( &tv, NULL );
955 return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);