ROOT logo
// $Id$
// $MpId: testAllIndices.C,v 1.7 2005/08/24 08:53:27 ivana Exp $
//
// Test macro for testing which pad is seen as "existing" by AliMpSector.

#if !defined(__CINT__) || defined(__MAKECINT__)

#include "AliMpStation12Type.h"
#include "AliMpPlaneType.h"
#include "AliMpDataProcessor.h"
#include "AliMpDataMap.h"
#include "AliMpDataStreams.h"
#include "AliMpSector.h"
#include "AliMpSectorReader.h"
#include "AliMpSectorSegmentation.h" 
#include "AliMpVPainter.h" 
#include "AliMpRow.h"
#include "AliMpVRowSegment.h"
#include "AliMpMotifMap.h"
#include "AliMpMotifPosition.h"
#include "AliMpMotifType.h"

#include <Riostream.h>
#include <TCanvas.h>
#include <TString.h>
#include <TH2.h>

#endif

TCanvas* CreateTCanvas(const TString& name, const TString& title,
                       AliMq::Station12Type station, AliMp::PlaneType plane)
{
  TString newName(name);
  TString newTitle(title);
  TString unique = AliMq::Station12TypeName(station) + AliMp::PlaneTypeName(plane);
  newName += unique;
  newTitle += unique;
  return new TCanvas(newName.Data(), newTitle.Data());
}                     

void testAllIndices(AliMq::Station12Type station, AliMp::PlaneType plane) 
{
  AliMpDataProcessor mp;
  AliMpDataMap* dataMap = mp.CreateDataMap("data");
  AliMpDataStreams dataStreams(dataMap);

  AliMpSectorReader r(dataStreams, station, plane);

  AliMpSector *sector=r.BuildSector();
  AliMpSectorSegmentation segmentation(sector);
  AliMpVPainter* painter = AliMpVPainter::CreatePainter(sector);

  TCanvas* c1 = CreateTCanvas("view ", 
                              "MSectorPainter::Draw() output (view per pad) ", 
                              station, plane);
  painter->Draw("ZSSMP");
  c1->Update();

  Int_t maxPadIndexX = segmentation.MaxPadIndexX();
  Int_t maxPadIndexY = segmentation.MaxPadIndexY();
  
  // Define histogram limits
  Int_t nx = (maxPadIndexX/10 + 1)*10;
  Int_t ny = (maxPadIndexY/10 + 1)*10;
  TH2C* histo  = new TH2C("histo","Existing pads", 
                          nx, -0.5, nx-0.5, ny, -0.5, ny-0.5);

  Int_t nx2 = 95/2;
  Int_t ny2 = 95/2;
  if (station == AliMq::kStation2) {
    nx2 = 120/2;
    ny2 = 120/2;
  }
  TH2F* histo2 = new TH2F("histo2","Existing positions",
                          nx2, 0, nx2*2, ny2, 0, ny2*2);

  // Define canvas
  TCanvas* c2 = CreateTCanvas("c2 ", "Only existing pads are filled ", station, plane);
  TCanvas* c3 = CreateTCanvas("c3 ", "Positions ", station, plane);
  
  for ( Int_t irow=0; irow<sector->GetNofRows(); irow++ ) {
    AliMpRow* row = sector->GetRow(irow);
    
    for ( Int_t  iseg=0; iseg<row->GetNofRowSegments(); iseg++ ) {
      AliMpVRowSegment* seg = row->GetRowSegment(iseg);
      
      for ( Int_t imot=0; imot<seg->GetNofMotifs(); imot++) {
        AliMpMotifPosition* motifPos 
         = sector->GetMotifMap()->FindMotifPosition(seg->GetMotifPositionId(imot));
         
        for ( Int_t gassNum=0; gassNum<64; gassNum++ ) {
          if (motifPos->GetMotif()->GetMotifType()->FindConnectionByGassiNum(gassNum)){
          
            AliMpPad pad = segmentation.PadByLocation(motifPos->GetID(),gassNum);
            if (pad != AliMpPad::Invalid()) {
              histo->Fill(pad.GetIx(), pad.GetIy());
              histo2->Fill(pad.GetPositionX(), pad.GetPositionY());
            }
          }
        }
      }
    }
  }
  c2->cd();
  histo->Draw("col");
  c3->cd();
  histo2->Draw("box");
}

void testSt12AllIndices()
{
  AliMq::Station12Type  station[2] = { AliMq::kStation1, AliMq::kStation2 }; 
  AliMp::PlaneType      plane[2]   = { AliMp::kBendingPlane, AliMp::kNonBendingPlane };
  
  for ( Int_t is = 0; is < 2; is++ ) {
    for ( Int_t ip = 0; ip < 2; ip++ ) {
    
      cout << "Running testAllIndices for " 
           << AliMq::Station12TypeName(station[is]) << "  "
           << AliMp::PlaneTypeName(plane[ip])  << " ... " << endl;
       
      testAllIndices(station[is], plane[ip]);
    
      cout << "... end running " << endl << endl;
    }  
  }   
}  
  
 testSt12AllIndices.C:1
 testSt12AllIndices.C:2
 testSt12AllIndices.C:3
 testSt12AllIndices.C:4
 testSt12AllIndices.C:5
 testSt12AllIndices.C:6
 testSt12AllIndices.C:7
 testSt12AllIndices.C:8
 testSt12AllIndices.C:9
 testSt12AllIndices.C:10
 testSt12AllIndices.C:11
 testSt12AllIndices.C:12
 testSt12AllIndices.C:13
 testSt12AllIndices.C:14
 testSt12AllIndices.C:15
 testSt12AllIndices.C:16
 testSt12AllIndices.C:17
 testSt12AllIndices.C:18
 testSt12AllIndices.C:19
 testSt12AllIndices.C:20
 testSt12AllIndices.C:21
 testSt12AllIndices.C:22
 testSt12AllIndices.C:23
 testSt12AllIndices.C:24
 testSt12AllIndices.C:25
 testSt12AllIndices.C:26
 testSt12AllIndices.C:27
 testSt12AllIndices.C:28
 testSt12AllIndices.C:29
 testSt12AllIndices.C:30
 testSt12AllIndices.C:31
 testSt12AllIndices.C:32
 testSt12AllIndices.C:33
 testSt12AllIndices.C:34
 testSt12AllIndices.C:35
 testSt12AllIndices.C:36
 testSt12AllIndices.C:37
 testSt12AllIndices.C:38
 testSt12AllIndices.C:39
 testSt12AllIndices.C:40
 testSt12AllIndices.C:41
 testSt12AllIndices.C:42
 testSt12AllIndices.C:43
 testSt12AllIndices.C:44
 testSt12AllIndices.C:45
 testSt12AllIndices.C:46
 testSt12AllIndices.C:47
 testSt12AllIndices.C:48
 testSt12AllIndices.C:49
 testSt12AllIndices.C:50
 testSt12AllIndices.C:51
 testSt12AllIndices.C:52
 testSt12AllIndices.C:53
 testSt12AllIndices.C:54
 testSt12AllIndices.C:55
 testSt12AllIndices.C:56
 testSt12AllIndices.C:57
 testSt12AllIndices.C:58
 testSt12AllIndices.C:59
 testSt12AllIndices.C:60
 testSt12AllIndices.C:61
 testSt12AllIndices.C:62
 testSt12AllIndices.C:63
 testSt12AllIndices.C:64
 testSt12AllIndices.C:65
 testSt12AllIndices.C:66
 testSt12AllIndices.C:67
 testSt12AllIndices.C:68
 testSt12AllIndices.C:69
 testSt12AllIndices.C:70
 testSt12AllIndices.C:71
 testSt12AllIndices.C:72
 testSt12AllIndices.C:73
 testSt12AllIndices.C:74
 testSt12AllIndices.C:75
 testSt12AllIndices.C:76
 testSt12AllIndices.C:77
 testSt12AllIndices.C:78
 testSt12AllIndices.C:79
 testSt12AllIndices.C:80
 testSt12AllIndices.C:81
 testSt12AllIndices.C:82
 testSt12AllIndices.C:83
 testSt12AllIndices.C:84
 testSt12AllIndices.C:85
 testSt12AllIndices.C:86
 testSt12AllIndices.C:87
 testSt12AllIndices.C:88
 testSt12AllIndices.C:89
 testSt12AllIndices.C:90
 testSt12AllIndices.C:91
 testSt12AllIndices.C:92
 testSt12AllIndices.C:93
 testSt12AllIndices.C:94
 testSt12AllIndices.C:95
 testSt12AllIndices.C:96
 testSt12AllIndices.C:97
 testSt12AllIndices.C:98
 testSt12AllIndices.C:99
 testSt12AllIndices.C:100
 testSt12AllIndices.C:101
 testSt12AllIndices.C:102
 testSt12AllIndices.C:103
 testSt12AllIndices.C:104
 testSt12AllIndices.C:105
 testSt12AllIndices.C:106
 testSt12AllIndices.C:107
 testSt12AllIndices.C:108
 testSt12AllIndices.C:109
 testSt12AllIndices.C:110
 testSt12AllIndices.C:111
 testSt12AllIndices.C:112
 testSt12AllIndices.C:113
 testSt12AllIndices.C:114
 testSt12AllIndices.C:115
 testSt12AllIndices.C:116
 testSt12AllIndices.C:117
 testSt12AllIndices.C:118
 testSt12AllIndices.C:119
 testSt12AllIndices.C:120
 testSt12AllIndices.C:121
 testSt12AllIndices.C:122
 testSt12AllIndices.C:123
 testSt12AllIndices.C:124
 testSt12AllIndices.C:125
 testSt12AllIndices.C:126
 testSt12AllIndices.C:127
 testSt12AllIndices.C:128
 testSt12AllIndices.C:129