Line data Source code
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 "AliLog.h"
21 : #include "AliMUONPainterGroup.h"
22 : #include "AliMUONPainterHelper.h"
23 : #include "AliMUONVPainter.h"
24 : #include "AliMUONVTrackerData.h"
25 : #include "TCanvas.h"
26 : #include "TGClient.h"
27 : #include "TPaveLabel.h"
28 : #include <Riostream.h>
29 : #include <TBox.h>
30 : #include <TMath.h>
31 : #include <TObjArray.h>
32 : #include <TObjString.h>
33 : #include <TROOT.h>
34 : #include <TVirtualPad.h>
35 : #include <float.h>
36 : #include "AliMUONPainterEnv.h"
37 : #include <cassert>
38 :
39 : ///\class AliMUONPainterMatrix
40 : ///
41 : /// Matrix of AliMUONVPainter
42 : ///
43 : ///\author Laurent Aphecetche, Subatech
44 :
45 : ///\cond CLASSIMP
46 12 : ClassImp(AliMUONPainterMatrix)
47 : ///\endcond
48 :
49 : //_____________________________________________________________________________
50 : AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
51 0 : : TObject(),
52 0 : fBasename(name),
53 0 : fWhatname(""),
54 0 : fNx(nx),
55 0 : fNy(ny),
56 0 : fPainters(new TObjArray(fNx*fNy)),
57 0 : fAttributes(),
58 0 : fName()
59 0 : {
60 : /// ctor
61 :
62 0 : fPainters->SetOwner(kTRUE);
63 0 : if ( fNx*fNy > 1 )
64 : {
65 0 : fAttributes.SetSingle(kFALSE);
66 : }
67 0 : SetName();
68 0 : }
69 :
70 : //_____________________________________________________________________________
71 : AliMUONPainterMatrix::~AliMUONPainterMatrix()
72 0 : {
73 : /// dtor
74 0 : delete fPainters;
75 0 : }
76 :
77 : //_____________________________________________________________________________
78 : void
79 : AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
80 : {
81 : /// Adopt a given painter
82 0 : fPainters->AddLast(painter);
83 0 : UpdateAttributes();
84 0 : }
85 :
86 :
87 : //_____________________________________________________________________________
88 : AliMUONPainterMatrix*
89 : AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
90 : {
91 : /// Clone with given attributes
92 :
93 0 : AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename(),Nx(),Ny());
94 :
95 0 : for ( Int_t i = 0; i < Size(); ++i )
96 : {
97 0 : AliMUONVPainter* oldPainter = Painter(i);
98 :
99 : AliMUONVPainter* newPainter(0x0);
100 :
101 0 : newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
102 : attributes,
103 0 : oldPainter->ID0(),
104 0 : oldPainter->ID1());
105 :
106 0 : if (newPainter)
107 : {
108 0 : newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
109 0 : clone->Adopt(newPainter);
110 0 : }
111 : else
112 : {
113 0 : AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
114 : oldPainter->ClassName(),
115 : oldPainter->ID0(),
116 : oldPainter->ID1()));
117 : }
118 : }
119 :
120 0 : return clone;
121 0 : }
122 :
123 : //_____________________________________________________________________________
124 : void
125 : AliMUONPainterMatrix::ComputeDataRange()
126 : {
127 : /// Compute the data range spanned by the painters in this matrix
128 :
129 : Double_t dataMin(FLT_MAX);
130 : Double_t dataMax(-FLT_MAX);
131 : Bool_t atLeastOnePlotter(kFALSE);
132 :
133 0 : for ( Int_t i = 0; i < Size(); ++i )
134 : {
135 0 : AliMUONVPainter* p = Painter(i);
136 0 : AliMUONPainterGroup* g = p->PlotterGroup();
137 :
138 0 : Double_t min(FLT_MAX);
139 0 : Double_t max(-FLT_MAX);
140 :
141 0 : if ( g )
142 : {
143 : atLeastOnePlotter = kTRUE;
144 0 : g->ComputeDataRange(min,max);
145 0 : if ( min <= max )
146 : {
147 0 : dataMin = TMath::Min(min,dataMin);
148 0 : dataMax = TMath::Max(max,dataMax);
149 0 : }
150 : }
151 0 : }
152 :
153 0 : if ( dataMin > dataMax && atLeastOnePlotter )
154 : {
155 0 : AliError(Form("data min %e > max %e : setting both to 0.0",
156 : dataMin,dataMax));
157 : dataMin = dataMax = 0.0;
158 0 : }
159 :
160 0 : SetDataRange(dataMin,dataMax);
161 0 : }
162 :
163 : //_____________________________________________________________________________
164 : void
165 : AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName,
166 : void* destObject, const char* destMethod)
167 : {
168 : /// Connect our painters
169 :
170 0 : for ( Int_t i = 0; i < Size(); ++i )
171 : {
172 0 : Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
173 : }
174 0 : }
175 :
176 : //_____________________________________________________________________________
177 : TCanvas*
178 : AliMUONPainterMatrix::CreateCanvas(Int_t x, Int_t y, Int_t w, Int_t h)
179 : {
180 : /// Generate a canvas to show the painter matrix.
181 : ///
182 : /// Layout is the following :
183 : ///
184 : /// ----------------------------------------------------
185 : /// | title describing what is plotted |
186 : /// ----------------------------------------------------
187 : /// | | |
188 : /// | | |
189 : /// | | |
190 : /// | | |
191 : /// | | |
192 : /// | painter themselves | color |
193 : /// | | range |
194 : /// | | |
195 : /// | | |
196 : /// ----------------------------------------------------
197 : ///
198 :
199 0 : Int_t mw = ( w <= 0 ? TMath::Nint(gClient->GetDisplayWidth()*0.9) : w );
200 0 : Int_t mh = ( h <= 0 ? TMath::Nint(gClient->GetDisplayHeight()*0.9) : h );
201 :
202 0 : TString name(GetName());
203 :
204 0 : TCanvas* d = new TCanvas(name.Data(),name.Data(),x,y,mw,mh);
205 :
206 0 : TVirtualPad* pTitle = new TPad(Form("%s-title",name.Data()),Form("%s-title",name.Data()),0,0.9,1.0,0.99);
207 :
208 0 : pTitle->Draw();
209 :
210 0 : pTitle->cd();
211 :
212 0 : TPaveLabel* text = new TPaveLabel(0,0,1,1,"");
213 0 : text->SetFillStyle(0);
214 0 : text->SetFillColor(0);
215 0 : text->SetTextColor(4);
216 0 : text->SetBorderSize(0);
217 :
218 0 : text->SetLabel(name.Data());
219 :
220 0 : text->Draw();
221 :
222 0 : d->cd();
223 :
224 0 : TVirtualPad* pMatrix = new TPad(Form("%s-matrix",name.Data()),Form("%s-matrix",name.Data()),0,0,0.9,0.89);
225 :
226 0 : pMatrix->Draw();
227 0 : pMatrix->cd();
228 :
229 0 : Draw();
230 :
231 0 : d->cd();
232 :
233 0 : TVirtualPad* pColor = new TPad(Form("%s-color",name.Data()),Form("%s-color",name.Data()),0.91,0.01,0.99,0.89);
234 :
235 0 : pColor->Range(0,0,1,1);
236 :
237 0 : pColor->Draw();
238 :
239 0 : pColor->cd();
240 :
241 : Int_t ndivisions(20);
242 :
243 : Double_t rangeXmin(0.1);
244 : Double_t rangeXmax(0.9);
245 :
246 0 : Double_t ymin, ymax;
247 :
248 0 : GetDataRange(ymin,ymax);
249 :
250 : Double_t min(0.0);
251 : Double_t max(1.0);
252 :
253 0 : Double_t step = (max-min)/ndivisions;
254 :
255 0 : Double_t hsize = 1.0/(ndivisions+2);
256 :
257 : Double_t ypos = 1.0;
258 :
259 0 : for ( Int_t i = -1; i < ndivisions+1; ++i )
260 : {
261 0 : Double_t value = max - (min + step*i);
262 :
263 0 : Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
264 :
265 : Bool_t limit(kFALSE);
266 :
267 0 : TString label;
268 0 : TString sign;
269 :
270 : Double_t yvalue(0.0);
271 :
272 0 : if ( i == -1 )
273 : {
274 0 : yvalue = ymax;
275 : limit = kTRUE;
276 0 : sign = ">";
277 : }
278 0 : else if ( i == ndivisions )
279 : {
280 0 : yvalue = ymin;
281 : limit = kTRUE;
282 0 : sign = "<=";
283 : }
284 :
285 0 : if (limit)
286 : {
287 0 : if ( TMath::Abs(yvalue) < 1E5 )
288 : {
289 0 : label = Form("%s %7.2f",sign.Data(),yvalue);
290 : }
291 : else
292 : {
293 0 : label = Form("%s %e",sign.Data(),yvalue);
294 : }
295 : }
296 :
297 0 : TPaveLabel* box = new TPaveLabel(rangeXmin,TMath::Max(0.001,ypos-hsize),rangeXmax,ypos,label.Data(),"");
298 :
299 : ypos -= hsize;
300 :
301 0 : box->SetFillColor(color);
302 0 : box->SetTextColor( i == -1 ? 0 : 1 );
303 0 : box->SetBorderSize(1);
304 0 : box->SetLineColor(1);
305 0 : box->Draw();
306 0 : }
307 :
308 0 : d->SetEditable(kFALSE);
309 :
310 : return d;
311 0 : }
312 :
313 : //_____________________________________________________________________________
314 : void
315 : AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
316 : {
317 : /// Get the data range spanned by the painters in this matrix
318 :
319 0 : dataMin=FLT_MAX;
320 0 : dataMax=-FLT_MAX;
321 :
322 0 : for ( Int_t i = 0; i < Size(); ++i )
323 : {
324 0 : AliMUONVPainter* p = Painter(i);
325 0 : if ( p )
326 : {
327 0 : AliMUONPainterGroup* g = p->PlotterGroup();
328 0 : if ( g )
329 : {
330 0 : dataMin = TMath::Min(dataMin,g->DataMin());
331 0 : dataMax = TMath::Max(dataMax,g->DataMax());
332 0 : }
333 0 : }
334 : }
335 0 : }
336 :
337 : //_____________________________________________________________________________
338 : void
339 : AliMUONPainterMatrix::GetTypes(TObjArray& types) const
340 : {
341 : /// Get the types of the painters in this matrix
342 :
343 0 : types.SetOwner(kTRUE);
344 0 : types.Clear();
345 :
346 0 : for ( Int_t i = 0; i < Size(); ++i )
347 : {
348 0 : AliMUONVPainter* p = Painter(i);
349 0 : TObjArray ptypes;
350 0 : p->GetTypes(ptypes);
351 0 : TIter next(&ptypes);
352 : TObject* o;
353 0 : while ( ( o = next() ) )
354 : {
355 0 : if ( ! types.FindObject(o) )
356 : {
357 0 : types.AddLast(o->Clone());
358 : }
359 : }
360 0 : }
361 0 : }
362 :
363 :
364 : //_____________________________________________________________________________
365 : AliMUONVTrackerData*
366 : AliMUONPainterMatrix::Data() const
367 : {
368 : /// Return our data
369 0 : AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
370 0 : return ( group ? group->Data() : 0x0 );
371 : }
372 :
373 : //_____________________________________________________________________________
374 : TString
375 : AliMUONPainterMatrix::DataPattern() const
376 : {
377 : /// Return our data pattern
378 0 : AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
379 0 : return ( group ? group->Type() : "" );
380 0 : }
381 :
382 : //_____________________________________________________________________________
383 : Int_t
384 : AliMUONPainterMatrix::DataIndex() const
385 : {
386 : /// Return our data index
387 0 : AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
388 0 : return ( group ? group->DataIndex() : -1 );
389 : }
390 :
391 : //_____________________________________________________________________________
392 : void
393 : AliMUONPainterMatrix::Draw(Option_t*)
394 : {
395 : /// Append our painters to the current pad
396 :
397 0 : if (!gPad)
398 : {
399 0 : gROOT->MakeDefCanvas();
400 0 : }
401 :
402 0 : TVirtualPad* pad = gPad;
403 :
404 0 : gPad->Divide(Nx(),Ny());
405 :
406 0 : for ( Int_t i = 0; i < Size(); ++i )
407 : {
408 0 : AliMUONVPainter* painter = Painter(i);
409 0 : pad->cd(i+1);
410 0 : painter->Draw("R");
411 : }
412 :
413 0 : AppendPad("");
414 0 : }
415 :
416 : //_____________________________________________________________________________
417 : std::string
418 : AliMUONPainterMatrix::NameIt(const char* whatname, const char* basename, const AliMUONAttPainter& att)
419 : {
420 : /// Build a name
421 0 : if ( strlen(whatname) > 0 )
422 : {
423 0 : return Form("%s-%s-%s",whatname,basename,att.GetName());
424 : }
425 : else
426 : {
427 0 : return Form("nodata-%s-%s",basename,att.GetName());
428 : }
429 0 : }
430 :
431 : //_____________________________________________________________________________
432 : AliMUONVPainter*
433 : AliMUONPainterMatrix::Painter(Int_t index) const
434 : {
435 : /// Get a given painter
436 :
437 0 : if ( index <= fPainters->GetLast() )
438 : {
439 0 : return static_cast<AliMUONVPainter*>(fPainters->At(index));
440 : }
441 0 : return 0x0;
442 0 : }
443 :
444 : //_____________________________________________________________________________
445 : void
446 : AliMUONPainterMatrix::Print(Option_t*) const
447 : {
448 : /// Printout
449 0 : std::cout << "Whatname=" << fWhatname.Data() << " Basename=" << fBasename.Data()
450 0 : << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << std::endl;
451 0 : }
452 :
453 : //_____________________________________________________________________________
454 : void
455 : AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
456 : Int_t indexInData)
457 : {
458 : /// Set the data to be plotted
459 :
460 0 : for ( Int_t i = 0; i < Size(); ++i )
461 : {
462 0 : AliMUONVPainter* painter = Painter(i);
463 0 : painter->SetData(pattern,d,indexInData);
464 : }
465 :
466 0 : if ( d )
467 : {
468 0 : fWhatname = Form("%s-%s",d->GetName(),d->DimensionName(indexInData).Data());
469 0 : }
470 : else
471 : {
472 0 : fWhatname = "";
473 : }
474 :
475 0 : SetName();
476 :
477 : // get the data source range, if any is given
478 :
479 0 : if ( d )
480 : {
481 0 : AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
482 :
483 0 : TString desc = env->DataSourceDescriptor(d->GetName());
484 0 : TString dimensionName = d->DimensionName(DataIndex());
485 :
486 0 : Double_t xmin,xmax;
487 :
488 0 : Bool_t ok = env->Ranges2DimensionRange(env->Descriptor2Ranges(desc),dimensionName.Data(),xmin,xmax);
489 :
490 0 : if (ok)
491 : {
492 0 : SetDataRange(xmin,xmax);
493 0 : env->Save();
494 : }
495 0 : }
496 0 : }
497 :
498 : //_____________________________________________________________________________
499 : void
500 : AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
501 : {
502 : /// Set the data range
503 :
504 0 : for ( Int_t i = 0; i < Size(); ++i )
505 : {
506 0 : AliMUONVPainter* p = Painter(i);
507 0 : AliMUONPainterGroup* g = p->PlotterGroup();
508 0 : if ( g )
509 : {
510 0 : g->SetDataRange(dataMin,dataMax);
511 0 : }
512 : }
513 :
514 0 : AliMUONVTrackerData* data = Data();
515 :
516 0 : if ( data )
517 : {
518 0 : AliMUONPainterEnv* env = AliMUONPainterHelper::Instance()->Env();
519 :
520 0 : TString dimensionName = data->DimensionName(DataIndex());
521 0 : env->SetDimensionRange(data->GetName(),dimensionName,dataMin,dataMax);
522 0 : }
523 :
524 0 : }
525 :
526 : //_____________________________________________________________________________
527 : void AliMUONPainterMatrix::SetName()
528 : {
529 : /// Build our name
530 : // fName = NameIt(fWhatname.Data(),fBasename.Data(),fAttributes);
531 0 : fName = "nodata";
532 :
533 0 : if ( fWhatname.Length() > 0 )
534 : {
535 0 : fName = fWhatname;
536 0 : }
537 0 : fName += "-";
538 0 : fName += fBasename;
539 0 : fName += "-";
540 0 : fName += fAttributes.GetName();
541 0 : }
542 :
543 :
544 : //_____________________________________________________________________________
545 : //void
546 : //AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
547 : //{
548 : // /// Change painters' attributes
549 : //
550 : // AliWarning("Implement me !");
551 : //
552 : // // for ( Int_t i = 0; i < Size(); ++i )
553 : // // {
554 : // // Painter(i)->SetAttributes(attributes);
555 : // // }
556 : //}
557 :
558 :
559 : //_____________________________________________________________________________
560 : void
561 : AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
562 : {
563 : /// Calls SetOutlined for all our painters
564 :
565 0 : for ( Int_t i = 0; i < Size(); ++i )
566 : {
567 0 : Painter(i)->SetOutlined(pattern,value);
568 : }
569 0 : }
570 :
571 : //_____________________________________________________________________________
572 : void
573 : AliMUONPainterMatrix::SetResponder(const char* pattern)
574 : {
575 : /// Calls SetResponder for all our painters
576 0 : for ( Int_t i = 0; i < Size(); ++i )
577 : {
578 0 : Painter(i)->SetResponder(pattern);
579 : }
580 0 : }
581 :
582 : //_____________________________________________________________________________
583 : Int_t
584 : AliMUONPainterMatrix::Size() const
585 : {
586 : /// Return the number of painters we actually handle
587 0 : return fPainters->GetLast()+1;
588 : }
589 :
590 : //_____________________________________________________________________________
591 : void
592 : AliMUONPainterMatrix::UpdateAttributes()
593 : {
594 : /// Update our attributes (using our painters' attributes)
595 :
596 : Bool_t cathode0(kFALSE);
597 : Bool_t cathode1(kFALSE);
598 : Bool_t bending(kFALSE);
599 : Bool_t nonbending(kFALSE);
600 : Bool_t front(kFALSE);
601 : Bool_t back(kFALSE);
602 : Bool_t cathplaneexclusive(kFALSE);
603 : Bool_t cathplanedisabled(kFALSE);
604 :
605 0 : for ( Int_t i = 0; i < Size(); ++i )
606 : {
607 0 : AliMUONAttPainter att = Painter(i)->Attributes();
608 :
609 0 : if ( att.IsCathodeDefined() )
610 : {
611 0 : if ( att.IsCathode0() ) cathode0 = kTRUE;
612 0 : if ( att.IsCathode1() ) cathode1 = kTRUE;
613 : }
614 :
615 0 : if ( att.IsPlaneDefined() )
616 : {
617 0 : if ( att.IsBendingPlane() ) bending = kTRUE;
618 0 : if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
619 : }
620 :
621 0 : if ( att.IsFrontView() ) front = kTRUE;
622 0 : if ( att.IsBackView() ) back = kTRUE;
623 :
624 0 : if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
625 :
626 0 : if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
627 0 : }
628 :
629 0 : fAttributes.SetCathode(cathode0,cathode1);
630 0 : fAttributes.SetPlane(bending,nonbending);
631 0 : fAttributes.SetViewPoint(front,back);
632 0 : fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
633 0 : fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
634 :
635 0 : SetName();
636 0 : }
637 :
638 : //_____________________________________________________________________________
639 : AliMUONAttPainter
640 : AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
641 : {
642 : /// Normalize attributes
643 :
644 0 : AliMUONAttPainter a;
645 :
646 0 : for ( Int_t i = 0; i < Size() && a.IsValid(); ++i )
647 : {
648 0 : a = Painter(i)->Validate(att);
649 : }
650 : return a;
651 0 : }
|