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 **************************************************************************/
18 #include "AliMUONPainterContour.h"
20 #include "AliMpArea.h"
22 #include <Riostream.h>
23 #include <TGeoMatrix.h>
25 #include <TObjArray.h>
26 #include <TPolyLine.h>
29 #include <TVirtualX.h>
32 ///\class AliMUONPainterContour
34 /// Contour for one painter. A contour is a set of TPolyLine (one polyline
35 /// per closed shape).
37 ///\author Laurent Aphecetche, Subatech
40 ClassImp(AliMUONPainterContour)
43 //_____________________________________________________________________________
44 AliMUONPainterContour::AliMUONPainterContour(const char* name) : TNamed(name,""),
45 fPolyLines(new TObjArray),
52 fPolyLines->SetOwner(kTRUE);
55 //_____________________________________________________________________________
56 AliMUONPainterContour::AliMUONPainterContour(const char* name, const AliMpArea& area)
58 fPolyLines(new TObjArray),
59 fXmin(area.LeftBorder()),
60 fXmax(area.RightBorder()),
61 fYmin(area.DownBorder()),
62 fYmax(area.UpBorder())
65 fPolyLines->SetOwner(kTRUE);
66 TPolyLine* line = new TPolyLine(5);
67 Double_t x, y, dx, dy;
68 area.GetParameters(x, y, dx, dy);
69 line->SetPoint(0,x-dx,y-dy);
70 line->SetPoint(1,x-dx,y+dy);
71 line->SetPoint(2,x+dx,y+dy);
72 line->SetPoint(3,x+dx,y-dy);
73 line->SetPoint(4,x-dx,y-dy);
75 fPolyLines->AddLast(line);
78 //______________________________________________________________________________
79 AliMUONPainterContour::AliMUONPainterContour(const AliMUONPainterContour& rhs)
89 ((AliMUONPainterContour&)rhs).Copy(*this);
92 //______________________________________________________________________________
93 AliMUONPainterContour&
94 AliMUONPainterContour::operator=(const AliMUONPainterContour& rhs)
96 /// Assignment operator
106 //_____________________________________________________________________________
107 AliMUONPainterContour::~AliMUONPainterContour()
113 //_____________________________________________________________________________
115 AliMUONPainterContour::AdoptPolyLine(TPolyLine* line)
117 /// Adopt one polyline into our array of polylines
118 fPolyLines->AddLast(line);
119 for ( Int_t i = 0; i <= line->GetLastPoint(); ++i )
121 Double_t x = line->GetX()[i];
122 Double_t y = line->GetY()[i];
123 fXmin = TMath::Min(fXmin,x);
124 fXmax = TMath::Max(fXmax,x);
125 fYmin = TMath::Min(fYmin,y);
126 fYmax = TMath::Max(fYmax,y);
130 //_____________________________________________________________________________
132 AliMUONPainterContour::Area() const
134 /// Return the area covered by this contour (i.e. the area that
135 /// contains all the poylines)
137 return AliMpArea( ( fXmax+fXmin)/2.0, (fYmax+fYmin)/2.0 ,
138 TMath::Abs(fXmax-fXmin)/2.0, TMath::Abs(fYmax-fYmin)/2.0 );
141 //______________________________________________________________________________
142 void AliMUONPainterContour::Copy(TObject& obj) const
146 AliMUONPainterContour& rhs = static_cast<AliMUONPainterContour&>(obj);
148 rhs.fPolyLines = new TObjArray;
149 rhs.fPolyLines->SetOwner(kTRUE);
150 TIter next(fPolyLines);
152 while ( ( line = static_cast<TPolyLine*>(next()) ) )
154 rhs.fPolyLines->AddLast(line->Clone());
162 //_____________________________________________________________________________
164 AliMUONPainterContour::IsInside(Double_t x, Double_t y) const
166 /// Whether the point (x,y) is inside one of ours polylines
167 // if ( x >= fXmin && x <= fXmax && y >= fYmin && y <= fYmax )
169 TIter next(fPolyLines);
171 while ( ( line = static_cast<TPolyLine*>(next()) ) )
173 if ( TMath::IsInside(x,y,line->Size(),line->GetX(),line->GetY() ) )
182 //_____________________________________________________________________________
184 AliMUONPainterContour::Offset(const TVector2& offset)
186 /// Offset all lines by a given offset
188 TIter next(fPolyLines);
191 while ( ( line = static_cast<TPolyLine*>(next()) ) )
193 for ( Int_t i = 0; i <= line->GetLastPoint(); ++i )
195 Double_t x = line->GetX()[i];
196 Double_t y = line->GetY()[i];
199 line->SetPoint(i,x,y);
209 //_____________________________________________________________________________
211 AliMUONPainterContour::PaintArea(Int_t fillColor, Int_t fillStyle)
213 /// Paint a filled contour
215 Int_t fc = gVirtualX->GetFillColor();
216 Int_t fs = gVirtualX->GetFillStyle();
218 TIter next(fPolyLines);
221 while ( ( line = static_cast<TPolyLine*>(next()) ) )
223 line->SetFillColor(fillColor);
224 line->SetFillStyle(fillStyle);
228 gVirtualX->SetFillColor(fc);
229 gVirtualX->SetFillStyle(fs);
232 //_____________________________________________________________________________
234 AliMUONPainterContour::PaintOutline(Int_t lineColor, Int_t lineWidth)
236 /// Paint the outline of this contour
238 Int_t lc = gVirtualX->GetLineColor();
239 Int_t lw = gVirtualX->GetLineWidth();
241 TIter next(fPolyLines);
244 while ( ( line = static_cast<TPolyLine*>(next()) ) )
246 line->SetLineColor(lineColor);
247 line->SetLineWidth(lineWidth);
251 gVirtualX->SetLineColor(lc);
252 gVirtualX->SetLineWidth(lw);
255 //_____________________________________________________________________________
257 AliMUONPainterContour::Print(Option_t* opt) const
261 cout << GetName() << " Ngroups=" << fPolyLines->GetLast()+1;
265 TIter next(fPolyLines);
267 while ( ( line = static_cast<TPolyLine*>(next()) ) )
269 cout << " (" << line->Size() << ")";
270 if ( sopt.Contains("FULL") )
273 for ( Int_t i = 0; i < line->Size(); ++i )
275 Double_t x = line->GetX()[i];
276 Double_t y = line->GetY()[i];
277 cout << Form("Point %3d = %7.3f %7.3f",i,x,y) << endl;
284 //_____________________________________________________________________________
286 AliMUONPainterContour::Transform(const TGeoHMatrix& matrix)
288 /// Transform the polylines using the given transformation
290 TIter next(fPolyLines);
292 while ( ( line = static_cast<TPolyLine*>(next()) ) )
294 for ( Int_t i = 0; i < line->Size(); ++i )
296 Double_t pl[3] = { line->GetX()[i], line->GetY()[i], 0 };
297 Double_t pg[3] = { 0., 0., 0. };
298 matrix.LocalToMaster(pl, pg);
299 line->SetPoint(i,pg[0],pg[1]);
304 Double_t pl[3] = { fXmin,fYmin, 0 };
305 Double_t pg[3] = { 0., 0., 0. };
306 matrix.LocalToMaster(pl, pg);
314 matrix.LocalToMaster(pl, pg);