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 = area.Position().X();
68 Double_t y = area.Position().Y();
69 Double_t dx = area.Dimensions().X();
70 Double_t dy = area.Dimensions().Y();
71 line->SetPoint(0,x-dx,y-dy);
72 line->SetPoint(1,x-dx,y+dy);
73 line->SetPoint(2,x+dx,y+dy);
74 line->SetPoint(3,x+dx,y-dy);
75 line->SetPoint(4,x-dx,y-dy);
77 fPolyLines->AddLast(line);
80 //______________________________________________________________________________
81 AliMUONPainterContour::AliMUONPainterContour(const AliMUONPainterContour& rhs)
91 ((AliMUONPainterContour&)rhs).Copy(*this);
94 //______________________________________________________________________________
95 AliMUONPainterContour&
96 AliMUONPainterContour::operator=(const AliMUONPainterContour& rhs)
98 /// Assignment operator
108 //_____________________________________________________________________________
109 AliMUONPainterContour::~AliMUONPainterContour()
115 //_____________________________________________________________________________
117 AliMUONPainterContour::AdoptPolyLine(TPolyLine* line)
119 /// Adopt one polyline into our array of polylines
120 fPolyLines->AddLast(line);
121 for ( Int_t i = 0; i <= line->GetLastPoint(); ++i )
123 Double_t x = line->GetX()[i];
124 Double_t y = line->GetY()[i];
125 fXmin = TMath::Min(fXmin,x);
126 fXmax = TMath::Max(fXmax,x);
127 fYmin = TMath::Min(fYmin,y);
128 fYmax = TMath::Max(fYmax,y);
132 //_____________________________________________________________________________
134 AliMUONPainterContour::Area() const
136 /// Return the area covered by this contour (i.e. the area that
137 /// contains all the poylines)
139 return AliMpArea( TVector2( (fXmax+fXmin)/2.0, (fYmax+fYmin)/2.0 ),
140 TVector2( TMath::Abs(fXmax-fXmin)/2.0, TMath::Abs(fYmax-fYmin)/2.0 ) );
143 //______________________________________________________________________________
144 void AliMUONPainterContour::Copy(TObject& obj) const
148 AliMUONPainterContour& rhs = static_cast<AliMUONPainterContour&>(obj);
150 rhs.fPolyLines = new TObjArray;
151 rhs.fPolyLines->SetOwner(kTRUE);
152 TIter next(fPolyLines);
154 while ( ( line = static_cast<TPolyLine*>(next()) ) )
156 rhs.fPolyLines->AddLast(line->Clone());
164 //_____________________________________________________________________________
166 AliMUONPainterContour::IsInside(Double_t x, Double_t y) const
168 /// Whether the point (x,y) is inside one of ours polylines
169 // if ( x >= fXmin && x <= fXmax && y >= fYmin && y <= fYmax )
171 TIter next(fPolyLines);
173 while ( ( line = static_cast<TPolyLine*>(next()) ) )
175 if ( TMath::IsInside(x,y,line->Size(),line->GetX(),line->GetY() ) )
184 //_____________________________________________________________________________
186 AliMUONPainterContour::Offset(const TVector2& offset)
188 /// Offset all lines by a given offset
190 TIter next(fPolyLines);
193 while ( ( line = static_cast<TPolyLine*>(next()) ) )
195 for ( Int_t i = 0; i <= line->GetLastPoint(); ++i )
197 Double_t x = line->GetX()[i];
198 Double_t y = line->GetY()[i];
201 line->SetPoint(i,x,y);
211 //_____________________________________________________________________________
213 AliMUONPainterContour::PaintArea(Int_t fillColor, Int_t fillStyle)
215 /// Paint a filled contour
217 Int_t fc = gVirtualX->GetFillColor();
218 Int_t fs = gVirtualX->GetFillStyle();
220 TIter next(fPolyLines);
223 while ( ( line = static_cast<TPolyLine*>(next()) ) )
225 line->SetFillColor(fillColor);
226 line->SetFillStyle(fillStyle);
230 gVirtualX->SetFillColor(fc);
231 gVirtualX->SetFillStyle(fs);
234 //_____________________________________________________________________________
236 AliMUONPainterContour::PaintOutline(Int_t lineColor, Int_t lineWidth)
238 /// Paint the outline of this contour
240 Int_t lc = gVirtualX->GetLineColor();
241 Int_t lw = gVirtualX->GetLineWidth();
243 TIter next(fPolyLines);
246 while ( ( line = static_cast<TPolyLine*>(next()) ) )
248 line->SetLineColor(lineColor);
249 line->SetLineWidth(lineWidth);
253 gVirtualX->SetLineColor(lc);
254 gVirtualX->SetLineWidth(lw);
257 //_____________________________________________________________________________
259 AliMUONPainterContour::Print(Option_t* opt) const
263 cout << GetName() << " Ngroups=" << fPolyLines->GetLast()+1;
267 TIter next(fPolyLines);
269 while ( ( line = static_cast<TPolyLine*>(next()) ) )
271 cout << " (" << line->Size() << ")";
272 if ( sopt.Contains("FULL") )
275 for ( Int_t i = 0; i < line->Size(); ++i )
277 Double_t x = line->GetX()[i];
278 Double_t y = line->GetY()[i];
279 cout << Form("Point %3d = %7.3f %7.3f",i,x,y) << endl;
286 //_____________________________________________________________________________
288 AliMUONPainterContour::Transform(const TGeoHMatrix& matrix)
290 /// Transform the polylines using the given transformation
292 TIter next(fPolyLines);
294 while ( ( line = static_cast<TPolyLine*>(next()) ) )
296 for ( Int_t i = 0; i < line->Size(); ++i )
298 Double_t pl[3] = { line->GetX()[i], line->GetY()[i], 0 };
299 Double_t pg[3] = { 0., 0., 0. };
300 matrix.LocalToMaster(pl, pg);
301 line->SetPoint(i,pg[0],pg[1]);
306 Double_t pl[3] = { fXmin,fYmin, 0 };
307 Double_t pg[3] = { 0., 0., 0. };
308 matrix.LocalToMaster(pl, pg);
316 matrix.LocalToMaster(pl, pg);