]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSectorPainter.cxx
Code for MUON Station1 (I.Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorPainter.cxx
CommitLineData
5f91c9e8 1// $Id$
2//
3// Authors: David Guez, IPN Orsay
4
5#include "AliMpSectorPainter.h"
6#include "AliMpGraphContext.h"
7#include "AliMpSector.h"
8#include "AliMpZone.h"
9#include "AliMpSubZone.h"
10#include "AliMpRow.h"
11#include "AliMpVRowSegment.h"
12//#include "AliMpZonePainter.h"
13
14ClassImp(AliMpSectorPainter)
15
16//_______________________________________________________________________
17 AliMpSectorPainter::AliMpSectorPainter()
18 :AliMpVPainter(),
19 fSector(0)
20{
21 // default dummy constructor
22}
23//_______________________________________________________________________
24AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
25 :AliMpVPainter(),
26 fSector(sector)
27{
28 // normal constructor
29
30}
31//_______________________________________________________________________
32void AliMpSectorPainter::DumpObject()
33{
34// Draw the owned object
35 fSector->Dump();
36
37}
38//_______________________________________________________________________
39TVector2 AliMpSectorPainter::GetPosition() const
40{
41// Get the owned object's position
42
43 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
44 AliMpRow* row = fSector->GetRow(0);
45
46 // bl = bottom left position;
47 TVector2 bl = row->Position()-row->Dimensions();
48 // ur = upper right position
49 TVector2 ur = row->Position()+row->Dimensions();;
50
51 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
52 row = fSector->GetRow(irow);
53 // update the bottom-left corner
54 if (bl.X()>row->Position().X()-row->Dimensions().X())
55 bl.Set(row->Position().X()-row->Position().X(),bl.Y());
56 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
57 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
58 // update the upper-right corner
59 if (ur.X()<row->Position().X()+row->Dimensions().X())
60 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
61 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
62 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
63 }
64 return (ur+bl)/2.;
65}
66//_______________________________________________________________________
67TVector2 AliMpSectorPainter::GetDimensions() const
68{
69// Get the owned object's dimensions
70 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
71 AliMpRow* row = fSector->GetRow(0);
72
73
74 // bl = bottom left position
75 TVector2 bl = row->Position()-row->Dimensions();
76 // ur = upper right position
77 TVector2 ur = row->Position()+row->Dimensions();
78
79 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
80 row = fSector->GetRow(irow);
81 // update the bottom-left corner
82 if (bl.X()>row->Position().X()-row->Dimensions().X())
83 bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
84 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
85 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
86 // update the upper-right corner
87 if (ur.X()<row->Position().X()+row->Dimensions().X())
88 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
89 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
90 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
91 }
92 return (ur-bl)/2.;
93
94}
95//_______________________________________________________________________
96void AliMpSectorPainter::Draw(Option_t *option)
97{
98// Draw the sector on the current pad
99// The first letter of <option> is treated as follows:
100// case "Z" : each zones are drawn separately
101// case "R" : each rows are drawn separately
102// case "" : the whole sector is drawn at once
103// in both cases, the rest of the option is passed
104// as argument to the Draw function of respectively
105// zone or row objects.
106// ---
107
108 AliMpGraphContext *gr = AliMpGraphContext::Instance();
109 if (!fSector) return;
110 gr->Push();
111 InitGraphContext();
112
113 switch (option[0]){
114 case 'Z':
115 {
116 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
117 AliMpZone *zone = fSector->GetZone(iZone);
118 gr->Push();
119
120 Double_t blx= 9999, bly= 9999;
121 Double_t urx= -9999, ury= -9999;
122
123 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
124 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
125 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
126 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
127
128 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
129 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
130
131 if (bl.X()<blx) blx=bl.X();
132 if (bl.Y()<bly) bly=bl.Y();
133 if (ur.X()>urx) urx=ur.X();
134 if (ur.Y()>ury) ury=ur.Y();
135 }
136 }
137 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
138 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
139
140 gr->SetPadPosForReal(position,dimensions);
141 gr->SetColor(iZone+3);
142 DrawObject(zone,option+1);
143
144 gr->Pop();
145 }
146 }
147 break;
148 case 'R':
149 {
150 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
151 AliMpRow *row = fSector->GetRow(iRow);
152 gr->Push();
153 gr->SetPadPosForReal(row->Position(),row->Dimensions());
154 DrawObject(row,option+1);
155 gr->Pop();
156 }
157 }
158 break;
159 default: AppendPad(option);
160 }
161 gr->Pop();
162}
163
164
165
166//_______________________________________________________________________
167void AliMpSectorPainter::Paint(Option_t *option)
168{
169// Paint the object
170 AliMpGraphContext *gr = AliMpGraphContext::Instance();
171 if (!fSector) return;
172 if (fSector->GetNofRows()<1) return;
173 Int_t col=gVirtualX->GetFillColor();
174 gr->Push();
175 InitGraphContext();
176 gPad->Range(0.,0.,1.,1.);
177
178
179 Double_t lx1=0.;
180 Double_t lx2=0.;
181 Int_t iRow;
182 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
183 AliMpRow *row = fSector->GetRow(iRow);
184 TVector2 pos,dim;
185 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
186 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
187 pos.X()+dim.X(),pos.Y()+dim.Y());
188 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
189 pos.X()-dim.X(),pos.Y()+dim.Y());
190 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
191 pos.X()+dim.X(),pos.Y()+dim.Y());
192
193 if (iRow>0){
194 gPad->DrawLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
195 gPad->DrawLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
196 }
197 lx1=pos.X()-dim.X();
198 lx2=pos.X()+dim.X();
199 }
200
201 // now we draw the lower and upper horizontal lines
202
203 AliMpRow *row = fSector->GetRow(0);
204 TVector2 pos,dim;
205 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
206 gPad->DrawLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
207 pos.X()+dim.X(),pos.Y()-dim.Y());
208
209 row = fSector->GetRow(fSector->GetNofRows()-1);
210 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
211 gPad->DrawLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
212 pos.X()+dim.X(),pos.Y()+dim.Y());
213
214 gr->Pop();
215 gVirtualX->SetFillColor(col);
216}
217