]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterMatrix.cxx
First big commit of the mchview program and its accompanying library,
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterMatrix.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 #include "AliMUONPainterMatrix.h"
19
20 #include "AliMUONPainterGroup.h"
21 #include "AliMUONVPainter.h"
22 #include "AliLog.h"
23 #include <Riostream.h>
24 #include <TObjArray.h>
25 #include <float.h>
26 #include <TObjString.h>
27
28 ///\class AliMUONPainterMatrix
29 ///
30 /// Matrix of AliMUONVPainter
31 ///
32 ///\author Laurent Aphecetche, Subatech
33
34 ///\cond CLASSIMP
35 ClassImp(AliMUONPainterMatrix)
36 ///\endcond
37
38 //_____________________________________________________________________________
39 AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
40 : TObject(),
41   fBasename(name),
42   fName(""),
43   fNx(nx),
44   fNy(ny),
45   fPainters(new TObjArray(fNx*fNy)),
46   fAttributes()
47 {
48     /// ctor
49
50     fPainters->SetOwner(kTRUE);
51     if ( fNx*fNy > 1 ) 
52     {
53       fAttributes.SetSingle(kFALSE);
54     }
55     
56     fName = NameIt(name,fAttributes);
57 }
58
59 //_____________________________________________________________________________
60 AliMUONPainterMatrix::~AliMUONPainterMatrix()
61 {
62   /// dtor
63   delete fPainters;
64 }
65
66 //_____________________________________________________________________________
67 void 
68 AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
69 {
70   /// Adopt a given painter
71   fPainters->AddLast(painter);
72   UpdateAttributes();
73 }
74
75 //_____________________________________________________________________________
76 void
77 AliMUONPainterMatrix::UpdateAttributes()
78 {
79   /// Update our attributes (using our painters' attributes)
80   
81   Bool_t cathode0(kFALSE);
82   Bool_t cathode1(kFALSE);
83   Bool_t bending(kFALSE);
84   Bool_t nonbending(kFALSE);
85   Bool_t front(kFALSE);
86   Bool_t back(kFALSE);
87   Bool_t cathplaneexclusive(kFALSE);
88   Bool_t cathplanedisabled(kFALSE);
89   
90   for ( Int_t i = 0; i < Size(); ++i )
91   {
92     AliMUONAttPainter att = Painter(i)->Attributes();
93     
94     if ( att.IsCathodeDefined() ) 
95     {
96       if ( att.IsCathode0() ) cathode0 = kTRUE;
97       if ( att.IsCathode1() ) cathode1 = kTRUE;
98     }
99
100     if ( att.IsPlaneDefined() ) 
101     {
102       if ( att.IsBendingPlane() ) bending = kTRUE;
103       if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
104     }
105     
106     if ( att.IsFrontView() ) front = kTRUE;
107     if ( att.IsBackView() ) back = kTRUE;
108     
109     if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
110     
111     if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
112   }
113   
114   fAttributes.SetCathode(cathode0,cathode1);
115   fAttributes.SetPlane(bending,nonbending);
116   fAttributes.SetViewPoint(front,back);
117   fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
118   fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
119   
120   fName = NameIt(fBasename,fAttributes);
121 }
122
123 //_____________________________________________________________________________
124 TString
125 AliMUONPainterMatrix::NameIt(const TString& basename, const AliMUONAttPainter& att)
126 {
127   /// Build a name 
128   TString name(basename);
129   
130   name += "-";
131   name += att.Name();
132   
133   return name;
134 }
135
136 //_____________________________________________________________________________
137 void 
138 AliMUONPainterMatrix::ComputeDataRange()
139 {
140   /// Compute the data range spanned by the painters in this matrix
141   
142   Double_t dataMin(FLT_MAX);
143   Double_t dataMax(-FLT_MAX);
144   Bool_t atLeastOnePlotter(kFALSE);
145   
146   for ( Int_t i = 0; i < Size(); ++i ) 
147   {
148     AliMUONVPainter* p = Painter(i);
149     AliMUONPainterGroup* g = p->PlotterGroup();
150
151     Double_t min(FLT_MAX);
152     Double_t max(-FLT_MAX);
153
154     if ( g ) 
155     {
156       atLeastOnePlotter = kTRUE;
157       g->ComputeDataRange(min,max);
158       if ( min <= max ) 
159       {
160         dataMin = TMath::Min(min,dataMin);
161         dataMax = TMath::Max(max,dataMax);
162       }
163     }
164
165     AliDebug(1,Form("painter %s group %s min %e max %e dataMin,Max=%7.3f,%7.3f",
166                     p->GetName(),
167                     g ? g->Type() : "none",
168                     min,max,
169                     dataMin,dataMax));
170   }
171
172   if ( dataMin > dataMax && atLeastOnePlotter ) 
173   {
174     AliError(Form("data min %e > max %e : setting both to 0.0",
175                     dataMin,dataMax));
176     dataMin = dataMax = 0.0;
177   }
178   
179   AliDebug(1,Form("Final dataMin,Max=%7.3f,%7.3f",dataMin,dataMax));
180   
181   SetDataRange(dataMin,dataMax);
182 }
183
184 //_____________________________________________________________________________
185 void 
186 AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName, 
187                               void* destObject, const char* destMethod)
188 {
189   /// Connect our painters
190   
191   for ( Int_t i = 0; i < Size(); ++i )
192   {
193     Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
194   }
195 }
196
197 //_____________________________________________________________________________
198 void
199 AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
200 {
201   /// Get the data range spanned by the painters in this matrix
202   
203   dataMin=FLT_MAX;
204   dataMax=-FLT_MAX;
205   
206   for ( Int_t i = 0; i < Size(); ++i ) 
207   {
208     AliMUONVPainter* p = Painter(i);
209     if ( p )
210     {
211       AliMUONPainterGroup* g = p->PlotterGroup();
212       if ( g ) 
213       {
214         dataMin = TMath::Min(dataMin,g->DataMin());
215         dataMax = TMath::Max(dataMax,g->DataMax());
216       }
217     }
218   }
219 }
220
221 //_____________________________________________________________________________
222 void 
223 AliMUONPainterMatrix::GetTypes(TObjArray& types) const
224 {
225   /// Get the types of the painters in this matrix
226   
227   types.SetOwner(kTRUE);
228   types.Clear();
229   
230   for ( Int_t i = 0; i < Size(); ++i ) 
231   {
232     AliMUONVPainter* p = Painter(i);
233     TObjArray ptypes;
234     p->GetTypes(ptypes);
235     TIter next(&ptypes);
236     TObject* o;
237     while ( ( o = next() ) )
238     {
239       if ( ! types.FindObject(o) )
240       {
241         types.AddLast(o->Clone());
242       }
243     }
244   }  
245 }
246
247 //_____________________________________________________________________________
248 AliMUONVPainter* 
249 AliMUONPainterMatrix::Painter(Int_t index) const
250 {
251   /// Get a given painter
252   
253   if ( index <= fPainters->GetLast() ) 
254   {
255     return static_cast<AliMUONVPainter*>(fPainters->At(index));
256   }
257   return 0x0;
258 }
259
260 //_____________________________________________________________________________
261 AliMUONVTrackerData* 
262 AliMUONPainterMatrix::Data() const
263 {
264   AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
265   return ( group ? group->Data() : 0x0 );
266 }
267
268 //_____________________________________________________________________________
269 TString 
270 AliMUONPainterMatrix::DataPattern() const
271 {
272   AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
273   return ( group ? group->Type() : "" );
274 }
275
276 //_____________________________________________________________________________
277 Int_t 
278 AliMUONPainterMatrix::DataIndex() const
279 {
280   AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
281   return ( group ? group->DataIndex() : -1 );
282 }
283
284 //_____________________________________________________________________________
285 void
286 AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
287                               Int_t indexInData)
288 {
289   /// Set the data to be plotted
290   
291   for ( Int_t i = 0; i < Size(); ++i )
292   {
293     AliMUONVPainter* painter = Painter(i);
294     painter->SetData(pattern,d,indexInData);
295   }
296 }
297
298 //_____________________________________________________________________________
299 void
300 AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
301 {
302   /// Set the data range
303   
304   for ( Int_t i = 0; i < Size(); ++i ) 
305   {
306     AliMUONVPainter* p = Painter(i);
307     AliMUONPainterGroup* g = p->PlotterGroup();
308     if ( g ) 
309     {
310       g->SetDataRange(dataMin,dataMax);
311     }
312   }       
313 }
314
315 //_____________________________________________________________________________
316 Int_t 
317 AliMUONPainterMatrix::Size() const
318 {
319   /// Return the number of painters we actually handle
320   return fPainters->GetLast()+1;
321 }
322
323 //_____________________________________________________________________________
324 void
325 AliMUONPainterMatrix::Print(Option_t*) const
326 {
327   /// Printout
328   cout << "Basename=" << fBasename.Data() << " Name=" << fName.Data() 
329   << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << endl;
330 }
331
332 //_____________________________________________________________________________
333 //void 
334 //AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
335 //{
336 //  /// Change painters' attributes
337 //  
338 //  AliWarning("Implement me !");
339 //  
340 //  //  for ( Int_t i = 0; i < Size(); ++i ) 
341 //  //  {
342 //  //    Painter(i)->SetAttributes(attributes);
343 //  //  }
344 //}
345
346 //_____________________________________________________________________________
347 AliMUONPainterMatrix*
348 AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
349 {
350   /// Clone with given attributes
351   
352   AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename().Data(),Nx(),Ny());
353
354   for ( Int_t i = 0; i < Size(); ++i ) 
355   {
356     AliMUONVPainter* oldPainter = Painter(i);
357     
358     AliMUONVPainter* newPainter(0x0);
359     
360     newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
361                                                 attributes,
362                                                 oldPainter->ID0(),
363                                                 oldPainter->ID1());
364     
365     if (newPainter)
366     {
367       newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
368       clone->Adopt(newPainter);
369     }
370     else
371     {
372       AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
373                     oldPainter->ClassName(),
374                     oldPainter->ID0(),
375                     oldPainter->ID1()));
376     }
377   }
378   
379   return clone;
380 }
381
382 //_____________________________________________________________________________
383 void
384 AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
385 {
386   /// Calls SetOutlined for all our painters
387
388   for ( Int_t i = 0; i < Size(); ++i ) 
389   {
390     Painter(i)->SetOutlined(pattern,value);
391   }
392 }
393
394 //_____________________________________________________________________________
395 void
396 AliMUONPainterMatrix::SetResponder(const char* pattern)
397 {
398   /// Calls SetResponder for all our painters
399   for ( Int_t i = 0; i < Size(); ++i ) 
400   {
401     Painter(i)->SetResponder(pattern);
402   }
403 }
404
405 //_____________________________________________________________________________
406 AliMUONAttPainter
407 AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
408 {
409   /// Normalize attributes
410
411   AliMUONAttPainter a;
412   
413   for ( Int_t i = 0; i < Size() && a.IsValid(); ++i ) 
414   {
415     a = Painter(i)->Validate(att);
416   }
417   return a;
418 }
419
420