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