]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
bug fix: reconstruction crash when the output buffer size exceed
[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 void AliHLTTPCCADisplay::SliceHitXYZ(int iRow, int iHit, double &x, double &y, double &z )
422 {
423   // get xyz of the hit
424
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   x = row.X();
432   y = y0 + fSlice->HitDataY( row, iHit ) * stepY;
433   z = z0 + fSlice->HitDataZ( row, iHit ) * stepZ;
434 }
435
436 void AliHLTTPCCADisplay::DrawSliceHit( int iRow, int iHit, int color, Size_t width )
437 {
438   // draw hit
439   if ( !fSlice ) return;
440
441   double x,y,z;
442   SliceHitXYZ( iRow, iHit, x, y, z );
443
444   SetSliceTransform( fSlice );
445
446   if ( color < 0 ) {
447     if ( 0 && fPerf ) {
448       //AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel lab
449       //= fPerf->GetClusterLabel( fSlice->Param().ISlice(), fSlice->HitInputID( row, iHit ) );
450       //color = GetColor( lab[0] + 1 );
451       //if ( lab[0] >= 0 ) {
452       //AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
453       //if ( mc.P() >= 1. ) color = kRed;
454       //else if ( fDrawOnlyRef ) return;
455       //}
456     } else color = GetColorZ( z );
457   }
458   if ( width > 0 )fMarker.SetMarkerSize( width );
459   else fMarker.SetMarkerSize( .3 );
460   fMarker.SetMarkerColor( color );
461   double vx, vy;
462   Slice2View( x, y, &vx, &vy );
463   fYX->cd();
464   fMarker.DrawMarker( vx, vy );
465   fZX->cd();
466   fMarker.DrawMarker( z, vy );
467 }
468
469 void AliHLTTPCCADisplay::DrawSliceHits( int color, Size_t width )
470 {
471
472   // draw hits
473
474   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
475     const AliHLTTPCCARow &row = fSlice->Row( iRow );
476     for ( int ih = 0; ih < row.NHits(); ih++ ) {
477       DrawSliceHit( iRow, ih, color, width );
478     }
479   }
480 }
481
482
483 void AliHLTTPCCADisplay::DrawSliceLink( int iRow, int iHit, int colorUp, int colorDn, int width )
484 {
485   // draw link between clusters
486
487   //if ( !fPerf ) return;
488   //AliHLTTPCCAGBTracker &tracker = *fGB;
489   if ( width < 0 ) width = 1.;
490   fLine.SetLineWidth( width );
491   int colUp = colorUp >= 0 ? colorUp : kMagenta;
492   int colDn = colorDn >= 0 ? colorDn : kBlack;
493   if ( iRow < 2 || iRow >= fSlice->Param().NRows() - 2 ) return;
494
495   const AliHLTTPCCARow& row = fSlice->Data().Row( iRow );
496
497   short iUp = fSlice->HitLinkUpData( row, iHit );
498   short iDn = fSlice->HitLinkDownData( row, iHit );
499
500
501   double p1[3], p2[3], p3[3];
502   SliceHitXYZ( iRow,  iHit, p1[0],p1[1],p1[2]);
503
504   double vx, vy, vx1, vy1;
505   Slice2View( p1[0], p1[1], &vx, &vy );
506
507   if ( iUp >= 0 ) {
508     SliceHitXYZ( iRow+2, iUp, p2[0],p2[1],p2[2]);
509     Slice2View( p2[0], p2[1], &vx1, &vy1 );
510     fLine.SetLineColor( colUp );
511     fYX->cd();
512     fLine.DrawLine( vx - .1, vy, vx1 - .1, vy1 );
513     fZX->cd();
514     fLine.DrawLine( p1[2] - 1., vy, p2[2] - 1., vy1 );
515   }
516   if ( iDn >= 0 ) {   
517     SliceHitXYZ( iRow-2, iDn, p3[0],p3[1],p3[2]);
518     Slice2View( p3[0], p3[1], &vx1, &vy1 );
519     fLine.SetLineColor( colDn );
520     fYX->cd();
521     fLine.DrawLine( vx + .1, vy, vx1 + .1, vy1 );
522     fZX->cd();
523     fLine.DrawLine( p1[2] + 1., vy, p3[2] + 1., vy1 );
524   }
525
526 }
527
528
529 void AliHLTTPCCADisplay::DrawSliceLinks( int colorUp, int colorDn, int width )
530 {
531   // draw links between clusters
532
533   for ( int iRow = 1; iRow < fSlice->Param().NRows() - 1; iRow++ ) {
534     const AliHLTTPCCARow& row = fSlice->Row( iRow );
535     for ( int ih = 0; ih < row.NHits(); ih++ ) {
536       DrawSliceLink( iRow, ih, colorUp, colorDn, width );
537     }
538   }
539 }
540
541
542
543 int AliHLTTPCCADisplay::GetTrackMC( const AliHLTTPCCADisplayTmpHit */*vHits*/, int /*NHits*/ )
544 {
545   // get MC label for the track
546   return 0;
547 #ifdef XXX
548   AliHLTTPCCAGBTracker &tracker = *fGB;
549
550   int label = -1;
551   double purity = 0;
552   int *lb = new int[NHits*3];
553   int nla = 0;
554   //std::cout<<"\n\nTrack hits mc: "<<std::endl;
555   for ( int ihit = 0; ihit < NHits; ihit++ ) {
556     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
557     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
558     if ( l.fLab[0] >= 0 ) lb[nla++] = l.fLab[0];
559     if ( l.fLab[1] >= 0 ) lb[nla++] = l.fLab[1];
560     if ( l.fLab[2] >= 0 ) lb[nla++] = l.fLab[2];
561     //std::cout<<ihit<<":  "<<l.fLab[0]<<" "<<l.fLab[1]<<" "<<l.fLab[2]<<std::endl;
562   }
563   sort( lb, lb + nla );
564   int labmax = -1, labcur = -1, lmax = 0, lcurr = 0, nh = 0;
565   //std::cout<<"MC track IDs :"<<std::endl;
566   for ( int i = 0; i < nla; i++ ) {
567     if ( lb[i] != labcur ) {
568       if ( 0 && i > 0 && lb[i-1] >= 0 ) {
569         AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[i-1]];
570         std::cout << lb[i-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
571                   << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
572                   << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
573
574       }
575       nh = 0;
576       if ( labcur >= 0 && lmax < lcurr ) {
577         lmax = lcurr;
578         labmax = labcur;
579       }
580       labcur = lb[i];
581       lcurr = 0;
582     }
583     lcurr++;
584     nh++;
585   }
586   if ( 0 && nla - 1 > 0 && lb[nla-1] >= 0 ) {
587     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[nla-1]];
588     std::cout << lb[nla-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
589               << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
590               << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
591
592   }
593   if ( labcur >= 0 && lmax < lcurr ) {
594     lmax = lcurr;
595     labmax = labcur;
596   }
597   lmax = 0;
598   for ( int ihit = 0; ihit < NHits; ihit++ ) {
599     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
600     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
601     if ( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax
602        ) lmax++;
603   }
604   label = labmax;
605   purity = ( ( NHits > 0 ) ? double( lmax ) / double( NHits ) : 0 );
606   if ( lb ) delete[] lb;
607   if ( purity < .9 ) label = -1;
608   return label;
609 #endif
610 }
611
612 bool AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrackParam /*t*/, double /*Alpha*/, const AliHLTTPCCADisplayTmpHit */*vHits*/,
613                                     int /*NHits*/, int /*color*/, int /*width*/, bool /*pPoint*/ )
614 {
615   // draw track
616   return 1;
617 #ifdef XXX
618   if ( NHits < 2 ) return 0;
619
620   //AliHLTTPCCAGBTracker &tracker = *fGB;
621   if ( width < 0 ) width = 2;
622
623   if ( fDrawOnlyRef ) {
624     int lab = GetTrackMC( vHits, NHits );
625     if ( lab < 0 ) return 0;
626     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
627     if ( mc.P() < 1 ) return 0;
628   }
629
630   if ( color < 0 ) {
631     //color = GetColorZ( (vz[0]+vz[mHits-1])/2. );
632     //color = GetColorK(t.GetKappa());
633     int lab = GetTrackMC( vHits, NHits );
634     color = GetColor( lab + 1 );
635     if ( lab >= 0 ) {
636       AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
637       if ( mc.P() >= 1. ) color = kRed;
638     }
639   }
640
641   if ( t.SinPhi() > .999 )  t.SetSinPhi( .999 );
642   else if ( t.SinPhi() < -.999 )  t.SetSinPhi( -.999 );
643
644   //  int iSlice = fSlice->Param().ISlice();
645
646   //sort(vHits, vHits + NHits, AliHLTTPCCADisplayTmpHit::CompareHitZ );
647
648   double vx[2000], vy[2000], vz[2000];
649   int mHits = 0;
650
651   //int oldSlice = -1;
652   double alpha = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
653   AliHLTTPCCATrackParam tt = t;
654
655   for ( int iHit = 0; iHit < NHits; iHit++ ) {
656
657     const AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[iHit].ID()];
658
659     double hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
660     double hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
661     double x0 = h.X(), y0 = h.Y(), z1 = h.Z();
662     double x1 = x0 * hCos + y0 * hSin;
663     double y1 = y0 * hCos - x0 * hSin;
664
665     {
666       double dx = x1 - tt.X();
667       double dy = y1 - tt.Y();
668       if ( dx*dx + dy*dy > 1. ) {
669         double dalpha = TMath::ATan2( dy, dx );
670         if ( tt.Rotate( dalpha ) ) {
671           alpha += dalpha;
672           hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
673           hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
674           x1 = x0 * hCos + y0 * hSin;
675           y1 = y0 * hCos - x0 * hSin;
676         }
677       }
678     }
679     SetSliceTransform( alpha );
680
681     //t.GetDCAPoint( x1, y1, z1, x1, y1, z1 );
682     std::cout << "mark 3" << std::endl;
683     bool ok = tt.TransportToX( x1, .999 );
684     std::cout << "mark 4" << std::endl;
685     if ( 1 || ok ) {
686       x1 = tt.X();
687       y1 = tt.Y();
688       z1 = tt.Z();
689     }
690
691     Slice2View( x1, y1, &x1, &y1 );
692     vx[mHits] = x1;
693     vy[mHits] = y1;
694     vz[mHits] = z1;
695     mHits++;
696     for ( int j = 0; j < 0; j++ ) {
697       x0 = h.X() + j; y0 = h.Y(); z1 = h.Z();
698       x1 = x0 * hCos + y0 * hSin;
699       y1 = y0 * hCos - x0 * hSin;
700       ok = tt.TransportToX( x1, .999 );
701       if ( ok ) {
702         x1 = tt.X();
703         y1 = tt.Y();
704         z1 = tt.Z();
705       }
706
707       Slice2View( x1, y1, &x1, &y1 );
708       vx[mHits] = x1;
709       vy[mHits] = y1;
710       vz[mHits] = z1;
711       mHits++;
712     }
713   }
714   if ( pPoint ) {
715     double x1 = t.X(), y1 = t.Y(), z1 = t.Z();
716     double a = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
717     SetSliceTransform( a );
718
719     Slice2View( x1, y1, &x1, &y1 );
720     double dx = x1 - vx[0];
721     double dy = y1 - vy[0];
722     //std::cout<<x1<<" "<<y1<<" "<<vx[0]<<" "<<vy[0]<<" "<<dx<<" "<<dy<<std::endl;
723     double d0 = dx * dx + dy * dy;
724     dx = x1 - vx[mHits-1];
725     dy = y1 - vy[mHits-1];
726     //std::cout<<x1<<" "<<y1<<" "<<vx[mHits-1]<<" "<<vy[mHits-1]<<" "<<dx<<" "<<dy<<std::endl;
727     double d1 = dx * dx + dy * dy;
728     //std::cout<<"d0, d1="<<d0<<" "<<d1<<std::endl;
729     if ( d1 < d0 ) {
730       vx[mHits] = x1;
731       vy[mHits] = y1;
732       vz[mHits] = z1;
733       mHits++;
734     } else {
735       for ( int i = mHits; i > 0; i-- ) {
736         vx[i] = vx[i-1];
737         vy[i] = vy[i-1];
738         vz[i] = vz[i-1];
739       }
740       vx[0] = x1;
741       vy[0] = y1;
742       vz[0] = z1;
743       mHits++;
744     }
745   }
746
747
748   fLine.SetLineColor( color );
749   fLine.SetLineWidth( width );
750   fArc.SetFillStyle( 0 );
751   fArc.SetLineColor( color );
752   fArc.SetLineWidth( width );
753   TPolyLine pl;
754   pl.SetLineColor( color );
755   pl.SetLineWidth( width );
756   TPolyLine plZ;
757   plZ.SetLineColor( color );
758   plZ.SetLineWidth( width );
759
760   fMarker.SetMarkerSize( width / 2. );
761   fMarker.SetMarkerColor( color );
762
763   fYX->cd();
764   pl.DrawPolyLine( mHits, vx, vy );
765   {
766     fMarker.DrawMarker( vx[0], vy[0] );
767     fMarker.DrawMarker( vx[mHits-1], vy[mHits-1] );
768   }
769   fZX->cd();
770   plZ.DrawPolyLine( mHits, vz, vy );
771   fMarker.DrawMarker( vz[0], vy[0] );
772   fMarker.DrawMarker( vz[mHits-1], vy[mHits-1] );
773
774   fLine.SetLineWidth( 1 );
775   return 1;
776 #endif
777 }
778
779
780 bool AliHLTTPCCADisplay::DrawTracklet( AliHLTTPCCATrackParam &/*track*/, const int */*hitstore*/, int /*color*/, int /*width*/, bool /*pPoint*/ )
781 {
782   // draw tracklet
783 #ifdef XXX
784   AliHLTTPCCAGBTracker &tracker = *fGB;
785   AliHLTTPCCADisplayTmpHit vHits[200];
786   int nHits = 0;
787   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
788     int iHit = hitstore[iRow];
789     if ( iHit < 0 ) continue;
790     const AliHLTTPCCARow &row = fSlice->Row( iRow );
791     int id = fSlice->HitInputID( row, iHit );
792     int iGBHit = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
793     const AliHLTTPCCAGBHit &h = tracker.Hits()[iGBHit];
794     vHits[nHits].SetID( iGBHit );
795     vHits[nHits].SetS( 0 );
796     vHits[nHits].SetZ( h.Z() );
797     nHits++;
798   }
799   return DrawTrack( track, -1, vHits, nHits, color, width, pPoint );
800 #endif
801   return 1;
802 }
803
804
805 void AliHLTTPCCADisplay::DrawSliceOutTrack( AliHLTTPCCATrackParam &/*t*/, double /*alpha*/, int /*itr*/, int /*color*/, int /*width*/ )
806 {
807   // draw slice track
808 #ifdef XXX
809   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
810   if ( track.NHits() < 2 ) return;
811
812   AliHLTTPCCAGBTracker &tracker = *fGB;
813   AliHLTTPCCADisplayTmpHit vHits[200];
814
815   for ( int ih = 0; ih < track.NHits(); ih++ ) {
816     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHit(track.FirstHitRef()+ih);
817     const AliHLTTPCCAGBHit &h = tracker.Hits()[id];
818     vHits[ih].SetID( id );
819     vHits[ih].SetS( 0 );
820     vHits[ih].SetZ( h.Z() );
821   }
822
823   DrawTrack( t, alpha, vHits, track.NHits(), color, width, 1 );
824 #endif
825 }
826
827 void AliHLTTPCCADisplay::DrawSliceOutTrack( int /*itr*/, int /*color*/, int /*width*/ )
828 {
829   // draw slice track
830 #ifdef XXX
831   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
832   if ( track.NHits() < 2 ) return;
833
834   AliHLTTPCCAGBTracker &tracker = *fGB;
835   AliHLTTPCCADisplayTmpHit vHits[200];
836
837   for ( int ih = 0; ih < track.NHits(); ih++ ) {
838     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHit(track.FirstHitRef()+ih);
839     const AliHLTTPCCAGBHit &h = tracker.Hits()[id];
840     vHits[ih].SetID( id );
841     vHits[ih].SetS( 0 );
842     vHits[ih].SetZ( h.Z() );
843   }
844
845   DrawTrack( track.StartPoint(), -1, vHits, track.NHits(), color, width );
846 #endif
847 }
848
849
850 void AliHLTTPCCADisplay::DrawSliceTrack( int /*itr*/, int /*color*/ )
851 {
852   // draw slice track
853 #ifdef XXX
854   const AliHLTTPCCATrack &track = fSlice->Tracks()[itr];
855   if ( track.NHits() < 2 ) return;
856
857   AliHLTTPCCAGBTracker &tracker = *fGB;
858   AliHLTTPCCADisplayTmpHit vHits[200];
859   for ( int ith = 0; ith < track.NHits(); ith++ ) {
860     AliHLTTPCCAHitId ic = ( fSlice->TrackHits()[track.FirstHitID()+ith] );
861     const AliHLTTPCCARow &row = fSlice->Row( ic );
862     int ih = ic.HitIndex();
863     int id = fSlice->HitInputID( row, ih );
864     int gbID = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
865     const AliHLTTPCCAGBHit &h = tracker.Hits()[gbID];
866     vHits[ith].SetID( gbID );
867     vHits[ith].SetS( 0 );
868     vHits[ith].SetZ( h.Z() );
869   }
870
871   DrawTrack( track.Param(), -1, vHits, track.NHits(), color, -1 );
872   //track.Param().Print();
873 #endif
874 }