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.6 2005/08/26 15:43:36 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 <TVirtualX.h>
29 #include "AliMpSectorPainter.h"
30 #include "AliMpGraphContext.h"
31 #include "AliMpSector.h"
32 #include "AliMpZone.h"
33 #include "AliMpSubZone.h"
35 #include "AliMpVRowSegment.h"
37 ClassImp(AliMpSectorPainter)
39 //_______________________________________________________________________
40 AliMpSectorPainter::AliMpSectorPainter()
44 /// Default constructor
46 //_______________________________________________________________________
47 AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
51 /// Standard constructor
55 //_____________________________________________________________________________
56 AliMpSectorPainter::AliMpSectorPainter(const AliMpSectorPainter& right)
57 : AliMpVPainter(right)
59 /// Protected copy constructor (not provided)
61 Fatal("AliMpSectorPainter", "Copy constructor not provided.");
64 //_______________________________________________________________________
65 AliMpSectorPainter::~AliMpSectorPainter()
70 //_____________________________________________________________________________
72 AliMpSectorPainter::operator=(const AliMpSectorPainter& right)
74 /// Assignment operator (not provided)
76 // check assignment to self
77 if (this == &right) return *this;
79 Fatal("operator =", "Assignment operator not provided.");
84 //_______________________________________________________________________
85 void AliMpSectorPainter::DumpObject()
87 //// Draw the owned object
92 //_______________________________________________________________________
93 TVector2 AliMpSectorPainter::GetPosition() const
95 //// Get the owned object's position
97 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
98 AliMpRow* row = fSector->GetRow(0);
100 // bl = bottom left position;
101 TVector2 bl = row->Position()-row->Dimensions();
102 // ur = upper right position
103 TVector2 ur = row->Position()+row->Dimensions();;
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());
121 //_______________________________________________________________________
122 TVector2 AliMpSectorPainter::GetDimensions() const
124 //// Get the owned object's dimensions
126 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
127 AliMpRow* row = fSector->GetRow(0);
130 // bl = bottom left position
131 TVector2 bl = row->Position()-row->Dimensions();
132 // ur = upper right position
133 TVector2 ur = row->Position()+row->Dimensions();
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());
151 //_______________________________________________________________________
152 void AliMpSectorPainter::Draw(Option_t *option)
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.
163 AliMpGraphContext *gr = AliMpGraphContext::Instance();
164 if (!fSector) return;
171 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
172 AliMpZone *zone = fSector->GetZone(iZone);
175 Double_t blx= 9999, bly= 9999;
176 Double_t urx= -9999, ury= -9999;
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);
183 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
184 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
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();
192 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
193 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
195 gr->SetPadPosForReal(position,dimensions);
196 gr->SetColor(iZone+3);
197 DrawObject(zone,option+1);
205 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
206 AliMpRow *row = fSector->GetRow(iRow);
208 gr->SetPadPosForReal(row->Position(),row->Dimensions());
209 DrawObject(row,option+1);
214 default: AppendPad(option);
219 //_______________________________________________________________________
220 void AliMpSectorPainter::Paint(Option_t* /*option*/)
222 //// Paint the object
224 AliMpGraphContext *gr = AliMpGraphContext::Instance();
225 if (!fSector) return;
226 if (fSector->GetNofRows()<1) return;
227 Int_t col=gVirtualX->GetFillColor();
230 gPad->Range(0.,0.,1.,1.);
236 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
237 AliMpRow *row = fSector->GetRow(iRow);
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());
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());
255 // now we draw the lower and upper horizontal lines
257 AliMpRow *row = fSector->GetRow(0);
259 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
260 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
261 pos.X()+dim.X(),pos.Y()-dim.Y());
263 row = fSector->GetRow(fSector->GetNofRows()-1);
264 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
265 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
266 pos.X()+dim.X(),pos.Y()+dim.Y());
269 gVirtualX->SetFillColor(col);