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