File indexing completed on 2024-04-06 12:25:48
0001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalHF_S9S1algorithm.h"
0002 #include "DataFormats/METReco/interface/HcalCaloFlagLabels.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
0005 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
0006 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
0007 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0008
0009 #include <algorithm> // for "max"
0010 #include <cmath>
0011 #include <iostream>
0012
0013 HcalHF_S9S1algorithm::HcalHF_S9S1algorithm() {
0014
0015 std::vector<double> blank;
0016 blank.clear();
0017 blank.push_back(0);
0018 std::vector<double> EnergyDefault;
0019 EnergyDefault.clear();
0020 EnergyDefault.push_back(50);
0021
0022
0023 LongSlopes.clear();
0024 ShortSlopes.clear();
0025 for (int i = 29; i <= 41; ++i) {
0026 LongSlopes.push_back(0);
0027 ShortSlopes.push_back(0);
0028 }
0029 LongEnergyThreshold.clear();
0030 LongETThreshold.clear();
0031 ShortEnergyThreshold.clear();
0032 ShortETThreshold.clear();
0033 for (int i = 29; i <= 41; ++i) {
0034 LongEnergyThreshold.push_back(EnergyDefault[0]);
0035 LongETThreshold.push_back(blank[0]);
0036 ShortEnergyThreshold.push_back(EnergyDefault[0]);
0037 ShortETThreshold.push_back(blank[0]);
0038 }
0039 HcalAcceptSeverityLevel_ = 0;
0040 isS8S1_ = false;
0041 }
0042
0043 HcalHF_S9S1algorithm::HcalHF_S9S1algorithm(const std::vector<double>& short_optimumSlope,
0044 const std::vector<double>& short_Energy,
0045 const std::vector<double>& short_ET,
0046 const std::vector<double>& long_optimumSlope,
0047 const std::vector<double>& long_Energy,
0048 const std::vector<double>& long_ET,
0049 int HcalAcceptSeverityLevel,
0050 bool isS8S1)
0051
0052 {
0053
0054
0055
0056
0057 LongSlopes = long_optimumSlope;
0058 ShortSlopes = short_optimumSlope;
0059
0060 while (LongSlopes.size() < 13)
0061 LongSlopes.push_back(0);
0062 while (ShortSlopes.size() < 13)
0063 ShortSlopes.push_back(0);
0064
0065
0066 LongEnergyThreshold.clear();
0067 LongETThreshold.clear();
0068 ShortEnergyThreshold.clear();
0069 ShortETThreshold.clear();
0070 LongEnergyThreshold = long_Energy;
0071 LongETThreshold = long_ET;
0072 ShortEnergyThreshold = short_Energy;
0073 ShortETThreshold = short_ET;
0074
0075 HcalAcceptSeverityLevel_ = HcalAcceptSeverityLevel;
0076 isS8S1_ = isS8S1;
0077 }
0078
0079 HcalHF_S9S1algorithm::~HcalHF_S9S1algorithm() {}
0080
0081 void HcalHF_S9S1algorithm::HFSetFlagFromS9S1(HFRecHit& hf,
0082 HFRecHitCollection& rec,
0083 const HcalChannelQuality* myqual,
0084 const HcalSeverityLevelComputer* mySeverity)
0085
0086 {
0087 int ieta = hf.id().ieta();
0088 int depth = hf.id().depth();
0089 int iphi = hf.id().iphi();
0090 std::pair<double, double> etas = myqual->topo()->etaRange(HcalForward, abs(ieta));
0091 double eta1 = etas.first;
0092 double eta2 = etas.second;
0093 double fEta = 0.5 * (eta1 + eta2);
0094 double energy = hf.energy();
0095 double ET = energy / fabs(cosh(fEta));
0096
0097
0098 double ETthresh = 0, Energythresh = 0;
0099 if (depth == 1)
0100 {
0101 Energythresh = LongEnergyThreshold[abs(ieta) - 29];
0102 ETthresh = LongETThreshold[abs(ieta) - 29];
0103 } else if (depth == 2)
0104 {
0105 Energythresh = ShortEnergyThreshold[abs(ieta) - 29];
0106 ETthresh = ShortETThreshold[abs(ieta) - 29];
0107 }
0108 if (energy < Energythresh || ET < ETthresh)
0109 return;
0110
0111
0112
0113 if (depth == 2 && abs(ieta) > 29 && isS8S1_) {
0114 double EL = 0;
0115
0116 HcalDetId neighbor(HcalForward, ieta, iphi, 1);
0117 HFRecHitCollection::const_iterator neigh = rec.find(neighbor);
0118 if (neigh != rec.end())
0119 EL = neigh->energy();
0120
0121 if (EL >= energy)
0122 return;
0123 }
0124
0125
0126 double S9S1 = 0;
0127 int testphi = -99;
0128
0129
0130 for (int d = 1; d <= 2; ++d)
0131 {
0132 for (int i = ieta - 1; i <= ieta + 1; ++i)
0133 {
0134 testphi = iphi;
0135
0136
0137 if (abs(ieta) == 39 && abs(i) > 39 && testphi % 4 == 1)
0138 testphi -= 2;
0139 while (testphi < 0)
0140 testphi += 72;
0141 if (i == ieta)
0142 if (d == depth || isS8S1_ == true)
0143 continue;
0144
0145
0146 HcalDetId neighbor(HcalForward, i, testphi, d);
0147 HFRecHitCollection::const_iterator neigh = rec.find(neighbor);
0148
0149 if (neigh != rec.end()) {
0150 const uint32_t chanstat = myqual->getValues(neighbor)->getValue();
0151 int SeverityLevel = mySeverity->getSeverityLevel(neighbor, neigh->flags(), chanstat);
0152 if (SeverityLevel <= HcalAcceptSeverityLevel_)
0153 S9S1 += neigh->energy();
0154 }
0155 }
0156 }
0157
0158
0159
0160 int phiseg = 2;
0161 if (abs(ieta) > 39)
0162 phiseg = 4;
0163 for (int d = 1; d <= 2; ++d) {
0164 for (int i = iphi - phiseg; i <= iphi + phiseg; i += phiseg) {
0165 if (i == iphi)
0166 continue;
0167 testphi = i;
0168
0169 while (testphi < 0)
0170 testphi += 72;
0171 while (testphi > 72)
0172 testphi -= 72;
0173
0174 HcalDetId neighbor(HcalForward, ieta, testphi, d);
0175 HFRecHitCollection::const_iterator neigh = rec.find(neighbor);
0176 if (neigh != rec.end()) {
0177 const uint32_t chanstat = myqual->getValues(neighbor)->getValue();
0178 int SeverityLevel = mySeverity->getSeverityLevel(neighbor, neigh->flags(), chanstat);
0179 if (SeverityLevel <= HcalAcceptSeverityLevel_)
0180 S9S1 += neigh->energy();
0181 }
0182 }
0183 }
0184
0185 if (abs(ieta) == 40)
0186 {
0187 for (int d = 1; d <= 2; ++d)
0188 {
0189 HcalDetId neighbor(HcalForward, 39 * abs(ieta) / ieta, (iphi + 2) % 72, d);
0190 HFRecHitCollection::const_iterator neigh = rec.find(neighbor);
0191 if (neigh != rec.end()) {
0192 const uint32_t chanstat = myqual->getValues(neighbor)->getValue();
0193 int SeverityLevel = mySeverity->getSeverityLevel(neighbor, neigh->flags(), chanstat);
0194 if (SeverityLevel <= HcalAcceptSeverityLevel_)
0195 S9S1 += neigh->energy();
0196 }
0197 }
0198 }
0199
0200
0201 S9S1 /= energy;
0202
0203
0204 double slope = 0;
0205 if (depth == 1)
0206 slope = LongSlopes[abs(ieta) - 29];
0207 else if (depth == 2)
0208 slope = ShortSlopes[abs(ieta) - 29];
0209 double intercept = 0;
0210 if (depth == 1)
0211 intercept = LongEnergyThreshold[abs(ieta) - 29];
0212 else if (depth == 2)
0213 intercept = ShortEnergyThreshold[abs(ieta) - 29];
0214
0215
0216 double S9S1cut = 0;
0217
0218 if (intercept > 0 && energy > 0)
0219 S9S1cut = -1. * slope * log(intercept) + slope * log(energy);
0220 if (S9S1 < S9S1cut) {
0221
0222 if (isS8S1_ == true)
0223 hf.setFlagField(1, HcalCaloFlagLabels::HFS8S1Ratio);
0224
0225 hf.setFlagField(1, HcalCaloFlagLabels::HFLongShort);
0226 }
0227 return;
0228 }
0229
0230 double HcalHF_S9S1algorithm::CalcSlope(int abs_ieta, const std::vector<double>& params) {
0231
0232
0233
0234
0235
0236
0237 double threshold = 0;
0238 for (std::vector<double>::size_type i = 0; i < params.size(); ++i) {
0239 threshold += params[i] * pow(static_cast<double>(abs_ieta), (int)i);
0240 }
0241 return threshold;
0242 }
0243
0244 double HcalHF_S9S1algorithm::CalcEnergyThreshold(double abs_energy, const std::vector<double>& params) {
0245
0246
0247
0248
0249
0250 double threshold = 0;
0251 for (std::vector<double>::size_type i = 0; i < params.size(); ++i) {
0252 threshold += params[i] * pow(abs_energy, (int)i);
0253 }
0254 return threshold;
0255 }