]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorPainter.cxx
New class - the factory for building mapping segmentations
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPainter.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
dee1d5f1 17// $MpId: AliMpSectorPainter.cxx,v 1.6 2005/08/26 15:43:36 ivana Exp $
5f91c9e8 18//
dbe945cc 19// Class AliMpSectorPainter
20// ------------------------
21// Class for drawing a sector into canvas
22// Included in AliRoot: 2003/05/02
5f91c9e8 23// Authors: David Guez, IPN Orsay
24
2998a151 25#include <TVirtualX.h>
26#include <TPad.h>
fb1bf5c0 27#include <TError.h>
2998a151 28
5f91c9e8 29#include "AliMpSectorPainter.h"
30#include "AliMpGraphContext.h"
31#include "AliMpSector.h"
32#include "AliMpZone.h"
33#include "AliMpSubZone.h"
34#include "AliMpRow.h"
35#include "AliMpVRowSegment.h"
5f91c9e8 36
37ClassImp(AliMpSectorPainter)
38
39//_______________________________________________________________________
2998a151 40AliMpSectorPainter::AliMpSectorPainter()
5f91c9e8 41 :AliMpVPainter(),
42 fSector(0)
43{
dee1d5f1 44 /// Default constructor
5f91c9e8 45}
46//_______________________________________________________________________
47AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
48 :AliMpVPainter(),
49 fSector(sector)
50{
dee1d5f1 51 /// Standard constructor
5f91c9e8 52
53}
fb1bf5c0 54
55//_____________________________________________________________________________
56AliMpSectorPainter::AliMpSectorPainter(const AliMpSectorPainter& right)
57 : AliMpVPainter(right)
58{
dee1d5f1 59 /// Protected copy constructor (not provided)
fb1bf5c0 60
61 Fatal("AliMpSectorPainter", "Copy constructor not provided.");
62}
63
5f91c9e8 64//_______________________________________________________________________
2998a151 65AliMpSectorPainter::~AliMpSectorPainter()
66{
dee1d5f1 67 /// Destructor
2998a151 68}
fb1bf5c0 69
70//_____________________________________________________________________________
71AliMpSectorPainter&
72AliMpSectorPainter::operator=(const AliMpSectorPainter& right)
73{
dee1d5f1 74 /// Assignment operator (not provided)
fb1bf5c0 75
dee1d5f1 76 // check assignment to self
fb1bf5c0 77 if (this == &right) return *this;
78
dee1d5f1 79 Fatal("operator =", "Assignment operator not provided.");
fb1bf5c0 80
81 return *this;
82}
83
2998a151 84//_______________________________________________________________________
5f91c9e8 85void AliMpSectorPainter::DumpObject()
86{
dee1d5f1 87//// Draw the owned object
5f91c9e8 88
dee1d5f1 89 fSector->Dump();
5f91c9e8 90}
dee1d5f1 91
5f91c9e8 92//_______________________________________________________________________
93TVector2 AliMpSectorPainter::GetPosition() const
94{
dee1d5f1 95//// Get the owned object's position
5f91c9e8 96
97 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
98 AliMpRow* row = fSector->GetRow(0);
99
100 // bl = bottom left position;
101 TVector2 bl = row->Position()-row->Dimensions();
102 // ur = upper right position
103 TVector2 ur = row->Position()+row->Dimensions();;
104
105 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
106 row = fSector->GetRow(irow);
107 // update the bottom-left corner
108 if (bl.X()>row->Position().X()-row->Dimensions().X())
109 bl.Set(row->Position().X()-row->Position().X(),bl.Y());
110 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
111 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
112 // update the upper-right corner
113 if (ur.X()<row->Position().X()+row->Dimensions().X())
114 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
115 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
116 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
117 }
118 return (ur+bl)/2.;
119}
dee1d5f1 120
5f91c9e8 121//_______________________________________________________________________
122TVector2 AliMpSectorPainter::GetDimensions() const
123{
dee1d5f1 124//// Get the owned object's dimensions
125
5f91c9e8 126 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
127 AliMpRow* row = fSector->GetRow(0);
128
129
130 // bl = bottom left position
131 TVector2 bl = row->Position()-row->Dimensions();
132 // ur = upper right position
133 TVector2 ur = row->Position()+row->Dimensions();
134
135 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
136 row = fSector->GetRow(irow);
137 // update the bottom-left corner
138 if (bl.X()>row->Position().X()-row->Dimensions().X())
139 bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
140 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
141 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
142 // update the upper-right corner
143 if (ur.X()<row->Position().X()+row->Dimensions().X())
144 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
145 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
146 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
147 }
148 return (ur-bl)/2.;
149
150}
151//_______________________________________________________________________
152void AliMpSectorPainter::Draw(Option_t *option)
153{
dee1d5f1 154/// Draw the sector on the current pad
155/// The first letter of <option> is treated as follows:
156/// - case "Z" : each zones are drawn separately
157/// - case "R" : each rows are drawn separately
158/// - case "" : the whole sector is drawn at once
159/// in both cases, the rest of the option is passed
160/// as argument to the Draw function of respectively
161/// zone or row objects.
5f91c9e8 162
163 AliMpGraphContext *gr = AliMpGraphContext::Instance();
164 if (!fSector) return;
165 gr->Push();
166 InitGraphContext();
167
168 switch (option[0]){
169 case 'Z':
170 {
171 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
172 AliMpZone *zone = fSector->GetZone(iZone);
173 gr->Push();
174
175 Double_t blx= 9999, bly= 9999;
176 Double_t urx= -9999, ury= -9999;
177
178 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
179 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
180 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
181 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
182
183 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
184 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
185
186 if (bl.X()<blx) blx=bl.X();
187 if (bl.Y()<bly) bly=bl.Y();
188 if (ur.X()>urx) urx=ur.X();
189 if (ur.Y()>ury) ury=ur.Y();
190 }
191 }
192 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
193 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
194
195 gr->SetPadPosForReal(position,dimensions);
196 gr->SetColor(iZone+3);
197 DrawObject(zone,option+1);
198
199 gr->Pop();
200 }
201 }
202 break;
203 case 'R':
204 {
205 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
206 AliMpRow *row = fSector->GetRow(iRow);
207 gr->Push();
208 gr->SetPadPosForReal(row->Position(),row->Dimensions());
209 DrawObject(row,option+1);
210 gr->Pop();
211 }
212 }
213 break;
214 default: AppendPad(option);
215 }
216 gr->Pop();
217}
218
5f91c9e8 219//_______________________________________________________________________
2998a151 220void AliMpSectorPainter::Paint(Option_t* /*option*/)
5f91c9e8 221{
dee1d5f1 222//// Paint the object
223
5f91c9e8 224 AliMpGraphContext *gr = AliMpGraphContext::Instance();
225 if (!fSector) return;
226 if (fSector->GetNofRows()<1) return;
227 Int_t col=gVirtualX->GetFillColor();
228 gr->Push();
229 InitGraphContext();
230 gPad->Range(0.,0.,1.,1.);
231
232
233 Double_t lx1=0.;
234 Double_t lx2=0.;
235 Int_t iRow;
236 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
237 AliMpRow *row = fSector->GetRow(iRow);
238 TVector2 pos,dim;
239 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
240 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
241 pos.X()+dim.X(),pos.Y()+dim.Y());
242 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
243 pos.X()-dim.X(),pos.Y()+dim.Y());
244 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
245 pos.X()+dim.X(),pos.Y()+dim.Y());
246
247 if (iRow>0){
e191bb57 248 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
249 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
5f91c9e8 250 }
251 lx1=pos.X()-dim.X();
252 lx2=pos.X()+dim.X();
253 }
254
255 // now we draw the lower and upper horizontal lines
256
257 AliMpRow *row = fSector->GetRow(0);
258 TVector2 pos,dim;
259 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
e191bb57 260 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
5f91c9e8 261 pos.X()+dim.X(),pos.Y()-dim.Y());
262
263 row = fSector->GetRow(fSector->GetNofRows()-1);
264 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
e191bb57 265 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
5f91c9e8 266 pos.X()+dim.X(),pos.Y()+dim.Y());
267
268 gr->Pop();
269 gVirtualX->SetFillColor(col);
270}
271