File indexing completed on 2023-03-17 10:46:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cmath>
0012 #include <iostream>
0013
0014 #include "CondFormats/CastorObjects/interface/CastorPedestalWidth.h"
0015
0016 namespace {
0017 int offset(int fCapId1, int fCapId2) {
0018
0019
0020
0021
0022
0023 return fCapId1 * 4 + fCapId2;
0024 }
0025 }
0026
0027 CastorPedestalWidth::CastorPedestalWidth(int fId) : mId(fId) {
0028 for (int i = 16; --i >= 0; *(&mSigma00 + i) = 0) {
0029 }
0030 }
0031
0032 float CastorPedestalWidth::getWidth(int fCapId) const { return sqrt(*(getValues() + offset(fCapId, fCapId))); }
0033
0034 float CastorPedestalWidth::getSigma(int fCapId1, int fCapId2) const {
0035 return *(getValues() + offset(fCapId1, fCapId2));
0036 }
0037
0038 void CastorPedestalWidth::setSigma(int fCapId1, int fCapId2, float fSigma) {
0039 *(&mSigma00 + offset(fCapId1, fCapId2)) = fSigma;
0040 }
0041
0042
0043 void CastorPedestalWidth::makeNoise(unsigned fFrames, const double* fGauss, double* fNoise) const {
0044 double s_xx_mean = (getSigma(0, 0) + getSigma(1, 1) + getSigma(2, 2) + getSigma(3, 3)) / 4;
0045 double s_xy_mean = (getSigma(1, 0) + getSigma(2, 1) + getSigma(3, 2) + getSigma(3, 0)) / 4;
0046 double sigma = sqrt(0.5 * (s_xx_mean + sqrt(s_xx_mean * s_xx_mean - 2 * s_xy_mean * s_xy_mean)));
0047 double corr = sigma == 0 ? 0 : 0.5 * s_xy_mean / sigma;
0048 for (unsigned i = 0; i < fFrames; i++) {
0049 fNoise[i] = fGauss[i] * sigma;
0050 if (i > 0)
0051 fNoise[i] += fGauss[i - 1] * corr;
0052 if (i < fFrames - 1)
0053 fNoise[i] += fGauss[i + 1] * corr;
0054 }
0055 }