File indexing completed on 2024-04-06 12:24:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0011 #include "CondFormats/DataRecord/interface/EcalClusterEnergyCorrectionObjectSpecificParametersRcd.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h"
0015 #include "CondFormats/EcalObjects/interface/EcalClusterEnergyCorrectionObjectSpecificParameters.h"
0016
0017 class EcalClusterEnergyCorrectionObjectSpecific : public EcalClusterFunctionBaseClass {
0018 public:
0019 EcalClusterEnergyCorrectionObjectSpecific(const edm::ParameterSet &, edm::ConsumesCollector iC)
0020 : paramsToken_(iC.esConsumes()) {}
0021
0022
0023 const EcalClusterEnergyCorrectionObjectSpecificParameters *getParameters() const { return params_; }
0024
0025 void checkInit() const;
0026
0027
0028 float getValue(const reco::SuperCluster &, const int mode) const override;
0029 float getValue(const reco::BasicCluster &, const EcalRecHitCollection &) const override { return 0.; };
0030
0031
0032 void init(const edm::EventSetup &es) override;
0033
0034 private:
0035 float fEta(float energy, float eta, int algorithm) const;
0036 float fBremEta(float sigmaPhiSigmaEta, float eta, int algorithm) const;
0037 float fEt(float et, int algorithm) const;
0038 float fEnergy(float e, int algorithm) const;
0039
0040 const edm::ESGetToken<EcalClusterEnergyCorrectionObjectSpecificParameters,
0041 EcalClusterEnergyCorrectionObjectSpecificParametersRcd>
0042 paramsToken_;
0043 const EcalClusterEnergyCorrectionObjectSpecificParameters *params_ = nullptr;
0044 };
0045
0046 void EcalClusterEnergyCorrectionObjectSpecific::init(const edm::EventSetup &es) { params_ = &es.getData(paramsToken_); }
0047
0048 void EcalClusterEnergyCorrectionObjectSpecific::checkInit() const {
0049 if (!params_) {
0050
0051 throw cms::Exception("EcalClusterEnergyCorrectionObjectSpecific::checkInit()")
0052 << "Trying to access an uninitialized correction function.\n"
0053 "Please call `init( edm::EventSetup &)' before any use of the function.\n";
0054 }
0055 }
0056
0057
0058
0059 float EcalClusterEnergyCorrectionObjectSpecific::fEta(float energy, float eta, int algorithm) const {
0060
0061
0062
0063 if (algorithm != 0)
0064 return energy;
0065
0066 float ieta = fabs(eta) * (5 / 0.087);
0067 float p0 = (params_->params())[0];
0068 float p1 = (params_->params())[1];
0069
0070
0071
0072 float correctedEnergy = energy;
0073 if (ieta < p0)
0074 correctedEnergy = energy;
0075 else
0076 correctedEnergy = energy / (1.0 + p1 * (ieta - p0) * (ieta - p0));
0077
0078 return correctedEnergy;
0079 }
0080
0081 float EcalClusterEnergyCorrectionObjectSpecific::fBremEta(float sigmaPhiSigmaEta, float eta, int algorithm) const {
0082 const float etaCrackMin = 1.44;
0083 const float etaCrackMax = 1.56;
0084
0085
0086 const int nBinsEta = 14;
0087 float leftEta[nBinsEta] = {0.02, 0.25, 0.46, 0.81, 0.91, 1.01, 1.16, etaCrackMax, 1.653, 1.8, 2.0, 2.2, 2.3, 2.4};
0088 float rightEta[nBinsEta] = {0.25, 0.42, 0.77, 0.91, 1.01, 1.13, etaCrackMin, 1.653, 1.8, 2.0, 2.2, 2.3, 2.4, 2.5};
0089
0090 float xcorr[nBinsEta];
0091
0092 float par0[nBinsEta];
0093 float par1[nBinsEta];
0094 float par2[nBinsEta];
0095 float par3[nBinsEta];
0096 float par4[nBinsEta];
0097
0098 float sigmaPhiSigmaEtaMin = 0.8;
0099 float sigmaPhiSigmaEtaMax = 5.;
0100
0101 float sigmaPhiSigmaEtaFit = -1;
0102
0103
0104
0105 if (sigmaPhiSigmaEta < sigmaPhiSigmaEtaMin)
0106 sigmaPhiSigmaEta = sigmaPhiSigmaEtaMin;
0107 if (sigmaPhiSigmaEta > sigmaPhiSigmaEtaMax)
0108 sigmaPhiSigmaEta = sigmaPhiSigmaEtaMax;
0109
0110
0111 if (std::abs(eta) < leftEta[0]) {
0112 eta = 0.02;
0113 }
0114
0115 if (std::abs(eta) >= rightEta[nBinsEta - 1]) {
0116 eta = 2.49;
0117 }
0118
0119 int tmpEta = -1;
0120 for (int iEta = 0; iEta < nBinsEta; ++iEta) {
0121 if (leftEta[iEta] <= std::abs(eta) && std::abs(eta) < rightEta[iEta]) {
0122 tmpEta = iEta;
0123 }
0124 }
0125
0126 if (algorithm == 0) {
0127
0128 xcorr[0] = (params_->params())[2];
0129 xcorr[1] = (params_->params())[3];
0130 xcorr[2] = (params_->params())[4];
0131 xcorr[3] = (params_->params())[5];
0132 xcorr[4] = (params_->params())[6];
0133 xcorr[5] = (params_->params())[7];
0134 xcorr[6] = (params_->params())[8];
0135 xcorr[7] = (params_->params())[9];
0136 xcorr[8] = (params_->params())[10];
0137 xcorr[9] = (params_->params())[11];
0138 xcorr[10] = (params_->params())[12];
0139 xcorr[11] = (params_->params())[13];
0140 xcorr[12] = (params_->params())[14];
0141 xcorr[13] = (params_->params())[15];
0142
0143 par0[0] = (params_->params())[16];
0144 par1[0] = (params_->params())[17];
0145 par2[0] = (params_->params())[18];
0146 par3[0] = (params_->params())[19];
0147 par4[0] = (params_->params())[20];
0148
0149 par0[1] = (params_->params())[21];
0150 par1[1] = (params_->params())[22];
0151 par2[1] = (params_->params())[23];
0152 par3[1] = (params_->params())[24];
0153 par4[1] = (params_->params())[25];
0154
0155 par0[2] = (params_->params())[26];
0156 par1[2] = (params_->params())[27];
0157 par2[2] = (params_->params())[28];
0158 par3[2] = (params_->params())[29];
0159 par4[2] = (params_->params())[30];
0160
0161 par0[3] = (params_->params())[31];
0162 par1[3] = (params_->params())[32];
0163 par2[3] = (params_->params())[33];
0164 par2[4] = (params_->params())[34];
0165 par2[5] = (params_->params())[35];
0166
0167 par0[4] = (params_->params())[36];
0168 par1[4] = (params_->params())[37];
0169 par2[4] = (params_->params())[38];
0170 par3[4] = (params_->params())[39];
0171 par4[4] = (params_->params())[40];
0172
0173 par0[5] = (params_->params())[41];
0174 par1[5] = (params_->params())[42];
0175 par2[5] = (params_->params())[43];
0176 par3[5] = (params_->params())[44];
0177 par4[5] = (params_->params())[45];
0178
0179 par0[6] = (params_->params())[46];
0180 par1[6] = (params_->params())[47];
0181 par2[6] = (params_->params())[48];
0182 par3[6] = (params_->params())[49];
0183 par4[6] = (params_->params())[50];
0184
0185 par0[7] = (params_->params())[51];
0186 par1[7] = (params_->params())[52];
0187 par2[7] = (params_->params())[53];
0188 par3[7] = (params_->params())[54];
0189 par4[7] = (params_->params())[55];
0190
0191 par0[8] = (params_->params())[56];
0192 par1[8] = (params_->params())[57];
0193 par2[8] = (params_->params())[58];
0194 par3[8] = (params_->params())[59];
0195 par4[8] = (params_->params())[60];
0196
0197 par0[9] = (params_->params())[61];
0198 par1[9] = (params_->params())[62];
0199 par2[9] = (params_->params())[63];
0200 par3[9] = (params_->params())[64];
0201 par4[9] = (params_->params())[65];
0202
0203 par0[10] = (params_->params())[66];
0204 par1[10] = (params_->params())[67];
0205 par2[10] = (params_->params())[68];
0206 par3[10] = (params_->params())[69];
0207 par4[10] = (params_->params())[70];
0208
0209 par0[11] = (params_->params())[71];
0210 par1[11] = (params_->params())[72];
0211 par2[11] = (params_->params())[73];
0212 par3[11] = (params_->params())[74];
0213 par4[11] = (params_->params())[75];
0214
0215 par0[12] = (params_->params())[76];
0216 par1[12] = (params_->params())[77];
0217 par2[12] = (params_->params())[78];
0218 par3[12] = (params_->params())[79];
0219 par4[12] = (params_->params())[80];
0220
0221 par0[13] = (params_->params())[81];
0222 par1[13] = (params_->params())[82];
0223 par2[13] = (params_->params())[83];
0224 par3[13] = (params_->params())[84];
0225 par4[13] = (params_->params())[85];
0226
0227 sigmaPhiSigmaEtaFit = 1.2;
0228 }
0229
0230 if (algorithm == 1) {
0231
0232 xcorr[0] = (params_->params())[86];
0233 xcorr[1] = (params_->params())[87];
0234 xcorr[2] = (params_->params())[88];
0235 xcorr[3] = (params_->params())[89];
0236 xcorr[4] = (params_->params())[90];
0237 xcorr[5] = (params_->params())[91];
0238 xcorr[6] = (params_->params())[92];
0239 xcorr[7] = (params_->params())[93];
0240 xcorr[8] = (params_->params())[94];
0241 xcorr[9] = (params_->params())[95];
0242 xcorr[10] = (params_->params())[96];
0243 xcorr[11] = (params_->params())[97];
0244 xcorr[12] = (params_->params())[98];
0245 xcorr[13] = (params_->params())[99];
0246
0247 par0[0] = (params_->params())[100];
0248 par1[0] = (params_->params())[101];
0249 par2[0] = (params_->params())[102];
0250 par3[0] = (params_->params())[103];
0251 par4[0] = (params_->params())[104];
0252
0253 par0[1] = (params_->params())[105];
0254 par1[1] = (params_->params())[106];
0255 par2[1] = (params_->params())[107];
0256 par3[1] = (params_->params())[108];
0257 par4[1] = (params_->params())[109];
0258
0259 par0[2] = (params_->params())[110];
0260 par1[2] = (params_->params())[111];
0261 par2[2] = (params_->params())[112];
0262 par3[2] = (params_->params())[113];
0263 par4[2] = (params_->params())[114];
0264
0265 par0[3] = (params_->params())[115];
0266 par1[3] = (params_->params())[116];
0267 par2[3] = (params_->params())[117];
0268 par3[3] = (params_->params())[118];
0269 par4[3] = (params_->params())[119];
0270
0271 par0[4] = (params_->params())[120];
0272 par1[4] = (params_->params())[121];
0273 par2[4] = (params_->params())[122];
0274 par3[4] = (params_->params())[123];
0275 par4[4] = (params_->params())[124];
0276
0277 par0[5] = (params_->params())[125];
0278 par1[5] = (params_->params())[126];
0279 par2[5] = (params_->params())[127];
0280 par3[5] = (params_->params())[128];
0281 par4[5] = (params_->params())[129];
0282
0283 par0[6] = (params_->params())[130];
0284 par1[6] = (params_->params())[131];
0285 par2[6] = (params_->params())[132];
0286 par3[6] = (params_->params())[133];
0287 par4[6] = (params_->params())[134];
0288
0289 par0[7] = (params_->params())[135];
0290 par1[7] = (params_->params())[136];
0291 par2[7] = (params_->params())[137];
0292 par3[7] = (params_->params())[138];
0293 par4[7] = (params_->params())[139];
0294
0295 par0[8] = (params_->params())[140];
0296 par1[8] = (params_->params())[141];
0297 par2[8] = (params_->params())[142];
0298 par3[8] = (params_->params())[143];
0299 par4[8] = (params_->params())[144];
0300
0301 par0[9] = (params_->params())[145];
0302 par1[9] = (params_->params())[146];
0303 par2[9] = (params_->params())[147];
0304 par3[9] = (params_->params())[148];
0305 par4[9] = (params_->params())[149];
0306
0307 par0[10] = (params_->params())[150];
0308 par1[10] = (params_->params())[151];
0309 par2[10] = (params_->params())[152];
0310 par3[10] = (params_->params())[153];
0311 par4[10] = (params_->params())[154];
0312
0313 par0[11] = (params_->params())[155];
0314 par1[11] = (params_->params())[156];
0315 par2[11] = (params_->params())[157];
0316 par3[11] = (params_->params())[158];
0317 par4[11] = (params_->params())[159];
0318
0319 par0[12] = (params_->params())[160];
0320 par1[12] = (params_->params())[161];
0321 par2[12] = (params_->params())[162];
0322 par3[12] = (params_->params())[163];
0323 par4[12] = (params_->params())[164];
0324
0325 par0[13] = (params_->params())[165];
0326 par1[13] = (params_->params())[166];
0327 par2[13] = (params_->params())[167];
0328 par3[13] = (params_->params())[168];
0329 par4[13] = (params_->params())[169];
0330
0331 sigmaPhiSigmaEtaFit = 1.;
0332 }
0333
0334
0335 float tmpInter = 1;
0336
0337 if (tmpEta == -1) {
0338 for (int iEta = 0; iEta < nBinsEta - 1; ++iEta) {
0339 if (rightEta[iEta] <= std::abs(eta) && std::abs(eta) < leftEta[iEta + 1]) {
0340 if (sigmaPhiSigmaEta >= sigmaPhiSigmaEtaFit) {
0341 if (algorithm == 0) {
0342 tmpInter = (par0[iEta] + sigmaPhiSigmaEta * par1[iEta] + sigmaPhiSigmaEta * sigmaPhiSigmaEta * par2[iEta] +
0343 par0[iEta + 1] + sigmaPhiSigmaEta * par1[iEta + 1] +
0344 sigmaPhiSigmaEta * sigmaPhiSigmaEta * par2[iEta + 1]) /
0345 2.;
0346 }
0347 if (algorithm == 1) {
0348 tmpInter = (par0[iEta] * (1. - exp(-(sigmaPhiSigmaEta - par4[iEta]) / par1[iEta])) * par2[iEta] *
0349 sigmaPhiSigmaEta +
0350 par3[iEta] +
0351 par0[iEta + 1] * (1. - exp(-(sigmaPhiSigmaEta - par4[iEta + 1]) / par1[iEta + 1])) *
0352 par2[iEta + 1] * sigmaPhiSigmaEta +
0353 par3[iEta + 1]) /
0354 2.;
0355 }
0356 } else
0357 tmpInter = (xcorr[iEta] + xcorr[iEta + 1]) / 2.;
0358 }
0359 }
0360 return tmpInter;
0361 }
0362
0363 if (sigmaPhiSigmaEta >= sigmaPhiSigmaEtaFit) {
0364 if (algorithm == 0)
0365 return par0[tmpEta] + sigmaPhiSigmaEta * par1[tmpEta] + sigmaPhiSigmaEta * sigmaPhiSigmaEta * par2[tmpEta];
0366 if (algorithm == 1)
0367 return par0[tmpEta] * (1. - exp(-(sigmaPhiSigmaEta - par4[tmpEta]) / par1[tmpEta])) * par2[tmpEta] *
0368 sigmaPhiSigmaEta +
0369 par3[tmpEta];
0370 } else
0371 return xcorr[tmpEta];
0372
0373 return 1.;
0374 }
0375
0376 float EcalClusterEnergyCorrectionObjectSpecific::fEt(float ET, int algorithm) const {
0377 float par0 = -1;
0378 float par1 = -1;
0379 float par2 = -1;
0380 float par3 = -1;
0381 float par4 = -1;
0382 float par5 = -1;
0383 float par6 = -1;
0384
0385 if (algorithm == 0) {
0386
0387 par0 = (params_->params())[170];
0388 par1 = (params_->params())[171];
0389 par2 = (params_->params())[172];
0390 par3 = (params_->params())[173];
0391 par4 = (params_->params())[174];
0392
0393
0394 if (ET > 200)
0395 ET = 200;
0396 if (ET < 5)
0397 return 1.;
0398 if (5 <= ET && ET < 10)
0399 return par0;
0400 if (10 <= ET && ET <= 200)
0401 return (par1 + ET * par2) * (1 - par3 * exp(ET / par4));
0402 }
0403
0404 if (algorithm == 1) {
0405
0406 par0 = (params_->params())[177];
0407 par1 = (params_->params())[178];
0408 par2 = (params_->params())[179];
0409 par3 = (params_->params())[180];
0410 par4 = (params_->params())[181];
0411
0412
0413 if (ET > 200)
0414 ET = 200;
0415 if (ET < 5)
0416 return 1.;
0417 if (5 <= ET && ET < 10)
0418 return par0;
0419 if (10 <= ET && ET <= 200)
0420 return (par1 + ET * par2) * (1 - par3 * exp(ET / par4));
0421 }
0422
0423 if (algorithm == 2) {
0424
0425 par0 = (params_->params())[184];
0426 par1 = (params_->params())[185];
0427 par2 = (params_->params())[186];
0428 par3 = (params_->params())[187];
0429 par4 = (params_->params())[188];
0430
0431
0432 if (ET < 5)
0433 return 1.;
0434 if (5 <= ET && ET < 10)
0435 return par0;
0436 if (10 <= ET && ET < 20)
0437 return par1;
0438 if (20 <= ET && ET < 140)
0439 return par2 + par3 * ET;
0440 if (140 <= ET)
0441 return par4;
0442 }
0443
0444 if (algorithm == 3) {
0445
0446 par0 = (params_->params())[191];
0447 par1 = (params_->params())[192];
0448 par2 = (params_->params())[193];
0449 par3 = (params_->params())[194];
0450 par4 = (params_->params())[195];
0451 par5 = (params_->params())[196];
0452 par6 = (params_->params())[197];
0453
0454 if (ET < 5)
0455 return 1.;
0456 if (5 <= ET && ET < 10)
0457 return par0;
0458 if (10 <= ET && ET < 20)
0459 return par1;
0460 if (20 <= ET && ET < 30)
0461 return par2;
0462 if (30 <= ET && ET < 200)
0463 return par3 + par4 * ET + par5 * ET * ET;
0464 if (200 <= ET)
0465 return par6;
0466 }
0467
0468 return 1.;
0469 }
0470
0471 float EcalClusterEnergyCorrectionObjectSpecific::fEnergy(float E, int algorithm) const {
0472 float par0 = -1;
0473 float par1 = -1;
0474 float par2 = -1;
0475 float par3 = -1;
0476 float par4 = -1;
0477
0478 if (algorithm == 0) {
0479 return 1.;
0480 }
0481
0482 if (algorithm == 1) {
0483
0484 par0 = (params_->params())[198];
0485 par1 = (params_->params())[199];
0486 par2 = (params_->params())[200];
0487 par3 = (params_->params())[201];
0488 par4 = (params_->params())[202];
0489
0490 if (E > par0)
0491 E = par0;
0492 if (E < 0)
0493 return 1.;
0494 if (0 <= E && E <= par0)
0495 return (par1 + E * par2) * (1 - par3 * exp(E / par4));
0496 }
0497
0498 if (algorithm == 2) {
0499 return 1.;
0500 }
0501
0502 if (algorithm == 3) {
0503
0504 par0 = (params_->params())[203];
0505 par1 = (params_->params())[204];
0506 par2 = (params_->params())[205];
0507
0508
0509 if (E > par0)
0510 E = par0;
0511 if (E < 0)
0512 return 1.;
0513 if (0 <= E && E <= par0)
0514 return par1 + E * par2;
0515 }
0516
0517 return 1.;
0518 }
0519
0520 float EcalClusterEnergyCorrectionObjectSpecific::getValue(const reco::SuperCluster &superCluster,
0521 const int mode) const {
0522 float corr = 1.;
0523 float corr2 = 1.;
0524 float energy = 0;
0525
0526 int subdet = superCluster.seed()->hitsAndFractions()[0].first.subdetId();
0527
0528
0529
0530
0531 if (subdet == EcalBarrel) {
0532 float cetacorr = fEta(superCluster.rawEnergy(), superCluster.eta(), 0) / superCluster.rawEnergy();
0533
0534
0535 energy = superCluster.rawEnergy() * cetacorr;
0536
0537 } else if (subdet == EcalEndcap) {
0538 energy = superCluster.rawEnergy() + superCluster.preshowerEnergy();
0539 }
0540
0541 float newEnergy = energy;
0542
0543 if (mode == 0) {
0544
0545 corr = fBremEta(superCluster.phiWidth() / superCluster.etaWidth(), superCluster.eta(), 0);
0546
0547 float et = energy * std::sin(2 * std::atan(std::exp(-superCluster.eta()))) / corr;
0548
0549 if (subdet == EcalBarrel)
0550 corr2 = corr * fEt(et, 0);
0551 if (subdet == EcalEndcap)
0552 corr2 = corr * fEnergy(energy / corr, 1);
0553
0554 newEnergy = energy / corr2;
0555 }
0556
0557 if (mode == 1) {
0558
0559 corr = fBremEta(superCluster.phiWidth() / superCluster.etaWidth(), superCluster.eta(), 1);
0560
0561 float et = energy * std::sin(2 * std::atan(std::exp(-superCluster.eta()))) / corr;
0562
0563 if (subdet == EcalBarrel)
0564 corr2 = corr * fEt(et, 2);
0565 if (subdet == EcalEndcap)
0566 corr2 = corr * fEnergy(energy / corr, 3);
0567
0568 newEnergy = energy / corr2;
0569 }
0570
0571 return newEnergy;
0572 }
0573
0574 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionFactory.h"
0575 DEFINE_EDM_PLUGIN(EcalClusterFunctionFactory,
0576 EcalClusterEnergyCorrectionObjectSpecific,
0577 "EcalClusterEnergyCorrectionObjectSpecific");