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