CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondFormats/CastorObjects/src/CastorPedestalWidth.cc

Go to the documentation of this file.
00001 
00011 #include <math.h>
00012 #include <iostream>
00013 
00014 #include "CondFormats/CastorObjects/interface/CastorPedestalWidth.h"
00015 
00016 namespace {
00017   int offset (int fCapId1, int fCapId2) {
00018     //    static int offsets [4] = {0, 1, 3, 6};
00019     //    if (fCapId1 < fCapId2) { // swap
00020     //      int tmp = fCapId1; fCapId1 = fCapId2; fCapId2 = tmp;
00021     //    }
00022     //    return offsets [fCapId1] + fCapId2;
00023     return fCapId1*4 + fCapId2;
00024   }
00025 }
00026 
00027 CastorPedestalWidth::CastorPedestalWidth (int fId) : mId (fId) {
00028   for (int i = 16; --i >= 0; *(&mSigma00 + i) = 0) {}
00029 }
00030 
00031 float CastorPedestalWidth::getWidth (int fCapId) const {
00032   return sqrt (*(getValues () + offset (fCapId, fCapId)));
00033 }
00034 
00035 float CastorPedestalWidth::getSigma (int fCapId1, int fCapId2) const {
00036   return *(getValues () + offset (fCapId1, fCapId2));
00037 }
00038 
00039 void CastorPedestalWidth::setSigma (int fCapId1, int fCapId2, float fSigma) {
00040   *(&mSigma00 + offset (fCapId1, fCapId2)) = fSigma;
00041 }
00042 
00043 // produces pedestal noise in assumption of near correlations and small variations
00044 void CastorPedestalWidth::makeNoise (unsigned fFrames, const double* fGauss, double* fNoise) const {
00045   double s_xx_mean = (getSigma (0,0) + getSigma (1,1) + getSigma (2,2) + getSigma (3,3)) / 4;
00046   double s_xy_mean = (getSigma (1,0) + getSigma (2,1) + getSigma (3,2) + getSigma (3,0)) / 4;
00047   double sigma = sqrt (0.5 * (s_xx_mean + sqrt (s_xx_mean*s_xx_mean - 2*s_xy_mean*s_xy_mean)));
00048   double corr = sigma == 0 ? 0 : 0.5*s_xy_mean / sigma;
00049   for (unsigned i = 0; i < fFrames; i++) {
00050     fNoise [i] = fGauss[i]*sigma;
00051     if (i > 0) fNoise [i] += fGauss[i-1]*corr;
00052     if (i < fFrames-1) fNoise [i] += fGauss[i+1]*corr;
00053   }
00054 }