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: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifPainter
22 // -----------------------
23 // Class for drawing a motif into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
29 #include "AliMpMotifPainter.h"
30 #include "AliMpGraphContext.h"
31 #include "AliMpMotifPosition.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotif.h"
34 #include "AliMpConnection.h"
35 #include "AliMpIntPair.h"
38 #include <TVirtualX.h>
42 ClassImp(AliMpMotifPainter)
45 //_______________________________________________________________________
46 AliMpMotifPainter::AliMpMotifPainter()
50 /// Default constructor
53 //_______________________________________________________________________
54 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
58 /// Standard constructor
59 AliDebug(1,"Default ctor");
62 //_______________________________________________________________________
63 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
67 /// Constructor from a motif Type. We hereby create a MotifPosition
68 /// object from it, using arbitrary pad sizes, as this is just a way
69 /// to visualize the *shape* of the motif.
71 AliDebug(1,"Ctor from motifType");
73 const Double_t kdx = 5;
74 const Double_t kdy = 5; // cm but arbitrary anyway
76 AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
80 fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions());
83 //_______________________________________________________________________
84 AliMpMotifPainter::~AliMpMotifPainter()
86 /// Default constructor
89 //_______________________________________________________________________
90 void AliMpMotifPainter::DumpObject()
92 /// Dump the owned object
97 //_______________________________________________________________________
98 TVector2 AliMpMotifPainter::GetPosition() const
100 /// Get the owned object's position
102 return fMotifPos->Position();
105 //_______________________________________________________________________
106 TVector2 AliMpMotifPainter::GetDimensions() const
108 /// Get the owned object's dimensions
110 return fMotifPos->Dimensions();
113 //_______________________________________________________________________
114 void AliMpMotifPainter::Paint(Option_t *option)
118 AliMpGraphContext *gr = AliMpGraphContext::Instance();
119 if (!fMotifPos) return;
120 Int_t col=gVirtualX->GetFillColor();
122 gPad->Range(0.,0.,1.,1.);
125 gVirtualX->SetLineWidth(1);
133 Float_t textSize = gVirtualX->GetTextSize();
134 gVirtualX->SetTextSize(10);
138 str = Form("%d",fMotifPos->GetID());
143 str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
144 fMotifPos->GetHighIndicesLimit().GetSecond());
147 str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
148 fMotifPos->GetLowIndicesLimit().GetSecond());
153 str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
154 (GetPosition()-GetDimensions()).Y());
157 gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
159 gVirtualX->SetTextSize(textSize);
165 //PaintWholeBox(kFALSE);
166 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
167 for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
168 for (Int_t i=0;i<motifType->GetNofPadsX();i++){
169 AliMpIntPair indices(i,j);
170 AliMpConnection* connect =
171 motifType->FindConnectionByLocalIndices(indices);
173 TVector2 realPadPos =
174 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
175 TVector2 padPadPos,padPadDim;
176 gr->RealToPad(realPadPos,
177 fMotifPos->GetMotif()->GetPadDimensions(indices),
178 padPadPos,padPadDim);
179 TVector2 bl = padPadPos - padPadDim;
180 TVector2 ur = padPadPos + padPadDim;
182 Style_t sty = gVirtualX->GetFillStyle();
183 gVirtualX->SetFillStyle(1);
184 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
185 gVirtualX->SetFillStyle(0);
186 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
187 gVirtualX->SetFillStyle(sty);
190 Float_t textSize = gVirtualX->GetTextSize();
191 gVirtualX->SetTextSize(10);
192 gVirtualX->SetTextAlign(22);
193 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
194 Form("%d",connect->GetManuChannel()));
196 gVirtualX->SetTextSize(textSize);
201 if ( option[0]=='Z' )
203 PaintContour(option,kFALSE);
209 PaintContour(option,kTRUE);
213 PaintWholeBox(kFALSE);
216 gVirtualX->SetFillColor(col);
219 //_______________________________________________________________________
220 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
222 /// Drawing real motif (not envelop) the real contour
224 AliMpGraphContext *gr = AliMpGraphContext::Instance();
229 Int_t searchMotif = -1;
230 TVector2 bl0 = TVector2(999, 999);
231 TVector2 ur0 = TVector2(0,0);
232 TVector2 padPadPos,padPadDim;
234 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
235 manuId = fMotifPos->GetID();
240 gVirtualX->SetFillColor(0);
242 gVirtualX->SetFillColor(38);
244 gVirtualX->SetFillColor(33);
246 gVirtualX->SetFillColor(16);
248 gVirtualX->SetFillColor(44);
251 Width_t lineW = gPad->GetLineWidth();
252 Width_t lw = lineW*3;
253 Double_t xlw = gPad->PixeltoX(lw/2);
256 if (option[1] == 'I' && option[2] == ':')
257 searchMotif = atoi(&option[3]);
259 gVirtualX->SetLineWidth(lw);
261 for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
263 for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
265 AliMpIntPair indices = AliMpIntPair(i,j);
266 AliMpConnection* connect = motifType->FindConnectionByLocalIndices(indices);
269 TVector2 realPadPos =
270 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
271 gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices),
272 padPadPos, padPadDim);
274 TVector2 bl = padPadPos - padPadDim;
275 TVector2 ur = padPadPos + padPadDim;
277 if (bl0.X() > bl.X())
280 if (ur0.Y() < ur.Y())
285 Style_t csty = gVirtualX->GetFillColor();
286 Style_t sty = gVirtualX->GetFillStyle();
287 gVirtualX->SetFillStyle(1);
288 if (manuId == searchMotif)
289 gVirtualX->SetFillColor(5); // yellow
290 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
291 gVirtualX->SetFillStyle(sty);
292 gVirtualX->SetFillColor(csty);
295 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1)))
297 gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
300 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1)))
302 gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
304 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j)))
306 gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
309 if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i+1,j)))
311 gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
319 // add manudId indexes
321 xl = bl0.X()+ padPadDim.X()/2.;
323 yl = bl0.Y() + 1.5*padPadDim.Y();
325 Float_t textSize = gVirtualX->GetTextSize();
326 gVirtualX->SetTextSize(12);
327 gVirtualX->SetTextAlign(13);
328 gVirtualX->SetTextAngle(90.);
330 gPad->PaintText(xl, yl, Form("%d", manuId));
332 gVirtualX->SetTextAngle(0.);
333 gVirtualX->SetTextSize(textSize);
337 gVirtualX->SetLineWidth(lineW);