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