]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ALIFAST/AliFDisplay.cxx
User stepping methods added (E. Futo)
[u/mrichter/AliRoot.git] / ALIFAST / AliFDisplay.cxx
1
2 //////////////////////////////////////////////////////////////////////////
3 //                                                                      //
4 // AliFDisplay                                                          //
5 //                                                                      //
6 // Utility class to display ALICE outline, tracks, clusters, jets,..    //
7 //                                                                      //
8 //////////////////////////////////////////////////////////////////////////
9
10 #include <TROOT.h>
11 #include <TButton.h>
12 #include <TCanvas.h>
13 #include <TView.h>
14 #include <TArc.h>
15 #include <TText.h>
16 #include <TPaveLabel.h>
17 #include <TPaveText.h>
18 #include <TList.h>
19 #include <TDiamond.h>
20 #include <TNode.h>
21 #include <TTUBE.h>
22 #include <TMath.h>
23 #include <X3DBuffer.h>
24
25 #include "AliFDisplay.h"
26 #include "AliFFruit.h"
27 #include "AliFParticle.h"
28 #include "AliFast.h"
29 #include "AliFMCMaker.h"
30
31
32 ClassImp(AliFDisplay)
33
34
35 //_____________________________________________________________________________
36 AliFDisplay::AliFDisplay() : AliFVirtualDisplay()
37 {
38    fCanvas    = 0;
39    fTrigPad   = 0;
40    fButtons   = 0;
41    fPad       = 0;
42    fTubin     = 0;
43    fTubout    = 0;
44    fNodin     = 0;
45    fFruits    = 0;
46    fParticle  = 0;   
47 }
48
49 //_____________________________________________________________________________
50 AliFDisplay::AliFDisplay(const char *title) : AliFVirtualDisplay()
51 {
52
53    gAliFast->SetDisplay(this);
54
55    // Initialize display default parameters
56    SetPTcut();
57    SetPTcutEGMUNU();
58    SetGeometry();
59
60    // Set front view by default
61    fTheta = 0;
62    fPhi   = -90;
63    fDrawAllViews  = kFALSE;
64    fDrawParticles = kTRUE;
65
66    // Create display canvas
67    fCanvas = new TCanvas("Canvas", (char*)title,14,47,740,650);
68    fCanvas->SetEditable(kIsNotEditable);
69
70    // Create main display pad
71    fPad = new TPad("viewpad", "AliFast display",0.15,0,1,1);
72    fPad->Draw();
73    fPad->Modified();
74    fPad->SetFillColor(1);
75    fPad->SetBorderSize(2);
76
77    // Create user interface control pad
78    DisplayButtons();
79    fCanvas->cd();
80
81    // Create trigger view pad
82    Float_t dxtr = 0.15;
83    Float_t dytr = 0.45;
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);
91    fTrigPad->Draw();
92    fTrigPad->cd();
93    fTrigPad->SetFillColor(22);
94    fTrigPad->SetBorderSize(2);
95
96    TText *t = new TText();
97    t->SetTextFont(61);
98    t->SetTextSize(0.2);
99    t->SetTextAlign(22);
100    t->DrawText(0.5*dxtr, 0.93*dytr,"Trigger");
101    t->SetTextSize(0.14);
102    t->SetTextAlign(22);
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
114
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);
118          
119
120    // Create list to support list of fruits
121    fFruits = new TList();
122
123    // Create particle manager
124    fParticle = new AliFParticle("particle_manager");
125
126    fCanvas->cd();
127    fCanvas->Update();
128
129 }
130
131
132 //_____________________________________________________________________________
133 AliFDisplay::~AliFDisplay()
134 {
135    delete fParticle;
136    if (fFruits) fFruits->Delete();
137    delete fFruits;
138 }
139
140 //_____________________________________________________________________________
141 void AliFDisplay::Clear(Option_t *)
142 {
143 //    Delete graphics temporary objects
144
145    fFruits->Delete();
146
147 }
148
149 //_____________________________________________________________________________
150 void AliFDisplay::DisplayButtons()
151 {
152 //    Create the user interface buttons
153
154    fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
155    fButtons->Draw();
156    fButtons->SetFillColor(38);
157    fButtons->SetBorderSize(2);
158    fButtons->cd();
159
160    Int_t butcolor = 33;
161    Float_t dbutton = 0.08;
162    Float_t y  = 0.96;
163    Float_t dy = 0.014;
164    Float_t x0 = 0.05;
165    Float_t x1 = 0.95;
166
167    TButton *button;
168    char *but1 = "gAliFast->Display()->ShowNextEvent(1)";
169    button = new TButton("Next",but1,x0,y-dbutton,x1,y);
170    button->SetFillColor(38);
171    button->Draw();
172
173    y -= dbutton +dy;
174    char *but2 = "gAliFast->Display()->ShowNextEvent(-1)";
175    button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
176    button->SetFillColor(38);
177    button->Draw();
178
179    y -= dbutton +dy;
180    char *but3 = "gAliFast->Display()->SetView(90,-90)";
181    button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
182    button->SetFillColor(butcolor);
183    button->Draw();
184
185    y -= dbutton +dy;
186    char *but4 = "gAliFast->Display()->SetView(90,0)";
187    button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
188    button->SetFillColor(butcolor);
189    button->Draw();
190
191    y -= dbutton +dy;
192    char *but5 = "gAliFast->Display()->SetView(0,-90)";
193    button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
194    button->SetFillColor(butcolor);
195    button->Draw();
196
197    y -= dbutton +dy;
198    char *but6 = "gAliFast->Display()->DrawAllViews()";
199    button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
200    button->SetFillColor(butcolor);
201    button->Draw();
202
203    y -= dbutton +dy;
204    char *but7 = "gAliFast->Display()->DrawViewGL()";
205    button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
206    button->SetFillColor(38);
207    button->Draw();
208
209    y -= dbutton +dy;
210    char *but8 = "gAliFast->Display()->DrawViewX3D()";
211    button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
212    button->SetFillColor(38);
213    button->Draw();
214
215    // display logo
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);
221    diamond->Draw();
222    diamond->AddText(".. ");
223    diamond->AddText("ROOT");
224    diamond->AddText("AliFAST");
225    diamond->AddText("... ");
226    diamond->AddText(" ");
227 }
228
229 //_____________________________________________________________________________
230
231 Int_t AliFDisplay::DistancetoPrimitive(Int_t px, Int_t py)
232 {
233 // Compute distance from point px,py to objects in event
234
235    if (gPad == fTrigPad) {gPad->SetCursor(kCross); return 0;}
236
237    const Int_t big = 9999;
238    Int_t dist = big;
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;
244
245     // scan list of particles
246    dist = fParticle->DistancetoPrimitive(px, py);
247    if (dist <= 0) return 0;
248
249     // scan list of fruits
250    TIter nextf(fFruits);
251    AliFFruit *fruit;
252    while((fruit=(AliFFruit*)nextf())) {
253       dist = fruit->DistancetoPrimitive(px, py);
254       if (dist < 5) {
255          gPad->SetSelected(fruit->Fruit());
256          gPad->SetCursor(kCross);
257          return 0;
258       }
259    }
260
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);
265    }
266    return 0;
267 }
268
269 //_____________________________________________________________________________
270 void AliFDisplay::Draw(Option_t *)
271 {
272 //    Insert current event in graphics pad list
273
274    if (fDrawAllViews) {
275       DrawAllViews();
276       return;
277    }
278
279    fPad->cd();
280
281    DrawView(fTheta, fPhi);
282
283    // Display the event number and title
284    fPad->cd();
285    DrawTitle();
286 }
287
288 //_____________________________________________________________________________
289 void AliFDisplay::DrawAllViews()
290 {
291 //    Draw front,top,side and 30 deg views
292
293    fDrawAllViews = kTRUE;
294    fPad->cd();
295    fPad->SetFillColor(15);
296    fPad->Clear();
297    fPad->Divide(2,2);
298
299    // draw 30 deg view
300    fPad->cd(1);
301    DrawView(30, 30);
302    DrawTitle();
303
304    // draw front view
305    fPad->cd(2);
306    DrawView(0, -90);
307    DrawTitle("Front");
308
309    // draw top view
310    fPad->cd(3);
311    DrawView(90, -90);
312    DrawTitle("Top");
313
314    // draw side view
315    fPad->cd(4);
316    DrawView(90, 0);
317    DrawTitle("Side");
318
319    fPad->cd(2);
320 }
321
322 //_____________________________________________________________________________
323 void AliFDisplay::DrawTitle(Option_t *option)
324 {
325 //    Draw the event title
326
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);
337       title->Draw();
338       char ptitle[100];
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);
343    } else {
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);
347       label->Draw();
348    }
349 }
350
351 //_____________________________________________________________________________
352 void AliFDisplay::DrawView(Float_t theta, Float_t phi)
353 {
354 //    Draw a view of ALIAS
355
356    gPad->SetFillColor(1);
357    // Display ALIAS outline
358    gPad->Clear();
359
360    Int_t iret;
361    TView *view = new TView(1);
362    view->SetRange(-fRin, -fRin, -fZin, fRin, fRin, fZin);
363
364    fNodin->Draw("same");
365
366     // add itself to the list
367    AppendPad();
368    
369    //Loop on all makers to add their products to the pad
370    TIter next(gAliFast->Makers());
371    AliFMaker *maker;
372    while ((maker = (AliFMaker*)next())) {
373       maker->Draw();
374    }
375    view->SetView(phi, theta, 0, iret);
376 }
377
378 //_____________________________________________________________________________
379 void AliFDisplay::DrawViewGL()
380 {
381 //    Draw current view using OPENGL
382
383    TPad *pad = (TPad*)gPad->GetPadSave();
384    pad->cd();
385    TView *view = pad->GetView();
386    if (!view) return;
387    pad->x3d("OPENGL");
388 }
389
390 //_____________________________________________________________________________
391 void AliFDisplay::DrawViewX3D()
392 {
393 //    Draw current view using X3D
394
395    TPad *pad = (TPad*)gPad->GetPadSave();
396    pad->cd();
397    TView *view = pad->GetView();
398    if (!view) return;
399    pad->x3d();
400 }
401
402 //______________________________________________________________________________
403 void AliFDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
404 {
405 //*-*-*-*-*-*-*-*-*-*-*Execute action corresponding to one event*-*-*-*
406 //*-*                  =========================================
407
408    if (gPad->GetView()) {
409       gPad->GetView()->ExecuteRotateView(event, px, py);
410    }
411 }
412
413 //_____________________________________________________________________________
414 void AliFDisplay::GetEvent(Int_t event)
415 {
416 //    Read event in memory
417
418    gAliFast->GetTreeEvent(event);
419
420    Draw();
421 }
422
423 //_____________________________________________________________________________
424 void AliFDisplay::Paint(Option_t *)
425 {
426 //    Paint miscellaneous items
427
428 }
429
430 //_____________________________________________________________________________
431 void AliFDisplay::PaintFruit(TObject *obj, Float_t eta, Float_t phi, Float_t
432 pt, Int_t type, Option_t *option)
433 {
434 //    Display fruit from obj
435
436    AliFFruit *fruit = new AliFFruit(obj, eta, phi, pt, type);
437    fFruits->Add(fruit);
438    fruit->Paint(option);
439 }
440
441 //_____________________________________________________________________________
442 void AliFDisplay::PaintParticles(Option_t *option)
443 {
444    if (fDrawParticles) fParticle->Paint(option);
445 }
446
447 //_____________________________________________________________________________
448 void AliFDisplay::SetGeometry(Float_t rin)
449 {
450 //  Set ALIAS in/out outline parameters
451
452    fRin  = rin;
453    fRout = 1.2*rin;
454    fZin  = 600;
455    fZout = 680;
456 }
457
458 //_____________________________________________________________________________
459 void AliFDisplay::SetPTcut(Float_t ptcut)
460 {
461    fPTcut = ptcut;
462
463    if (fDrawAllViews) {
464       fPad->cd(1); gPad->Modified();
465       fPad->cd(2); gPad->Modified();
466       fPad->cd(3); gPad->Modified();
467       fPad->cd(4); gPad->Modified();
468       fPad->cd();
469    }
470 }
471
472 //_____________________________________________________________________________
473 void AliFDisplay::SetPTcutEGMUNU(Float_t ptcut)
474 {
475    fPTcutEGMUNU = ptcut;
476
477    if (fDrawAllViews) {
478       fPad->cd(1); gPad->Modified();
479       fPad->cd(2); gPad->Modified();
480       fPad->cd(3); gPad->Modified();
481       fPad->cd(4); gPad->Modified();
482       fPad->cd();
483    }
484 }
485
486 //_____________________________________________________________________________
487 void AliFDisplay::SetView(Float_t theta, Float_t phi)
488 {
489 //  change viewing angles for current event
490
491    fPad->cd();
492    fDrawAllViews = kFALSE;
493    fPhi   = phi;
494    fTheta = theta;
495    Int_t iret;
496
497    TView *view = gPad->GetView();
498    if (view) view->SetView(fPhi, fTheta, 0, iret);
499    else      Draw();
500
501    gPad->Modified();
502 }
503
504 //_____________________________________________________________________________
505 void AliFDisplay::ShowNextEvent(Int_t delta)
506 {
507 //  Display (current event_number+delta)
508 //    delta =  1  shown next event
509 //    delta = -1 show previous event
510
511   if (delta) {
512      gAliFast->Clear();
513      Int_t current_event = gAliFast->Event();
514      Int_t new_event     = current_event + delta;
515      gAliFast->GetTreeEvent(new_event); 
516    }
517   fPad->cd(); 
518   Draw();
519 }
520
521 //______________________________________________________________________________
522 void AliFDisplay::SizeFruit() const
523 {
524    const Int_t npoints = 2;
525    gSize3D.numPoints += npoints;
526    gSize3D.numSegs   += (npoints-1);
527    gSize3D.numPolys  += 0;
528 }
529
530 //______________________________________________________________________________
531 void AliFDisplay::SizeParticles() const
532 {
533    if (fDrawParticles)  fParticle->SizeParticles();
534 }
535
536
537
538
539
540
541
542
543
544