]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSCalibrationSPD.cxx
Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSPD.cxx
index 70570c75a1232ac3e452183c3d725a46b2c25c61..917078ca97d68d3382d1019c2cb0454ee8247980 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-
-
-
+#include "TArrayI.h"
 #include "AliITSCalibrationSPD.h"
 
-const Double_t AliITSCalibrationSPD::fgkThreshDefault = 3000.;
-const Double_t AliITSCalibrationSPD::fgkSigmaDefault = 250.;
-const Double_t AliITSCalibrationSPD::fgkCouplColDefault = 0.;
-const Double_t AliITSCalibrationSPD::fgkCouplRowDefault = 0.047;
-const Double_t AliITSCalibrationSPD::fgkBiasVoltageDefault = 18.182;
-
-ClassImp(AliITSCalibrationSPD) 
 ///////////////////////////////////////////////////////////////////////////
 //  Calibration class for set:ITS                   
 //  Specific subdetector implementation for         
 //  Silicon pixels                                  
 //
 //  Modified by D. Elia, G.E. Bruno, H. Tydesjo
-//  March-April 2006
-//
 ///////////////////////////////////////////////////////////////////////////
 
+ClassImp(AliITSCalibrationSPD)
+
 //______________________________________________________________________
 AliITSCalibrationSPD::AliITSCalibrationSPD():
 AliITSCalibration(),
-fBaseline(0.0),
-fNoise(0.0),
-fThresh(fgkThreshDefault),
-fSigma(fgkSigmaDefault),
-fCouplCol(fgkCouplColDefault),
-fCouplRow(fgkCouplRowDefault),
-fBiasVoltage(fgkBiasVoltageDefault),
-fNrDead(0),
-fDeadChannels(0),
-fNrNoisy(0),
-fNoisyChannels(0){
+fNrBad(0),
+fBadChannels(0){
   // constructor
 
-   SetThresholds(fgkThreshDefault,fgkSigmaDefault);
-   SetCouplingParam(fgkCouplColDefault,fgkCouplRowDefault);
-   SetBiasVoltage(fgkBiasVoltageDefault);
-   SetNoiseParam(0.,0.);
    SetDataType("simulated");
+   ClearBad();
 }
-//_________________________________________________________________________
-
-void AliITSCalibrationSPD::AddDead(UInt_t col, UInt_t row) {
-  //
-  // Add a dead channel to fDeadChannel array
-  //
-  fDeadChannels.Set(fNrDead*2+2);
-  fDeadChannels.AddAt(col,fNrDead*2);
-  fDeadChannels.AddAt(row,fNrDead*2+1);
-  fNrDead++;
-}
-//_________________________________________________________________________
-Int_t AliITSCalibrationSPD::GetDeadColAt(UInt_t index) {
-  // 
-  // Returns column of index-th dead channel
-  //
-  if (index<fNrDead) {
-    return fDeadChannels.At(index*2);
+//____________________________________________________________________________
+void AliITSCalibrationSPD::ClearBad() {
+  // clear all bad pixels (single+chips)
+  fBadChannels.Reset();
+  fNrBad=0;
+  for (UInt_t chip=0; chip<5; chip++) {
+    fBadChip[chip]=kFALSE;
   }
+}
+//____________________________________________________________________________
+void AliITSCalibrationSPD::AddBad(UInt_t col, UInt_t row) {
+  // add single bad pixel 
+  fBadChannels.Set(fNrBad*2+2);
+  fBadChannels.AddAt(col,fNrBad*2);
+  fBadChannels.AddAt(row,fNrBad*2+1);
+  fNrBad++;
+}
+//____________________________________________________________________________
+void AliITSCalibrationSPD::SetChipBad(UInt_t chip) {
+  // set full chip bad
+  if (chip>=5) {AliError("Wrong chip number");
+  }
+  else {
+    fBadChip[chip]=kTRUE;
+  }
+}
+//____________________________________________________________________________
+void AliITSCalibrationSPD::UnSetChipBad(UInt_t chip) {
+  // unset full chip bad
+  if (chip>=5 ) {AliError("Wrong chip number");
+  }
+  else {
+    fBadChip[chip]=kFALSE;
+  }
+}
+//____________________________________________________________________________
+Int_t AliITSCalibrationSPD::GetBadColAt(UInt_t index) const {
+  // Get column of index-th bad pixel
+  if ((Int_t)index<GetNrBadSingle()) {
+    return fBadChannels.At(index*2);
+  }
+  else {
+    Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
+    Int_t badChipsFound =0;
+    for (UInt_t chip=0; chip<5; chip++) {
+      if (fBadChip[chip]) badChipsFound++;
+      if (badChipIndex==badChipsFound-1) {
+       Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
+       return chip*32 + badPixelIndex/256;
+      }
+    }
+  }
+  AliError(Form("Index %d is out of bounds - returning -1",index));
   return -1;
 }
-//_________________________________________________________________________
-Int_t AliITSCalibrationSPD::GetDeadRowAt(UInt_t index) {
-  // 
-  // Returns row of index-th dead channel
-  //
-  if (index<fNrDead) {
-    return fDeadChannels.At(index*2+1);
+//____________________________________________________________________________
+Int_t AliITSCalibrationSPD::GetBadRowAt(UInt_t index) const {
+  // Get row of index-th bad pixel
+  if ((Int_t)index<GetNrBadSingle()) {
+    return fBadChannels.At(index*2+1);
+  }
+  else {
+    Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
+    Int_t badChipsFound =0;
+    for (UInt_t chip=0; chip<5; chip++) {
+      if (fBadChip[chip]) badChipsFound++;
+      if (badChipIndex==badChipsFound-1) {
+       Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
+       return badPixelIndex%256;
+      }
+    }
   }
+  AliError(Form("Index %d is out of bounds - returning -1",index));
   return -1;
 }
-//_________________________________________________________________________
-Bool_t AliITSCalibrationSPD::IsPixelDead(Int_t col, Int_t row) const {
-  //
-  // Check if pixel (col,row) is dead
-  //
-  for (UInt_t i=0; i<fNrDead; i++) { 
-    if (fDeadChannels.At(i*2)==col && fDeadChannels.At(i*2+1)==row) {
-      return true;
+//____________________________________________________________________________
+void AliITSCalibrationSPD::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const {
+  // i: is the i-th bad pixel in single bad pixel list
+  // row: is the corresponding row (-1 if i is out of range)
+  // col: is the corresponding column (-1 if i is out of range)
+  row = -1;
+  col = -1;
+  if(index>=0 && index<GetNrBadSingle()){
+    col = GetBadColAt(index);
+    row = GetBadRowAt(index);
+    return;
+  }
+  else {
+    if (index>=0) {
+      Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
+      Int_t badChipsFound =0;
+      for (UInt_t chip=0; chip<5; chip++) {
+       if (fBadChip[chip]) badChipsFound++;
+       if (badChipIndex==badChipsFound-1) {
+         Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
+         col = chip*32 + badPixelIndex/256;
+         row = badPixelIndex%256;
+         return;
+       }
+      }
     }
   }
-  return false;
+  AliError(Form("Index %d is out of bounds - nothing done",index));
 }
-
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 //___________________________________________________________________________
-// THIS METHOD SHOULD BE DELETED AS SOON AS POSSIBLE!!!!!!!!!!!!!!!!!!!!!!!!!
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-Bool_t AliITSCalibrationSPD::IsPixelDead(Int_t mod,Int_t ix,Int_t iz) const {
- // Returns kTRUE if pixel is dead
-  // Inputs:
-  //    Int_t mod      module number
-  //    Int_t ix       x pixel number
-  //    Int_t iz       z pixel number
-  // Outputs:
-  //    none.
-  // Return:
-  //    kFALSE if pixel is alive, or kTRUE if pixel is dead.
-
-  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  Double_t fDeadPixels = 0.01; // fix to keep AliITSsimulationSPDdubna alive!!!
-  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-  Bool_t  dead = kFALSE;
-  Int_t   seed;
-  static TRandom ran; // don't use gRandom. This must not be a true randome
-  // sequence. These sequence must be random one and then fully repetable.
-
-  seed = mod*256*256+iz*256+ix;
-  ran.SetSeed(seed);
-  if(ran.Rndm(0)<fDeadPixels) dead = kTRUE;
-  return dead;
+Int_t  AliITSCalibrationSPD::GetNrBad() const {
+  // Total number of bad pixels (including bad chips) in a given module
+  Int_t bad=0;
+  // single pixels:
+  bad+=fNrBad;
+  // whole chips:
+  for (UInt_t chip=0; chip<5; chip++) {
+    bad+=fBadChip[chip]*32*256;
+  }
+  return bad;
 }
-//____________________________________________________________________________
-void AliITSCalibrationSPD::AddNoisy(UInt_t col, UInt_t row) {
-  //
-  // add noisy pixel 
-  //
-  fDeadChannels.Set(fNrNoisy*2+2);
-  fNoisyChannels.AddAt(col,fNrNoisy*2);
-  fNoisyChannels.AddAt(row,fNrNoisy*2+1);
-  fNrNoisy++;
+//___________________________________________________________________________
+Int_t  AliITSCalibrationSPD::GetNrBadInChip(Int_t chip) const {
+  // Total number of bad pixels (including bad chips) in a given chip: chip range [0,4]
+  if(chip<0 || chip>4) {AliError("Wrong chip number"); return -1;}
+  if (fBadChip[chip]) return 32*256;
+  else {
+    Int_t bad=0;
+    for (UInt_t i=0; i<fNrBad; i++) {
+      Int_t col = GetBadColAt(i);
+      if (col!=-1) {
+       if (GetChipIndexFromCol(col)==chip) bad++;
+      }
+    }
+    return bad;
+  }
 }
-//____________________________________________________________________________
-Int_t AliITSCalibrationSPD::GetNoisyColAt(UInt_t index) {
-  //
-  // Get column of index-th noisy pixel
-  //
-  if (index<fNrNoisy) {
-    return fNoisyChannels.At(index*2);
+//___________________________________________________________________________
+Int_t  AliITSCalibrationSPD::GetNrBadInColumn(Int_t col) const {
+  // Total number of bad pixels (including bad chips) in a given column: col. range [0,159]
+  if(col<0 || col>159) {AliError("Wrong column number"); return -1;}
+  if (fBadChip[GetChipIndexFromCol(col)]) return 256;
+  else {
+    Int_t bad=0;
+    for (UInt_t i=0; i<fNrBad; i++) {
+      if (GetBadColAt(i)==col) bad++;
+    }
+    return bad;
   }
-  return -1;
 }
-//____________________________________________________________________________
-Int_t AliITSCalibrationSPD::GetNoisyRowAt(UInt_t index) {
-  //
-  // Get row of index-th noisy pixel
-  //
-  if (index<fNrNoisy) {
-    return fNoisyChannels.At(index*2+1);
+//______________________________________________________________________
+Bool_t AliITSCalibrationSPD::IsBad() const {
+  // Are all chips of this module bad?
+  for (UInt_t chip=0; chip<5; chip++) {
+    if (!fBadChip[chip]) return kFALSE;
   }
-  return -1;
+  return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSCalibrationSPD::IsChipBad(Int_t chip) const {
+  // Is the full chip bad?
+  return (GetNrBadInChip(chip)==32*256);
+}
+//______________________________________________________________________
+Bool_t AliITSCalibrationSPD::IsColumnBad(Int_t col) const {
+  // Is the full column bad?
+  return (GetNrBadInColumn(col)==256);
 }
 //____________________________________________________________________________
-Bool_t AliITSCalibrationSPD::IsPixelNoisy(Int_t col, Int_t row) const {
-  //
-  // Check if pixel (col,row) is noisy
-  //
-  for (UInt_t i=0; i<fNrNoisy; i++) { 
-    if (fNoisyChannels.At(i*2)==col && fNoisyChannels.At(i*2+1)==row) {
-      return true;
+Bool_t AliITSCalibrationSPD::IsPixelBad(Int_t col, Int_t row) const {
+  // Is this pixel bad?
+  if(col<0 || col>159) {AliError("Wrong column number"); return kFALSE;}
+  Int_t chip = GetChipIndexFromCol(col);
+  if (fBadChip[chip]) return kTRUE;
+  for (UInt_t i=0; i<fNrBad; i++) { 
+    if (GetBadColAt(i)==col && GetBadRowAt(i)==row) {
+      return kTRUE;
+    }
+  }
+  return kFALSE;
+}
+//______________________________________________________________________
+Int_t AliITSCalibrationSPD::GetChipIndexFromCol(UInt_t col) const {
+  // returns chip index for specific column
+  if(col>=160) {AliWarning("Wrong column number"); return -1;}
+  return col/32;
+}
+//______________________________________________________________________
+void AliITSCalibrationSPD::SetNrBad(UInt_t /*nr*/) {
+  // should not be used anymore !!!
+  AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
+}
+//______________________________________________________________________
+void AliITSCalibrationSPD::Streamer(TBuffer &ruub) {
+  // Stream an object of class AliITSCalibrationSPD.
+  UInt_t ruus, ruuc;
+  if (ruub.IsReading()) {
+    Version_t ruuv = ruub.ReadVersion(&ruus, &ruuc); if (ruuv) { }
+    AliITSCalibration::Streamer(ruub);
+    if (ruuv >= 8) {
+      ruub >> fNrBad;
+      fBadChannels.Streamer(ruub);
+      ruub.ReadStaticArray((bool*)fBadChip);
+    }
+    else {
+      Double_t dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> dummy;
+      ruub >> fNrBad;
+      if (ruuv == 7) {
+       fBadChannels.Streamer(ruub);
+       ruub.ReadStaticArray((bool*)fBadChip);
+      }
+      else {
+       if (ruuv == 6) {
+         fBadChannels.Streamer(ruub);
+       }
+       else {
+         TArrayI fBadChannelsV1;
+         fBadChannelsV1.Streamer(ruub);
+         fBadChannels.Set(fNrBad*2);
+         for (UInt_t i=0; i<fNrBad*2; i++) {
+           fBadChannels[i] = fBadChannelsV1[i];
+         }
+       }
+       for (UInt_t i=0; i<5; i++) {
+         fBadChip[i]=kFALSE;
+       }
+      }
     }
+    ruub.CheckByteCount(ruus, ruuc, AliITSCalibrationSPD::IsA());
+  }
+  else {
+    ruuc = ruub.WriteVersion(AliITSCalibrationSPD::IsA(), kTRUE);
+    AliITSCalibration::Streamer(ruub);
+    ruub << fNrBad;
+    fBadChannels.Streamer(ruub);
+    ruub.WriteArray(fBadChip, 5);
+    ruub.SetByteCount(ruuc, kTRUE);
   }
-  return false;
 }