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