Replacement of AliMpIntPair object with algoritmic
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpIteratorPainter.cxx
CommitLineData
3617b752 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
18#include "AliMpIteratorPainter.h"
19
20#include "AliMpVPadIterator.h"
21#include "AliMpPad.h"
22#include "AliMpGraphContext.h"
23
24#include "AliLog.h"
25
26#include "TObjArray.h"
27#include "TVirtualX.h"
28#include "TVirtualPad.h"
29#include "TVector2.h"
30#include "TMath.h"
31
3d1463c8 32//-----------------------------------------------------------------------------
3617b752 33/// \class AliMpIteratorPainter
34///
35/// A painter for a group of pads, which is defined by an iterator
36///
37///
38/// \author L. Aphecetche
3d1463c8 39//-----------------------------------------------------------------------------
3617b752 40
41/// \cond CLASSIMP
42ClassImp(AliMpIteratorPainter)
43/// \endcond
44
45//_____________________________________________________________________________
46AliMpIteratorPainter::AliMpIteratorPainter(AliMpVPadIterator *it)
47: AliMpVPainter(), fPads(new TObjArray), fPosition(), fDimensions()
48{
49 /// Ctor. Iterator must not be null.
50
51 //if (!it) throw;
52 if (!it) {
53 AliFatal("Iterator must not be null.");;
54 }
55
56 Double_t xmin(1E9), xmax(-1E9);
57 Double_t ymin(1E9), ymax(-1E9);
58
59 fPads->SetOwner(kTRUE);
60 it->First();
61 while ( !it->IsDone() )
62 {
63 AliMpPad pad = it->CurrentItem();
64 fPads->AddLast(new AliMpPad(pad));
65 TVector2 lowerLeft(pad.Position()-pad.Dimensions());
66 TVector2 upperRight(pad.Position()+pad.Dimensions());
67 xmin = TMath::Min(lowerLeft.X(),xmin);
68 ymin = TMath::Min(lowerLeft.Y(),ymin);
69 xmax = TMath::Max(upperRight.X(),xmax);
70 ymax = TMath::Max(upperRight.Y(),ymax);
71 it->Next();
72 }
73 fPosition = TVector2((xmin+xmax)/2.0,(ymin+ymax)/2.0);
74 fDimensions = TVector2((xmax-xmin)/2.0,(ymax-ymin)/2.0);
75}
76
77//_____________________________________________________________________________
78AliMpIteratorPainter::~AliMpIteratorPainter()
79{
80 /// dtor
81 delete fPads;
82}
83
84//_____________________________________________________________________________
85void
86AliMpIteratorPainter::Draw(Option_t* option)
87{
88 /// Append ourselves to the current graphic pad
89 AliMpGraphContext *gr = AliMpGraphContext::Instance();
90 gr->Push();
91 InitGraphContext();
92 gr->SetPadPosForReal(GetPosition(),GetDimensions());
93 AppendPad(option);
94 gr->Pop();
95}
96
97//_____________________________________________________________________________
98void
99AliMpIteratorPainter::Paint(Option_t*)
100{
101 /// Actual drawing method
102
103 AliMpGraphContext* gr = AliMpGraphContext::Instance();
104 gr->Push();
105 InitGraphContext();
106 gPad->Range(0.,0.,1.,1.);
107
108 TIter next(fPads);
109 AliMpPad* pad;
110
111 while ( ( pad = static_cast<AliMpPad*>(next()) ) )
112 {
113 TVector2 padPadPos;
114 TVector2 padPadDim;
115
116 gr->RealToPad(pad->Position(),
117 pad->Dimensions(),
118 padPadPos,
119 padPadDim);
120
121 TVector2 bl = padPadPos - padPadDim;
122 TVector2 ur = padPadPos + padPadDim;
123
168e9c4d 124 Int_t manuId = pad->GetManuId();
3617b752 125
126 Style_t sty = gVirtualX->GetFillStyle();
127
128 gVirtualX->SetFillStyle(1);
129 if (manuId % 5 == 0)
130 gVirtualX->SetFillColor(0);
131 if (manuId % 5 == 1)
132 gVirtualX->SetFillColor(38);
133 if (manuId % 5 == 2)
134 gVirtualX->SetFillColor(33);
135 if (manuId % 5 == 3)
136 gVirtualX->SetFillColor(16);
137 if (manuId % 5 == 4)
138 gVirtualX->SetFillColor(44);
139
140 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
141 gVirtualX->SetFillStyle(0);
142 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
143 gVirtualX->SetFillStyle(sty);
144
145 Float_t textSize = gVirtualX->GetTextSize();
146 gVirtualX->SetTextSize(10);
147 gVirtualX->SetTextAlign(22);
148 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
168e9c4d 149 Form("%d",pad->GetManuChannel()));
3617b752 150
151 gVirtualX->SetTextSize(textSize);
152
153 }
154}
155
156