]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
clean up
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCADisplay.cxx
1 // $Id$
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          *
4 // ALICE Experiment at CERN, All rights reserved.                           *
5 //                                                                          *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
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
20
21 #include "AliHLTTPCCADisplay.h"
22
23
24 #include "AliHLTTPCCATracker.h"
25 #include "AliHLTTPCCAStandaloneFramework.h"
26 #include "AliHLTTPCCARow.h"
27 #include "AliHLTTPCCATrack.h"
28 #include "AliHLTTPCCAPerformance.h"
29 #include "AliHLTTPCCAMCTrack.h"
30 #include "AliHLTTPCCAOutTrack.h"
31
32 #include "TString.h"
33 #include "Riostream.h"
34 #include "TMath.h"
35 #include "TStyle.h"
36 #include "TCanvas.h"
37 #include "TApplication.h"
38
39
40 class AliHLTTPCCADisplay::AliHLTTPCCADisplayTmpHit
41 {
42
43   public:
44
45     int ID() const { return fHitID; }
46     double S() const { return fS; }
47     double Z() const { return fZ; }
48
49     void SetID( int v ) { fHitID = v; }
50     void SetS( double v ) { fS = v; }
51     void SetZ( double v ) { fZ = v; }
52
53     static bool CompareHitDS( const AliHLTTPCCADisplayTmpHit &a,
54                               const AliHLTTPCCADisplayTmpHit  &b ) {
55       return ( a.fS < b.fS );
56     }
57
58     static bool CompareHitZ( const AliHLTTPCCADisplayTmpHit &a,
59                              const AliHLTTPCCADisplayTmpHit  &b ) {
60       return ( a.fZ < b.fZ );
61     }
62
63   private:
64
65     int fHitID; // hit ID
66     double fS;  // hit position on the XY track curve
67     double fZ;  // hit Z position
68
69 };
70
71
72
73 AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
74 {
75   // reference to static object
76   static AliHLTTPCCADisplay gAliHLTTPCCADisplay;
77   static bool firstCall = 1;
78   if ( firstCall ) {
79     if ( !gApplication ) new TApplication( "myapp", 0, 0 );
80     gAliHLTTPCCADisplay.Init();
81     firstCall = 0;
82   }
83   return gAliHLTTPCCADisplay;
84 }
85
86 AliHLTTPCCADisplay::AliHLTTPCCADisplay() : fYX( 0 ), fZX( 0 ), fAsk( 1 ), fSliceView( 1 ), fSlice( 0 ), fPerf( 0 ),
87     fCos( 1 ), fSin( 0 ), fZMin( -250 ), fZMax( 250 ), fYMin( -250 ), fYMax( 250 ), fSliceCos( 1 ), fSliceSin( 0 ),
88     fRInnerMin( 83.65 ), fRInnerMax( 133.3 ), fROuterMin( 133.5 ), fROuterMax( 247.7 ),
89     fTPCZMin( -250. ), fTPCZMax( 250 ), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex(), fDrawOnlyRef( 0 )
90 {
91   fPerf = &( AliHLTTPCCAPerformance::Instance() );
92   // constructor
93 }
94
95
96 AliHLTTPCCADisplay::AliHLTTPCCADisplay( const AliHLTTPCCADisplay& )
97     : fYX( 0 ), fZX( 0 ), fAsk( 1 ), fSliceView( 1 ), fSlice( 0 ), fPerf( 0 ),
98     fCos( 1 ), fSin( 0 ), fZMin( -250 ), fZMax( 250 ), fYMin( -250 ), fYMax( 250 ), fSliceCos( 1 ), fSliceSin( 0 ),
99     fRInnerMin( 83.65 ), fRInnerMax( 133.3 ), fROuterMin( 133.5 ), fROuterMax( 247.7 ),
100     fTPCZMin( -250. ), fTPCZMax( 250 ), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex(), fDrawOnlyRef( 0 )
101 {
102   // dummy
103 }
104
105 const AliHLTTPCCADisplay& AliHLTTPCCADisplay::operator=( const AliHLTTPCCADisplay& ) const
106 {
107   // dummy
108   return *this;
109 }
110
111 AliHLTTPCCADisplay::~AliHLTTPCCADisplay()
112 {
113   // destructor
114   delete fYX;
115   delete fZX;
116 }
117
118 void AliHLTTPCCADisplay::Init()
119 {
120   // initialization
121   gStyle->SetCanvasBorderMode( 0 );
122   gStyle->SetCanvasBorderSize( 1 );
123   gStyle->SetCanvasColor( 0 );
124   fYX = new TCanvas ( "YX", "YX window", -1, 0, 600, 600 );
125   fZX = new TCanvas ( "ZX", "ZX window", -610, 0, 590, 600 );
126   fMarker = TMarker( 0.0, 0.0, 20 );//6);
127   fDrawOnlyRef = 0;
128 }
129
130 void AliHLTTPCCADisplay::Update()
131 {
132   // update windows
133   if ( !fAsk ) return;
134   fYX->Update();
135   fZX->Update();
136   fYX->Print( "YX.pdf" );
137   fZX->Print( "ZX.pdf" );
138
139 }
140
141 void AliHLTTPCCADisplay::ClearView()
142 {
143   // clear windows
144   fYX->Clear();
145   fZX->Clear();
146 }
147
148 void AliHLTTPCCADisplay::Ask()
149 {
150   // wait for the pressed key, when "r" pressed, don't ask anymore
151   char symbol;
152   if ( fAsk ) {
153     Update();
154     std::cout << "ask> " << std::endl;
155     do {
156       std::cin.get( symbol );
157       if ( symbol == 'r' )
158         fAsk = false;
159     } while ( symbol != '\n' );
160   }
161 }
162
163
164 void AliHLTTPCCADisplay::SetSliceView()
165 {
166   // switch to slice view
167   fSliceView = 1;
168 }
169
170 void AliHLTTPCCADisplay::SetTPCView()
171 {
172   // switch to full TPC view
173   fSliceView = 0;
174   fCos = 1;
175   fSin = 0;
176   fZMin = fTPCZMin;
177   fZMax = fTPCZMax;
178   fYMin = -fROuterMax;
179   fYMax = fROuterMax;
180 }
181
182
183 void AliHLTTPCCADisplay::SetCurrentSlice( AliHLTTPCCATracker *slice )
184 {
185   // set reference to the current CA tracker, and read the current slice geometry
186   fSlice = slice;
187   SetSliceTransform( slice );
188   if ( fSliceView ) {
189     fCos = slice->Param().SinAlpha();
190     fSin = slice->Param().CosAlpha();
191     fZMin = slice->Param().ZMin();
192     fZMax = slice->Param().ZMax();
193     ClearView();
194     double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
195     double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
196     fYMin = -dr;
197     fYMax = dr;
198     double cx = 0;
199     double cy = r0;
200     double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
201     double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
202     fYX->Range( cx - dr, cy - dr*1.05, cx + dr, cy + dr );
203     fZX->Range( cz - dz, cy - dr*1.05, cz + dz, cy + dr );
204
205     //fYX->Range(cx-dr*.3, cy-dr*1.05, cx+dr*.3, cy-dr*.35);
206     //fZX->Range(cz-dz, cy-dr*1.05, cz+dz, cy-dr*.3);
207
208     //fYX->Range(cx-dr*.3, cy-dr*.8, cx-dr*.1, cy-dr*.75);
209     //fZX->Range(cz-dz*0, cy-dr*.8, cz+dz, cy-dr*.75);
210
211     //fYX->Range(cx-dr*.08, cy-dr*1., cx-dr*.02, cy-dr*0.7);
212     //fZX->Range(cz-dz*.2, cy-dr*1., cz-dz*.05, cy-dr*0.7);
213
214     //double x0 = cx-dr*.1, x1 = cx-dr*.05;
215     //double y0 = cy-dr*1.05, y1 = cy-dr*0.7;
216     //double z0 = cz-dz*.3, z1 = cz;
217     //double xc = (x0+x1)/2, yc= (y0+y1)/2, zc=(z0+z1)/2;
218     //double d = TMath::Max((x1-x0)/2,TMath::Max((y1-y0)/2,(z1-z0)/2));
219     //fYX->Range(xc-d, yc-d, xc+d, yc+d);
220     //fZX->Range(zc-d, yc-d, zc+d, yc+d);
221
222   }
223 }
224
225 void AliHLTTPCCADisplay::SetSliceTransform( double alpha )
226 {
227   fSliceCos = TMath::Cos( alpha );
228   fSliceSin = TMath::Sin( alpha );
229 }
230
231 void AliHLTTPCCADisplay::SetSliceTransform( AliHLTTPCCATracker *slice )
232 {
233   SetSliceTransform( slice->Param().Alpha() );
234 }
235
236
237 void AliHLTTPCCADisplay::DrawTPC()
238 {
239   // schematically draw TPC detector
240   fYX->Range( -fROuterMax, -fROuterMax, fROuterMax, fROuterMax );
241   //fYX->Range( -fROuterMax*.7, -fROuterMax, fROuterMax*0., -fROuterMax*.5);
242   fYX->Clear();
243   {
244     fArc.SetLineColor( kBlack );
245     fArc.SetFillStyle( 0 );
246     fYX->cd();
247     for ( int iSlice = 0; iSlice < 18; iSlice++ ) {
248       fCrown.SetLineColor( kBlack );
249       fCrown.SetFillStyle( 0 );
250       fCrown.DrawCrown( 0, 0, fRInnerMin, fRInnerMax, 360. / 18.*iSlice, 360. / 18.*( iSlice + 1 ) );
251       fCrown.DrawCrown( 0, 0, fROuterMin, fROuterMax, 360. / 18.*iSlice, 360. / 18.*( iSlice + 1 ) );
252     }
253   }
254   fZX->cd();
255   fZX->Range( fTPCZMin, -fROuterMax, fTPCZMax*1.1, fROuterMax );
256   //fZX->Range( fTPCZMax*.1, -fROuterMax, fTPCZMax*.3, -fROuterMax*0.5 );
257   fZX->Clear();
258 }
259
260 void AliHLTTPCCADisplay::DrawSlice( AliHLTTPCCATracker *slice, bool DrawRows )
261 {
262   // draw current the TPC slice
263   fYX->cd();
264   double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
265   double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
266   double cx = r0 * slice->Param().CosAlpha();
267   double cy = r0 * slice->Param().SinAlpha();
268   double raddeg = 180. / 3.1415;
269   double a0 = raddeg * .5 * ( slice->Param().AngleMax() + slice->Param().AngleMin() );
270   double da = raddeg * .5 * ( slice->Param().AngleMax() - slice->Param().AngleMin() );
271   if ( fSliceView ) {
272     cx = 0; cy = r0;
273     a0 = 90.;
274     fLatex.DrawLatex( cx - dr + dr*.05, cy - dr + dr*.05, Form( "YX, Slice %2i", slice->Param().ISlice() ) );
275   } else {
276     a0 += raddeg * TMath::ATan2( fSin, fCos );
277   }
278   fArc.SetLineColor( kBlack );
279   fArc.SetFillStyle( 0 );
280   fCrown.SetLineColor( kBlack );
281   fCrown.SetFillStyle( 0 );
282   fCrown.DrawCrown( 0, 0, fRInnerMin, fRInnerMax, a0 - da, a0 + da );
283   fCrown.DrawCrown( 0, 0, fROuterMin, fROuterMax, a0 - da, a0 + da );
284   //fCrown.DrawCrown(0,0, slice->Param().RMin(),slice->Param().RMax(), a0-da, a0+da );
285
286   fLine.SetLineColor( kBlack );
287
288   fZX->cd();
289
290   double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
291   double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
292   //fLine.DrawLine(cz+dz, cy-dr, cz+dz, cy+dr );
293   if ( fSliceView ) fLatex.DrawLatex( cz - dz + dz*.05, cy - dr + dr*.05, Form( "ZX, Slice %2i", slice->Param().ISlice() ) );
294
295   if ( DrawRows ) {
296     fLine.SetLineWidth( 1 );
297     fLine.SetLineColor( kBlack );
298     SetSliceTransform( fSlice );
299     for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
300       double x = fSlice->Row( iRow ).X();
301       double y = fSlice->Row( iRow ).MaxY();
302       double vx0, vy0, vx1, vy1;
303       Slice2View( x, y, &vx0, &vy0 );
304       Slice2View( x, -y, &vx1, &vy1 );
305       fYX->cd();
306       fLine.DrawLine( vx0, vy0, vx1, vy1 );
307       fZX->cd();
308       fLine.DrawLine( fTPCZMin, vy0, fTPCZMax, vy1 );
309     }
310   }
311
312 }
313
314
315 void AliHLTTPCCADisplay::Set2Slices( AliHLTTPCCATracker * const slice )
316 {
317   //* Set view for two neighbouring slices
318
319   fSlice = slice;
320   fSliceView = 0;
321   fCos = TMath::Cos( TMath::Pi() / 2 - ( slice->Param().Alpha() + 10. / 180.*TMath::Pi() ) );
322   fSin = TMath::Sin( TMath::Pi() / 2 - ( slice->Param().Alpha() + 10. / 180.*TMath::Pi() ) );
323   fZMin = slice->Param().ZMin();
324   fZMax = slice->Param().ZMax();
325   ClearView();
326   double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
327   double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
328   double cx = 0;
329   double cy = r0;
330   fYX->Range( cx - 1.3*dr, cy - 1.1*dr, cx + 1.3*dr, cy + 1.1*dr );
331   fYX->cd();
332   int islice = slice->Param().ISlice();
333   int jslice = slice->Param().ISlice() + 1;
334   if ( islice == 17 ) jslice = 0;
335   else if ( islice == 35 ) jslice = 18;
336   fLatex.DrawLatex( cx - 1.3*dr + 1.3*dr*.05, cy - dr + dr*.05, Form( "YX, Slices %2i/%2i", islice, jslice ) );
337   double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
338   double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
339   fZX->Range( cz - dz, cy - 1.1*dr, cz + dz, cy + 1.1*dr );//+dr);
340   fZX->cd();
341   fLatex.DrawLatex( cz - dz + dz*.05, cy - dr + dr*.05, Form( "ZX, Slices %2i/%2i", islice, jslice ) );
342 }
343
344 int AliHLTTPCCADisplay::GetColor( int i ) const
345 {
346   // Get color with respect to Z coordinate
347   const Color_t kMyColor[9] = { kGreen, kBlue, kYellow, kCyan, kOrange,
348                                 kSpring, kTeal, kAzure, kViolet
349                               };
350   if ( i < 0 ) i = 0;
351   if ( i == 0 ) return kBlack;
352   return kMyColor[( i-1 )%9];
353 }
354
355 int AliHLTTPCCADisplay::GetColorZ( double z ) const
356 {
357   // Get color with respect to Z coordinate
358   const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
359                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
360                                };
361
362   double zz = ( z - fZMin ) / ( fZMax - fZMin );
363   int iz = ( int ) ( zz * 11 );
364   if ( iz < 0 ) iz = 0;
365   if ( iz > 10 ) iz = 10;
366   return kMyColor[iz];
367 }
368
369 int AliHLTTPCCADisplay::GetColorY( double y ) const
370 {
371   // Get color with respect to Z coordinate
372   const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
373                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
374                                };
375
376   double yy = ( y - fYMin ) / ( fYMax - fYMin );
377   int iy = ( int ) ( yy * 11 );
378   if ( iy < 0 ) iy = 0;
379   if ( iy > 10 ) iy = 10;
380   return kMyColor[iy];
381 }
382
383 int AliHLTTPCCADisplay::GetColorK( double k ) const
384 {
385   // Get color with respect to Z coordinate
386   const Color_t kMyColor[11] = { kRed, kBlue, kYellow, kMagenta, kCyan,
387                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
388                                };
389   const double kCLight = 0.000299792458;
390   const double kBz = 5;
391   double k2QPt = 100;
392   if ( TMath::Abs( kBz ) > 1.e-4 ) k2QPt = 1. / ( kBz * kCLight );
393   double qPt = k * k2QPt;
394   double pt = 100;
395   if ( TMath::Abs( qPt ) > 1.e-4 ) pt = 1. / TMath::Abs( qPt );
396
397   double yy = ( pt - 0.1 ) / ( 1. - 0.1 );
398   int iy = ( int ) ( yy * 11 );
399   if ( iy < 0 ) iy = 0;
400   if ( iy > 10 ) iy = 10;
401   return kMyColor[iy];
402 }
403
404 void AliHLTTPCCADisplay::Global2View( double x, double y, double *xv, double *yv ) const
405 {
406   // convert coordinates global->view
407   *xv = x * fCos + y * fSin;
408   *yv = y * fCos - x * fSin;
409 }
410
411
412 void AliHLTTPCCADisplay::Slice2View( double x, double y, double *xv, double *yv ) const
413 {
414   // convert coordinates slice->view
415   double xg = x * fSliceCos - y * fSliceSin;
416   double yg = y * fSliceCos + x * fSliceSin;
417   *xv = xg * fCos - yg * fSin;
418   *yv = yg * fCos + xg * fSin;
419 }
420
421
422 void AliHLTTPCCADisplay::DrawSliceHit( int iRow, int iHit, int color, Size_t width )
423 {
424   // draw hit
425   if ( !fSlice ) return;
426   const AliHLTTPCCARow &row = fSlice->Row( iRow );
427   float y0 = row.Grid().YMin();
428   float z0 = row.Grid().ZMin();
429   float stepY = row.HstepY();
430   float stepZ = row.HstepZ();
431   float x = row.X();
432   float y = y0 + fSlice->HitDataY( row, iHit ) * stepY;
433   float z = z0 + fSlice->HitDataZ( row, iHit ) * stepZ;
434
435   SetSliceTransform( fSlice );
436
437   if ( color < 0 ) {
438     if ( 0 && fPerf ) {
439       //AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel lab
440       //= fPerf->GetClusterLabel( fSlice->Param().ISlice(), fSlice->HitInputID( row, iHit ) );
441       //color = GetColor( lab[0] + 1 );
442       //if ( lab[0] >= 0 ) {
443       //AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
444       //if ( mc.P() >= 1. ) color = kRed;
445       //else if ( fDrawOnlyRef ) return;
446       //}
447     } else color = GetColorZ( z );
448   }
449   if ( width > 0 )fMarker.SetMarkerSize( width );
450   else fMarker.SetMarkerSize( .3 );
451   fMarker.SetMarkerColor( color );
452   double vx, vy;
453   Slice2View( x, y, &vx, &vy );
454   fYX->cd();
455   fMarker.DrawMarker( vx, vy );
456   fZX->cd();
457   fMarker.DrawMarker( z, vy );
458 }
459
460 void AliHLTTPCCADisplay::DrawSliceHits( int color, Size_t width )
461 {
462
463   // draw hits
464
465   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
466     const AliHLTTPCCARow &row = fSlice->Row( iRow );
467     for ( int ih = 0; ih < row.NHits(); ih++ ) {
468       DrawSliceHit( iRow, ih, color, width );
469     }
470   }
471 }
472
473
474 void AliHLTTPCCADisplay::DrawSliceLink( int /*iRow*/, int /*iHit*/, int /*colorUp*/, int /*colorDn*/, int /*width*/ )
475 {
476   // draw link between clusters
477 #ifdef XXX
478   if ( !fPerf || !fGB ) return;
479   AliHLTTPCCAGBTracker &tracker = *fGB;
480   if ( width < 0 ) width = 1.;
481   fLine.SetLineWidth( width );
482   int colUp = colorUp >= 0 ? colorUp : kMagenta;
483   int colDn = colorDn >= 0 ? colorDn : kBlack;
484   if ( iRow < 2 || iRow >= fSlice->Param().NRows() - 2 ) return;
485
486   const AliHLTTPCCARow& row = fSlice->Row( iRow );
487   const AliHLTTPCCARow& rowUp = fSlice->Row( iRow + 2 );
488   const AliHLTTPCCARow& rowDn = fSlice->Row( iRow - 2 );
489
490   int id = fSlice->HitInputID( row, iHit );
491   const AliHLTTPCCAGBHit &h = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id];
492   short iUp = fSlice->HitLinkUpData( row, iHit );
493   short iDn = fSlice->HitLinkDownData( row, iHit );
494
495   if ( iUp >= 0 ) {
496     int id1 = fSlice->HitInputID( rowUp, iUp );
497     const AliHLTTPCCAGBHit &h1 = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id1];
498     double vx, vy, vx1, vy1;
499     Slice2View( h.X(), h.Y(), &vx, &vy );
500     Slice2View( h1.X(), h1.Y(), &vx1, &vy1 );
501     fLine.SetLineColor( colUp );
502     fYX->cd();
503     fLine.DrawLine( vx - .1, vy, vx1 - .1, vy1 );
504     fZX->cd();
505     fLine.DrawLine( h.Z() - 1., vy, h1.Z() - 1., vy1 );
506   }
507   if ( iDn >= 0 ) {
508     int id1 = fSlice->HitInputID( rowDn, iDn );
509     const AliHLTTPCCAGBHit &h1 = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id1];
510     double vx, vy, vx1, vy1;
511     Slice2View( h.X(), h.Y(), &vx, &vy );
512     Slice2View( h1.X(), h1.Y(), &vx1, &vy1 );
513     fLine.SetLineColor( colDn );
514     fYX->cd();
515     fLine.DrawLine( vx + .1, vy, vx1 + .1, vy1 );
516     fZX->cd();
517     fLine.DrawLine( h.Z() + 1., vy, h1.Z() + 1., vy1 );
518   }
519 #endif
520 }
521
522
523 void AliHLTTPCCADisplay::DrawSliceLinks( int colorUp, int colorDn, int width )
524 {
525   // draw links between clusters
526
527   for ( int iRow = 1; iRow < fSlice->Param().NRows() - 1; iRow++ ) {
528     const AliHLTTPCCARow& row = fSlice->Row( iRow );
529     for ( int ih = 0; ih < row.NHits(); ih++ ) {
530       DrawSliceLink( iRow, ih, colorUp, colorDn, width );
531     }
532   }
533 }
534
535
536
537 int AliHLTTPCCADisplay::GetTrackMC( const AliHLTTPCCADisplayTmpHit */*vHits*/, int /*NHits*/ )
538 {
539   // get MC label for the track
540   return 0;
541 #ifdef XXX
542   AliHLTTPCCAGBTracker &tracker = *fGB;
543
544   int label = -1;
545   double purity = 0;
546   int *lb = new int[NHits*3];
547   int nla = 0;
548   //std::cout<<"\n\nTrack hits mc: "<<std::endl;
549   for ( int ihit = 0; ihit < NHits; ihit++ ) {
550     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
551     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
552     if ( l.fLab[0] >= 0 ) lb[nla++] = l.fLab[0];
553     if ( l.fLab[1] >= 0 ) lb[nla++] = l.fLab[1];
554     if ( l.fLab[2] >= 0 ) lb[nla++] = l.fLab[2];
555     //std::cout<<ihit<<":  "<<l.fLab[0]<<" "<<l.fLab[1]<<" "<<l.fLab[2]<<std::endl;
556   }
557   sort( lb, lb + nla );
558   int labmax = -1, labcur = -1, lmax = 0, lcurr = 0, nh = 0;
559   //std::cout<<"MC track IDs :"<<std::endl;
560   for ( int i = 0; i < nla; i++ ) {
561     if ( lb[i] != labcur ) {
562       if ( 0 && i > 0 && lb[i-1] >= 0 ) {
563         AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[i-1]];
564         std::cout << lb[i-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
565                   << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
566                   << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
567
568       }
569       nh = 0;
570       if ( labcur >= 0 && lmax < lcurr ) {
571         lmax = lcurr;
572         labmax = labcur;
573       }
574       labcur = lb[i];
575       lcurr = 0;
576     }
577     lcurr++;
578     nh++;
579   }
580   if ( 0 && nla - 1 > 0 && lb[nla-1] >= 0 ) {
581     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[nla-1]];
582     std::cout << lb[nla-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
583               << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
584               << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
585
586   }
587   if ( labcur >= 0 && lmax < lcurr ) {
588     lmax = lcurr;
589     labmax = labcur;
590   }
591   lmax = 0;
592   for ( int ihit = 0; ihit < NHits; ihit++ ) {
593     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
594     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
595     if ( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax
596        ) lmax++;
597   }
598   label = labmax;
599   purity = ( ( NHits > 0 ) ? double( lmax ) / double( NHits ) : 0 );
600   if ( lb ) delete[] lb;
601   if ( purity < .9 ) label = -1;
602   return label;
603 #endif
604 }
605
606 bool AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrackParam /*t*/, double /*Alpha*/, const AliHLTTPCCADisplayTmpHit */*vHits*/,
607                                     int /*NHits*/, int /*color*/, int /*width*/, bool /*pPoint*/ )
608 {
609   // draw track
610   return 1;
611 #ifdef XXX
612   if ( NHits < 2 ) return 0;
613
614   //AliHLTTPCCAGBTracker &tracker = *fGB;
615   if ( width < 0 ) width = 2;
616
617   if ( fDrawOnlyRef ) {
618     int lab = GetTrackMC( vHits, NHits );
619     if ( lab < 0 ) return 0;
620     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
621     if ( mc.P() < 1 ) return 0;
622   }
623
624   if ( color < 0 ) {
625     //color = GetColorZ( (vz[0]+vz[mHits-1])/2. );
626     //color = GetColorK(t.GetKappa());
627     int lab = GetTrackMC( vHits, NHits );
628     color = GetColor( lab + 1 );
629     if ( lab >= 0 ) {
630       AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
631       if ( mc.P() >= 1. ) color = kRed;
632     }
633   }
634
635   if ( t.SinPhi() > .999 )  t.SetSinPhi( .999 );
636   else if ( t.SinPhi() < -.999 )  t.SetSinPhi( -.999 );
637
638   //  int iSlice = fSlice->Param().ISlice();
639
640   //sort(vHits, vHits + NHits, AliHLTTPCCADisplayTmpHit::CompareHitZ );
641
642   double vx[2000], vy[2000], vz[2000];
643   int mHits = 0;
644
645   //int oldSlice = -1;
646   double alpha = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
647   AliHLTTPCCATrackParam tt = t;
648
649   for ( int iHit = 0; iHit < NHits; iHit++ ) {
650
651     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[iHit].ID()];
652
653     double hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
654     double hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
655     double x0 = h.X(), y0 = h.Y(), z1 = h.Z();
656     double x1 = x0 * hCos + y0 * hSin;
657     double y1 = y0 * hCos - x0 * hSin;
658
659     {
660       double dx = x1 - tt.X();
661       double dy = y1 - tt.Y();
662       if ( dx*dx + dy*dy > 1. ) {
663         double dalpha = TMath::ATan2( dy, dx );
664         if ( tt.Rotate( dalpha ) ) {
665           alpha += dalpha;
666           hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
667           hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
668           x1 = x0 * hCos + y0 * hSin;
669           y1 = y0 * hCos - x0 * hSin;
670         }
671       }
672     }
673     SetSliceTransform( alpha );
674
675     //t.GetDCAPoint( x1, y1, z1, x1, y1, z1 );
676     std::cout << "mark 3" << std::endl;
677     bool ok = tt.TransportToX( x1, .999 );
678     std::cout << "mark 4" << std::endl;
679     if ( 1 || ok ) {
680       x1 = tt.X();
681       y1 = tt.Y();
682       z1 = tt.Z();
683     }
684
685     Slice2View( x1, y1, &x1, &y1 );
686     vx[mHits] = x1;
687     vy[mHits] = y1;
688     vz[mHits] = z1;
689     mHits++;
690     for ( int j = 0; j < 0; j++ ) {
691       x0 = h.X() + j; y0 = h.Y(); z1 = h.Z();
692       x1 = x0 * hCos + y0 * hSin;
693       y1 = y0 * hCos - x0 * hSin;
694       ok = tt.TransportToX( x1, .999 );
695       if ( ok ) {
696         x1 = tt.X();
697         y1 = tt.Y();
698         z1 = tt.Z();
699       }
700
701       Slice2View( x1, y1, &x1, &y1 );
702       vx[mHits] = x1;
703       vy[mHits] = y1;
704       vz[mHits] = z1;
705       mHits++;
706     }
707   }
708   if ( pPoint ) {
709     double x1 = t.X(), y1 = t.Y(), z1 = t.Z();
710     double a = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
711     SetSliceTransform( a );
712
713     Slice2View( x1, y1, &x1, &y1 );
714     double dx = x1 - vx[0];
715     double dy = y1 - vy[0];
716     //std::cout<<x1<<" "<<y1<<" "<<vx[0]<<" "<<vy[0]<<" "<<dx<<" "<<dy<<std::endl;
717     double d0 = dx * dx + dy * dy;
718     dx = x1 - vx[mHits-1];
719     dy = y1 - vy[mHits-1];
720     //std::cout<<x1<<" "<<y1<<" "<<vx[mHits-1]<<" "<<vy[mHits-1]<<" "<<dx<<" "<<dy<<std::endl;
721     double d1 = dx * dx + dy * dy;
722     //std::cout<<"d0, d1="<<d0<<" "<<d1<<std::endl;
723     if ( d1 < d0 ) {
724       vx[mHits] = x1;
725       vy[mHits] = y1;
726       vz[mHits] = z1;
727       mHits++;
728     } else {
729       for ( int i = mHits; i > 0; i-- ) {
730         vx[i] = vx[i-1];
731         vy[i] = vy[i-1];
732         vz[i] = vz[i-1];
733       }
734       vx[0] = x1;
735       vy[0] = y1;
736       vz[0] = z1;
737       mHits++;
738     }
739   }
740
741
742   fLine.SetLineColor( color );
743   fLine.SetLineWidth( width );
744   fArc.SetFillStyle( 0 );
745   fArc.SetLineColor( color );
746   fArc.SetLineWidth( width );
747   TPolyLine pl;
748   pl.SetLineColor( color );
749   pl.SetLineWidth( width );
750   TPolyLine plZ;
751   plZ.SetLineColor( color );
752   plZ.SetLineWidth( width );
753
754   fMarker.SetMarkerSize( width / 2. );
755   fMarker.SetMarkerColor( color );
756
757   fYX->cd();
758   pl.DrawPolyLine( mHits, vx, vy );
759   {
760     fMarker.DrawMarker( vx[0], vy[0] );
761     fMarker.DrawMarker( vx[mHits-1], vy[mHits-1] );
762   }
763   fZX->cd();
764   plZ.DrawPolyLine( mHits, vz, vy );
765   fMarker.DrawMarker( vz[0], vy[0] );
766   fMarker.DrawMarker( vz[mHits-1], vy[mHits-1] );
767
768   fLine.SetLineWidth( 1 );
769   return 1;
770 #endif
771 }
772
773
774 bool AliHLTTPCCADisplay::DrawTracklet( AliHLTTPCCATrackParam &/*track*/, const int */*hitstore*/, int /*color*/, int /*width*/, bool /*pPoint*/ )
775 {
776   // draw tracklet
777 #ifdef XXX
778   AliHLTTPCCAGBTracker &tracker = *fGB;
779   AliHLTTPCCADisplayTmpHit vHits[200];
780   int nHits = 0;
781   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
782     int iHit = hitstore[iRow];
783     if ( iHit < 0 ) continue;
784     const AliHLTTPCCARow &row = fSlice->Row( iRow );
785     int id = fSlice->HitInputID( row, iHit );
786     int iGBHit = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
787     const AliHLTTPCCAGBHit &h = tracker.Hits()[iGBHit];
788     vHits[nHits].SetID( iGBHit );
789     vHits[nHits].SetS( 0 );
790     vHits[nHits].SetZ( h.Z() );
791     nHits++;
792   }
793   return DrawTrack( track, -1, vHits, nHits, color, width, pPoint );
794 #endif
795   return 1;
796 }
797
798
799 void AliHLTTPCCADisplay::DrawSliceOutTrack( AliHLTTPCCATrackParam &/*t*/, double /*alpha*/, int /*itr*/, int /*color*/, int /*width*/ )
800 {
801   // draw slice track
802 #ifdef XXX
803   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
804   if ( track.NHits() < 2 ) return;
805
806   AliHLTTPCCAGBTracker &tracker = *fGB;
807   AliHLTTPCCADisplayTmpHit vHits[200];
808
809   for ( int ih = 0; ih < track.NHits(); ih++ ) {
810     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHits()[track.FirstHitRef()+ih];
811     const AliHLTTPCCAGBHit &h = tracker.Hits()[id];
812     vHits[ih].SetID( id );
813     vHits[ih].SetS( 0 );
814     vHits[ih].SetZ( h.Z() );
815   }
816
817   DrawTrack( t, alpha, vHits, track.NHits(), color, width, 1 );
818 #endif
819 }
820
821 void AliHLTTPCCADisplay::DrawSliceOutTrack( int /*itr*/, int /*color*/, int /*width*/ )
822 {
823   // draw slice track
824 #ifdef XXX
825   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
826   if ( track.NHits() < 2 ) return;
827
828   AliHLTTPCCAGBTracker &tracker = *fGB;
829   AliHLTTPCCADisplayTmpHit vHits[200];
830
831   for ( int ih = 0; ih < track.NHits(); ih++ ) {
832     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHits()[track.FirstHitRef()+ih];
833     const AliHLTTPCCAGBHit &h = tracker.Hits()[id];
834     vHits[ih].SetID( id );
835     vHits[ih].SetS( 0 );
836     vHits[ih].SetZ( h.Z() );
837   }
838
839   DrawTrack( track.StartPoint(), -1, vHits, track.NHits(), color, width );
840 #endif
841 }
842
843
844 void AliHLTTPCCADisplay::DrawSliceTrack( int /*itr*/, int /*color*/ )
845 {
846   // draw slice track
847 #ifdef XXX
848   const AliHLTTPCCATrack &track = fSlice->Tracks()[itr];
849   if ( track.NHits() < 2 ) return;
850
851   AliHLTTPCCAGBTracker &tracker = *fGB;
852   AliHLTTPCCADisplayTmpHit vHits[200];
853   for ( int ith = 0; ith < track.NHits(); ith++ ) {
854     AliHLTTPCCAHitId ic = ( fSlice->TrackHits()[track.FirstHitID()+ith] );
855     const AliHLTTPCCARow &row = fSlice->Row( ic );
856     int ih = ic.HitIndex();
857     int id = fSlice->HitInputID( row, ih );
858     int gbID = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
859     const AliHLTTPCCAGBHit &h = tracker.Hits()[gbID];
860     vHits[ith].SetID( gbID );
861     vHits[ith].SetS( 0 );
862     vHits[ith].SetZ( h.Z() );
863   }
864
865   DrawTrack( track.Param(), -1, vHits, track.NHits(), color, -1 );
866   //track.Param().Print();
867 #endif
868 }