2 //////////////////////////////////////////////////////////////////////////
6 // Utility class to display ALICE outline, tracks, clusters, jets,.. //
8 //////////////////////////////////////////////////////////////////////////
16 #include <TPaveLabel.h>
17 #include <TPaveText.h>
23 #include <X3DBuffer.h>
25 #include "AliFDisplay.h"
26 #include "AliFFruit.h"
27 #include "AliFParticle.h"
29 #include "AliFMCMaker.h"
35 //_____________________________________________________________________________
36 AliFDisplay::AliFDisplay() : AliFVirtualDisplay()
49 //_____________________________________________________________________________
50 AliFDisplay::AliFDisplay(const char *title) : AliFVirtualDisplay()
53 gAliFast->SetDisplay(this);
55 // Initialize display default parameters
60 // Set front view by default
63 fDrawAllViews = kFALSE;
64 fDrawParticles = kTRUE;
66 // Create display canvas
67 fCanvas = new TCanvas("Canvas", (char*)title,14,47,740,650);
68 fCanvas->SetEditable(kIsNotEditable);
70 // Create main display pad
71 fPad = new TPad("viewpad", "AliFast display",0.15,0,1,1);
74 fPad->SetFillColor(1);
75 fPad->SetBorderSize(2);
77 // Create user interface control pad
81 // Create trigger view pad
84 Float_t xt = 0.3*dxtr;
85 Float_t yt = 0.8*dytr;
86 Float_t dyt = 0.07*dytr;
87 Float_t xarc = 0.7*dxtr;
88 Float_t rarc = 0.3*dyt;
89 fTrigPad = new TPad("TrigPad", "trigger pad",0,0,dxtr,dytr);
90 fTrigPad->Range(0,0,dxtr,dytr);
93 fTrigPad->SetFillColor(22);
94 fTrigPad->SetBorderSize(2);
96 TText *t = new TText();
100 t->DrawText(0.5*dxtr, 0.93*dytr,"Trigger");
101 t->SetTextSize(0.14);
103 t->DrawText(xt,yt, "EM1");
104 t->DrawText(xt,yt-dyt, "PH1");
105 t->DrawText(xt,yt-2*dyt,"EM2");
106 t->DrawText(xt,yt-3*dyt,"MU1");
107 t->DrawText(xt,yt-4*dyt,"MU2");
108 t->DrawText(xt,yt-5*dyt,"EMU");
109 t->DrawText(xt,yt-6*dyt,"JT1");
110 t->DrawText(xt,yt-7*dyt,"JT2");
111 t->DrawText(xt,yt-8*dyt,"JT3");
112 t->DrawText(xt,yt-9*dyt,"ALL");
113 AppendPad(); // append display object as last object to force selection
115 fTubin = new TTUBE("tubin","inner tube"," ", fRin, fRin+5, fZin);
116 fNodin = new TNode("nodin","ALIAS outline","tubin",0,0,0," ");
117 fNodin->SetLineColor(7);
120 // Create list to support list of fruits
121 fFruits = new TList();
123 // Create particle manager
124 fParticle = new AliFParticle("particle_manager");
132 //_____________________________________________________________________________
133 AliFDisplay::~AliFDisplay()
136 if (fFruits) fFruits->Delete();
140 //_____________________________________________________________________________
141 void AliFDisplay::Clear(Option_t *)
143 // Delete graphics temporary objects
149 //_____________________________________________________________________________
150 void AliFDisplay::DisplayButtons()
152 // Create the user interface buttons
154 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
156 fButtons->SetFillColor(38);
157 fButtons->SetBorderSize(2);
161 Float_t dbutton = 0.08;
168 char *but1 = "gAliFast->Display()->ShowNextEvent(1)";
169 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
170 button->SetFillColor(38);
174 char *but2 = "gAliFast->Display()->ShowNextEvent(-1)";
175 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
176 button->SetFillColor(38);
180 char *but3 = "gAliFast->Display()->SetView(90,-90)";
181 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
182 button->SetFillColor(butcolor);
186 char *but4 = "gAliFast->Display()->SetView(90,0)";
187 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
188 button->SetFillColor(butcolor);
192 char *but5 = "gAliFast->Display()->SetView(0,-90)";
193 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
194 button->SetFillColor(butcolor);
198 char *but6 = "gAliFast->Display()->DrawAllViews()";
199 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
200 button->SetFillColor(butcolor);
204 char *but7 = "gAliFast->Display()->DrawViewGL()";
205 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
206 button->SetFillColor(38);
210 char *but8 = "gAliFast->Display()->DrawViewX3D()";
211 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
212 button->SetFillColor(38);
216 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
217 diamond->SetFillColor(50);
218 diamond->SetTextAlign(22);
219 diamond->SetTextColor(5);
220 diamond->SetTextSize(0.11);
222 diamond->AddText(".. ");
223 diamond->AddText("ROOT");
224 diamond->AddText("AliFAST");
225 diamond->AddText("... ");
226 diamond->AddText(" ");
229 //_____________________________________________________________________________
231 Int_t AliFDisplay::DistancetoPrimitive(Int_t px, Int_t py)
233 // Compute distance from point px,py to objects in event
235 if (gPad == fTrigPad) {gPad->SetCursor(kCross); return 0;}
237 const Int_t big = 9999;
239 Float_t xmin = gPad->GetX1();
240 Float_t xmax = gPad->GetX2();
241 Float_t dx = 0.05*(xmax - xmin);
242 Float_t x = gPad->AbsPixeltoX(px);
243 if (x < xmin+dx || x > xmax-dx) return dist;
245 // scan list of particles
246 dist = fParticle->DistancetoPrimitive(px, py);
247 if (dist <= 0) return 0;
249 // scan list of fruits
250 TIter nextf(fFruits);
252 while((fruit=(AliFFruit*)nextf())) {
253 dist = fruit->DistancetoPrimitive(px, py);
255 gPad->SetSelected(fruit->Fruit());
256 gPad->SetCursor(kCross);
261 // scan list of detectors (currently only one tube)
262 dist = fNodin->DistancetoPrimitive(px, py);
263 if (gPad->GetCanvas()->GetSelected() == gPad->GetView()) {
264 gPad->SetSelected(this);
269 //_____________________________________________________________________________
270 void AliFDisplay::Draw(Option_t *)
272 // Insert current event in graphics pad list
281 DrawView(fTheta, fPhi);
283 // Display the event number and title
288 //_____________________________________________________________________________
289 void AliFDisplay::DrawAllViews()
291 // Draw front,top,side and 30 deg views
293 fDrawAllViews = kTRUE;
295 fPad->SetFillColor(15);
322 //_____________________________________________________________________________
323 void AliFDisplay::DrawTitle(Option_t *option)
325 // Draw the event title
327 Float_t xmin = gPad->GetX1();
328 Float_t xmax = gPad->GetX2();
329 Float_t ymin = gPad->GetY1();
330 Float_t ymax = gPad->GetY2();
331 Float_t dx = xmax-xmin;
332 Float_t dy = ymax-ymin;
333 if (strlen(option) == 0) {
334 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
335 title->SetBit(kCanDelete);
336 title->SetFillColor(42);
339 sprintf(ptitle,"Pythia event: %d, Run:%d",gAliFast->Event(), gAliFast->Run());
340 title->AddText(ptitle);
341 sprintf(ptitle,"Pythia Mode: %s",gAliFast->MCMaker()->GetTitle());
342 title->AddText(ptitle);
344 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
345 label->SetBit(kCanDelete);
346 label->SetFillColor(42);
351 //_____________________________________________________________________________
352 void AliFDisplay::DrawView(Float_t theta, Float_t phi)
354 // Draw a view of ALIAS
356 gPad->SetFillColor(1);
357 // Display ALIAS outline
361 TView *view = new TView(1);
362 view->SetRange(-fRin, -fRin, -fZin, fRin, fRin, fZin);
364 fNodin->Draw("same");
366 // add itself to the list
369 //Loop on all makers to add their products to the pad
370 TIter next(gAliFast->Makers());
372 while ((maker = (AliFMaker*)next())) {
375 view->SetView(phi, theta, 0, iret);
378 //_____________________________________________________________________________
379 void AliFDisplay::DrawViewGL()
381 // Draw current view using OPENGL
383 TPad *pad = (TPad*)gPad->GetPadSave();
385 TView *view = pad->GetView();
390 //_____________________________________________________________________________
391 void AliFDisplay::DrawViewX3D()
393 // Draw current view using X3D
395 TPad *pad = (TPad*)gPad->GetPadSave();
397 TView *view = pad->GetView();
402 //______________________________________________________________________________
403 void AliFDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
405 //*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
406 //*-* =========================================
408 if (gPad->GetView()) {
409 gPad->GetView()->ExecuteRotateView(event, px, py);
413 //_____________________________________________________________________________
414 void AliFDisplay::GetEvent(Int_t event)
416 // Read event in memory
418 gAliFast->GetTreeEvent(event);
423 //_____________________________________________________________________________
424 void AliFDisplay::Paint(Option_t *)
426 // Paint miscellaneous items
430 //_____________________________________________________________________________
431 void AliFDisplay::PaintFruit(TObject *obj, Float_t eta, Float_t phi, Float_t
432 pt, Int_t type, Option_t *option)
434 // Display fruit from obj
436 AliFFruit *fruit = new AliFFruit(obj, eta, phi, pt, type);
438 fruit->Paint(option);
441 //_____________________________________________________________________________
442 void AliFDisplay::PaintParticles(Option_t *option)
444 if (fDrawParticles) fParticle->Paint(option);
447 //_____________________________________________________________________________
448 void AliFDisplay::SetGeometry(Float_t rin)
450 // Set ALIAS in/out outline parameters
458 //_____________________________________________________________________________
459 void AliFDisplay::SetPTcut(Float_t ptcut)
464 fPad->cd(1); gPad->Modified();
465 fPad->cd(2); gPad->Modified();
466 fPad->cd(3); gPad->Modified();
467 fPad->cd(4); gPad->Modified();
472 //_____________________________________________________________________________
473 void AliFDisplay::SetPTcutEGMUNU(Float_t ptcut)
475 fPTcutEGMUNU = ptcut;
478 fPad->cd(1); gPad->Modified();
479 fPad->cd(2); gPad->Modified();
480 fPad->cd(3); gPad->Modified();
481 fPad->cd(4); gPad->Modified();
486 //_____________________________________________________________________________
487 void AliFDisplay::SetView(Float_t theta, Float_t phi)
489 // change viewing angles for current event
492 fDrawAllViews = kFALSE;
497 TView *view = gPad->GetView();
498 if (view) view->SetView(fPhi, fTheta, 0, iret);
504 //_____________________________________________________________________________
505 void AliFDisplay::ShowNextEvent(Int_t delta)
507 // Display (current event_number+delta)
508 // delta = 1 shown next event
509 // delta = -1 show previous event
513 Int_t current_event = gAliFast->Event();
514 Int_t new_event = current_event + delta;
515 gAliFast->GetTreeEvent(new_event);
521 //______________________________________________________________________________
522 void AliFDisplay::SizeFruit() const
524 const Int_t npoints = 2;
525 gSize3D.numPoints += npoints;
526 gSize3D.numSegs += (npoints-1);
527 gSize3D.numPolys += 0;
530 //______________________________________________________________________________
531 void AliFDisplay::SizeParticles() const
533 if (fDrawParticles) fParticle->SizeParticles();