00001
00002
00003
00004
00005
00006 #include "FWCore/Framework/interface/eventsetupdata_registration_macro.h"
00007
00008 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00009 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00010 #include "CalibFormats/HcalObjects/interface/QieShape.h"
00011
00012 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00013 #include "CalibFormats/HcalObjects/interface/HcalCalibrationWidths.h"
00014
00015 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00016
00017 #include <cmath>
00018
00019 HcalDbService::HcalDbService (const edm::ParameterSet& cfg)
00020 :
00021 mQieShapeCache (0),
00022 mPedestals (0),
00023 mPedestalWidths (0),
00024 mGains (0),
00025 mGainWidths (0),
00026 mQIEData(0),
00027 mElectronicsMap(0),
00028 mRespCorrs(0),
00029 mPedestalInADC(cfg.getUntrackedParameter<bool>("PedestalInADC",false))
00030 {}
00031
00032 bool HcalDbService::makeHcalCalibration (const HcalGenericDetId& fId, HcalCalibrations* fObject) const {
00033 if (fObject) {
00034 const HcalPedestal* pedestal = getPedestal (fId);
00035 const HcalGain* gain = getGain (fId);
00036 const HcalRespCorr* respcorr = getHcalRespCorr (fId);
00037
00038 if (mPedestalInADC) {
00039 const HcalQIEShape* shape=getHcalShape();
00040 const HcalQIECoder* coder=getHcalCoder(fId);
00041 if (pedestal && gain && shape && coder && respcorr) {
00042 float pedTrue[4];
00043 for (int i=0; i<4; i++) {
00044 float x=pedestal->getValues()[i];
00045 int x1=(int)std::floor(pedTrue[i]);
00046 int x2=(int)std::floor(pedTrue[i]+1);
00047
00048 float y2=coder->charge(*shape,x2,i);
00049 float y1=coder->charge(*shape,x1,i);
00050 pedTrue[i]=(y2-y1)*(x-x1)+y1;
00051 }
00052 *fObject = HcalCalibrations (gain->getValues (), pedTrue, respcorr->getValue() );
00053 return true;
00054 }
00055 } else {
00056 if (pedestal && gain && respcorr) {
00057 *fObject = HcalCalibrations (gain->getValues (), pedestal->getValues (), respcorr->getValue() );
00058 return true;
00059 }
00060 }
00061 }
00062 return false;
00063 }
00064
00065 void HcalDbService::buildCalibrations() {
00066
00067 if ((!mPedestals) || (!mGains) || (!mQIEData) || (!mRespCorrs)) return;
00068 std::vector<DetId> ids=mPedestals->getAllChannels();
00069
00070 mCalibSet.clear();
00071
00072 HcalCalibrations tool;
00073
00074
00075 for (std::vector<DetId>::const_iterator id=ids.begin(); id!=ids.end(); ++id) {
00076
00077 bool ok=makeHcalCalibration(*id,&tool);
00078
00079 if (ok) mCalibSet.setCalibrations(*id,tool);
00080
00081 }
00082 mCalibSet.sort();
00083 }
00084
00085 bool HcalDbService::makeHcalCalibrationWidth (const HcalGenericDetId& fId, HcalCalibrationWidths* fObject) const {
00086 if (fObject) {
00087 const HcalPedestalWidth* pedestal = getPedestalWidth (fId);
00088 const HcalGainWidth* gain = getGainWidth (fId);
00089 if (mPedestalInADC) {
00090 const HcalQIEShape* shape=getHcalShape();
00091 const HcalQIECoder* coder=getHcalCoder(fId);
00092 if (pedestal && gain && shape && coder) {
00093 float pedTrueWidth[4];
00094 for (int i=0; i<4; i++) {
00095 float x=pedestal->getWidth(i);
00096
00097
00098 float y2=coder->charge(*shape,1,i);
00099 float y1=coder->charge(*shape,0,i);
00100 pedTrueWidth[i]=(y2-y1)*x;
00101 }
00102 *fObject = HcalCalibrationWidths (gain->getValues (), pedTrueWidth);
00103 return true;
00104 }
00105 } else {
00106 if (pedestal && gain) {
00107 float pedestalWidth [4];
00108 for (int i = 0; i < 4; i++) pedestalWidth [i] = pedestal->getWidth (i);
00109 *fObject = HcalCalibrationWidths (gain->getValues (), pedestalWidth);
00110 return true;
00111 }
00112 }
00113 }
00114 return false;
00115 }
00116
00117
00118 const HcalRespCorr* HcalDbService::getHcalRespCorr (const HcalGenericDetId& fId) const {
00119 if (mRespCorrs) {
00120 return mRespCorrs->getValues (fId);
00121 }
00122 return 0;
00123 }
00124
00125 const HcalPedestal* HcalDbService::getPedestal (const HcalGenericDetId& fId) const {
00126 if (mPedestals) {
00127 return mPedestals->getValues (fId);
00128 }
00129 return 0;
00130 }
00131
00132 const HcalPedestalWidth* HcalDbService::getPedestalWidth (const HcalGenericDetId& fId) const {
00133 if (mPedestalWidths) {
00134 return mPedestalWidths->getValues (fId);
00135 }
00136 return 0;
00137 }
00138
00139 const HcalGain* HcalDbService::getGain (const HcalGenericDetId& fId) const {
00140 if (mGains) {
00141 return mGains->getValues(fId);
00142 }
00143 return 0;
00144 }
00145
00146 const HcalGainWidth* HcalDbService::getGainWidth (const HcalGenericDetId& fId) const {
00147 if (mGainWidths) {
00148 return mGainWidths->getValues (fId);
00149 }
00150 return 0;
00151 }
00152
00153 const HcalQIECoder* HcalDbService::getHcalCoder (const HcalGenericDetId& fId) const {
00154 if (mQIEData) {
00155 return mQIEData->getCoder (fId);
00156 }
00157 return 0;
00158 }
00159
00160 const HcalQIEShape* HcalDbService::getHcalShape () const {
00161 if (mQIEData) {
00162 return &mQIEData->getShape ();
00163 }
00164 return 0;
00165 }
00166 const HcalElectronicsMap* HcalDbService::getHcalMapping () const {
00167 return mElectronicsMap;
00168 }
00169
00170 EVENTSETUP_DATA_REG(HcalDbService);