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()
62 //_______________________________________________________________________
63 void AliMpSectorPainter::DumpObject()
65 //// Draw the owned object
70 //_______________________________________________________________________
71 TVector2 AliMpSectorPainter::GetPosition() const
73 //// Get the owned object's position
75 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
76 AliMpRow* row = fSector->GetRow(0);
78 // bl = bottom left position;
79 TVector2 bl = row->Position()-row->Dimensions();
80 // ur = upper right position
81 TVector2 ur = row->Position()+row->Dimensions();;
83 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
84 row = fSector->GetRow(irow);
85 // update the bottom-left corner
86 if (bl.X()>row->Position().X()-row->Dimensions().X())
87 bl.Set(row->Position().X()-row->Position().X(),bl.Y());
88 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
89 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
90 // update the upper-right corner
91 if (ur.X()<row->Position().X()+row->Dimensions().X())
92 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
93 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
94 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
99 //_______________________________________________________________________
100 TVector2 AliMpSectorPainter::GetDimensions() const
102 //// Get the owned object's dimensions
104 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
105 AliMpRow* row = fSector->GetRow(0);
108 // bl = bottom left position
109 TVector2 bl = row->Position()-row->Dimensions();
110 // ur = upper right position
111 TVector2 ur = row->Position()+row->Dimensions();
113 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
114 row = fSector->GetRow(irow);
115 // update the bottom-left corner
116 if (bl.X()>row->Position().X()-row->Dimensions().X())
117 bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
118 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
119 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
120 // update the upper-right corner
121 if (ur.X()<row->Position().X()+row->Dimensions().X())
122 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
123 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
124 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
129 //_______________________________________________________________________
130 void AliMpSectorPainter::Draw(Option_t *option)
132 /// Draw the sector on the current pad
133 /// The first letter of \a option is treated as follows:
134 /// - case "Z" : each zones are drawn separately
135 /// - case "R" : each rows are drawn separately
136 /// - case "" : the whole sector is drawn at once
137 /// in both cases, the rest of the option is passed
138 /// as argument to the Draw function of respectively
139 /// zone or row objects.
141 AliMpGraphContext *gr = AliMpGraphContext::Instance();
142 if (!fSector) return;
149 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
150 AliMpZone *zone = fSector->GetZone(iZone);
153 Double_t blx= 9999, bly= 9999;
154 Double_t urx= -9999, ury= -9999;
156 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
157 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
158 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
159 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
161 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
162 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
164 if (bl.X()<blx) blx=bl.X();
165 if (bl.Y()<bly) bly=bl.Y();
166 if (ur.X()>urx) urx=ur.X();
167 if (ur.Y()>ury) ury=ur.Y();
170 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
171 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
173 gr->SetPadPosForReal(position,dimensions);
174 gr->SetColor(iZone+3);
175 DrawObject(zone,option+1);
183 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
184 AliMpRow *row = fSector->GetRow(iRow);
186 gr->SetPadPosForReal(row->Position(),row->Dimensions());
187 DrawObject(row,option+1);
192 default: AppendPad(option);
197 //_______________________________________________________________________
198 void AliMpSectorPainter::Paint(Option_t* /*option*/)
200 //// Paint the object
202 AliMpGraphContext *gr = AliMpGraphContext::Instance();
203 if (!fSector) return;
204 if (fSector->GetNofRows()<1) return;
205 Int_t col=gVirtualX->GetFillColor();
208 gPad->Range(0.,0.,1.,1.);
214 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
215 AliMpRow *row = fSector->GetRow(iRow);
217 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
218 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
219 pos.X()+dim.X(),pos.Y()+dim.Y());
220 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
221 pos.X()-dim.X(),pos.Y()+dim.Y());
222 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
223 pos.X()+dim.X(),pos.Y()+dim.Y());
226 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
227 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
233 // now we draw the lower and upper horizontal lines
235 AliMpRow *row = fSector->GetRow(0);
237 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
238 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
239 pos.X()+dim.X(),pos.Y()-dim.Y());
241 row = fSector->GetRow(fSector->GetNofRows()-1);
242 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
243 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
244 pos.X()+dim.X(),pos.Y()+dim.Y());
247 gVirtualX->SetFillColor(col);