1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPainterMatrix.h"
21 #include "AliMUONPainterGroup.h"
22 #include "AliMUONPainterHelper.h"
23 #include "AliMUONVPainter.h"
24 #include "AliMUONVTrackerData.h"
27 #include "TPaveLabel.h"
28 #include <Riostream.h>
31 #include <TObjArray.h>
32 #include <TObjString.h>
34 #include <TVirtualPad.h>
37 ///\class AliMUONPainterMatrix
39 /// Matrix of AliMUONVPainter
41 ///\author Laurent Aphecetche, Subatech
44 ClassImp(AliMUONPainterMatrix)
47 //_____________________________________________________________________________
48 AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
54 fPainters(new TObjArray(fNx*fNy)),
59 fPainters->SetOwner(kTRUE);
62 fAttributes.SetSingle(kFALSE);
66 //_____________________________________________________________________________
67 AliMUONPainterMatrix::~AliMUONPainterMatrix()
73 //_____________________________________________________________________________
75 AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
77 /// Adopt a given painter
78 fPainters->AddLast(painter);
82 //_____________________________________________________________________________
84 AliMUONPainterMatrix::UpdateAttributes()
86 /// Update our attributes (using our painters' attributes)
88 Bool_t cathode0(kFALSE);
89 Bool_t cathode1(kFALSE);
90 Bool_t bending(kFALSE);
91 Bool_t nonbending(kFALSE);
94 Bool_t cathplaneexclusive(kFALSE);
95 Bool_t cathplanedisabled(kFALSE);
97 for ( Int_t i = 0; i < Size(); ++i )
99 AliMUONAttPainter att = Painter(i)->Attributes();
101 if ( att.IsCathodeDefined() )
103 if ( att.IsCathode0() ) cathode0 = kTRUE;
104 if ( att.IsCathode1() ) cathode1 = kTRUE;
107 if ( att.IsPlaneDefined() )
109 if ( att.IsBendingPlane() ) bending = kTRUE;
110 if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
113 if ( att.IsFrontView() ) front = kTRUE;
114 if ( att.IsBackView() ) back = kTRUE;
116 if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
118 if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
121 fAttributes.SetCathode(cathode0,cathode1);
122 fAttributes.SetPlane(bending,nonbending);
123 fAttributes.SetViewPoint(front,back);
124 fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
125 fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
128 //_____________________________________________________________________________
130 AliMUONPainterMatrix::Name() const
134 return NameIt(fWhatname.Data(),fBasename.Data(),fAttributes).Data();
137 //_____________________________________________________________________________
139 AliMUONPainterMatrix::NameIt(const char* whatname, const char* basename, const AliMUONAttPainter& att)
142 if ( strlen(whatname) > 0 )
144 return Form("%s-%s-%s",whatname,basename,att.Name().Data());
148 return Form("noda-%s-%s",basename,att.Name().Data());
152 //_____________________________________________________________________________
154 AliMUONPainterMatrix::ComputeDataRange()
156 /// Compute the data range spanned by the painters in this matrix
158 Double_t dataMin(FLT_MAX);
159 Double_t dataMax(-FLT_MAX);
160 Bool_t atLeastOnePlotter(kFALSE);
162 for ( Int_t i = 0; i < Size(); ++i )
164 AliMUONVPainter* p = Painter(i);
165 AliMUONPainterGroup* g = p->PlotterGroup();
167 Double_t min(FLT_MAX);
168 Double_t max(-FLT_MAX);
172 atLeastOnePlotter = kTRUE;
173 g->ComputeDataRange(min,max);
176 dataMin = TMath::Min(min,dataMin);
177 dataMax = TMath::Max(max,dataMax);
181 AliDebug(1,Form("painter %s group %s min %e max %e dataMin,Max=%7.3f,%7.3f",
183 g ? g->Type() : "none",
188 if ( dataMin > dataMax && atLeastOnePlotter )
190 AliError(Form("data min %e > max %e : setting both to 0.0",
192 dataMin = dataMax = 0.0;
195 AliDebug(1,Form("Final dataMin,Max=%7.3f,%7.3f",dataMin,dataMax));
197 SetDataRange(dataMin,dataMax);
200 //_____________________________________________________________________________
202 AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName,
203 void* destObject, const char* destMethod)
205 /// Connect our painters
207 for ( Int_t i = 0; i < Size(); ++i )
209 Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
213 //_____________________________________________________________________________
215 AliMUONPainterMatrix::CreateCanvas(Int_t x, Int_t y, Int_t w, Int_t h)
217 /// Generate a canvas to show the painter matrix.
219 /// Layout is the following :
221 /// ----------------------------------------------------
222 /// | title describing what is plotted |
223 /// ----------------------------------------------------
229 /// | painter themselves | color |
233 /// ----------------------------------------------------
236 Int_t mw = ( w <= 0 ? TMath::Nint(gClient->GetDisplayWidth()*0.9) : w );
237 Int_t mh = ( h <= 0 ? TMath::Nint(gClient->GetDisplayHeight()*0.9) : h );
239 TString name(Name());
241 TCanvas* d = new TCanvas(name.Data(),name.Data(),x,y,mw,mh);
243 TVirtualPad* pTitle = new TPad(Form("%s-title",name.Data()),Form("%s-title",name.Data()),0,0.9,1.0,0.99);
249 TPaveLabel* text = new TPaveLabel(0,0,1,1,"");
250 text->SetFillStyle(0);
251 text->SetFillColor(0);
252 text->SetTextColor(4);
253 text->SetBorderSize(0);
255 text->SetLabel(name.Data());
261 TVirtualPad* pMatrix = new TPad(Form("%s-matrix",name.Data()),Form("%s-matrix",name.Data()),0,0,0.9,0.89);
270 TVirtualPad* pColor = new TPad(Form("%s-color",name.Data()),Form("%s-color",name.Data()),0.91,0.01,0.99,0.89);
272 pColor->Range(0,0,1,1);
278 Int_t ndivisions(20);
280 Double_t rangeXmin(0.1);
281 Double_t rangeXmax(0.9);
285 GetDataRange(ymin,ymax);
290 Double_t step = (max-min)/ndivisions;
292 Double_t hsize = 1.0/(ndivisions+2);
296 for ( Int_t i = -1; i < ndivisions+1; ++i )
298 Double_t value = max - (min + step*i);
300 Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
302 Bool_t limit(kFALSE);
307 Double_t yvalue(0.0);
315 else if ( i == ndivisions )
324 if ( TMath::Abs(yvalue) < 1E5 )
326 label = Form("%s %7.2f",sign.Data(),yvalue);
330 label = Form("%s %e",sign.Data(),yvalue);
334 TPaveLabel* box = new TPaveLabel(rangeXmin,TMath::Max(0.001,ypos-hsize),rangeXmax,ypos,label.Data(),"");
338 box->SetFillColor(color);
339 box->SetTextColor( i == -1 ? 0 : 1 );
340 box->SetBorderSize(1);
341 box->SetLineColor(1);
345 d->SetEditable(kFALSE);
350 //_____________________________________________________________________________
352 AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
354 /// Get the data range spanned by the painters in this matrix
359 for ( Int_t i = 0; i < Size(); ++i )
361 AliMUONVPainter* p = Painter(i);
364 AliMUONPainterGroup* g = p->PlotterGroup();
367 dataMin = TMath::Min(dataMin,g->DataMin());
368 dataMax = TMath::Max(dataMax,g->DataMax());
374 //_____________________________________________________________________________
376 AliMUONPainterMatrix::GetTypes(TObjArray& types) const
378 /// Get the types of the painters in this matrix
380 types.SetOwner(kTRUE);
383 for ( Int_t i = 0; i < Size(); ++i )
385 AliMUONVPainter* p = Painter(i);
390 while ( ( o = next() ) )
392 if ( ! types.FindObject(o) )
394 types.AddLast(o->Clone());
401 //_____________________________________________________________________________
403 AliMUONPainterMatrix::Draw(Option_t*)
405 /// Append our painters to the current pad
409 gROOT->MakeDefCanvas();
412 TVirtualPad* pad = gPad;
414 gPad->Divide(Nx(),Ny());
416 for ( Int_t i = 0; i < Size(); ++i )
418 AliMUONVPainter* painter = Painter(i);
426 //_____________________________________________________________________________
428 AliMUONPainterMatrix::Painter(Int_t index) const
430 /// Get a given painter
432 if ( index <= fPainters->GetLast() )
434 return static_cast<AliMUONVPainter*>(fPainters->At(index));
439 //_____________________________________________________________________________
441 AliMUONPainterMatrix::Data() const
444 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
445 return ( group ? group->Data() : 0x0 );
448 //_____________________________________________________________________________
450 AliMUONPainterMatrix::DataPattern() const
452 /// Return our data pattern
453 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
454 return ( group ? group->Type() : "" );
457 //_____________________________________________________________________________
459 AliMUONPainterMatrix::DataIndex() const
461 /// Return our data index
462 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
463 return ( group ? group->DataIndex() : -1 );
466 //_____________________________________________________________________________
468 AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
471 /// Set the data to be plotted
473 for ( Int_t i = 0; i < Size(); ++i )
475 AliMUONVPainter* painter = Painter(i);
476 painter->SetData(pattern,d,indexInData);
481 fWhatname = Form("%s-%s",d->GetName(),d->DimensionName(indexInData).Data());
489 //_____________________________________________________________________________
491 AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
493 /// Set the data range
495 for ( Int_t i = 0; i < Size(); ++i )
497 AliMUONVPainter* p = Painter(i);
498 AliMUONPainterGroup* g = p->PlotterGroup();
501 g->SetDataRange(dataMin,dataMax);
506 //_____________________________________________________________________________
508 AliMUONPainterMatrix::Size() const
510 /// Return the number of painters we actually handle
511 return fPainters->GetLast()+1;
514 //_____________________________________________________________________________
516 AliMUONPainterMatrix::Print(Option_t*) const
519 cout << "Whatname=" << fWhatname.Data() << "Basename=" << fBasename.Data()
520 << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << endl;
523 //_____________________________________________________________________________
525 //AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
527 // /// Change painters' attributes
529 // AliWarning("Implement me !");
531 // // for ( Int_t i = 0; i < Size(); ++i )
533 // // Painter(i)->SetAttributes(attributes);
537 //_____________________________________________________________________________
538 AliMUONPainterMatrix*
539 AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
541 /// Clone with given attributes
543 AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename(),Nx(),Ny());
545 for ( Int_t i = 0; i < Size(); ++i )
547 AliMUONVPainter* oldPainter = Painter(i);
549 AliMUONVPainter* newPainter(0x0);
551 newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
558 newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
559 clone->Adopt(newPainter);
563 AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
564 oldPainter->ClassName(),
573 //_____________________________________________________________________________
575 AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
577 /// Calls SetOutlined for all our painters
579 for ( Int_t i = 0; i < Size(); ++i )
581 Painter(i)->SetOutlined(pattern,value);
585 //_____________________________________________________________________________
587 AliMUONPainterMatrix::SetResponder(const char* pattern)
589 /// Calls SetResponder for all our painters
590 for ( Int_t i = 0; i < Size(); ++i )
592 Painter(i)->SetResponder(pattern);
596 //_____________________________________________________________________________
598 AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
600 /// Normalize attributes
604 for ( Int_t i = 0; i < Size() && a.IsValid(); ++i )
606 a = Painter(i)->Validate(att);