Line data Source code
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 : ///
19 : /// \class AliMUONContourMakerTest
20 : ///
21 : /// Class used to test (and in particular time) the contour creation
22 : /// algorithms.
23 : ///
24 : /// \author Laurent Aphecetche, Subatech
25 : ///
26 :
27 : #include "AliMUONContourMakerTest.h"
28 :
29 : #include "AliCodeTimer.h"
30 : #include "AliLog.h"
31 : #include "AliMUONContour.h"
32 : #include "AliMUONPolygon.h"
33 : #include "AliMUONSegment.h"
34 : #include "AliMUONContourHandler.h"
35 : #include "AliMpCDB.h"
36 : #include "AliMpDDLStore.h"
37 : #include "AliMpExMap.h"
38 : #include <float.h>
39 : #include "Riostream.h"
40 : #include "TArrow.h"
41 : #include "TCanvas.h"
42 : #include "TFile.h"
43 : #include "TGeoMatrix.h"
44 : #include "TLine.h"
45 : #include "TMap.h"
46 : #include "TObjArray.h"
47 : #include "TPolyLine.h"
48 : #include "TSystem.h"
49 :
50 : ///\cond CLASSIMP
51 12 : ClassImp(AliMUONContourMakerTest)
52 : ///\endcond
53 :
54 : namespace
55 : {
56 : //_____________________________________________________________________________
57 : void Plot(TPolyLine& line, Bool_t orientation)
58 : {
59 0 : if ( !orientation )
60 : {
61 0 : line.Draw();
62 0 : }
63 : else
64 : {
65 0 : Double_t* x = line.GetX();
66 0 : Double_t* y = line.GetY();
67 :
68 0 : for ( Int_t i = 0; i < line.GetLastPoint(); ++i )
69 : {
70 0 : Double_t x1 = x[i];
71 0 : Double_t y1 = y[i];
72 0 : Double_t x2 = x[i+1];
73 0 : Double_t y2 = y[i+1];
74 :
75 0 : Bool_t horizontal = AliMUONSegment::AreEqual(y1,y2);
76 :
77 0 : TLine* a = new TArrow(x1,y1,x2,y2,0.03,"->-");
78 0 : if (horizontal)
79 : {
80 0 : a->SetLineStyle(3);
81 0 : }
82 0 : a->Draw();
83 : }
84 : }
85 0 : }
86 : }
87 :
88 : //_____________________________________________________________________________
89 0 : AliMUONContourMakerTest::AliMUONContourMakerTest()
90 0 : {
91 : /// ctor
92 0 : }
93 :
94 : //_____________________________________________________________________________
95 : AliMUONContourMakerTest::~AliMUONContourMakerTest()
96 0 : {
97 : /// dtor
98 0 : }
99 :
100 :
101 : //_____________________________________________________________________________
102 : void
103 : AliMUONContourMakerTest::Exec(const Option_t* opt)
104 : {
105 : /// Main method
106 : /// Generate the geometry transformations, then
107 : /// contours for all manus, and then for all the elements
108 : /// (bus patches, detection elements, etc...)
109 :
110 0 : AliInfo("Resetting all timers before I start...");
111 :
112 0 : AliCodeTimer::Instance()->Reset();
113 :
114 0 : AliMpCDB::LoadDDLStore2();
115 :
116 0 : AliCodeTimer::Instance()->Print();
117 :
118 0 : AliInfo("Resetting all timers after loading the mapping...");
119 :
120 0 : AliCodeTimer::Instance()->Reset();
121 :
122 0 : AliCodeTimerAuto("",0);
123 :
124 0 : TString sopt(opt);
125 :
126 : Bool_t explodedView(kTRUE);
127 :
128 0 : if (sopt.Contains("REAL")) explodedView = kFALSE;
129 :
130 0 : AliMUONContourHandler ch(explodedView);
131 :
132 0 : if ( sopt.Contains("SAVE") )
133 : {
134 0 : TFile f2("AliMUONContourMakerTest.manuContours.root","RECREATE");
135 0 : ch.AllContourMap()->Write("ALL",TObject::kSingleKey);
136 0 : f2.Close();
137 0 : }
138 :
139 0 : AliCodeTimer::Instance()->Print();
140 0 : }
141 :
142 :
143 : //_____________________________________________________________________________
144 : void
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
149 : {
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)
153 : ///
154 :
155 0 : xmin=ymin=FLT_MAX;
156 0 : xmax=ymax=-FLT_MAX;
157 0 : TIter next(&array);
158 : AliMUONContour* contour;
159 0 : while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
160 : {
161 0 : AliMpArea area(contour->Area());
162 0 : xmin = TMath::Min(xmin,area.LeftBorder());
163 0 : xmax = TMath::Max(xmax,area.RightBorder());
164 0 : ymin = TMath::Min(ymin,area.DownBorder());
165 0 : ymax = TMath::Max(ymax,area.UpBorder());
166 0 : }
167 :
168 0 : if (enlarge)
169 : {
170 0 : Double_t xsize = (xmax-xmin);
171 0 : Double_t ysize = (ymax-ymin);
172 0 : Double_t xshift = xsize*0.1;
173 0 : Double_t yshift = ysize*0.1;
174 0 : xmin -= xshift;
175 0 : ymin -= yshift;
176 0 : xmax = xmin + xsize + xshift*2;
177 0 : ymax = ymin + ysize + yshift*2;
178 0 : }
179 0 : }
180 :
181 : //_____________________________________________________________________________
182 : void
183 : AliMUONContourMakerTest::PlotSegments(const TObjArray& segments, Int_t lineColor, Int_t lineWidth, Bool_t orientation) const
184 : {
185 : /// Plot an array of segments
186 :
187 0 : TIter next(&segments);
188 : AliMUONSegment* s;
189 0 : while ( ( s = static_cast<AliMUONSegment*>(next()) ) )
190 : {
191 0 : TPolyLine* line = new TPolyLine(2);
192 0 : line->SetPoint(0,s->StartX(),s->StartY());
193 0 : line->SetPoint(1,s->EndX(),s->EndY());
194 0 : line->SetLineColor(lineColor);
195 0 : line->SetLineWidth(lineWidth);
196 0 : ::Plot(*line,orientation);
197 : }
198 0 : }
199 :
200 : //_____________________________________________________________________________
201 : void
202 : AliMUONContourMakerTest::Plot(const AliMUONPolygon& polygon,
203 : Int_t lineColor, Int_t lineWidth,
204 : Bool_t orientation) const
205 : {
206 : /// Plot a polygon
207 0 : TPolyLine* line = new TPolyLine(polygon.NumberOfVertices());
208 0 : for ( Int_t i = 0; i < polygon.NumberOfVertices(); ++i )
209 : {
210 0 : line->SetPoint(i,polygon.X(i),polygon.Y(i));
211 : }
212 :
213 0 : line->SetLineColor(lineColor);
214 0 : line->SetLineWidth(lineWidth);
215 0 : ::Plot(*line,kFALSE);
216 0 : if ( orientation ) ::Plot(*line,kTRUE);
217 0 : }
218 :
219 : //_____________________________________________________________________________
220 : void
221 : AliMUONContourMakerTest::Plot(const AliMUONContour& contour, Int_t lineColor, Int_t lineWidth,
222 : Bool_t orientation) const
223 : {
224 : /// Plot a contour (i.e. a set of polygons)
225 0 : const TObjArray* polygons = contour.Polygons();
226 0 : TIter next(polygons);
227 : AliMUONPolygon* pol;
228 0 : while ( ( pol = static_cast<AliMUONPolygon*>(next()) ) )
229 : {
230 0 : Plot(*pol,lineColor,lineWidth,orientation);
231 : }
232 0 : }
233 :
234 : //_____________________________________________________________________________
235 : void
236 : AliMUONContourMakerTest::PlotContours(const TObjArray& array, Bool_t orientations) const
237 : {
238 : /// Plot an array of contours
239 0 : TIter next(&array);
240 : AliMUONContour* contour;
241 0 : while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
242 : {
243 0 : Plot(*contour,5,4,orientations);
244 : }
245 0 : }
246 :
247 : //______________________________________________________________________________
248 : void
249 : AliMUONContourMakerTest::PrintAsPNG(const char* basename, const TObjArray& contourArray,
250 : const TObjArray* verticals, const TObjArray* horizontals) const
251 : {
252 : /// Output contours and segments into a PNG file.
253 0 : TCanvas* c = new TCanvas(basename,basename,0,0,600,600);
254 0 : double xmin,ymin,xmax,ymax;
255 0 : GetBoundingBox(contourArray,xmin,ymin,xmax,ymax,kTRUE);
256 0 : c->Range(xmin,ymin,xmax,ymax);
257 0 : PlotContours(contourArray,kTRUE);
258 0 : c->Modified();
259 0 : c->Update();
260 0 : TString name(Form("%s",basename));
261 0 : name.ReplaceAll("/","_");
262 0 : c->Print(Form("%s.png",name.Data()));
263 0 : if ( verticals || horizontals )
264 : {
265 0 : c->Clear();
266 0 : if ( verticals ) PlotSegments(*verticals,1);
267 0 : if ( horizontals) PlotSegments(*horizontals,2);
268 0 : c->Modified();
269 0 : c->Update();
270 0 : name = Form("%s",basename);
271 0 : name.ReplaceAll("/","_");
272 0 : c->Print(Form("%s-segments.png",name.Data()));
273 : }
274 0 : delete c;
275 0 : }
276 :
|