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