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 **************************************************************************/
19 /// \class AliMUONContourMakerTest
21 /// Class used to test (and in particular time) the contour creation
24 /// \author Laurent Aphecetche, Subatech
27 #include "AliMUONContourMakerTest.h"
29 #include "AliCodeTimer.h"
31 #include "AliMUONContour.h"
32 #include "AliMUONPolygon.h"
33 #include "AliMUONSegment.h"
34 #include "AliMUONContourHandler.h"
36 #include "AliMpDDLStore.h"
37 #include "AliMpExMap.h"
39 #include "Riostream.h"
43 #include "TGeoMatrix.h"
46 #include "TObjArray.h"
47 #include "TPolyLine.h"
51 ClassImp(AliMUONContourMakerTest)
56 //_____________________________________________________________________________
57 void Plot(TPolyLine& line, Bool_t orientation)
65 Double_t* x = line.GetX();
66 Double_t* y = line.GetY();
68 for ( Int_t i = 0; i < line.GetLastPoint(); ++i )
75 Bool_t horizontal = AliMUONSegment::AreEqual(y1,y2);
77 TLine* a = new TArrow(x1,y1,x2,y2,0.03,"->-");
88 //_____________________________________________________________________________
89 AliMUONContourMakerTest::AliMUONContourMakerTest()
94 //_____________________________________________________________________________
95 AliMUONContourMakerTest::~AliMUONContourMakerTest()
101 //_____________________________________________________________________________
103 AliMUONContourMakerTest::Exec(const Option_t* opt)
106 /// Generate the geometry transformations, then
107 /// contours for all manus, and then for all the elements
108 /// (bus patches, detection elements, etc...)
110 AliInfo("Resetting all timers before I start...");
112 AliCodeTimer::Instance()->Reset();
114 AliMpCDB::LoadDDLStore2();
116 AliCodeTimer::Instance()->Print();
118 AliInfo("Resetting all timers after loading the mapping...");
120 AliCodeTimer::Instance()->Reset();
122 AliCodeTimerAuto("",0);
126 Bool_t explodedView(kTRUE);
128 if (sopt.Contains("REAL")) explodedView = kFALSE;
130 AliMUONContourHandler ch(explodedView);
132 if ( sopt.Contains("SAVE") )
134 TFile f2("AliMUONContourMakerTest.manuContours.root","RECREATE");
135 ch.AllContourMap()->Write("ALL",TObject::kSingleKey);
139 AliCodeTimer::Instance()->Print();
143 //_____________________________________________________________________________
145 AliMUONContourMakerTest::GetBoundingBox(const TObjArray& array,
146 Double_t& xmin, Double_t& ymin,
147 Double_t& xmax, Double_t& ymax,
148 Bool_t enlarge) const
150 /// Get the bounding box of all the contours in array.
151 /// If enlarge = kTRUE, the bounding box is "enlarged" a bit
152 /// (e.g. to leave some blank around a plot in a canvas)
158 AliMUONContour* contour;
159 while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
161 AliMpArea area(contour->Area());
162 xmin = TMath::Min(xmin,area.LeftBorder());
163 xmax = TMath::Max(xmax,area.RightBorder());
164 ymin = TMath::Min(ymin,area.DownBorder());
165 ymax = TMath::Max(ymax,area.UpBorder());
170 Double_t xsize = (xmax-xmin);
171 Double_t ysize = (ymax-ymin);
172 Double_t xshift = xsize*0.1;
173 Double_t yshift = ysize*0.1;
176 xmax = xmin + xsize + xshift*2;
177 ymax = ymin + ysize + yshift*2;
181 //_____________________________________________________________________________
183 AliMUONContourMakerTest::PlotSegments(const TObjArray& segments, Int_t lineColor, Int_t lineWidth, Bool_t orientation) const
185 /// Plot an array of segments
187 TIter next(&segments);
189 while ( ( s = static_cast<AliMUONSegment*>(next()) ) )
191 TPolyLine* line = new TPolyLine(2);
192 line->SetPoint(0,s->StartX(),s->StartY());
193 line->SetPoint(1,s->EndX(),s->EndY());
194 line->SetLineColor(lineColor);
195 line->SetLineWidth(lineWidth);
196 ::Plot(*line,orientation);
200 //_____________________________________________________________________________
202 AliMUONContourMakerTest::Plot(const AliMUONPolygon& polygon,
203 Int_t lineColor, Int_t lineWidth,
204 Bool_t orientation) const
207 TPolyLine* line = new TPolyLine(polygon.NumberOfVertices());
208 for ( Int_t i = 0; i < polygon.NumberOfVertices(); ++i )
210 line->SetPoint(i,polygon.X(i),polygon.Y(i));
213 line->SetLineColor(lineColor);
214 line->SetLineWidth(lineWidth);
215 ::Plot(*line,kFALSE);
216 if ( orientation ) ::Plot(*line,kTRUE);
219 //_____________________________________________________________________________
221 AliMUONContourMakerTest::Plot(const AliMUONContour& contour, Int_t lineColor, Int_t lineWidth,
222 Bool_t orientation) const
224 /// Plot a contour (i.e. a set of polygons)
225 const TObjArray* polygons = contour.Polygons();
226 TIter next(polygons);
228 while ( ( pol = static_cast<AliMUONPolygon*>(next()) ) )
230 Plot(*pol,lineColor,lineWidth,orientation);
234 //_____________________________________________________________________________
236 AliMUONContourMakerTest::PlotContours(const TObjArray& array, Bool_t orientations) const
238 /// Plot an array of contours
240 AliMUONContour* contour;
241 while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
243 Plot(*contour,5,4,orientations);
247 //______________________________________________________________________________
249 AliMUONContourMakerTest::PrintAsPNG(const char* basename, const TObjArray& contourArray,
250 const TObjArray* verticals, const TObjArray* horizontals) const
252 /// Output contours and segments into a PNG file.
253 TCanvas* c = new TCanvas(basename,basename,0,0,600,600);
254 double xmin,ymin,xmax,ymax;
255 GetBoundingBox(contourArray,xmin,ymin,xmax,ymax,kTRUE);
256 c->Range(xmin,ymin,xmax,ymax);
257 PlotContours(contourArray,kTRUE);
260 TString name(Form("%s",basename));
261 name.ReplaceAll("/","_");
262 c->Print(Form("%s.png",name.Data()));
263 if ( verticals || horizontals )
266 if ( verticals ) PlotSegments(*verticals,1);
267 if ( horizontals) PlotSegments(*horizontals,2);
270 name = Form("%s",basename);
271 name.ReplaceAll("/","_");
272 c->Print(Form("%s-segments.png",name.Data()));