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
46 ClassImp(AliMUONPainterMatrix)
49 //_____________________________________________________________________________
50 AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
56 fPainters(new TObjArray(fNx*fNy)),
61 fPainters->SetOwner(kTRUE);
64 fAttributes.SetSingle(kFALSE);
68 //_____________________________________________________________________________
69 AliMUONPainterMatrix::~AliMUONPainterMatrix()
75 //_____________________________________________________________________________
77 AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
79 /// Adopt a given painter
80 fPainters->AddLast(painter);
84 //_____________________________________________________________________________
86 AliMUONPainterMatrix::UpdateAttributes()
88 /// Update our attributes (using our painters' attributes)
90 Bool_t cathode0(kFALSE);
91 Bool_t cathode1(kFALSE);
92 Bool_t bending(kFALSE);
93 Bool_t nonbending(kFALSE);
96 Bool_t cathplaneexclusive(kFALSE);
97 Bool_t cathplanedisabled(kFALSE);
99 for ( Int_t i = 0; i < Size(); ++i )
101 AliMUONAttPainter att = Painter(i)->Attributes();
103 if ( att.IsCathodeDefined() )
105 if ( att.IsCathode0() ) cathode0 = kTRUE;
106 if ( att.IsCathode1() ) cathode1 = kTRUE;
109 if ( att.IsPlaneDefined() )
111 if ( att.IsBendingPlane() ) bending = kTRUE;
112 if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
115 if ( att.IsFrontView() ) front = kTRUE;
116 if ( att.IsBackView() ) back = kTRUE;
118 if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
120 if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
123 fAttributes.SetCathode(cathode0,cathode1);
124 fAttributes.SetPlane(bending,nonbending);
125 fAttributes.SetViewPoint(front,back);
126 fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
127 fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
130 //_____________________________________________________________________________
132 AliMUONPainterMatrix::Name() const
136 return NameIt(fWhatname.Data(),fBasename.Data(),fAttributes).Data();
139 //_____________________________________________________________________________
141 AliMUONPainterMatrix::NameIt(const char* whatname, const char* basename, const AliMUONAttPainter& att)
144 if ( strlen(whatname) > 0 )
146 return Form("%s-%s-%s",whatname,basename,att.Name().Data());
150 return Form("noda-%s-%s",basename,att.Name().Data());
154 //_____________________________________________________________________________
156 AliMUONPainterMatrix::ComputeDataRange()
158 /// Compute the data range spanned by the painters in this matrix
160 Double_t dataMin(FLT_MAX);
161 Double_t dataMax(-FLT_MAX);
162 Bool_t atLeastOnePlotter(kFALSE);
164 for ( Int_t i = 0; i < Size(); ++i )
166 AliMUONVPainter* p = Painter(i);
167 AliMUONPainterGroup* g = p->PlotterGroup();
169 Double_t min(FLT_MAX);
170 Double_t max(-FLT_MAX);
174 atLeastOnePlotter = kTRUE;
175 g->ComputeDataRange(min,max);
178 dataMin = TMath::Min(min,dataMin);
179 dataMax = TMath::Max(max,dataMax);
183 AliDebug(1,Form("painter %s group %s min %e max %e dataMin,Max=%7.3f,%7.3f",
185 g ? g->Type() : "none",
190 if ( dataMin > dataMax && atLeastOnePlotter )
192 AliError(Form("data min %e > max %e : setting both to 0.0",
194 dataMin = dataMax = 0.0;
197 AliDebug(1,Form("Final dataMin,Max=%7.3f,%7.3f",dataMin,dataMax));
199 SetDataRange(dataMin,dataMax);
202 //_____________________________________________________________________________
204 AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName,
205 void* destObject, const char* destMethod)
207 /// Connect our painters
209 for ( Int_t i = 0; i < Size(); ++i )
211 Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
215 //_____________________________________________________________________________
217 AliMUONPainterMatrix::CreateCanvas(Int_t x, Int_t y, Int_t w, Int_t h)
219 /// Generate a canvas to show the painter matrix.
221 /// Layout is the following :
223 /// ----------------------------------------------------
224 /// | title describing what is plotted |
225 /// ----------------------------------------------------
231 /// | painter themselves | color |
235 /// ----------------------------------------------------
238 Int_t mw = ( w <= 0 ? TMath::Nint(gClient->GetDisplayWidth()*0.9) : w );
239 Int_t mh = ( h <= 0 ? TMath::Nint(gClient->GetDisplayHeight()*0.9) : h );
241 TString name(Name());
243 TCanvas* d = new TCanvas(name.Data(),name.Data(),x,y,mw,mh);
245 TVirtualPad* pTitle = new TPad(Form("%s-title",name.Data()),Form("%s-title",name.Data()),0,0.9,1.0,0.99);
251 TPaveLabel* text = new TPaveLabel(0,0,1,1,"");
252 text->SetFillStyle(0);
253 text->SetFillColor(0);
254 text->SetTextColor(4);
255 text->SetBorderSize(0);
257 text->SetLabel(name.Data());
263 TVirtualPad* pMatrix = new TPad(Form("%s-matrix",name.Data()),Form("%s-matrix",name.Data()),0,0,0.9,0.89);
272 TVirtualPad* pColor = new TPad(Form("%s-color",name.Data()),Form("%s-color",name.Data()),0.91,0.01,0.99,0.89);
274 pColor->Range(0,0,1,1);
280 Int_t ndivisions(20);
282 Double_t rangeXmin(0.1);
283 Double_t rangeXmax(0.9);
287 GetDataRange(ymin,ymax);
292 Double_t step = (max-min)/ndivisions;
294 Double_t hsize = 1.0/(ndivisions+2);
298 for ( Int_t i = -1; i < ndivisions+1; ++i )
300 Double_t value = max - (min + step*i);
302 Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
304 Bool_t limit(kFALSE);
309 Double_t yvalue(0.0);
317 else if ( i == ndivisions )
326 if ( TMath::Abs(yvalue) < 1E5 )
328 label = Form("%s %7.2f",sign.Data(),yvalue);
332 label = Form("%s %e",sign.Data(),yvalue);
336 TPaveLabel* box = new TPaveLabel(rangeXmin,TMath::Max(0.001,ypos-hsize),rangeXmax,ypos,label.Data(),"");
340 box->SetFillColor(color);
341 box->SetTextColor( i == -1 ? 0 : 1 );
342 box->SetBorderSize(1);
343 box->SetLineColor(1);
347 d->SetEditable(kFALSE);
352 //_____________________________________________________________________________
354 AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
356 /// Get the data range spanned by the painters in this matrix
361 for ( Int_t i = 0; i < Size(); ++i )
363 AliMUONVPainter* p = Painter(i);
366 AliMUONPainterGroup* g = p->PlotterGroup();
369 dataMin = TMath::Min(dataMin,g->DataMin());
370 dataMax = TMath::Max(dataMax,g->DataMax());
376 //_____________________________________________________________________________
378 AliMUONPainterMatrix::GetTypes(TObjArray& types) const
380 /// Get the types of the painters in this matrix
382 types.SetOwner(kTRUE);
385 for ( Int_t i = 0; i < Size(); ++i )
387 AliMUONVPainter* p = Painter(i);
392 while ( ( o = next() ) )
394 if ( ! types.FindObject(o) )
396 types.AddLast(o->Clone());
403 //_____________________________________________________________________________
405 AliMUONPainterMatrix::Draw(Option_t*)
407 /// Append our painters to the current pad
411 gROOT->MakeDefCanvas();
414 TVirtualPad* pad = gPad;
416 gPad->Divide(Nx(),Ny());
418 for ( Int_t i = 0; i < Size(); ++i )
420 AliMUONVPainter* painter = Painter(i);
428 //_____________________________________________________________________________
430 AliMUONPainterMatrix::Painter(Int_t index) const
432 /// Get a given painter
434 if ( index <= fPainters->GetLast() )
436 return static_cast<AliMUONVPainter*>(fPainters->At(index));
441 //_____________________________________________________________________________
443 AliMUONPainterMatrix::Data() const
446 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
447 return ( group ? group->Data() : 0x0 );
450 //_____________________________________________________________________________
452 AliMUONPainterMatrix::DataPattern() const
454 /// Return our data pattern
455 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
456 return ( group ? group->Type() : "" );
459 //_____________________________________________________________________________
461 AliMUONPainterMatrix::DataIndex() const
463 /// Return our data index
464 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
465 return ( group ? group->DataIndex() : -1 );
468 //_____________________________________________________________________________
470 AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
473 /// Set the data to be plotted
475 for ( Int_t i = 0; i < Size(); ++i )
477 AliMUONVPainter* painter = Painter(i);
478 painter->SetData(pattern,d,indexInData);
483 fWhatname = Form("%s-%s",d->GetName(),d->DimensionName(indexInData).Data());
491 //_____________________________________________________________________________
493 AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
495 /// Set the data range
497 for ( Int_t i = 0; i < Size(); ++i )
499 AliMUONVPainter* p = Painter(i);
500 AliMUONPainterGroup* g = p->PlotterGroup();
503 g->SetDataRange(dataMin,dataMax);
508 //_____________________________________________________________________________
510 AliMUONPainterMatrix::Size() const
512 /// Return the number of painters we actually handle
513 return fPainters->GetLast()+1;
516 //_____________________________________________________________________________
518 AliMUONPainterMatrix::Print(Option_t*) const
521 cout << "Whatname=" << fWhatname.Data() << "Basename=" << fBasename.Data()
522 << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << endl;
525 //_____________________________________________________________________________
527 //AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
529 // /// Change painters' attributes
531 // AliWarning("Implement me !");
533 // // for ( Int_t i = 0; i < Size(); ++i )
535 // // Painter(i)->SetAttributes(attributes);
539 //_____________________________________________________________________________
540 AliMUONPainterMatrix*
541 AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
543 /// Clone with given attributes
545 AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename(),Nx(),Ny());
547 for ( Int_t i = 0; i < Size(); ++i )
549 AliMUONVPainter* oldPainter = Painter(i);
551 AliMUONVPainter* newPainter(0x0);
553 newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
560 newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
561 clone->Adopt(newPainter);
565 AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
566 oldPainter->ClassName(),
575 //_____________________________________________________________________________
577 AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
579 /// Calls SetOutlined for all our painters
581 for ( Int_t i = 0; i < Size(); ++i )
583 Painter(i)->SetOutlined(pattern,value);
587 //_____________________________________________________________________________
589 AliMUONPainterMatrix::SetResponder(const char* pattern)
591 /// Calls SetResponder for all our painters
592 for ( Int_t i = 0; i < Size(); ++i )
594 Painter(i)->SetResponder(pattern);
598 //_____________________________________________________________________________
600 AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
602 /// Normalize attributes
606 for ( Int_t i = 0; i < Size() && a.IsValid(); ++i )
608 a = Painter(i)->Validate(att);