Go to the documentation of this file.00001 #include <iostream>
00002
00003 #include "FWCore/Utilities/interface/typelookup.h"
00004
00005 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
00006
00007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
00008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEEGeom.h"
00009
00010
00011
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013
00014 using namespace std;
00015
00016 EcalLaserDbService::EcalLaserDbService ()
00017 :
00018 mAlphas_ (0),
00019 mAPDPNRatiosRef_ (0),
00020 mAPDPNRatios_ (0),
00021 mLinearCorrections_ (0)
00022 {}
00023
00024
00025
00026 const EcalLaserAlphas* EcalLaserDbService::getAlphas () const {
00027 return mAlphas_;
00028 }
00029
00030 const EcalLaserAPDPNRatiosRef* EcalLaserDbService::getAPDPNRatiosRef () const {
00031 return mAPDPNRatiosRef_;
00032 }
00033
00034 const EcalLaserAPDPNRatios* EcalLaserDbService::getAPDPNRatios () const {
00035 return mAPDPNRatios_;
00036 }
00037
00038 const EcalLinearCorrections* EcalLaserDbService::getLinearCorrections () const {
00039 return mLinearCorrections_;
00040 }
00041
00042
00043 float EcalLaserDbService::getLaserCorrection (DetId const & xid, edm::Timestamp const & iTime) const {
00044
00045 float correctionFactor = 1.0;
00046
00047 const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& laserRatiosMap = mAPDPNRatios_->getLaserMap();
00048 const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap = mAPDPNRatios_->getTimeMap();
00049 const EcalLaserAPDPNRatiosRefMap& laserRefMap = mAPDPNRatiosRef_->getMap();
00050 const EcalLaserAlphaMap& laserAlphaMap = mAlphas_->getMap();
00051 const EcalLinearCorrections::EcalValueMap& linearValueMap = mLinearCorrections_->getValueMap();
00052 const EcalLinearCorrections::EcalTimeMap& linearTimeMap = mLinearCorrections_->getTimeMap();
00053
00054 EcalLaserAPDPNRatios::EcalLaserAPDPNpair apdpnpair;
00055 EcalLaserAPDPNRatios::EcalLaserTimeStamp timestamp;
00056 EcalLaserAPDPNref apdpnref;
00057 EcalLaserAlpha alpha;
00058 EcalLinearCorrections::Values linValues;
00059 EcalLinearCorrections::Times linTimes;
00060
00061 if (xid.det()==DetId::Ecal) {
00062
00063 } else {
00064
00065 edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL" << endl;
00066 return correctionFactor;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 int iLM;
00085 if (xid.subdetId()==EcalBarrel) {
00086 EBDetId ebid( xid.rawId() );
00087 iLM = MEEBGeom::lmr(ebid.ieta(), ebid.iphi());
00088 } else if (xid.subdetId()==EcalEndcap) {
00089 EEDetId eeid( xid.rawId() );
00090
00091 MEEEGeom::SuperCrysCoord iX = (eeid.ix()-1)/5 + 1;
00092 MEEEGeom::SuperCrysCoord iY = (eeid.iy()-1)/5 + 1;
00093 iLM = MEEEGeom::lmr(iX, iY, eeid.zside());
00094 } else {
00095 edm::LogError("EcalLaserDbService") << " DetId is NOT in ECAL Barrel or Endcap" << endl;
00096 return correctionFactor;
00097 }
00098
00099
00100
00101
00102 EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap::const_iterator itratio = laserRatiosMap.find(xid);
00103 if (itratio != laserRatiosMap.end()) {
00104 apdpnpair = (*itratio);
00105 } else {
00106 edm::LogError("EcalLaserDbService") << "error with laserRatiosMap!" << endl;
00107 return correctionFactor;
00108 }
00109
00110 if (iLM-1< (int)laserTimeMap.size()) {
00111 timestamp = laserTimeMap[iLM-1];
00112 } else {
00113 edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
00114 return correctionFactor;
00115 }
00116
00117 EcalLinearCorrections::EcalValueMap::const_iterator itlin = linearValueMap.find(xid);
00118 if (itlin != linearValueMap.end()) {
00119 linValues = (*itlin);
00120 } else {
00121 edm::LogError("EcalLaserDbService") << "error with linearValueMap!" << endl;
00122 return correctionFactor;
00123 }
00124
00125 if (iLM-1< (int)linearTimeMap.size()) {
00126 linTimes = linearTimeMap[iLM-1];
00127 } else {
00128 edm::LogError("EcalLaserDbService") << "error with laserTimeMap!" << endl;
00129 return correctionFactor;
00130 }
00131
00132 EcalLaserAPDPNRatiosRefMap::const_iterator itref = laserRefMap.find(xid);
00133 if ( itref != laserRefMap.end() ) {
00134 apdpnref = (*itref);
00135 } else {
00136 edm::LogError("EcalLaserDbService") << "error with laserRefMap!" << endl;
00137 return correctionFactor;
00138 }
00139
00140 EcalLaserAlphaMap::const_iterator italpha = laserAlphaMap.find(xid);
00141 if ( italpha != laserAlphaMap.end() ) {
00142 alpha = (*italpha);
00143 } else {
00144 edm::LogError("EcalLaserDbService") << "error with laserAlphaMap!" << endl;
00145 return correctionFactor;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 edm::TimeValue_t t = iTime.value();
00165 edm::TimeValue_t t_i = 0, t_f = 0;
00166 float p_i = 0, p_f = 0;
00167 edm::TimeValue_t lt_i = 0, lt_f = 0;
00168 float lp_i = 0, lp_f = 0;
00169
00170 if ( t >= timestamp.t1.value() && t < timestamp.t2.value() ) {
00171 t_i = timestamp.t1.value();
00172 t_f = timestamp.t2.value();
00173 p_i = apdpnpair.p1;
00174 p_f = apdpnpair.p2;
00175 } else if ( t >= timestamp.t2.value() && t <= timestamp.t3.value() ) {
00176 t_i = timestamp.t2.value();
00177 t_f = timestamp.t3.value();
00178 p_i = apdpnpair.p2;
00179 p_f = apdpnpair.p3;
00180 } else if ( t < timestamp.t1.value() ) {
00181 t_i = timestamp.t1.value();
00182 t_f = timestamp.t2.value();
00183 p_i = apdpnpair.p1;
00184 p_f = apdpnpair.p2;
00185
00186
00187 } else if ( t > timestamp.t3.value() ) {
00188 t_i = timestamp.t2.value();
00189 t_f = timestamp.t3.value();
00190 p_i = apdpnpair.p2;
00191 p_f = apdpnpair.p3;
00192
00193
00194 }
00195
00196 if ( t >= linTimes.t1.value() && t < linTimes.t2.value() ) {
00197 lt_i = linTimes.t1.value();
00198 lt_f = linTimes.t2.value();
00199 lp_i = linValues.p1;
00200 lp_f = linValues.p2;
00201 } else if ( t >= linTimes.t2.value() && t <= linTimes.t3.value() ) {
00202 lt_i = linTimes.t2.value();
00203 lt_f = linTimes.t3.value();
00204 lp_i = linValues.p2;
00205 lp_f = linValues.p3;
00206 } else if ( t < linTimes.t1.value() ) {
00207 lt_i = linTimes.t1.value();
00208 lt_f = linTimes.t2.value();
00209 lp_i = linValues.p1;
00210 lp_f = linValues.p2;
00211
00212
00213 } else if ( t > linTimes.t3.value() ) {
00214 lt_i = linTimes.t2.value();
00215 lt_f = linTimes.t3.value();
00216 lp_i = linValues.p2;
00217 lp_f = linValues.p3;
00218
00219
00220 }
00221
00222 if ( apdpnref != 0 && (t_i - t_f) != 0 && (lt_i - lt_f) != 0) {
00223 float interpolatedLaserResponse = p_i/apdpnref + (t-t_i)*(p_f-p_i)/apdpnref/(t_f-t_i);
00224 float interpolatedLinearResponse = lp_i/apdpnref + (t-lt_i)*(lp_f-lp_i)/apdpnref/(lt_f-lt_i);
00225
00226 if(interpolatedLinearResponse >2 || interpolatedLinearResponse <0.1) interpolatedLinearResponse=1;
00227 if ( interpolatedLaserResponse <= 0 ) {
00228 edm::LogWarning("EcalLaserDbService") << "The interpolated laser correction is <= zero! ("
00229 << interpolatedLaserResponse << "). Using 1. as correction factor.";
00230 return correctionFactor;
00231 } else {
00232
00233 float interpolatedTransparencyResponse = interpolatedLaserResponse / interpolatedLinearResponse;
00234
00235 correctionFactor = 1/( pow(interpolatedTransparencyResponse,alpha) *interpolatedLinearResponse );
00236
00237 }
00238
00239 } else {
00240 edm::LogError("EcalLaserDbService")
00241 << "apdpnref (" << apdpnref << ") "
00242 << "or t_i-t_f (" << (t_i - t_f) << " is zero!";
00243 return correctionFactor;
00244 }
00245
00246 return correctionFactor;
00247 }
00248
00249
00250 TYPELOOKUP_DATA_REG(EcalLaserDbService);