Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
 * =====================================================================================
 *
 *       Filename:  SiPixelGainCalibrationServic.cc
 *
 *    Description:  
 *
 *        Version:  1.0 (some functionality moved from ../interface/SiPixelGainCalibrationService.h)
 *        Created:  04/16/2008 10:35:35 AM
 *
 *         Author:  Evan Friis (evan.klose.friis@cern.ch)
 *                  University of California, Davis
 *
 * =====================================================================================
 */

#include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"

void SiPixelGainCalibrationServiceBase::calibrate(
    uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int* electron) {
  int i = 0;
  for (DigiIterator di = b; di != e; ++di) {
    int row = di->row();
    int col = di->column();

    if (isDead(detID, col, row) || isNoisy(detID, col, row))
      electron[i++] = 0;
    else {
      float DBgain = getGain(detID, col, row);
      float DBpedestal = getPedestal(detID, col, row) * DBgain;
      float vcal = float(di->adc()) * DBgain - DBpedestal;
      electron[i++] = int(vcal * conversionFactor + offset);
    }
  }
  assert(i == (e - b));
}

float SiPixelGainCalibrationService::getPedestal(const uint32_t& detID, const int& col, const int& row) {
  bool isDead = false;
  bool isNoisy = false;
  float pedestalValue = this->getPedestalByPixel(detID, col, row, isDead, isNoisy);
  if (isDead || isNoisy) {
    this->throwExepctionForBadRead("FullCalibration getPedestal()", detID, col, row, pedestalValue);
    return 0.0;
  }
  return pedestalValue;
}

float SiPixelGainCalibrationService::getGain(const uint32_t& detID, const int& col, const int& row) {
  bool isDead = false;
  bool isNoisy = false;
  float gainValue = this->getGainByColumn(detID, col, row, isDead, isNoisy);
  if (isDead || isNoisy) {
    this->throwExepctionForBadRead("FullCalibration getGain()", detID, col, row, gainValue);
    return 0.0;
  }
  return gainValue;
}

bool SiPixelGainCalibrationService::isDead(const uint32_t& detID, const int& col, const int& row) {
  bool isDead = false;
  bool isNoisy = false;
  try {
    this->getPedestalByPixel(detID, col, row, isDead, isNoisy);
  } catch (cms::Exception& e) {
    // Do not stop processing if you check if a nonexistant pixel is dead
    edm::LogInfo("SiPixelGainCalibrationService")
        << "Attempting to check if nonexistant pixel is dead.  Exception message: " << e.what();
    isDead = false;
  }
  return isDead;
}

bool SiPixelGainCalibrationService::isNoisy(const uint32_t& detID, const int& col, const int& row) {
  bool isDead = false;
  bool isNoisy = false;
  try {
    this->getPedestalByPixel(detID, col, row, isDead, isNoisy);
  } catch (cms::Exception& e) {
    // Do not stop processing if you check if a nonexistant pixel is noisy
    edm::LogInfo("SiPixelGainCalibrationService")
        << "Attempting to check if nonexistant pixel is noisy.  Exception message: " << e.what();
    isNoisy = false;
  }
  return isNoisy;
}

bool SiPixelGainCalibrationService::isDeadColumn(const uint32_t& detID, const int& col, const int& row) {
  edm::LogError("SiPixelGainCalibrationService")
      << "You attempted to check if an entire column was dead with a payload that stores information at pixel "
         "granularity.  Please check by pixel. THANKS!";
  return false;
}

bool SiPixelGainCalibrationService::isNoisyColumn(const uint32_t& detID, const int& col, const int& row) {
  edm::LogError("SiPixelGainCalibrationService")
      << "You attempted to check if an entire column was noisy with a payload that stores information at pixel "
         "granularity.  Please check by pixel. THANKS!";
  return false;
}