]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDisplay.cxx
- Adapted comments for Doxygen
[u/mrichter/AliRoot.git] / MUON / AliMUONDisplay.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /// \class AliMUONDisplay
19 /// Create an event display object.
20 /// A canvas named "edisplay" is created with a vertical size in pixels  \n
21 ///
22 ///    A QUICK Overview of the Event Display functions                   \n
23 ///    ===============================================                   \n
24 ///
25 /// The event display can ve invoked by executing the macro "display.C"  \n
26 /// A canvas like in the picture below will appear.
27 ///
28 ///  On the left side of the canvas, the following buttons appear:
29 ///  - *Next*       to move to the next event
30 ///  - *Previous*   to move to the previous event
31 ///  - *Pick*       Select this option to be able to point on a track with the
32 ///                 mouse. Once on the track, use the right button to select
33 ///                 an action. For example, select SetMarkerAttributes to
34 ///                 change the marker type/color/size for the track.
35 ///  - *Zoom*       Select this option (default) if you want to zoom.
36 ///                 To zoom, simply select the selected area with the left button.
37 ///  - *UnZoom*     To revert to the previous picture size.
38 ///
39 ///  - slider R     On the left side, the vertical slider can be used to
40 ///                 set the default picture size.
41 ///
42 ///  When you are in Zoom mode, you can click on the black part of the canvas
43 ///  to select special options with the right mouse button.
44 ///
45 /// When you are in pick mode, you can "Inspect" the object pointed by the mouse.
46 /// When you are on a track, select the menu item "InspectParticle"
47 /// to display the current particle attributes.
48 ///
49 /// You can activate the Root browser by selecting the Inspect menu
50 /// in the canvas tool bar menu. Then select "Start Browser"
51 /// This will open a new canvas with the browser. At this point, you may want
52 /// to display some histograms (from the Trees). Go to the "File" menu
53 /// of the browser and click on "New canvas".
54 /// In the browser, click on item "ROOT files" in the left pane.
55 /// Click on galice.root.
56 /// Click on TH
57 /// Click on TPC for example
58 /// Click on any variable (eg TPC.fX) to histogram the variable.
59 ///
60 /// If you are lost, you can click on HELP in any Root canvas or browser.
61
62 //Begin_Html
63 /*
64 <img src="gif/AliMUONDisplay.gif">
65 */
66 //End_Html
67
68 #include "AliMUONDisplay.h"
69 #include "AliMUON.h"
70 #include "AliMUONPoints.h"
71 #include "AliMUONGlobalTrigger.h"
72 #include "AliMUONHit.h"
73 #include "AliMUONDigit.h"
74 #include "AliMUONRawCluster.h"
75 #include "AliMUONTrack.h"
76 #include "AliMUONTrackParam.h"
77 #include "AliMUONGeometryTransformer.h"
78 #include "AliMUONSegmentation.h"
79 #include "AliMUONGeometrySegmentation.h"
80 #include "AliMUONConstants.h"
81 #include "AliMUONTriggerSegmentationV2.h"
82
83 #include "AliMpDEIterator.h"
84 #include "AliMpSegFactory.h"
85 #include "AliMpSlatSegmentation.h"
86 #include "AliMpSlat.h"
87 #include "AliMpSectorSegmentation.h"
88 #include "AliMpSector.h"
89 #include "AliMpTriggerSegmentation.h"
90 #include "AliMpTrigger.h"
91 #include "AliMpStationType.h"
92 #include "AliMpDEManager.h"
93
94 #include "AliMC.h"
95 #include "AliLog.h"
96 #include "AliRun.h"
97 #include "AliHeader.h"
98
99 #include <TButton.h>
100 #include <TColor.h>
101 #include <TCanvas.h>
102 #include <TView.h>
103 #include <TText.h>
104 #include <TPaveLabel.h>
105 #include <TPaveText.h>
106 #include <TDiamond.h>
107 #include <TNode.h>
108 #include <TArc.h>
109 #include <TSlider.h>
110 #include <TVirtualX.h>
111 #include <TMath.h>
112 #include <TGeometry.h>
113 #include <TMarker3DBox.h>
114 #include <TParticle.h>
115 #include <TPolyLine3D.h>
116 #include <TBox.h>
117
118 /// \cond CLASSIMP
119 ClassImp(AliMUONDisplay)
120 /// \endcond
121
122 //_____________________________________________________________________________
123 AliMUONDisplay::AliMUONDisplay()
124   : AliDisplay(),
125     fEvent(0),
126     fChamber(0),
127     fCathode(0),
128     fDrawClusters(kTRUE),
129     fDrawCoG(kTRUE),
130     fDrawTracks(kFALSE),
131     fClustersCuts(0),
132     fColPad(0),
133     fPoints(0),
134     fPhits(0),
135     fRpoints(0),
136     fNextCathode(0),
137     fLoader(0), 
138     fMUONData(0)
139 {
140 /// Default constructor
141 }
142
143 //_____________________________________________________________________________
144 AliMUONDisplay::AliMUONDisplay(Int_t size, AliLoader * loader)
145   : AliDisplay(),
146     fEvent(0),
147     fChamber(1),
148     fCathode(1),
149     fDrawClusters(kTRUE),
150     fDrawCoG(kTRUE),
151     fDrawTracks(kFALSE),
152     fClustersCuts(0),
153     fColPad(0),
154     fPoints(0),
155     fPhits(0),
156     fRpoints(0),
157     fNextCathode(kFALSE),
158     fLoader(loader), 
159     fMUONData(0)
160   
161 {
162 /// Standard constructor to create an event display object.
163
164     fPad = 0;
165     
166     gAlice->SetDisplay(this);
167    
168    // Initialize display default parameters
169     SetRange(200,2000);
170
171    // Set front view by default
172     fTheta =   0;
173     fPhi   = -90;
174     fPsi   =   0;
175     fZoomMode      = 1;
176     fZooms         = 0;
177
178     // Create colors
179     CreateColors();
180     // Create display canvas
181     Int_t ysize = size;
182     if (ysize < 100) ysize = 750;
183     Int_t xsize = Int_t(size*830./ysize);
184     fCanvas = new TCanvas("Canvas", "MUON Display",14,47,xsize,ysize);
185     fCanvas->ToggleEventStatus();
186     
187    // Create main display pad
188     fPad = new TPad("viewpad", "MUON display",0.15,0,0.9,1);
189     fPad->Draw();
190     fPad->Modified();
191     fPad->SetFillColor(30);
192     fPad->SetBorderSize(2);
193
194     fCanvas->cd();
195
196    // Create colors pad
197     fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1);
198     fColPad->Draw();
199     fColPad->SetFillColor(17);
200     fColPad->SetBorderSize(2);
201     fColPad->cd();
202     DisplayColorScale();
203
204     fCanvas->cd();
205    // Create user interface control pad
206     DisplayButtons();
207     fCanvas->cd();
208
209    // Create Range and mode pad
210     Float_t dxtr     = 0.15;
211     Float_t dytr     = 0.45;
212     fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
213     fTrigPad->Draw();
214     fTrigPad->cd();
215     fTrigPad->SetFillColor(22);
216     fTrigPad->SetBorderSize(2);
217     fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
218     fRangeSlider->SetObject(this);
219     char pickmode[] = "gAlice->Display()->SetPickMode()";
220     Float_t db = 0.09;
221     fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
222     fPickButton->SetFillColor(38);
223     fPickButton->Draw();
224     char zoommode[] = "gAlice->Display()->SetZoomMode()";
225     fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
226     fZoomButton->SetFillColor(38);
227     fZoomButton->Draw();
228     fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
229     fArcButton->SetFillColor(kGreen);
230     fArcButton->Draw();
231     char butUnzoom[] = "gAlice->Display()->UnZoom()";
232     TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
233     button->SetFillColor(38);
234     button->Draw();
235     AppendPad(); // append display object as last object to force selection
236     
237     fCanvas->cd();
238     fTrigPad->SetEditable(kFALSE);
239     fButtons->SetEditable(kFALSE);
240     fCanvas->Update();
241  
242     // initialize container
243     if(fLoader) 
244       fMUONData = new AliMUONData(fLoader,"MUON","MUON");
245     else
246       fMUONData =0x0;
247 }
248
249 //_____________________________________________________________________________
250 AliMUONDisplay::~AliMUONDisplay()
251 {
252 /// Destructor
253
254   // Delete space point structure
255     if (fPoints) fPoints->Delete();
256     delete fPoints;
257     fPoints     = 0;
258     //
259     if (fPhits) fPhits->Delete();
260     delete fPhits;
261     fPhits     = 0;
262     //
263     if (fRpoints) fRpoints->Delete();
264     delete fRpoints;
265     fRpoints     = 0;
266 }
267
268 //_____________________________________________________________________________
269 void AliMUONDisplay::Clear(Option_t *)
270 {
271 /// Delete graphics temporary objects
272 }
273
274 //_____________________________________________________________________________
275 void AliMUONDisplay::DisplayButtons()
276 {
277 /// Create the user interface buttons
278
279
280     fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
281     fButtons->Draw();
282     fButtons->SetFillColor(38);
283     fButtons->SetBorderSize(2);
284     fButtons->cd();
285     
286 //   Int_t butcolor = 33;
287     Float_t dbutton = 0.08;
288     Float_t y  = 0.96;
289     Float_t dy = 0.014;
290     Float_t x0 = 0.05;
291     Float_t x1 = 0.95;
292     
293     TButton *button;
294     char but1[] = "gAlice->Display()->ShowNextEvent(1)";
295     button = new TButton("Event +", but1, x0, y - dbutton, x1, y);
296     button->SetFillColor(38);
297     button->Draw();
298     
299     y -= dbutton + dy;
300     char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
301     button = new TButton("Event -", but2, x0, y - dbutton, x1, y);
302     button->SetFillColor(38);
303     button->Draw();
304    
305     y -= dbutton + dy;
306     char but3[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(1)";
307     button = new TButton("Chamber +", but3, x0, y - dbutton, x1, y);
308     button->SetFillColor(38);
309     button->Draw();
310     
311     y -= dbutton + dy;
312     char but4[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(-1)";
313     button = new TButton("Chamber -", but4, x0, y - dbutton, x1, y);
314     button->SetFillColor(38);
315     button->Draw();
316     
317     y -= dbutton + dy;
318     char but5[] = "((AliMUONDisplay*)(gAlice->Display()))->SetChamberAndCathode(1,1)";
319     button = new TButton("Chamber 1", but5, x0, y - dbutton, x1, y);
320     button->SetFillColor(38);
321     button->Draw();
322    
323     y -= dbutton + dy;
324     char but6[] = "((AliMUONDisplay*)(gAlice->Display()))->NextCathode()";
325     button = new TButton("Cathode <>", but6, x0, y - dbutton, x1, y);
326     button->SetFillColor(38);
327     button->Draw();
328
329     y -= dbutton + dy;
330     char but7[] = "((AliMUONDisplay*)(gAlice->Display()))->Trigger()";
331     button = new TButton("Trigger", but7, x0, y - dbutton, x1, y);
332     button->SetFillColor(38);
333     button->Draw();
334     
335     y -= dbutton + dy;
336     char but8[] = "((AliMUONDisplay*)(gAlice->Display()))->DrawReco()";
337     button = new TButton("Tracking", but8, x0, y - dbutton, x1, y);
338     button->SetFillColor(38);
339     button->Draw();
340
341    // display logo
342     TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
343     diamond->SetFillColor(50);
344     diamond->SetTextAlign(22);
345     diamond->SetTextColor(5);
346     diamond->SetTextSize(0.11);
347     diamond->Draw();
348     diamond->AddText(".. ");
349     diamond->AddText("ROOT");
350     diamond->AddText("MUON");
351     diamond->AddText("... ");
352     diamond->AddText(" ");
353 }
354
355 //_____________________________________________________________________________
356 void AliMUONDisplay::CreateColors() const
357 {
358 /// Create the colors palette used to display clusters
359
360     Int_t k,i;
361     Int_t color;
362     Float_t r,g,b;
363     
364     for (k=1;k<=5;k++) {
365         switch(k) {
366         case 1:
367             for (i=1;i<=5;i++) {
368                 r=1.;
369                 g=i*0.2;  
370                 b=0.;
371                 color=i;
372                 color=260+23-color;
373                 new TColor(color,r,g,b);
374             } 
375             break;
376         case 2:
377             for (i=1;i<=4;i++) {
378                 r=1.1-i*0.2;
379                 g=1.;  
380                 b=0.;
381                 color=i+5;
382                 color=260+23-color;
383                 new TColor(color,r,g,b);
384             } 
385             break;
386         case 3:
387             for (i=1;i<=4;i++) {
388                 r=0.;
389                 g=1.;  
390                 b=i*0.2+0.2;
391                 color=i+9;
392                 color=260+23-color;
393                 new TColor(color,r,g,b);
394             } 
395             break;
396         case 4:
397             for (i=1;i<=4;i++) {
398                 r=0.;
399                 g=1.1-i*0.2;  
400                 b=1.;
401                 color=i+13;
402                 color=260+23-color;
403                 new TColor(color,r,g,b);
404             } 
405             break;
406         case 5:
407             for (i=1;i<=5;i++) {
408                 r=i*0.2;
409                 g=0.;  
410                 b=1.;
411                 color=i+17;
412                 color=260+23-color;
413                 new TColor(color,r,g,b);
414             } 
415             break;
416         }
417     }
418 }
419
420 //_____________________________________________________________________________
421 void AliMUONDisplay::DisplayColorScale()
422 {
423 /// Display pulse height color scale
424
425     Int_t i;
426     Int_t color;
427     Float_t xlow, ylow, xup, yup, hs;
428     Float_t x1, y1, x2, y2;
429     x1 = y1 = 0;
430     x2 = y2 = 1.0;
431     
432     TText *text = new TText(0,0,"");
433     text->SetTextFont(61);
434     text->SetTextSize(0.2);
435     text->SetTextAlign(22);
436     
437
438     Int_t adcmax=4096; // default 12 bits ADC
439
440     
441
442     TBox *box;
443     char label[8];
444 //*-* draw colortable boxes
445     hs = (y2-y1)/Float_t(22);
446     xlow=x1+.05;
447     xup=x2-0.5;
448     for (i=0;i<22;i++) {
449         ylow = y1 + hs*(Float_t(i));
450         yup  = y1 + hs*(Float_t(i+1));
451         color = 261+i;
452         Double_t logscale=Double_t(i+1)*(TMath::Log(adcmax)/22);
453         Int_t scale=(Int_t)TMath::Exp(logscale);
454         sprintf(label,"%d",scale);
455         box = new TBox(xlow, ylow, xup, yup);
456         box->Draw();
457         box->SetFillColor(color);
458         text->DrawText(xlow+0.7, 0.5*(ylow+yup),label);
459     }
460 }
461
462 //______________________________________________________________________________
463 Int_t AliMUONDisplay::DistancetoPrimitive(Int_t px, Int_t)
464 {
465 /// Compute distance from point px,py to objects in event
466
467     gPad->SetCursor(kCross);
468     
469     if (gPad == fTrigPad) return 9999;
470     
471     const Int_t kBig = 9999;
472     Int_t dist   = kBig;
473     Float_t xmin = gPad->GetX1();
474     Float_t xmax = gPad->GetX2();
475     Float_t dx   = 0.02*(xmax - xmin);
476     Float_t x    = gPad->AbsPixeltoX(px);
477     if (x < xmin+dx || x > xmax-dx) return dist;
478     
479     if (fZoomMode) return 0;
480     else           return 7;
481 }
482
483 //_____________________________________________________________________________
484 void AliMUONDisplay::Draw(Option_t *)
485 {
486 /// Display current event
487
488     if (!fDrawTracks) 
489       DrawChamber();   
490     else 
491       DrawReco();
492     
493 }
494 //_____________________________________________________________________________
495 void AliMUONDisplay::DrawChamber()
496 {
497 /// Display current event
498
499   fDrawTracks = kFALSE;
500   fPad->cd();
501   DrawView(fTheta, fPhi, fPsi);   
502   // Display the event number and title
503   fPad->cd();
504   DrawTitle();
505  
506 }
507 //_____________________________________________________________________________
508 void AliMUONDisplay::DrawReco(Option_t *)
509 {
510 /// Display current event
511
512   fDrawTracks = kTRUE;
513   // print kinematics of generated particles
514     PrintKinematics();
515     // Draw global view of muon system
516     fPad->cd();
517     DrawGlobalView(135, -50, -140); 
518   
519     // Display the event number and title
520     fPad->cd();
521     DrawTitle();
522 }
523
524 //_____________________________________________________________________________
525 void AliMUONDisplay::PrintKinematics()
526 {
527 /// Print kinematic tree
528
529   AliRunLoader * runLoader;
530   TParticle *particle = new TParticle();
531   Int_t nPart;
532   Float_t vertex[3], momentum[3];
533
534   if (fLoader)
535     runLoader = fLoader->GetRunLoader();
536   else
537     runLoader = 0x0;
538   
539   printf("******  Event # %d ******\n",runLoader->GetEventNumber());
540   runLoader->TreeK()->GetBranch("Particles")->SetAddress(&particle);
541   nPart = (Int_t)runLoader->TreeK()->GetEntries();
542   for(Int_t iPart = 0; iPart < nPart; iPart++) {
543     runLoader->TreeK()->GetEvent(iPart);
544     vertex[0] = particle->Vx();
545     vertex[1] = particle->Vy();
546     vertex[2] = particle->Vz();
547     momentum[0] = particle->Px();
548     momentum[1] = particle->Py();
549     momentum[2] = particle->Pz();
550     
551     printf("===================================================\n");
552     printf(" Generated particle # %d \n",iPart);
553     printf(" name: %s \n",particle->GetName());
554     printf(" vertex x,y,z (cm): %f %f %f \n",vertex[0],vertex[1],vertex[2]); 
555     printf(" momentum Px,Py,Pz (GeV/c): %f %f %f \n",momentum[0],momentum[1],momentum[2]);
556   }
557   delete particle;    
558 }
559
560 //_____________________________________________________________________________
561 void AliMUONDisplay::DrawSegmentation()
562 {
563 /// \todo to be re-written for new seg
564 /// Draw graphical representation of segmenatation
565 /// Attention: still experimental code
566 //     Int_t icat=1;
567     
568 //     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
569 //     AliMUONChamber*   iChamber;
570
571 //     AliSegmentation*  seg;
572 //     iChamber = &(pMUON->Chamber(fChamber));
573 //     seg=iChamber->SegmentationModel(icat);
574
575 //     Float_t zpos=iChamber->Z();
576 //     Float_t r=iChamber->ROuter();
577     
578 //     TMarker3DBox *marker;
579 //     if (icat == 1) {
580 //      for (Int_t j=0; j<seg->Npy(); j++) {
581 //          Float_t y0;
582 //          y0=j*seg->Dpy()-seg->Dpy()/2.;
583 //          for (seg->FirstPad(0.,y0,0,300,0.); 
584 //               seg->MorePads();
585 //               seg->NextPad())
586 //          {
587 //              if (seg->ISector()==0) continue;
588 //              Float_t x,y,z;
589 //              seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
590 //              Float_t dpx=seg->Dpx(seg->ISector())/2;
591 //              Float_t dpy=seg->Dpy(seg->ISector())/2;
592 //              marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
593 //              marker->SetLineColor(seg->ISector()+1);
594 //              marker->SetFillStyle(1001);
595 //              marker->SetFillColor(0);
596 //              marker->Draw();
597 //          }
598 //      }
599 //     } else {
600 //      for (Int_t j=0; j<250; j++) {
601 //          Float_t x0=j*seg->Dpx();
602 //          Float_t y0=TMath::Sqrt(r*r-x0*x0);
603             
604 //          for (seg->FirstPad(x0,0,0,0,y0); 
605 //               seg->MorePads();
606 //               seg->NextPad())
607 //          {
608 //              if (seg->ISector()==0) continue;
609                 
610 //              Float_t x,y,z;
611 //              seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
612 //              Float_t dpx=seg->Dpx(seg->ISector())/2;
613 //              Float_t dpy=seg->Dpy(seg->ISector())/2;
614 //              marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
615 //              marker->SetLineColor(seg->ISector()+1);
616 //              marker->SetFillStyle(1001);
617 //              marker->SetFillColor(0);
618 //              marker->Draw();
619 //          }
620 //      }
621 //     }
622  }
623
624 //_____________________________________________________________________________
625 void AliMUONDisplay::DrawClusters()
626 {
627 /// Draw clusters for MUON chambers
628
629     Int_t ndigits, digit;
630     TObjArray *points;
631     AliMUONPoints *pm;
632
633       
634     fClustersCuts = 0;
635     points = Points();
636     if (!points) return;
637     ndigits = points->GetEntriesFast();
638     for (digit=0;digit<ndigits;digit++){
639         pm = (AliMUONPoints*)points->UncheckedAt(digit);
640         if (!pm) continue;
641         Float_t *pxyz;
642         pxyz=pm->GetP();
643         for (Int_t im=0;im<3;im++) {
644             TMarker3DBox *marker=pm->GetMarker(im);
645             if (marker)
646                 marker->Draw();
647         }
648         pm->Draw();
649         fClustersCuts += pm->GetN();
650     }
651 }
652
653 //_____________________________________________________________________________
654 void AliMUONDisplay::DrawHits()
655 {
656 /// Draw hits for MUON chambers
657
658     LoadHits(fChamber);
659
660     Int_t ntracks, track;
661     TObjArray *points;
662     AliMUONPoints *pm;
663     
664     fHitsCuts = 0;
665     points = Phits();
666     if (!points) return;
667     ntracks = points->GetEntriesFast();
668     for (track=0;track<ntracks;track++) {
669         pm = (AliMUONPoints*)points->UncheckedAt(track);
670         if (!pm) continue;
671         pm->Draw();
672         fHitsCuts += pm->GetN();
673     }
674 }
675
676
677 //_____________________________________________________________________________
678 void AliMUONDisplay::DrawCoG()
679 {
680 /// Draw hits for MUON chambers
681
682     if (!fDrawCoG) return;
683     if (fChamber > 10) return;
684     LoadCoG(fChamber,fCathode);
685     
686     Int_t ncog, icog;
687     TObjArray *points;
688     AliMUONPoints *pm;
689
690     points = Rpoints();
691     if (!points) return;
692     ncog = points->GetEntriesFast();
693     for (icog=0;icog<ncog;icog++) {
694         pm = (AliMUONPoints*)points->UncheckedAt(icog);
695         if (!pm) continue;
696         pm->Draw();
697     }
698 }
699 //_____________________________________________________________________________
700 void AliMUONDisplay::DrawTracks()
701 {
702 /// Draw tracks
703
704     if (!fDrawTracks) return;
705     LoadTracks();
706     
707     Int_t nTrack, iTrack;
708     TObjArray *points;
709     TPolyLine3D *pm;
710
711     points = Rpoints();
712     if (!points) return;
713     nTrack = points->GetEntriesFast();
714     for ( iTrack = 0; iTrack < nTrack; iTrack++) {
715         pm = (TPolyLine3D*)points->UncheckedAt(iTrack);
716         if (!pm) continue;
717         pm->Draw();
718     }
719 }
720 //_____________________________________________________________________________
721
722 void AliMUONDisplay::DrawTitle(Option_t *option)
723 {
724 /// Draw the event title
725
726     Float_t xmin = gPad->GetX1();
727     Float_t xmax = gPad->GetX2();
728     Float_t ymin = gPad->GetY1();
729     Float_t ymax = gPad->GetY2();
730     Float_t dx   = xmax-xmin;
731     Float_t dy   = ymax-ymin;
732     
733     AliRunLoader * runLoader;
734     if (fLoader)
735       runLoader = fLoader->GetRunLoader();
736     else
737       runLoader = 0x0;
738
739
740     if (strlen(option) == 0) {
741         TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
742 //      title->SetTextSize(0.023932);
743         title->SetTextSize(0.02);
744         title->SetBit(kCanDelete);
745         title->SetFillColor(42);
746         title->Draw();
747         char ptitle[100];
748         sprintf(ptitle, "Alice event:%d Run:%d Chamber:%d Cathode:%d",
749                 runLoader->GetEventNumber(),
750                 gAlice->GetHeader()->GetRun(),
751                 fChamber,
752                 fCathode);
753         title->AddText(ptitle);
754         Int_t nparticles = gAlice->GetMCApp()->Particles()->GetEntriesFast();
755         sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",
756                 nparticles, fHitsCuts,fClustersCuts);
757         title->AddText(ptitle);
758     } else {
759         TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
760         label->SetBit(kCanDelete);
761         label->SetFillColor(42);
762         label->Draw();
763     }
764 }
765
766 //_____________________________________________________________________________
767 void AliMUONDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
768 {
769 /// Draw a view of MUON clusters
770
771   AliInfo(" Draw View");
772   
773   gPad->SetCursor(kWatch);
774   // gPad->SetFillColor(39);
775   gPad->SetFillColor(1);
776   gPad->Clear();
777   // gPad->SetFillColor(39);
778   gPad->SetFillColor(1);
779   
780   Int_t iret=0;
781   TView *view = new TView(1);
782   
783   Float_t range = fRrange*fRangeSlider->GetMaximum();
784   view->SetRange(-range,-range,-range,range, range, range);
785   // zoom back to full scale only if DrawView not called from NextCathode
786   if (!fNextCathode) {
787     fZoomX0[0] = -1;
788     fZoomY0[0] = -1;
789     fZoomX1[0] =  1;
790     fZoomY1[0] =  1;
791     fZooms = 0;
792   }
793   
794   Float_t xg1, xg2, yg1, yg2, zg1, zg2;
795   
796   // Recovering the chamber 
797   AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
798   
799   const AliMUONGeometryTransformer* kGeomTransformer 
800     = pMUON->GetGeometryTransformer();
801   
802   AliMUONSegmentation* segmentation = pMUON->GetSegmentation();
803   AliMpSegFactory segFactory;
804   // Mapping segmentation factory will be used only to create mapping
805         // segmentations if not present in the DE segmentations
806   
807   // Display MUON Chamber Geometry
808   char nodeName[7];
809   sprintf(nodeName,"MUON%d",100+fChamber);
810   printf(">>>> chamber is %d\n",fChamber);
811   
812   if(fChamber < 5) {
813     AliMpDEIterator it;
814     for ( it.First(fChamber-1); ! it.IsDone(); it.Next() ) {
815       
816       Int_t detElemId = it.CurrentDE();
817       AliMpSectorSegmentation * seg =   
818         (AliMpSectorSegmentation *) segmentation->GetMpSegmentation(detElemId, 0);
819       const AliMpSector * sector = seg->GetSector();
820       
821       // get sector measurements
822       TVector2 position  = sector->Position(); 
823       TVector2 dimension = sector->Dimensions(); // half length
824       
825       Float_t xlocal1 =  position.Px(); // FIXME: not really needed as it's 0 ?
826       Float_t ylocal1 =  position.Py(); // FIXME: not really needed as it's 0 ?
827       Float_t xlocal2 =  dimension.Px() * 2.;
828       Float_t ylocal2 =  dimension.Px() * 2.;
829       
830       kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
831       kGeomTransformer->Local2Global(detElemId, xlocal2, ylocal2, 0, xg2, yg2, zg2);
832       
833       // drawing 
834       TPolyLine3D* poly = new  TPolyLine3D();
835       Int_t nPoint = 0;
836       
837       poly->SetPoint(nPoint++, xg1, yg1, 0.);
838       for (Float_t d = 0; d < TMath::Pi()/2.; d+= 0.01) {
839         Float_t x = xg1 + xg2 * TMath::Cos(d);
840         Float_t y = yg1 + yg2 * TMath::Sin(d);
841         poly->SetPoint(nPoint++, x, y, 0.);
842       }
843       poly->SetPoint(nPoint++, xg1, yg1, 0.);
844       
845       poly->SetLineColor(2);
846       poly->Draw("s");
847     }
848     
849   }
850   
851   if (fChamber>4) 
852   {
853     AliMpDEIterator it;
854     for ( it.First(fChamber-1); ! it.IsDone(); it.Next() ) 
855     {
856       Int_t detElemId = it.CurrentDE();
857       AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
858
859       if (  segmentation->HasDE(detElemId) ) 
860       {
861         const AliMpVSegmentation* seg = segmentation->GetMpSegmentation(detElemId, 0);
862         if (!seg) { 
863           // Create mapping segmentation if old trigger segmentation
864           // (not using mapping)
865           seg = segFactory.CreateMpSegmentation(detElemId, 0);
866         }         
867         if (seg) 
868         {  
869           Float_t deltax = seg->Dimensions().X();
870           Float_t deltay = seg->Dimensions().Y();
871           Float_t xlocal1 =  -deltax;
872           Float_t ylocal1 =  -deltay;
873           Float_t xlocal2 =  +deltax;
874           Float_t ylocal2 =  +deltay;
875           kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
876           kGeomTransformer->Local2Global(detElemId, xlocal2, ylocal2, 0, xg2, yg2, zg2);
877           
878           // drawing slat active volumes
879           Float_t xCenter = (xg1 + xg2)/2.;
880           Float_t yCenter = (yg1 + yg2)/2.;
881           
882           TMarker3DBox* box = new TMarker3DBox(xCenter,yCenter,0,xlocal1,ylocal2,0,0,0);
883           
884           box->SetFillStyle(0);
885           box->SetLineColor( stationType == kStationTrigger ? 4 : 2);
886           box->Draw("s");
887           
888           if ( stationType == kStation345 )
889           {
890             // drawing inner circle + disc
891             TPolyLine3D* poly  = new  TPolyLine3D();
892             TPolyLine3D* poly1 = new  TPolyLine3D();
893             
894             Int_t nPoint = 0;
895             Int_t nPoint1 = 0;
896             for (Float_t d = 0; d < 6.24; d+= 0.005) 
897             {
898               Double_t x = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Cos(d)/2.;
899               Double_t y = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Sin(d)/2.;
900               if (nPoint % 2 == 0) poly->SetPoint(nPoint++, 0., 0., 0.);
901               poly->SetPoint(nPoint++, x, y, 0.);
902               poly1->SetPoint(nPoint1++, x, y, 0.);            
903             }
904             poly->SetLineColor(1);
905             poly->Draw("s");
906             poly1->SetLineColor(2);
907             poly1->Draw("s");
908           }
909         }  
910       }
911     }
912   }
913   
914 //   // Delete mapping segmentations created with factory
915 //  segFactory.DeleteSegmentations();
916   
917   //add clusters to the pad
918   DrawClusters();
919   DrawHits();
920   DrawCoG();
921   //     DrawSegmentation();
922   // add itself to the list (must be last)
923   AppendPad();
924   view->SetView(phi, theta, psi, iret);
925 }
926
927 //_____________________________________________________________________________
928 void AliMUONDisplay::DrawGlobalView(Float_t theta, Float_t phi, Float_t psi)
929 {
930 /// Draw a view of muons chambers with tracks
931     
932     gPad->SetCursor(kWatch);
933     // gPad->SetFillColor(39);
934     gPad->SetFillColor(1);
935     gPad->Clear();
936     // gPad->SetFillColor(39);
937     gPad->SetFillColor(1);
938     
939
940     Int_t iret=0;
941     TView *view = new TView(1);
942     
943     Float_t range = fRrange*fRangeSlider->GetMaximum()*3.;
944     view->SetRange(-range,-range,-range,range,range,range);
945
946 // Display all MUON Chambers segmentation
947     char nodeName[7];
948     TNode *node1;
949     sprintf(nodeName,"alice");
950     
951     node1=gAlice->GetGeometry()->GetNode(nodeName);
952     if (node1) node1->Draw("same"); 
953      
954       
955 // Draw clusters for all chambers
956     Int_t chamberSave = fChamber;
957     for (fChamber = 1; fChamber <= 10; fChamber++){
958       DrawCoG();
959     }
960     fChamber = chamberSave;
961 // Draw reconstructed tracks
962     DrawTracks();
963
964     AppendPad();
965
966     Float_t zoom = 2.;
967     Float_t shift = 0.9;
968     Float_t x0 = (-1+shift)/zoom;
969     Float_t y0 = (-1+shift)/zoom;
970     Float_t x1 = (1+shift)/zoom;
971     Float_t y1 = (1+shift)/zoom;
972     gPad->Range(x0,y0,x1,y1);
973     view->SetView(phi, theta, psi, iret);
974
975 }
976
977 //______________________________________________________________________________
978 void AliMUONDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
979 {
980 /// Execute action corresponding to the mouse event
981
982     static Float_t x0, y0, x1, y1;
983     
984     static Int_t pxold, pyold;
985     static Int_t px0, py0;
986     static Int_t linedrawn;
987     Float_t temp;
988     
989     if (px == 0 && py == 0) { //when called by sliders
990         if (event == kButton1Up) {
991             Draw();
992         }
993         return;
994     }
995     if (!fZoomMode && gPad->GetView()) {
996         gPad->GetView()->ExecuteRotateView(event, px, py);
997         return;
998     }
999
1000     // something to zoom ?
1001     gPad->SetCursor(kCross);
1002     
1003     switch (event) {
1004
1005     case kButton1Down:
1006         gVirtualX->SetLineColor(-1);
1007         gPad->TAttLine::Modify();  //Change line attributes only if necessary
1008         x0 = gPad->AbsPixeltoX(px);
1009         y0 = gPad->AbsPixeltoY(py);
1010         px0   = px; py0   = py;
1011         pxold = px; pyold = py;
1012         linedrawn = 0;
1013         return;
1014         
1015     case kButton1Motion:
1016         if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
1017         pxold = px;
1018         pyold = py;
1019         linedrawn = 1;
1020         gVirtualX->DrawBox(px0, py0, pxold, pyold,  TVirtualX::kHollow);
1021         return;
1022         
1023     case kButton1Up:
1024         gPad->GetCanvas()->FeedbackMode(kFALSE);
1025         if (px == px0) return;
1026         if (py == py0) return;
1027         x1 = gPad->AbsPixeltoX(px);
1028         y1 = gPad->AbsPixeltoY(py);
1029         
1030         if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
1031         if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
1032         gPad->Range(x0,y0,x1,y1);
1033         if (fZooms < AliMUONConstants::MaxZoom()-1) {
1034             fZooms++;
1035             fZoomX0[fZooms] = x0;
1036             fZoomY0[fZooms] = y0;
1037             fZoomX1[fZooms] = x1;
1038             fZoomY1[fZooms] = y1;
1039         }
1040         gPad->Modified(kTRUE);
1041         return;
1042     }
1043 }
1044  
1045 //___________________________________________
1046 void AliMUONDisplay::LoadDigits(Int_t chamber, Int_t cathode)
1047 {
1048 /// Read digits info and store x,y,z info in arrays fPoints.
1049 /// Loop on all detectors
1050
1051     if (chamber > 14) return;
1052     fChamber = chamber;
1053     fCathode = cathode;
1054     
1055     ResetPoints();
1056     
1057     AliMUON *pMUON  =     (AliMUON*)gAlice->GetModule("MUON");
1058
1059     AliMUONGeometrySegmentation*  segmentation2 = 0x0;
1060
1061     GetMUONData()->SetTreeAddress("D");
1062
1063     TClonesArray *muonDigits  = GetMUONData()->Digits(chamber-1);
1064     if (muonDigits == 0) return;
1065
1066     gAlice->ResetDigits();
1067     Int_t nent = 0;
1068  
1069     if (GetLoader()->TreeD()) {
1070         nent = (Int_t) GetLoader()->TreeD()->GetEntries();
1071         //     gAlice->TreeD()->GetEvent(nent-2+cathode-1);
1072         GetMUONData()->GetDigits();
1073     }
1074     
1075     Int_t ndigits = muonDigits->GetEntriesFast();    
1076     if (ndigits == 0) return;
1077     if (fPoints == 0) fPoints = new TObjArray(ndigits);
1078     
1079     Float_t zpos = AliMUONConstants::DefaultChamberZ(chamber-1);
1080
1081     AliMUONDigit  *mdig;
1082     AliMUONPoints *points  = 0;
1083     TMarker3DBox  *marker  = 0;
1084
1085     Int_t npoints  = 1;
1086     Float_t adcmax = 1024; // default
1087     if (chamber<11) adcmax = 4096;
1088
1089 // check if trigger is using new or old segmentation
1090     Bool_t old = true;
1091     AliMUONSegmentation* segmentation = pMUON->GetSegmentation();
1092     if ( segmentation->GetMpSegmentation(1100, cathode-1) ) old = false;
1093
1094     if ( old  && chamber > 10) {
1095         if (chamber > 10) printf(">>> old segmentation for trigger \n");
1096         else printf(">>> old segmentation for tracking \n");
1097
1098         segmentation2
1099             = pMUON->GetSegmentation()->GetModuleSegmentation(chamber-1, cathode-1);
1100         for (Int_t digit = 0; digit < ndigits; digit++) {
1101             mdig    = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
1102             if (mdig->Cathode() != cathode-1) continue;
1103             
1104             //
1105             // First get all needed parameters
1106             //
1107             Int_t charge = mdig->Signal();
1108             Int_t index  = Int_t(TMath::Log(charge)/(TMath::Log(adcmax)/22));
1109             Int_t color  = 261+index;
1110             Int_t colorTrigger = 2;   
1111             if (color > 282) color = 282;
1112             
1113             if (chamber > 10) { // trigger chamber 
1114                 
1115                 Int_t sumCharge = 0;
1116                 for (Int_t icharge = 0; icharge < 10; icharge++) {
1117                     sumCharge = sumCharge+mdig->TrackCharge(icharge);
1118                 }
1119                 Int_t testCharge = sumCharge-(Int_t(sumCharge/10))*10;
1120                 if(sumCharge <= 10 || testCharge > 0) {
1121                     colorTrigger = color; 
1122                 } else {
1123                     colorTrigger = 5; 
1124                 }
1125             }
1126             
1127             // get the center of the pad - add on x and y half of pad size
1128             Float_t xpad, ypad, zpad;
1129             Int_t isec;
1130             Float_t dpx, dpy;
1131             
1132             Int_t detElemId = mdig->DetElemId();
1133             segmentation2->GetPadC(detElemId, mdig->PadX(), mdig->PadY(), xpad, ypad, zpad);
1134             isec = segmentation2->Sector(detElemId, mdig->PadX(), mdig->PadY());
1135             dpx = segmentation2->Dpx(detElemId, isec)/2;
1136             dpy = segmentation2->Dpy(detElemId, isec)/2;
1137             
1138             // Then set the objects
1139             points = new AliMUONPoints(npoints);
1140             fPoints->AddAt(points,digit);
1141             if (chamber > 10) {
1142                 points->SetMarkerColor(colorTrigger);
1143             } else {  
1144                 points->SetMarkerColor(color);
1145             }
1146             points->SetMarkerStyle(21);
1147             points->SetMarkerSize(0.5);
1148             points->SetParticle(-1);
1149             points->SetHitIndex(-1);
1150             points->SetTrackIndex(-1);
1151             points->SetDigitIndex(digit);
1152             points->SetPoint(0,xpad,ypad,zpos);
1153             
1154             Int_t lineColor = (zpad-zpos > 0) ? 2:3;
1155             marker=new TMarker3DBox(xpad,ypad,zpos,dpx,dpy,0,0,0);
1156             
1157             
1158             marker->SetLineColor(lineColor);
1159             marker->SetFillStyle(1001);
1160             marker->SetFillColor(color);
1161             marker->SetRefObject((TObject*)points);
1162             points->Set3DMarker(0, marker);
1163         } // end loop on digits     
1164         
1165     } else {    
1166         if (chamber > 10) printf(">>> new segmentation for trigger \n");
1167         else printf(">>> new segmentation for tracking \n");
1168         
1169         const AliMUONGeometryTransformer* kGeomTransformer 
1170             = pMUON->GetGeometryTransformer();
1171         
1172         //loop over all digits and store their position
1173         for (Int_t digit = 0; digit < ndigits; digit++) {
1174             mdig    = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
1175             if (mdig->Cathode() != cathode-1) continue;
1176             
1177             // get all needed parameters
1178             Int_t ix=mdig->PadX();
1179             Int_t iy=mdig->PadY();
1180             Int_t detElemId=mdig->DetElemId();      
1181             Int_t charge = mdig->Signal();
1182             Int_t index  = Int_t(TMath::Log(charge)/(TMath::Log(adcmax)/22));
1183             Int_t color  = 261+index;
1184             Int_t colorTrigger = 2;   
1185             if (color > 282) color = 282;
1186             
1187             const AliMpVSegmentation* seg = 
1188                 pMUON->GetSegmentation()->GetMpSegmentation(detElemId,cathode-1);
1189             
1190             AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
1191             
1192             if (chamber > 10) { // trigger chamber
1193                 Int_t sumCharge = 0;
1194     Int_t n = mdig->Ntracks();
1195                 for (Int_t icharge = 0; icharge < n; icharge++) {
1196                     sumCharge = sumCharge+mdig->TrackCharge(icharge);
1197                 }
1198     assert(sumCharge==mdig->Signal());
1199                 Int_t testCharge = sumCharge-(Int_t(sumCharge/n))*n;
1200                 if(sumCharge <= n || testCharge > 0) {
1201                     colorTrigger = color; 
1202                 } else {
1203                     colorTrigger = 5; 
1204                 }
1205             }
1206             
1207             // get the pad position and dimensions
1208             Float_t xlocal1 = pad.Position().X();
1209             Float_t ylocal1 = pad.Position().Y();
1210             Float_t xlocal2 = pad.Dimensions().X();
1211             Float_t ylocal2 = pad.Dimensions().Y();
1212             
1213             Float_t xg1, xg2, yg1, yg2, zg1;
1214             
1215             kGeomTransformer->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
1216             // (no transformation for pad dimensions)
1217             xg2 = xlocal2;
1218             yg2 = ylocal2;
1219             
1220             // Then set the objects
1221             points = new AliMUONPoints(npoints);
1222             fPoints->AddAt(points,digit);
1223             if (chamber > 10) {
1224                 points->SetMarkerColor(colorTrigger);
1225             } else {  
1226                 points->SetMarkerColor(color);
1227             }
1228             points->SetMarkerStyle(21);
1229             points->SetMarkerSize(0.5);
1230             points->SetParticle(-1);
1231             points->SetHitIndex(-1);
1232             points->SetTrackIndex(-1);
1233             points->SetDigitIndex(digit);
1234             points->SetPoint(0,xg1,yg1,zpos);
1235             
1236             Int_t lineColor = (zg1-zpos > 0) ? 2:3;
1237             marker=new TMarker3DBox(xg1,yg1,zpos,xg2,yg2,0,0,0);
1238             
1239             marker->SetLineColor(lineColor);
1240             marker->SetFillStyle(1001);
1241             marker->SetFillColor(color);
1242             marker->SetRefObject((TObject*)points);
1243             points->Set3DMarker(0, marker);
1244             
1245         } // end loop on digits
1246     } // end of new segmentation    
1247 }
1248 //___________________________________________
1249 void AliMUONDisplay::LoadCoG(Int_t chamber, Int_t /*cathode*/)
1250 {
1251 /// Read raw clusters info and store x,y,z info in arrays fRpoints.
1252 /// Loop on all detectors
1253
1254     if (chamber > 10) return;
1255     
1256     ResetRpoints();
1257     
1258     GetMUONData()->SetTreeAddress("RC");
1259     TClonesArray *muonRawClusters  = GetMUONData()->RawClusters(chamber-1);
1260
1261     if (muonRawClusters == 0) return;
1262
1263     Int_t nent = 0;
1264     if (GetMUONData()->TreeR()) {
1265         nent=(Int_t) GetMUONData()->TreeR()->GetEntries();
1266         GetMUONData()->TreeR()->GetEvent(0);
1267     }
1268     
1269     Int_t nrawcl = muonRawClusters->GetEntriesFast();
1270     if (nrawcl == 0) return;
1271     if (fRpoints == 0) fRpoints = new TObjArray(nrawcl);
1272     
1273     Float_t zpos = AliMUONConstants::DefaultChamberZ(chamber-1);  
1274     AliMUONRawCluster  *mRaw;
1275     AliMUONPoints *points = 0;
1276     //
1277     //loop over all raw clusters and store their position
1278     points = new AliMUONPoints(nrawcl);
1279     for (Int_t iraw=0;iraw<nrawcl;iraw++) {
1280         mRaw   = (AliMUONRawCluster*)muonRawClusters->UncheckedAt(iraw);
1281         points->SetMarkerColor(51);
1282         points->SetMarkerStyle(2);
1283         points->SetMarkerSize(1.);
1284         points->SetParticle(-1);
1285         points->SetHitIndex(-1);
1286         points->SetTrackIndex(-1);
1287         points->SetDigitIndex(-1);
1288         points->SetPoint(iraw,mRaw->GetX(0),mRaw->GetY(0),zpos);
1289         fRpoints->AddAt(points,iraw);
1290         //      printf("%f and %f and %f\n",mRaw->GetX(0),mRaw->GetY(0),mRaw->GetZ(0));
1291     }
1292 }
1293
1294 //___________________________________________
1295 void AliMUONDisplay::LoadTracks()
1296 {
1297 /// Load tracks
1298
1299   AliMUONTrack* recTrack = 0;
1300   AliMUONTrackParam* trackParam = 0;
1301   TClonesArray *  trackParamAtHit = 0;   
1302
1303   ResetRpoints();
1304
1305   GetMUONData()->SetTreeAddress("RT");
1306   TClonesArray* recTracksArray = GetMUONData()->RecTracks();
1307   if (recTracksArray == NULL) return;
1308   GetMUONData()->GetRecTracks();
1309
1310   Int_t nRecTracks = 0;
1311   if (recTracksArray)
1312     nRecTracks = (Int_t) recTracksArray->GetEntriesFast();
1313
1314
1315   if (fRpoints == 0) fRpoints = new TObjArray(nRecTracks);
1316
1317   for (Int_t iRecTracks = 0; iRecTracks <  nRecTracks;  iRecTracks++) {
1318     // reading info from tracks
1319     recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
1320
1321     Int_t nTrackHits = recTrack->GetNTrackHits();
1322
1323     if (nTrackHits == 0) continue;
1324
1325     Int_t iPoint = 0;
1326     TPolyLine3D *points = new TPolyLine3D(nTrackHits+1); 
1327     points->SetLineColor(6);
1328     points->SetLineWidth(1);
1329     fRpoints->AddAt(points,iRecTracks);
1330
1331     Float_t xRec=0;
1332     Float_t yRec=0;
1333     Float_t zRec=0;
1334
1335     trackParam = recTrack->GetTrackParamAtVertex(); 
1336     xRec  = trackParam->GetNonBendingCoor();
1337     yRec  = trackParam->GetBendingCoor();
1338     zRec  = trackParam->GetZ();
1339     points->SetPoint(iPoint,xRec,yRec,zRec);
1340     iPoint++;   
1341
1342     for (Int_t iHit = 0; iHit < nTrackHits; iHit++){
1343       trackParamAtHit = recTrack->GetTrackParamAtHit();
1344       trackParam = (AliMUONTrackParam*) trackParamAtHit->At(iHit); 
1345       xRec  = trackParam->GetNonBendingCoor();
1346       yRec  = trackParam->GetBendingCoor();
1347       zRec  = trackParam->GetZ();
1348       points->SetPoint(iPoint,xRec,yRec,zRec);
1349       iPoint++; 
1350     } // end loop rec. hits
1351     PrintTrack(iRecTracks,recTrack);
1352   } // end loop tracks
1353   
1354
1355 }
1356
1357 //___________________________________________
1358 void AliMUONDisplay::PrintTrack(Int_t iRecTracks, AliMUONTrack *recTrack)
1359 {
1360 /// Print reconstructed track
1361
1362   AliMUONTrackParam *trackParam;
1363   Float_t vertex[3], momentum[3];
1364   Float_t pYZ, bendingSlope, nonBendingSlope, chi2dof;
1365   Int_t charge;
1366
1367   trackParam = recTrack->GetTrackParamAtVertex();
1368   vertex[0] = trackParam->GetNonBendingCoor();
1369   vertex[1] = trackParam->GetBendingCoor();
1370   vertex[2] = trackParam->GetZ();
1371   pYZ =  1./TMath::Abs(trackParam->GetInverseBendingMomentum());
1372   bendingSlope = trackParam->GetBendingSlope();
1373   nonBendingSlope = trackParam->GetNonBendingSlope();
1374   momentum[2] = -pYZ / TMath::Sqrt(1.0 + bendingSlope*bendingSlope);
1375   momentum[0] = momentum[2] * nonBendingSlope;
1376   momentum[1] = momentum[2] * bendingSlope;
1377   charge = Int_t(TMath::Sign(1.,trackParam->GetInverseBendingMomentum()));
1378   chi2dof = recTrack->GetFitFMin()/(2.0 * recTrack->GetNTrackHits() - 5.);
1379   
1380   printf("===================================================\n");
1381   printf(" Reconstructed track # %d \n",iRecTracks);
1382   printf(" charge: %d \n",charge);
1383   printf(" vertex x,y,z (cm): %f %f %f \n",vertex[0],vertex[1],vertex[2]); 
1384   printf(" momentum Px,Py,Pz (GeV/c): %f %f %f \n",momentum[0],momentum[1],momentum[2]);
1385   printf(" track chi2/dof: %f \n",chi2dof); 
1386   
1387 }
1388
1389 //___________________________________________
1390 void AliMUONDisplay::LoadHits(Int_t chamber)
1391 {
1392 /// Read hits info and store x,y,z info in arrays fPhits.
1393 /// Loop on all detectors
1394
1395     if (chamber > 14) return;
1396     Int_t track;
1397
1398     fChamber=chamber;
1399  
1400     ResetPhits();
1401     
1402     Float_t zpos=AliMUONConstants::DefaultChamberZ(chamber-1);
1403
1404     if (GetMUONData()->TreeH()) {
1405       GetMUONData()->SetTreeAddress("H");
1406       Int_t ntracks = (Int_t)GetMUONData()->TreeH()->GetEntries(); //skowron
1407       Int_t nthits  = 0;
1408       for (track = 0; track < ntracks; track++) {
1409         GetMUONData()->ResetHits();
1410         GetMUONData()->GetTrack(track);//skowron
1411         TClonesArray *muonHits  = GetMUONData()->Hits();
1412         if (muonHits == 0) return;
1413         nthits += muonHits->GetEntriesFast();
1414       } 
1415       if (fPhits == 0) fPhits = new TObjArray(nthits);
1416       Int_t nhold=0;
1417       for (track=0; track<ntracks;track++) {
1418         GetMUONData()->ResetHits();
1419         GetMUONData()->GetTrack(track);//skowron
1420         TClonesArray *muonHits  = GetMUONData()->Hits();
1421         if (muonHits == 0) return;
1422         Int_t nhits = muonHits->GetEntriesFast();
1423         if (nhits == 0) continue;
1424         AliMUONHit *mHit;
1425         AliMUONPoints *points = 0;
1426         Int_t npoints=1;
1427         for (Int_t hit=0;hit<nhits;hit++) {
1428           mHit = (AliMUONHit*)muonHits->UncheckedAt(hit);
1429           Int_t nch  = mHit->Chamber();              // chamber number
1430           if (nch != chamber) continue;
1431           //
1432           // Retrieve info and set the objects
1433           //
1434           points = new AliMUONPoints(npoints);
1435           fPhits->AddAt(points,nhold+hit);
1436           points->SetMarkerColor(kRed);
1437           points->SetMarkerStyle(5);
1438           points->SetMarkerSize(1.);
1439           points->SetParticle(mHit->Track());
1440           points->SetHitIndex(hit);
1441           points->SetTrackIndex(track);
1442           points->SetDigitIndex(-1);
1443           points->SetPoint(0,mHit->X(),mHit->Y(),zpos);
1444           //        printf("%f and %f and %f\n",mHit->X(),mHit->Y(),mHit->Z());
1445         }
1446         nhold+=nhits;
1447       }
1448     }
1449 }
1450
1451 //_____________________________________________________________________________
1452 void AliMUONDisplay::Paint(Option_t *)
1453 {
1454 /// Paint miscellaneous items
1455 }
1456
1457 //_____________________________________________________________________________
1458 void AliMUONDisplay::SetPickMode()
1459 {
1460 /// Set parameters for pick mode.
1461  
1462     fZoomMode = 0;
1463
1464     fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
1465     fTrigPad->Modified();
1466 }
1467
1468 //_____________________________________________________________________________
1469 void AliMUONDisplay::SetZoomMode()
1470 {
1471 /// Set parameters for zoom mode
1472
1473     fZoomMode = 1;
1474     
1475     fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
1476     fTrigPad->Modified();
1477 }
1478
1479 //_____________________________________________________________________________
1480 void AliMUONDisplay::NextChamber(Int_t delta)
1481 {
1482 /// To go from chamber to next chamber if delta = 1
1483 /// or previous chamber otherwise
1484     if (delta == 1) {
1485         if (fChamber < AliMUONConstants::NCh()) fChamber++;
1486     } else {
1487         if (fChamber > 1) fChamber--;
1488     }
1489     if (!fPad) return;
1490     fPad->Clear();
1491     LoadDigits(fChamber, fCathode);
1492     DrawChamber();
1493 }
1494
1495 //_____________________________________________________________________________
1496 void AliMUONDisplay::NextCathode()
1497 {
1498 /// To switch to other cathode plane
1499
1500     if (!fPad) return;
1501     fPad->Clear();
1502     if (fCathode == 1) {
1503         LoadDigits(fChamber, 2);        
1504     } else {
1505         LoadDigits(fChamber, 1);
1506     }
1507     fNextCathode = kTRUE; // to keep the same zoom
1508     DrawChamber();
1509     fNextCathode = kFALSE;
1510     TPad *pad = (TPad*)gPad->GetPadSave();
1511     pad->Range(fZoomX0[fZooms], fZoomY0[fZooms],
1512                fZoomX1[fZooms], fZoomY1[fZooms]);
1513     pad->Modified();
1514     fPad->cd();
1515     DrawTitle();
1516 }
1517
1518 //_____________________________________________________________________________
1519 void AliMUONDisplay::Trigger()
1520 {
1521 /// Print global trigger output
1522
1523   AliMUONGlobalTrigger* globalTrig;
1524
1525   GetMUONData()->SetTreeAddress("GLT");
1526   GetMUONData()->GetTriggerD();
1527
1528   globalTrig =  (AliMUONGlobalTrigger*)GetMUONData()->GlobalTrigger()->UncheckedAt(0);
1529   if (globalTrig == 0) return;
1530
1531   globalTrig->Print("full");
1532
1533  //  // returns Trigger Decision for current event
1534 //   AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(GetLoader(),1);
1535
1536 //   //  AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
1537 //   AliMUONData* muonData = decision->GetMUONData();
1538 //   muonData->SetTreeAddress("D");
1539 //   decision->Trigger(); 
1540 }
1541 //_____________________________________________________________________________
1542 void AliMUONDisplay::SetChamberAndCathode(Int_t chamber, Int_t cathode)
1543 {
1544 /// Set chamber and cathode number
1545
1546    fChamber = chamber;
1547    fCathode = cathode;
1548
1549    if (!fPad) return;
1550    fPad->Clear();
1551    LoadDigits(chamber,cathode);
1552    DrawChamber();
1553 }
1554
1555 //_____________________________________________________________________________
1556 void AliMUONDisplay::SetEvent(Int_t newevent)
1557 {
1558 /// Chose event 
1559
1560     gAlice->GetEvent(newevent);
1561     fEvent=newevent;
1562     if (!gAlice->TreeD()) return; 
1563     if (!fPad) return;
1564     fPad->Clear();
1565     LoadDigits(fChamber,fCathode);
1566     Draw();
1567 }
1568
1569 //_____________________________________________________________________________
1570 void AliMUONDisplay::SetRange(Float_t rrange, Float_t zrange)
1571 {
1572 /// Set view range along R and Z
1573
1574     fRrange = rrange;
1575     fZrange = zrange;
1576
1577     if (!fPad) return;
1578     fPad->Clear();
1579     Draw();
1580 }
1581    
1582 //_____________________________________________________________________________
1583 void AliMUONDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
1584 {
1585 /// Change viewing angles for current event
1586
1587     fPad->cd();
1588     fPhi   = phi;
1589     fTheta = theta;
1590     fPsi   = psi;
1591     Int_t iret = 0;
1592     
1593     TView *view = gPad->GetView();
1594     if (view) view->SetView(fPhi, fTheta, fPsi, iret);
1595     else      Draw();
1596     gPad->Modified();
1597 }
1598
1599 //_____________________________________________________________________________
1600 void AliMUONDisplay::ShowNextEvent(Int_t delta)
1601 {
1602 /// Display (current event_number + delta)
1603 ///  -  delta =  1  shown next event
1604 ///  -  delta = -1 show previous event
1605
1606   AliRunLoader * runLoader;
1607   if (fLoader)
1608     runLoader = fLoader->GetRunLoader();
1609   else
1610     runLoader = 0x0;
1611     
1612     if (delta) {
1613       //runLoader->CleanDetectors();
1614       //runLoader->CleanKinematics();
1615       Int_t currentEvent = runLoader->GetEventNumber();
1616       Int_t newEvent     = currentEvent + delta;
1617       runLoader->GetEvent(newEvent);
1618       fEvent=newEvent;
1619     }
1620     LoadDigits(fChamber, fCathode);
1621     fPad->cd(); 
1622     Draw();
1623 }
1624
1625 //______________________________________________________________________________
1626 void AliMUONDisplay::UnZoom()
1627 {
1628 /// Unzoom 
1629
1630     if (fZooms <= 0) return;
1631     fZooms--;
1632     TPad *pad = (TPad*)gPad->GetPadSave();
1633     pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
1634     pad->Modified();
1635 }
1636
1637 //_____________________________________________________________________________
1638 void AliMUONDisplay::ResetPoints()
1639 {
1640 /// Reset array of points
1641
1642     if (fPoints) {
1643         fPoints->Delete();
1644         delete fPoints;
1645         fPoints = 0;
1646     }
1647 }
1648 //_____________________________________________________________________________
1649 void AliMUONDisplay::ResetPhits()
1650 {
1651 /// Reset array of points
1652
1653     if (fPhits) {
1654         fPhits->Delete();
1655         delete fPhits;
1656         fPhits = 0;
1657     }
1658 }
1659 //_____________________________________________________________________________
1660 void AliMUONDisplay::ResetRpoints()
1661 {
1662 /// Reset array of points
1663
1664     if (fRpoints) {
1665         fRpoints->Clear();
1666         //      delete fRpoints;
1667         fRpoints = 0;
1668     }
1669 }