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$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  TRD calibration class for the single pad status                          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include <TStyle.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TH2F.h>

#include "AliTRDCalPadStatus.h"
#include "AliTRDgeometry.h"
#include "AliTRDpadPlane.h"
#include "AliTRDCalSingleChamberStatus.h"  // test

ClassImp(AliTRDCalPadStatus)

//_____________________________________________________________________________
AliTRDCalPadStatus::AliTRDCalPadStatus()
  :TNamed()
{
  //
  // AliTRDCalPadStatus default constructor
  //

  for (Int_t idet = 0; idet < kNdet; idet++) {
    fROC[idet] = 0;
  }

}

//_____________________________________________________________________________
AliTRDCalPadStatus::AliTRDCalPadStatus(const Text_t *name, const Text_t *title)
  :TNamed(name,title)
{
  //
  // AliTRDCalPadStatus constructor
  //

  for (Int_t isec = 0; isec < kNsect; isec++) {
    for (Int_t ipla = 0; ipla < kNplan; ipla++) {
      for (Int_t icha = 0; icha < kNcham; icha++) {
        Int_t idet = AliTRDgeometry::GetDetector(ipla,icha,isec);
        fROC[idet] = new AliTRDCalSingleChamberStatus(ipla,icha,144);
      }
    }
  }

}

//_____________________________________________________________________________
AliTRDCalPadStatus::AliTRDCalPadStatus(const AliTRDCalPadStatus &c)
  :TNamed(c)
{
  //
  // AliTRDCalPadStatus copy constructor
  //

  ((AliTRDCalPadStatus &) c).Copy(*this);

}

//_____________________________________________________________________________
AliTRDCalPadStatus::~AliTRDCalPadStatus()
{
  //
  // AliTRDCalPadStatus destructor
  //

  for (Int_t idet = 0; idet < kNdet; idet++) {
    if (fROC[idet]) {
      delete fROC[idet];
      fROC[idet] = 0;
    }
  }

}

//_____________________________________________________________________________
AliTRDCalPadStatus &AliTRDCalPadStatus::operator=(const AliTRDCalPadStatus &c)
{
  //
  // Assignment operator
  //

  if (this != &c) ((AliTRDCalPadStatus &) c).Copy(*this);
  return *this;

}

//_____________________________________________________________________________
void AliTRDCalPadStatus::Copy(TObject &c) const
{
  //
  // Copy function
  //

  for (Int_t idet = 0; idet < kNdet; idet++) {
    if (fROC[idet]) {
      fROC[idet]->Copy(*((AliTRDCalPadStatus &) c).fROC[idet]);
    }
  }

  TObject::Copy(c);

}

//_____________________________________________________________________________
Bool_t AliTRDCalPadStatus::CheckStatus(Int_t d, Int_t col, Int_t row, Int_t bitMask) const
{
  //
  // Checks the pad status
  //

  AliTRDCalSingleChamberStatus *roc = GetCalROC(d);
  if (!roc) {
    return kFALSE;
  }
  else {
    return (roc->GetStatus(col, row) & bitMask) ? kTRUE : kFALSE;
  }

}

//_____________________________________________________________________________
AliTRDCalSingleChamberStatus* AliTRDCalPadStatus::GetCalROC(Int_t p, Int_t c, Int_t s) const
{ 
  //
  // Returns the readout chamber of this pad
  //

  return fROC[AliTRDgeometry::GetDetector(p,c,s)];   

}

//_____________________________________________________________________________
TH1F *AliTRDCalPadStatus::MakeHisto1D()
{
  //
  // Make 1D histo
  //

  char  name[1000];
  snprintf(name,1000,"%s Pad 1D",GetTitle());
  TH1F * his = new TH1F(name,name,6, -0.5,5.5);
  his->GetXaxis()->SetBinLabel(1,"Good");
  his->GetXaxis()->SetBinLabel(2,"Masked");
  his->GetXaxis()->SetBinLabel(3,"PadBridgedLeft");
  his->GetXaxis()->SetBinLabel(4,"PadBridgedRight");
  his->GetXaxis()->SetBinLabel(5,"ReadSecond");
  his->GetXaxis()->SetBinLabel(6,"NotConnected");

  for (Int_t idet = 0; idet < kNdet; idet++) 
    {
      if (fROC[idet])
	{
	  for (Int_t ichannel=0; ichannel<fROC[idet]->GetNchannels(); ichannel++)
	    {
	      Int_t status = (Int_t) fROC[idet]->GetStatus(ichannel);
	      if(status==2)  status= 1;
	      if(status==4)  status= 2;
	      if(status==8)  status= 3;
	      if(status==16) status= 4;
	      if(status==32) status= 5;
	      his->Fill(status);
	    }
	}
    }

  return his;

}

//_____________________________________________________________________________
TH2F *AliTRDCalPadStatus::MakeHisto2DSmPl(Int_t sm, Int_t pl)
{
  //
  // Make 2D graph
  //

  gStyle->SetPalette(1);
  AliTRDgeometry *trdGeo = new AliTRDgeometry();
  AliTRDpadPlane *padPlane0 = trdGeo->GetPadPlane(pl,0);
  Double_t row0    = padPlane0->GetRow0();
  Double_t col0    = padPlane0->GetCol0();

  char  name[1000];
  snprintf(name,1000,"%s Pad 2D sm %d pl %d",GetTitle(),sm,pl);
  TH2F * his = new TH2F( name, name, 88,-TMath::Abs(row0),TMath::Abs(row0)
                                   ,148,-TMath::Abs(col0),TMath::Abs(col0));

  // Where we begin
  Int_t offsetsmpl = 30*sm+pl;

  for (Int_t k = 0; k < kNcham; k++){
    Int_t det = offsetsmpl+k*6;
    if (fROC[det]){
      AliTRDCalSingleChamberStatus * calRoc = fROC[det];
      for (Int_t icol=0; icol<calRoc->GetNcols(); icol++){
	for (Int_t irow=0; irow<calRoc->GetNrows(); irow++){
	  Int_t binz     = 0;
	  Int_t kb       = kNcham-1-k;
	  Int_t krow     = calRoc->GetNrows()-1-irow;
	  Int_t kcol     = calRoc->GetNcols()-1-icol;
	  if(kb > 2) binz = 16*(kb-1)+12+krow+1+2*(kb+1);
	  else binz = 16*kb+krow+1+2*(kb+1); 
	  Int_t biny = kcol+1+2;
	  Float_t value = calRoc->GetStatus(icol,irow);
	  his->SetBinContent(binz,biny,value);
	}
      }
      for(Int_t icol = 1; icol < 147; icol++){
	for(Int_t l = 0; l < 2; l++){
	  Int_t binz     = 0;
	  Int_t kb       = kNcham-1-k;
	  if(kb > 2) binz = 16*(kb-1)+12+1+2*(kb+1)-(l+1);
	  else binz = 16*kb+1+2*(kb+1)-(l+1); 
	  his->SetBinContent(binz,icol,50.0);
	}
      }
    }
  }
  for(Int_t icol = 1; icol < 147; icol++){
    his->SetBinContent(88,icol,50.0);
    his->SetBinContent(87,icol,50.0);
  }
  for(Int_t irow = 1; irow < 89; irow++){
    his->SetBinContent(irow,1,50.0);
    his->SetBinContent(irow,2,50.0);
    his->SetBinContent(irow,147,50.0);
    his->SetBinContent(irow,148,50.0);
  }

  his->SetXTitle("z (cm)");
  his->SetYTitle("y (cm)");
  his->SetMaximum(50);
  his->SetMinimum(0.0);
  his->SetStats(0);

  return his;

}

//_____________________________________________________________________________
void AliTRDCalPadStatus::PlotHistos2DSm(Int_t sm, const Char_t *name)
{
  //
  // Make 2D graph
  //

  gStyle->SetPalette(1);
  TCanvas *c1 = new TCanvas(name,name,50,50,600,800);
  c1->Divide(3,2);
  c1->cd(1);
  MakeHisto2DSmPl(sm,0)->Draw("colz");
  c1->cd(2);
  MakeHisto2DSmPl(sm,1)->Draw("colz");
  c1->cd(3);
  MakeHisto2DSmPl(sm,2)->Draw("colz");
  c1->cd(4);
  MakeHisto2DSmPl(sm,3)->Draw("colz");
  c1->cd(5);
  MakeHisto2DSmPl(sm,4)->Draw("colz");
  c1->cd(6);
  MakeHisto2DSmPl(sm,5)->Draw("colz");

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