]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
c0890b0a7d7f8d47b72d1c23ec9b85d2d74fd80f
[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 "AliHLTTPCCAGBTracker.h"
26 #include "AliHLTTPCCARow.h"
27 #include "AliHLTTPCCATrack.h"
28 #include "AliHLTTPCCAGBTrack.h"
29 #include "AliHLTTPCCAGBHit.h"
30 #include "AliHLTTPCCAPerformance.h"
31 #include "AliHLTTPCCAMCTrack.h"
32 #include "AliHLTTPCCAOutTrack.h"
33
34 #include "TString.h"
35 #include "Riostream.h"
36 #include "TMath.h"
37 #include "TStyle.h"
38 #include "TCanvas.h"
39 #include "TApplication.h"
40
41
42 class AliHLTTPCCADisplay::AliHLTTPCCADisplayTmpHit
43 {
44
45   public:
46
47     int ID() const { return fHitID; }
48     double S() const { return fS; }
49     double Z() const { return fZ; }
50
51     void SetID( int v ) { fHitID = v; }
52     void SetS( double v ) { fS = v; }
53     void SetZ( double v ) { fZ = v; }
54
55     static bool CompareHitDS( const AliHLTTPCCADisplayTmpHit &a,
56                                 const AliHLTTPCCADisplayTmpHit  &b ) {
57       return ( a.fS < b.fS );
58     }
59
60     static bool CompareHitZ( const AliHLTTPCCADisplayTmpHit &a,
61                                const AliHLTTPCCADisplayTmpHit  &b ) {
62       return ( a.fZ < b.fZ );
63     }
64
65   private:
66
67     int fHitID; // hit ID
68     double fS;  // hit position on the XY track curve
69     double fZ;  // hit Z position
70
71 };
72
73
74
75 AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
76 {
77   // reference to static object
78   static AliHLTTPCCADisplay gAliHLTTPCCADisplay;
79   static bool firstCall = 1;
80   if ( firstCall ) {
81     if ( !gApplication ) new TApplication( "myapp", 0, 0 );
82     gAliHLTTPCCADisplay.Init();
83     firstCall = 0;
84   }
85   return gAliHLTTPCCADisplay;
86 }
87
88 AliHLTTPCCADisplay::AliHLTTPCCADisplay() : fYX( 0 ), fZX( 0 ), fAsk( 1 ), fSliceView( 1 ), fSlice( 0 ), fGB( 0 ), fPerf( 0 ),
89     fCos( 1 ), fSin( 0 ), fZMin( -250 ), fZMax( 250 ), fYMin( -250 ), fYMax( 250 ), fSliceCos( 1 ), fSliceSin( 0 ),
90     fRInnerMin( 83.65 ), fRInnerMax( 133.3 ), fROuterMin( 133.5 ), fROuterMax( 247.7 ),
91     fTPCZMin( -250. ), fTPCZMax( 250 ), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex(), fDrawOnlyRef( 0 )
92 {
93   fPerf = &( AliHLTTPCCAPerformance::Instance() );
94   // constructor
95 }
96
97
98 AliHLTTPCCADisplay::AliHLTTPCCADisplay( const AliHLTTPCCADisplay& )
99     : fYX( 0 ), fZX( 0 ), fAsk( 1 ), fSliceView( 1 ), fSlice( 0 ), fGB( 0 ), fPerf( 0 ),
100     fCos( 1 ), fSin( 0 ), fZMin( -250 ), fZMax( 250 ), fYMin( -250 ), fYMax( 250 ), fSliceCos( 1 ), fSliceSin( 0 ),
101     fRInnerMin( 83.65 ), fRInnerMax( 133.3 ), fROuterMin( 133.5 ), fROuterMax( 247.7 ),
102     fTPCZMin( -250. ), fTPCZMax( 250 ), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex(), fDrawOnlyRef( 0 )
103 {
104   // dummy
105 }
106
107 const AliHLTTPCCADisplay& AliHLTTPCCADisplay::operator=( const AliHLTTPCCADisplay& ) const
108 {
109   // dummy
110   return *this;
111 }
112
113 AliHLTTPCCADisplay::~AliHLTTPCCADisplay()
114 {
115   // destructor
116   delete fYX;
117   delete fZX;
118 }
119
120 void AliHLTTPCCADisplay::Init()
121 {
122   // initialization
123   gStyle->SetCanvasBorderMode( 0 );
124   gStyle->SetCanvasBorderSize( 1 );
125   gStyle->SetCanvasColor( 0 );
126   fYX = new TCanvas ( "YX", "YX window", -1, 0, 600, 600 );
127   fZX = new TCanvas ( "ZX", "ZX window", -610, 0, 590, 600 );
128   fMarker = TMarker( 0.0, 0.0, 20 );//6);
129   fDrawOnlyRef = 0;
130 }
131
132 void AliHLTTPCCADisplay::Update()
133 {
134   // update windows
135   if ( !fAsk ) return;
136   fYX->Update();
137   fZX->Update();
138   fYX->Print( "YX.pdf" );
139   fZX->Print( "ZX.pdf" );
140
141 }
142
143 void AliHLTTPCCADisplay::ClearView()
144 {
145   // clear windows
146   fYX->Clear();
147   fZX->Clear();
148 }
149
150 void AliHLTTPCCADisplay::Ask()
151 {
152   // whait for the pressed key, when "r" pressed, don't ask anymore
153   char symbol;
154   if ( fAsk ) {
155     Update();
156     std::cout << "ask> " << std::endl;
157     do {
158       std::cin.get( symbol );
159       if ( symbol == 'r' )
160         fAsk = false;
161     } while ( symbol != '\n' );
162   }
163 }
164
165
166 void AliHLTTPCCADisplay::SetSliceView()
167 {
168   // switch to slice view
169   fSliceView = 1;
170 }
171
172 void AliHLTTPCCADisplay::SetTPCView()
173 {
174   // switch to full TPC view
175   fSliceView = 0;
176   fCos = 1;
177   fSin = 0;
178   fZMin = fTPCZMin;
179   fZMax = fTPCZMax;
180   fYMin = -fROuterMax;
181   fYMax = fROuterMax;
182 }
183
184
185 void AliHLTTPCCADisplay::SetGB( AliHLTTPCCAGBTracker * const GBTracker )
186 {
187   fGB = GBTracker;
188 }
189
190 void AliHLTTPCCADisplay::SetCurrentSlice( AliHLTTPCCATracker *slice )
191 {
192   // set reference to the current CA tracker, and read the current slice geometry
193   fSlice = slice;
194   SetSliceTransform( slice );
195   if ( fSliceView ) {
196     fCos = slice->Param().SinAlpha();
197     fSin = slice->Param().CosAlpha();
198     fZMin = slice->Param().ZMin();
199     fZMax = slice->Param().ZMax();
200     ClearView();
201     double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
202     double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
203     fYMin = -dr;
204     fYMax = dr;
205     double cx = 0;
206     double cy = r0;
207     double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
208     double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
209     fYX->Range( cx - dr, cy - dr*1.05, cx + dr, cy + dr );
210     fZX->Range( cz - dz, cy - dr*1.05, cz + dz, cy + dr );
211
212     //fYX->Range(cx-dr*.3, cy-dr*1.05, cx+dr*.3, cy-dr*.35);
213     //fZX->Range(cz-dz, cy-dr*1.05, cz+dz, cy-dr*.3);
214
215     //fYX->Range(cx-dr*.3, cy-dr*.8, cx-dr*.1, cy-dr*.75);
216     //fZX->Range(cz-dz*0, cy-dr*.8, cz+dz, cy-dr*.75);
217
218     //fYX->Range(cx-dr*.08, cy-dr*1., cx-dr*.02, cy-dr*0.7);
219     //fZX->Range(cz-dz*.2, cy-dr*1., cz-dz*.05, cy-dr*0.7);
220
221     //double x0 = cx-dr*.1, x1 = cx-dr*.05;
222     //double y0 = cy-dr*1.05, y1 = cy-dr*0.7;
223     //double z0 = cz-dz*.3, z1 = cz;
224     //double xc = (x0+x1)/2, yc= (y0+y1)/2, zc=(z0+z1)/2;
225     //double d = TMath::Max((x1-x0)/2,TMath::Max((y1-y0)/2,(z1-z0)/2));
226     //fYX->Range(xc-d, yc-d, xc+d, yc+d);
227     //fZX->Range(zc-d, yc-d, zc+d, yc+d);
228
229   }
230 }
231
232 void AliHLTTPCCADisplay::SetSliceTransform( double alpha )
233 {
234   fSliceCos = TMath::Cos( alpha );
235   fSliceSin = TMath::Sin( alpha );
236 }
237
238 void AliHLTTPCCADisplay::SetSliceTransform( AliHLTTPCCATracker *slice )
239 {
240   SetSliceTransform( slice->Param().Alpha() );
241 }
242
243
244 void AliHLTTPCCADisplay::DrawTPC()
245 {
246   // schematically draw TPC detector
247   fYX->Range( -fROuterMax, -fROuterMax, fROuterMax, fROuterMax );
248   //fYX->Range( -fROuterMax*.7, -fROuterMax, fROuterMax*0., -fROuterMax*.5);
249   fYX->Clear();
250   {
251     fArc.SetLineColor( kBlack );
252     fArc.SetFillStyle( 0 );
253     fYX->cd();
254     for ( int iSlice = 0; iSlice < 18; iSlice++ ) {
255       fCrown.SetLineColor( kBlack );
256       fCrown.SetFillStyle( 0 );
257       fCrown.DrawCrown( 0, 0, fRInnerMin, fRInnerMax, 360. / 18.*iSlice, 360. / 18.*( iSlice + 1 ) );
258       fCrown.DrawCrown( 0, 0, fROuterMin, fROuterMax, 360. / 18.*iSlice, 360. / 18.*( iSlice + 1 ) );
259     }
260   }
261   fZX->cd();
262   fZX->Range( fTPCZMin, -fROuterMax, fTPCZMax*1.1, fROuterMax );
263   //fZX->Range( fTPCZMax*.1, -fROuterMax, fTPCZMax*.3, -fROuterMax*0.5 );
264   fZX->Clear();
265 }
266
267 void AliHLTTPCCADisplay::DrawSlice( AliHLTTPCCATracker *slice, bool DrawRows )
268 {
269   // draw current the TPC slice
270   fYX->cd();
271   double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
272   double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
273   double cx = r0 * slice->Param().CosAlpha();
274   double cy = r0 * slice->Param().SinAlpha();
275   double raddeg = 180. / 3.1415;
276   double a0 = raddeg * .5 * ( slice->Param().AngleMax() + slice->Param().AngleMin() );
277   double da = raddeg * .5 * ( slice->Param().AngleMax() - slice->Param().AngleMin() );
278   if ( fSliceView ) {
279     cx = 0; cy = r0;
280     a0 = 90.;
281     fLatex.DrawLatex( cx - dr + dr*.05, cy - dr + dr*.05, Form( "YX, Slice %2i", slice->Param().ISlice() ) );
282   } else {
283     a0 += raddeg * TMath::ATan2( fSin, fCos );
284   }
285   fArc.SetLineColor( kBlack );
286   fArc.SetFillStyle( 0 );
287   fCrown.SetLineColor( kBlack );
288   fCrown.SetFillStyle( 0 );
289   fCrown.DrawCrown( 0, 0, fRInnerMin, fRInnerMax, a0 - da, a0 + da );
290   fCrown.DrawCrown( 0, 0, fROuterMin, fROuterMax, a0 - da, a0 + da );
291   //fCrown.DrawCrown(0,0, slice->Param().RMin(),slice->Param().RMax(), a0-da, a0+da );
292
293   fLine.SetLineColor( kBlack );
294
295   fZX->cd();
296
297   double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
298   double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
299   //fLine.DrawLine(cz+dz, cy-dr, cz+dz, cy+dr );
300   if ( fSliceView ) fLatex.DrawLatex( cz - dz + dz*.05, cy - dr + dr*.05, Form( "ZX, Slice %2i", slice->Param().ISlice() ) );
301
302   if ( DrawRows ) {
303     fLine.SetLineWidth( 1 );
304     fLine.SetLineColor( kBlack );
305     SetSliceTransform( fSlice );
306     for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
307       double x = fSlice->Row( iRow ).X();
308       double y = fSlice->Row( iRow ).MaxY();
309       double vx0, vy0, vx1, vy1;
310       Slice2View( x, y, &vx0, &vy0 );
311       Slice2View( x, -y, &vx1, &vy1 );
312       fYX->cd();
313       fLine.DrawLine( vx0, vy0, vx1, vy1 );
314       fZX->cd();
315       fLine.DrawLine( fTPCZMin, vy0, fTPCZMax, vy1 );
316     }
317   }
318
319 }
320
321
322 void AliHLTTPCCADisplay::Set2Slices( AliHLTTPCCATracker * const slice )
323 {
324   //* Set view for two neighbouring slices
325
326   fSlice = slice;
327   fSliceView = 0;
328   fCos = TMath::Cos( TMath::Pi() / 2 - ( slice->Param().Alpha() + 10. / 180.*TMath::Pi() ) );
329   fSin = TMath::Sin( TMath::Pi() / 2 - ( slice->Param().Alpha() + 10. / 180.*TMath::Pi() ) );
330   fZMin = slice->Param().ZMin();
331   fZMax = slice->Param().ZMax();
332   ClearView();
333   double r0 = .5 * ( slice->Param().RMax() + slice->Param().RMin() );
334   double dr = .5 * ( slice->Param().RMax() - slice->Param().RMin() );
335   double cx = 0;
336   double cy = r0;
337   fYX->Range( cx - 1.3*dr, cy - 1.1*dr, cx + 1.3*dr, cy + 1.1*dr );
338   fYX->cd();
339   int islice = slice->Param().ISlice();
340   int jslice = slice->Param().ISlice() + 1;
341   if ( islice == 17 ) jslice = 0;
342   else if ( islice == 35 ) jslice = 18;
343   fLatex.DrawLatex( cx - 1.3*dr + 1.3*dr*.05, cy - dr + dr*.05, Form( "YX, Slices %2i/%2i", islice, jslice ) );
344   double cz = .5 * ( slice->Param().ZMax() + slice->Param().ZMin() );
345   double dz = .5 * ( slice->Param().ZMax() - slice->Param().ZMin() ) * 1.2;
346   fZX->Range( cz - dz, cy - 1.1*dr, cz + dz, cy + 1.1*dr );//+dr);
347   fZX->cd();
348   fLatex.DrawLatex( cz - dz + dz*.05, cy - dr + dr*.05, Form( "ZX, Slices %2i/%2i", islice, jslice ) );
349 }
350
351 int AliHLTTPCCADisplay::GetColor( int i ) const
352 {
353   // Get color with respect to Z coordinate
354   const Color_t kMyColor[9] = { kGreen, kBlue, kYellow, kCyan, kOrange,
355                                 kSpring, kTeal, kAzure, kViolet
356                               };
357   if ( i < 0 ) i = 0;
358   if ( i == 0 ) return kBlack;
359   return kMyColor[( i-1 )%9];
360 }
361
362 int AliHLTTPCCADisplay::GetColorZ( double z ) const
363 {
364   // Get color with respect to Z coordinate
365   const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
366                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
367                                };
368
369   double zz = ( z - fZMin ) / ( fZMax - fZMin );
370   int iz = ( int ) ( zz * 11 );
371   if ( iz < 0 ) iz = 0;
372   if ( iz > 10 ) iz = 10;
373   return kMyColor[iz];
374 }
375
376 int AliHLTTPCCADisplay::GetColorY( double y ) const
377 {
378   // Get color with respect to Z coordinate
379   const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
380                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
381                                };
382
383   double yy = ( y - fYMin ) / ( fYMax - fYMin );
384   int iy = ( int ) ( yy * 11 );
385   if ( iy < 0 ) iy = 0;
386   if ( iy > 10 ) iy = 10;
387   return kMyColor[iy];
388 }
389
390 int AliHLTTPCCADisplay::GetColorK( double k ) const
391 {
392   // Get color with respect to Z coordinate
393   const Color_t kMyColor[11] = { kRed, kBlue, kYellow, kMagenta, kCyan,
394                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
395                                };
396   const double kCLight = 0.000299792458;
397   const double kBz = 5;
398   double k2QPt = 100;
399   if ( TMath::Abs( kBz ) > 1.e-4 ) k2QPt = 1. / ( kBz * kCLight );
400   double qPt = k * k2QPt;
401   double pt = 100;
402   if ( TMath::Abs( qPt ) > 1.e-4 ) pt = 1. / TMath::Abs( qPt );
403
404   double yy = ( pt - 0.1 ) / ( 1. - 0.1 );
405   int iy = ( int ) ( yy * 11 );
406   if ( iy < 0 ) iy = 0;
407   if ( iy > 10 ) iy = 10;
408   return kMyColor[iy];
409 }
410
411 void AliHLTTPCCADisplay::Global2View( double x, double y, double *xv, double *yv ) const
412 {
413   // convert coordinates global->view
414   *xv = x * fCos + y * fSin;
415   *yv = y * fCos - x * fSin;
416 }
417
418
419 void AliHLTTPCCADisplay::Slice2View( double x, double y, double *xv, double *yv ) const
420 {
421   // convert coordinates slice->view
422   double xg = x * fSliceCos - y * fSliceSin;
423   double yg = y * fSliceCos + x * fSliceSin;
424   *xv = xg * fCos - yg * fSin;
425   *yv = yg * fCos + xg * fSin;
426 }
427
428
429 void AliHLTTPCCADisplay::DrawGBHit( AliHLTTPCCAGBTracker &tracker, int iHit, int color, Size_t width  )
430 {
431   // draw hit
432   AliHLTTPCCAGBHit &h = tracker.Hits()[iHit];
433   AliHLTTPCCATracker &slice = tracker.Slices()[h.ISlice()];
434   SetSliceTransform( &slice );
435
436   if ( color < 0 ) {
437     if ( fPerf ) {
438       int lab = fPerf->HitLabels()[h.ID()].fLab[0];
439       color = GetColor( lab + 1 );
440       if ( lab >= 0 ) {
441         AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
442         if ( mc.P() >= 1. ) color = kRed;
443         else if ( fDrawOnlyRef ) return;
444       }
445     } else color = GetColorZ( h.Z() );
446   }
447   if ( width > 0 )fMarker.SetMarkerSize( width );
448   else fMarker.SetMarkerSize( .3 );
449   fMarker.SetMarkerColor( color );
450   double vx, vy;
451   Slice2View( h.X(), h.Y(), &vx, &vy );
452
453   fYX->cd();
454   fMarker.DrawMarker( vx, vy );
455   fZX->cd();
456   fMarker.DrawMarker( h.Z(), vy );
457 }
458
459 void AliHLTTPCCADisplay::DrawGBHits( AliHLTTPCCAGBTracker &tracker, int color, Size_t width )
460 {
461   // draw hits
462
463   if ( !fPerf ) return;
464   if ( width < 0 ) width = .3;
465
466   for ( int iHit = 0; iHit < tracker.NHits(); iHit++ ) {
467     AliHLTTPCCAGBHit &h = tracker.Hits()[iHit];
468     int imc = fPerf->HitLabels()[h.ID()].fLab[0];
469     AliHLTTPCCAMCTrack *mc = ( imc >= 0 ) ? &( fPerf->MCTracks()[imc] ) : 0;
470     if ( fDrawOnlyRef && ( !mc || ( mc->P() < 1 ) ) ) continue;
471     int col = color;
472     if ( color < 0 ) {
473       col = GetColor( imc + 1 ) ;
474       if ( mc && ( mc->P() >= 1. ) ) col = kRed;
475     }
476
477     AliHLTTPCCATracker &slice = tracker.Slices()[h.ISlice()];
478     SetSliceTransform( &slice );
479
480     fMarker.SetMarkerSize( width );
481     fMarker.SetMarkerColor( col );
482     double vx, vy;
483     Slice2View( h.X(), h.Y(), &vx, &vy );
484
485     fYX->cd();
486     fMarker.DrawMarker( vx, vy );
487     fZX->cd();
488     fMarker.DrawMarker( h.Z(), vy );
489   }
490 }
491
492 void AliHLTTPCCADisplay::DrawSliceHit( int iRow, int iHit, int color, Size_t width )
493 {
494   // draw hit
495   if ( !fSlice ) return;
496   const AliHLTTPCCARow &row = fSlice->Row( iRow );
497   float y0 = row.Grid().YMin();
498   float z0 = row.Grid().ZMin();
499   float stepY = row.HstepY();
500   float stepZ = row.HstepZ();
501   const uint4* tmpint4 = fSlice->RowData() + row.FullOffset();
502   const ushort2 *hits = reinterpret_cast<const ushort2*>( tmpint4 );
503   ushort2 hh = hits[iHit];
504   float x = row.X();
505   float y = y0 + hh.x * stepY;
506   float z = z0 + hh.y * stepZ;
507
508   SetSliceTransform( fSlice );
509
510   if ( color < 0 ) {
511     if ( fPerf && fGB ) {
512       int id = fGB->FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->HitInputIDs()[row.FirstHit()+iHit];
513       AliHLTTPCCAGBHit &h = fGB->Hits()[id];
514       int lab = fPerf->HitLabels()[h.ID()].fLab[0];
515       color = GetColor( lab + 1 );
516       if ( lab >= 0 ) {
517         AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
518         if ( mc.P() >= 1. ) color = kRed;
519         else if ( fDrawOnlyRef ) return;
520       }
521     } else color = GetColorZ( z );
522   }
523   if ( width > 0 )fMarker.SetMarkerSize( width );
524   else fMarker.SetMarkerSize( .3 );
525   fMarker.SetMarkerColor( color );
526   double vx, vy;
527   Slice2View( x, y, &vx, &vy );
528   fYX->cd();
529   fMarker.DrawMarker( vx, vy );
530   fZX->cd();
531   fMarker.DrawMarker( z, vy );
532 }
533
534 void AliHLTTPCCADisplay::DrawSliceHits( int color, Size_t width )
535 {
536
537   // draw hits
538
539   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
540     const AliHLTTPCCARow &row = fSlice->Row( iRow );
541     for ( int ih = 0; ih < row.NHits(); ih++ ) {
542       DrawSliceHit( iRow, ih, color, width );
543     }
544   }
545 }
546
547
548 void AliHLTTPCCADisplay::DrawSliceLink( int iRow, int iHit, int colorUp, int colorDn, int width )
549 {
550   // draw link between clusters
551
552   if ( !fPerf || !fGB ) return;
553   AliHLTTPCCAGBTracker &tracker = *fGB;
554   if ( width < 0 ) width = 1.;
555   fLine.SetLineWidth( width );
556   int colUp = colorUp >= 0 ? colorUp : kMagenta;
557   int colDn = colorDn >= 0 ? colorDn : kBlack;
558   if ( iRow < 1 || iRow >= fSlice->Param().NRows() - 1 ) return;
559
560   const AliHLTTPCCARow& row = fSlice->Row( iRow );
561   const AliHLTTPCCARow& rowUp = fSlice->Row( iRow + 1 );
562   const AliHLTTPCCARow& rowDn = fSlice->Row( iRow - 1 );
563
564   int id = fSlice->HitInputIDs()[row.FirstHit()+iHit];
565   AliHLTTPCCAGBHit &h = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id];
566   short iUp = ( ( short* )( fSlice->RowData() + row.FullOffset() ) )[row.FullLinkOffset()+iHit];
567   short iDn = ( ( short* )( fSlice->RowData() + row.FullOffset() ) )[row.FullLinkOffset()+row.NHits()+iHit];
568
569   if ( iUp >= 0 ) {
570     int id1 = fSlice->HitInputIDs()[rowUp.FirstHit()+iUp];
571     AliHLTTPCCAGBHit &h1 = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id1];
572     double vx, vy, vx1, vy1;
573     Slice2View( h.X(), h.Y(), &vx, &vy );
574     Slice2View( h1.X(), h1.Y(), &vx1, &vy1 );
575     fLine.SetLineColor( colUp );
576     fYX->cd();
577     fLine.DrawLine( vx - .1, vy, vx1 - .1, vy1 );
578     fZX->cd();
579     fLine.DrawLine( h.Z() - 1., vy, h1.Z() - 1., vy1 );
580   }
581   if ( iDn >= 0 ) {
582     int id1 = fSlice->HitInputIDs()[rowDn.FirstHit()+iDn];
583     AliHLTTPCCAGBHit &h1 = tracker.Hits()[tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id1];
584     double vx, vy, vx1, vy1;
585     Slice2View( h.X(), h.Y(), &vx, &vy );
586     Slice2View( h1.X(), h1.Y(), &vx1, &vy1 );
587     fLine.SetLineColor( colDn );
588     fYX->cd();
589     fLine.DrawLine( vx + .1, vy, vx1 + .1, vy1 );
590     fZX->cd();
591     fLine.DrawLine( h.Z() + 1., vy, h1.Z() + 1., vy1 );
592   }
593 }
594
595
596 void AliHLTTPCCADisplay::DrawSliceLinks( int colorUp, int colorDn, int width )
597 {
598   // draw links between clusters
599
600   for ( int iRow = 1; iRow < fSlice->Param().NRows() - 1; iRow++ ) {
601     const AliHLTTPCCARow& row = fSlice->Row( iRow );
602     for ( int ih = 0; ih < row.NHits(); ih++ ) {
603       DrawSliceLink( iRow, ih, colorUp, colorDn, width );
604     }
605   }
606 }
607
608
609
610 int AliHLTTPCCADisplay::GetTrackMC( const AliHLTTPCCADisplayTmpHit *vHits, int NHits )
611 {
612   // get MC label for the track
613
614   AliHLTTPCCAGBTracker &tracker = *fGB;
615
616   int label = -1;
617   double purity = 0;
618   int *lb = new int[NHits*3];
619   int nla = 0;
620   //std::cout<<"\n\nTrack hits mc: "<<std::endl;
621   for ( int ihit = 0; ihit < NHits; ihit++ ) {
622     AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
623     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
624     if ( l.fLab[0] >= 0 ) lb[nla++] = l.fLab[0];
625     if ( l.fLab[1] >= 0 ) lb[nla++] = l.fLab[1];
626     if ( l.fLab[2] >= 0 ) lb[nla++] = l.fLab[2];
627     //std::cout<<ihit<<":  "<<l.fLab[0]<<" "<<l.fLab[1]<<" "<<l.fLab[2]<<std::endl;
628   }
629   sort( lb, lb + nla );
630   int labmax = -1, labcur = -1, lmax = 0, lcurr = 0, nh = 0;
631   //std::cout<<"MC track IDs :"<<std::endl;
632   for ( int i = 0; i < nla; i++ ) {
633     if ( lb[i] != labcur ) {
634       if ( 0 && i > 0 && lb[i-1] >= 0 ) {
635         AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[i-1]];
636         std::cout << lb[i-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
637                   << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
638                   << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
639
640       }
641       nh = 0;
642       if ( labcur >= 0 && lmax < lcurr ) {
643         lmax = lcurr;
644         labmax = labcur;
645       }
646       labcur = lb[i];
647       lcurr = 0;
648     }
649     lcurr++;
650     nh++;
651   }
652   if ( 0 && nla - 1 > 0 && lb[nla-1] >= 0 ) {
653     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lb[nla-1]];
654     std::cout << lb[nla-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
655               << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
656               << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
657
658   }
659   if ( labcur >= 0 && lmax < lcurr ) {
660     lmax = lcurr;
661     labmax = labcur;
662   }
663   lmax = 0;
664   for ( int ihit = 0; ihit < NHits; ihit++ ) {
665     AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
666     AliHLTTPCCAPerformance::AliHLTTPCCAHitLabel &l = fPerf->HitLabels()[h.ID()];
667     if ( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax
668        ) lmax++;
669   }
670   label = labmax;
671   purity = ( ( NHits > 0 ) ? double( lmax ) / double( NHits ) : 0 );
672   if ( lb ) delete[] lb;
673   if ( purity < .9 ) label = -1;
674   return label;
675 }
676
677 bool AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrackParam t, double Alpha, const AliHLTTPCCADisplayTmpHit *vHits,
678                                       int NHits, int color, int width, bool pPoint )
679 {
680   // draw track
681
682   if ( NHits < 2 ) return 0;
683
684   AliHLTTPCCAGBTracker &tracker = *fGB;
685   if ( width < 0 ) width = 2;
686
687   if ( fDrawOnlyRef ) {
688     int lab = GetTrackMC( vHits, NHits );
689     if ( lab < 0 ) return 0;
690     AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
691     if ( mc.P() < 1 ) return 0;
692   }
693
694   if ( color < 0 ) {
695     //color = GetColorZ( (vz[0]+vz[mHits-1])/2. );
696     //color = GetColorK(t.GetKappa());
697     int lab = GetTrackMC( vHits, NHits );
698     color = GetColor( lab + 1 );
699     if ( lab >= 0 ) {
700       AliHLTTPCCAMCTrack &mc = fPerf->MCTracks()[lab];
701       if ( mc.P() >= 1. ) color = kRed;
702     }
703   }
704
705   if ( t.SinPhi() > .999 )  t.SetSinPhi( .999 );
706   else if ( t.SinPhi() < -.999 )  t.SetSinPhi( -.999 );
707
708   //  int iSlice = fSlice->Param().ISlice();
709
710   //sort(vHits, vHits + NHits, AliHLTTPCCADisplayTmpHit::CompareHitZ );
711
712   double vx[2000], vy[2000], vz[2000];
713   int mHits = 0;
714
715   //int oldSlice = -1;
716   double alpha = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
717   AliHLTTPCCATrackParam tt = t;
718
719   for ( int iHit = 0; iHit < NHits; iHit++ ) {
720
721     AliHLTTPCCAGBHit &h = tracker.Hits()[vHits[iHit].ID()];
722
723     double hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
724     double hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
725     double x0 = h.X(), y0 = h.Y(), z1 = h.Z();
726     double x1 = x0 * hCos + y0 * hSin;
727     double y1 = y0 * hCos - x0 * hSin;
728
729     {
730       double dx = x1 - tt.X();
731       double dy = y1 - tt.Y();
732       if ( dx*dx + dy*dy > 1. ) {
733         double dalpha = TMath::ATan2( dy, dx );
734         if ( tt.Rotate( dalpha ) ) {
735           alpha += dalpha;
736           hCos = TMath::Cos( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
737           hSin = TMath::Sin( alpha - tracker.Slices()[h.ISlice()].Param().Alpha() );
738           x1 = x0 * hCos + y0 * hSin;
739           y1 = y0 * hCos - x0 * hSin;
740         }
741       }
742     }
743     SetSliceTransform( alpha );
744
745     //t.GetDCAPoint( x1, y1, z1, x1, y1, z1 );
746     std::cout << "mark 3" << std::endl;
747     bool ok = tt.TransportToX( x1, .999 );
748     std::cout << "mark 4" << std::endl;
749     if ( 1 || ok ) {
750       x1 = tt.X();
751       y1 = tt.Y();
752       z1 = tt.Z();
753     }
754
755     Slice2View( x1, y1, &x1, &y1 );
756     vx[mHits] = x1;
757     vy[mHits] = y1;
758     vz[mHits] = z1;
759     mHits++;
760     for ( int j = 0; j < 0; j++ ) {
761       x0 = h.X() + j; y0 = h.Y(); z1 = h.Z();
762       x1 = x0 * hCos + y0 * hSin;
763       y1 = y0 * hCos - x0 * hSin;
764       ok = tt.TransportToX( x1, .999 );
765       if ( ok ) {
766         x1 = tt.X();
767         y1 = tt.Y();
768         z1 = tt.Z();
769       }
770
771       Slice2View( x1, y1, &x1, &y1 );
772       vx[mHits] = x1;
773       vy[mHits] = y1;
774       vz[mHits] = z1;
775       mHits++;
776     }
777   }
778   if ( pPoint ) {
779     double x1 = t.X(), y1 = t.Y(), z1 = t.Z();
780     double a = ( TMath::Abs( Alpha + 1 ) < 1.e-4 ) ? fSlice->Param().Alpha() : Alpha;
781     SetSliceTransform( a );
782
783     Slice2View( x1, y1, &x1, &y1 );
784     double dx = x1 - vx[0];
785     double dy = y1 - vy[0];
786     //std::cout<<x1<<" "<<y1<<" "<<vx[0]<<" "<<vy[0]<<" "<<dx<<" "<<dy<<std::endl;
787     double d0 = dx * dx + dy * dy;
788     dx = x1 - vx[mHits-1];
789     dy = y1 - vy[mHits-1];
790     //std::cout<<x1<<" "<<y1<<" "<<vx[mHits-1]<<" "<<vy[mHits-1]<<" "<<dx<<" "<<dy<<std::endl;
791     double d1 = dx * dx + dy * dy;
792     //std::cout<<"d0, d1="<<d0<<" "<<d1<<std::endl;
793     if ( d1 < d0 ) {
794       vx[mHits] = x1;
795       vy[mHits] = y1;
796       vz[mHits] = z1;
797       mHits++;
798     } else {
799       for ( int i = mHits; i > 0; i-- ) {
800         vx[i] = vx[i-1];
801         vy[i] = vy[i-1];
802         vz[i] = vz[i-1];
803       }
804       vx[0] = x1;
805       vy[0] = y1;
806       vz[0] = z1;
807       mHits++;
808     }
809   }
810
811
812   fLine.SetLineColor( color );
813   fLine.SetLineWidth( width );
814   fArc.SetFillStyle( 0 );
815   fArc.SetLineColor( color );
816   fArc.SetLineWidth( width );
817   TPolyLine pl;
818   pl.SetLineColor( color );
819   pl.SetLineWidth( width );
820   TPolyLine plZ;
821   plZ.SetLineColor( color );
822   plZ.SetLineWidth( width );
823
824   fMarker.SetMarkerSize( width / 2. );
825   fMarker.SetMarkerColor( color );
826
827   fYX->cd();
828   pl.DrawPolyLine( mHits, vx, vy );
829   {
830     fMarker.DrawMarker( vx[0], vy[0] );
831     fMarker.DrawMarker( vx[mHits-1], vy[mHits-1] );
832   }
833   fZX->cd();
834   plZ.DrawPolyLine( mHits, vz, vy );
835   fMarker.DrawMarker( vz[0], vy[0] );
836   fMarker.DrawMarker( vz[mHits-1], vy[mHits-1] );
837
838   fLine.SetLineWidth( 1 );
839   return 1;
840 }
841
842
843 bool AliHLTTPCCADisplay::DrawTracklet( AliHLTTPCCATrackParam &track, const int *hitstore, int color, int width, bool pPoint )
844 {
845   // draw tracklet
846   AliHLTTPCCAGBTracker &tracker = *fGB;
847   AliHLTTPCCADisplayTmpHit vHits[200];
848   int nHits = 0;
849   for ( int iRow = 0; iRow < fSlice->Param().NRows(); iRow++ ) {
850     int iHit = hitstore[iRow];
851     if ( iHit < 0 ) continue;
852     const AliHLTTPCCARow &row = fSlice->Row( iRow );
853     int id = fSlice->HitInputIDs()[row.FirstHit()+iHit];
854     int iGBHit = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
855     AliHLTTPCCAGBHit &h = tracker.Hits()[iGBHit];
856     vHits[nHits].SetID( iGBHit );
857     vHits[nHits].SetS( 0 );
858     vHits[nHits].SetZ( h.Z() );
859     nHits++;
860   }
861   return DrawTrack( track, -1, vHits, nHits, color, width, pPoint );
862 }
863
864
865 void AliHLTTPCCADisplay::DrawSliceOutTrack( AliHLTTPCCATrackParam &t, double alpha, int itr, int color, int width )
866 {
867   // draw slice track
868
869   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
870   if ( track.NHits() < 2 ) return;
871
872   AliHLTTPCCAGBTracker &tracker = *fGB;
873   AliHLTTPCCADisplayTmpHit vHits[200];
874
875   for ( int ih = 0; ih < track.NHits(); ih++ ) {
876     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHits()[track.FirstHitRef()+ih];
877     AliHLTTPCCAGBHit &h = tracker.Hits()[id];
878     vHits[ih].SetID( id );
879     vHits[ih].SetS( 0 );
880     vHits[ih].SetZ( h.Z() );
881   }
882
883   DrawTrack( t, alpha, vHits, track.NHits(), color, width, 1 );
884 }
885
886 void AliHLTTPCCADisplay::DrawSliceOutTrack( int itr, int color, int width )
887 {
888   // draw slice track
889
890   AliHLTTPCCAOutTrack &track = fSlice->OutTracks()[itr];
891   if ( track.NHits() < 2 ) return;
892
893   AliHLTTPCCAGBTracker &tracker = *fGB;
894   AliHLTTPCCADisplayTmpHit vHits[200];
895
896   for ( int ih = 0; ih < track.NHits(); ih++ ) {
897     int id = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + fSlice->OutTrackHits()[track.FirstHitRef()+ih];
898     AliHLTTPCCAGBHit &h = tracker.Hits()[id];
899     vHits[ih].SetID( id );
900     vHits[ih].SetS( 0 );
901     vHits[ih].SetZ( h.Z() );
902   }
903
904   DrawTrack( track.StartPoint(), -1, vHits, track.NHits(), color, width );
905 }
906
907
908 void AliHLTTPCCADisplay::DrawSliceTrack( int itr, int color )
909 {
910   // draw slice track
911
912   AliHLTTPCCATrack &track = fSlice->Tracks()[itr];
913   if ( track.NHits() < 2 ) return;
914
915   AliHLTTPCCAGBTracker &tracker = *fGB;
916   AliHLTTPCCADisplayTmpHit vHits[200];
917   for ( int ith = 0; ith < track.NHits(); ith++ ) {
918     int ic = ( fSlice->TrackHits()[track.FirstHitID()+ith] );
919     const AliHLTTPCCARow &row = fSlice->ID2Row( ic );
920     int ih = fSlice->ID2IHit( ic );
921     int id = fSlice->HitInputIDs()[row.FirstHit()+ih];
922     int gbID = tracker.FirstSliceHit()[fSlice->Param().ISlice()] + id;
923     AliHLTTPCCAGBHit &h = tracker.Hits()[gbID];
924     vHits[ith].SetID( gbID );
925     vHits[ith].SetS( 0 );
926     vHits[ith].SetZ( h.Z() );
927   }
928
929   DrawTrack( track.Param(), -1, vHits, track.NHits(), color, -1 );
930   //track.Param().Print();
931 }
932
933
934 void AliHLTTPCCADisplay::DrawGBTrack( int itr, int color, int width )
935 {
936   // draw global track
937
938   AliHLTTPCCAGBTracker &tracker = *fGB;
939   AliHLTTPCCADisplayTmpHit vHits[1000];
940
941   AliHLTTPCCAGBTrack &track = tracker.Tracks()[itr];
942   if ( track.NHits() < 2 ) return;
943
944   for ( int ih = 0; ih < track.NHits(); ih++ ) {
945     int i = tracker.TrackHits()[ track.FirstHitRef() + ih];
946     AliHLTTPCCAGBHit &h = tracker.Hits()[i];
947     vHits[ih].SetID( i );
948     vHits[ih].SetS( 0 );
949     vHits[ih].SetZ( h.Z() );
950   }
951
952   DrawTrack( track.Param(), track.Alpha(), vHits, track.NHits(), color, width );
953 }
954
955
956 void AliHLTTPCCADisplay::DrawGBTrackFast( AliHLTTPCCAGBTracker &tracker, int itr, int color )
957 {
958   // draw global track
959
960   AliHLTTPCCAGBTrack &track = tracker.Tracks()[itr];
961   if ( track.NHits() < 2 ) return;
962   int width = 1;
963
964   AliHLTTPCCADisplayTmpHit *vHits = new AliHLTTPCCADisplayTmpHit[track.NHits()];
965   AliHLTTPCCATrackParam t = track.Param();
966
967   for ( int ih = 0; ih < track.NHits(); ih++ ) {
968     int i = tracker.TrackHits()[ track.FirstHitRef() + ih];
969     AliHLTTPCCAGBHit *h = &( tracker.Hits()[i] );
970     vHits[ih].SetID( i );
971     vHits[ih].SetS( 0 );
972     vHits[ih].SetZ( h->Z() );
973   }
974
975   sort( vHits, vHits + track.NHits(), AliHLTTPCCADisplayTmpHit::CompareHitZ );
976   int colorY = color;
977   {
978     AliHLTTPCCAGBHit &h1 = tracker.Hits()[ vHits[0].ID()];
979     AliHLTTPCCAGBHit &h2 = tracker.Hits()[ vHits[track.NHits()-1].ID()];
980     if ( color < 0 ) color = GetColorZ( ( h1.Z() + h2.Z() ) / 2. );
981     double gx1, gy1, gx2, gy2;
982     Slice2View( h1.X(), h1.Y(), &gx1, &gy1 );
983     Slice2View( h2.X(), h2.Y(), &gx2, &gy2 );
984     if ( colorY < 0 ) colorY = GetColorY( ( gy1 + gy2 ) / 2. );
985     color = colorY = GetColorK( t.GetQPt() );
986   }
987
988   fMarker.SetMarkerColor( color );//kBlue);
989   fMarker.SetMarkerSize( 1. );
990   fLine.SetLineColor( color );
991   fLine.SetLineWidth( width );
992   fArc.SetFillStyle( 0 );
993   fArc.SetLineColor( color );
994   fArc.SetLineWidth( width );
995   TPolyLine pl;
996   pl.SetLineColor( colorY );
997   pl.SetLineWidth( width );
998
999   int oldSlice = -1;
1000   double alpha = track.Alpha();
1001   // YX
1002   {
1003
1004     AliHLTTPCCAGBHit &h1 = tracker.Hits()[vHits[0].ID()];
1005     AliHLTTPCCAGBHit &h2 = tracker.Hits()[vHits[track.NHits()-1].ID()];
1006     float x1, y1, z1, x2, y2, z2;
1007     double vx1, vy1, vx2, vy2;
1008
1009     if ( h1.ISlice() != oldSlice ) {
1010       t.Rotate( tracker.Slices()[h1.ISlice()].Param().Alpha() - alpha );
1011       oldSlice = h1.ISlice();
1012       alpha = tracker.Slices()[h1.ISlice()].Param().Alpha();
1013       SetSliceTransform( &( tracker.Slices()[oldSlice] ) );
1014     }
1015     t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, fSlice->Param().Bz()  );
1016     Slice2View( x1, y1, &vx1, &vy1 );
1017
1018     if ( h2.ISlice() != oldSlice ) {
1019       t.Rotate( tracker.Slices()[h2.ISlice()].Param().Alpha() - alpha );
1020       oldSlice = h2.ISlice();
1021       alpha = tracker.Slices()[h2.ISlice()].Param().Alpha();
1022       SetSliceTransform( &( tracker.Slices()[oldSlice] ) );
1023     }
1024     t.GetDCAPoint( h2.X(), h2.Y(), h2.Z(), x2, y2, z2, fSlice->Param().Bz()  );
1025     Slice2View( x2, y2, &vx2, &vy2 );
1026
1027     double x0 = t.GetX();
1028     double y0 = t.GetY();
1029     double sinPhi = t.GetSinPhi();
1030     double k = t.GetKappa( fSlice->Param().Bz() );
1031     double ex = t.GetCosPhi();
1032     double ey = sinPhi;
1033
1034     if ( TMath::Abs( k ) > 1.e-4 ) {
1035
1036       fYX->cd();
1037
1038       double r = 1 / TMath::Abs( k );
1039       double xc = x0 - ey * ( 1 / k );
1040       double yc = y0 + ex * ( 1 / k );
1041
1042       double vx, vy;
1043       Slice2View( xc, yc, &vx, &vy );
1044
1045       double a1 = TMath::ATan2( vy1 - vy, vx1 - vx ) / TMath::Pi() * 180.;
1046       double a2 = TMath::ATan2( vy2 - vy, vx2 - vx ) / TMath::Pi() * 180.;
1047       if ( a1 < 0 ) a1 += 360;
1048       if ( a2 < 0 ) a2 += 360;
1049       if ( a2 < a1 ) a2 += 360;
1050       double da = TMath::Abs( a2 - a1 );
1051       if ( da > 360 ) da -= 360;
1052       if ( da > 180 ) {
1053         da = a1;
1054         a1 = a2;
1055         a2 = da;
1056         if ( a2 < a1 ) a2 += 360;
1057       }
1058       fArc.DrawArc( vx, vy, r, a1, a2, "only" );
1059       //fArc.DrawArc(vx,vy,r, 0,360,"only");
1060     } else {
1061       fYX->cd();
1062       fLine.DrawLine( vx1, vy1, vx2, vy2 );
1063     }
1064   }
1065
1066   // ZX
1067   double py[track.NHits()], pz[track.NHits()];
1068
1069   for ( int iHit = 0; iHit < track.NHits(); iHit++ ) {
1070
1071     AliHLTTPCCAGBHit &h1 = tracker.Hits()[vHits[iHit].ID()];
1072     float x1, y1, z1;
1073     double vx1, vy1;
1074     if ( h1.ISlice() != oldSlice ) {
1075       t.Rotate( tracker.Slices()[h1.ISlice()].Param().Alpha() - alpha );
1076       oldSlice = h1.ISlice();
1077       alpha = tracker.Slices()[h1.ISlice()].Param().Alpha();
1078       SetSliceTransform( &( tracker.Slices()[oldSlice] ) );
1079     }
1080     t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, fSlice->Param().Bz()  );
1081     Slice2View( x1, y1, &vx1, &vy1 );
1082     py[iHit] = vy1;
1083     pz[iHit] = z1;
1084   }
1085
1086
1087   fZX->cd();
1088   pl.DrawPolyLine( track.NHits(), pz, py );
1089
1090   fLine.SetLineWidth( 1 );
1091   delete[] vHits;
1092 }
1093
1094
1095
1096
1097
1098 #ifdef XXXX
1099
1100
1101
1102
1103 void AliHLTTPCCADisplay::DrawMergedHit( int iRow, int iHit, int color )
1104 {
1105   // connect two cells on display
1106
1107 #ifdef XXX
1108
1109   const AliHLTTPCCARow &row = fSlice->Row( iRow );
1110   AliHLTTPCCAHit &h = row.Hits()[iHit];
1111   AliHLTTPCCAHit &hyz = row.HitsYZ()[iHit];
1112
1113   double x = row.X();
1114   double y = hyz.Y();
1115   double z = hyz.Z();
1116   double x1 = x, x2 = x;
1117   double y1 = y, y2 = y;
1118   double z1 = z, z2 = z;
1119   int iRow1 = iRow, iHit1 = iHit;
1120   int iRow2 = iRow, iHit2 = iHit;
1121
1122   if ( fSlice->HitLinksDown()[] >= 0 ) {
1123     iRow1 = iRow - 1;
1124     iHit1 = h.LinkDown();
1125     AliHLTTPCCARow &row1 = fSlice->Rows()[iRow1];
1126     AliHLTTPCCAHitYZ &h1 = row1.HitsYZ()[iHit1];
1127     x1 = row1.X();
1128     y1 = h1.Y();
1129     z1 = h1.Z();
1130   }
1131   if ( h.LinkUp() >= 0 ) {
1132     iRow2 = iRow + 1;
1133     iHit2 = h.LinkUp();
1134     AliHLTTPCCARow &row2 = fSlice->Rows()[iRow2];
1135     AliHLTTPCCAHitYZ &h2 = row2.HitsYZ()[iHit2];
1136     x2 = row2.X();
1137     y2 = h2.Y();
1138     z2 = h2.Z();
1139   }
1140   if ( color < 0 ) color = GetColorZ( ( z + z1 + z2 ) / 3. );
1141
1142
1143   Slice2View( x, y, &x, &y );
1144   Slice2View( x1, y1, &x1, &y1 );
1145   Slice2View( x2, y2, &x2, &y2 );
1146
1147   double lx[] = { x1, x, x2 };
1148   double ly[] = { y1, y, y2 };
1149   double lz[] = { z1, z, z2 };
1150
1151   fPLine.SetLineColor( color );
1152   fPLine.SetLineWidth( 1 );
1153   //fPLine.SetFillColor(color);
1154   fPLine.SetFillStyle( -1 );
1155
1156   fYX->cd();
1157   fPLine.DrawPolyLine( 3, lx, ly );
1158   fZX->cd();
1159   fPLine.DrawPolyLine( 3, lz, ly );
1160   DrawHit( iRow, iHit, color );
1161   DrawHit( iRow1, iHit1, color );
1162   DrawHit( iRow2, iHit2, color );
1163 #endif
1164 }
1165
1166
1167 void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, int color, bool DrawHits )
1168 {
1169   // draw track
1170
1171   if ( track.NHits() < 2 ) return;
1172   int width = 2;
1173
1174   AliHLTTPCCADisplayTmpHit *vHits = new AliHLTTPCCADisplayTmpHit[track.NHits()];
1175   AliHLTTPCCATrackParam &t = track.Param();
1176
1177   int iID = track.FirstHitID();
1178   int nhits = 0;
1179   {
1180     int iHit = 0;
1181     for ( int ih = 0; ih < track.NHits(); ih++ ) {
1182       int i = fSlice->TrackHits()[iID];
1183       AliHLTTPCCAHit *h = &( fSlice->ID2Hit( i ) );
1184       AliHLTTPCCARow &row = fSlice->ID2Row( i );
1185       vHits[iHit].ID() = i;
1186       vHits[iHit].S() = t.GetS( row.X(), h->Y() );
1187       vHits[iHit].Z() = h->Z();
1188       iHit++;
1189       nhits++;
1190       iID++;
1191     }
1192   }
1193   sort( vHits, vHits + track.NHits(), AliHLTTPCCADisplayTmpHit::CompareHitZ );
1194   //cout<<"Draw track, nhits = "<<nhits<<endl;
1195   {
1196     AliHLTTPCCAHit &c1 = fSlice->ID2Hit( vHits[0].ID() );
1197     AliHLTTPCCAHit &c2 = fSlice->ID2Hit( vHits[track.NHits()-1].ID() );
1198     if ( color < 0 ) color = GetColorZ( ( c1.Z() + c2.Z() ) / 2. );
1199   }
1200
1201   fMarker.SetMarkerColor( color );//kBlue);
1202   fMarker.SetMarkerSize( 1. );
1203   /*
1204   for( int i=0; i<3; i++){
1205     AliHLTTPCCAHit &c1 = fSlice->ID2Hit(track.HitID()[i]);
1206     AliHLTTPCCARow &row1 = fSlice->ID2Row(track.HitID()[i]);
1207     double vx1, vy1;
1208     Slice2View(row1.X(), c1.Y(), &vx1, &vy1 );
1209     fYX->cd();
1210     fMarker.DrawMarker(vx1,vy1);
1211     fZX->cd();
1212     fMarker.DrawMarker(c1.Z(),vy1);
1213   }
1214   */
1215
1216   //DrawTrackletPoint( fSlice->ID2Point(track.PointID()[0]).Param(), kBlack);//color );
1217   //DrawTrackletPoint( fSlice->ID2Point(track.PointID()[1]).Param(), kBlack);//color );
1218   //cout<<"DrawTrack end points x = "<<fSlice->ID2Point(track.PointID()[0]).Param().GetX()<<" "<<fSlice->ID2Point(track.PointID()[1]).Param().GetX()<<endl;
1219   for ( int iHit = 0; iHit < track.NHits() - 1; iHit++ ) {
1220     AliHLTTPCCAHit &c1 = fSlice->ID2Hit( vHits[iHit].ID() );
1221     AliHLTTPCCAHit &c2 = fSlice->ID2Hit( vHits[iHit+1].ID() );
1222     AliHLTTPCCARow &row1 = fSlice->ID2Row( vHits[iHit].ID() );
1223     AliHLTTPCCARow &row2 = fSlice->ID2Row( vHits[iHit+1].ID() );
1224     float x1, y1, z1, x2, y2, z2;
1225     t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1, fSlice->Param().Bz()  );
1226     t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2, fSlice->Param().Bz()  );
1227
1228     //if( color<0 ) color = GetColorZ( (z1+z2)/2. );
1229     double vx1, vy1, vx2, vy2;
1230     Slice2View( x1, y1, &vx1, &vy1 );
1231     Slice2View( x2, y2, &vx2, &vy2 );
1232
1233     fLine.SetLineColor( color );
1234     fLine.SetLineWidth( width );
1235
1236     double x0 = t.GetX();
1237     double y0 = t.GetY();
1238     double sinPhi = t.GetSinPhi();
1239     double k = t.GetKappa();
1240     double ex = t.GetCosPhi();
1241     double ey = sinPhi;
1242
1243     if ( TMath::Abs( k ) > 1.e-4 ) {
1244
1245       fArc.SetFillStyle( 0 );
1246       fArc.SetLineColor( color );
1247       fArc.SetLineWidth( width );
1248
1249       fYX->cd();
1250
1251       double r = 1 / TMath::Abs( k );
1252       double xc = x0 - ey * ( 1 / k );
1253       double yc = y0 + ex * ( 1 / k );
1254
1255       double vx, vy;
1256       Slice2View( xc, yc, &vx, &vy );
1257
1258       double a1 = TMath::ATan2( vy1 - vy, vx1 - vx ) / TMath::Pi() * 180.;
1259       double a2 = TMath::ATan2( vy2 - vy, vx2 - vx ) / TMath::Pi() * 180.;
1260       if ( a1 < 0 ) a1 += 360;
1261       if ( a2 < 0 ) a2 += 360;
1262       if ( a2 < a1 ) a2 += 360;
1263       double da = TMath::Abs( a2 - a1 );
1264       if ( da > 360 ) da -= 360;
1265       if ( da > 180 ) {
1266         da = a1;
1267         a1 = a2;
1268         a2 = da;
1269         if ( a2 < a1 ) a2 += 360;
1270       }
1271       fArc.DrawArc( vx, vy, r, a1, a2, "only" );
1272       //fArc.DrawArc(vx,vy,r, 0,360,"only");
1273     } else {
1274       fYX->cd();
1275       fLine.DrawLine( vx1, vy1, vx2, vy2 );
1276     }
1277   }
1278
1279   for ( int iHit = 0; iHit < track.NHits() - 1; iHit++ ) {
1280     AliHLTTPCCAHit &c1 = fSlice->ID2Hit( vHits[iHit].ID() );
1281     AliHLTTPCCAHit &c2 = fSlice->ID2Hit( vHits[iHit+1].ID() );
1282     AliHLTTPCCARow &row1 = fSlice->ID2Row( vHits[iHit].ID() );
1283     AliHLTTPCCARow &row2 = fSlice->ID2Row( vHits[iHit+1].ID() );
1284
1285     //if( DrawHits ) ConnectHits( fSlice->ID2IRow(vHits[iHit].ID()),c1,
1286     //fSlice->ID2IRow(vHits[iHit+1].ID()),c2, color );
1287     float x1, y1, z1, x2, y2, z2;
1288     t.GetDCAPoint( row1.X(), c1.Y(), c1.Z(), x1, y1, z1, fSlice->Param().Bz()  );
1289     t.GetDCAPoint( row2.X(), c2.Y(), c2.Z(), x2, y2, z2, fSlice->Param().Bz()  );
1290
1291     double vx1, vy1, vx2, vy2;
1292     Slice2View( x1, y1, &vx1, &vy1 );
1293     Slice2View( x2, y2, &vx2, &vy2 );
1294
1295     fLine.SetLineColor( color );
1296     fLine.SetLineWidth( width );
1297
1298     fZX->cd();
1299     fLine.DrawLine( z1, vy1, z2, vy2 );
1300   }
1301   fLine.SetLineWidth( 1 );
1302   delete[] vHits;
1303 }
1304
1305
1306 void AliHLTTPCCADisplay::DrawTrackletPoint( AliHLTTPCCATrackParam &t, int color )
1307 {
1308   // draw tracklet point
1309
1310   double x = t.GetX();
1311   double y = t.GetY();
1312   double sinPhi = t.GetSinPhi();
1313   double z = t.GetZ();
1314   double dzds = t.GetDzDs();
1315   double ex = t.GetCosPhi();
1316   double ey = sinPhi;
1317
1318   int width = 1;
1319
1320   if ( color < 0 ) color = GetColorZ( t.GetZ() );
1321
1322   fMarker.SetMarkerColor( color );
1323   fMarker.SetMarkerSize( .5 );
1324   fLine.SetLineWidth( width );
1325   fLine.SetLineColor( color );
1326
1327   double vx, vy, vex, vey, vdx, vdy;
1328   double dz = TMath::Sqrt( t.GetErr2Z() );
1329   Slice2View( x, y, &vx, &vy );
1330   Slice2View( ex, ey, &vex, &vey );
1331   Slice2View( 0, TMath::Sqrt( t.GetErr2Y() )*3.5, &vdx, &vdy );
1332   double d = TMath::Sqrt( vex * vex + vey * vey );
1333   vex /= d;
1334   vey /= d;
1335   fYX->cd();
1336   fMarker.DrawMarker( vx, vy );
1337   fLine.DrawLine( vx, vy, vx + vex*4, vy + vey*4 );
1338   fLine.DrawLine( vx - vdx, vy - vdy, vx + vdx, vy + vdy );
1339   fZX->cd();
1340   fMarker.DrawMarker( z, vy );
1341   fLine.DrawLine( z, vy, z + dzds*4, vy + vey*4 );
1342   fLine.DrawLine( z - 3.5*dz, vy - vdy, z + 3.5*dz, vy + vdy );
1343   fLine.SetLineWidth( 1 );
1344 }
1345 #endif //XXXX