]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONContourMakerTest.cxx
Update HFE v2 analyses
[u/mrichter/AliRoot.git] / MUON / AliMUONContourMakerTest.cxx
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 ClassImp(AliMUONContourMakerTest)
52 ///\endcond 
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 //_____________________________________________________________________________
89 AliMUONContourMakerTest::AliMUONContourMakerTest()
90 {
91   /// ctor
92 }
93
94 //_____________________________________________________________________________
95 AliMUONContourMakerTest::~AliMUONContourMakerTest()
96 {
97   /// dtor
98 }
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   AliInfo("Resetting all timers before I start...");
111   
112   AliCodeTimer::Instance()->Reset();
113   
114   AliMpCDB::LoadDDLStore2();
115   
116   AliCodeTimer::Instance()->Print();
117   
118   AliInfo("Resetting all timers after loading the mapping...");
119   
120   AliCodeTimer::Instance()->Reset();
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
139   AliCodeTimer::Instance()->Print();  
140 }
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   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 {
185   /// Plot an array of segments 
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 
202 AliMUONContourMakerTest::Plot(const AliMUONPolygon& polygon, 
203                               Int_t lineColor, Int_t lineWidth,
204                               Bool_t orientation) const 
205 {
206   /// Plot a polygon
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 {
224   /// Plot a contour (i.e. a set of polygons)
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 {
238   /// Plot an array of contours
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 {
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);
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