AliRoot Core  edcc906 (edcc906)
AliMUONContourMakerTest.cxx
Go to the documentation of this file.
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 
26 
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 
53 
54 namespace
55 {
56  //_____________________________________________________________________________
57  void Plot(TPolyLine& line, Bool_t orientation)
58  {
59  if ( !orientation )
60  {
61  line.Draw();
62  }
63  else
64  {
65  Double_t* x = line.GetX();
66  Double_t* y = line.GetY();
67 
68  for ( Int_t i = 0; i < line.GetLastPoint(); ++i )
69  {
70  Double_t x1 = x[i];
71  Double_t y1 = y[i];
72  Double_t x2 = x[i+1];
73  Double_t y2 = y[i+1];
74 
75  Bool_t horizontal = AliMUONSegment::AreEqual(y1,y2);
76 
77  TLine* a = new TArrow(x1,y1,x2,y2,0.03,"->-");
78  if (horizontal)
79  {
80  a->SetLineStyle(3);
81  }
82  a->Draw();
83  }
84  }
85  }
86 }
87 
88 //_____________________________________________________________________________
90 {
92 }
93 
94 //_____________________________________________________________________________
96 {
98 }
99 
100 
101 //_____________________________________________________________________________
102 void
103 AliMUONContourMakerTest::Exec(const Option_t* opt)
104 {
109 
110  AliInfo("Resetting all timers before I start...");
111 
113 
115 
117 
118  AliInfo("Resetting all timers after loading the mapping...");
119 
121 
122  AliCodeTimerAuto("",0);
123 
124  TString sopt(opt);
125 
126  Bool_t explodedView(kTRUE);
127 
128  if (sopt.Contains("REAL")) explodedView = kFALSE;
129 
130  AliMUONContourHandler ch(explodedView);
131 
132  if ( sopt.Contains("SAVE") )
133  {
134  TFile f2("AliMUONContourMakerTest.manuContours.root","RECREATE");
135  ch.AllContourMap()->Write("ALL",TObject::kSingleKey);
136  f2.Close();
137  }
138 
140 }
141 
142 
143 //_____________________________________________________________________________
144 void
146  Double_t& xmin, Double_t& ymin,
147  Double_t& xmax, Double_t& ymax,
148  Bool_t enlarge) const
149 {
154 
155  xmin=ymin=FLT_MAX;
156  xmax=ymax=-FLT_MAX;
157  TIter next(&array);
158  AliMUONContour* contour;
159  while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
160  {
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());
166  }
167 
168  if (enlarge)
169  {
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;
174  xmin -= xshift;
175  ymin -= yshift;
176  xmax = xmin + xsize + xshift*2;
177  ymax = ymin + ysize + yshift*2;
178  }
179 }
180 
181 //_____________________________________________________________________________
182 void
183 AliMUONContourMakerTest::PlotSegments(const TObjArray& segments, Int_t lineColor, Int_t lineWidth, Bool_t orientation) const
184 {
186 
187  TIter next(&segments);
188  AliMUONSegment* s;
189  while ( ( s = static_cast<AliMUONSegment*>(next()) ) )
190  {
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);
197  }
198 }
199 
200 //_____________________________________________________________________________
201 void
203  Int_t lineColor, Int_t lineWidth,
204  Bool_t orientation) const
205 {
207  TPolyLine* line = new TPolyLine(polygon.NumberOfVertices());
208  for ( Int_t i = 0; i < polygon.NumberOfVertices(); ++i )
209  {
210  line->SetPoint(i,polygon.X(i),polygon.Y(i));
211  }
212 
213  line->SetLineColor(lineColor);
214  line->SetLineWidth(lineWidth);
215  ::Plot(*line,kFALSE);
216  if ( orientation ) ::Plot(*line,kTRUE);
217 }
218 
219 //_____________________________________________________________________________
220 void
221 AliMUONContourMakerTest::Plot(const AliMUONContour& contour, Int_t lineColor, Int_t lineWidth,
222  Bool_t orientation) const
223 {
225  const TObjArray* polygons = contour.Polygons();
226  TIter next(polygons);
227  AliMUONPolygon* pol;
228  while ( ( pol = static_cast<AliMUONPolygon*>(next()) ) )
229  {
230  Plot(*pol,lineColor,lineWidth,orientation);
231  }
232 }
233 
234 //_____________________________________________________________________________
235 void
236 AliMUONContourMakerTest::PlotContours(const TObjArray& array, Bool_t orientations) const
237 {
239  TIter next(&array);
240  AliMUONContour* contour;
241  while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
242  {
243  Plot(*contour,5,4,orientations);
244  }
245 }
246 
247 //______________________________________________________________________________
248 void
249 AliMUONContourMakerTest::PrintAsPNG(const char* basename, const TObjArray& contourArray,
250  const TObjArray* verticals, const TObjArray* horizontals) const
251 {
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);
258  c->Modified();
259  c->Update();
260  TString name(Form("%s",basename));
261  name.ReplaceAll("/","_");
262  c->Print(Form("%s.png",name.Data()));
263  if ( verticals || horizontals )
264  {
265  c->Clear();
266  if ( verticals ) PlotSegments(*verticals,1);
267  if ( horizontals) PlotSegments(*horizontals,2);
268  c->Modified();
269  c->Update();
270  name = Form("%s",basename);
271  name.ReplaceAll("/","_");
272  c->Print(Form("%s-segments.png",name.Data()));
273  }
274  delete c;
275 }
276 
Double_t EndX() const
Return the x-coordinate of our ending point.
Double_t Y(Int_t i) const
Return the y-coordinate of the i-th vertex.
AliMpArea Area() const
void Print(Option_t *opt="") const
Print the list of timers we manage.
#define TObjArray
TMap * AllContourMap() const
Get all the contours as a map.
A planar polygon.
static Bool_t AreEqual(double a, double b)
void GetBoundingBox(const TObjArray &array, Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax, Bool_t enlarge=kFALSE) const
Test of ContourMaker classes.
void Plot(const AliMUONContour &contour, Int_t lineColor=5, Int_t lineWidth=4, Bool_t orientation=kFALSE) const
void PlotSegments(const TObjArray &segments, Int_t lineColor=1, Int_t lineWidth=2, Bool_t orientations=kFALSE) const
A rectangle area positioned in plane..
Definition: AliMpArea.h:20
static Bool_t LoadDDLStore2(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0, Bool_t warn=false)
Definition: AliMpCDB.cxx:282
Double_t StartY() const
Return the y-coordinate of our starting point.
TObjArray * array
Definition: AnalyzeLaser.C:12
void Exec(const Option_t *opt="ALL")
Double_t StartX() const
Return the x-coordinate of our starting point.
Int_t NumberOfVertices() const
Get the number of vertices of this polygon.
Double_t X(Int_t i) const
Return the x-coordinate of the i-th vertex.
#define AliInfo(message)
Definition: AliLog.h:484
A basic line segment, used for contour making algorithm(s)
void PlotContours(const TObjArray &array, Bool_t orientations=kFALSE) const
#define AliCodeTimerAuto(message, counter)
Definition: AliCodeTimer.h:137
void PrintAsPNG(const char *basename, const TObjArray &contourArray, const TObjArray *contourVerticalEdges=0x0, const TObjArray *horizontals=0x0) const
const TObjArray * Polygons() const
Get the list of polygons we have.
Holder for MUON tracker contours.
static AliCodeTimer * Instance()
Unique instance of this class, which is a singleton.
void Reset()
Reset all our timers.
Double_t EndY() const
Return the y-coordinate of our ending point.
TH1 ** Plot(const AliMUONVStore &store, const char *name, Int_t nbins)
Definition: AliMUONCDB.cxx:655
2D contour