]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCADisplay.cxx
4f994471d59fd9fcbb1273c797d8306c300f7a5a
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCADisplay.cxx
1 // @(#) $Id$
2 //*************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project        * 
4 // ALICE Experiment at CERN, All rights reserved.                         *
5 //                                                                        *
6 // Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>              *
8 //                  for The ALICE HLT Project.                            *
9 //                                                                        *
10 // Permission to use, copy, modify and distribute this software and its   *
11 // documentation strictly for non-commercial purposes is hereby granted   *
12 // without fee, provided that the above copyright notice appears in all   *
13 // copies and that both the copyright notice and this permission notice   *
14 // appear in the supporting documentation. The authors make no claims     *
15 // about the suitability of this software for any purpose. It is          *
16 // provided "as is" without express or implied warranty.                  *
17 //*************************************************************************
18
19 #include "AliHLTTPCCADisplay.h"
20
21 #include "AliHLTTPCCATracker.h"
22   //#include "TString.h"
23 #include "Riostream.h"
24 #include "TMath.h"
25 #include "TStyle.h"
26 #include "TCanvas.h"
27 #include <algorithm>
28
29 ClassImp(AliHLTTPCCADisplay)
30
31 AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
32 {
33   // reference to static object
34   static AliHLTTPCCADisplay gAliHLTTPCCADisplay;
35   return gAliHLTTPCCADisplay; 
36 }
37
38 AliHLTTPCCADisplay::AliHLTTPCCADisplay() : fYX(0), fZX(0), fAsk(1), fSectorView(1), fSector(0), 
39                                            fCos(1), fSin(0), fZMin(-250), fZMax(250),
40                                            fRInnerMin(83.65), fRInnerMax(133.3), fROuterMin(133.5), fROuterMax(247.7),
41                                            fTPCZMin(-250.), fTPCZMax(250), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex()
42 {
43   // constructor
44 }
45
46 AliHLTTPCCADisplay::AliHLTTPCCADisplay( const AliHLTTPCCADisplay& ) 
47   : fYX(0), fZX(0), fAsk(1), fSectorView(1), fSector(0), 
48     fCos(1), fSin(0), fZMin(-250), fZMax(250),
49     fRInnerMin(83.65), fRInnerMax(133.3), fROuterMin(133.5), fROuterMax(247.7),
50     fTPCZMin(-250.), fTPCZMax(250), fArc(), fLine(), fPLine(), fMarker(), fBox(), fCrown(), fLatex()
51 {
52   // dummy
53 }
54
55 AliHLTTPCCADisplay& AliHLTTPCCADisplay::operator=( const AliHLTTPCCADisplay& )
56 {
57   // dummy
58   return *this;
59 }
60  
61 AliHLTTPCCADisplay::~AliHLTTPCCADisplay()
62 {
63   // destructor
64   delete fYX; 
65   delete fZX;
66 }
67
68 void AliHLTTPCCADisplay::Init()
69 {
70   // initialization
71   gStyle->SetCanvasBorderMode(0);
72   gStyle->SetCanvasBorderSize(1);
73   gStyle->SetCanvasColor(0);
74   fYX = new TCanvas ("YX", "YX window", -1, 0, 600, 600);
75   fZX = new TCanvas ("ZX", "ZX window", -610, 0, 590, 600);  
76   fMarker = TMarker(0.0, 0.0, 6);
77 }
78
79 void AliHLTTPCCADisplay::Update()
80 {
81   // update windows
82   if( !fAsk ) return;
83   fYX->Update();
84   fZX->Update();
85 }
86
87 void AliHLTTPCCADisplay::Clear()
88 {
89   // clear windows
90   fYX->Clear();
91   fZX->Clear();
92 }
93
94 void AliHLTTPCCADisplay::Ask()
95 {
96   // whait for the pressed key, when "r" pressed, don't ask anymore
97   char symbol;
98   if (fAsk){
99     Update();
100     std::cout<<"ask> "<<std::endl;
101     do{
102       std::cin.get(symbol);
103       if (symbol == 'r')
104         fAsk = false;
105     } while (symbol != '\n');
106   }
107 }
108
109
110 void AliHLTTPCCADisplay::SetSectorView()
111 {
112   // switch to sector view
113   fSectorView = 1;
114 }
115
116 void AliHLTTPCCADisplay::SetTPCView()
117 {
118   // switch to full TPC view
119   fSectorView = 0;
120   fCos = 1;
121   fSin = 0;
122   fZMin = fTPCZMin;
123   fZMax = fTPCZMax;
124 }
125
126 void AliHLTTPCCADisplay::SetCurrentSector( AliHLTTPCCATracker *sec )
127 {
128   // set reference to the current CA tracker, and read the current sector geometry
129   fSector = sec;
130   if( fSectorView ){
131     fCos = sec->Param().SinAlpha();
132     fSin = - sec->Param().CosAlpha();
133     fZMin = sec->Param().ZMin();
134     fZMax = sec->Param().ZMax();
135     Clear();
136     Double_t r0 = .5*(sec->Param().RMax()+sec->Param().RMin());
137     Double_t dr = .5*(sec->Param().RMax()-sec->Param().RMin());
138     Double_t cx = 0;
139     Double_t cy = r0;
140
141     fYX->Range(cx-dr, cy-dr, cx+dr, cy+dr);
142     Double_t cz = .5*(sec->Param().ZMax()+sec->Param().ZMin());
143     Double_t dz = .5*(sec->Param().ZMax()-sec->Param().ZMin())*1.2;
144     fZX->Range(cz-dz, cy-dr, cz+dz, cy+dr);
145   }
146 }
147
148 Int_t AliHLTTPCCADisplay::GetColor( Double_t z ) const 
149 {
150   // Get color with respect to Z coordinate
151   const Color_t kMyColor[11] = { kGreen, kBlue, kYellow, kMagenta, kCyan, 
152                                  kOrange, kSpring, kTeal, kAzure, kViolet, kPink };
153
154   Double_t zz = (z-fZMin)/(fZMax-fZMin);    
155   Int_t iz = (int) (zz*11);
156   if( iz<0 ) iz = 0;
157   if( iz>10 ) iz = 10;
158   return kMyColor[iz];
159 }
160
161 void AliHLTTPCCADisplay::Global2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
162 {
163   // convert coordinates global->view
164   *xv = x*fCos + y*fSin;
165   *yv = y*fCos - x*fSin;
166 }
167
168 void AliHLTTPCCADisplay::Sec2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
169 {
170   // convert coordinates sector->view
171   Double_t xg = x*fSector->Param().CosAlpha() - y*fSector->Param().SinAlpha();
172   Double_t yg = y*fSector->Param().CosAlpha() + x*fSector->Param().SinAlpha();
173   *xv = xg*fCos + yg*fSin;
174   *yv = yg*fCos - xg*fSin;
175 }
176
177
178 void AliHLTTPCCADisplay::DrawTPC()
179 {
180   // schematically draw TPC detector
181   fYX->Range(-fROuterMax, -fROuterMax, fROuterMax, fROuterMax);
182   fYX->Clear();
183   {
184     fArc.SetLineColor(kBlack);
185     fArc.SetFillStyle(0);
186     fYX->cd();    
187     for( Int_t iSec=0; iSec<18; iSec++){
188       fCrown.SetLineColor(kBlack);
189       fCrown.SetFillStyle(0);
190       fCrown.DrawCrown(0,0,fRInnerMin, fRInnerMax, 360./18.*iSec, 360./18.*(iSec+1) );
191       fCrown.DrawCrown(0,0,fROuterMin, fROuterMax, 360./18.*iSec, 360./18.*(iSec+1) );
192     }
193   }
194   fZX->cd();
195   fZX->Range( fTPCZMin, -fROuterMax, fTPCZMax, fROuterMax );
196   fZX->Clear();
197 }
198
199 void AliHLTTPCCADisplay::DrawSector( AliHLTTPCCATracker *sec )
200 {     
201   // draw current the TPC sector
202   fYX->cd();
203   Double_t r0 = .5*(sec->Param().RMax()+sec->Param().RMin());
204   Double_t dr = .5*(sec->Param().RMax()-sec->Param().RMin());
205   Double_t cx = r0*sec->Param().CosAlpha();
206   Double_t cy = r0*sec->Param().SinAlpha();
207   Double_t raddeg = 180./3.1415;
208   Double_t a0 = raddeg*.5*(sec->Param().AngleMax() + sec->Param().AngleMin());
209   Double_t da = raddeg*.5*(sec->Param().AngleMax() - sec->Param().AngleMin());
210   if( fSectorView ){
211     cx = 0; cy = r0;
212     a0 = 90.;
213     fLatex.DrawLatex(cx-dr+dr*.05,cy-dr+dr*.05, Form("Sec.%2i",sec->Param().ISec()));
214   }
215   fArc.SetLineColor(kBlack);
216   fArc.SetFillStyle(0);     
217   fCrown.SetLineColor(kBlack);
218   fCrown.SetFillStyle(0);
219     
220   fCrown.DrawCrown(0,0, sec->Param().RMin(),sec->Param().RMax(), a0-da, a0+da );
221
222   fLine.SetLineColor(kBlack);
223  
224   fZX->cd();
225
226   Double_t cz = .5*(sec->Param().ZMax()+sec->Param().ZMin());
227   Double_t dz = .5*(sec->Param().ZMax()-sec->Param().ZMin())*1.2;
228   //fLine.DrawLine(cz+dz, cy-dr, cz+dz, cy+dr ); 
229   if( fSectorView ) fLatex.DrawLatex(cz-dz+dz*.05,cy-dr+dr*.05, Form("Sec.%2i",sec->Param().ISec()));
230 }
231
232
233 void AliHLTTPCCADisplay::DrawHit( Int_t iRow, Int_t iHit, Int_t color )
234 {
235   // draw hit
236   if( !fSector ) return;
237   AliHLTTPCCARow &row = fSector->Rows()[iRow];
238   AliHLTTPCCAHit *h = &(row.Hits()[iHit]);
239   if( color<0 ) color = GetColor( h->Z() );
240
241   //Double_t dgy = 3.*TMath::Abs(h->ErrY()*fSector->Param().CosAlpha() - fSector->Param().ErrX()*fSector->Param().SinAlpha() );
242   //Double_t dx = fSector->Param().ErrX()*TMath::Sqrt(12.)/2.;
243   //Double_t dy = h->ErrY()*3.;
244   //Double_t dz = h->ErrZ()*3.;
245   fMarker.SetMarkerColor(color);
246   fArc.SetLineColor(color);
247   fArc.SetFillStyle(0);
248   Double_t vx, vy;
249   Sec2View( row.X(), h->Y(), &vx, &vy );
250   
251   fYX->cd();
252   //if( fSectorView ) fArc.DrawEllipse( vx, vy, dx, dy, 0,360, 90);
253   //else  fArc.DrawEllipse( vx, vy, dx, dy, 0,360, fSector->Param().Alpha()*180./3.1415);
254   fMarker.DrawMarker(vx, vy);
255   fZX->cd();
256   //if( fSectorView ) fArc.DrawEllipse( h->Z(), vy, dz, dx, 0,360, 90 );
257   //else fArc.DrawEllipse( h->Z(), vy, dz, dgy, 0,360, fSector->Param().Alpha()*180./3.1415);
258   fMarker.DrawMarker(h->Z(), vy); 
259 }
260
261 void AliHLTTPCCADisplay::DrawCell( Int_t iRow, AliHLTTPCCACell &cell, Int_t width, Int_t color )
262 {
263   // draw cell
264   AliHLTTPCCARow &row = fSector->Rows()[iRow];
265   Double_t vx, vy, vdx, vdy;
266   Sec2View(row.X(), cell.Y(), &vx, &vy);
267   Sec2View(0, cell.ErrY()*3, &vdx, &vdy);
268   if( color<0 ) color = GetColor(cell.Z());
269   fLine.SetLineColor(color);
270   fLine.SetLineWidth(width);
271   fYX->cd();
272   fLine.DrawLine(vx-vdx,vy-vdy, vx+vdx, vy+vdy );
273   fZX->cd();
274   fLine.DrawLine(cell.Z()-3*cell.ErrZ(),vy-vdy, cell.Z()+3*cell.ErrZ(), vy+vdy ); 
275   fLine.SetLineWidth(1);
276 }
277
278 void  AliHLTTPCCADisplay::DrawCell( Int_t iRow, Int_t iCell, Int_t width, Int_t color )
279 {
280   // draw cell
281   AliHLTTPCCARow &row = fSector->Rows()[iRow];
282   DrawCell( iRow, row.Cells()[iCell], width, color );
283 }
284  
285 void AliHLTTPCCADisplay::ConnectCells( Int_t iRow1, AliHLTTPCCACell &cell1, 
286                                        Int_t iRow2, AliHLTTPCCACell &cell2, Int_t color )
287 {
288   // connect two cells on display, kind of row is drawing
289   AliHLTTPCCARow &row1 = fSector->Rows()[iRow1];
290   AliHLTTPCCARow &row2 = fSector->Rows()[iRow2];
291
292   AliHLTTPCCAHit &h11 = row1.GetCellHit(cell1,0);
293   AliHLTTPCCAHit &h12 = row1.GetCellHit(cell1,cell1.NHits()-1);
294   AliHLTTPCCAHit &h21 = row2.GetCellHit(cell2,0);
295   AliHLTTPCCAHit &h22=  row2.GetCellHit(cell2,cell2.NHits()-1);
296
297   Double_t x11 = row1.X();
298   Double_t x12 = row1.X();
299   Double_t y11 = h11.Y() - h11.ErrY()*3;
300   Double_t y12 = h12.Y() + h12.ErrY()*3;
301   Double_t z11 = h11.Z();
302   Double_t z12 = h12.Z();
303   Double_t x21 = row2.X();
304   Double_t x22 = row2.X();
305   Double_t y21 = h21.Y() - h21.ErrY()*3;
306   Double_t y22 = h22.Y() + h22.ErrY()*3;
307   Double_t z21 = h21.Z();
308   Double_t z22 = h22.Z();
309
310   Double_t vx11, vx12, vy11, vy12, vx21, vx22, vy21, vy22;
311
312   Sec2View(x11,y11, &vx11, &vy11 );
313   Sec2View(x12,y12, &vx12, &vy12 );
314   Sec2View(x21,y21, &vx21, &vy21 );
315   Sec2View(x22,y22, &vx22, &vy22 );
316
317   Double_t lx[] = { vx11, vx12, vx22, vx21, vx11 };
318   Double_t ly[] = { vy11, vy12, vy22, vy21, vy11 };
319   Double_t lz[] = { z11, z12, z22, z21, z11 };
320
321   if( color<0 ) color = GetColor( (z11+z12+z22+z21)/4. );
322   fPLine.SetLineColor(color);    
323   fPLine.SetLineWidth(1);        
324   //fPLine.SetFillColor(color);
325   fPLine.SetFillStyle(-1);
326  
327   fYX->cd();
328   fPLine.DrawPolyLine(5, lx, ly );
329   fZX->cd();
330   fPLine.DrawPolyLine(5, lz, ly );   
331   DrawCell( iRow1, cell1, 1, color );
332   DrawCell( iRow2, cell2, 1, color );
333 }
334
335
336 void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color )
337 {
338   // draw track
339
340   if( track.NCells()<2 ) return;
341   int width = 3;
342   Double_t b = -5;    
343
344   AliHLTTPCCADisplayTmpCell *vCells = new AliHLTTPCCADisplayTmpCell[track.NCells()];
345
346   AliHLTTPCCATrackPar t = track.Param();
347   for( Int_t iCell=0; iCell<track.NCells(); iCell++ ){
348     AliHLTTPCCACell &c = fSector->GetTrackCell(track,iCell);
349     AliHLTTPCCARow &row = fSector->GetTrackCellRow(track,iCell);
350     Double_t xyz[3] = {row.X(), c.Y(), c.Z()};
351     if( iCell==0 ) t.TransportBz(-5, xyz);    
352     vCells[iCell].Index() = iCell;
353     vCells[iCell].S() = t.GetDsToPointBz(-5.,xyz);
354   }
355   sort(vCells, vCells + track.NCells(), AliHLTTPCCADisplayTmpCell::CompareCellDS );
356   t.Normalize();
357   const Double_t kCLight = 0.000299792458;
358   Double_t bc = b*kCLight;
359   Double_t pt = sqrt(t.Par()[3]*t.Par()[3] +t.Par()[4]*t.Par()[4] );
360   //Double_t p = sqrt(pt*pt +t.Par()[5]*t.Par()[5] );
361   Double_t q = t.Par()[6];
362
363   //for( Int_t iCell=0; iCell<track.fNCells-1; iCell++ )
364   {    
365     AliHLTTPCCACell &c1 = fSector->GetTrackCell(track,vCells[0].Index());
366     AliHLTTPCCACell &c2 = fSector->GetTrackCell(track,vCells[track.NCells()-1].Index());
367     AliHLTTPCCARow &row1 = fSector->GetTrackCellRow(track,vCells[0].Index());
368     AliHLTTPCCARow &row2 = fSector->GetTrackCellRow(track,vCells[track.NCells()-1].Index());
369     Double_t x1, y1, z1, x2, y2, z2;
370     {
371       Double_t xyz[3] = {row1.X(), c1.Y(), c1.Z()};
372       t.TransportBz(-5, xyz);
373       x1 = t.Par()[0]; y1 = t.Par()[1]; z1 = t.Par()[2];
374     }
375     {
376       Double_t xyz[3] = {row2.X(), c2.Y(), c2.Z()};
377       t.TransportBz(-5, xyz);
378       x2 = t.Par()[0]; y2 = t.Par()[1]; z2 = t.Par()[2];
379     }
380
381     if( color<0 ) color = GetColor( (z1+z2)/2. );
382     Double_t vx1, vy1, vx2, vy2;
383     Sec2View(x1, y1, &vx1, &vy1 );
384     Sec2View(x2, y2, &vx2, &vy2 );
385     
386     fLine.SetLineColor( color );
387     fLine.SetLineWidth( width );
388     
389     if( TMath::Abs(q)>.1 ){
390       Double_t qq = pt/q;
391       
392       Double_t xc = t.Par()[0] + qq*t.Par()[4]/pt/bc;
393       Double_t yc = t.Par()[1] - qq*t.Par()[3]/pt/bc;
394       Double_t r = TMath::Abs(qq)/TMath::Abs(bc);
395         
396       Double_t vx, vy;
397       Sec2View( xc, yc, &vx, &vy );
398       
399       Double_t a1 = TMath::ATan2(vy1-vy, vx1-vx)/TMath::Pi()*180.;
400       Double_t a2 = TMath::ATan2(vy2-vy, vx2-vx)/TMath::Pi()*180.;
401       Double_t da= a2-a1;      
402       if( da>=180 ) da=360-da;
403       if( da<=-180 ) da=360-da;
404       a1 = a2-da;
405       fArc.SetFillStyle(0);
406       fArc.SetLineColor(color);    
407       fArc.SetLineWidth(width);        
408       
409       fYX->cd();
410       
411       fArc.DrawArc(vx,vy,r, a1,a2,"only");
412     } else {
413       fYX->cd();
414       fLine.DrawLine(vx1,vy1, vx2, vy2 );
415     }
416     
417   }
418
419   for( Int_t iCell=0; iCell<track.NCells()-1; iCell++ ){
420     
421     AliHLTTPCCACell &c1 = fSector->GetTrackCell(track,vCells[iCell].Index());
422     AliHLTTPCCACell &c2 = fSector->GetTrackCell(track,vCells[iCell+1].Index());
423     AliHLTTPCCARow &row1 = fSector->GetTrackCellRow(track,vCells[iCell].Index());
424     AliHLTTPCCARow &row2 = fSector->GetTrackCellRow(track,vCells[iCell+1].Index());
425     ConnectCells( fSector->GetTrackCellIRow(track,vCells[iCell].Index()),c1,
426                   fSector->GetTrackCellIRow(track,vCells[iCell+1].Index()),c2, color );
427     Double_t x1, y1, z1, x2, y2, z2;
428     {
429       Double_t xyz[3] = {row1.X(), c1.Y(), c1.Z()};
430       t.TransportBz(-5, xyz);
431       x1 = t.Par()[0]; y1 = t.Par()[1]; z1 = t.Par()[2];
432     }
433     {
434       Double_t xyz[3] = {row2.X(), c2.Y(), c2.Z()};
435       t.TransportBz(-5, xyz);
436       x2 = t.Par()[0]; y2 = t.Par()[1]; z2 = t.Par()[2];
437     }
438    
439     Double_t vx1, vy1, vx2, vy2;
440     Sec2View(x1, y1, &vx1, &vy1 );
441     Sec2View(x2, y2, &vx2, &vy2 );
442     
443     fLine.SetLineColor(color);
444     fLine.SetLineWidth(width);    
445     
446     fZX->cd();
447     fLine.DrawLine(z1,vy1, z2, vy2 ); 
448   }
449   fLine.SetLineWidth(1);     
450   delete[] vCells;
451 }
452