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