]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTGlobalBarrelTrack.cxx
separate function to calculate track points from local settings
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTGlobalBarrelTrack.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTGlobalBarrelTrack.cxx
20     @author Matthias Richter
21     @date   2009-06-24
22     @brief  An AliKalmanTrack implementation for global HLT barrel tracks.
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31 #include <cassert>
32 #include <memory>
33 #include <iostream>
34 #include "AliHLTGlobalBarrelTrack.h"
35 #include "AliHLTSpacePointContainer.h"
36 #include "AliHLTTrackGeometry.h"
37 #include "AliHLTMisc.h"
38 #include "TClonesArray.h"
39 #include "TFile.h"
40 #include "TArrayC.h"
41 #include "TMath.h"
42 #include "TMarker.h"
43 #include "TArc.h"
44
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTGlobalBarrelTrack)
47
48 AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack()
49 : AliKalmanTrack()
50   , fPoints()
51   , fLastX(0.0)
52   , fLastY(0.0)
53   , fTrackID(-1)
54   , fHelixRadius(0.0)
55   , fHelixCenterX(0.0)
56   , fHelixCenterY(0.0)
57   , fSpacePoints(NULL)
58   , fTrackPoints(NULL)
59 {
60   // see header file for class documentation
61   // or
62   // refer to README to build package
63   // or
64   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65 }
66
67 AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack(const AliHLTGlobalBarrelTrack& t)
68   : AliKalmanTrack(t)
69   , fPoints()
70   , fLastX(t.GetLastPointX())
71   , fLastY(t.GetLastPointY())
72   , fTrackID(t.TrackID())
73   , fHelixRadius(t.fHelixRadius)
74   , fHelixCenterX(t.fHelixCenterX)
75   , fHelixCenterY(t.fHelixCenterY)
76   , fSpacePoints(NULL)
77   , fTrackPoints(NULL)
78 {
79   // see header file for class documentation
80   fPoints.assign(t.fPoints.begin(), t.fPoints.end());
81 }
82
83 AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack(const AliHLTExternalTrackParam& p )
84   : AliKalmanTrack()
85   , fPoints()
86   , fLastX(p.fLastX)
87   , fLastY(p.fLastY)
88   , fTrackID(p.fTrackID)
89   , fHelixRadius(0.0)
90   , fHelixCenterX(0.0)
91   , fHelixCenterY(0.0)
92   , fSpacePoints(NULL)
93   , fTrackPoints(NULL)
94 {
95   // see header file for class documentation
96
97   // the 5 track parameters are named in the AliHLTExternalTrackParam
98   // while AliExternalTrackParam just uses an array[5]
99   // the members have the same order, fY is the first one
100   Set(p.fX, p.fAlpha, &p.fY, p.fC);
101   SetPoints(p.fPointIDs, p.fNPoints);
102   SetNumberOfClusters(p.fNPoints);
103   //SetIntegratedLength(GetPathLengthTo( GetLastPointX(), b);
104 }
105
106 AliHLTGlobalBarrelTrack::AliHLTGlobalBarrelTrack(const AliExternalTrackParam& p )
107   : AliKalmanTrack()
108   , fPoints()
109   , fLastX(0)
110   , fLastY(0)
111   , fTrackID(0)
112   , fHelixRadius(0.0)
113   , fHelixCenterX(0.0)
114   , fHelixCenterY(0.0)
115   , fSpacePoints(NULL)
116   , fTrackPoints(NULL)
117 {
118   // see header file for class documentation
119   *(dynamic_cast<AliExternalTrackParam*>(this))=p;
120 }
121
122 AliHLTGlobalBarrelTrack::~AliHLTGlobalBarrelTrack()
123 {
124   // see header file for class documentation
125 }
126
127
128 Double_t AliHLTGlobalBarrelTrack::GetPathLengthTo( Double_t x, Double_t b ) const
129 {
130   // calculate the trajectory length for dx step
131     
132   Double_t dx = x - GetX();
133   Double_t ey = GetSnp();
134   if( TMath::Abs( ey )>=kAlmost1 ) return 0;
135
136   Double_t ex = TMath::Sqrt(1-ey*ey);
137   Double_t k  = GetC(b);
138
139   Double_t ey1 = k * dx + ey;
140
141   // check for intersection with X=x
142
143   if ( TMath::Abs( ey1 ) >= kAlmost1  ) return 0;
144
145   Double_t ex1 = TMath::Sqrt(1-ey1*ey1);
146
147   Double_t ss = ey + ey1;
148   Double_t cc = ex + ex1;
149
150   if ( TMath::Abs( cc ) < 1.e-4  ) return 0;
151
152   Double_t tg = ss / cc; 
153   Double_t dl = dx * TMath::Sqrt( 1 + tg * tg );
154   Double_t dSin = dl * k / 2;
155   if ( dSin > 1 ) dSin = 1;
156   if ( dSin < -1 ) dSin = -1;
157   Double_t dS = ( TMath::Abs( k ) > 1.e-4 )  ? ( 2 * TMath::ASin( dSin ) / k ) : dl;
158
159   return dS*TMath::Sqrt(1 + GetTgl()*GetTgl() );
160 }
161
162
163
164
165 int AliHLTGlobalBarrelTrack::ConvertTrackDataArray(const AliHLTTracksData* pTracks, unsigned sizeInByte, vector<AliHLTGlobalBarrelTrack> &tgtArray )
166 {
167   // see header file for class documentation
168   int iResult=0;
169   if (!pTracks || sizeInByte<sizeof(AliHLTTracksData) || pTracks->fCount==0) return 0;
170
171   const AliHLTUInt8_t* pEnd=reinterpret_cast<const AliHLTUInt8_t*>(pTracks);
172   pEnd+=sizeInByte;
173
174   tgtArray.resize(pTracks->fCount + tgtArray.size());
175   const AliHLTUInt8_t* pCurrent=reinterpret_cast<const AliHLTUInt8_t*>(pTracks->fTracklets);
176   for (unsigned i=0; i<pTracks->fCount; i++) {
177     if (pCurrent+sizeof(AliHLTExternalTrackParam)>pEnd) {
178       iResult=-EINVAL; break;
179     }
180     const AliHLTExternalTrackParam* track=reinterpret_cast<const AliHLTExternalTrackParam*>(pCurrent);
181     if (pCurrent+sizeof(AliHLTExternalTrackParam)+track->fNPoints*sizeof(UInt_t)>pEnd) {
182       iResult=-EINVAL; break;
183     }
184     tgtArray[i]=*track;
185     pCurrent+=sizeof(AliHLTExternalTrackParam)+track->fNPoints*sizeof(UInt_t);
186   }
187   if (iResult<0) tgtArray.clear();
188   else iResult=tgtArray.size();
189   return iResult;
190 }
191
192 UInt_t AliHLTGlobalBarrelTrack::GetNumberOfPoints() const
193 {
194   // see header file for class documentation
195   return fPoints.size();
196 }
197
198 const UInt_t* AliHLTGlobalBarrelTrack::GetPoints() const
199 {
200   // see header file for class documentation
201   if (fPoints.size()==0) return NULL;
202   return &fPoints[0];
203 }
204
205 int AliHLTGlobalBarrelTrack::SetPoints(const UInt_t* pArray, UInt_t arraySize)
206 {
207   // see header file for class documentation
208   if (!pArray || arraySize==0) return 0;
209   fPoints.resize(arraySize);
210   for (unsigned i=0; i<arraySize; i++) fPoints[i]=pArray[i];
211   return fPoints.size();
212 }
213
214 int AliHLTGlobalBarrelTrack::CalculateHelixParams()
215 {
216   // calculate radius and center of the helix
217   // using the global magnetic field
218   return CalculateHelixParams(AliHLTMisc::Instance().GetBz());
219 }
220
221 int AliHLTGlobalBarrelTrack::CalculateHelixParams(float bfield)
222 {
223   // calculate radius and center of the helix
224   if (TMath::Abs(bfield)<kAlmost0) {
225     // no magnetic field -> straight lines
226     fHelixRadius=kVeryBig;
227     fHelixCenterX=kVeryBig;
228     fHelixCenterY=kVeryBig;
229   } else {
230     fHelixRadius = GetSignedPt()/(-kB2C*bfield);
231     Double_t trackPhi = Phi()-GetAlpha();
232
233     //cout << "Helix: phi=" << trackPhi << " x=" << GetX() << " y=" << GetY() << endl;
234     fHelixCenterX = GetX() + fHelixRadius *  sin(trackPhi);
235     fHelixCenterY = GetY() - fHelixRadius *  cos(trackPhi);
236     //cout << "Helix: center" << " x=" << fHelixCenterX << " y=" << fHelixCenterY << endl;
237   }
238   return 0;
239 }
240
241 int AliHLTGlobalBarrelTrack::CalculateCrossingPoint(float xPlane, float alphaPlane, float& y, float& z)
242 {
243   // calculate crossing point of helix with a plane in yz
244   // in the local coordinates of the plane
245   int iResult=0;
246   if (TMath::Abs(fHelixRadius)<kAlmost0 &&
247       (iResult=CalculateHelixParams())<0) {
248     return iResult;
249   }
250
251   if (TMath::Abs(fHelixRadius)>=kVeryBig) {
252     // no magnetic field -> straight lines
253   } else {
254     // rotate helix center to local coordinates of the plane reference frame
255     float cosa=TMath::Cos(alphaPlane-GetAlpha());
256     float sina=TMath::Sin(alphaPlane-GetAlpha());
257     float cx= fHelixCenterX * cosa + fHelixCenterY * sina;
258     float cy=-fHelixCenterX * sina + fHelixCenterY * cosa;
259
260     // crossing point of helix with plane
261     Double_t aa = (cx - xPlane)*(cx - xPlane);
262     Double_t r2 = fHelixRadius*fHelixRadius;
263     if(aa > r2) // no crossing
264       return 0;
265
266     Double_t aa2 = sqrt(r2 - aa);
267     Double_t y1 = cy + aa2;
268     Double_t y2 = cy - aa2;
269     y = y1;
270     if(TMath::Abs(y2) < TMath::Abs(y1)) y = y2;
271   
272     // calculate the arc length between (x,y) and (x0,y0) with radius (cx,cy)
273     // reference point is (x0,y0) rotated by the diffence of the plane angle and
274     // the track reference frame angle alpha
275     // 1) angle of (x,y)
276     Double_t angle1 = atan2((y - cy),(xPlane - cx));
277     if(angle1 < 0) angle1 += TMath::TwoPi();
278
279     // 2) angle of (x0,y0)
280     float x0= GetX() * cosa + GetY() * sina;
281     float y0=-GetX() * sina + GetY() * cosa;
282     Double_t angle2 = atan2((y0 - cy),(x0 - cx));
283     if(angle2 < 0) angle2 += TMath::TwoPi();
284
285     // 3) angle between (x,y) and (x0,y0)
286     Double_t diffangle = angle1 - angle2;
287     diffangle = fmod(diffangle,TMath::TwoPi());
288
289     // 4) arc length
290     Double_t arclength = TMath::Abs(diffangle*fHelixRadius);
291
292     // 5) direction depending on whether going outwards or inwards
293     int direction=GetX()>xPlane?-1:1;
294     z = GetZ() + direction*arclength*GetTgl();
295
296     //cout << "x=" << xPlane << " y=" << y << " cx=" << cx << " cy=" << cy << " a1=" << angle1 << " a2=" << angle2 << " diffa=" << diffangle << " s=" << arclength << " z=" << z << endl;
297   }
298   return 1;
299 }
300
301 void AliHLTGlobalBarrelTrack::Print(Option_t* option) const
302 {
303   // see header file for class documentation
304   cout << "********* Track Id: " << fTrackID << " *******************" << endl;
305   AliExternalTrackParam::Print(option);
306 //   cout << "  Alpha "     << GetAlpha();
307 //   cout << "  X "         << GetX();
308 //   cout << "  Y "         << GetY();
309 //   cout << "  Z "         << GetZ() << endl;
310 //   cout << "  Snp "       << GetSnp();
311 //   cout << "  Tgl "       << GetTgl();
312 //   cout << "  Signed1Pt " << GetSigned1Pt() << endl;
313 }
314
315 void AliHLTGlobalBarrelTrack::Draw(Option_t *option)
316 {
317   /// Inherited from TObject, draw the track
318   float scale=250;
319   float center[2]={0.5,0.5};
320
321   if (TMath::Abs(fHelixRadius)<kAlmost0 &&
322       (CalculateHelixParams())<0) {
323     return;
324   }
325
326   TString strOption(option);
327   if (strOption.IsNull()) strOption="spacepoints trackarc";
328   std::auto_ptr<TObjArray> tokens(strOption.Tokenize(" "));
329   if (!tokens.get()) return;
330   for (int i=0; i<tokens->GetEntriesFast(); i++) {
331     if (!tokens->At(i)) continue;
332     const char* key="";
333     TString arg=tokens->At(i)->GetName();
334
335     key="scale=";
336     if (arg.BeginsWith(key)) {
337       arg.ReplaceAll(key, "");
338       scale=arg.Atof();
339       continue;
340     }
341     key="centerx=";
342     if (arg.BeginsWith(key)) {
343       arg.ReplaceAll(key, "");
344       center[0]=arg.Atof();
345       continue;
346     }
347     key="centery=";
348     if (arg.BeginsWith(key)) {
349       arg.ReplaceAll(key, "");
350       center[1]=arg.Atof();
351       continue;
352     }
353     key="spacepoints";
354     if (arg.CompareTo(key)==0) {
355       if (fSpacePoints) DrawProjXYSpacePoints(option, fSpacePoints, scale, center);
356       continue;
357     }
358     key="trackarc";
359     if (arg.CompareTo(key)==0) {
360       DrawProjXYTrack(option, scale, center);
361       continue;
362     }
363   }
364 }
365
366 int AliHLTGlobalBarrelTrack::DrawProjXYSpacePoints(Option_t */*option*/, const AliHLTSpacePointContainer* spacePoints, const float scale, float center[2])
367 {
368   /// draw space points
369   int markerColor=3;
370
371   if (!spacePoints) return -EINVAL;
372
373   const UInt_t* pointids=GetPoints();
374   for (unsigned i=0; i<GetNumberOfPoints() && pointids; i++) {
375     float clusterphi=spacePoints->GetPhi(pointids[i]);
376     float cosphi=TMath::Cos(clusterphi);
377     float sinphi=TMath::Sin(clusterphi);
378     float clusterx=spacePoints->GetX(pointids[i]);
379     float clustery=spacePoints->GetY(pointids[i]);
380     // rotate
381     float pointx= clusterx*sinphi + clustery*cosphi;
382     float pointy=-clusterx*cosphi + clustery*sinphi;
383
384     // FIXME: cleanup of marker objects
385     TMarker* m=new TMarker(pointx/(2*scale)+center[0], pointy/(2*scale)+center[1], 3);
386     m->SetMarkerColor(markerColor);
387     m->Draw("same");
388   }
389   return 0;
390 }
391
392 // FIXME: make this a general geometry definition
393 // through an abstract class interface
394 const Double_t gkTPCX[159] = {
395   85.195,
396   85.945,
397   86.695,
398   87.445,
399   88.195,
400   88.945,
401   89.695,
402   90.445,
403   91.195,
404   91.945,
405   92.695,
406   93.445,
407   94.195,
408   94.945,
409   95.695,
410   96.445,
411   97.195,
412   97.945,
413   98.695,
414   99.445,
415   100.195,
416   100.945,
417   101.695,
418   102.445,
419   103.195,
420   103.945,
421   104.695,
422   105.445,
423   106.195,
424   106.945,
425   107.695,
426   108.445,
427   109.195,
428   109.945,
429   110.695,
430   111.445,
431   112.195,
432   112.945,
433   113.695,
434   114.445,
435   115.195,
436   115.945,
437   116.695,
438   117.445,
439   118.195,
440   118.945,
441   119.695,
442   120.445,
443   121.195,
444   121.945,
445   122.695,
446   123.445,
447   124.195,
448   124.945,
449   125.695,
450   126.445,
451   127.195,
452   127.945,
453   128.695,
454   129.445,
455   130.195,
456   130.945,
457   131.695,
458   135.180,
459   136.180,
460   137.180,
461   138.180,
462   139.180,
463   140.180,
464   141.180,
465   142.180,
466   143.180,
467   144.180,
468   145.180,
469   146.180,
470   147.180,
471   148.180,
472   149.180,
473   150.180,
474   151.180,
475   152.180,
476   153.180,
477   154.180,
478   155.180,
479   156.180,
480   157.180,
481   158.180,
482   159.180,
483   160.180,
484   161.180,
485   162.180,
486   163.180,
487   164.180,
488   165.180,
489   166.180,
490   167.180,
491   168.180,
492   169.180,
493   170.180,
494   171.180,
495   172.180,
496   173.180,
497   174.180,
498   175.180,
499   176.180,
500   177.180,
501   178.180,
502   179.180,
503   180.180,
504   181.180,
505   182.180,
506   183.180,
507   184.180,
508   185.180,
509   186.180,
510   187.180,
511   188.180,
512   189.180,
513   190.180,
514   191.180,
515   192.180,
516   193.180,
517   194.180,
518   195.180,
519   196.180,
520   197.180,
521   198.180,
522   199.430,
523   200.930,
524   202.430,
525   203.930,
526   205.430,
527   206.930,
528   208.430,
529   209.930,
530   211.430,
531   212.930,
532   214.430,
533   215.930,
534   217.430,
535   218.930,
536   220.430,
537   221.930,
538   223.430,
539   224.930,
540   226.430,
541   227.930,
542   229.430,
543   230.930,
544   232.430,
545   233.930,
546   235.430,
547   236.930,
548   238.430,
549   239.930,
550   241.430,
551   242.930,
552   244.430,
553   245.930
554 };
555
556 int AliHLTGlobalBarrelTrack::DrawProjXYTrack(Option_t *option, const float scale, float center[2])
557 {
558   /// draw track
559   bool bDrawArc=false; // draw TArc
560   bool bNoTrackPoints=false; // don't draw track points
561   TString strOption(option);
562   if (strOption.IsNull()) strOption="spacepoints trackarc";
563   std::auto_ptr<TObjArray> tokens(strOption.Tokenize(" "));
564   if (!tokens.get()) return 0;
565   for (int i=0; i<tokens->GetEntriesFast(); i++) {
566     if (!tokens->At(i)) continue;
567     const char* key="";
568     TString arg=tokens->At(i)->GetName();
569
570     key="drawarc";
571     if (arg.BeginsWith(key)) {
572       bDrawArc=true;
573       continue;
574     }
575     key="notrackpoints";
576     if (arg.BeginsWith(key)) {
577       bNoTrackPoints=true;
578       continue;
579     }
580   }
581
582   float cosa=TMath::Cos(GetAlpha());
583   float sina=TMath::Sin(GetAlpha());
584
585   // first point
586   float firstpoint[2];
587   firstpoint[0]= GetX()*sina + GetY()*cosa;
588   firstpoint[1]=-GetX()*cosa + GetY()*sina;
589   {
590     //cout << " first point alpha=" << GetAlpha() << " x: " << firstpoint[0] << " y: " << firstpoint[1] << endl;
591     // FIXME: cleanup of marker objects
592     TMarker* m=new TMarker(firstpoint[0]/(2*scale)+center[0], firstpoint[1]/(2*scale)+center[1], 29);
593     m->SetMarkerSize(2);
594     m->SetMarkerColor(2);
595     m->Draw("same");
596   }
597
598   // draw points in step width and remember the last point
599   float lastpoint[2]={0.0, 0.0};
600   int firstpadrow=0;
601   for (; firstpadrow<159 && gkTPCX[firstpadrow]<GetX(); firstpadrow++);
602   DrawProjXYTrackPoints(option, scale, center, firstpadrow, -1, firstpoint);
603   DrawProjXYTrackPoints(option, scale, center, firstpadrow, 1, lastpoint);
604
605   if (bDrawArc) {
606     if (TMath::Abs(fHelixRadius)>=kVeryBig) {
607       // no magnetic field -> straight lines
608     } else {
609       // rotate helix center to local coordinates of the plane reference frame
610       float cx= fHelixCenterX * sina + fHelixCenterY * cosa;
611       float cy=-fHelixCenterX * cosa + fHelixCenterY * sina;
612
613       float diffx=cx-firstpoint[0];
614       float diffy=cy-firstpoint[1];
615       float phimin=0.0;
616       float phimax=2*TMath::Pi();
617       if (TMath::Abs(diffx)<kAlmost0) {
618         phimin=TMath::Pi()/2;
619       } else {
620         phimin=TMath::ATan(diffy/diffx);
621       }
622       if (diffx>0) phimin+=TMath::Pi();
623
624       diffx=cx-lastpoint[0];
625       diffy=cy-lastpoint[1];
626       if (TMath::Abs(diffx)<kAlmost0) {
627         phimax=TMath::Pi()/2;
628       } else {
629         phimax=TMath::ATan(diffy/diffx);
630       }
631       //cout << "diffx=" << diffx << " diffy=" << diffy << " phimin=" << phimin << " phimax=" << phimax << endl;
632       if (diffx>0) phimax+=TMath::Pi();
633       if (phimax<0 && phimin>=0 && 
634           phimax+TMath::TwoPi()-phimin<TMath::Pi()) phimax+=TMath::TwoPi();
635       //if (phimax<0 && TMath::Abs(phimax-phimin)<TMath::Pi()) phimax+=TMath::TwoPi();
636       if (phimax-phimin>TMath::Pi()) phimax-=TMath::TwoPi();
637
638       if (0/*phimin>phimax*/) {
639         float tmp=phimin;
640         phimin=phimax;
641         phimax=tmp;
642       }
643       phimin*=360.0/(2*TMath::Pi());
644       phimax*=360.0/(2*TMath::Pi());
645       //cout << " cx=" << cx << " cy=" << cy << " r=" << fHelixRadius << " phimin=" << phimin << " phimax=" << phimax << endl;
646       // FIXME: cleanup of graphics objects
647       TArc* tarc=new TArc(cx/(2*scale)+center[0], cy/(2*scale)+center[1], TMath::Abs(fHelixRadius)/(2*scale), phimin, phimax);
648       tarc->SetNoEdges();
649       tarc->SetFillStyle(0);
650       tarc->Draw("same");
651     }
652   }
653   return 0;
654 }
655
656 int AliHLTGlobalBarrelTrack::DrawProjXYTrackPoints(Option_t */*option*/, const float scale, const float center[2], int firstpadrow, int step, float point[2])
657 {
658   // draw points in step width and return the last point
659   float offsetAlpha=0.0;
660   float cosa=TMath::Cos(GetAlpha());
661   float sina=TMath::Sin(GetAlpha());
662   int markerColor=1;
663   for (int padrow=firstpadrow; padrow>=0 && padrow<159; padrow+=step) {
664     float x=gkTPCX[padrow];
665     float y=0.0;
666     float z=0.0;
667
668     int maxshift=9;
669     int shift=0;
670     int result=0;
671     do {
672       if ((result=CalculateCrossingPoint(x, GetAlpha()-offsetAlpha, y, z))<1) break;
673       float pointAlpha=TMath::ATan(y/x);
674       if (TMath::Abs(pointAlpha)>TMath::Pi()/18) {
675         offsetAlpha+=(pointAlpha>0?-1:1)*TMath::Pi()/9;
676         result=0;
677         markerColor++;
678         cosa=TMath::Cos(GetAlpha()-offsetAlpha);
679         sina=TMath::Sin(GetAlpha()-offsetAlpha);
680       }
681     } while (result==0 && shift++<maxshift);
682     if (result<1) continue;
683     point[0]= x*sina + y*cosa;
684     point[1]=-x*cosa + y*sina;
685
686     //cout << x << " : x=" << x << " y=" << y << endl;
687     // FIXME: cleanup of TMarker objects?
688     TMarker* m=new TMarker(point[0]/(2*scale)+center[0], point[1]/(2*scale)+center[1], z>=0?2:5);
689     m->SetMarkerColor(markerColor);
690     m->Draw("same");
691   }
692   return 0;
693 }
694
695 void AliHLTGlobalBarrelTrack::SetTrackGeometry(AliHLTTrackGeometry* points)
696 {
697   /// set the instance to the track points container
698   fTrackPoints=points; 
699   if (!fTrackPoints) return; 
700   fTrackPoints->SetTrackId(GetID());
701 }
702
703 int AliHLTGlobalBarrelTrack::AssociateSpacePoints(AliHLTTrackGeometry* trackpoints, AliHLTSpacePointContainer& spacepoints) const
704 {
705   /// associate the track space points to the calculated track points
706   AliHLTTrackGeometry* instance=trackpoints;
707   if (!instance) instance=fTrackPoints;
708   if (!instance) return 0;
709
710   UInt_t nofIds=GetNumberOfPoints();
711   const UInt_t* ids=GetPoints();
712   int result=instance->AssociateSpacePoints(ids, nofIds, spacepoints);
713   return result;
714 }
715
716 int AliHLTGlobalBarrelTrack::ReadTracks(const char* filename, TClonesArray& tgt, AliHLTComponentDataType /*dt*/, unsigned /*specification*/)
717 {
718   // open block from file and add to collection
719   if (!filename) return -EINVAL;
720   
721   TString input=filename;
722   input+="?filetype=raw";
723   std::auto_ptr<TFile> pFile(new TFile(input));
724   if (!pFile.get()) return -ENOMEM;
725   if (pFile->IsZombie()) return -ENOENT;
726
727   int iResult=0;
728   pFile->Seek(0);
729   std::auto_ptr<TArrayC> buffer(new TArrayC);
730   if (!buffer.get()) return -ENOMEM;
731
732   buffer->Set(pFile->GetSize());
733   if (pFile->ReadBuffer(buffer->GetArray(), buffer->GetSize())==0) {
734     const AliHLTTracksData* pTracks=reinterpret_cast<const AliHLTTracksData*>(buffer->GetArray());
735     vector<AliHLTGlobalBarrelTrack> tracks;
736     iResult=ConvertTrackDataArray(pTracks, buffer->GetSize(), tracks);
737     if (iResult>=0) {
738       int offset=tgt.GetEntriesFast();
739       tgt.ExpandCreate(offset+tracks.size());
740       for (unsigned i=0; i<tracks.size(); i++) {
741         new (tgt[offset+i]) AliHLTGlobalBarrelTrack(tracks[i]);
742       }
743       iResult=tracks.size();
744     } else {
745       //HLTError("failed to convert tracks from file %s size %d byte(s) ", filename, pFile->GetSize());
746     }
747   } else {
748     //HLTError("failed reading %d byte(s) from file %s", pFile->GetSize(), filename);
749     iResult=-ENODATA;
750   }
751
752   return iResult;
753 }
754
755 int AliHLTGlobalBarrelTrack::ReadTrackList(const char* listfile, TClonesArray& tgt, AliHLTComponentDataType dt, unsigned specification)
756 {
757   // open blank separated list of files and read tracks
758   ifstream list(listfile);
759   if (!list.good()) return -ENOENT;
760
761   int count=0;
762   TString file;
763   while (file.ReadLine(list)) {
764     //HLTInfo("adding tracks from file %s", file.Data());
765     int iResult=ReadTracks(file.Data(), tgt, dt, specification);
766     if (iResult<0) {
767       //HLTInfo("failed to add data from file %s: error %d", file.Data(), iResult);
768       return iResult;
769     }
770     count+=iResult;
771   }
772
773   return count;
774 }