Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifPainter.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
5f91c9e8 18// Category: graphics
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpMotifPainter
22// -----------------------
23// Class for drawing a motif into canvas
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, IPN Orsay
3d1463c8 26//-----------------------------------------------------------------------------
5f91c9e8 27
5f91c9e8 28#include "AliMpMotifPainter.h"
29#include "AliMpGraphContext.h"
30#include "AliMpMotifPosition.h"
31#include "AliMpMotifType.h"
bde6e10f 32#include "AliMpMotif.h"
5f91c9e8 33#include "AliMpConnection.h"
bde6e10f 34#include "AliLog.h"
5f91c9e8 35
2c605e66 36#include <TVirtualX.h>
37#include <TPad.h>
38
168e9c4d 39#include <cstdlib>
40
13985652 41/// \cond CLASSIMP
5f91c9e8 42ClassImp(AliMpMotifPainter)
13985652 43/// \endcond
5f91c9e8 44
45//_______________________________________________________________________
46AliMpMotifPainter::AliMpMotifPainter()
47 : AliMpVPainter(),
48 fMotifPos(0)
49{
dee1d5f1 50 /// Default constructor
5f91c9e8 51}
fb1bf5c0 52
5f91c9e8 53//_______________________________________________________________________
54AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
55 : AliMpVPainter(),
56 fMotifPos(motifPos)
57{
dee1d5f1 58 /// Standard constructor
bde6e10f 59 AliDebug(1,"Default ctor");
60}
5f91c9e8 61
bde6e10f 62//_______________________________________________________________________
63AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
64: AliMpVPainter(),
65fMotifPos(0x0)
66{
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.
70
71 AliDebug(1,"Ctor from motifType");
72
6231d6db 73 const Double_t kdx = 5;
74 const Double_t kdy = 5; // cm but arbitrary anyway
bde6e10f 75
76 AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
77 motifType,
6231d6db 78 TVector2(kdx,kdy));
bde6e10f 79
80 fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions());
5f91c9e8 81}
fb1bf5c0 82
5f91c9e8 83//_______________________________________________________________________
2998a151 84AliMpMotifPainter::~AliMpMotifPainter()
85{
dee1d5f1 86 /// Default constructor
2998a151 87}
fb1bf5c0 88
2998a151 89//_______________________________________________________________________
5f91c9e8 90void AliMpMotifPainter::DumpObject()
91{
dee1d5f1 92/// Dump the owned object
5f91c9e8 93
dee1d5f1 94 fMotifPos->Dump();
5f91c9e8 95}
96
97//_______________________________________________________________________
98TVector2 AliMpMotifPainter::GetPosition() const
99{
dee1d5f1 100/// Get the owned object's position
5f91c9e8 101
dee1d5f1 102 return fMotifPos->Position();
5f91c9e8 103}
dee1d5f1 104
5f91c9e8 105//_______________________________________________________________________
106TVector2 AliMpMotifPainter::GetDimensions() const
107{
dee1d5f1 108/// Get the owned object's dimensions
5f91c9e8 109
dee1d5f1 110 return fMotifPos->Dimensions();
5f91c9e8 111}
112
113//_______________________________________________________________________
114void AliMpMotifPainter::Paint(Option_t *option)
115{
dee1d5f1 116/// Paint the object
117
5f91c9e8 118 AliMpGraphContext *gr = AliMpGraphContext::Instance();
119 if (!fMotifPos) return;
120 Int_t col=gVirtualX->GetFillColor();
121 gr->Push();
122 gPad->Range(0.,0.,1.,1.);
123 InitGraphContext();
124
aae373bb 125 gVirtualX->SetLineWidth(1);
126
5f91c9e8 127 switch (option[0]){
aae373bb 128 case 'T':
129 case 'I':
130 case 'X':
5f91c9e8 131 {
132 PaintWholeBox();
133 Float_t textSize = gVirtualX->GetTextSize();
134 gVirtualX->SetTextSize(10);
135 TString str;
136 switch (option[0]) {
137 case 'T' :
138 str = Form("%d",fMotifPos->GetID());
139 break;
140 case 'I':{
aae373bb 141 switch (option[1]){
142 case '+' :
168e9c4d 143 str = Form("(%d,%d)",fMotifPos->GetHighLimitIx(),
144 fMotifPos->GetHighLimitIy());
aae373bb 145 break;
146 default:
168e9c4d 147 str = Form("(%d,%d)",fMotifPos->GetLowLimitIx(),
148 fMotifPos->GetLowLimitIy());
5f91c9e8 149 }
aae373bb 150 }
151 break;
5f91c9e8 152 case 'X' :
153 str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
aae373bb 154 (GetPosition()-GetDimensions()).Y());
5f91c9e8 155 break;
156 }
157 gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
158
159 gVirtualX->SetTextSize(textSize);
160 }
aae373bb 161 break;
162 case 'P':
163 case 'Z':
164 {
165 //PaintWholeBox(kFALSE);
166 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
aae373bb 167 for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
168 for (Int_t i=0;i<motifType->GetNofPadsX();i++){
aae373bb 169 AliMpConnection* connect =
168e9c4d 170 motifType->FindConnectionByLocalIndices(i,j);
aae373bb 171 if (connect){
172 TVector2 realPadPos =
168e9c4d 173 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(i,j);
aae373bb 174 TVector2 padPadPos,padPadDim;
175 gr->RealToPad(realPadPos,
168e9c4d 176 fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j),
aae373bb 177 padPadPos,padPadDim);
178 TVector2 bl = padPadPos - padPadDim;
179 TVector2 ur = padPadPos + padPadDim;
38f79959 180
aae373bb 181 Style_t sty = gVirtualX->GetFillStyle();
182 gVirtualX->SetFillStyle(1);
183 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
184 gVirtualX->SetFillStyle(0);
185 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
186 gVirtualX->SetFillStyle(sty);
38f79959 187
aae373bb 188 if (option[1]=='T'){
189 Float_t textSize = gVirtualX->GetTextSize();
190 gVirtualX->SetTextSize(10);
191 gVirtualX->SetTextAlign(22);
aae373bb 192 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
34ee05d7 193 Form("%d",connect->GetManuChannel()));
aae373bb 194
195 gVirtualX->SetTextSize(textSize);
196 }
197 }
198 }
199 }
200 if ( option[0]=='Z' )
201 {
202 PaintContour(option,kFALSE);
203 }
204 }
205 break;
206
207 case 'C':
208 PaintContour(option,kTRUE);
209 break;
210
211 default:
212 PaintWholeBox(kFALSE);
213 }
214 gr->Pop();
215 gVirtualX->SetFillColor(col);
216}
217
218//_______________________________________________________________________
219void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
220{
144129ae 221/// Drawing real motif (not envelop) the real contour
222
aae373bb 223 AliMpGraphContext *gr = AliMpGraphContext::Instance();
224
aae373bb 225 Float_t xl = 0;
226 Float_t yl = 0;
227 Int_t manuId = 0;
38f79959 228 Int_t searchMotif = -1;
aae373bb 229 TVector2 bl0 = TVector2(999, 999);
230 TVector2 ur0 = TVector2(0,0);
231 TVector2 padPadPos,padPadDim;
232
233 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
234 manuId = fMotifPos->GetID();
235
236 if ( fill )
bde6e10f 237 {
aae373bb 238 if (manuId % 5 == 0)
239 gVirtualX->SetFillColor(0);
240 if (manuId % 5 == 1)
241 gVirtualX->SetFillColor(38);
242 if (manuId % 5 == 2)
243 gVirtualX->SetFillColor(33);
244 if (manuId % 5 == 3)
245 gVirtualX->SetFillColor(16);
246 if (manuId % 5 == 4)
247 gVirtualX->SetFillColor(44);
248 }
249
250 Width_t lineW = gPad->GetLineWidth();
38f79959 251 Width_t lw = lineW*3;
252 Double_t xlw = gPad->PixeltoX(lw/2);
aae373bb 253
38f79959 254
255 if (option[1] == 'I' && option[2] == ':')
256 searchMotif = atoi(&option[3]);
257
aae373bb 258 gVirtualX->SetLineWidth(lw);
259
260 for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
261
262 for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
263
168e9c4d 264 AliMpConnection* connect = motifType->FindConnectionByLocalIndices(i,j);
38f79959 265
bde6e10f 266 if (connect){
267 TVector2 realPadPos =
168e9c4d 268 GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(i,j);
269 gr->RealToPad(realPadPos,
270 fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j),
aae373bb 271 padPadPos, padPadDim);
272
bde6e10f 273 TVector2 bl = padPadPos - padPadDim;
274 TVector2 ur = padPadPos + padPadDim;
38f79959 275
aae373bb 276 if (bl0.X() > bl.X())
277 bl0 = bl;
bde6e10f 278
aae373bb 279 if (ur0.Y() < ur.Y())
280 ur0 = ur;
bde6e10f 281
aae373bb 282 if ( fill )
283 {
38f79959 284 Style_t csty = gVirtualX->GetFillColor();
285 Style_t sty = gVirtualX->GetFillStyle();
286 gVirtualX->SetFillStyle(1);
287 if (manuId == searchMotif)
288 gVirtualX->SetFillColor(5); // yellow
289 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
aae373bb 290 gVirtualX->SetFillStyle(sty);
38f79959 291 gVirtualX->SetFillColor(csty);
292 }
293
168e9c4d 294 if (!motifType->FindConnectionByLocalIndices(i,j-1))
aae373bb 295 {
296 gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
5f91c9e8 297 }
aae373bb 298
168e9c4d 299 if (!motifType->FindConnectionByLocalIndices(i,j+1))
aae373bb 300 {
301 gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
302 }
168e9c4d 303 if (!motifType->FindConnectionByLocalIndices(i-1,j))
aae373bb 304 {
305 gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
306 }
307
168e9c4d 308 if (!motifType->FindConnectionByLocalIndices(i+1,j))
aae373bb 309 {
38f79959 310 gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
311 }
aae373bb 312 }
38f79959 313
5f91c9e8 314 }
aae373bb 315 }
bde6e10f 316
aae373bb 317 switch (option[1]) {
318 // add manudId indexes
319 case 'I' :
320 xl = bl0.X()+ padPadDim.X()/2.;
321
322 yl = bl0.Y() + 1.5*padPadDim.Y();
323
324 Float_t textSize = gVirtualX->GetTextSize();
325 gVirtualX->SetTextSize(12);
326 gVirtualX->SetTextAlign(13);
327 gVirtualX->SetTextAngle(90.);
328
329 gPad->PaintText(xl, yl, Form("%d", manuId));
330
331 gVirtualX->SetTextAngle(0.);
332 gVirtualX->SetTextSize(textSize);
333 break;
5f91c9e8 334 }
0f6198f2 335
aae373bb 336 gVirtualX->SetLineWidth(lineW);
0f6198f2 337
5f91c9e8 338}