ROOT logo
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
*                                                                        *
* Author: The ALICE Off-line Project.                                    *
* Contributors are mentioned in the code where appropriate.              *
*                                                                        *
* Permission to use, copy, modify and distribute this software and its   *
* documentation strictly for non-commercial purposes is hereby granted   *
* without fee, provided that the above copyright notice appears in all   *
* copies and that both the copyright notice and this permission notice   *
* appear in the supporting documentation. The authors make no claims     *
* about the suitability of this software for any purpose. It is          *
* provided "as is" without express or implied warranty.                  *
**************************************************************************/

// $Id$

///
/// \class AliMUONContourMakerTest
/// 
/// Class used to test (and in particular time) the contour creation
/// algorithms.
///
/// \author Laurent Aphecetche, Subatech
///

#include "AliMUONContourMakerTest.h"

#include "AliCodeTimer.h"
#include "AliLog.h"
#include "AliMUONContour.h"
#include "AliMUONPolygon.h"
#include "AliMUONSegment.h"
#include "AliMUONContourHandler.h"
#include "AliMpCDB.h"
#include "AliMpDDLStore.h"
#include "AliMpExMap.h"
#include <float.h>
#include "Riostream.h"
#include "TArrow.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TGeoMatrix.h"
#include "TLine.h"
#include "TMap.h"
#include "TObjArray.h"
#include "TPolyLine.h"
#include "TSystem.h"

///\cond CLASSIMP
ClassImp(AliMUONContourMakerTest)
///\endcond 

namespace
{
  //_____________________________________________________________________________
  void Plot(TPolyLine& line, Bool_t orientation)
  {
    if ( !orientation ) 
    {
      line.Draw();
    }
    else
    {
      Double_t* x = line.GetX();
      Double_t* y = line.GetY();
      
      for ( Int_t i = 0; i < line.GetLastPoint(); ++i ) 
      {
        Double_t x1 = x[i];
        Double_t y1 = y[i];
        Double_t x2 = x[i+1];
        Double_t y2 = y[i+1];
        
        Bool_t horizontal = AliMUONSegment::AreEqual(y1,y2);
        
        TLine* a = new TArrow(x1,y1,x2,y2,0.03,"->-");
        if (horizontal)
        {
          a->SetLineStyle(3);
        }
        a->Draw();
      }
    }
  }
}

//_____________________________________________________________________________
AliMUONContourMakerTest::AliMUONContourMakerTest()
{
  /// ctor
}

//_____________________________________________________________________________
AliMUONContourMakerTest::~AliMUONContourMakerTest()
{
  /// dtor
}


//_____________________________________________________________________________
void 
AliMUONContourMakerTest::Exec(const Option_t* opt)
{
  /// Main method
  /// Generate the geometry transformations, then
  /// contours for all manus, and then for all the elements
  /// (bus patches, detection elements, etc...)
  
  AliInfo("Resetting all timers before I start...");
  
  AliCodeTimer::Instance()->Reset();
  
  AliMpCDB::LoadDDLStore2();
  
  AliCodeTimer::Instance()->Print();
  
  AliInfo("Resetting all timers after loading the mapping...");
  
  AliCodeTimer::Instance()->Reset();
  
  AliCodeTimerAuto("",0);

  TString sopt(opt);
  
  Bool_t explodedView(kTRUE);
  
  if (sopt.Contains("REAL")) explodedView = kFALSE;
    
  AliMUONContourHandler ch(explodedView);
  
  if ( sopt.Contains("SAVE") )
  {
    TFile f2("AliMUONContourMakerTest.manuContours.root","RECREATE");
    ch.AllContourMap()->Write("ALL",TObject::kSingleKey);
    f2.Close();
  }

  AliCodeTimer::Instance()->Print();  
}


//_____________________________________________________________________________
void 
AliMUONContourMakerTest::GetBoundingBox(const TObjArray& array, 
                                        Double_t& xmin, Double_t& ymin, 
                                        Double_t& xmax, Double_t& ymax,
                                        Bool_t enlarge) const
{
  /// Get the bounding box of all the contours in array. 
  /// If enlarge = kTRUE, the bounding box is "enlarged" a bit
  /// (e.g. to leave some blank around a plot in a canvas)
  ///
  
  xmin=ymin=FLT_MAX;
  xmax=ymax=-FLT_MAX;
  TIter next(&array);
  AliMUONContour* contour;
  while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
  {
    AliMpArea area(contour->Area());
    xmin = TMath::Min(xmin,area.LeftBorder());
    xmax = TMath::Max(xmax,area.RightBorder());
    ymin = TMath::Min(ymin,area.DownBorder());
    ymax = TMath::Max(ymax,area.UpBorder());
  }

  if (enlarge)
  {
    Double_t xsize = (xmax-xmin);
    Double_t ysize = (ymax-ymin);
    Double_t xshift = xsize*0.1;
    Double_t yshift = ysize*0.1;    
    xmin -= xshift;
    ymin -= yshift;
    xmax = xmin + xsize + xshift*2;
    ymax = ymin + ysize + yshift*2;
  }
}

//_____________________________________________________________________________
void
AliMUONContourMakerTest::PlotSegments(const TObjArray& segments, Int_t lineColor, Int_t lineWidth, Bool_t orientation) const
{
  /// Plot an array of segments 
  
  TIter next(&segments);
  AliMUONSegment* s;
  while ( ( s = static_cast<AliMUONSegment*>(next()) ) )
  {
    TPolyLine* line = new TPolyLine(2);
    line->SetPoint(0,s->StartX(),s->StartY());
    line->SetPoint(1,s->EndX(),s->EndY());
    line->SetLineColor(lineColor);
    line->SetLineWidth(lineWidth);
    ::Plot(*line,orientation);
  }
}

//_____________________________________________________________________________
void 
AliMUONContourMakerTest::Plot(const AliMUONPolygon& polygon, 
                              Int_t lineColor, Int_t lineWidth,
                              Bool_t orientation) const 
{
  /// Plot a polygon
  TPolyLine* line = new TPolyLine(polygon.NumberOfVertices());
  for ( Int_t i = 0; i < polygon.NumberOfVertices(); ++i )
  {
    line->SetPoint(i,polygon.X(i),polygon.Y(i));
  }
  
  line->SetLineColor(lineColor);
  line->SetLineWidth(lineWidth);
  ::Plot(*line,kFALSE);
  if ( orientation ) ::Plot(*line,kTRUE);
}

//_____________________________________________________________________________
void 
AliMUONContourMakerTest::Plot(const AliMUONContour& contour, Int_t lineColor, Int_t lineWidth,
                              Bool_t orientation) const 
{
  /// Plot a contour (i.e. a set of polygons)
  const TObjArray* polygons = contour.Polygons();
  TIter next(polygons);
  AliMUONPolygon* pol;
  while ( ( pol = static_cast<AliMUONPolygon*>(next()) ) )
  {
    Plot(*pol,lineColor,lineWidth,orientation);
  }
}

//_____________________________________________________________________________
void 
AliMUONContourMakerTest::PlotContours(const TObjArray& array, Bool_t orientations) const
{
  /// Plot an array of contours
  TIter next(&array);
  AliMUONContour* contour;
  while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
  {
    Plot(*contour,5,4,orientations);
  }
}

//______________________________________________________________________________
void 
AliMUONContourMakerTest::PrintAsPNG(const char* basename, const TObjArray& contourArray,
                                    const TObjArray* verticals, const TObjArray* horizontals) const
{
  /// Output contours and segments into a PNG file.
  TCanvas* c = new TCanvas(basename,basename,0,0,600,600);
  double xmin,ymin,xmax,ymax;
  GetBoundingBox(contourArray,xmin,ymin,xmax,ymax,kTRUE);
  c->Range(xmin,ymin,xmax,ymax);
  PlotContours(contourArray,kTRUE);
  c->Modified();
  c->Update();
  TString name(Form("%s",basename));
  name.ReplaceAll("/","_");
  c->Print(Form("%s.png",name.Data()));
  if ( verticals || horizontals ) 
  {
    c->Clear();
    if ( verticals ) PlotSegments(*verticals,1);
    if ( horizontals) PlotSegments(*horizontals,2);
    c->Modified();
    c->Update();
    name = Form("%s",basename);
    name.ReplaceAll("/","_");
    c->Print(Form("%s-segments.png",name.Data()));
  }
  delete c;
}

 AliMUONContourMakerTest.cxx:1
 AliMUONContourMakerTest.cxx:2
 AliMUONContourMakerTest.cxx:3
 AliMUONContourMakerTest.cxx:4
 AliMUONContourMakerTest.cxx:5
 AliMUONContourMakerTest.cxx:6
 AliMUONContourMakerTest.cxx:7
 AliMUONContourMakerTest.cxx:8
 AliMUONContourMakerTest.cxx:9
 AliMUONContourMakerTest.cxx:10
 AliMUONContourMakerTest.cxx:11
 AliMUONContourMakerTest.cxx:12
 AliMUONContourMakerTest.cxx:13
 AliMUONContourMakerTest.cxx:14
 AliMUONContourMakerTest.cxx:15
 AliMUONContourMakerTest.cxx:16
 AliMUONContourMakerTest.cxx:17
 AliMUONContourMakerTest.cxx:18
 AliMUONContourMakerTest.cxx:19
 AliMUONContourMakerTest.cxx:20
 AliMUONContourMakerTest.cxx:21
 AliMUONContourMakerTest.cxx:22
 AliMUONContourMakerTest.cxx:23
 AliMUONContourMakerTest.cxx:24
 AliMUONContourMakerTest.cxx:25
 AliMUONContourMakerTest.cxx:26
 AliMUONContourMakerTest.cxx:27
 AliMUONContourMakerTest.cxx:28
 AliMUONContourMakerTest.cxx:29
 AliMUONContourMakerTest.cxx:30
 AliMUONContourMakerTest.cxx:31
 AliMUONContourMakerTest.cxx:32
 AliMUONContourMakerTest.cxx:33
 AliMUONContourMakerTest.cxx:34
 AliMUONContourMakerTest.cxx:35
 AliMUONContourMakerTest.cxx:36
 AliMUONContourMakerTest.cxx:37
 AliMUONContourMakerTest.cxx:38
 AliMUONContourMakerTest.cxx:39
 AliMUONContourMakerTest.cxx:40
 AliMUONContourMakerTest.cxx:41
 AliMUONContourMakerTest.cxx:42
 AliMUONContourMakerTest.cxx:43
 AliMUONContourMakerTest.cxx:44
 AliMUONContourMakerTest.cxx:45
 AliMUONContourMakerTest.cxx:46
 AliMUONContourMakerTest.cxx:47
 AliMUONContourMakerTest.cxx:48
 AliMUONContourMakerTest.cxx:49
 AliMUONContourMakerTest.cxx:50
 AliMUONContourMakerTest.cxx:51
 AliMUONContourMakerTest.cxx:52
 AliMUONContourMakerTest.cxx:53
 AliMUONContourMakerTest.cxx:54
 AliMUONContourMakerTest.cxx:55
 AliMUONContourMakerTest.cxx:56
 AliMUONContourMakerTest.cxx:57
 AliMUONContourMakerTest.cxx:58
 AliMUONContourMakerTest.cxx:59
 AliMUONContourMakerTest.cxx:60
 AliMUONContourMakerTest.cxx:61
 AliMUONContourMakerTest.cxx:62
 AliMUONContourMakerTest.cxx:63
 AliMUONContourMakerTest.cxx:64
 AliMUONContourMakerTest.cxx:65
 AliMUONContourMakerTest.cxx:66
 AliMUONContourMakerTest.cxx:67
 AliMUONContourMakerTest.cxx:68
 AliMUONContourMakerTest.cxx:69
 AliMUONContourMakerTest.cxx:70
 AliMUONContourMakerTest.cxx:71
 AliMUONContourMakerTest.cxx:72
 AliMUONContourMakerTest.cxx:73
 AliMUONContourMakerTest.cxx:74
 AliMUONContourMakerTest.cxx:75
 AliMUONContourMakerTest.cxx:76
 AliMUONContourMakerTest.cxx:77
 AliMUONContourMakerTest.cxx:78
 AliMUONContourMakerTest.cxx:79
 AliMUONContourMakerTest.cxx:80
 AliMUONContourMakerTest.cxx:81
 AliMUONContourMakerTest.cxx:82
 AliMUONContourMakerTest.cxx:83
 AliMUONContourMakerTest.cxx:84
 AliMUONContourMakerTest.cxx:85
 AliMUONContourMakerTest.cxx:86
 AliMUONContourMakerTest.cxx:87
 AliMUONContourMakerTest.cxx:88
 AliMUONContourMakerTest.cxx:89
 AliMUONContourMakerTest.cxx:90
 AliMUONContourMakerTest.cxx:91
 AliMUONContourMakerTest.cxx:92
 AliMUONContourMakerTest.cxx:93
 AliMUONContourMakerTest.cxx:94
 AliMUONContourMakerTest.cxx:95
 AliMUONContourMakerTest.cxx:96
 AliMUONContourMakerTest.cxx:97
 AliMUONContourMakerTest.cxx:98
 AliMUONContourMakerTest.cxx:99
 AliMUONContourMakerTest.cxx:100
 AliMUONContourMakerTest.cxx:101
 AliMUONContourMakerTest.cxx:102
 AliMUONContourMakerTest.cxx:103
 AliMUONContourMakerTest.cxx:104
 AliMUONContourMakerTest.cxx:105
 AliMUONContourMakerTest.cxx:106
 AliMUONContourMakerTest.cxx:107
 AliMUONContourMakerTest.cxx:108
 AliMUONContourMakerTest.cxx:109
 AliMUONContourMakerTest.cxx:110
 AliMUONContourMakerTest.cxx:111
 AliMUONContourMakerTest.cxx:112
 AliMUONContourMakerTest.cxx:113
 AliMUONContourMakerTest.cxx:114
 AliMUONContourMakerTest.cxx:115
 AliMUONContourMakerTest.cxx:116
 AliMUONContourMakerTest.cxx:117
 AliMUONContourMakerTest.cxx:118
 AliMUONContourMakerTest.cxx:119
 AliMUONContourMakerTest.cxx:120
 AliMUONContourMakerTest.cxx:121
 AliMUONContourMakerTest.cxx:122
 AliMUONContourMakerTest.cxx:123
 AliMUONContourMakerTest.cxx:124
 AliMUONContourMakerTest.cxx:125
 AliMUONContourMakerTest.cxx:126
 AliMUONContourMakerTest.cxx:127
 AliMUONContourMakerTest.cxx:128
 AliMUONContourMakerTest.cxx:129
 AliMUONContourMakerTest.cxx:130
 AliMUONContourMakerTest.cxx:131
 AliMUONContourMakerTest.cxx:132
 AliMUONContourMakerTest.cxx:133
 AliMUONContourMakerTest.cxx:134
 AliMUONContourMakerTest.cxx:135
 AliMUONContourMakerTest.cxx:136
 AliMUONContourMakerTest.cxx:137
 AliMUONContourMakerTest.cxx:138
 AliMUONContourMakerTest.cxx:139
 AliMUONContourMakerTest.cxx:140
 AliMUONContourMakerTest.cxx:141
 AliMUONContourMakerTest.cxx:142
 AliMUONContourMakerTest.cxx:143
 AliMUONContourMakerTest.cxx:144
 AliMUONContourMakerTest.cxx:145
 AliMUONContourMakerTest.cxx:146
 AliMUONContourMakerTest.cxx:147
 AliMUONContourMakerTest.cxx:148
 AliMUONContourMakerTest.cxx:149
 AliMUONContourMakerTest.cxx:150
 AliMUONContourMakerTest.cxx:151
 AliMUONContourMakerTest.cxx:152
 AliMUONContourMakerTest.cxx:153
 AliMUONContourMakerTest.cxx:154
 AliMUONContourMakerTest.cxx:155
 AliMUONContourMakerTest.cxx:156
 AliMUONContourMakerTest.cxx:157
 AliMUONContourMakerTest.cxx:158
 AliMUONContourMakerTest.cxx:159
 AliMUONContourMakerTest.cxx:160
 AliMUONContourMakerTest.cxx:161
 AliMUONContourMakerTest.cxx:162
 AliMUONContourMakerTest.cxx:163
 AliMUONContourMakerTest.cxx:164
 AliMUONContourMakerTest.cxx:165
 AliMUONContourMakerTest.cxx:166
 AliMUONContourMakerTest.cxx:167
 AliMUONContourMakerTest.cxx:168
 AliMUONContourMakerTest.cxx:169
 AliMUONContourMakerTest.cxx:170
 AliMUONContourMakerTest.cxx:171
 AliMUONContourMakerTest.cxx:172
 AliMUONContourMakerTest.cxx:173
 AliMUONContourMakerTest.cxx:174
 AliMUONContourMakerTest.cxx:175
 AliMUONContourMakerTest.cxx:176
 AliMUONContourMakerTest.cxx:177
 AliMUONContourMakerTest.cxx:178
 AliMUONContourMakerTest.cxx:179
 AliMUONContourMakerTest.cxx:180
 AliMUONContourMakerTest.cxx:181
 AliMUONContourMakerTest.cxx:182
 AliMUONContourMakerTest.cxx:183
 AliMUONContourMakerTest.cxx:184
 AliMUONContourMakerTest.cxx:185
 AliMUONContourMakerTest.cxx:186
 AliMUONContourMakerTest.cxx:187
 AliMUONContourMakerTest.cxx:188
 AliMUONContourMakerTest.cxx:189
 AliMUONContourMakerTest.cxx:190
 AliMUONContourMakerTest.cxx:191
 AliMUONContourMakerTest.cxx:192
 AliMUONContourMakerTest.cxx:193
 AliMUONContourMakerTest.cxx:194
 AliMUONContourMakerTest.cxx:195
 AliMUONContourMakerTest.cxx:196
 AliMUONContourMakerTest.cxx:197
 AliMUONContourMakerTest.cxx:198
 AliMUONContourMakerTest.cxx:199
 AliMUONContourMakerTest.cxx:200
 AliMUONContourMakerTest.cxx:201
 AliMUONContourMakerTest.cxx:202
 AliMUONContourMakerTest.cxx:203
 AliMUONContourMakerTest.cxx:204
 AliMUONContourMakerTest.cxx:205
 AliMUONContourMakerTest.cxx:206
 AliMUONContourMakerTest.cxx:207
 AliMUONContourMakerTest.cxx:208
 AliMUONContourMakerTest.cxx:209
 AliMUONContourMakerTest.cxx:210
 AliMUONContourMakerTest.cxx:211
 AliMUONContourMakerTest.cxx:212
 AliMUONContourMakerTest.cxx:213
 AliMUONContourMakerTest.cxx:214
 AliMUONContourMakerTest.cxx:215
 AliMUONContourMakerTest.cxx:216
 AliMUONContourMakerTest.cxx:217
 AliMUONContourMakerTest.cxx:218
 AliMUONContourMakerTest.cxx:219
 AliMUONContourMakerTest.cxx:220
 AliMUONContourMakerTest.cxx:221
 AliMUONContourMakerTest.cxx:222
 AliMUONContourMakerTest.cxx:223
 AliMUONContourMakerTest.cxx:224
 AliMUONContourMakerTest.cxx:225
 AliMUONContourMakerTest.cxx:226
 AliMUONContourMakerTest.cxx:227
 AliMUONContourMakerTest.cxx:228
 AliMUONContourMakerTest.cxx:229
 AliMUONContourMakerTest.cxx:230
 AliMUONContourMakerTest.cxx:231
 AliMUONContourMakerTest.cxx:232
 AliMUONContourMakerTest.cxx:233
 AliMUONContourMakerTest.cxx:234
 AliMUONContourMakerTest.cxx:235
 AliMUONContourMakerTest.cxx:236
 AliMUONContourMakerTest.cxx:237
 AliMUONContourMakerTest.cxx:238
 AliMUONContourMakerTest.cxx:239
 AliMUONContourMakerTest.cxx:240
 AliMUONContourMakerTest.cxx:241
 AliMUONContourMakerTest.cxx:242
 AliMUONContourMakerTest.cxx:243
 AliMUONContourMakerTest.cxx:244
 AliMUONContourMakerTest.cxx:245
 AliMUONContourMakerTest.cxx:246
 AliMUONContourMakerTest.cxx:247
 AliMUONContourMakerTest.cxx:248
 AliMUONContourMakerTest.cxx:249
 AliMUONContourMakerTest.cxx:250
 AliMUONContourMakerTest.cxx:251
 AliMUONContourMakerTest.cxx:252
 AliMUONContourMakerTest.cxx:253
 AliMUONContourMakerTest.cxx:254
 AliMUONContourMakerTest.cxx:255
 AliMUONContourMakerTest.cxx:256
 AliMUONContourMakerTest.cxx:257
 AliMUONContourMakerTest.cxx:258
 AliMUONContourMakerTest.cxx:259
 AliMUONContourMakerTest.cxx:260
 AliMUONContourMakerTest.cxx:261
 AliMUONContourMakerTest.cxx:262
 AliMUONContourMakerTest.cxx:263
 AliMUONContourMakerTest.cxx:264
 AliMUONContourMakerTest.cxx:265
 AliMUONContourMakerTest.cxx:266
 AliMUONContourMakerTest.cxx:267
 AliMUONContourMakerTest.cxx:268
 AliMUONContourMakerTest.cxx:269
 AliMUONContourMakerTest.cxx:270
 AliMUONContourMakerTest.cxx:271
 AliMUONContourMakerTest.cxx:272
 AliMUONContourMakerTest.cxx:273
 AliMUONContourMakerTest.cxx:274
 AliMUONContourMakerTest.cxx:275
 AliMUONContourMakerTest.cxx:276