AliRoot Core  a565103 (a565103)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpZonePainter.cxx
Go to the documentation of this file.
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 
16 // $Id$
17 // $MpId: AliMpZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpZonePainter
22 // ----------------------
23 // Class for drawing a zone into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
27 
28 #include "AliMpZonePainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpZone.h"
31 #include "AliMpSubZone.h"
32 #include "AliMpVRowSegment.h"
33 
34 #include <TVirtualX.h>
35 #include <TPad.h>
36 
40 
41 //_______________________________________________________________________
43  : AliMpVPainter(),
44  fZone(0)
45 {
47 }
48 
49 //_______________________________________________________________________
51  : AliMpVPainter(),
52  fZone(zone)
53 {
55 
56 }
57 
58 //_______________________________________________________________________
60 {
62 }
63 
64 //_______________________________________________________________________
66 {
69 
70  if (fZone->GetNofSubZones()<1) return 9999;
72 
73  gr->Push();
75 
76  TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
77 
78  Double_t res=9999.;
79  for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
80  // for each sub-zones
81  AliMpSubZone* sub = fZone->GetSubZone(isub);
82  for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
83  //for each row segments
84  AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
85 
86  TVector2 pos,dim;
87  gr->RealToPad(TVector2(seg->GetPositionX(), seg->GetPositionY()),
88  TVector2(seg->GetDimensionX(),seg->GetDimensionY()),pos,dim);
89 
90  if ( IsInside(point,pos,dim) ){
91  Double_t value = (point-pos).Mod();
92  if (value<res) res=value;
93  }
94  }
95  }
96  gr->Pop();
97  return (Int_t)res;
98 }
99 
100 //_______________________________________________________________________
102 {
104 
105  fZone->Dump();
106 }
107 
108 //_______________________________________________________________________
110 {
112 
113  if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
114 
115  TVector2 bl(9999,9999),ur(-9999,-9999);
116 
117  for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
118  // for each sub-zones
119  AliMpSubZone* sub = fZone->GetSubZone(isub);
120  for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
121  //for each row segments
122  AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
123 
124  // update the bottom-left corner
125  if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
126  bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
127  if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
128  bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
129  // update the upper-right corner
130  if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
131  ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
132  if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
133  ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
134  } //iseg
135  } //isub
136  return (ur+bl)/2.;
137 }
138 
139 //_______________________________________________________________________
141 {
143 
144  if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
145 
146  TVector2 bl(9999,9999),ur(-9999,-9999);
147 
148  for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
149  // for each sub-zones
150  AliMpSubZone* sub = fZone->GetSubZone(isub);
151  for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
152  //for each row segments
153  AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
154 
155  // update the bottom-left corner
156  if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
157  bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
158  if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
159  bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
160  // update the upper-right corner
161  if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
162  ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
163  if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
164  ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
165  } //iseg
166  } //isub
167  return (ur-bl)/2.;
168 }
169 
170 //_______________________________________________________________________
171 void AliMpZonePainter::Draw(Option_t *option)
172 {
180 
182  if (!fZone) return;
183 
184  gr->Push();
186  switch (option[0]){
187  case 'S':
188  {
189  for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
190  AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
191  gr->Push();
192 
193  Double_t blx= 9999, bly= 9999;
194  Double_t urx= -9999, ury= -9999;
195 
196  for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
197  AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
198 
199  TVector2 bl = TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY());
200  bl -= TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY());
201  TVector2 ur = TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY());
202  ur += TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY());
203 
204  if (bl.X()<blx) blx=bl.X();
205  if (bl.Y()<bly) bly=bl.Y();
206  if (ur.X()>urx) urx=ur.X();
207  if (ur.Y()>ury) ury=ur.Y();
208  }
209  TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
210  TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
211 
212  gr->SetPadPosForReal(position,dimensions);
213  gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
214  DrawObject(subZone,option+1);
215 
216  gr->Pop();
217  }
218  }
219  break;
220  default: AppendPad(option);
221  }
222  gr->Pop();
223 }
224 
225 //_______________________________________________________________________
226 void AliMpZonePainter::Paint(Option_t *option)
227 {
229 
231  if (!fZone) return;
232  if (fZone->GetNofSubZones()<1) return;
233  gr->Push();
234  gPad->Range(0.,0.,1.,1.);
235 
236  Int_t col=gVirtualX->GetFillColor();
238 
239  gVirtualX->SetFillColor(GetColor());
240  Float_t textSize = gVirtualX->GetTextSize();
241  for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
242  AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
243  for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
244  AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
245  TVector2 pos,dim;
246  gr->RealToPad(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
247  TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()),
248  pos,dim);
249  gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
250  pos.X()+dim.X(),pos.Y()+dim.Y());
251  if (option[0]=='T'){
252  gVirtualX->SetTextSize(15);
253  gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
254  Form("%d",fZone->GetID()));
255  }
256  }
257  }
258  gVirtualX->SetTextSize(textSize);
259  gVirtualX->SetFillColor(col);
260  gr->Pop();
261 }
virtual TVector2 GetDimensions() const
Return the owned object's dimensions.
virtual Double_t GetDimensionX() const =0
Return the x dimension of the row segment centre.
Int_t GetColor() const
Return the color.
Definition: AliMpVPainter.h:41
Int_t GetNofRowSegments() const
static AliMpGraphContext * Instance()
void SetPadPosForReal(const TVector2 &position, const TVector2 &dimensions)
void SetColor(Int_t color)
Set color to use.
A region of pads of the same dimensions composed of subzones.
Definition: AliMpZone.h:25
Int_t GetNofSubZones() const
Definition: AliMpZone.cxx:103
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Bool_t IsInside(const TVector2 &point, const TVector2 &pos, const TVector2 &dim)
An interface for a row segment.
virtual void Draw(Option_t *option)
Class for drawing a zone into canvas.
virtual Double_t GetPositionX() const =0
Return the x position of the row segment centre.
virtual Double_t GetPositionY() const =0
Return the y position of the row segment centre.
TGraph * gr
Definition: CalibTime.C:25
virtual void DumpObject()
Abstract base class for drawing objects into canvas.
Definition: AliMpVPainter.h:21
AliMpZone * fZone
the zone to draw
virtual ~AliMpZonePainter()
virtual TVector2 GetPosition() const
Return the owned object's position.
virtual Double_t GetDimensionY() const =0
Return the y dimension of the row segment centre.
UInt_t GetID() const
Return ID.
Definition: AliMpZone.h:62
AliMpVPainter * DrawObject(TObject *object, Option_t *option="")
Not implemented.
TVector2 RealToPad(const TVector2 &position) const
AliMpSubZone * GetSubZone(Int_t i) const
Definition: AliMpZone.cxx:111
Class describing the correspondance between a given area in pad, and a zone of real (cm) position...
virtual Int_t DistancetoPrimitive(Int_t x, Int_t y)
AliMpVRowSegment * GetRowSegment(Int_t i) const
void InitGraphContext()
virtual void Paint(Option_t *option)
Paint the associated object.
A region in zone composed of the row segments with the same motif type.
Definition: AliMpSubZone.h:23