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