]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpIteratorPainter.cxx
Adding new libraries
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpIteratorPainter.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 "AliMpIteratorPainter.h"
19
20 #include "AliMpVPadIterator.h"
21 #include "AliMpPad.h"
22 #include "AliMpGraphContext.h"
23
24 #include "AliLog.h"
25
26 #include "TObjArray.h"
27 #include "TVirtualX.h"
28 #include "TVirtualPad.h"
29 #include "TVector2.h"
30 #include "TMath.h"
31
32 /// 
33 /// \class AliMpIteratorPainter
34 ///
35 /// A painter for a group of pads, which is defined by an iterator
36 ///
37 ///
38 /// \author L. Aphecetche
39
40 /// \cond CLASSIMP
41 ClassImp(AliMpIteratorPainter)
42 /// \endcond
43
44 //_____________________________________________________________________________
45 AliMpIteratorPainter::AliMpIteratorPainter(AliMpVPadIterator *it)
46 : AliMpVPainter(), fPads(new TObjArray), fPosition(), fDimensions()
47 {
48   /// Ctor. Iterator must not be null.
49   
50   //if (!it) throw;
51   if (!it) {
52     AliFatal("Iterator must not be null.");;
53   }  
54  
55   Double_t xmin(1E9), xmax(-1E9);
56   Double_t ymin(1E9), ymax(-1E9);
57   
58   fPads->SetOwner(kTRUE);
59   it->First();
60   while ( !it->IsDone() ) 
61   {
62     AliMpPad pad = it->CurrentItem();
63     fPads->AddLast(new AliMpPad(pad));
64     TVector2 lowerLeft(pad.Position()-pad.Dimensions());
65     TVector2 upperRight(pad.Position()+pad.Dimensions());
66     xmin = TMath::Min(lowerLeft.X(),xmin);
67     ymin = TMath::Min(lowerLeft.Y(),ymin);
68     xmax = TMath::Max(upperRight.X(),xmax);
69     ymax = TMath::Max(upperRight.Y(),ymax);
70     it->Next();
71   }
72   fPosition = TVector2((xmin+xmax)/2.0,(ymin+ymax)/2.0);
73   fDimensions = TVector2((xmax-xmin)/2.0,(ymax-ymin)/2.0);
74 }
75
76 //_____________________________________________________________________________
77 AliMpIteratorPainter::~AliMpIteratorPainter()
78 {
79   /// dtor
80   delete fPads;
81 }
82
83 //_____________________________________________________________________________
84 void
85 AliMpIteratorPainter::Draw(Option_t* option)
86 {
87   /// Append ourselves to the current graphic pad
88   AliMpGraphContext *gr = AliMpGraphContext::Instance();
89   gr->Push();
90   InitGraphContext();
91   gr->SetPadPosForReal(GetPosition(),GetDimensions());
92   AppendPad(option);
93   gr->Pop();
94 }
95
96 //_____________________________________________________________________________
97 void
98 AliMpIteratorPainter::Paint(Option_t*)
99 {
100   /// Actual drawing method
101   
102   AliMpGraphContext* gr = AliMpGraphContext::Instance();
103   gr->Push();
104   InitGraphContext();
105   gPad->Range(0.,0.,1.,1.);
106   
107   TIter next(fPads);
108   AliMpPad* pad;
109   
110   while ( ( pad = static_cast<AliMpPad*>(next()) ) )
111   {
112     TVector2 padPadPos;
113     TVector2 padPadDim;
114     
115     gr->RealToPad(pad->Position(),
116                   pad->Dimensions(),
117                   padPadPos,
118                   padPadDim);
119
120     TVector2 bl = padPadPos - padPadDim;
121     TVector2 ur = padPadPos + padPadDim;
122     
123     Int_t manuId = pad->GetLocation().GetFirst();
124
125     Style_t sty = gVirtualX->GetFillStyle();
126
127     gVirtualX->SetFillStyle(1);
128     if (manuId % 5 == 0) 
129         gVirtualX->SetFillColor(0);
130     if (manuId % 5 == 1) 
131         gVirtualX->SetFillColor(38);
132     if (manuId % 5 == 2) 
133         gVirtualX->SetFillColor(33);
134     if (manuId % 5 == 3) 
135         gVirtualX->SetFillColor(16);
136     if (manuId % 5 == 4) 
137         gVirtualX->SetFillColor(44);
138
139     gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
140     gVirtualX->SetFillStyle(0);
141     gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
142     gVirtualX->SetFillStyle(sty);    
143
144     Float_t textSize =   gVirtualX->GetTextSize();
145     gVirtualX->SetTextSize(10);
146     gVirtualX->SetTextAlign(22);
147     gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
148                     Form("%d",pad->GetLocation().GetSecond()));
149     
150     gVirtualX->SetTextSize(textSize);
151     
152   }
153 }
154
155