2 //*************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
6 // Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
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 //*************************************************************************
19 #include "AliHLTTPCCADisplay.h"
21 #include "AliHLTTPCCATracker.h"
22 //#include "TString.h"
23 #include "Riostream.h"
29 ClassImp(AliHLTTPCCADisplay)
31 AliHLTTPCCADisplay &AliHLTTPCCADisplay::Instance()
33 // reference to static object
34 static AliHLTTPCCADisplay gAliHLTTPCCADisplay;
35 return gAliHLTTPCCADisplay;
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()
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()
55 AliHLTTPCCADisplay& AliHLTTPCCADisplay::operator=( const AliHLTTPCCADisplay& )
61 AliHLTTPCCADisplay::~AliHLTTPCCADisplay()
68 void AliHLTTPCCADisplay::Init()
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);
79 void AliHLTTPCCADisplay::Update()
87 void AliHLTTPCCADisplay::Clear()
94 void AliHLTTPCCADisplay::Ask()
96 // whait for the pressed key, when "r" pressed, don't ask anymore
100 std::cout<<"ask> "<<std::endl;
102 std::cin.get(symbol);
105 } while (symbol != '\n');
110 void AliHLTTPCCADisplay::SetSectorView()
112 // switch to sector view
116 void AliHLTTPCCADisplay::SetTPCView()
118 // switch to full TPC view
126 void AliHLTTPCCADisplay::SetCurrentSector( AliHLTTPCCATracker *sec )
128 // set reference to the current CA tracker, and read the current sector geometry
131 fCos = sec->Param().SinAlpha();
132 fSin = - sec->Param().CosAlpha();
133 fZMin = sec->Param().ZMin();
134 fZMax = sec->Param().ZMax();
136 Double_t r0 = .5*(sec->Param().RMax()+sec->Param().RMin());
137 Double_t dr = .5*(sec->Param().RMax()-sec->Param().RMin());
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);
148 Int_t AliHLTTPCCADisplay::GetColor( Double_t z ) const
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 };
154 Double_t zz = (z-fZMin)/(fZMax-fZMin);
155 Int_t iz = (int) (zz*11);
161 void AliHLTTPCCADisplay::Global2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
163 // convert coordinates global->view
164 *xv = x*fCos + y*fSin;
165 *yv = y*fCos - x*fSin;
168 void AliHLTTPCCADisplay::Sec2View( Double_t x, Double_t y, Double_t *xv, Double_t *yv ) const
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;
178 void AliHLTTPCCADisplay::DrawTPC()
180 // schematically draw TPC detector
181 fYX->Range(-fROuterMax, -fROuterMax, fROuterMax, fROuterMax);
184 fArc.SetLineColor(kBlack);
185 fArc.SetFillStyle(0);
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) );
195 fZX->Range( fTPCZMin, -fROuterMax, fTPCZMax, fROuterMax );
199 void AliHLTTPCCADisplay::DrawSector( AliHLTTPCCATracker *sec )
201 // draw current the TPC sector
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());
213 fLatex.DrawLatex(cx-dr+dr*.05,cy-dr+dr*.05, Form("Sec.%2i",sec->Param().ISec()));
215 fArc.SetLineColor(kBlack);
216 fArc.SetFillStyle(0);
217 fCrown.SetLineColor(kBlack);
218 fCrown.SetFillStyle(0);
220 fCrown.DrawCrown(0,0, sec->Param().RMin(),sec->Param().RMax(), a0-da, a0+da );
222 fLine.SetLineColor(kBlack);
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()));
233 void AliHLTTPCCADisplay::DrawHit( Int_t iRow, Int_t iHit, Int_t color )
236 if( !fSector ) return;
237 AliHLTTPCCARow &row = fSector->Rows()[iRow];
238 AliHLTTPCCAHit *h = &(row.Hits()[iHit]);
239 if( color<0 ) color = GetColor( h->Z() );
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);
249 Sec2View( row.X(), h->Y(), &vx, &vy );
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);
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);
261 void AliHLTTPCCADisplay::DrawCell( Int_t iRow, AliHLTTPCCACell &cell, Int_t width, Int_t color )
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);
272 fLine.DrawLine(vx-vdx,vy-vdy, vx+vdx, vy+vdy );
274 fLine.DrawLine(cell.Z()-3*cell.ErrZ(),vy-vdy, cell.Z()+3*cell.ErrZ(), vy+vdy );
275 fLine.SetLineWidth(1);
278 void AliHLTTPCCADisplay::DrawCell( Int_t iRow, Int_t iCell, Int_t width, Int_t color )
281 AliHLTTPCCARow &row = fSector->Rows()[iRow];
282 DrawCell( iRow, row.Cells()[iCell], width, color );
285 void AliHLTTPCCADisplay::ConnectCells( Int_t iRow1, AliHLTTPCCACell &cell1,
286 Int_t iRow2, AliHLTTPCCACell &cell2, Int_t color )
288 // connect two cells on display, kind of row is drawing
289 AliHLTTPCCARow &row1 = fSector->Rows()[iRow1];
290 AliHLTTPCCARow &row2 = fSector->Rows()[iRow2];
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);
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();
310 Double_t vx11, vx12, vy11, vy12, vx21, vx22, vy21, vy22;
312 Sec2View(x11,y11, &vx11, &vy11 );
313 Sec2View(x12,y12, &vx12, &vy12 );
314 Sec2View(x21,y21, &vx21, &vy21 );
315 Sec2View(x22,y22, &vx22, &vy22 );
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 };
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);
328 fPLine.DrawPolyLine(5, lx, ly );
330 fPLine.DrawPolyLine(5, lz, ly );
331 DrawCell( iRow1, cell1, 1, color );
332 DrawCell( iRow2, cell2, 1, color );
336 void AliHLTTPCCADisplay::DrawTrack( AliHLTTPCCATrack &track, Int_t color )
340 if( track.NCells()<2 ) return;
344 AliHLTTPCCADisplayTmpCell *vCells = new AliHLTTPCCADisplayTmpCell[track.NCells()];
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);
355 sort(vCells, vCells + track.NCells(), AliHLTTPCCADisplayTmpCell::CompareCellDS );
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];
363 //for( Int_t iCell=0; iCell<track.fNCells-1; iCell++ )
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;
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];
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];
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 );
386 fLine.SetLineColor( color );
387 fLine.SetLineWidth( width );
389 if( TMath::Abs(q)>.1 ){
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);
397 Sec2View( xc, yc, &vx, &vy );
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.;
402 if( da>=180 ) da=360-da;
403 if( da<=-180 ) da=360-da;
405 fArc.SetFillStyle(0);
406 fArc.SetLineColor(color);
407 fArc.SetLineWidth(width);
411 fArc.DrawArc(vx,vy,r, a1,a2,"only");
414 fLine.DrawLine(vx1,vy1, vx2, vy2 );
419 for( Int_t iCell=0; iCell<track.NCells()-1; iCell++ ){
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;
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];
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];
439 Double_t vx1, vy1, vx2, vy2;
440 Sec2View(x1, y1, &vx1, &vy1 );
441 Sec2View(x2, y2, &vx2, &vy2 );
443 fLine.SetLineColor(color);
444 fLine.SetLineWidth(width);
447 fLine.DrawLine(z1,vy1, z2, vy2 );
449 fLine.SetLineWidth(1);