]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDisplay.cxx
trigger geometry part made more compact
[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 <TROOT.h>
27 #include <TTree.h>
28 #include <TButton.h>
29 #include <TColor.h>
30 #include <TCanvas.h>
31 #include <TView.h>
32 #include <TText.h>
33 #include <TPolyMarker3D.h>
34 #include <TPaveLabel.h>
35 #include <TPaveText.h>
36 #include <TList.h>
37 #include <TDiamond.h>
38 #include <TNode.h>
39 #include <TArc.h>
40 #include <TTUBE.h>
41 #include <TSlider.h>
42 #include <TSliderBox.h>
43 #include <TGaxis.h>
44 #include <TVirtualX.h>
45 #include <TMath.h>
46 #include <TMatrix.h>
47 #include <TGeometry.h>
48 #include <X3DBuffer.h>
49 #include <TMarker3DBox.h>
50
51 #include "AliRun.h"
52 #include "AliDetector.h"
53 #include "AliMUON.h"
54 #include "AliMUONDisplay.h"
55 #include "AliMUONPoints.h"
56 #include "TParticle.h"
57 #include "AliMUONTriggerDecision.h"
58 #include "AliHeader.h"
59
60 #include "AliMUONHit.h"
61 #include "AliMUONPadHit.h"
62 #include "AliMUONDigit.h"
63 #include "AliMUONRawCluster.h"
64
65 #include "AliSegmentation.h"
66 #include "AliMUONResponse.h"
67 #include "AliMUONChamber.h"
68 #include "AliMUONConstants.h"
69 // to manage the same zoom on both cathodes
70
71
72
73 ClassImp(AliMUONDisplay)
74
75
76 //_____________________________________________________________________________
77 AliMUONDisplay::AliMUONDisplay()
78 {
79 // Constructor
80     fPoints = 0;
81     fPhits = 0;
82     fRpoints = 0;
83     fCanvas = 0;
84     fNextCathode = kFALSE; 
85     fColPad = 0;
86 }
87
88 //_____________________________________________________________________________
89 AliMUONDisplay::AliMUONDisplay(Int_t size)
90 {
91 // Create an event display object.
92 // A canvas named "edisplay" is created with a vertical size in pixels
93 //
94 //    A QUICK Overview of the Event Display functions
95 //    ===============================================
96 //
97 //  The event display can ve invoked by executing the macro "display.C"
98 // A canvas like in the picture below will appear.
99 //
100 //  On the left side of the canvas, the following buttons appear:
101 //   *Next*       to move to the next event
102 //   *Previous*   to move to the previous event
103
104 //   *Pick*       Select this option to be able to point on a track with the
105 //                mouse. Once on the track, use the right button to select
106 //                an action. For example, select SetMarkerAttributes to
107 //                change the marker type/color/size for the track.
108 //   *Zoom*       Select this option (default) if you want to zoom.
109 //                To zoom, simply select the selected area with the left button.
110 //   *UnZoom*     To revert to the previous picture size.
111 //
112 //   slider R     On the left side, the vertical slider can be used to
113 //                set the default picture size.
114 //
115 //    When you are in Zoom mode, you can click on the black part of the canvas
116 //  to select special options with the right mouse button.
117
118 //
119 //  When you are in pick mode, you can "Inspect" the object pointed by the mouse.
120 //  When you are on a track, select the menu item "InspectParticle"
121 //  to display the current particle attributes.
122 //
123 //  You can activate the Root browser by selecting the Inspect menu
124 //  in the canvas tool bar menu. Then select "Start Browser"
125 //  This will open a new canvas with the browser. At this point, you may want
126 //  to display some histograms (from the Trees). Go to the "File" menu
127 //  of the browser and click on "New canvas".
128 //  In the browser, click on item "ROOT files" in the left pane.
129 //  Click on galice.root.
130 //  Click on TH
131 //  Click on TPC for example
132 //  Click on any variable (eg TPC.fX) to histogram the variable.
133 //
134 //   If you are lost, you can click on HELP in any Root canvas or browser.
135 //Begin_Html
136 /*
137 <img src="gif/AliMUONDisplay.gif">
138 */
139 //End_Html
140
141
142     fPad = 0;
143     
144     gAlice->SetDisplay(this);
145    
146    // Initialize display default parameters
147     SetRange(200,2000);
148    // Set front view by default
149     fTheta =   0;
150     fPhi   = -90;
151     fPsi   =   0;
152     fChamber = 1;
153     fCathode = 1;
154     //   fRzone   = 1.e10;
155     fDrawClusters  = kTRUE;
156     fDrawCoG       = kTRUE;
157     fZoomMode      = 1;
158     fZooms         = 0;
159     fClustersCuts  = 0;
160     fPoints        = 0;
161     fPhits         = 0;
162     fRpoints       = 0;
163     // Create colors
164     CreateColors();
165     // Create display canvas
166     Int_t ysize = size;
167     if (ysize < 100) ysize = 750;
168     Int_t xsize = Int_t(size*830./ysize);
169     fCanvas = new TCanvas("Canvas", "MUON Clusters Display",14,47,xsize,ysize);
170     fCanvas->ToggleEventStatus();
171     
172    // Create main display pad
173     fPad = new TPad("viewpad", "MUON display",0.15,0,0.9,1);
174     fPad->Draw();
175     fPad->Modified();
176     fPad->SetFillColor(30);
177     fPad->SetBorderSize(2);
178
179     fCanvas->cd();
180
181    // Create colors pad
182     fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1);
183     fColPad->Draw();
184     fColPad->SetFillColor(17);
185     fColPad->SetBorderSize(2);
186     fColPad->cd();
187     DisplayColorScale();
188
189     fCanvas->cd();
190    // Create user interface control pad
191     DisplayButtons();
192     fCanvas->cd();
193
194    // Create Range and mode pad
195     Float_t dxtr     = 0.15;
196     Float_t dytr     = 0.45;
197     fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
198     fTrigPad->Draw();
199     fTrigPad->cd();
200     fTrigPad->SetFillColor(22);
201     fTrigPad->SetBorderSize(2);
202     fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
203     fRangeSlider->SetObject(this);
204     char pickmode[] = "gAlice->Display()->SetPickMode()";
205     Float_t db = 0.09;
206     fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
207     fPickButton->SetFillColor(38);
208     fPickButton->Draw();
209     char zoommode[] = "gAlice->Display()->SetZoomMode()";
210     fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
211     fZoomButton->SetFillColor(38);
212     fZoomButton->Draw();
213     fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
214     fArcButton->SetFillColor(kGreen);
215     fArcButton->Draw();
216     char butUnzoom[] = "gAlice->Display()->UnZoom()";
217     TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
218     button->SetFillColor(38);
219     button->Draw();
220     AppendPad(); // append display object as last object to force selection
221     
222     fCanvas->cd();
223     fTrigPad->SetEditable(kFALSE);
224     fButtons->SetEditable(kFALSE);
225     fCanvas->Update();
226     fNextCathode = kFALSE; 
227 }
228
229 AliMUONDisplay::AliMUONDisplay(const AliMUONDisplay & display):AliDisplay(display)
230 {
231 // Dummy copy constructor    
232     ;
233 }
234
235
236
237 //_____________________________________________________________________________
238 AliMUONDisplay::~AliMUONDisplay()
239 {
240   // Delete space point structure
241     if (fPoints) fPoints->Delete();
242     delete fPoints;
243     fPoints     = 0;
244     //
245     if (fPhits) fPhits->Delete();
246     delete fPhits;
247     fPhits     = 0;
248     //
249     if (fRpoints) fRpoints->Delete();
250     delete fRpoints;
251     fRpoints     = 0;
252 }
253
254 //_____________________________________________________________________________
255 void AliMUONDisplay::Clear(Option_t *)
256 {
257 //    Delete graphics temporary objects
258 }
259
260 //_____________________________________________________________________________
261 void AliMUONDisplay::DisplayButtons()
262 {
263 //    Create the user interface buttons
264
265
266     fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
267     fButtons->Draw();
268     fButtons->SetFillColor(38);
269     fButtons->SetBorderSize(2);
270     fButtons->cd();
271     
272 //   Int_t butcolor = 33;
273     Float_t dbutton = 0.08;
274     Float_t y  = 0.96;
275     Float_t dy = 0.014;
276     Float_t x0 = 0.05;
277     Float_t x1 = 0.95;
278     
279     TButton *button;
280     char but1[] = "gAlice->Display()->ShowNextEvent(1)";
281     button = new TButton("Event +", but1, x0, y - dbutton, x1, y);
282     button->SetFillColor(38);
283     button->Draw();
284     
285     y -= dbutton + dy;
286     char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
287     button = new TButton("Event -", but2, x0, y - dbutton, x1, y);
288     button->SetFillColor(38);
289     button->Draw();
290    
291     y -= dbutton + dy;
292     char but3[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(1)";
293     button = new TButton("Chamber +", but3, x0, y - dbutton, x1, y);
294     button->SetFillColor(38);
295     button->Draw();
296     
297     y -= dbutton + dy;
298     char but4[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(-1)";
299     button = new TButton("Chamber -", but4, x0, y - dbutton, x1, y);
300     button->SetFillColor(38);
301     button->Draw();
302     
303     y -= dbutton + dy;
304     char but5[] = "((AliMUONDisplay*)(gAlice->Display()))->SetChamberAndCathode(1,1)";
305     button = new TButton("Chamber 1", but5, x0, y - dbutton, x1, y);
306     button->SetFillColor(38);
307     button->Draw();
308    
309     y -= dbutton + dy;
310     char but6[] = "((AliMUONDisplay*)(gAlice->Display()))->NextCathode()";
311     button = new TButton("Cathode <>", but6, x0, y - dbutton, x1, y);
312     button->SetFillColor(38);
313     button->Draw();
314
315     y -= dbutton + dy;
316     char but7[] = "((AliMUONDisplay*)(gAlice->Display()))->Trigger()";
317     button = new TButton("Trigger", but7, x0, y - dbutton, x1, y);
318     button->SetFillColor(38);
319     button->Draw();
320     
321    // display logo
322     TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
323     diamond->SetFillColor(50);
324     diamond->SetTextAlign(22);
325     diamond->SetTextColor(5);
326     diamond->SetTextSize(0.11);
327     diamond->Draw();
328     diamond->AddText(".. ");
329     diamond->AddText("ROOT");
330     diamond->AddText("MUON");
331     diamond->AddText("... ");
332     diamond->AddText(" ");
333 }
334
335 //_____________________________________________________________________________
336 void AliMUONDisplay::CreateColors()
337 {
338 //    Create the colors palette used to display clusters
339
340     Int_t k,i;
341     Int_t color;
342     Float_t r,g,b;
343     
344     for (k=1;k<=5;k++) {
345         switch(k) {
346         case 1:
347             for (i=1;i<=5;i++) {
348                 r=1.;
349                 g=i*0.2;  
350                 b=0.;
351                 color=i;
352                 color=260+23-color;
353                 new TColor(color,r,g,b);
354             } 
355             break;
356         case 2:
357             for (i=1;i<=4;i++) {
358                 r=1.1-i*0.2;
359                 g=1.;  
360                 b=0.;
361                 color=i+5;
362                 color=260+23-color;
363                 new TColor(color,r,g,b);
364             } 
365             break;
366         case 3:
367             for (i=1;i<=4;i++) {
368                 r=0.;
369                 g=1.;  
370                 b=i*0.2+0.2;
371                 color=i+9;
372                 color=260+23-color;
373                 new TColor(color,r,g,b);
374             } 
375             break;
376         case 4:
377             for (i=1;i<=4;i++) {
378                 r=0.;
379                 g=1.1-i*0.2;  
380                 b=1.;
381                 color=i+13;
382                 color=260+23-color;
383                 new TColor(color,r,g,b);
384             } 
385             break;
386         case 5:
387             for (i=1;i<=5;i++) {
388                 r=i*0.2;
389                 g=0.;  
390                 b=1.;
391                 color=i+17;
392                 color=260+23-color;
393                 new TColor(color,r,g,b);
394             } 
395             break;
396         }
397     }
398 }
399
400 //_____________________________________________________________________________
401 void AliMUONDisplay::DisplayColorScale()
402 {
403 // Display pulse height color scale
404     Int_t i;
405     Int_t color;
406     Float_t xlow, ylow, xup, yup, hs;
407     Float_t x1, y1, x2, y2;
408     x1 = y1 = 0;
409     x2 = y2 = 1.0;
410     
411     TText *text = new TText(0,0,"");
412     text->SetTextFont(61);
413     text->SetTextSize(0.2);
414     text->SetTextAlign(22);
415     
416     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
417     AliMUONChamber *iChamber = &(pMUON->Chamber(fChamber-1));
418     AliMUONResponse * response=iChamber->ResponseModel();
419     Int_t adcmax=1024;
420     if (response) adcmax = (Int_t) response->MaxAdc();
421     
422
423     TBox *box;
424     char label[8];
425 //*-* draw colortable boxes
426     hs = (y2-y1)/Float_t(22);
427     xlow=x1+.05;
428     xup=x2-0.5;
429     for (i=0;i<22;i++) {
430         ylow = y1 + hs*(Float_t(i));
431         yup  = y1 + hs*(Float_t(i+1));
432         color = 261+i;
433         Double_t logscale=Double_t(i+1)*(TMath::Log(adcmax)/22);
434         Int_t scale=(Int_t)TMath::Exp(logscale);
435         sprintf(label,"%d",scale);
436         box = new TBox(xlow, ylow, xup, yup);
437         box->Draw();
438         box->SetFillColor(color);
439         text->DrawText(xlow+0.7, 0.5*(ylow+yup),label);
440     }
441 }
442
443 //______________________________________________________________________________
444 Int_t AliMUONDisplay::DistancetoPrimitive(Int_t px, Int_t)
445 {
446 // Compute distance from point px,py to objects in event
447
448     gPad->SetCursor(kCross);
449     
450     if (gPad == fTrigPad) return 9999;
451     
452     const Int_t kBig = 9999;
453     Int_t dist   = kBig;
454     Float_t xmin = gPad->GetX1();
455     Float_t xmax = gPad->GetX2();
456     Float_t dx   = 0.02*(xmax - xmin);
457     Float_t x    = gPad->AbsPixeltoX(px);
458     if (x < xmin+dx || x > xmax-dx) return dist;
459     
460     if (fZoomMode) return 0;
461     else           return 7;
462 }
463
464 //_____________________________________________________________________________
465 void AliMUONDisplay::Draw(Option_t *)
466 {
467 //    Display current event
468
469     fPad->cd();
470
471     DrawView(fTheta, fPhi, fPsi);   
472     // Display the event number and title
473     fPad->cd();
474     DrawTitle();
475 }
476
477 void AliMUONDisplay::DrawSegmentation()
478 {
479 // Draw graphical representation of segmenatation
480 // Attention: still experimental code
481     Int_t icat=1;
482     
483     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
484     AliMUONChamber*   iChamber;
485     AliSegmentation*  seg;
486     iChamber = &(pMUON->Chamber(fChamber));
487     seg=iChamber->SegmentationModel(icat);
488     Float_t zpos=iChamber->Z();
489     Float_t r=iChamber->ROuter();
490     
491     TMarker3DBox *marker;
492     if (icat == 1) {
493         for (Int_t j=0; j<seg->Npy(); j++) {
494             Float_t y0;
495             y0=j*seg->Dpy()-seg->Dpy()/2.;
496             for (seg->FirstPad(0.,y0,0,300,0.); 
497                  seg->MorePads();
498                  seg->NextPad())
499             {
500                 if (seg->ISector()==0) continue;
501                 Float_t x,y,z;
502                 seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
503                 Float_t dpx=seg->Dpx(seg->ISector())/2;
504                 Float_t dpy=seg->Dpy(seg->ISector())/2;
505                 marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
506                 marker->SetLineColor(seg->ISector()+1);
507                 marker->SetFillStyle(1001);
508                 marker->SetFillColor(0);
509                 marker->Draw();
510             }
511         }
512     } else {
513         for (Int_t j=0; j<250; j++) {
514             Float_t x0=j*seg->Dpx();
515             Float_t y0=TMath::Sqrt(r*r-x0*x0);
516             
517             for (seg->FirstPad(x0,0,0,0,y0); 
518                  seg->MorePads();
519                  seg->NextPad())
520             {
521                 if (seg->ISector()==0) continue;
522                 
523                 Float_t x,y,z;
524                 seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
525                 Float_t dpx=seg->Dpx(seg->ISector())/2;
526                 Float_t dpy=seg->Dpy(seg->ISector())/2;
527                 marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
528                 marker->SetLineColor(seg->ISector()+1);
529                 marker->SetFillStyle(1001);
530                 marker->SetFillColor(0);
531                 marker->Draw();
532             }
533         }
534     }
535 }
536
537 //_____________________________________________________________________________
538 void AliMUONDisplay::DrawClusters()
539 {
540 //    Draw clusters for MUON chambers
541
542     Int_t ndigits, digit;
543     TObjArray *points;
544     AliMUONPoints *pm;
545
546       
547     fClustersCuts = 0;
548     points = Points();
549     if (!points) return;
550     ndigits = points->GetEntriesFast();
551     for (digit=0;digit<ndigits;digit++){
552         pm = (AliMUONPoints*)points->UncheckedAt(digit);
553         if (!pm) continue;
554         Float_t *pxyz;
555         pxyz=pm->GetP();
556         for (Int_t im=0;im<3;im++) {
557             TMarker3DBox *marker=pm->GetMarker(im);
558             if (marker)
559                 marker->Draw();
560         }
561         pm->Draw();
562         fClustersCuts +=pm->GetN();
563     }
564 }
565
566 //_____________________________________________________________________________
567 void AliMUONDisplay::DrawHits()
568 {
569 //    Draw hits for MUON chambers
570
571     LoadHits(fChamber);
572
573     Int_t ntracks, track;
574     TObjArray *points;
575     AliMUONPoints *pm;
576     
577     fHitsCuts = 0;
578     points = Phits();
579     if (!points) return;
580     ntracks = points->GetEntriesFast();
581     for (track=0;track<ntracks;track++) {
582         pm = (AliMUONPoints*)points->UncheckedAt(track);
583         if (!pm) continue;
584         pm->Draw();
585         fHitsCuts += pm->GetN();
586     }
587 }
588
589
590 //_____________________________________________________________________________
591 void AliMUONDisplay::DrawCoG()
592 {
593 //    Draw hits for MUON chambers
594     if (!fDrawCoG) return;
595     if (fChamber > 10) return;
596     LoadCoG(fChamber,fCathode);
597     
598     Int_t ncog, icog;
599     TObjArray *points;
600     AliMUONPoints *pm;
601
602     points = Rpoints();
603     if (!points) return;
604     ncog = points->GetEntriesFast();
605     for (icog=0;icog<ncog;icog++) {
606         pm = (AliMUONPoints*)points->UncheckedAt(icog);
607         if (!pm) continue;
608         pm->Draw();
609     }
610 }
611 //_____________________________________________________________________________
612
613 void AliMUONDisplay::DrawTitle(Option_t *option)
614 {
615 //    Draw the event title
616
617     Float_t xmin = gPad->GetX1();
618     Float_t xmax = gPad->GetX2();
619     Float_t ymin = gPad->GetY1();
620     Float_t ymax = gPad->GetY2();
621     Float_t dx   = xmax-xmin;
622     Float_t dy   = ymax-ymin;
623     
624     if (strlen(option) == 0) {
625         TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
626 //      title->SetTextSize(0.023932);
627         title->SetTextSize(0.02);
628         title->SetBit(kCanDelete);
629         title->SetFillColor(42);
630         title->Draw();
631         char ptitle[100];
632         sprintf(ptitle, "Alice event:%d Run:%d Chamber:%d Cathode:%d",
633                 gAlice->GetHeader()->GetEvent(),
634                 gAlice->GetHeader()->GetRun(),
635                 fChamber,
636                 fCathode);
637         title->AddText(ptitle);
638         Int_t nparticles = gAlice->Particles()->GetEntriesFast();
639         sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",
640                 nparticles, fHitsCuts,fClustersCuts);
641         title->AddText(ptitle);
642     } else {
643         TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
644         label->SetBit(kCanDelete);
645         label->SetFillColor(42);
646         label->Draw();
647     }
648 }
649
650 //_____________________________________________________________________________
651 void AliMUONDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
652 {
653 //    Draw a view of MUON clusters
654     printf("\n Draw View");
655     
656     gPad->SetCursor(kWatch);
657     // gPad->SetFillColor(39);
658     gPad->SetFillColor(1);
659     gPad->Clear();
660     // gPad->SetFillColor(39);
661     gPad->SetFillColor(1);
662     
663
664     Int_t iret=0;
665     TView *view = new TView(1);
666     
667     Float_t range = fRrange*fRangeSlider->GetMaximum();
668     view->SetRange(-range,-range,-range,range, range, range);
669     // zoom back to full scale only if DrawView not called from NextCathode
670     if (!fNextCathode) {
671         fZoomX0[0] = -1;
672         fZoomY0[0] = -1;
673         fZoomX1[0] =  1;
674         fZoomY1[0] =  1;
675         fZooms = 0;
676     }
677
678 // Display MUON Chamber Geometry
679     char nodeName[7];
680     sprintf(nodeName,"MUON%d",100+fChamber);
681     
682     TNode *node1=gAlice->GetGeometry()->GetNode(nodeName);
683     if (node1) node1->Draw("same");  
684 //add clusters to the pad
685     DrawClusters();
686     DrawHits();
687     DrawCoG();
688 //     DrawSegmentation();
689     // add itself to the list (must be last)
690     AppendPad();
691     view->SetView(phi, theta, psi, iret);
692 }
693
694
695 //______________________________________________________________________________
696 void AliMUONDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
697 {
698 //  Execute action corresponding to the mouse event
699
700     static Float_t x0, y0, x1, y1;
701     
702     static Int_t pxold, pyold;
703     static Int_t px0, py0;
704     static Int_t linedrawn;
705     Float_t temp;
706     
707     if (px == 0 && py == 0) { //when called by sliders
708         if (event == kButton1Up) {
709             Draw();
710         }
711         return;
712     }
713     if (!fZoomMode && gPad->GetView()) {
714         gPad->GetView()->ExecuteRotateView(event, px, py);
715         return;
716     }
717
718     // something to zoom ?
719     gPad->SetCursor(kCross);
720     
721     switch (event) {
722
723     case kButton1Down:
724         gVirtualX->SetLineColor(-1);
725         gPad->TAttLine::Modify();  //Change line attributes only if necessary
726         x0 = gPad->AbsPixeltoX(px);
727         y0 = gPad->AbsPixeltoY(py);
728         px0   = px; py0   = py;
729         pxold = px; pyold = py;
730         linedrawn = 0;
731         return;
732         
733     case kButton1Motion:
734         if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
735         pxold = px;
736         pyold = py;
737         linedrawn = 1;
738         gVirtualX->DrawBox(px0, py0, pxold, pyold,  TVirtualX::kHollow);
739         return;
740         
741     case kButton1Up:
742         gPad->GetCanvas()->FeedbackMode(kFALSE);
743         if (px == px0) return;
744         if (py == py0) return;
745         x1 = gPad->AbsPixeltoX(px);
746         y1 = gPad->AbsPixeltoY(py);
747         
748         if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
749         if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
750         gPad->Range(x0,y0,x1,y1);
751         if (fZooms < AliMUONConstants::MaxZoom()-1) {
752             fZooms++;
753             fZoomX0[fZooms] = x0;
754             fZoomY0[fZooms] = y0;
755             fZoomX1[fZooms] = x1;
756             fZoomY1[fZooms] = y1;
757         }
758         gPad->Modified(kTRUE);
759         return;
760     }
761 }
762  
763 //___________________________________________
764 void AliMUONDisplay::LoadDigits(Int_t chamber, Int_t cathode)
765 {
766 // Read digits info and store x,y,z info in arrays fPoints
767 // Loop on all detectors
768
769     if (chamber > 14) return;
770     printf(" chamber %d \n",chamber);
771     fChamber = chamber;
772     fCathode = cathode;
773     
774     ResetPoints();
775     
776     AliMUON *pMUON  =     (AliMUON*)gAlice->GetModule("MUON");
777     AliMUONChamber*       iChamber;
778     AliSegmentation*      segmentation;
779     AliMUONResponse*      response;
780
781     TClonesArray *muonDigits  = pMUON->GetMUONData()->Digits(chamber-1,0);
782     if (muonDigits == 0) return;
783
784 //     gAlice->ResetDigits();
785     Int_t nent = 0;
786  
787    if (gAlice->TreeD()) {
788      nent = (Int_t) gAlice->TreeD()->GetEntries();
789      printf(" entries %d \n", nent);
790      //     gAlice->TreeD()->GetEvent(nent-2+cathode-1);
791      gAlice->TreeD()->GetEvent(cathode-1);
792     }
793     
794     Int_t ndigits = muonDigits->GetEntriesFast();
795     if (ndigits == 0) return;
796     if (fPoints == 0) fPoints = new TObjArray(ndigits);
797     
798     iChamber = &(pMUON->Chamber(chamber-1));
799
800     segmentation = iChamber->SegmentationModel(cathode);
801     response     = iChamber->ResponseModel();
802     Float_t zpos = iChamber->Z();
803
804     AliMUONDigit  *mdig;
805     AliMUONPoints *points  = 0;
806     TMarker3DBox  *marker  = 0;
807     //
808     //loop over all digits and store their position
809     
810     Int_t npoints  = 1;
811     Float_t adcmax = 1024;
812     if (response) adcmax = response->MaxAdc();
813
814     for (Int_t digit = 0; digit < ndigits; digit++) {
815         mdig    = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
816         if (mdig->Cathode() != cathode-1) continue;
817
818         //
819         // First get all needed parameters
820         //
821         Int_t charge = mdig->Signal();
822         Int_t index  = Int_t(TMath::Log(charge)/(TMath::Log(adcmax)/22));
823         Int_t color  = 261+index;
824         Int_t colorTrigger = 2;   
825         if (color > 282) color = 282;
826
827         if (chamber > 10) { // trigger chamber 
828             Int_t sumCharge = 0;
829             for (Int_t icharge = 0; icharge < 10; icharge++) {
830                 sumCharge = sumCharge+mdig->TrackCharge(icharge);
831             }
832             Int_t testCharge = sumCharge-(Int_t(sumCharge/10))*10;
833             if(sumCharge <= 10 || testCharge > 0) {
834                 colorTrigger = color; 
835             } else {
836                 colorTrigger = 5; 
837             }
838         }
839
840         // get the center of the pad - add on x and y half of pad size
841         Float_t xpad, ypad, zpad;
842         segmentation->GetPadC(mdig->PadX(), mdig->PadY(), xpad, ypad, zpad);
843         
844         Int_t   isec = segmentation->Sector(mdig->PadX(), mdig->PadY());
845         Float_t  dpx = segmentation->Dpx(isec)/2;
846         Float_t  dpy = segmentation->Dpy(isec)/2;
847 //
848 //      segmentation->Dump();
849         
850         //
851         // Then set the objects
852         //
853         points = new AliMUONPoints(npoints);
854         fPoints->AddAt(points,digit);
855         if (chamber > 10) {
856             points->SetMarkerColor(colorTrigger);
857         } else {  
858             points->SetMarkerColor(color);
859         }
860         points->SetMarkerStyle(21);
861         points->SetMarkerSize(0.5);
862         points->SetParticle(-1);
863         points->SetHitIndex(-1);
864         points->SetTrackIndex(-1);
865         points->SetDigitIndex(digit);
866         points->SetPoint(0,xpad,ypad,zpos);     
867
868         Int_t lineColor = (zpad-zpos > 0) ? 2:3;
869         marker=new TMarker3DBox(xpad,ypad,zpos,dpx,dpy,0,0,0);
870
871             
872         marker->SetLineColor(lineColor);
873         marker->SetFillStyle(1001);
874         marker->SetFillColor(color);
875         marker->SetRefObject((TObject*)points);
876         points->Set3DMarker(0, marker);
877     }
878 }
879 //___________________________________________
880 void AliMUONDisplay::LoadCoG(Int_t chamber, Int_t /*cathode*/)
881 {
882 // Read raw clusters info and store x,y,z info in arrays fRpoints
883 // Loop on all detectors
884
885     if (chamber > 10) return;
886     
887     ResetRpoints();
888     
889     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
890     AliMUONChamber*  iChamber;
891     
892     TClonesArray *muonRawClusters  = pMUON->GetMUONData()->RawClusters(chamber-1);
893     if (muonRawClusters == 0) return;
894
895 //     pMUON->ResetRawClusters();
896
897     Int_t nent = 0;
898     if (gAlice->TreeR()) {
899         nent=(Int_t)gAlice->TreeR()->GetEntries();
900         gAlice->TreeR()->GetEvent(0);
901     }
902     
903     Int_t nrawcl = muonRawClusters->GetEntriesFast();
904     if (nrawcl == 0) return;
905     if (fRpoints == 0) fRpoints = new TObjArray(nrawcl);
906     
907     iChamber = &(pMUON->Chamber(chamber-1));
908     Float_t zpos=iChamber->Z();  
909     AliMUONRawCluster  *mRaw;
910     AliMUONPoints *points = 0;
911     //
912     //loop over all raw clusters and store their position
913     points = new AliMUONPoints(nrawcl);
914     for (Int_t iraw=0;iraw<nrawcl;iraw++) {
915         mRaw   = (AliMUONRawCluster*)muonRawClusters->UncheckedAt(iraw);
916         fRpoints->AddAt(points,iraw);
917         points->SetMarkerColor(51);
918         points->SetMarkerStyle(2);
919         points->SetMarkerSize(1.);
920         points->SetParticle(-1);
921         points->SetHitIndex(-1);
922         points->SetTrackIndex(-1);
923         points->SetDigitIndex(-1);
924         points->SetPoint(iraw,mRaw->fX[0],mRaw->fY[0],zpos);
925     }
926 }
927 //___________________________________________
928 void AliMUONDisplay::LoadHits(Int_t chamber)
929 {
930 // Read hits info and store x,y,z info in arrays fPhits
931 // Loop on all detectors
932
933     if (chamber > 14) return;
934     Int_t track;
935
936     fChamber=chamber;
937  
938     ResetPhits();
939     
940     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
941     AliMUONChamber*  iChamber;
942
943     iChamber = &(pMUON->Chamber(chamber-1));
944     Float_t zpos=iChamber->Z();
945
946     Int_t ntracks = (Int_t)pMUON->TreeH()->GetEntries(); //skowron
947     Int_t nthits  = 0;
948     for (track = 0; track < ntracks; track++) {
949         gAlice->ResetHits();
950         pMUON->TreeH()->GetEvent(track);//skowron
951         TClonesArray *muonHits  = pMUON->Hits();
952         if (muonHits == 0) return;
953         nthits += muonHits->GetEntriesFast();
954     } 
955     if (fPhits == 0) fPhits = new TObjArray(nthits);
956     Int_t nhold=0;
957     for (track=0; track<ntracks;track++) {
958         gAlice->ResetHits();
959         pMUON->TreeH()->GetEvent(track);//skowron
960         TClonesArray *muonHits  = pMUON->Hits();
961         if (muonHits == 0) return;
962         Int_t nhits = muonHits->GetEntriesFast();
963         if (nhits == 0) continue;
964         AliMUONHit *mHit;
965         AliMUONPoints *points = 0;
966         Int_t npoints=1;
967         for (Int_t hit=0;hit<nhits;hit++) {
968             mHit = (AliMUONHit*)muonHits->UncheckedAt(hit);
969             Int_t nch  = mHit->Chamber();              // chamber number
970             if (nch != chamber) continue;
971             //
972             // Retrieve info and set the objects
973             //
974             points = new AliMUONPoints(npoints);
975             fPhits->AddAt(points,nhold+hit);
976             points->SetMarkerColor(kRed);
977             points->SetMarkerStyle(5);
978             points->SetMarkerSize(1.);
979             points->SetParticle(mHit->Track());
980             points->SetHitIndex(hit);
981             points->SetTrackIndex(track);
982             points->SetDigitIndex(-1);
983             points->SetPoint(0,mHit->X(),mHit->Y(),zpos);
984         }
985         nhold+=nhits;
986     }
987 }
988
989 //_____________________________________________________________________________
990 void AliMUONDisplay::Paint(Option_t *)
991 {
992 //    Paint miscellaneous items
993 }
994
995 //_____________________________________________________________________________
996 void AliMUONDisplay::SetPickMode()
997 {
998 // Set parameters for pick mode.
999 // 
1000     fZoomMode = 0;
1001
1002     fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
1003     fTrigPad->Modified();
1004 }
1005
1006 //_____________________________________________________________________________
1007 void AliMUONDisplay::SetZoomMode()
1008 {
1009 //  Set parameters for zoom mode
1010     fZoomMode = 1;
1011     
1012     fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
1013     fTrigPad->Modified();
1014 }
1015
1016 //_____________________________________________________________________________
1017 void AliMUONDisplay::NextChamber(Int_t delta)
1018 {
1019   // to go from chamber to next chamber if delta = 1
1020   // or previous chamber otherwise
1021     if (delta == 1) {
1022         if (fChamber < AliMUONConstants::NCh()) fChamber++;
1023     } else {
1024         if (fChamber > 1) fChamber--;
1025     }
1026     if (!fPad) return;
1027     fPad->Clear();
1028     LoadDigits(fChamber, fCathode);
1029     Draw();
1030 }
1031
1032 //_____________________________________________________________________________
1033 void AliMUONDisplay::NextCathode()
1034 {
1035     // to switch to other cathode plane
1036     if (!fPad) return;
1037     fPad->Clear();
1038     if (fCathode == 1) {
1039         LoadDigits(fChamber, 2);        
1040     } else {
1041         LoadDigits(fChamber, 1);
1042     }
1043     fNextCathode = kTRUE; // to keep the same zoom
1044     Draw();
1045     fNextCathode = kFALSE;
1046     TPad *pad = (TPad*)gPad->GetPadSave();
1047     pad->Range(fZoomX0[fZooms], fZoomY0[fZooms],
1048                fZoomX1[fZooms], fZoomY1[fZooms]);
1049     pad->Modified();
1050     fPad->cd();
1051     DrawTitle();
1052 }
1053
1054 //_____________________________________________________________________________
1055 void AliMUONDisplay::Trigger()
1056 {
1057   // returns Trigger Decision for current event
1058   AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
1059   decision->Trigger(); 
1060 }
1061
1062
1063 //_____________________________________________________________________________
1064 void AliMUONDisplay::SetChamberAndCathode(Int_t chamber, Int_t cathode)
1065 {
1066 // Set chamber and cathode number
1067    fChamber = chamber;
1068    fCathode = cathode;
1069
1070    if (!fPad) return;
1071    fPad->Clear();
1072    LoadDigits(chamber,cathode);
1073    Draw();
1074 }
1075
1076 void AliMUONDisplay::SetEvent(Int_t newevent)
1077 {
1078 // Chose event 
1079     gAlice->GetEvent(newevent);
1080     fEvent=newevent;
1081     if (!gAlice->TreeD()) return; 
1082     if (!fPad) return;
1083     fPad->Clear();
1084     LoadDigits(fChamber,fCathode);
1085     Draw();
1086 }
1087
1088 //_____________________________________________________________________________
1089 void AliMUONDisplay::SetRange(Float_t rrange, Float_t zrange)
1090 {
1091 // Set view range along R and Z
1092     fRrange = rrange;
1093     fZrange = zrange;
1094
1095     if (!fPad) return;
1096     fPad->Clear();
1097     Draw();
1098 }
1099    
1100 //_____________________________________________________________________________
1101 void AliMUONDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
1102 {
1103 //  change viewing angles for current event
1104
1105     fPad->cd();
1106     fPhi   = phi;
1107     fTheta = theta;
1108     fPsi   = psi;
1109     Int_t iret = 0;
1110     
1111     TView *view = gPad->GetView();
1112     if (view) view->SetView(fPhi, fTheta, fPsi, iret);
1113     else      Draw();
1114     gPad->Modified();
1115 }
1116
1117 //_____________________________________________________________________________
1118 void AliMUONDisplay::ShowNextEvent(Int_t delta)
1119 {
1120 //  Display (current event_number + delta)
1121 //    delta =  1  shown next event
1122 //    delta = -1 show previous event
1123     if (delta) {
1124         gAlice->Clear();
1125         Int_t currentEvent = gAlice->GetHeader()->GetEvent();
1126         Int_t newEvent     = currentEvent + delta;
1127         gAlice->GetEvent(newEvent);
1128         fEvent=newEvent;
1129         if (!gAlice->TreeD()) return; 
1130     }
1131     
1132     LoadDigits(fChamber, fCathode);
1133     fPad->cd(); 
1134     Draw();
1135 }
1136
1137 //______________________________________________________________________________
1138 void AliMUONDisplay::UnZoom()
1139 {
1140 // Unzoom 
1141     if (fZooms <= 0) return;
1142     fZooms--;
1143     TPad *pad = (TPad*)gPad->GetPadSave();
1144     pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
1145     pad->Modified();
1146 }
1147
1148 //_____________________________________________________________________________
1149 void AliMUONDisplay::ResetPoints()
1150 {
1151     //
1152     // Reset array of points
1153     //
1154     if (fPoints) {
1155         fPoints->Delete();
1156         delete fPoints;
1157         fPoints = 0;
1158     }
1159 }
1160 //_____________________________________________________________________________
1161 void AliMUONDisplay::ResetPhits()
1162 {
1163     //
1164     // Reset array of points
1165     //
1166     if (fPhits) {
1167         fPhits->Delete();
1168         delete fPhits;
1169         fPhits = 0;
1170     }
1171 }
1172 //_____________________________________________________________________________
1173 void AliMUONDisplay::ResetRpoints()
1174 {
1175   //
1176   // Reset array of points
1177   //
1178     if (fRpoints) {
1179         fRpoints->Delete();
1180         delete fRpoints;
1181         fRpoints = 0;
1182     }
1183 }
1184
1185 AliMUONDisplay & AliMUONDisplay::operator = (const AliMUONDisplay &)
1186 {
1187 // Dummy assignment operator
1188     return *this;
1189 }
1190
1191
1192
1193
1194
1195
1196
1197
1198