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"
20 #include "AliMUONPainterGroup.h"
21 #include "AliMUONVPainter.h"
23 #include <Riostream.h>
24 #include <TObjArray.h>
26 #include <TObjString.h>
28 ///\class AliMUONPainterMatrix
30 /// Matrix of AliMUONVPainter
32 ///\author Laurent Aphecetche, Subatech
35 ClassImp(AliMUONPainterMatrix)
38 //_____________________________________________________________________________
39 AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
45 fPainters(new TObjArray(fNx*fNy)),
50 fPainters->SetOwner(kTRUE);
53 fAttributes.SetSingle(kFALSE);
56 fName = NameIt(name,fAttributes);
59 //_____________________________________________________________________________
60 AliMUONPainterMatrix::~AliMUONPainterMatrix()
66 //_____________________________________________________________________________
68 AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
70 /// Adopt a given painter
71 fPainters->AddLast(painter);
75 //_____________________________________________________________________________
77 AliMUONPainterMatrix::UpdateAttributes()
79 /// Update our attributes (using our painters' attributes)
81 Bool_t cathode0(kFALSE);
82 Bool_t cathode1(kFALSE);
83 Bool_t bending(kFALSE);
84 Bool_t nonbending(kFALSE);
87 Bool_t cathplaneexclusive(kFALSE);
88 Bool_t cathplanedisabled(kFALSE);
90 for ( Int_t i = 0; i < Size(); ++i )
92 AliMUONAttPainter att = Painter(i)->Attributes();
94 if ( att.IsCathodeDefined() )
96 if ( att.IsCathode0() ) cathode0 = kTRUE;
97 if ( att.IsCathode1() ) cathode1 = kTRUE;
100 if ( att.IsPlaneDefined() )
102 if ( att.IsBendingPlane() ) bending = kTRUE;
103 if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
106 if ( att.IsFrontView() ) front = kTRUE;
107 if ( att.IsBackView() ) back = kTRUE;
109 if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
111 if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
114 fAttributes.SetCathode(cathode0,cathode1);
115 fAttributes.SetPlane(bending,nonbending);
116 fAttributes.SetViewPoint(front,back);
117 fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
118 fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
120 fName = NameIt(fBasename,fAttributes);
123 //_____________________________________________________________________________
125 AliMUONPainterMatrix::NameIt(const TString& basename, const AliMUONAttPainter& att)
128 TString name(basename);
136 //_____________________________________________________________________________
138 AliMUONPainterMatrix::ComputeDataRange()
140 /// Compute the data range spanned by the painters in this matrix
142 Double_t dataMin(FLT_MAX);
143 Double_t dataMax(-FLT_MAX);
144 Bool_t atLeastOnePlotter(kFALSE);
146 for ( Int_t i = 0; i < Size(); ++i )
148 AliMUONVPainter* p = Painter(i);
149 AliMUONPainterGroup* g = p->PlotterGroup();
151 Double_t min(FLT_MAX);
152 Double_t max(-FLT_MAX);
156 atLeastOnePlotter = kTRUE;
157 g->ComputeDataRange(min,max);
160 dataMin = TMath::Min(min,dataMin);
161 dataMax = TMath::Max(max,dataMax);
165 AliDebug(1,Form("painter %s group %s min %e max %e dataMin,Max=%7.3f,%7.3f",
167 g ? g->Type() : "none",
172 if ( dataMin > dataMax && atLeastOnePlotter )
174 AliError(Form("data min %e > max %e : setting both to 0.0",
176 dataMin = dataMax = 0.0;
179 AliDebug(1,Form("Final dataMin,Max=%7.3f,%7.3f",dataMin,dataMax));
181 SetDataRange(dataMin,dataMax);
184 //_____________________________________________________________________________
186 AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName,
187 void* destObject, const char* destMethod)
189 /// Connect our painters
191 for ( Int_t i = 0; i < Size(); ++i )
193 Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
197 //_____________________________________________________________________________
199 AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
201 /// Get the data range spanned by the painters in this matrix
206 for ( Int_t i = 0; i < Size(); ++i )
208 AliMUONVPainter* p = Painter(i);
211 AliMUONPainterGroup* g = p->PlotterGroup();
214 dataMin = TMath::Min(dataMin,g->DataMin());
215 dataMax = TMath::Max(dataMax,g->DataMax());
221 //_____________________________________________________________________________
223 AliMUONPainterMatrix::GetTypes(TObjArray& types) const
225 /// Get the types of the painters in this matrix
227 types.SetOwner(kTRUE);
230 for ( Int_t i = 0; i < Size(); ++i )
232 AliMUONVPainter* p = Painter(i);
237 while ( ( o = next() ) )
239 if ( ! types.FindObject(o) )
241 types.AddLast(o->Clone());
247 //_____________________________________________________________________________
249 AliMUONPainterMatrix::Painter(Int_t index) const
251 /// Get a given painter
253 if ( index <= fPainters->GetLast() )
255 return static_cast<AliMUONVPainter*>(fPainters->At(index));
260 //_____________________________________________________________________________
262 AliMUONPainterMatrix::Data() const
265 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
266 return ( group ? group->Data() : 0x0 );
269 //_____________________________________________________________________________
271 AliMUONPainterMatrix::DataPattern() const
273 /// Return our data pattern
274 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
275 return ( group ? group->Type() : "" );
278 //_____________________________________________________________________________
280 AliMUONPainterMatrix::DataIndex() const
282 /// Return our data index
283 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
284 return ( group ? group->DataIndex() : -1 );
287 //_____________________________________________________________________________
289 AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
292 /// Set the data to be plotted
294 for ( Int_t i = 0; i < Size(); ++i )
296 AliMUONVPainter* painter = Painter(i);
297 painter->SetData(pattern,d,indexInData);
301 //_____________________________________________________________________________
303 AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
305 /// Set the data range
307 for ( Int_t i = 0; i < Size(); ++i )
309 AliMUONVPainter* p = Painter(i);
310 AliMUONPainterGroup* g = p->PlotterGroup();
313 g->SetDataRange(dataMin,dataMax);
318 //_____________________________________________________________________________
320 AliMUONPainterMatrix::Size() const
322 /// Return the number of painters we actually handle
323 return fPainters->GetLast()+1;
326 //_____________________________________________________________________________
328 AliMUONPainterMatrix::Print(Option_t*) const
331 cout << "Basename=" << fBasename.Data() << " Name=" << fName.Data()
332 << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << endl;
335 //_____________________________________________________________________________
337 //AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
339 // /// Change painters' attributes
341 // AliWarning("Implement me !");
343 // // for ( Int_t i = 0; i < Size(); ++i )
345 // // Painter(i)->SetAttributes(attributes);
349 //_____________________________________________________________________________
350 AliMUONPainterMatrix*
351 AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
353 /// Clone with given attributes
355 AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename().Data(),Nx(),Ny());
357 for ( Int_t i = 0; i < Size(); ++i )
359 AliMUONVPainter* oldPainter = Painter(i);
361 AliMUONVPainter* newPainter(0x0);
363 newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
370 newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
371 clone->Adopt(newPainter);
375 AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
376 oldPainter->ClassName(),
385 //_____________________________________________________________________________
387 AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
389 /// Calls SetOutlined for all our painters
391 for ( Int_t i = 0; i < Size(); ++i )
393 Painter(i)->SetOutlined(pattern,value);
397 //_____________________________________________________________________________
399 AliMUONPainterMatrix::SetResponder(const char* pattern)
401 /// Calls SetResponder for all our painters
402 for ( Int_t i = 0; i < Size(); ++i )
404 Painter(i)->SetResponder(pattern);
408 //_____________________________________________________________________________
410 AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
412 /// Normalize attributes
416 for ( Int_t i = 0; i < Size() && a.IsValid(); ++i )
418 a = Painter(i)->Validate(att);