FairRoot/PandaRoot
PndFTSCADisplay.cxx
Go to the documentation of this file.
1 // $Id: PndFTSCADisplay.cxx,v 1.8 2016/12/16 23:29:41 mpugach Exp $
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 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Mykhailo Pugach <M.Pugach@gsi.de> *
12 // Maksym Zyzak <M.Zyzak@gsi.de> *
13 // *
14 // Permission to use, copy, modify and distribute this software and its *
15 // documentation strictly for non-commercial purposes is hereby granted *
16 // without fee, provided that the above copyright notice appears in all *
17 // copies and that both the copyright notice and this permission notice *
18 // appear in the supporting documentation. The authors make no claims *
19 // about the suitability of this software for any purpose. It is *
20 // provided "as is" without express or implied warranty. *
21 // *
22 //***************************************************************************
23 
24 // TODO now we use right CS, so z change sign, but it wasn't changed everywhere in the Display-code
25 
26 #include "PndFTSCADisplay.h"
27 
28 //#define DRAW_3D // infrequent use for drawing 3D pictures
29 #define CLEAR
30 //#define DRAW_ZR
31 
32 #include "PndFTSCAParameters.h"
33 
34 #include "PndFTSCAGBTracker.h"
35 #include "PndFTSCAGBTrack.h"
36 #include "PndFTSCAGBHit.h"
37 #include "PndFTSCAPerformance.h"
38 #include "PndFTSCAMCTrack.h"
39 #include "PndFTSCAParam.h"
40 #include "PndFTSCAClusterData.h"
41 
43 #include "PndFTSCATrackParam.h"
44 
45 #include "FTSCAHits.h"
46 #include "FTSCAHitsV.h"
47 #include "FTSCATracks.h"
48 
49 #include "TString.h"
50 #include "Riostream.h"
51 #include "TMath.h"
52 #include "TStyle.h"
53 #include "TCanvas.h"
54 #include "TApplication.h"
55 #include "TLatex.h"
56 #include "TVector3.h"
57 #include "TEllipse.h"
58 
59 #ifdef DRAW_3D
60  #include "TVector3.h"
61 #endif // DRAW_3D
62 
64 {
65  //* Displaying information on the screen*//
66 
67 
68  public:
69 
70  int ID() const { return fHitID; }
71  double S() const { return fS; }
72  double Z() const { return fZ; }
73 
74  void SetID( int v ) { fHitID = v; }
75  void SetS( double v ) { fS = v; }
76  void SetZ( double v ) { fZ = v; }
77 
78  static bool CompareHitDS( const PndFTSCADisplayTmpHit &a,
79  const PndFTSCADisplayTmpHit &b ) {
80  return ( a.fS < b.fS );
81  }
82 
83  static bool CompareHitZ( const PndFTSCADisplayTmpHit &a,
84  const PndFTSCADisplayTmpHit &b ) {
85  return ( a.fZ < b.fZ );
86  }
87 
88  private:
89 
90  int fHitID; // hit ID
91  double fS; // hit position on the XY track curve
92  double fZ; // hit Z position
93 
94 };
95 
96 
97 
99 {
100  // reference to static object
101  static PndFTSCADisplay gPndFTSCADisplay;
102 
103  return gPndFTSCADisplay;
104 }
105 
107  fYX( 0 ), fZX( 0 ), fZR( 0 ), fAsk( 1 ), fGB( 0 ), fPerf( 0 ),
108  fZMin( -60 ), fZMax( 60 ), fYMin( -210 ), fYMax( 210 ),
109 #ifdef PANDA_FTS
110  fXMin(0), fXMax(0),
111 #else
112  fRInnerMin( 50. ), fRInnerMax( 133.3 ), fROuterMin( 50 ), fROuterMax( 50 ), fTPCZMin( -60. ), fTPCZMax( 60 ),
113 #endif
114  fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex(), fDrawOnlyRef( 0 ) // iklm. This is just default. If they are not correct SetTPC(...) can and should be used!
115 {
116  fPerf = &( PndFTSCAPerformance::Instance() );
117  // constructor
118 }
119 
120 
122 {
123  // destructor
124 // if(fYX) delete fYX;
125 // if(fZX) delete fZX;
126 // if( fZR ) delete fZR;
127 }
128 
130 {
131  static bool firstCall = 1;
132  if ( firstCall ) {
133  if ( !gApplication ) new TApplication( "myapp", 0, 0 );
134 
135  // initialization
136  gStyle->SetCanvasBorderMode( 0 );
137  gStyle->SetCanvasBorderSize( 1 );
138  gStyle->SetCanvasColor( 0 );
139 #ifdef PANDA_FTS
140  fCanvas = new TCanvas( "CA", "CA Display", 2*400, 2*300 );
141  fCanvas->Divide( 2, 1 );
142  fZX = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_1" ) );
143  fYX = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_2" ) );
144 #else
145 #ifdef DRAW_ZR
146  fCanvas = new TCanvas( "CA", "CA Display", 400*1.5, 300 ); //1280*1.5, 645
147  fCanvas->Divide( 3, 1 );
148  fZX = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_2" ) ); // ("ZX", "ZX window", -610, 0, 590, 600);
149  fZR = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_3" ) ); // ("ZX", "ZX window", -610, 0, 590, 600);
150 #else
151  fCanvas = new TCanvas( "CA", "CA Display", 400*2, 300*2 );
152  fCanvas->Divide( 2, 1 );
153  fZX = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_2" ) ); // ("ZX", "ZX window", -610, 0, 590, 600);
154 #endif
155  fYX = static_cast<TPad *>( fCanvas->GetPrimitive( "CA_1" ) ); // ("YX", "YX window", -1, 0, 600, 600);
156 #endif // PANDA_FTS
157 
158  fYX->SetCanvas( fCanvas );
159  fYX->SetTitle( "XY" );
160  fZX->SetCanvas( fCanvas );
161  fZX->SetTitle( "ZX" );
162  if (fZR) {
163  fZR->SetCanvas( fCanvas );
164  fZR->SetTitle( "ZR" );
165  }
166 
167 
168  fMarker = TMarker( 0.0, 0.0, 20 );//6);
169  fDrawOnlyRef = 0;
170 
171  firstCall = 0;
172  }
173 }
174 
176 {
177  // update windows
178  if ( !fAsk ) return;
179  fYX->Update();
180  fZX->Update();
181 //X fYX->Print( "YX.pdf" );
182  fZX->Print( "ZX.pdf" );
183 
184 }
185 
187 {
188  // clear windows
189 #ifdef CLEAR
190  fYX->Clear();
191  fZX->Clear();
192 #endif
193  DrawTPC();
194 }
195 
197 {
198  // wait for the pressed key, when "r" pressed, don't ask anymore
199  char symbol;
200  if ( fAsk ) {
201  Update();
202  std::cout << "ask> ";
203  do {
204  std::cin.get( symbol );
205  if ( symbol == 'r' )
206  fAsk = false;
207  } while ( symbol != '\n' );
208  }
209 }
210 
211 
212 void PndFTSCADisplay::SetGB( const PndFTSCAGBTracker * GBTracker )
213 {
214  fGB = GBTracker;
215 }
216 
218 {
219  // schematically draw TPC detector
220  const int detColor = kGray+1; // color of the detector
221 #if defined(PANDA_STT)
222  // just borders
223  fYX->cd();
224 #ifdef CLEAR
225  fYX->Clear();
226 #endif
227  {
228  fArc.SetLineColor( detColor );
229  fArc.SetFillStyle( 0 );
230  fArc.SetLineWidth(.1);
231  fArc.DrawArc( 0, 0, fROuterMax );
232  fArc.DrawArc( 0, 0, fRInnerMin );
233 
234  TLatex Tl;
235  Tl.SetTextSize(0.03);
236  Tl.SetTextAlign(22);
237  Tl.DrawLatex( -fROuterMax, fROuterMax, "XY" );
238  }
239 
240  fZX->cd();
241 #ifdef CLEAR
242  fZX->Clear();
243 #endif
244  {
245  TBox ZX;
246  ZX.SetFillStyle( 0 );
247  ZX.SetFillColor(0);
248  ZX.SetLineWidth(.1);
249  ZX.SetLineColor(detColor);
250  ZX.DrawBox(fZMin,-fROuterMax,fZMax,fROuterMax);
251  // ZX.DrawBox(fZMin,fROuterMax,fZMax,fRInnerMin);
252 
253  TLatex Tl;
254  Tl.SetTextSize(0.03);
255  Tl.SetTextAlign(22);
256  Tl.DrawLatex( fZMin*0.93, fROuterMax*0.95, "ZY" );
257  }
258 #elif defined(PANDA_FTS)
259  // just borders
260  fYX->cd();
261 #ifdef CLEAR
262  fYX->Clear();
263 #endif
264  {
265  TBox XY;
266  XY.SetFillStyle( 0 );
267  XY.SetFillColor(0);
268  XY.SetLineWidth(.1);
269  XY.SetLineColor(detColor);
270  XY.DrawBox(fXMin,fYMin,fXMax,fYMax);
271 
272  TLatex Tl;
273  Tl.SetTextSize(0.03);
274  Tl.SetTextAlign(22);
275  Tl.DrawLatex( fXMin + (fXMax-fXMin)*0.07, fYMax - (fYMax-fYMin)*0.05, "XY" );
276  }
277 
278  fZX->cd();
279 #ifdef CLEAR
280  fZX->Clear();
281 #endif
282  {
283  TBox ZX;
284  ZX.SetFillStyle( 0 );
285  ZX.SetFillColor(0);
286  ZX.SetLineWidth(.1);
287  ZX.SetLineColor(detColor);
288  ZX.DrawBox(fZMin,fXMin,fZMax,fXMax);
289 
290  const int NStations = 6;
291  const float XLeft[NStations] = { -659.025, -659.025, -881.225, -1042.825, -1951.825, -1951.825 }; // mm
292  const float NTubes[NStations] = { 132, 132, 176, 208, 388, 388 };
293  const float MinZ[NStations] = { 2949.627, 3269.627, 3940.627, 4380.627, 6070.627, 6390.627 };
294  const float MaxZ[NStations] = { 3108.373, 3428.373, 4244.123, 4684.123, 6229.373, 6549.373 };
295  const float Offset = 2;
296  for ( int iS = 0; iS < NStations; iS++ )
297  ZX.DrawBox( MinZ[iS]/10 - Offset, XLeft[iS]/10 - Offset, MaxZ[iS]/10 + Offset, (XLeft[iS] + NTubes[iS]*10.1)/10 + Offset );
298 
299 
300  TLatex Tl;
301  Tl.SetTextSize(0.03);
302  Tl.SetTextAlign(22);
303  Tl.DrawLatex( fZMin + (fZMax-fZMin)*0.07, fXMax - (fXMax-fXMin)*0.05, "ZX" );
304  }
305 #else // FTS
306  fYX->cd();
307 #ifdef CLEAR
308  fYX->Clear();
309 #endif
310  const int color = detColor;
311  const float width = .1;
312  // STT
313  {
314  const float RMax = 40.827;
315 
316  {
317  TLine l;
318  l.SetLineColor( color );
319  l.SetLineWidth( width );
320  l.SetLineStyle( 9 );
321 
322  const float x0L = 16.1;//16.825;
323  const float a = x0L/sqrt(3.f/4.f);
324  double
325  x[7] = {0,x0L,x0L,0,-x0L,-x0L,0},
326  y[7] = {-a,-a/2,a/2,a,a/2,-a/2,-a};
327 
328  for ( int i = 0; i < 6; i++ ) {
329  const double c = RMax/sqrt(x[i]*x[i] + y[i]*y[i]);
330  l.DrawLine( x[i], y[i], c*x[i], c*y[i] );
331  }
332  }
333 
334 
335 
336  TPolyLine pl;
337  pl.SetLineColor( color );
338  pl.SetLineWidth( width );
339 
340  {
341  const float x0L = 16.1;//16.825;
342  const float a = x0L/sqrt(3.f/4.f);
343  double
344  x[7] = {0,x0L,x0L,0,-x0L,-x0L},
345  y[7] = {-a,-a/2,a/2,a,a/2,-a/2,-a};
346  pl.DrawPolyLine( 7, x, y );
347  }
348 
349  pl.SetLineStyle( 9 );
350 
351  {
352  const float x0L = 23.3;//16.825;
353  const float a = x0L/sqrt(3.f/4.f);
354  double
355  x[7] = {0,x0L,x0L,0,-x0L,-x0L},
356  y[7] = {-a,-a/2,a/2,a,a/2,-a/2,-a};
357  pl.DrawPolyLine( 7, x, y );
358  }
359 
360 
361  {
362  const float x0L = 31.7;//16.825;
363  const float a = x0L/sqrt(3.f/4.f);
364  double
365  x[7] = {0,x0L,x0L,0,-x0L,-x0L},
366  y[7] = {-a,-a/2,a/2,a,a/2,-a/2,-a};
367  pl.DrawPolyLine( 7, x, y );
368  }
369 
370  // MVD
371 
372  // {
373  // const float xMin = 2.126;
374  // TBox b;
375  // b.SetFillStyle(1);
376  // b.SetFillColor(kWhite);
377  // b.SetLineWidth(0);
378  // b.SetLineColor(kWhite);
379  // b.DrawBox(-xMin,-RMax-.1,xMin,RMax+.1);
380  // }
381 
382  fArc.SetLineColor( color );
383  fArc.SetFillStyle( 0 );
384  fArc.SetNoEdges(0);
385  fArc.SetLineWidth(width);
386  // {
387  // const float R = 2.408;
388  // const float xmin = 1.143;
389  // const float phi = 90 - 180.f*asin(xmin/R)/TMath::Pi();
390  // fArc.DrawArc( 0, 0, R, -phi, phi,"only" ); // 1st MVD
391  // }
392  // {
393  // const float R = 2.408;
394  // const float xmin = -1.538;
395  // const float phi = 90 - 180.f*asin(xmin/R)/TMath::Pi();
396  // fArc.DrawArc( 0, 0, R, -phi+360, phi,"only" ); // 1st MVD
397  // }
398  fArc.DrawArc( 0, 0, 2.408 ); // 1st MVD
399  fArc.DrawArc( 0, 0, 4.969 );
400  fArc.DrawArc( 0, 0, 9.210 );
401  fArc.DrawArc( 0, 0, 12.529 );
402  fArc.DrawArc( 0, 0, RMax ); // rMax STT
403 
404  TLatex Tl;
405  Tl.SetTextSize(0.03);
406  Tl.SetTextAlign(22);
407  Tl.DrawLatex( -fROuterMax, fROuterMax, "XY" );
408  }
409 
410  fZX->cd();
411 #ifdef CLEAR
412  fZX->Clear();
413 #endif
414  {
415  // barell MVD
416  TBox ZX;
417  ZX.SetFillStyle( 0 );
418  ZX.SetFillColor(0);
419  ZX.SetLineWidth(width);
420  ZX.SetLineColor(color);
421  // ZX.DrawBox(-1.601, -1.940, 0.976, 2.336); // from MCPoints
422  // ZX.DrawBox(-6.066, -5.209, 5.773, 5.178);
423  // ZX.DrawBox(-11.380, -9.567, 13.840, 9.616);
424  // ZX.DrawBox(-7.292, -12.788, 13.713, 12.767);
425  // ZX.DrawBox(-22.672, -40., 109.645, 40.);
426  ZX.DrawBox(-39.8/10, -28.58/10, 9.8/10, 28.58/10); // from TDR
427  ZX.DrawBox(-79.8/10, -52.82/10, 57.8/10, 52.82/10);
428  ZX.DrawBox(-133.8/10, -96.86/10, 139.0/10, 96.86/10);
429  ZX.DrawBox(-169.2/10, -129.24/10, 139.0/10, 129.24/10);
430  ZX.DrawBox(fZMin,-fROuterMax,fZMax,fROuterMax);
431 
432  // forward MVD
433  TLine l;
434  l.SetLineWidth(width);
435  l.SetLineColor(color);
436 
437  l.DrawLine(22/10, -36.56/10, 22/10, 36.56/10);
438  l.DrawLine(42/10, -36.56/10, 42/10, 36.56/10);
439  l.DrawLine(72/10, -73.96/10, 72/10, 73.96/10);
440  l.DrawLine(102/10, -73.96/10, 102/10, 73.96/10);
441  l.DrawLine(150/10, -73.96/10, 150/10, 73.96/10); // 5.1
442  l.DrawLine(162.5/10, -131.15/10, 162.5/10, 131.15/10); // 5.2
443  l.DrawLine(220/10, -73.96/10, 220/10, 73.96/10); // 6.1
444  l.DrawLine(207.5/10, -131.15/10, 207.5/10, 131.15/10); // 6.2
445 
446  TLatex Tl;
447  Tl.SetTextSize(0.03);
448  Tl.SetTextAlign(22);
449  Tl.DrawLatex( fZMin*0.93, fROuterMax*0.95, "ZY" );
450  }
451  if (fZR) {
452  fZR->cd();
453 #ifdef CLEAR
454  fZR->Clear();
455 #endif
456  {
457  // STT
458  {
459  TLine l;
460  l.SetLineWidth(width);
461  l.SetLineColor(color);
462 
463  l.DrawLine(fZMin, 16.1, fZMax, 16.1);
464  l.SetLineStyle( 9 );
465  l.DrawLine(fZMin, 23.3, fZMax, 23.3);
466  l.DrawLine(fZMin, 31.7, fZMax, 31.7);
467  }
468 
469  // barrel MVD
470  TBox ZX;
471  ZX.SetFillStyle( 0 );
472  ZX.SetFillColor(0);
473  ZX.SetLineWidth(width);
474  ZX.SetLineColor(color);
475  // ZX.DrawBox(-1.601, -1.940, 0.976, 2.336); // from MCPoints
476  // ZX.DrawBox(-6.066, -5.209, 5.773, 5.178);
477  // ZX.DrawBox(-11.380, -9.567, 13.840, 9.616);
478  // ZX.DrawBox(-7.292, -12.788, 13.713, 12.767);
479  // ZX.DrawBox(-22.672, 0., 109.645, 40.);
480  ZX.DrawBox(-39.8/10, 0, 9.8/10, 28.58/10); // from TDR
481  ZX.DrawBox(-79.8/10, 0, 57.8/10, 52.82/10);
482  ZX.DrawBox(-133.8/10, 0, 139.0/10, 96.86/10);
483  ZX.DrawBox(-169.2/10, 0, 139.0/10, 129.24/10);
484  ZX.DrawBox(fZMin, 0.,fZMax,fROuterMax);
485 
486  // forward MVD
487  {
488  TLine l;
489  l.SetLineWidth(width);
490  l.SetLineColor(color);
491 
492  l.DrawLine(22/10, 11.70/10, 22/10, 36.56/10);
493  l.DrawLine(42/10, 11.70/10, 42/10, 36.56/10);
494  l.DrawLine(72/10, 11.70/10, 72/10, 73.96/10);
495  l.DrawLine(102/10, 11.70/10, 102/10, 73.96/10);
496  l.DrawLine(150/10, 11.70/10, 150/10, 73.96/10); // 5.1
497  l.DrawLine(162.5/10, 74.33/10, 162.5/10, 131.15/10); // 5.2
498  l.DrawLine(220/10, 11.70/10, 220/10, 73.96/10); // 6.1
499  l.DrawLine(207.5/10, 74.33/10, 207.5/10, 131.15/10); // 6.2
500  }
501 
502  TLatex Tl;
503  Tl.SetTextSize(0.03);
504  Tl.SetTextAlign(22);
505  Tl.DrawLatex( fZMin*0.93, fROuterMax*0.975, "ZR" );
506  }
507  }
508 #endif // PANDA // detailed view
509 
510 }
511 
512 void PndFTSCADisplay::DrawArc(float x, float y, float r, int Start, Size_t width )
513 {
514  fArc.SetLineWidth( width );
515  fArc.SetLineColor( 2 + Start);
516 
517  fYX->cd();
518  fArc.DrawArc( x, y, r );
519 }
520 
521 void PndFTSCADisplay::DrawPoint(float x, float y, float z, int Start, Size_t width )
522 {
523  fMarker.SetMarkerSize( width );
524  fMarker.SetMarkerColor( 2 + Start);
525 
526  fYX->cd();
527  fMarker.DrawMarker( x, y );
528  fZX->cd();
529  fMarker.DrawMarker( z, y );
530 }
531 
532 void PndFTSCADisplay::DrawGBPoint(float x, float y, float z, int Start, Size_t width )
533 {
534  //std::cout<<"x y z "<<x<<" "<<y<<" "<<z<<std::endl;
535  fMarker.SetMarkerSize( width );
536  fMarker.SetMarkerColor( Start);
537 
538  fYX->cd();
539  fMarker.DrawMarker( x, y );
540  fZX->cd();
541 #ifdef PANDA_FTS
542  fMarker.DrawMarker( z, x );
543 #else
544  fMarker.DrawMarker( z, y );
545 
546  if (fZR) {
547  fZR->cd();
548  fMarker.DrawMarker( z, sqrt(y*y+x*x) );
549  }
550 #endif
551 }
552 
553 void PndFTSCADisplay::DrawGBPoint(float x, float y, float z, float angle, int Start, Size_t width )
554 {
555 
556  fMarker.SetMarkerSize( width );
557  fMarker.SetMarkerColor( Start);
558 
559  // fArrow.SetAngle(h.Angle());
560  fArrow.SetFillColor( Start );
561  fArrow.SetLineColor( Start );
562  fArrow.SetLineWidth( 1*width );
563 
564  double ax, ay, az;
565  double ax1 = 0;
566  double ay1 = 3;
567  double az1 = 0;
568  PndFTSCAParameters::CALocalToGlobal(ax1,ay1,az1, double(angle), ax, ay, az );
569  ax += x;
570  ay += y;
571 
572  fYX->cd();
573  fMarker.DrawMarker( x, y );
574 // fArrow.DrawArrow(x, y, ax, ay, 0.003, "|>"); // draw module direction
575 
576  fZX->cd();
577 #ifdef PANDA_FTS
578  fMarker.DrawMarker( z, x );
579 #else
580  fMarker.DrawMarker( z, y );
581 
582  if( fZR ) {
583  fZR->cd();
584  fMarker.DrawMarker( z, sqrt(y*y+x*x) );
585  }
586 #endif
587 }
588 
589 void PndFTSCADisplay::DrawGBLine(float x, float y, float z, float x2, float y2, float z2, int Start, Size_t /*width*/, int projection ) //[R.K. 9/2018] unused
590 {
591  fLine.SetLineWidth( 2 );
592  fLine.SetLineColor( Start);
593 
594  if ( projection == -1 || projection == 0 ) {
595 #ifdef PANDA_FTS
596  fZX->cd();
597  fLine.DrawLine( z, x, z2, x2 );
598 #else
599  fYX->cd();
600  fLine.DrawLine( x, y, x2, y2 );
601 #endif
602  }
603  if ( projection == -1 || projection == 1 ) {
604 #ifdef PANDA_FTS
605  fYX->cd();
606  fLine.DrawLine( x, y, x2, y2 );
607 #else
608  fZX->cd();
609  fLine.DrawLine( z, y, z2, y2 );
610  if (fZR) {
611  fZR->cd();
612  fLine.DrawLine( z, sqrt(x*x+y*y), z2, sqrt(x2*x2+y2*y2) );
613  }
614 #endif
615  }
616 }
617 
618 int PndFTSCADisplay::GetColor( int i ) const
619 {
620  // Get color with respect to Z coordinate
621  const Color_t kMyColor[9] = { kGreen, kBlue, kYellow, kCyan, kOrange,
622  kSpring, kTeal, kAzure, kViolet
623  };
624  if ( i < 0 ) i = 0;
625  if ( i == 0 ) return kBlack;
626  return kMyColor[( i-1 )%9];
627 }
628 
629 int PndFTSCADisplay::GetColorZ( double z ) const
630 {
631  // Get color with respect to Z coordinate
632  const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
633  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
634  };
635 
636  double zz = ( z - fZMin ) / ( fZMax - fZMin );
637  int iz = ( int ) ( zz * 11 );
638  if ( iz < 0 ) iz = 0;
639  if ( iz > 10 ) iz = 10;
640  return kMyColor[iz];
641 }
642 
643 int PndFTSCADisplay::GetColorY( double y ) const
644 {
645  // Get color with respect to Z coordinate
646  const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan,
647  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
648  };
649 
650  double yy = ( y - fYMin ) / ( fYMax - fYMin );
651  int iy = ( int ) ( yy * 11 );
652  if ( iy < 0 ) iy = 0;
653  if ( iy > 10 ) iy = 10;
654  return kMyColor[iy];
655 }
656 
657 int PndFTSCADisplay::GetColorK( double k ) const
658 {
659  // Get color with respect to Z coordinate
660  const Color_t kMyColor[11] = { kRed, kBlue, kYellow, kMagenta, kCyan,
661  kOrange, kSpring, kTeal, kAzure, kViolet, kPink
662  };
663  const double kCLight = 0.000299792458;
664  const double kBz = 5;
665  double k2QPt = 100;
666  if ( TMath::Abs( kBz ) > 1.e-4 ) k2QPt = 1. / ( kBz * kCLight );
667  double qPt = k * k2QPt;
668  double pt = 100;
669  if ( TMath::Abs( qPt ) > 1.e-4 ) pt = 1. / TMath::Abs( qPt );
670 
671  double yy = ( pt - 0.1 ) / ( 1. - 0.1 );
672  int iy = ( int ) ( yy * 11 );
673  if ( iy < 0 ) iy = 0;
674  if ( iy > 10 ) iy = 10;
675  return kMyColor[iy];
676 }
677 
678 void PndFTSCADisplay::DrawGBHit( const PndFTSCAGBTracker &tracker, int iHit, int color, Size_t width )
679 {
680  // draw hit
681  const PndFTSCAGBHit &h = tracker.Hits()[iHit];
682 
683  if ( color < 0 ) {
684  if ( fPerf ) {
685  int lab = fPerf->HitLabel( h.ID() ).fLab[0];
686  color = GetColor( lab + 1 );
687  if ( lab >= 0 ) {
688  const PndFTSCAMCTrack &mc = fPerf->MCTrack( lab );
689  if ( mc.P() >= 1. ) color = kRed;
690  else if ( fDrawOnlyRef ) return;
691  }
692  } else color = GetColorZ( h.Z() );
693  }
694  if ( width > 0 )fMarker.SetMarkerSize( width );
695  else fMarker.SetMarkerSize( .3 );
696  fMarker.SetMarkerColor( color );
697  double vx = h.X(), vy = h.Y();
698 
699  fYX->cd();
700  fMarker.DrawMarker( vx, vy );
701  fZX->cd();
702  fMarker.DrawMarker( h.Z(), vy );
703 }
704 
705 void PndFTSCADisplay::DrawGBHits( const PndFTSCAGBTracker &tracker, int color, Size_t width, int hitsType)
706 {
707  // draw hits
708 
709  if ( !fPerf ) return;
710  if ( width < 0 ) width = .6;
711 
712  for ( int iHit = 0; iHit < tracker.NHits(); iHit++ ) {
713  const PndFTSCAGBHit &h = tracker.Hits()[iHit];
714 // if ((hitsType == 1) && (h.ISlice() >= 12)) continue;
715 // if ((hitsType == 2) && (h.ISlice() < 12) ) continue;
716 
717  int imc = fPerf->HitLabel( h.ID() ).fLab[0];
718  const PndFTSCAMCTrack *mc = ( imc >= 0 ) ? &( fPerf->MCTrack( imc ) ) : 0;
719  if ( fDrawOnlyRef && ( !mc || ( mc->P() < 1 ) ) ) continue;
720  int col = color;
721  if ( color < 0 ) {
722  if (hitsType == 1) {
723  if (h.Z() >= 0) col = kBlue;
724  if (h.Z() < 0) col = 8;
725  }
726  else{
727  col = GetColor( imc + 1 ) ;
728  if ( mc && ( mc->P() >= PParameters::RefThreshold ) ) col = kRed;
729  }
730  }
731 
732  fMarker.SetMarkerSize( width );
733  fMarker.SetMarkerColor( col );
734  double vx = h.X(), vy = h.Y();
735 
736  // // fArrow.SetAngle(h.Angle());
737  // fArrow.SetFillColor( col );
738  // fArrow.SetLineColor( col );
739  // fArrow.SetLineWidth( 1*width );
740 
741  // double ax, ay, az;
742  // double ax1 = 0;
743  // double ay1 = 1;
744  // double az1 = 0;
745  // PndFTSCAParameters::CALocalToGlobal(ax1,ay1,az1, double(h.Angle()), ax, ay, az );
746  // ax += vx;
747  // ay += vy;
748 
749  fYX->cd();
750  fMarker.DrawMarker( vx, vy );
751  // fArrow.DrawArrow(vx, vy, ax, ay, 0.001, "|>"); // draw module direction
752 
753 #if defined(DRIFT_TUBES)
754  if ( h.IRow() < PndFTSCAParameters::NMVDStations ) // only MVD
755 #endif
756  {
757  fZX->cd();
758  fMarker.DrawMarker( h.Z(), vy );
759 
760  if (fZR) {
761  fZR->cd();
762  fMarker.DrawMarker( h.Z(), sqrt(vx*vx+vy*vy) );
763  }
764  }
765 
766 #if defined(DRIFT_TUBES)
767  TEllipse el;
768  el.SetLineWidth( width );
769  el.SetLineColor( col );
770  el.SetFillStyle( 0 );
771  if ( h.IsPileduped() ) {
772  el.SetLineColor( kBlack );
773  }
774 #ifdef PANDA_STT
775  fYX->cd();
776 
777  if ( fabs(h.ErrX12()) < 1e-7 ) {
778  el.DrawEllipse( h.XW(), h.YW(), h.R(), h.R(), 0, 360, h.Angle()*180/TMath::Pi() );
779  fMarker.DrawMarker( h.XW(), h.YW() );
780  } else { // find the closes point of stereo tube to the track
781 
782  double b = h.Beta();
783  double r2Min = 10e10, xSaved = 0, ySaved = 0, zSaved = 0;
784  for ( int itr = 0; itr < fGB->NTracks(); itr++ ) {
785  PndFTSCAGBTrack &t = fGB->Tracks()[itr];
787 
788  // transport to hit
789  const bool rotated = p.Rotate( -p.Angle() + h.Angle() );
790  float x0,x1,x2;
791  PndFTSCAParameters::GlobalToCALocal(h.XW(), h.YW(), h.ZW(), h.Angle(), x0, x1, x2);
792  const bool transported = p.TransportToX0( x0, fGB->GetParameters().cBz() );
793  if (!rotated || !transported) continue;
794 
795  float p1 = p.Y(), p2 = p.Z();
796 
797  // find closest point on line
798  // xx1 - x1 = b*(xx2 - x2)
799  // perpendicular xx1 - p1 = 1/b*(xx2 - p2)
800 
801  const double beta = b;
802  const double betaLast = M_PI_2 + b;
803  const double zL = p2, yL = p1;
804  const double z = x2, y = x1;
805 
806  const double ctbL = tan( - betaLast);
807  const double ctb = tan( - beta);
808  double xM = x0;
809  double zM = ((zL*ctbL - yL) - (z*ctb - y))/(ctbL - ctb);
810  double yM = y + (zM - z)*ctb;
811 
812  double r2 = (yM - yL)*(yM - yL) + (zM - zL)*(zM - zL);
813 
814  if (r2 > r2Min) continue;
815  r2Min = r2;
816  PndFTSCAParameters::CALocalToGlobal(xM, yM, zM, static_cast<double>(h.Angle()), xSaved, ySaved, zSaved);
817  }
818  el.DrawEllipse( xSaved, ySaved, h.R(), h.R(), 0, 360, h.Angle()*180/TMath::Pi() );
819  fMarker.DrawMarker( xSaved, ySaved );
820  }
821 #else // PANDA_FTS
822  fZX->cd();
823 
824  if ( fabs(h.ErrX12()) < 1e-7 ) {
825  el.DrawEllipse( h.ZW(), h.XW(), h.R(), h.R(), 0, 360, h.Angle()*180/TMath::Pi() );
826  fMarker.DrawMarker( h.ZW(), h.XW() );
827  } else {
828  fMarker.DrawMarker( h.ZW(), h.XW() );
829  }
830 #endif
831 
832 
833  // fMarker.SetMarkerStyle(10);
834  // fMarker.SetMarkerSize(width/4);
835 
836  // fMarker.SetMarkerStyle(9);
837  // fMarker.SetMarkerSize(width);
838 
839 // TLatex* Tl = new TLatex();
840 // Tl->SetTextSize(0.002);
841 // Tl->SetTextAlign(22);
842 // TString s = "";
843 // s += h.ID();
844 // s += ";";
845 // s += fPerf->HitLabel( h.ID() ).fLab[0];
846 // s += ";";
847 // // s += fPerf->HitLabel( h.ID() ).fLab[1];
848 // // s += ";";
849 // // s += fPerf->HitLabel( h.ID() ).fLab[2];
850 // // s += ";";
851 // s += h.IRow();
852 
853 // #ifdef PANDA_FTS
854 // s += ";";
855 // s+= int(h.Z()*100);
856 // s+= ";";
857 // s+= int(h.X()*100);
858 // Tl->DrawLatex( h.ZW(), h.XW(), s);
859 // #else
860 // // s+= int(h.X()*100);
861 // // s+= ";";
862 // // s+= int(h.Y()*100);
863 // Tl->DrawLatex( vx, vy, s);
864 // #endif
865 
866 #ifdef PANDA_STT
867  fZX->cd(); // TODO
868 #else
869  fYX->cd(); // TODO
870 #endif
871 
872  // { // draw covariance ellipse
873  // // eigen values;
874  // const double C00 = h.C(2,2);
875  // const double C01 = h.C(2,1);
876  // const double C11 = h.C(1,1);
877  // const double b = - (C00+C11);
878  // const double det = sqrt(b*b - 4*(C00*C11 - C01*C01)); // l^2 - (C00+C11)l + C00*C11 - C01*C01 = 0
879  // const double e1 = (- b + det)*0.5, e2 = (- b - det)*0.5;
880  // double a = 0;
881  // if (abs(C00 - C11) > 1e-7) {
882  // a = 0.5*atan(2*C01/(C00-C11));
883  // if (C00 < C11)
884  // a = TMath::Pi()/2 - a;
885  // }
886 
887  // el.DrawEllipse( h.ZW(), h.YW(), sqrt(e1)*kSS, sqrt(e2)*kSS*1e-10, 0, 360, a*180/TMath::Pi() );
888  // }
889 
890  // if( h.IRow() >= 8 && h.IRow() <= 15 )
891  // el.DrawEllipse( h.Z(), vy, sqrt(h.Err2Z()), sqrt(h.Err2Y()), 0, 360, 0 );//h.Angle()*180/TMath::Pi() );
892 #endif // DRIFT_TUBES
893  }
894 }
895 
896 void PndFTSCADisplay::HitToGlobal( const FTSCAHit& h, float& x, float& y, float &z )
897 {
898  PndFTSCAParameters::CALocalToGlobal(h.X0(), h.X1(), h.X2(), h.Angle(), x, y, z);
899 }
900 
901 void PndFTSCADisplay::HitToGlobal( const FTSCAHitV& h, int iV, float& x, float& y, float &z )
902 {
903  PndFTSCAParameters::CALocalToGlobal(float(h.X0()[iV]), float(h.X1()[iV]), float(h.X2()[iV]), float(h.Angle()[iV]), x, y, z);
904 }
905 
906 #if defined(DRIFT_TUBES)
907 #define COUNT_SAME_HITS // count same wires positions
908 #endif
909 #ifdef COUNT_SAME_HITS
910 bool operator<(const TVector3& a, const TVector3& b) {
911  if (a.X() != b.X())
912  return a.X() < b.X();
913  else
914  if (a.Y() != b.Y())
915  return a.Y() < b.Y();
916  else
917  return a.Z() < b.Z();
918 }
919 #endif
920 
921 
923 
924  for( int iS = 0, iColor = 0; iS < all.NStations(); ++iS, iColor++ ) {
925  if ( iColor == kYellow )
926  iColor++;
927  if ( iColor == kWhite )
928  iColor++;
929 
930 #ifdef COUNT_SAME_HITS
931  map<TVector3,int> nSameHits;
932 #endif
933  const FTSCAElementsOnStation<FTSCAHitV>& s = all.OnStation( iS );
934  for( unsigned int i = 0; i < s.size(); ++i ) {
935 
936  const FTSCAHitV &h = s[i];
937  foreach_bit( int iV, h.IsValid() ) {
938  float gx, gy, gz;
939  HitToGlobal( h, iV, gx, gy, gz );
940  //if ( abs(atan(gy/gx)) < 3.1415/180*5 )
941  DrawGBPoint( gx, gy, gz, iColor, 0.1 );
942 
943 #ifdef COUNT_SAME_HITS
944  TVector3 v(gx, gy, gz);
945  if ( nSameHits.count(v) > 0 )
946  nSameHits[v]++;
947  else
948  nSameHits[v] = 1;
949 #endif
950 
951  TLatex* Tl = new TLatex();
952  Tl->SetTextSize(0.002);
953  Tl->SetTextAlign(22);
954  // TString ss = "";
955  // ss+= h.Angle()[iV];
956  // ss+= " ";
957  // ss+= h.X0()[iV];
958  // ss+= " ";
959  // ss+= h.X1()[iV];
960  TString ss = "";
961  ss += fPerf->HitLabel( fGB->Hits()[h.Id()[iV]].ID() ).fLab[0];
962  ss += ";";
963  ss += fPerf->HitLabel( fGB->Hits()[h.Id()[iV]].ID() ).fLab[1];
964  ss += ";";
965  ss += fPerf->HitLabel( fGB->Hits()[h.Id()[iV]].ID() ).fLab[2];
966  fYX->cd();
967  Tl->DrawLatex( gx, gy, ss);
968  // std::cout << iS << " " << i << cd -" " << iV << " " << h.X1()[iV] << " " << h.X2()[iV] << " " << h.X0()[iV] << std::endl; // dbg
969  }
970  }
971 #ifdef COUNT_SAME_HITS
972  for (std::map<TVector3,int>::iterator it=nSameHits.begin(); it!=nSameHits.end(); ++it) {
973  TLatex* Tl = new TLatex();
974  Tl->SetTextSize(0.002);
975  Tl->SetTextAlign(22);
976  TString text = "";
977  text += it->second;
978  fYX->cd();
979  Tl->DrawLatex( it->first.X(), it->first.Y(), text );
980  }
981 #endif
982 
983  }
984 }
985 
986 
988 
989  for( int iS = 0, iColor = 0; iS < all.NStations(); ++iS, iColor++ ) {
990  if ( iColor == kYellow )
991  iColor++;
992  if ( iColor == kWhite )
993  iColor++;
994 
995 #ifdef COUNT_SAME_HITS
996  map<TVector3,int> nSameHits;
997 #endif
998  const FTSCAElementsOnStation<FTSCAHit>& s = all.OnStation( iS );
999  for( unsigned int i = 0; i < s.size(); ++i ) {
1000 
1001  const FTSCAHit &h = s[i];
1002  //if (h.IsUsed()) continue;
1003  if (h.IStation()<0) continue;
1004  float gx, gy, gz;
1005  HitToGlobal( h, gx, gy, gz );
1006  //if ( abs(atan(gy/gx)) < 3.1415/180*5 )
1007  DrawGBPoint( gx, gy, gz, iColor, 0.8 );
1008 
1009 #ifdef COUNT_SAME_HITS
1010  TVector3 v(gx, gy, gz);
1011  if ( nSameHits.count(v) > 0 )
1012  nSameHits[v]++;
1013  else
1014  nSameHits[v] = 1;
1015 #endif
1016 
1017  TLatex* Tl = new TLatex();
1018  Tl->SetTextSize(0.002);
1019  Tl->SetTextAlign(22);
1020  // TString ss = "";
1021  // ss+= h.Angle()[iV];
1022  // ss+= " ";
1023  // ss+= h.X0()[iV];
1024  // ss+= " ";
1025  // ss+= h.X1()[iV];
1026  TString ss = "";
1027  ss += fPerf->HitLabel( fGB->Hits()[h.Id()].ID() ).fLab[0];
1028  ss += ";";
1029  ss += fPerf->HitLabel( fGB->Hits()[h.Id()].ID() ).fLab[1];
1030  ss += ";";
1031  ss += fPerf->HitLabel( fGB->Hits()[h.Id()].ID() ).fLab[2];
1032  fYX->cd();
1033  Tl->DrawLatex( gx, gy, ss);
1034  // std::cout << iS << " " << i << cd -" " << " " << h.X1() << " " << h.X2() << " " << h.X0() << std::endl; // dbg
1035 
1036  }
1037 #ifdef COUNT_SAME_HITS
1038  for (std::map<TVector3,int>::iterator it=nSameHits.begin(); it!=nSameHits.end(); ++it) {
1039  TLatex* Tl = new TLatex();
1040  Tl->SetTextSize(0.002);
1041  Tl->SetTextAlign(22);
1042  TString text = "";
1043  text += it->second;
1044  fYX->cd();
1045  Tl->DrawLatex( it->first.X(), it->first.Y(), text );
1046  }
1047 #endif
1048 
1049  }
1050 }
1051 
1052 //#define CALC_GEO
1054 #ifdef CALC_GEO
1055  const int NSta = 30;
1056  static int N[NSta];
1057  // for MVD
1058  static double r[NSta];
1059  static double zRange[NSta][2];
1060  static double yRange[NSta][2];
1061  static double xRange[NSta][2][2]; // 0 - negative, 1 - positive
1062  // for STT
1063  static double rMax[NSta];
1064  static double x0LRange[NSta][2];
1065 
1066  static bool first_call = true;
1067  if (first_call) {
1068  for( int i = 0; i < NSta; i++ ) {
1069  N[i] = 0;
1070  r[i] = 0;
1071  zRange[i][0] = 1e10;
1072  zRange[i][1] = -1e10;
1073  yRange[i][0] = 1e10;
1074  yRange[i][1] = -1e10;
1075  xRange[i][0][0] = 1e10;
1076  xRange[i][0][1] = -1e10;
1077  xRange[i][1][0] = 1e10;
1078  xRange[i][1][1] = -1e10;
1079  rMax[i] = -1e10;
1080  x0LRange[i][0] = 1e10;
1081  x0LRange[i][1] = -1e10;
1082  }
1083  first_call = false;
1084  }
1085 #endif // CALC_GEO
1086 
1087  const PndFTSResizableArray<PndFTSCALocalMCPoint>& mcPs = *(fPerf->GetMCPoints());
1088  for( int i = 0; i < mcPs.Size(); ++i ) {
1089  PndFTSCALocalMCPoint mcPoint = mcPs[i];
1090  double mcX0 = mcPoint.X();
1091  double mcY0 = mcPoint.Y();
1092  double mcZ = mcPoint.Z();
1093 
1094  PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kRed, (Size_t).8);
1095  // switch ( mcPoint.IRow() ) {
1096  // case 0: PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kBlack, (Size_t).2); break;
1097  // case 1: PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kBlue, (Size_t).2); break;
1098  // case 2: PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kGreen, (Size_t).2); break;
1099  // case 3: PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kRed, (Size_t).2); break;
1100  // default: PndFTSCADisplay::Instance().DrawGBPoint((float)mcX0, (float)mcY0, (float)mcZ, kGray, (Size_t).2);
1101  // }
1102 
1103 #ifdef CALC_GEO
1104  const int iS = mcPoint.IRow();
1105  if ( iS >= NSta || iS < 0 ) continue;
1106  N[iS]++;
1107  const double rCurr = sqrt(mcX0*mcX0 + mcY0*mcY0);
1108  r[iS] += sqrt(mcX0*mcX0 + mcY0*mcY0);
1109  zRange[iS][0] = std::min( zRange[iS][0], mcZ );
1110  zRange[iS][1] = std::max( zRange[iS][1], mcZ );
1111  yRange[iS][0] = std::min( yRange[iS][0], mcY0 );
1112  yRange[iS][1] = std::max( yRange[iS][1], mcY0 );
1113  if ( mcX0 < 0 ) {
1114  xRange[iS][0][0] = std::min( xRange[iS][0][0], mcX0 );
1115  xRange[iS][0][1] = std::max( xRange[iS][0][1], mcX0 );
1116  } else {
1117  xRange[iS][1][0] = std::min( xRange[iS][1][0], mcX0 );
1118  xRange[iS][1][1] = std::max( xRange[iS][1][1], mcX0 );
1119  }
1120  rMax[iS] = std::max( rMax[iS], rCurr );
1121  double x0,x1;
1122 
1123  double A = atan( abs(mcY0/mcX0) ); // angle of slice
1124  const double pi2 = TMath::Pi()/2;
1125  if ( mcY0 >= 0 && mcX0 >= 0 ) A = pi2 - A;
1126  if ( mcY0 < 0 && mcX0 >= 0 ) A = pi2 + A;
1127  if ( mcY0 < 0 && mcX0 < 0 ) A = 3*pi2 - A;
1128  if ( mcY0 >= 0 && mcX0 < 0 ) A = 3*pi2 + A;
1129  A = floor(A/pi2*6)*pi2*2/3.f;
1130  // turn by -(A+3.1415/6)
1131  A = A+pi2/3.f;
1132  PndFTSCAParameters::GlobalToCALocal(mcX0,mcY0,-A,x0,x1);
1133 
1134  cout << iS << " " << mcX0 << " "<< x0 << " " << A << " " << mcPoint.Angle() << endl;
1135  x0LRange[iS][0] = std::min( x0LRange[iS][0], abs(x0) );
1136  x0LRange[iS][1] = std::max( x0LRange[iS][1], abs(x0) );
1137 #endif // CALC_GEO
1138  }
1139 
1140 #ifdef CALC_GEO
1141  for( int i = 0; i < NSta; i++ )
1142  cout << i << " station: "
1143  << " x- = [" << xRange[i][0][0] << "," << xRange[i][0][1] << "]"
1144  << " x+ = [" << xRange[i][1][0] << "," << xRange[i][1][1] << "]"
1145  << " y = [" << yRange[i][0] << "," << yRange[i][1] << "]"
1146  << " z = [" << zRange[i][0] << "," << zRange[i][1] << "]" << endl
1147  << " r = " << r[i]/N[i]
1148  << " rMax = " << rMax[i]
1149  << " x0Local = [" << x0LRange[i][0] << "," << x0LRange[i][1] << "]" << endl;
1150 #endif // CALC_GEO
1151 }
1152 
1153 void PndFTSCADisplay::DrawPVHisto(const vector<float>& pvHist, const PndFTSCAParam& param) {
1154  const unsigned int N = pvHist.size();
1155  const float maxZ = param.MaxZ();
1156  float max = -1;
1157  for( unsigned int i = 0; i < N; ++i ) {
1158  max = ( max < pvHist[i] ) ? pvHist[i] : max;
1159  }
1160 
1161  for( unsigned int i = 0; i < N; ++i ) {
1162  float z = (2.f*i/N-1)*maxZ;
1163  float dr = pvHist[i]/max*maxZ;
1164 
1165  fZX->cd();
1166  fLine.SetLineColor( kBlue );
1167  fLine.SetLineWidth(0);
1168  fLine.DrawLine( z, 0, z, -dr );
1169  }
1170 }
1171 
1173  for( int iS = 0; iS < all.NStations(); ++iS )
1174  {
1175  const FTSCAElementsOnStation<FTSCANPletV>& s = all.OnStation( iS );
1176  if ( s.size() <= 0 ) continue;
1177  const int N = s[0].N();
1178 
1179  int color = 2;
1180  color = kRed;
1181  /*switch( N )
1182  {
1183  case 1: color = kYellow; break;
1184  case 2: color = kMagenta; break;
1185  case 3: color = kBlue; break;
1186  case 4: color = kOrange; break;
1187  case 5: color = kGreen; break;
1188  case 6: color = kRed; break;
1189  }*/
1190  /*switch( int(iS/10) )
1191  {
1192  case 0: color = kViolet+iS; break;
1193  case 1: color = kOrange+((iS%2)*10); break;
1194  case 2: color = kAzure+((iS%2)*10); break;
1195  case 3: color = kGreen+((iS%2)*4); break;
1196  case 4: color = kMagenta+((iS%2)*4); break;
1197  }*/
1198  for( unsigned int i = 0; i < s.size(); ++i )
1199  {
1200  foreach_bit( int iV, s[i].IsValid() )
1201  {
1202  vector<float> gx(N), gy(N), gz(N);
1203  for ( int ih = 0; ih < N; ih++ )
1204  {
1205  HitToGlobal( s.GetHit( iV, ih, i ), gx[ih], gy[ih], gz[ih] );
1206  }
1207 
1208  for ( int ih = 1; ih < N; ih++ )
1209  {
1210  DrawGBLine( gx[ih-1], gy[ih-1], gz[ih-1], gx[ih], gy[ih], gz[ih], color, 0 );
1211  }
1212 
1213  if ( N == 1 ) // singlets
1214  DrawGBLine( 0,0,0, gx[0], gy[0], gz[0], color, 0 );
1215 
1216  /*if (gz[N-1]>606){
1217  cout<<"N "<<s[i].N()<<" QP "<<s[i].Param().QP()[0]<<" Tx "<<s[i].Param().Tx()[0]<<" Ty "<<s[i].Param().Ty()[0]<<" X "<<s[i].Param().X()[0]<<" Y "<<s[i].Param().Y()[0]<<" Chi2 "<<s[i].Param().Chi2()[0]<<endl;
1218  Ask();
1219  }*/
1220  cout<<"N "<<s[i].N()<<" QP "<<s[i].Param().QP()[0]<<" Tx "<<s[i].Param().Tx()[0]<<" Ty "<<s[i].Param().Ty()[0]<<" X "<<s[i].Param().X()[0]<<" Y "<<s[i].Param().Y()[0]<<" Chi2 "<<s[i].Param().Chi2()[0]<<endl;
1221  }
1222  }
1223  //Update();
1224  //Ask();
1225  }
1226 }
1227 
1228 
1230 {
1231  if ( s.size() <= 0 ) return;
1232  const int N = s[0].N();
1233 
1234  int color = 2;
1235  switch( N )
1236  {
1237  case 1: color = kYellow; break;
1238  case 2: color = kMagenta; break;
1239  case 3: color = kBlue; break;
1240  case 4: color = kOrange; break;
1241  case 5: color = kGreen; break;
1242  case 6: color = kRed; break;
1243  }
1244 
1245  for( unsigned int i = 0; i < s.size(); ++i )
1246  {
1247  //cout<<"s[i].IsValid() "<<s[i].IsValid()<<endl;
1248  //cout<<"N "<<N<<endl;
1249  foreach_bit( int iV, s[i].IsValid() )
1250  {
1251  vector<float> gx(N), gy(N), gz(N);
1252  for ( int ih = 0; ih < N; ih++ )
1253  {
1254  HitToGlobal( s.GetHit( iV, ih, i ), gx[ih], gy[ih], gz[ih] );
1255  }
1256  if ( N == 1 ) // singlets
1257  {
1258  //cout<<"gx[0], gy[0], gz[0] "<<gx[0]<<" "<<gy[0]<<" "<<gz[0]<<endl;
1259  DrawGBLine( 0,0,0, gx[0], gy[0], gz[0], color, 0 );
1260  }
1261  for ( int ih = 1; ih < N; ih++ )
1262  {
1263  //cout<<"gx[ih], gy[ih], gz[ih] "<<gx[ih]<<" "<<gy[ih]<<" "<<gz[ih]<<endl;
1264  DrawGBLine( gx[ih-1], gy[ih-1], gz[ih-1], gx[ih], gy[ih], gz[ih], color+2*(ih==1), 0 );
1265  }
1266  }
1267  }
1268 }
1269 
1270 
1272  for( unsigned int i = 0; i < all.size(); ++i ) {
1273  const FTSCATrack& t = all[i];
1274  const unsigned int NTHits = t.NHits();
1275  FTSCAHit hitP = all.Hit(0, i);
1276  for( unsigned int iH=1; iH < NTHits; iH++) {
1277  const FTSCAHit& hit = all.Hit(iH, i);
1278 
1279  float gx0, gy0, gz0, gx1, gy1, gz1;
1280  HitToGlobal( hitP, gx0, gy0, gz0 );
1281  HitToGlobal( hit, gx1, gy1, gz1 );
1282  DrawGBLine( gx0, gy0, gz0, gx1, gy1, gz1, kRed, 0.1 );
1283 
1284  hitP = hit;
1285  }
1286  }
1287 }
1288 
1290 {
1291  // get MC label for the track
1292 
1293  const PndFTSCAGBTracker &tracker = *fGB;
1294 
1295  int label = -1;
1296  double purity = 0;
1297  int *lb = new int[NHits*3];
1298  int nla = 0;
1299  //std::cout<<"\n\nTrack hits mc: "<<std::endl;
1300  for ( int ihit = 0; ihit < NHits; ihit++ ) {
1301  const PndFTSCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
1302  const PndFTSCAPerformance::PndFTSCAHitLabel &l = fPerf->HitLabel( h.ID() );
1303  if ( l.fLab[0] >= 0 ) lb[nla++] = l.fLab[0];
1304  if ( l.fLab[1] >= 0 ) lb[nla++] = l.fLab[1];
1305  if ( l.fLab[2] >= 0 ) lb[nla++] = l.fLab[2];
1306  //std::cout<<ihit<<": "<<l.fLab[0]<<" "<<l.fLab[1]<<" "<<l.fLab[2]<<std::endl;
1307  }
1308  std::sort( lb, lb + nla );
1309  int labmax = -1, labcur = -1, lmax = 0, lcurr = 0, nh = 0;
1310  //std::cout<<"MC track IDs :"<<std::endl;
1311  for ( int i = 0; i < nla; i++ ) {
1312  if ( lb[i] != labcur ) {
1313  if ( 0 && i > 0 && lb[i-1] >= 0 ) {
1314  const PndFTSCAMCTrack &mc = fPerf->MCTrack( lb[i-1] );
1315  std::cout << lb[i-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
1316  << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
1317  << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
1318 
1319  }
1320  nh = 0;
1321  if ( labcur >= 0 && lmax < lcurr ) {
1322  lmax = lcurr;
1323  labmax = labcur;
1324  }
1325  labcur = lb[i];
1326  lcurr = 0;
1327  }
1328  lcurr++;
1329  nh++;
1330  }
1331  if ( 0 && nla - 1 > 0 && lb[nla-1] >= 0 ) {
1332  const PndFTSCAMCTrack &mc = fPerf->MCTrack( lb[nla-1] );
1333  std::cout << lb[nla-1] << ": nhits=" << nh << ", pdg=" << mc.PDG() << ", Pt=" << mc.Pt() << ", P=" << mc.P()
1334  << ", par=" << mc.Par()[0] << " " << mc.Par()[1] << " " << mc.Par()[2]
1335  << " " << mc.Par()[3] << " " << mc.Par()[4] << " " << mc.Par()[5] << " " << mc.Par()[6] << std::endl;
1336 
1337  }
1338  if ( labcur >= 0 && lmax < lcurr ) {
1339  lmax = lcurr;
1340  labmax = labcur;
1341  }
1342  lmax = 0;
1343  for ( int ihit = 0; ihit < NHits; ihit++ ) {
1344  const PndFTSCAGBHit &h = tracker.Hits()[vHits[ihit].ID()];
1345  const PndFTSCAPerformance::PndFTSCAHitLabel &l = fPerf->HitLabel( h.ID() );
1346  if ( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax
1347  ) lmax++;
1348  }
1349  label = labmax;
1350  purity = ( ( NHits > 0 ) ? double( lmax ) / double( NHits ) : 0 );
1351  if ( lb ) delete[] lb;
1352  if ( purity < .9 ) label = -1;
1353  return label;
1354 }
1355 
1356 
1358  int NHits, int color, Size_t width, bool pPoint )
1359 {
1360 // // draw track
1361 // #ifndef DRAW_3D
1362 // bool drawEndPoints = 1;
1363 // #else
1364  const bool drawEndPoints = 0;
1365 // #endif // DRAW_3D
1366 
1367  if ( NHits < 2 ) return 0;
1368 
1369  const PndFTSCAGBTracker &tracker = *fGB;
1370  if ( width < 0 ) width = 2;
1371 
1372  if ( fDrawOnlyRef ) {
1373  int lab = GetTrackMC( vHits, NHits );
1374  if ( lab < 0 ) return 0;
1375  const PndFTSCAMCTrack &mc = fPerf->MCTrack( lab );
1376  if ( mc.P() < 1 ) return 0;
1377  }
1378 
1379  if ( color < 0 ) {
1380  //color = GetColorZ( (vz[0]+vz[mHits-1])/2. );
1381  //color = GetColorK(t.Kappa());
1382  int lab = GetTrackMC( vHits, NHits );
1383  color = GetColor( lab + 1 );
1384  if ( lab >= 0 ) {
1385  const PndFTSCAMCTrack &mc = fPerf->MCTrack( lab );
1386  if ( mc.P() >= PParameters::RefThreshold ) color = kRed;
1387  }
1388  }
1389 
1390 #if !defined(PANDA_FTS)
1391  if ( t.SinPhi() > .999 ) t.SetSinPhi( .999 );
1392  else if ( t.SinPhi() < -.999 ) t.SetSinPhi( -.999 );
1393 #endif
1394  // int iSlice = fSlice->Param().ISlice();
1395 
1396  //sort(vHits, vHits + NHits, PndFTSCADisplayTmpHit::CompareHitZ );
1397 
1398  vector<double> vx(NHits), vy(NHits), vz(NHits);
1399  int mHits = 0;
1400 
1401  //int oldSlice = -1;
1402  double alpha = Alpha;
1403  PndFTSCATrackParam tt = t;
1404 
1405  for ( int iHit = 0; iHit < NHits; iHit++ ) {
1406 
1407  const PndFTSCAGBHit &h = tracker.Hits()[vHits[iHit].ID()];
1408 
1409  double hCos = TMath::Cos( alpha );
1410  double hSin = TMath::Sin( alpha );
1411  double x0 = h.X(), y0 = h.Y(), z1 = h.Z();
1412  double x1 = x0 * hCos + y0 * hSin;
1413  double y1 = y0 * hCos - x0 * hSin;
1414 
1415  {
1416  double dx = x1 - tt.X();
1417  double dy = y1 - tt.Y();
1418  if ( dx*dx + dy*dy > 1. ) {
1419  double dalpha = TMath::ATan2( dy, dx );
1420  if ( tt.Rotate( dalpha ) ) {
1421  alpha += dalpha;
1422  hCos = TMath::Cos( alpha );
1423  hSin = TMath::Sin( alpha );
1424  x1 = x0 * hCos + y0 * hSin;
1425  y1 = y0 * hCos - x0 * hSin;
1426  }
1427  }
1428  }
1429 
1430  vx[mHits] = x1;
1431  vy[mHits] = y1;
1432  vz[mHits] = z1;
1433  mHits++;
1434  }
1435  if ( pPoint ) {
1436  double x1 = t.X(), y1 = t.Y(), z1 = t.Z();
1437 
1438  double dx = x1 - vx[0];
1439  double dy = y1 - vy[0];
1440  //std::cout<<x1<<" "<<y1<<" "<<vx[0]<<" "<<vy[0]<<" "<<dx<<" "<<dy<<std::endl;
1441  double d0 = dx * dx + dy * dy;
1442  dx = x1 - vx[mHits-1];
1443  dy = y1 - vy[mHits-1];
1444  //std::cout<<x1<<" "<<y1<<" "<<vx[mHits-1]<<" "<<vy[mHits-1]<<" "<<dx<<" "<<dy<<std::endl;
1445  double d1 = dx * dx + dy * dy;
1446  //std::cout<<"d0, d1="<<d0<<" "<<d1<<std::endl;
1447  if ( d1 < d0 ) {
1448  vx[mHits] = x1;
1449  vy[mHits] = y1;
1450  vz[mHits] = z1;
1451  mHits++;
1452  } else {
1453  for ( int i = mHits; i > 0; i-- ) {
1454  vx[i] = vx[i-1];
1455  vy[i] = vy[i-1];
1456  vz[i] = vz[i-1];
1457  }
1458  vx[0] = x1;
1459  vy[0] = y1;
1460  vz[0] = z1;
1461  mHits++;
1462  }
1463  }
1464 
1465 #ifdef DRAW_3D
1466  const float zoom = 0.6;
1467  const float z_zoom = 1.2;
1468  const float z0_zoom = 1000.;
1469  for ( int i = mHits - 1; i >= 0; i-- ) {
1470  TVector3 v(vx[i], -vz[i], vy[i]);
1471 
1472  v.RotateX(TMath::Pi()/70);
1473  v.RotateZ(TMath::Pi()/12);
1474  vx[i] = v.X()*zoom;
1475  vy[i] = v.Z()*zoom;
1476  vz[i] = -v.Y()*zoom;
1477 
1478  vx[i] *= (z0_zoom-vz[i])/z0_zoom * z_zoom;
1479  vy[i] *= (z0_zoom-vz[i])/z0_zoom * z_zoom;
1480  }
1481 #endif // DRAW_3D
1482 
1483 
1484  fLine.SetLineColor( color );
1485  fLine.SetLineWidth( width );
1486  fArc.SetFillStyle( 0 );
1487  fArc.SetLineColor( color );
1488  fArc.SetLineWidth( width );
1489  TPolyLine pl;
1490  pl.SetLineColor( color );
1491  pl.SetLineWidth( width );
1492  TPolyLine plZ;
1493  plZ.SetLineColor( color );
1494  plZ.SetLineWidth( width );
1495 
1496  fMarker.SetMarkerSize( width / 2. );
1497  fMarker.SetMarkerColor( color );
1498 
1499  fYX->cd();
1500  pl.DrawPolyLine( mHits, &vx[0], &vy[0] );
1501  if (drawEndPoints) {
1502  fMarker.DrawMarker( vx[0], vy[0] );
1503  fMarker.DrawMarker( vx[mHits-1], vy[mHits-1] );
1504  }
1505  fZX->cd();
1506  plZ.DrawPolyLine( mHits, &vz[0], &vy[0] );
1507  if (drawEndPoints) {
1508  fMarker.DrawMarker( vz[0], vy[0] );
1509  fMarker.DrawMarker( vz[mHits-1], vy[mHits-1] );
1510  }
1511 
1512  fLine.SetLineWidth( 1 );
1513  return 1;
1514 }
1515 
1516 void PndFTSCADisplay::DrawHelix(float p0, float c, float z, float zStart, float z0, float xc, float yc, float r, float b, int color, Size_t width)
1517 {
1518  fLine.SetLineColor(color);
1519  fLine.SetLineWidth(width);
1520  // draw slice track
1521  float x,y,p;
1522  p = p0 + c*(zStart-z0)/b;
1523  y = yc + r*sin(p);
1524  x = xc + c*r*cos(p);
1525 
1526  float zPrev = zStart;
1527  float xPrev = x;
1528  float yPrev = y;
1529  float zEnd = z;
1530 
1531  for(int i=1; i<100; i++)
1532  {
1533  z = zStart + (zEnd-zStart)/100*i;
1534  p = p0 + c*(z-z0)/b;
1535  y = yc + r*sin(p);
1536  x = xc + c*r*cos(p);
1537 
1538  fYX->cd();
1539  fLine.DrawLine( x, y, xPrev, yPrev);
1540  fZX->cd();
1541  fLine.DrawLine( z, y, zPrev, yPrev);
1542 
1543  xPrev = x;
1544  yPrev = y;
1545  zPrev = z;
1546  }
1547 }
1548 
1549 void PndFTSCADisplay::DrawParticleGlobal(float *param, float q, float tStart, float tEnd, float b, int color, Size_t width)
1550 {
1551  fLine.SetLineColor(color);
1552  fLine.SetLineWidth(width);
1553  fArrow.SetFillColor( color );
1554  fArrow.SetLineColor( color );
1555  fArrow.SetLineWidth( width );
1556 
1557  float p[8];
1558  for(int iP=0; iP<8; iP++)
1559  p[iP] = param[iP];
1560 
1561  float t = tStart;
1562 
1563  float xPrev=0, yPrev=0, zPrev=0;
1564 
1565  const float kCLight = 0.000299792458;
1566  b = b*q*kCLight;
1567 
1568  for(int i=0; i<=100; i++)
1569  {
1570  t = tEnd/100*i;
1571  float bs= b*t;
1572  float s = sin(bs), c = cos(bs);
1573  float sB, cB;
1574 
1575  const float kOvSqr6 = 1./sqrt(6.);
1576 
1577  sB = (1.e-8 < fabs(bs)) ? (s/b) : ((1-bs*kOvSqr6)*(1+bs*kOvSqr6)*t) ;
1578  cB = (1.e-8 < fabs(bs)) ? ((1-c)/b) : (.5*sB*bs) ;
1579 
1580  float px = param[3];
1581  float py = param[4];
1582  float pz = param[5];
1583 
1584  p[0] = param[0] + sB*px + cB*py;
1585  p[1] = param[1] - cB*px + sB*py;
1586  p[2] = param[2] + t*pz;
1587  p[3] = c*px + s*py;
1588  p[4] = -s*px + c*py;
1589  p[5] = param[5];
1590  p[6] = param[6];
1591  p[7] = param[7];
1592 
1593  if(i>0)
1594  {
1595  fYX->cd();
1596  fLine.DrawLine( p[0], p[1], xPrev, yPrev);
1597  fZX->cd();
1598  fLine.DrawLine( p[2], p[1], zPrev, yPrev);
1599  }
1600 
1601  xPrev = p[0];
1602  yPrev = p[1];
1603  zPrev = p[2];
1604  }
1605 }
1606 
1607 void PndFTSCADisplay::DrawParticleGlobal(float *param, float q, float n[4], float b, int color, Size_t width)
1608 {
1609  fLine.SetLineColor(color);
1610  fLine.SetLineWidth(width);
1611  fArrow.SetFillColor( color );
1612  fArrow.SetLineColor( color );
1613  fArrow.SetLineWidth( width );
1614 
1615  float p[8];
1616  for(int iP=0; iP<8; iP++)
1617  p[iP] = param[iP];
1618 
1619  float t = 0;
1620 
1621  float xPrev=p[0], yPrev=p[1], zPrev=p[2];
1622 
1623  const float kCLight = 0.000299792458;
1624  b = b*q*kCLight;
1625 
1626  float step = -0.05;
1627  double dist = p[0]*n[0]+p[1]*n[1]+p[2]*n[2]+n[3];
1628  double dist_last = dist;
1629  bool step_changed = false;
1630  for(int i=1; dist > 0 && i < 10000; i++)
1631  {
1632 // cout << p[0]*n[0]+p[1]*n[1]+p[2]*n[2]+n[3] << endl;
1633  t = step*i;
1634  float bs= b*t;
1635  float s = sin(bs), c = cos(bs);
1636  float sB, cB;
1637 
1638  const float kOvSqr6 = 1./sqrt(6.);
1639 
1640  sB = (1.e-8 < fabs(bs)) ? (s/b) : ((1-bs*kOvSqr6)*(1+bs*kOvSqr6)*t) ;
1641  cB = (1.e-8 < fabs(bs)) ? ((1-c)/b) : (.5*sB*bs) ;
1642 
1643  float px = param[3];
1644  float py = param[4];
1645  float pz = param[5];
1646 
1647  p[0] = param[0] + sB*px + cB*py;
1648  p[1] = param[1] - cB*px + sB*py;
1649  p[2] = param[2] + t*pz;
1650  p[3] = c*px + s*py;
1651  p[4] = -s*px + c*py;
1652  p[5] = param[5];
1653  p[6] = param[6];
1654  p[7] = param[7];
1655 
1656  dist = p[0]*n[0]+p[1]*n[1]+p[2]*n[2]+n[3];
1657 
1658  if(dist < dist_last)
1659  {
1660  fYX->cd();
1661  fLine.DrawLine( p[0], p[1], xPrev, yPrev);
1662  fZX->cd();
1663  fLine.DrawLine( p[2], p[1], zPrev, yPrev);
1664  }
1665  else if ( abs(dist - dist_last) < 1e-8 ) {
1666  step *= 2;
1667  i--;
1668  continue;
1669  }
1670  else if (!step_changed) { // wrong direction
1671  step *= -1;
1672  step_changed = true;
1673  i--;
1674  continue;
1675  }
1676  else { // too curved track
1677  break;
1678  }
1679 
1680  xPrev = p[0];
1681  yPrev = p[1];
1682  zPrev = p[2];
1683 
1684  dist_last = dist;
1685  }
1686 
1687  DrawGBPoint( xPrev, yPrev, zPrev, color, 0.2 );
1688 }
1689 
1690 void PndFTSCADisplay::DrawGBTrack( int itr, int color, int width )
1691 {
1692  // draw global track
1693 
1694  const PndFTSCAGBTracker &tracker = *fGB;
1695 
1696  const PndFTSCAGBTrack &track = tracker.Track( itr );
1697  if ( track.NHits() < 2 ) return;
1698 
1699  vector<PndFTSCADisplayTmpHit> vHits( track.NHits() );
1700 
1701  for ( int ih = 0; ih < track.NHits(); ih++ ) {
1702  const int i = tracker.TrackHit( track.FirstHitRef() + ih );
1703  const PndFTSCAGBHit &h = tracker.Hit( i );
1704  vHits[ih].SetID( i );
1705  vHits[ih].SetS( 0 );
1706  vHits[ih].SetZ( h.Z() );
1707  }
1708 
1709  DrawTrack( track.Param(), track.Param().Angle(), &(vHits[0]), track.NHits(), color, width );
1710 }
1711 
1712 void PndFTSCADisplay::DrawRecoTrack( int itr, int color, int width )
1713 {
1714  const PndFTSCAGBTracker &tracker = *fGB;
1715 
1716  const PndFTSCAGBTrack &track = tracker.Track( itr );
1717  if ( track.NHits() < 2 ) return;
1718 
1719 #if 1 // draw by hits or by parameters
1720  PndFTSCAGBHit hLast = tracker.Hit( tracker.TrackHit( track.FirstHitRef() ) );
1721 #if defined(DRIFT_TUBES)
1722  double hLx = hLast.X(), hLy = hLast.Y(), hLz = hLast.Z();
1723  int skipped = 0;
1724 #endif
1725  for ( int ih = 1; ih < track.NHits(); ih++ ) {
1726  const int i = tracker.TrackHit( track.FirstHitRef() + ih );
1727  const PndFTSCAGBHit& h = tracker.Hit( i );
1728 #if defined(DRIFT_TUBES)
1729 
1730  // draw cross point (this point is drawn in assupmtion that track is perpendicular to layers, if it is not, the point will be shifted a little)
1731  {
1732  const double betaLast = M_PI_2 + hLast.Beta(); // strip angle
1733  const double beta = M_PI_2 + h.Beta(); // strip angle
1734  if ( fabs(betaLast - beta) > 5e-7 && h.IRow() > PndFTSCAParameters::NMVDStations ) {
1735 
1736  const double ctbL = tan(M_PI_2 - betaLast);
1737  const double ctb = tan(M_PI_2 - beta);
1738  float xL, yL, zL, x, y, z;
1739  hLast.GetLocalX0X1X2( xL, yL, zL );
1740  h.GetLocalX0X1X2( x, y, z );
1741 
1742  double xM = (xL + x)*0.5;
1743  double zM = ((zL*ctbL - yL) - (z*ctb - y))/(ctbL - ctb);
1744  double yM = y + (zM - z)*ctb;
1745  double xMg, yMg, zMg;
1746  PndFTSCAParameters::CALocalToGlobal(xM, yM, zM, static_cast<double>(h.Angle()), xMg, yMg, zMg);
1747 
1748  if ( ih - skipped != 1 || ( fabs(hLast.ErrX12()) < 1e-7) ) {
1749  if ( fabs(hLast.ErrX12()) < 1e-7 )
1750  DrawGBLine( hLx, hLy, hLz, xMg, yMg, zMg, color, width, 0 );
1751  else
1752  DrawGBLine( hLx, hLy, hLz, xMg, yMg, zMg, color, width );
1753  }
1754  DrawGBPoint( xMg, yMg, zMg, kBlack, 0.1 );
1755 
1756  hLx = xMg;
1757  hLy = yMg;
1758  hLz = zMg;
1759  skipped = 0;
1760  }
1761  else
1762  skipped++;
1763  }
1764 
1765  if ( fabs(h.ErrX12()) < 1e-7 ) {
1766  if ( h.IRow() >= PndFTSCAParameters::NMVDStations )
1767  DrawGBLine( hLx, hLy, hLz, h.X(), h.Y(), h.Z(), color, width, 0 );
1768  else
1769  DrawGBLine( hLx, hLy, hLz, h.X(), h.Y(), h.Z(), color, width );
1770  hLx = h.X(), hLy = h.Y(), hLz = h.Z();
1771  skipped = 0;
1772  }
1773 
1774 
1775 #else
1776  DrawGBLine( hLast.X(), hLast.Y(), hLast.Z(), h.X(), h.Y(), h.Z(), color, width );
1777 #endif
1778  hLast = h;
1779  }
1780 #else // draw by hits or by parameters
1781 
1782  PndFTSCATrackParam p = track.InnerParam();
1783 
1784  float x,y,z,px,py,pz;
1785  PndFTSCAParameters::CALocalToGlobal( p.X(), p.Y(), p.Z(), p.Angle(), x, y, z );
1786  const float px0 = p.SignCosPhi()*sqrt(1-p.SinPhi()*p.SinPhi())/p.QPt();
1787  const float py0 = p.SinPhi()/p.QPt();
1788  const float pz0 = p.DzDs()/p.QPt();
1789  PndFTSCAParameters::CALocalToGlobal( px0, py0, pz0, p.Angle(), px, py, pz );
1790 
1791  float param[8] = { x,y,z,px,py,pz, 0, 0 };
1792  const float l = fGB->GetParameters().MaxR()-sqrt(x*x + y*y);
1793  DrawParticleGlobal( param, 1.f, 0, l/sqrt(px0*px0+py0*py0), tracker.GetParameters().Bz(), color, 0 );
1794 #endif // draw by hits or by parameters
1795 }
1796 
1797 void PndFTSCADisplay::DrawMCTrack( int itr, int color, int width )
1798 {
1799  PndFTSCAPerformance& perf = PndFTSCAPerformance::Instance();
1800 
1801  const PndFTSResizableArray<PndFTSCAMCTrack>& mcTs = *perf.GetMCTracks();
1802  const PndFTSResizableArray<PndFTSCALocalMCPoint>& mcPs = *perf.GetMCPoints();
1803 
1804  const PndFTSCAMCTrack &track = mcTs[itr];
1805  if ( track.NMCPoints() < 2 ) return;
1806 
1807  fLine.SetLineStyle( 3 );
1808  PndFTSCALocalMCPoint mcPLast = mcPs[ track.FirstMCPointID() ];
1809  for ( int ih = 1; ih < track.NMCPoints(); ih++ ) {
1810  const PndFTSCALocalMCPoint& mcP = mcPs[ track.FirstMCPointID() + ih ];
1811  DrawGBLine( mcPLast.X(), mcPLast.Y(), mcPLast.Z(), mcP.X(), mcP.Y(), mcP.Z(), color, width );
1812  mcPLast = mcP;
1813  }
1814 
1815  fLine.SetLineStyle( 1 );
1816 }
1817 
1818 #if !defined(PANDA_FTS)
1819 void PndFTSCADisplay::DrawGBTrackFast( const PndFTSCAGBTracker &tracker, int itr, int color )
1820 {
1821  // draw global track
1822 
1823  PndFTSCAGBTrack &track = tracker.Tracks()[itr];
1824  if ( track.NHits() < 2 ) return;
1825  int width = 1;
1826 
1827  PndFTSCADisplayTmpHit *vHits = new PndFTSCADisplayTmpHit[track.NHits()];
1828  PndFTSCATrackParam t = track.Param();
1829 
1830  for ( int ih = 0; ih < track.NHits(); ih++ ) {
1831  int i = tracker.TrackHits()[ track.FirstHitRef() + ih];
1832  const PndFTSCAGBHit *h = &( tracker.Hits()[i] );
1833  vHits[ih].SetID( i );
1834  vHits[ih].SetS( 0 );
1835  vHits[ih].SetZ( h->Z() );
1836  }
1837 
1838  sort( vHits, vHits + track.NHits(), PndFTSCADisplayTmpHit::CompareHitZ );
1839  int colorY = color;
1840  {
1841  const PndFTSCAGBHit &h1 = tracker.Hits()[ vHits[0].ID()];
1842  const PndFTSCAGBHit &h2 = tracker.Hits()[ vHits[track.NHits()-1].ID()];
1843  if ( color < 0 ) color = GetColorZ( ( h1.Z() + h2.Z() ) / 2. );
1844  double gy1 = h1.Y(), gy2 = h2.Y();
1845  if ( colorY < 0 ) colorY = GetColorY( ( gy1 + gy2 ) / 2. );
1846  color = colorY = GetColorK( t.QPt() );
1847  }
1848 
1849  fMarker.SetMarkerColor( color );//kBlue);
1850  fMarker.SetMarkerSize( 1. );
1851  fLine.SetLineColor( color );
1852  fLine.SetLineWidth( width );
1853  fArc.SetFillStyle( 0 );
1854  fArc.SetLineColor( color );
1855  fArc.SetLineWidth( width );
1856  TPolyLine pl;
1857  pl.SetLineColor( colorY );
1858  pl.SetLineWidth( width );
1859 
1860  // YX
1861  {
1862 
1863  const PndFTSCAGBHit &h1 = tracker.Hits()[vHits[0].ID()];
1864  const PndFTSCAGBHit &h2 = tracker.Hits()[vHits[track.NHits()-1].ID()];
1865  float x1, y1, z1, x2, y2, z2;
1866  double vx1, vy1, vx2, vy2;
1867 
1868  t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, tracker.GetParameters().Bz() );
1869  vx1 = x1;
1870  vy1 = y1;
1871 
1872  t.GetDCAPoint( h2.X(), h2.Y(), h2.Z(), x2, y2, z2, tracker.GetParameters().Bz() );
1873  vx2 = x2;
1874  vy2 = y2;
1875 
1876  double x0 = t.X();
1877  double y0 = t.Y();
1878  double sinPhi = t.SinPhi();
1879  double k = t.Kappa( tracker.GetParameters().Bz() );
1880  double ex = t.CosPhi();
1881  double ey = sinPhi;
1882 
1883  if ( TMath::Abs( k ) > 1.e-4 ) {
1884 
1885  fYX->cd();
1886 
1887  double r = 1 / TMath::Abs( k );
1888  double xc = x0 - ey * ( 1 / k );
1889  double yc = y0 + ex * ( 1 / k );
1890 
1891  double vx = xc, vy = yc;
1892 
1893  double a1 = TMath::ATan2( vy1 - vy, vx1 - vx ) / TMath::Pi() * 180.;
1894  double a2 = TMath::ATan2( vy2 - vy, vx2 - vx ) / TMath::Pi() * 180.;
1895  if ( a1 < 0 ) a1 += 360;
1896  if ( a2 < 0 ) a2 += 360;
1897  if ( a2 < a1 ) a2 += 360;
1898  double da = TMath::Abs( a2 - a1 );
1899  if ( da > 360 ) da -= 360;
1900  if ( da > 180 ) {
1901  da = a1;
1902  a1 = a2;
1903  a2 = da;
1904  if ( a2 < a1 ) a2 += 360;
1905  }
1906  fArc.DrawArc( vx, vy, r, a1, a2, "only" );
1907  //fArc.DrawArc(vx,vy,r, 0,360,"only");
1908  } else {
1909  fYX->cd();
1910  fLine.DrawLine( vx1, vy1, vx2, vy2 );
1911  }
1912  }
1913 
1914  // ZX
1915  PndFTSResizableArray<double> py( track.NHits() ), pz( track.NHits() );
1916 
1917  for ( int iHit = 0; iHit < track.NHits(); iHit++ ) {
1918 
1919  const PndFTSCAGBHit &h1 = tracker.Hits()[vHits[iHit].ID()];
1920  float x1, y1, z1;
1921  double vx1, vy1;
1922  t.GetDCAPoint( h1.X(), h1.Y(), h1.Z(), x1, y1, z1, tracker.GetParameters().Bz() );
1923  vx1 = x1;
1924  vy1 = y1;
1925  py[iHit] = vy1;
1926  pz[iHit] = z1;
1927  }
1928 
1929 
1930  fZX->cd();
1931  pl.DrawPolyLine( track.NHits(), pz.Data(), py.Data() );
1932 
1933  fLine.SetLineWidth( 1 );
1934  delete[] vHits;
1935 }
1936 
1938 {
1939  const PndFTSCAGBTracker &tracker = *fGB;
1940 
1941  for ( int i = 0; i < 100; ++i ) {
1942  double x = t.X();
1943  double y = t.Y();
1944  double sinPhi = t.SinPhi();
1945  double z = t.Z();
1946  double dzds = t.DzDs();
1947  double ex = t.CosPhi();
1948  double ey = sinPhi;
1949 
1950  fLine.SetLineWidth( 1 );
1951  fLine.SetLineColor( color );
1952 
1953  double vx = x, vy = y, vex = ex, vey = ey;
1954  double d = CAMath::RSqrt( vex * vex + vey * vey );
1955  vex *= d;
1956  vey *= d;
1957 
1958  fYX->cd();
1959  fLine.DrawLine( vx, vy, vx + vex*4, vy + vey*4 );
1960  fZX->cd();
1961  fLine.DrawLine( z, vy, z + dzds*4, vy + vey*4 );
1962 
1963  t.TransportToX0( x + ex * CAMath::RSqrt( ex * ex + ey * ey ), tracker.GetParameters().cBz() );
1964  }
1965 }
1966 #endif
1968  fCanvas->SaveAs(fileName);
1969 }
1970 
1972 #ifdef PANDA_FTS
1973  fXMin = tpcParam.MinX();
1974  fXMax = tpcParam.MaxX();
1975  fYMin = tpcParam.MinY();
1976  fYMax = tpcParam.MaxY();
1977  fZMin = tpcParam.MinZ();
1978  fZMax = tpcParam.MaxZ();
1979 
1980  const double dx = fXMax - fXMin;
1981  const double dy = fYMax - fYMin;
1982  const double dz = fZMax - fZMin;
1983  fYX->Range( fXMin - dx*0.01, fYMin - dy*0.01, fXMax + dx*0.01, fYMax + dy*0.01 );
1984  fZX->Range( fZMin - dz*0.01, fXMin - dx*0.01, fZMax + dz*0.01, fXMax + dx*0.01 );
1985  // fZX->Range( fZMin - dz*0.01, fXMin - -53*dx*0.01, fZMax + -90*dz*0.01, fXMax + -44*dx*0.01 ); zoom
1986 #else
1987  fZMin = tpcParam.MinZ();
1988  fZMax = tpcParam.MaxZ();
1989  fYMin = -60;
1990  fYMax = 60;
1991  fRInnerMin = tpcParam.MinR();
1992  fRInnerMax = 123.; // approximate TODO: from file!
1993  fROuterMin = 123.;
1994  fROuterMax = tpcParam.MaxR();//tpcParam.RMax();
1995 
1996  fYX->Range( -fROuterMax-2, -fROuterMax-2, fROuterMax+2, fROuterMax+2 );
1997  fZX->Range( fZMin*1.01, -fROuterMax*1.01, fZMax*1.01, fROuterMax*1.01 );
1998  if (fZR) {
1999  fZR->Range( fZMin*1.01, -fROuterMax*0.01, fZMax*1.01, fROuterMax*1.01 );
2000  }
2001 #endif
2002 }
2003 
2004 
void HitToGlobal(const FTSCAHit &hit, float &x, float &y, float &z)
Double_t z0
Definition: checkhelixhit.C:62
Double_t x0
Definition: checkhelixhit.C:70
float Z() const
float X2() const
Definition: FTSCAHits.h:43
float_v X2() const
Definition: FTSCAHitsV.h:51
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
double dy
const PndFTSCAGBTrack & Track(int i) const
float DzDs() const
void SetTPC(const PndFTSCAParam &tpcParam)
double r
Definition: RiemannTest.C:14
TObjArray * d
int TrackHit(int i) const
void DrawRecoTrack(int itr, int color=-1, int width=-1)
void DrawPVHisto(const vector< float > &pvHist, const PndFTSCAParam &param)
Int_t i
Definition: run_full.C:25
void GetDCAPoint(float x, float y, float z, float &px, float &py, float &pz, float Bz) const
TTree * b
int NMCPoints() const
char IStation() const
Definition: FTSCAHits.h:33
bool Rotate(float alpha, float maxSinPhi=.999)
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
PndRiemannTrack track
Definition: RiemannTest.C:33
float SignCosPhi() const
float Angle() const
Definition: FTSCAHits.h:71
void DrawGBPoint(float x, float y, float z, int Start=1, Size_t width=1)
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
TLorentzVector s
Definition: Pnd2DStar.C:50
PndFTSCAGBTrack * Tracks() const
static T Sin(const T &x)
Definition: PndCAMath.h:42
int col
Definition: anaLmdDigi.C:67
float P() const
int PDG() const
int n
int GetColorK(double k) const
int IRow() const
Definition: PndFTSCAGBHit.h:56
int GetTrackMC(const PndFTSCADisplayTmpHit *vHits, int NHits)
float Z() const
Definition: PndFTSCAGBHit.h:43
float_m IsValid() const
Definition: FTSCAHitsV.h:38
int FirstHitRef() const
void DrawGBHit(const PndFTSCAGBTracker &tracker, int iHit, int color=-1, Size_t width=-1)
static PndFTSCADisplay & Instance()
timer Start()
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
float_v X1() const
Definition: FTSCAHitsV.h:50
FairBoxGenerator * fBox
static T Cos(const T &x)
Definition: PndCAMath.h:43
float_v Angle() const
Definition: FTSCAHitsV.h:73
const PndFTSCAGBTracker * fGB
__m128 v
Definition: P4_F32vec4.h:4
float X0() const
Definition: FTSCAHits.h:41
void DrawGBLine(float x, float y, float z, float x2, float y2, float z2, int Start=1, Size_t width=1, int projection=-1)
float X1() const
Definition: FTSCAHits.h:42
Double_t p
Definition: anasim.C:58
float Y() const
Definition: PndFTSCAGBHit.h:42
int NStations() const
Definition: FTSCAHitsV.h:141
int GetColorY(double y) const
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
char NStations() const
Definition: FTSCAHits.h:152
Double_t d0
Definition: checkhelixhit.C:59
float ErrX12() const
Definition: PndFTSCAGBHit.h:53
static T Abs(const T &x)
Definition: PndCAMath.h:39
const PndFTSCATrackParam & OuterParam() const
void DrawGBTrackFast(const PndFTSCAGBTracker &tracker, int itr, int color=-1)
int NHits() const
float Bz() const
Definition: PndFTSCAParam.h:48
const FTSCAHit & GetHit(int iV, int IH, int i) const
FTSCAElementsOnStation< T > & OnStation(char i)
Definition: FTSCAHits.h:135
static T RSqrt(const T &x)
Definition: PndCAMath.h:38
void DrawMCTrack(int itr, int color=-1, int width=-1)
Int_t a
Definition: anaLmdDigi.C:126
float Par(int i) const
PndFTSCAPerformance * fPerf
char NStations() const
void SetGB(const PndFTSCAGBTracker *GBTracker)
static void GlobalToCALocal(T x, T y, T angle, T &x0, T &x1)
float cBz() const
Definition: PndFTSCAParam.h:49
static bool CompareHitDS(const PndFTSCADisplayTmpHit &a, const PndFTSCADisplayTmpHit &b)
void DrawGBTracks(const FTSCATracks &all)
float Angle() const
const PndFTSCAParam & GetParameters() const
Double_t y0
Definition: checkhelixhit.C:71
static T ATan2(const T &y, const T &x)
int GetColor(int i) const
void DrawGBTrack(int itr, int color=-1, int width=-1)
FTSCAElementsOnStation< T > & OnStation(char i)
Definition: FTSCAHitsV.h:128
TFile * f
Definition: bump_analys.C:12
const PndFTSCAGBHit * Hits() const
void SaveCanvasToFile(TString fileName)
FTSCAElementsOnStation< T > & OnStation(char i)
float MaxR() const
Double_t z
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
bool TransportToX0(float x, float Bz, float maxSinPhi=.999)
int ID() const
Definition: PndFTSCAGBHit.h:57
int * TrackHits() const
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
float X() const
Definition: PndFTSCAGBHit.h:41
bool DrawTrack(PndFTSCATrackParam t, double Alpha, const PndFTSCADisplayTmpHit *vHits, int NHits, int color=-1, Size_t width=-1, bool pPoint=0)
void GetLocalX0X1X2(float &x0, float &x1, float &x2) const
float MinR() const
void DrawGBNPlets(const FTSCANPletsV &all)
int NTracks() const
virtual ~PndFTSCADisplay()
const PndFTSCATrackParam & InnerParam() const
float MinZ() const
TPad * p2
Definition: hist-t7.C:117
double dx
static bool CompareHitZ(const PndFTSCADisplayTmpHit &a, const PndFTSCADisplayTmpHit &b)
void DrawPoint(float x, float y, float z, int Start=1, Size_t width=1)
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
double mcZ
Definition: anaLmdCluster.C:53
float Angle() const
Double_t x
const PndFTSCATrackParam & Param() const
float Pt() const
void DrawTrackParam(PndFTSCATrackParam t, int color=1)
static void CALocalToGlobal(T x0, T x1, T angle, T &x, T &y)
TPad * p1
Definition: hist-t7.C:116
void DrawArc(float x, float y, float r, int Start=1, Size_t width=1)
TTree * t
Definition: bump_analys.C:13
float_v X0() const
Definition: FTSCAHitsV.h:49
int Id() const
Definition: FTSCAHits.h:35
void SetID(int v)
Definition: PndFTSCAGBHit.h:96
Double_t y
double alpha
Definition: f_Init.h:9
Double_t angle
const PndFTSCAGBHit & Hit(int index) const
float SinPhi() const
uint_v Id() const
Definition: FTSCAHitsV.h:47
Double_t Pi
float MaxZ() const
const FTSCAHit & Hit(int iH, int iT) const
Definition: FTSCATracks.h:123
friend F32vec4 operator<(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:75
double r2
double pz[39]
Definition: pipisigmas.h:14
float X() const
void DrawParticleGlobal(float *param, float q, float tStart, float tEnd, float b, int color=kOrange, Size_t width=1)
float Kappa(float Bz) const
void DrawGBHits(const FTSCAHitsV &all)
float Y() const
int FirstMCPointID() const
int NHits() const
Definition: FTSCATracks.h:22
void DrawHelix(float p0, float c, float z, float zStart, float z0, float xc, float yc, float r, float b, int color, Size_t width)
static const float RefThreshold
int GetColorZ(double z) const