00001
00007 #include <iostream>
00008 #include <fstream>
00009 #include <cmath>
00010
00011 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00012 #include <iomanip>
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 using namespace std;
00016
00017 L1RCTParameters::L1RCTParameters(double eGammaLSB,
00018 double jetMETLSB,
00019 double eMinForFGCut,
00020 double eMaxForFGCut,
00021 double hOeCut,
00022 double eMinForHoECut,
00023 double eMaxForHoECut,
00024 double hMinForHoECut,
00025 double eActivityCut,
00026 double hActivityCut,
00027 unsigned eicIsolationThreshold,
00028 unsigned jscQuietThresholdBarrel,
00029 unsigned jscQuietThresholdEndcap,
00030 bool noiseVetoHB,
00031 bool noiseVetoHEplus,
00032 bool noiseVetoHEminus,
00033 bool useCorrections,
00034 const std::vector<double>& eGammaECalScaleFactors,
00035 const std::vector<double>& eGammaHCalScaleFactors,
00036 const std::vector<double>& jetMETECalScaleFactors,
00037 const std::vector<double>& jetMETHCalScaleFactors,
00038 const std::vector<double>& ecal_calib,
00039 const std::vector<double>& hcal_calib,
00040 const std::vector<double>& hcal_high_calib,
00041 const std::vector<double>& cross_terms,
00042 const std::vector<double>& lowHoverE_smear,
00043 const std::vector<double>& highHoverE_smear
00044 ) :
00045 eGammaLSB_(eGammaLSB),
00046 jetMETLSB_(jetMETLSB),
00047 eMinForFGCut_(eMinForFGCut),
00048 eMaxForFGCut_(eMaxForFGCut),
00049 hOeCut_(hOeCut),
00050 eMinForHoECut_(eMinForHoECut),
00051 eMaxForHoECut_(eMaxForHoECut),
00052 hMinForHoECut_(hMinForHoECut),
00053 eActivityCut_(eActivityCut),
00054 hActivityCut_(hActivityCut),
00055 eicIsolationThreshold_(eicIsolationThreshold),
00056 jscQuietThresholdBarrel_(jscQuietThresholdBarrel),
00057 jscQuietThresholdEndcap_(jscQuietThresholdEndcap),
00058 noiseVetoHB_(noiseVetoHB),
00059 noiseVetoHEplus_(noiseVetoHEplus),
00060 noiseVetoHEminus_(noiseVetoHEminus),
00061 useCorrections_(useCorrections),
00062 eGammaECalScaleFactors_(eGammaECalScaleFactors),
00063 eGammaHCalScaleFactors_(eGammaHCalScaleFactors),
00064 jetMETECalScaleFactors_(jetMETECalScaleFactors),
00065 jetMETHCalScaleFactors_(jetMETHCalScaleFactors),
00066 HoverE_smear_low_(lowHoverE_smear),
00067 HoverE_smear_high_(highHoverE_smear)
00068 {
00069 ecal_calib_.resize(28);
00070 hcal_calib_.resize(28);
00071 hcal_high_calib_.resize(28);
00072 cross_terms_.resize(28);
00073
00074 for(unsigned i = 0; i < ecal_calib.size(); ++i)
00075 ecal_calib_[i/3].push_back(ecal_calib[i]);
00076 for(unsigned i = 0; i < hcal_calib.size(); ++i)
00077 hcal_calib_[i/3].push_back(hcal_calib[i]);
00078 for(unsigned i = 0; i < hcal_high_calib.size(); ++i)
00079 hcal_high_calib_[i/3].push_back(hcal_high_calib[i]);
00080 for(unsigned i = 0; i < cross_terms.size(); ++i)
00081 cross_terms_[i/6].push_back(cross_terms[i]);
00082 }
00083
00084
00085 unsigned short L1RCTParameters::calcCrate(unsigned short rct_iphi, short ieta) const
00086 {
00087 unsigned short crate = rct_iphi/8;
00088 if(abs(ieta) > 28) crate = rct_iphi / 2;
00089 if (ieta > 0){
00090 crate = crate + 9;
00091 }
00092 return crate;
00093 }
00094
00095
00096 unsigned short L1RCTParameters::calcCard(unsigned short rct_iphi,
00097 unsigned short absIeta) const
00098 {
00099 unsigned short card = 999;
00100
00101 if (absIeta <= 24){
00102 card = ((absIeta-1)/8)*2 + (rct_iphi%8)/4;
00103 }
00104
00105 else if ((absIeta >= 25) && (absIeta <= 28)){
00106 card = 6;
00107 }
00108 else{}
00109 return card;
00110 }
00111
00112
00113 unsigned short L1RCTParameters::calcTower(unsigned short rct_iphi,
00114 unsigned short absIeta) const
00115 {
00116 unsigned short tower = 999;
00117 unsigned short iphi = rct_iphi;
00118 unsigned short regionPhi = (iphi % 8)/4;
00119
00120
00121 if (absIeta <= 24){
00122
00123 tower = ((absIeta-1)%8)*4 + (iphi%4);
00124 }
00125
00126 else if ((absIeta >= 25) && (absIeta <= 28)){
00127 if (regionPhi == 0){
00128
00129 tower = (absIeta-25)*4 + (iphi%4);
00130 }
00131 else {
00132 tower = 28 + iphi % 4 + (25 - absIeta) * 4;
00133 }
00134 }
00135
00136 else if ((absIeta >= 29) && (absIeta <= 32)){
00137
00138
00139 regionPhi = iphi % 2;
00140
00141
00142 tower = (regionPhi) * 4 + absIeta - 29;
00143 }
00144 return tower;
00145 }
00146
00147
00148 short L1RCTParameters::calcIEta(unsigned short iCrate, unsigned short iCard,
00149 unsigned short iTower) const
00150 {
00151 unsigned short absIEta = calcIAbsEta(iCrate, iCard, iTower);
00152 short iEta;
00153 if(iCrate < 9) iEta = -absIEta;
00154 else iEta = absIEta;
00155 return iEta;
00156 }
00157
00158
00159 unsigned short L1RCTParameters::calcIPhi(unsigned short iCrate,
00160 unsigned short iCard,
00161 unsigned short iTower) const
00162 {
00163 short iPhi;
00164 if(iCard < 6)
00165 iPhi = (iCrate % 9) * 8 + (iCard % 2) * 4 + (iTower % 4);
00166 else if(iCard == 6){
00167
00168 if(iTower < 16)
00169 iPhi = (iCrate % 9) * 8 + (iTower % 4);
00170
00171 else
00172 iPhi = (iCrate % 9) * 8 + ((iTower - 16) % 4) + 4;
00173 }
00174
00175 else
00176 iPhi = (iCrate % 9) * 2 + iTower / 4;
00177 return iPhi;
00178 }
00179
00180
00181 unsigned short L1RCTParameters::calcIAbsEta(unsigned short iCrate, unsigned short iCard,
00182 unsigned short iTower) const
00183 {
00184 unsigned short absIEta;
00185 if(iCard < 6)
00186 absIEta = (iCard / 2) * 8 + (iTower / 4) + 1;
00187 else if(iCard == 6) {
00188
00189 if(iTower < 16)
00190 absIEta = 25 + iTower / 4;
00191
00192 else
00193 absIEta = 28 - ((iTower - 16) / 4);
00194 }
00195
00196 else
00197 absIEta = 29 + iTower % 4;
00198 return absIEta;
00199 }
00200
00201 float L1RCTParameters::JetMETTPGSum(const float& ecal, const float& hcal, const unsigned& iAbsEta) const
00202 {
00203 float ecal_c = ecal*jetMETECalScaleFactors_.at(iAbsEta-1);
00204 float hcal_c = hcal*jetMETHCalScaleFactors_.at(iAbsEta-1);
00205 float result = ecal_c + hcal_c;
00206
00207 if(useCorrections_)
00208 {
00209 if(jetMETHCalScaleFactors_.at(iAbsEta-1) != 0)
00210 hcal_c = hcal;
00211
00212 if(jetMETECalScaleFactors_.at(iAbsEta-1) != 0)
00213 ecal_c = ecal*eGammaECalScaleFactors_.at(iAbsEta-1);
00214
00215 result = correctedTPGSum(ecal_c,hcal_c,iAbsEta-1);
00216 }
00217
00218 return result;
00219 }
00220
00221 float L1RCTParameters::EGammaTPGSum(const float& ecal, const float& hcal, const unsigned& iAbsEta) const
00222 {
00223 float ecal_c = ecal*eGammaECalScaleFactors_.at(iAbsEta-1);
00224 float hcal_c = hcal*eGammaHCalScaleFactors_.at(iAbsEta-1);
00225 float result = ecal_c + hcal_c;
00226
00227 if(useCorrections_)
00228 {
00229 if(eGammaHCalScaleFactors_.at(iAbsEta-1) != 0)
00230 hcal_c = hcal;
00231
00232 result = correctedTPGSum(ecal_c,hcal_c,iAbsEta-1);
00233 }
00234
00235 return result;
00236 }
00237
00238
00239 float L1RCTParameters::correctedTPGSum(const float& ecal, const float& hcal, const unsigned& index) const
00240 {
00241 if(index >= 28 && ecal > 120 && hcal > 120) return (ecal + hcal);
00242
00243
00244 if(ecal_calib_.at(index).size() != 3 || hcal_calib_.at(index).size() != 3 ||
00245 hcal_high_calib_.at(index).size() != 3 || cross_terms_.at(index).size() != 6 ||
00246 HoverE_smear_high_.size() <= index || HoverE_smear_low_.size() <= index)
00247 return (ecal+hcal);
00248
00249 double e = ecal, h = hcal;
00250 double ec = 0.0, hc = 0.0, c = 0.0;
00251
00252 ec = (ecal_calib_.at(index).at(0)*std::pow(e,3.) +
00253 ecal_calib_.at(index).at(1)*std::pow(e,2.) +
00254 ecal_calib_.at(index).at(2)*e);
00255
00256 if(e + h < 23)
00257 {
00258 hc = (hcal_calib_.at(index).at(0)*std::pow(h,3.) +
00259 hcal_calib_.at(index).at(1)*std::pow(h,2.) +
00260 hcal_calib_.at(index).at(2)*h);
00261
00262 c = (cross_terms_.at(index).at(0)*std::pow(e, 2.)*h +
00263 cross_terms_.at(index).at(1)*std::pow(h, 2.)*e +
00264 cross_terms_.at(index).at(2)*e*h +
00265 cross_terms_.at(index).at(3)*std::pow(e, 3.)*h +
00266 cross_terms_.at(index).at(4)*std::pow(h, 3.)*e +
00267 cross_terms_.at(index).at(5)*std::pow(h, 2.)*std::pow(e, 2.));
00268 }
00269 else
00270 {
00271 hc = (hcal_high_calib_.at(index).at(0)*std::pow(h,3.) +
00272 hcal_high_calib_.at(index).at(1)*std::pow(h,2.) +
00273 hcal_high_calib_.at(index).at(2)*h);
00274 }
00275
00276 if(h/(e+h) >= 0.05)
00277 {
00278 ec *= HoverE_smear_high_.at(index);
00279 hc *= HoverE_smear_high_.at(index);
00280 c *= HoverE_smear_high_.at(index);
00281 }
00282 else
00283 {
00284 ec *= HoverE_smear_low_.at(index);
00285 }
00286 return ec + hc + c;
00287 }
00288
00289 void
00290 L1RCTParameters::print(std::ostream& s) const {
00291
00292 s << "\nPrinting record L1RCTParametersRcd" <<endl;
00293 s << "\n\"Parameter description\" \n \"Parameter name\" \"Value\" "
00294 << endl;
00295 s << "\ne/gamma least significant bit energy transmitted from receiver cards to EIC cards. \n "
00296 << "eGammaLSB = " << eGammaLSB_ << endl ;
00297 s << "\nLSB of region Et scale from RCT to GCT (GeV) \n "
00298 << "jetMETLSB = " << jetMETLSB_ << endl ;
00299 s << "\nminimum ECAL Et for which fine-grain veto is applied (GeV) \n "
00300 << " eMinForFGCut = " << eMinForFGCut_ << endl ;
00301 s << "\nmaximum ECAL Et for which fine-grain veto is applied (GeV) \n "
00302 << "eMaxForFGCut = " << eMaxForFGCut_ << endl ;
00303 s << "\nmaximum value of (HCAL Et / ECAL Et) \n "
00304 << "hOeCut = " << hOeCut_ << endl ;
00305 s << "\nminimum ECAL Et for which H/E veto is applied (GeV) \n "
00306 << "eMinForHoECut = " << eMinForHoECut_ << endl ;
00307 s << "\nmaximum ECAL Et for which H/E veto is applied (GeV) \n "
00308 << "eMaxForHoECut = " << eMaxForHoECut_ << endl ;
00309 s << "\nminimum HCAL Et for which H/E veto is applied (GeV) \n "
00310 << "hMinForHoECut = " << hMinForHoECut_ << endl ;
00311 s << "\nECAL Et threshold above which tau activity bit is set (GeV) \n "
00312 << "eActivityCut = " << eActivityCut_ << endl ;
00313 s << "\nHCAL Et threshold above which tau activity bit is set (GeV) \n "
00314 << "hActivityCut = " << hActivityCut_ << endl ;
00315 s << "\nNeighboring trigger tower energy minimum threshold that marks candidate as non-isolated. (LSB bits) \n "
00316 << "eicIsolationThreshold = " << eicIsolationThreshold_ << endl ;
00317 s << "\nIf jetMet energy in RCT Barrel Region is below this value, a quiet bit is set. (LSB bits)\n "
00318 << "jscQuietThreshBarrel = " << jscQuietThresholdBarrel_ << endl ;
00319 s << "\nIf jetMet energy in RCT Endcap Region is below this value, a quiet bit is set. (LSB bits) \n "
00320 << "jscQuietThreshEndcap = " << jscQuietThresholdEndcap_ << endl ;
00321 s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT Barrel \n "
00322 << "noiseVetoHB = " << noiseVetoHB_ << endl ;
00323 s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT Encap+ \n "
00324 << "noiseVetoHEplus = " << noiseVetoHEplus_ << endl ;
00325 s << "\nWhen set to TRUE, HCAL energy is ignored if no ECAL energy is present in corresponding trigger tower for RCT Endcap- \n "
00326 << "noiseVetoHEminus = " << noiseVetoHEminus_ << endl ;
00327
00328 s << "\n\neta-dependent multiplicative factors for ECAL Et before summation \n "
00329 << "eGammaECal Scale Factors " << endl;
00330 s << "ieta ScaleFactor" <<endl;
00331 for(int i = 0 ; i<28; i++)
00332 s << setw(4) << i+1 << " " << eGammaECalScaleFactors_.at(i) <<endl;
00333
00334 s << "\n\neta-dependent multiplicative factors for HCAL Et before summation \n "
00335 <<"eGammaHCal Scale Factors "<<endl;
00336 s << "ieta ScaleFactor" <<endl;
00337 for(int i = 0 ; i<28; i++)
00338 s << setw(4) << i+1 << " " << eGammaHCalScaleFactors_.at(i) <<endl;
00339
00340 s << "\n\neta-dependent multiplicative factors for ECAL Et before summation \n "
00341 <<"jetMETECal Scale Factors "<<endl;
00342 s << "ieta ScaleFactor" <<endl;
00343 for(int i = 0 ; i<28; i++)
00344 s<< setw(4) << i+1 << " " << jetMETECalScaleFactors_.at(i) <<endl;
00345
00346 s << "\n\neta-dependent multiplicative factors for HCAL Et before summation \n"
00347 <<"jetMETHCal Scale Factors "<<endl;
00348 s << "ieta ScaleFactor" <<endl;
00349 for(int i = 0 ; i<28; i++)
00350 s << setw(4) <<i+1 << " " << jetMETHCalScaleFactors_.at(i) <<endl;
00351
00352
00353 if(useCorrections_) {
00354 s<< "\n\nUSING calibration variables " <<endl;
00355
00356
00357 s << "\n\nH over E smear low Correction Factors "<<endl;
00358 s << "ieta Correction Factor" <<endl;
00359 for(int i = 0 ; i<28; i++)
00360 s << setw(4) <<i+1 << " " << HoverE_smear_low_.at(i) <<endl;
00361
00362
00363 s << "\n\nH over E smear high Correction Factors "<<endl;
00364 s <<"ieta Correction Factor" <<endl;
00365 for(int i = 0 ; i<28; i++)
00366 s << setw(4) <<i+1 << " " << HoverE_smear_high_.at(i) <<endl;
00367
00368 s << "\n\necal calibrations "<<endl;
00369 s << "ieta CorrFactor1 CorrFactor2 CorrFactor3" <<endl;
00370 int end = ecal_calib_[0].size();
00371 for(int i = 0 ; i<28; i++) {
00372 s << setw(4) << i;
00373 for(int j = 0; j< end ; j++)
00374 s << setw(11) << setprecision(8) << ecal_calib_[i][j] ;
00375
00376 s << endl;
00377
00378 }
00379
00380 s <<"\n\nhcal calibrations "<<endl;
00381 s <<"ieta CorrFactor1 CorrFactor2 CorrFactor3" <<endl;
00382 end = hcal_calib_[0].size();
00383 for(int i = 0 ; i<28; i++) {
00384 s << setw(4) << i;
00385 for(int j = 0; j< end ; j++)
00386 s << setw(11) << setprecision(8) << hcal_calib_[i][j] ;
00387
00388 s << endl;
00389
00390 }
00391 s <<"\n\nhcal_high calibrations "<<endl;
00392 s <<"ieta CorrFactor1 CorrFactor2 CorrFactor3" <<endl;
00393 end = hcal_high_calib_[0].size();
00394 for(int i = 0 ; i<28; i++) {
00395 s << setw(4) << i;
00396 for(int j = 0; j< end ; j++)
00397 s << setw(11) << setprecision(8) << hcal_high_calib_[i][j] ;
00398
00399 s << endl;
00400
00401 }
00402 end = cross_terms_[0].size();
00403 s <<"\n\ncross terms calibrations "<<endl;
00404 s <<"ieta CorrFactor1 CorrFactor2 CorrFactor3 CorrFactor4 CorrFactor5 CorrFactor6" <<endl;
00405 for(int i = 0 ; i<28; i++) {
00406 s << setw(4) << i;
00407 for(int j = 0; j< end ; j++)
00408 s << setw(11) << setprecision(8) << cross_terms_[i][j] ;
00409
00410 s << endl;
00411
00412 }
00413
00414 } else
00415 s<< "\n\nNOT USING calibration variables " <<endl;
00416
00417 s << "\n\n" <<endl;
00418
00419 }