- bugfix AliHLTDataBuffer: size of buffer descriptor set correctly
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCConfMapper.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTConfMapper.cxx,v 1.26 2005/06/14 10:55:21 cvetan Exp $
a6c02c85 3
4/** \class AliHLTTPCConfMapper
5<pre>
6//_____________________________________________________________
7// AliHLTTPCConfMapper
8//
9// Conformal mapping base class
10//
11// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
12// Copyright &copy ALICE HLT Group
13</pre>
14*/
15
16#include <sys/time.h>
17
a6c02c85 18#include "AliHLTTPCRootTypes.h"
19#include "AliHLTTPCSpacePointData.h"
20#include "AliHLTTPCLogging.h"
21#include "AliHLTTPCVertex.h"
22#include "AliHLTTPCConfMapTrack.h"
23#include "AliHLTTPCConfMapPoint.h"
24#include "AliHLTTPCTrackArray.h"
25#include "AliHLTTPCTransform.h"
26#include "AliHLTTPCConfMapper.h"
27
28#if __GNUC__ >= 3
29using namespace std;
30#endif
31
32ClassImp(AliHLTTPCConfMapper)
33
34AliHLTTPCConfMapper::AliHLTTPCConfMapper()
2a083ac4 35 :
36 fBench(kTRUE),
37 fNTracks(0),
38 fVertex(NULL),
39 fVertexFinder(kFALSE),
40 fHit(NULL),
41 fTrack(NULL),
42 fMaxDca(0.0), // no clue whether this is reasonable, but at least better than without initialization
43 fVolume(NULL),
44 fRow(NULL),
45 fNumRowSegment(0),
46 fNumPhiSegment(0),
47 fNumEtaSegment(0),
48 fNumRowSegmentPlusOne(0),
49 fNumPhiSegmentPlusOne(0),
50 fNumEtaSegmentPlusOne(0),
51 fNumPhiEtaSegmentPlusOne(0),
52 fBounds(0),
53 fPhiHitsOutOfRange(0),
54 fEtaHitsOutOfRange(0),
55 fPhiMin(0),
56 fPhiMax(0),
57 fEtaMin(0),
58 fEtaMax(0),
59 fRowMin(0),
60 fRowMax(0),
61 fVertexConstraint(kTRUE)
a6c02c85 62{
63 //Default constructor
a6c02c85 64 fParamSet[0]=0;
65 fParamSet[1]=0;
66}
67
a6c02c85 68AliHLTTPCConfMapper::~AliHLTTPCConfMapper()
69{
70 // Destructor.
71 if(fVolume) {
72 delete [] fVolume;
73 }
74 if(fRow) {
75 delete [] fRow;
76 }
77 if(fHit) {
78 delete [] fHit;
79 }
80 if(fTrack) {
81 delete fTrack;
82 }
83}
84
85void AliHLTTPCConfMapper::InitVolumes()
86{
87 //Data organization.
88 //Allocate volumes, set conformal coordinates and pointers.
89
90 //Should be done after setting the track parameters
91
92 fNumRowSegmentPlusOne = AliHLTTPCTransform::GetNRows();//NumRows[0]; //Maximum 32.
93 fNumPhiSegmentPlusOne = fNumPhiSegment+1;
94 fNumEtaSegmentPlusOne = fNumEtaSegment+1;
95 fNumPhiEtaSegmentPlusOne = fNumPhiSegmentPlusOne*fNumEtaSegmentPlusOne;
96 fBounds = fNumRowSegmentPlusOne * fNumPhiSegmentPlusOne * fNumEtaSegmentPlusOne;
97
98 //Allocate volumes:
99 if(fVolume) delete [] fVolume;
100 if(fRow) delete [] fRow;
101
fc455fba 102 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::InitVolumes","Memory")<<AliHLTTPCLog::kDec<<
a6c02c85 103 "Allocating "<<fBounds*sizeof(AliHLTTPCConfMapContainer)<<" Bytes to fVolume"<<ENDLOG;
fc455fba 104 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::InitVolumes","Memory")<<AliHLTTPCLog::kDec<<
a6c02c85 105 "Allocating "<<fNumRowSegmentPlusOne*sizeof(AliHLTTPCConfMapContainer)<<" Bytes to fRow"<<ENDLOG;
106
107 fVolume = new AliHLTTPCConfMapContainer[fBounds];
108 fRow = new AliHLTTPCConfMapContainer[fNumRowSegmentPlusOne];
109
110 memset(fVolume,0,fBounds*sizeof(AliHLTTPCConfMapContainer));
111 memset(fRow,0,fNumRowSegmentPlusOne*sizeof(AliHLTTPCConfMapContainer));
112
113 Int_t maxnumoftracks = 2000;
114 Int_t maxnumofhits = 120000;
115
116 if(fHit)
117 delete [] fHit;
118 if(fTrack)
119 delete fTrack;
120
121 fHit = new AliHLTTPCConfMapPoint[maxnumofhits];
122 fTrack = new AliHLTTPCTrackArray("AliHLTTPCConfMapTrack",maxnumoftracks);
123}
124
125void AliHLTTPCConfMapper::InitSector(Int_t sector,Int_t *rowrange,Float_t *etarange)
126{ //sector means slice here
127 //Initialize tracker for tracking in a given sector.
128 //Resets track and hit arrays.
129 //Here it is also possible to specify a subsector, by defining
130 //rowrange[0]=innermost row;
131 //rowrange[1]=outermostrow;
132 //Finally you can specify etaslices to save time (assuming a good seed from TRD...)
133
134 //Define tracking area:
135 if(rowrange)
136 {
137 fRowMin = rowrange[0];
138 fRowMax = rowrange[1];
139 }
140 else //complete sector
141 {
142 fRowMin = 0;
143 fRowMax = AliHLTTPCTransform::GetNRows() - 1;
144 }
145 if(etarange)
146 {
147 fEtaMin = etarange[0];
148 fEtaMax = sector < 18 ? etarange[1] : -etarange[1];
149 }
150 else
151 {
152 fEtaMin = 0;
153 fEtaMax = sector < 18 ? 0.9 : -0.9;
154 }
155
156 //Set the angles to sector 2:
157 fPhiMin = -10*AliHLTTPCTransform::ToRad();//fParam->GetAngle(sector) - 10/todeg;
158 fPhiMax = 10*AliHLTTPCTransform::ToRad();//fParam->GetAngle(sector) + 10/todeg;
159
160 fNTracks=0;
161 fMainVertexTracks = 0;
162 fClustersUnused = 0;
163 fEtaHitsOutOfRange=0;
164 fPhiHitsOutOfRange=0;
165
166 fNumRowSegment = fRowMax - fRowMin; //number of rows to be considered by tracker
167 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::InitSector","B-field")
168 <<"Tracker initializing with a magnetic field of "<<AliHLTTPCTransform::GetBField()<<ENDLOG;
169
170 fTrack->Reset();
171}
172
173Bool_t AliHLTTPCConfMapper::ReadHits(UInt_t count, AliHLTTPCSpacePointData* hits )
174{
175 //read hits
176 Int_t nhit=(Int_t)count;
177 for (Int_t i=0;i<nhit;i++)
738c049f 178 {
179 fHit[i+fClustersUnused].Reset();
180 fHit[i+fClustersUnused].ReadHits(&(hits[i]));
a6c02c85 181 }
182 fClustersUnused += nhit;
738c049f 183
fc455fba 184 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::ReadHits","#hits")
a6c02c85 185 <<AliHLTTPCLog::kDec<<"hit_counter: "<<nhit<<" count: "<<count<<ENDLOG;
186
187 return true;
188}
189
190void AliHLTTPCConfMapper::SetPointers()
191{
192 //Check if there are not enough clusters to make a track in this sector
193 //Can happen in pp events.
194
195 if(fClustersUnused < fMinPoints[fVertexConstraint])
196 return;
197
198 //Reset detector volumes
199 memset(fVolume,0,fBounds*sizeof(AliHLTTPCConfMapContainer));
200 memset(fRow,0,fNumRowSegmentPlusOne*sizeof(AliHLTTPCConfMapContainer));
201
202 Float_t phiSlice = (fPhiMax-fPhiMin)/fNumPhiSegment;
203 Float_t etaSlice = (fEtaMax-fEtaMin)/fNumEtaSegment;
204
205 Int_t volumeIndex;
206 Int_t localcounter=0;
207 for(Int_t j=0; j<fClustersUnused; j++)
208 {
209 //AliHLTTPCConfMapPoint *thisHit = (AliHLTTPCConfMapPoint*)fHit->At(j);
210 AliHLTTPCConfMapPoint *thisHit = &(fHit[j]);
211
212 thisHit->Setup(fVertex);
213
214 Int_t localrow = thisHit->GetPadRow();
215
216 if(localrow < fRowMin || localrow > fRowMax)
217 continue;
218
219 //Get indexes:
220 thisHit->SetPhiIndex((Int_t)((thisHit->GetPhi()-fPhiMin)/phiSlice +1));
221
222 if(thisHit->GetPhiIndex()<1 || thisHit->GetPhiIndex()>fNumPhiSegment)
223 {
224 //cout << "Phiindex: " << thisHit->phiIndex << " " << thisHit->GetPhi() << endl;
225 fPhiHitsOutOfRange++;
226 continue;
227 }
228
229 thisHit->SetEtaIndex((Int_t)((thisHit->GetEta()-fEtaMin)/etaSlice + 1));
230 if(thisHit->GetEtaIndex()<1 || thisHit->GetEtaIndex()>fNumEtaSegment)
231 {
232 //cout << "Etaindex: " << thisHit->etaIndex << " " << thisHit->GetEta() << endl;
233 fEtaHitsOutOfRange++;
234 continue;
235 }
236 localcounter++;
237
238 volumeIndex = (localrow-fRowMin)*fNumPhiEtaSegmentPlusOne +
239 thisHit->GetPhiIndex()*fNumEtaSegmentPlusOne+thisHit->GetEtaIndex();
240
241 if(fVolume[volumeIndex].first == NULL)
242 fVolume[volumeIndex].first = (void *)thisHit;
243 else
244 ((AliHLTTPCConfMapPoint *)fVolume[volumeIndex].last)->SetNextVolumeHit(thisHit);
245 fVolume[volumeIndex].last = (void *)thisHit;
246
247
248 //set row pointers
249 if(fRow[(localrow-fRowMin)].first == NULL)
250 fRow[(localrow-fRowMin)].first = (void *)thisHit;
251 else
252 ((AliHLTTPCConfMapPoint *)(fRow[(localrow-fRowMin)].last))->SetNextRowHit(thisHit);
253 fRow[(localrow-fRowMin)].last = (void *)thisHit;
254 }
255
256 if(fClustersUnused>0 && localcounter==0)
257 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::SetPointers","Parameters")
258 <<AliHLTTPCLog::kDec<<"No points passed to track finder, hits out of range: "
259 <<fEtaHitsOutOfRange+fPhiHitsOutOfRange<<ENDLOG;
260
261 Int_t hits_accepted=fClustersUnused-(fEtaHitsOutOfRange+fPhiHitsOutOfRange);
262 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::SetPointers","Setup")
263 <<"Setup finished, hits out of range: "<<fEtaHitsOutOfRange+fPhiHitsOutOfRange
264 <<" hits accepted "<<hits_accepted<<ENDLOG;
265}
266
2a083ac4 267void AliHLTTPCConfMapper::MainVertexTrackingA()
a6c02c85 268{
269 //Tracking with vertex constraint.
270
271 if(!fParamSet[(Int_t)kTRUE])
272 {
273 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
274 "Tracking parameters not set!"<<ENDLOG;
275 return;
276 }
277
278 Double_t initCpuTime,cpuTime;
279 initCpuTime = CpuTime();
280
281 SetPointers();
282 SetVertexConstraint(true);
283 cpuTime = CpuTime() - initCpuTime;
284 if(fBench)
2a083ac4 285 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::MainVertexTrackingA","Timing")
a6c02c85 286 <<AliHLTTPCLog::kDec<<"Setup finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
287
288}
289
2a083ac4 290void AliHLTTPCConfMapper::MainVertexTrackingB()
a6c02c85 291{
292 //Tracking with vertex constraint.
293
294 if(!fParamSet[(Int_t)kTRUE])
295 {
296 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
297 "Tracking parameters not set!"<<ENDLOG;
298 return;
299 }
300 Double_t initCpuTime,cpuTime;
301 initCpuTime = CpuTime();
302
303 ClusterLoop();
304
305 cpuTime = CpuTime() - initCpuTime;
306 if(fBench)
2a083ac4 307 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::MainVertexTrackingB","Timing")
a6c02c85 308 <<AliHLTTPCLog::kDec<<"Main Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
309}
310
311void AliHLTTPCConfMapper::MainVertexTracking()
312{
313 //Tracking with vertex constraint.
314
315 if(!fParamSet[(Int_t)kTRUE])
316 {
317 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::MainVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
318 "Tracking parameters not set!"<<ENDLOG;
319 return;
320 }
321
322 Double_t initCpuTime,cpuTime;
323 initCpuTime = CpuTime();
437e8e54 324
325 SetPointers();
326
a6c02c85 327 SetVertexConstraint(true);
328
329 ClusterLoop();
330
331 cpuTime = CpuTime() - initCpuTime;
332 if(fBench)
333 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::MainVertexTracking","Timing")<<AliHLTTPCLog::kDec<<
334 "Tracking finished in "<<cpuTime*1000<<" ms"<<ENDLOG;
335
336 return;
337}
338
339void AliHLTTPCConfMapper::NonVertexTracking()
340{
341 //Tracking with no vertex constraint. This should be called after doing MainVertexTracking,
342 //in order to do tracking on the remaining clusters.
343 //The conformal mapping is now done with respect to the first cluster
344 //assosciated with this track.
345
346 if(!fParamSet[(Int_t)kFALSE])
347 {
348 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::NonVertexTracking","Parameters")<<AliHLTTPCLog::kDec<<
349 "Tracking parameters not set!"<<ENDLOG;
350 return;
351 }
352
353 SetVertexConstraint(false);
437e8e54 354
355 SetPointers(); //To be able to do only nonvertextracking (more testing)
356
a6c02c85 357 ClusterLoop();
358 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCConfMapper::NonVertexTracking","ntracks")<<AliHLTTPCLog::kDec<<
359 "Number of nonvertex tracks found: "<<(fNTracks-fMainVertexTracks)<<ENDLOG;
360 return;
361}
362
363void AliHLTTPCConfMapper::MainVertexSettings(Int_t trackletlength, Int_t tracklength,
364 Int_t rowscopetracklet, Int_t rowscopetrack,
365 Double_t maxphi,Double_t maxeta)
366{
367 //Settings for main vertex tracking. The cuts are:
368 //TrackletLength: #hits on segment, before trying to build a track
369 //TrackLength: Minimum hits on a track
370 //RowScopeTracklet: Row search range for segments
371 //RowScopeTrack: Row search range for tracks
372
373 SetTrackletLength(trackletlength,(Bool_t)true);
374 SetRowScopeTracklet(rowscopetracklet, (Bool_t) true);
375 SetRowScopeTrack(rowscopetrack, (Bool_t) true);
376 SetMinPoints(tracklength,(Bool_t)true);
377 fMaxPhi=maxphi;
378 fMaxEta=maxeta;
379 SetParamDone(kTRUE);
380}
381
382void AliHLTTPCConfMapper::NonVertexSettings(Int_t trackletlength, Int_t tracklength,
383 Int_t rowscopetracklet, Int_t rowscopetrack)
384{
385 //set parameters for non-vertex tracking
386 SetTrackletLength(trackletlength,(Bool_t)false);
387 SetRowScopeTracklet(rowscopetracklet, (Bool_t)false);
388 SetRowScopeTrack(rowscopetrack, (Bool_t)false);
389 SetMinPoints(tracklength,(Bool_t)false);
390 SetParamDone(kFALSE);
391}
392
393void AliHLTTPCConfMapper::SetTrackCuts(Double_t hitChi2Cut, Double_t goodHitChi2, Double_t trackChi2Cut,Int_t maxdist,Bool_t vertexconstraint)
394{
395 //Settings for tracks. The cuts are:
396 //HitChi2Cut: Maximum hit chi2
397 //goodHitChi2: Chi2 to stop look for next hit
398 //trackChi2Cut: Maximum track chi2
399 //maxdist: Maximum distance between two clusters when forming segments
400
401 SetHitChi2Cut(hitChi2Cut,vertexconstraint);
402 SetGoodHitChi2(goodHitChi2,vertexconstraint);
403 SetTrackChi2Cut(trackChi2Cut,vertexconstraint);
404 SetMaxDist(maxdist,vertexconstraint);
405}
406
407void AliHLTTPCConfMapper::SetTrackletCuts(Double_t maxangle,Double_t goodDist, Bool_t vc)
408{
409 //Sets cuts of tracklets. Right now this is only:
410 //maxangle: Maximum angle when forming segments (if trackletlength > 2)
411
412 fGoodDist=goodDist;
413 SetMaxAngleTracklet(maxangle, vc);
414}
415
416void AliHLTTPCConfMapper::ClusterLoop()
417{
418 //Loop over hits, starting at outermost padrow, and trying to build segments.
419
420 //Check if there are not enough clusters to make a track in this sector
421 //Can happen in pp events.
422 if(fClustersUnused < fMinPoints[fVertexConstraint])
423 return;
424
425 Int_t rowsegm,lastrow = fRowMin + fMinPoints[fVertexConstraint];
426 AliHLTTPCConfMapPoint *hit;
427
428 //Loop over rows, and try to create tracks from the hits.
429 //Starts at the outermost row, and loops as long as a track can be build, due to length.
430
431 for(rowsegm = fRowMax; rowsegm >= lastrow; rowsegm--)
432 {
433 if(fRow[(rowsegm-fRowMin)].first && ((AliHLTTPCConfMapPoint*)fRow[(rowsegm-fRowMin)].first)->GetPadRow() < fRowMin + 1)
434 break;
435
436 for(hit = (AliHLTTPCConfMapPoint*)fRow[(rowsegm-fRowMin)].first; hit!=0; hit=hit->GetNextRowHit())
437 {
438 if(hit->GetUsage() == true)
439 continue;
440 else
441 CreateTrack(hit);
442 }
443 }
444
445 return;
446}
447
448
449void AliHLTTPCConfMapper::CreateTrack(AliHLTTPCConfMapPoint *hit)
450{
451 //Tries to create a track from the initial hit given by ClusterLoop()
452
453 AliHLTTPCConfMapPoint *closesthit = NULL;
454 AliHLTTPCConfMapTrack *track = NULL;
455
456 Int_t point;
457 Int_t tracks = fNTracks;
458 fNTracks++;
459
460 track = (AliHLTTPCConfMapTrack*)fTrack->NextTrack();
461
462 //reset hit parameters:
463 track->Reset();
464
465 UInt_t *trackhitnumber = track->GetHitNumbers();
466
467 //set conformal coordinates if we are looking for non vertex tracks
468 if(!fVertexConstraint)
469 {
470 hit->SetAllCoord(hit);
471 }
472
473 //fill fit parameters of initial track:
474 track->UpdateParam(hit); //here the number of hits is incremented.
475 trackhitnumber[track->GetNumberOfPoints()-1] = hit->GetHitNumber();
476
477 Double_t dx,dy;
478 //create tracklets:
479
480 for(point=1; point<fTrackletLength[fVertexConstraint]; point++)
481 {
482 if((closesthit = GetNextNeighbor(hit)))
483 {//closest hit exist
484
485 // Calculate track length in sz plane
486 dx = ((AliHLTTPCConfMapPoint*)closesthit)->GetX() - ((AliHLTTPCConfMapPoint*)hit)->GetX();
487 dy = ((AliHLTTPCConfMapPoint*)closesthit)->GetY() - ((AliHLTTPCConfMapPoint*)hit)->GetY();
488 //track->fLength += (Double_t)sqrt ( dx * dx + dy * dy ) ;
489 Double_t length = track->GetLength()+(Double_t)sqrt ( dx * dx + dy * dy );
490 track->SetLength(length);
491
492 //closesthit->SetS(track->fLength);
493 closesthit->SetS(track->GetLength());
494
495 //update fit parameters
496 track->UpdateParam(closesthit);
497 trackhitnumber[track->GetNumberOfPoints()-1] = closesthit->GetHitNumber();
498
499 hit = closesthit;
500 }
501 else
502 {
503 //closest hit does not exist:
504 track->DeleteCandidate();
505 fTrack->RemoveLast();
506 fNTracks--;
507 point = fTrackletLength[fVertexConstraint];
508 }
509 }
510
511 //tracklet is long enough to be extended to a track
512 if(track->GetNumberOfPoints() == fTrackletLength[fVertexConstraint])
513 {
514
515 track->SetProperties(true);
516
517 if(TrackletAngle(track) > fMaxAngleTracklet[fVertexConstraint])
518 {//proof if the first points seem to be a beginning of a track
519 track->SetProperties(false);
520 track->DeleteCandidate();
521 fTrack->RemoveLast();
522 fNTracks--;
523 }
524
525 else//good tracklet ->proceed, follow the trackfit
526 {
527 tracks++;
528
529 //define variables to keep the total chi:
530 Double_t xyChi2 = track->GetChiSq1();
531 Double_t szChi2 = track->GetChiSq2();
532
533 for(point = fTrackletLength[fVertexConstraint]; point <= fNumRowSegment; point++)
534 {
535 track->SetChiSq1(fHitChi2Cut[fVertexConstraint]);
536 closesthit = GetNextNeighbor((AliHLTTPCConfMapPoint*)track->GetLastHit(),track);
537
538 if(closesthit)
539 {
540 //keep total chi:
541 Double_t lxyChi2 = track->GetChiSq1()-track->GetChiSq2();
542 xyChi2 += lxyChi2;
543 closesthit->SetXYChi2(lxyChi2);
544
545 //update track length:
546 track->SetLength(closesthit->GetS());
547 szChi2 += track->GetChiSq2();
548 closesthit->SetSZChi2(track->GetChiSq2());
549
550 track->UpdateParam(closesthit);
551 trackhitnumber[track->GetNumberOfPoints()-1] = closesthit->GetHitNumber();
552
553 //add closest hit to track
554 closesthit->SetUsage(true);
555 closesthit->SetTrackNumber(tracks-1);
556
557 }//closesthit
558
559 else
560 {
561 //closest hit does not exist
562 point = fNumRowSegment; //continue with next hit in segment
563 }//else
564
565 }//create tracks
566
567 //store track chi2:
568 track->SetChiSq1(xyChi2);
569 track->SetChiSq2(szChi2);
570 Double_t normalizedchi2 = (track->GetChiSq1()+track->GetChiSq2())/track->GetNumberOfPoints();
571
572 //remove tracks with not enough points already now
573 if(track->GetNumberOfPoints() < fMinPoints[fVertexConstraint] || normalizedchi2 > fTrackChi2Cut[fVertexConstraint])
574 {
575 track->SetProperties(false);
576 fNTracks--;
577 track->DeleteCandidate();
578 fTrack->RemoveLast();
579 tracks--;
580 }
581
582 else
583 {
584 fClustersUnused -= track->GetNumberOfPoints();
585 track->ComesFromMainVertex(fVertexConstraint);
586 //mark track as main vertex track or not
587 track->SetSector(2); //only needed for testing purposes.
588 track->SetRowRange(fRowMin,fRowMax);
589
590 if(fVertexConstraint)
591 fMainVertexTracks++;
592 }
593
594 }//good tracklet
595
596 }
597
598 return;
599}
600
601AliHLTTPCConfMapPoint *AliHLTTPCConfMapper::GetNextNeighbor(AliHLTTPCConfMapPoint *starthit,
602 AliHLTTPCConfMapTrack *track)
603{
604 //When forming segments: Finds closest hit to input hit
605 //When forming tracks: Find closest hit to track fit.
606
607 Double_t dist,closestdist = fMaxDist[fVertexConstraint];
608
609 AliHLTTPCConfMapPoint *hit = NULL;
610 AliHLTTPCConfMapPoint *closesthit = NULL;
611
612 Int_t subrowsegm;
613 Int_t subphisegm;
614 Int_t subetasegm;
615 Int_t volumeIndex;
616 Int_t testhit;
617
618 Int_t maxrow = starthit->GetPadRow()-1;
619 Int_t minrow;
620
621 if(track) //finding hit close to trackfit
622 {
623 minrow = starthit->GetPadRow()-fRowScopeTrack[fVertexConstraint];
624 }
625 else
626 {
627 minrow = starthit->GetPadRow()-fRowScopeTracklet[fVertexConstraint];
628 }
629
630 //make a smart loop
631 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};
632 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};
633
634 if(minrow < fRowMin)
635 minrow = fRowMin;
636 if(maxrow < fRowMin)
637 return 0; //reached the last padrow under consideration
638
639 else
640 {
641 //loop over sub rows
642 for(subrowsegm=maxrow; subrowsegm>=minrow; subrowsegm--)
643 {
644 //loop over subsegments, in the order defined above.
645 for(Int_t i=0; i<9; i++)
646 {
647 subphisegm = starthit->GetPhiIndex() + loopphi[i];
648
649 if(subphisegm < 0 || subphisegm >= fNumPhiSegment)
650 continue;
651 /*
652 if(subphisegm<0)
653 subphisegm += fNumPhiSegment;
654
655 else if(subphisegm >=fNumPhiSegment)
656 subphisegm -= fNumPhiSegment;
657 */
658 //loop over sub eta segments
659
660 subetasegm = starthit->GetEtaIndex() + loopeta[i];
661
662 if(subetasegm < 0 || subetasegm >=fNumEtaSegment)
663 continue;//segment exceeds bounds->skip it
664
665 //loop over hits in this sub segment:
666 volumeIndex=(subrowsegm-fRowMin)*fNumPhiEtaSegmentPlusOne +
667 subphisegm*fNumEtaSegmentPlusOne + subetasegm;
668
669 if(volumeIndex<0)
670 {//debugging
671 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapper::GetNextNeighbor","Memory")<<AliHLTTPCLog::kDec<<
672 "VolumeIndex error "<<volumeIndex<<ENDLOG;
673 }
674
675 for(hit = (AliHLTTPCConfMapPoint*)fVolume[volumeIndex].first;
676 hit!=0; hit = hit->GetNextVolumeHit())
677 {
678
679 if(!hit->GetUsage())
680 {//hit was not used before
681
682 //set conformal mapping if looking for nonvertex tracks:
683 if(!fVertexConstraint)
684 {
685 hit->SetAllCoord(starthit);
686 }
687
688 if(track)//track search - look for nearest neighbor to extrapolated track
689 {
437e8e54 690 if (fVertexConstraint) {
691 if(!VerifyRange(starthit,hit))
692 continue;
693 }
a6c02c85 694 testhit = EvaluateHit(starthit,hit,track);
695
696 if(testhit == 0)//chi2 not good enough, keep looking
697 continue;
698 else if(testhit==2)//chi2 good enough, return it
699 return hit;
700 else
701 closesthit = hit;//chi2 acceptable, but keep looking
702
703 }//track search
704
705 else //tracklet search, look for nearest neighbor
706 {
707
708 if((dist=CalcDistance(starthit,hit)) < closestdist)
709 {
437e8e54 710 if (fVertexConstraint) {
738c049f 711 if(!VerifyRange(starthit,hit))
437e8e54 712 continue;
713 }
a6c02c85 714 closestdist = dist;
715 closesthit = hit;
716
717 //if this hit is good enough, return it:
718 if(closestdist < fGoodDist)
719 return closesthit;
720 }
721 else
722 continue;//sub hit was farther away than a hit before
723
724 }//tracklet search
725
726 }//hit not used before
727
728 else continue; //sub hit was used before
729
730 }//loop over hits in sub segment
731
732 }//loop over sub segments
733
734 }//loop over subrows
735
736 }//else
737
738 //closest hit found:
739 if(closesthit)// && closestdist < mMaxDist)
740 return closesthit;
741 else
742 return 0;
743}
744
745Int_t AliHLTTPCConfMapper::EvaluateHit(AliHLTTPCConfMapPoint *starthit,AliHLTTPCConfMapPoint *hit,AliHLTTPCConfMapTrack *track)
746{
747 //Check if space point gives a fit with acceptable chi2.
748
749 Double_t temp,dxy,lchi2,dx,dy,slocal,dsz,lszChi2;
750 temp = (track->GetA2Xy()*hit->GetXprime()-hit->GetYprime()+track->GetA1Xy());
751 dxy = temp*temp/(track->GetA2Xy()*track->GetA2Xy() + 1.);
752
753 //Calculate chi2
754 lchi2 = (dxy*hit->GetXYWeight());
755
756 if(lchi2 > track->GetChiSq1())//chi2 was worse than before.
757 return 0;
758
759 //calculate s and the distance hit-line
760 dx = starthit->GetX()-hit->GetX();
761 dy = starthit->GetY()-hit->GetY();
762 //slocal = track->fLength+sqrt(dx*dx+dy*dy);
763 slocal = track->GetLength()+sqrt(dx*dx+dy*dy);
764
765 temp = (track->GetA2Sz()*slocal-hit->GetZ()+track->GetA1Sz());
766 dsz = temp*temp/(track->GetA2Sz()*track->GetA2Sz()+1);
767
768 //calculate chi2
769 lszChi2 = dsz*hit->GetZWeight();
770 lchi2 += lszChi2;
771
772
773 //check whether chi2 is better than previous one:
774 if(lchi2 < track->GetChiSq1())
775 {
776 track->SetChiSq1(lchi2);
777 track->SetChiSq2(lszChi2);
778
779 hit->SetS(slocal);
780
781 //if chi2 good enough, stop here:
782 if(lchi2 < fGoodHitChi2[fVertexConstraint])
783 return 2;
784
785 return 1;
786 }
787
788 return 0;
789
790}
791
792Double_t AliHLTTPCConfMapper::CalcDistance(const AliHLTTPCConfMapPoint *hit1,const AliHLTTPCConfMapPoint *hit2) const
793{
794 //Return distance between two clusters, defined by Pablo
795
796 Double_t phidiff = fabs( hit1->GetPhi() - hit2->GetPhi() );
797 if (phidiff > AliHLTTPCTransform::Pi()) phidiff = AliHLTTPCTransform::TwoPi() - phidiff;
798
799 return AliHLTTPCTransform::ToDeg()*fabs((Float_t)((hit1->GetPadRow() - hit2->GetPadRow()) *
800 (phidiff + fabs( hit1->GetEta() - hit2->GetEta()))));
801}
802
803Bool_t AliHLTTPCConfMapper::VerifyRange(const AliHLTTPCConfMapPoint *hit1,const AliHLTTPCConfMapPoint *hit2) const
804{
805 //Check if the hit are within reasonable range in phi and eta
806 Double_t dphi,deta;//maxphi=0.1,maxeta=0.1;
807 dphi = fabs(hit1->GetPhi() - hit2->GetPhi());
808 if(dphi > AliHLTTPCTransform::Pi()) dphi = fabs(AliHLTTPCTransform::TwoPi() - dphi);
809 if(dphi > fMaxPhi) return false;
810
811 deta = fabs(hit1->GetEta() - hit2->GetEta());
812 if(deta > fMaxEta) return false;
813
814 return true;
815
816}
817
818Double_t AliHLTTPCConfMapper::TrackletAngle(AliHLTTPCConfMapTrack *track,Int_t n) const
819{
820 // Returns the angle 'between' the last three points (started at point number n) on this track.
821
822 if(n > track->GetNumberOfPoints())
823 n = track->GetNumberOfPoints();
824
825 if(n<3)
826 return 0;
827
828 Double_t x1[2];
829 Double_t x2[2];
830 Double_t x3[2];
831 Double_t angle1,angle2;
832 Int_t counter=0;
833 for(track->StartLoop(); track->LoopDone(); track->GetNextHit())
834 {
835 AliHLTTPCConfMapPoint *p = (AliHLTTPCConfMapPoint*)track->GetCurrentHit();
836 if( (n-1) == counter)
837 {
838 x1[0] = p->GetX();
839 x1[1] = p->GetY();
840 }
841 else if( (n-2) == counter)
842 {
843 x2[0] = p->GetX();
844 x2[1] = p->GetY();
845 }
846 else if( (n-3) == counter)
847 {
848 x3[0] = p->GetX();
849 x3[1] = p->GetY();
850 }
851 counter++;
852 }
853
854 angle1 = atan2(x2[1]-x3[1],x2[0]-x3[0]);
855 angle2 = atan2(x1[1]-x2[1],x1[0]-x2[0]);
856
857 return fabs(angle1-angle2);
858
859 /*
860 Double_t x1[2];
861 Double_t x2[2];
862 Double_t angle1,angle2;
863 TObjArray *hits = track->GetHits();
864
865 if (n > track->GetNumberOfPoints()) {
866 n = track->GetNumberOfPoints();
867 }
868
869 if (n<3)
870 return 0;
871
872
873 x1[0] = ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetX() - ((AliHLTTPCConfMapPoint *)hits->At(n-3))->GetX();
874 x1[1] = ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetY() - ((AliHLTTPCConfMapPoint *)hits->At(n-3))->GetY();
875
876 x2[0] = ((AliHLTTPCConfMapPoint *)hits->At(n-1))->GetX() - ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetX();
877 x2[1] = ((AliHLTTPCConfMapPoint *)hits->At(n-1))->GetY() - ((AliHLTTPCConfMapPoint *)hits->At(n-2))->GetY();
878
879 angle1 = atan2(x1[1],x1[0]);
880 angle2 = atan2(x2[1],x1[0]);
881 return fabs(angle1-angle2);
882 */
883}
884
885Int_t AliHLTTPCConfMapper::FillTracks()
886{
887 //Fill track parameters. Which basically means do a fit of helix in real space,
888 //which should be done in order to get nice tracks.
889
890 Int_t numoftracks = fNTracks;
891 if(fNTracks == 0)
892 {
cb703d46 893 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::FillTracks","fNTracks")<<AliHLTTPCLog::kDec<<
a6c02c85 894 "No tracks found!!"<<ENDLOG;
895 return 0;
896 }
897
fc455fba 898 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapper::FillTracks","fNTracks")<<AliHLTTPCLog::kDec<<
a6c02c85 899 "Number of found tracks: "<<fNTracks<<ENDLOG;
900
901 // fTrack->Sort();
902 for(Int_t i=0; i<numoftracks; i++)
903 {
904 AliHLTTPCConfMapTrack *track = (AliHLTTPCConfMapTrack*)fTrack->GetTrack(i);
905 track->Fill(fVertex,fMaxDca);
906 }
907 return 1;
908}
909
910Double_t AliHLTTPCConfMapper::CpuTime()
911{
912 //Return the Cputime in seconds.
913 struct timeval tv;
914 gettimeofday( &tv, NULL );
915 return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);
916}