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 **************************************************************************/
17 // $MpId: AliMpSectorPainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
19 // Class AliMpSectorPainter
20 // ------------------------
21 // Class for drawing a sector into canvas
22 // Included in AliRoot: 2003/05/02
23 // Authors: David Guez, IPN Orsay
25 #include "AliMpSectorPainter.h"
26 #include "AliMpGraphContext.h"
27 #include "AliMpSector.h"
28 #include "AliMpZone.h"
29 #include "AliMpSubZone.h"
31 #include "AliMpVRowSegment.h"
33 #include <TVirtualX.h>
37 ClassImp(AliMpSectorPainter)
40 //_______________________________________________________________________
41 AliMpSectorPainter::AliMpSectorPainter()
45 /// Default constructor
47 //_______________________________________________________________________
48 AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
52 /// Standard constructor
56 //_____________________________________________________________________________
57 AliMpSectorPainter::AliMpSectorPainter(const AliMpSectorPainter& right)
58 : AliMpVPainter(right)
60 /// Protected copy constructor (not provided)
62 Fatal("AliMpSectorPainter", "Copy constructor not provided.");
65 //_______________________________________________________________________
66 AliMpSectorPainter::~AliMpSectorPainter()
71 //_____________________________________________________________________________
73 AliMpSectorPainter::operator=(const AliMpSectorPainter& right)
75 /// Assignment operator (not provided)
77 // check assignment to self
78 if (this == &right) return *this;
80 Fatal("operator =", "Assignment operator not provided.");
85 //_______________________________________________________________________
86 void AliMpSectorPainter::DumpObject()
88 //// Draw the owned object
93 //_______________________________________________________________________
94 TVector2 AliMpSectorPainter::GetPosition() const
96 //// Get the owned object's position
98 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
99 AliMpRow* row = fSector->GetRow(0);
101 // bl = bottom left position;
102 TVector2 bl = row->Position()-row->Dimensions();
103 // ur = upper right position
104 TVector2 ur = row->Position()+row->Dimensions();;
106 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
107 row = fSector->GetRow(irow);
108 // update the bottom-left corner
109 if (bl.X()>row->Position().X()-row->Dimensions().X())
110 bl.Set(row->Position().X()-row->Position().X(),bl.Y());
111 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
112 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
113 // update the upper-right corner
114 if (ur.X()<row->Position().X()+row->Dimensions().X())
115 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
116 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
117 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
122 //_______________________________________________________________________
123 TVector2 AliMpSectorPainter::GetDimensions() const
125 //// Get the owned object's dimensions
127 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
128 AliMpRow* row = fSector->GetRow(0);
131 // bl = bottom left position
132 TVector2 bl = row->Position()-row->Dimensions();
133 // ur = upper right position
134 TVector2 ur = row->Position()+row->Dimensions();
136 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
137 row = fSector->GetRow(irow);
138 // update the bottom-left corner
139 if (bl.X()>row->Position().X()-row->Dimensions().X())
140 bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
141 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
142 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
143 // update the upper-right corner
144 if (ur.X()<row->Position().X()+row->Dimensions().X())
145 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
146 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
147 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
152 //_______________________________________________________________________
153 void AliMpSectorPainter::Draw(Option_t *option)
155 /// Draw the sector on the current pad
156 /// The first letter of \a option is treated as follows:
157 /// - case "Z" : each zones are drawn separately
158 /// - case "R" : each rows are drawn separately
159 /// - case "" : the whole sector is drawn at once
160 /// in both cases, the rest of the option is passed
161 /// as argument to the Draw function of respectively
162 /// zone or row objects.
164 AliMpGraphContext *gr = AliMpGraphContext::Instance();
165 if (!fSector) return;
172 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
173 AliMpZone *zone = fSector->GetZone(iZone);
176 Double_t blx= 9999, bly= 9999;
177 Double_t urx= -9999, ury= -9999;
179 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
180 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
181 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
182 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
184 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
185 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
187 if (bl.X()<blx) blx=bl.X();
188 if (bl.Y()<bly) bly=bl.Y();
189 if (ur.X()>urx) urx=ur.X();
190 if (ur.Y()>ury) ury=ur.Y();
193 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
194 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
196 gr->SetPadPosForReal(position,dimensions);
197 gr->SetColor(iZone+3);
198 DrawObject(zone,option+1);
206 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
207 AliMpRow *row = fSector->GetRow(iRow);
209 gr->SetPadPosForReal(row->Position(),row->Dimensions());
210 DrawObject(row,option+1);
215 default: AppendPad(option);
220 //_______________________________________________________________________
221 void AliMpSectorPainter::Paint(Option_t* /*option*/)
223 //// Paint the object
225 AliMpGraphContext *gr = AliMpGraphContext::Instance();
226 if (!fSector) return;
227 if (fSector->GetNofRows()<1) return;
228 Int_t col=gVirtualX->GetFillColor();
231 gPad->Range(0.,0.,1.,1.);
237 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
238 AliMpRow *row = fSector->GetRow(iRow);
240 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
241 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
242 pos.X()+dim.X(),pos.Y()+dim.Y());
243 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
244 pos.X()-dim.X(),pos.Y()+dim.Y());
245 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
246 pos.X()+dim.X(),pos.Y()+dim.Y());
249 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
250 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
256 // now we draw the lower and upper horizontal lines
258 AliMpRow *row = fSector->GetRow(0);
260 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
261 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
262 pos.X()+dim.X(),pos.Y()-dim.Y());
264 row = fSector->GetRow(fSector->GetNofRows()-1);
265 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
266 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
267 pos.X()+dim.X(),pos.Y()+dim.Y());
270 gVirtualX->SetFillColor(col);