]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSCalibrationSPD.cxx
code updates, Add Muon Corrections, KT4index bug fix
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSPD.cxx
index a7252dfef9b5dda786c6f6f0dfe2fc549523c4ad..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"
+
 ///////////////////////////////////////////////////////////////////////////
 //  Calibration class for set:ITS                   
 //  Specific subdetector implementation for         
 //  Silicon pixels                                  
 //
 //  Modified by D. Elia, G.E. Bruno, H. Tydesjo
-//  March-April 2006
-//  Last mod:  H. Tydesjo  Oct 2007
-//  September   2007: CouplingRowDefault = 0.055 (was 0.047)
-//
 ///////////////////////////////////////////////////////////////////////////
-const Double_t AliITSCalibrationSPD::fgkThreshDefault = 3000.;
-const Double_t AliITSCalibrationSPD::fgkSigmaDefault = 250.;
-const Double_t AliITSCalibrationSPD::fgkCouplColDefault = 0.;
-const Double_t AliITSCalibrationSPD::fgkCouplRowDefault = 0.055;
-const Double_t AliITSCalibrationSPD::fgkBiasVoltageDefault = 18.182;
 
-ClassImp(AliITSCalibrationSPD) 
+ClassImp(AliITSCalibrationSPD)
 
 //______________________________________________________________________
 AliITSCalibrationSPD::AliITSCalibrationSPD():
 AliITSCalibration(),
-fBaseline(0.0),
-fNoise(0.0),
-fThresh(fgkThreshDefault),
-fSigma(fgkSigmaDefault),
-fCouplCol(fgkCouplColDefault),
-fCouplRow(fgkCouplRowDefault),
-fBiasVoltage(fgkBiasVoltageDefault),
 fNrBad(0),
 fBadChannels(0){
   // constructor
 
-   SetThresholds(fgkThreshDefault,fgkSigmaDefault);
-   SetCouplingParam(fgkCouplColDefault,fgkCouplRowDefault);
-   SetBiasVoltage(fgkBiasVoltageDefault);
-   SetNoiseParam(0.,0.);
    SetDataType("simulated");
+   ClearBad();
+}
+//____________________________________________________________________________
+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 bad pixel 
-  //
+  // add single bad pixel 
   fBadChannels.Set(fNrBad*2+2);
   fBadChannels.AddAt(col,fNrBad*2);
   fBadChannels.AddAt(row,fNrBad*2+1);
   fNrBad++;
 }
 //____________________________________________________________________________
-Int_t AliITSCalibrationSPD::GetBadColAt(UInt_t index) {
-  //
+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 (index<fNrBad) {
+  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::GetBadRowAt(UInt_t index) {
-  //
+Int_t AliITSCalibrationSPD::GetBadRowAt(UInt_t index) const {
   // Get row of index-th bad pixel
-  //
-  if (index<fNrBad) {
+  if ((Int_t)index<GetNrBadSingle()) {
     return fBadChannels.At(index*2+1);
   }
-  return -1;
-}
-//____________________________________________________________________________
-Bool_t AliITSCalibrationSPD::IsPixelBad(Int_t col, Int_t row) const {
-  //
-  // Check if pixel (col,row) is bad
-  //
-  for (UInt_t i=0; i<fNrBad; i++) { 
-    if (fBadChannels.At(i*2)==col && fBadChannels.At(i*2+1)==row) {
-      return true;
+  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;
+      }
     }
   }
-  return false;
+  AliError(Form("Index %d is out of bounds - returning -1",index));
+  return -1;
 }
-
 //____________________________________________________________________________
-void AliITSCalibrationSPD::GetBadPixel(Int_t i, Int_t &row, Int_t &col) const {
-  //
-  // i: is the i-th bad pixel in fBadChannels
+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(i<0 || i>=GetNrBad()){
-    AliWarning(Form("Index %d is out of bounds - nothing done",i));
+  if(index>=0 && index<GetNrBadSingle()){
+    col = GetBadColAt(index);
+    row = GetBadRowAt(index);
     return;
   }
-  col = fBadChannels.At(i*2);
-  row = fBadChannels.At(i*2+1);
+  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;
+       }
+      }
+    }
+  }
+  AliError(Form("Index %d is out of bounds - nothing done",index));
 }
 //___________________________________________________________________________
-Int_t  AliITSCalibrationSPD::GetNrBadInColumn(Int_t col) const {
- //
- // Count n. of bad in a given column: col. range [0,159]
- //
- if(col<0 || col>159) {AliWarning("GetNrBadInColumn: wrong column number"); return -1;}
- Int_t bad=0;
- for (UInt_t i=0; i<fNrBad; i++) if (fBadChannels.At(i*2)==col) bad++;
- return bad;
+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;
 }
 //___________________________________________________________________________
 Int_t  AliITSCalibrationSPD::GetNrBadInChip(Int_t chip) const {
- //
- // Count n. of bad in a given chip: chip range [0,4]
- //
- if(chip<0 || chip>4) {AliWarning("GetNrBadInChip: wrong chip number"); return -1;}
- Int_t bad=0;
- for (Int_t col=32*chip; col<32*(chip+1); col++) bad+=GetNrBadInColumn(col);
- return bad;
+  // 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::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;
+  }
+}
+//______________________________________________________________________
+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 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::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);
+  }
 }