87 shortFibreThr_(iConfig.getParameter<double>(
"shortFibreThr")),
88 longFibreThr_(iConfig.getParameter<double>(
"longFibreThr")) {
89 produces<reco::PFCandidateCollection>();
90 produces<reco::PFCandidateCollection>(
"discarded");
91 produces<edm::ValueMap<reco::PFCandidateRef>>();
105 buggedRespCorrs.
setTopo(&theHBHETopology);
117 for (
auto id : cellsHE) {
120 if (buggedRespCorr == 0.)
123 float ratio = currentRespCorr / buggedRespCorr;
132 for (
auto id : cellsHF) {
135 if (buggedRespCorr == 0.)
138 float ratio = currentRespCorr / buggedRespCorr;
161 copy->reserve(nPfCand);
162 std::vector<int> oldToNew(nPfCand), newToOld, badToOld;
163 newToOld.reserve(nPfCand);
165 LogDebug(
"PFCandidateRecalibrator") <<
"NEW EV:";
174 if (
pf.particleId() == reco::PFCandidate::ParticleType::h0 &&
176 absEta > 1.4 && absEta < 3.) {
183 discarded->push_back(
pf);
184 oldToNew[
i] = (-discarded->size());
185 badToOld.push_back(
i);
189 oldToNew[
i] = (
copy->size());
190 newToOld.push_back(
i);
194 else if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF ||
195 pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF) &&
199 GlobalPoint ecalGPoint(ecalPoint.X(), ecalPoint.Y(), ecalPoint.Z());
203 HcalDetId hDetId(closestDetId.subdet(), closestDetId.ieta(), closestDetId.iphi(), 1);
206 float longE =
pf.rawEcalEnergy() +
pf.rawHcalEnergy() / 2.;
207 float shortE =
pf.rawHcalEnergy() / 2.;
210 float hcalEnergy =
pf.rawHcalEnergy();
212 float totEnergyOrig = totEnergy;
216 for (
auto const& badIt :
badChHF_) {
217 if (hDetId.ieta() == badIt.ieta && hDetId.iphi() == badIt.iphi) {
219 <<
"==> orig en (tot,H,E): " <<
pf.energy() <<
" " <<
pf.rawHcalEnergy() <<
" " <<
pf.rawEcalEnergy();
220 if (badIt.depth == 1)
222 longE *= badIt.ratio;
223 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
227 shortE *= badIt.ratio;
228 hcalEnergy = 2 * shortE;
229 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
233 if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF && shortE <
shortFibreThr_) ||
234 (
pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF && longE <
longFibreThr_))
237 LogDebug(
"PFCandidateRecalibrator") <<
"====> ieta,iphi,depth: " << badIt.ieta <<
" " << badIt.iphi <<
" " 238 << badIt.depth <<
" corr: " << badIt.ratio;
240 <<
"====> recal en (tot,H,E): " << totEnergy <<
" " << hcalEnergy <<
" " <<
ecalEnergy;
245 discarded->push_back(
pf);
246 oldToNew[
i] = (-discarded->size());
247 badToOld.push_back(
i);
249 LogDebug(
"PFCandidateRecalibrator") <<
"==> KILLED ";
252 oldToNew[
i] = (
copy->size());
253 newToOld.push_back(
i);
255 copy->back().setHcalEnergy(hcalEnergy, hcalEnergy);
258 float scalingFactor = totEnergy / totEnergyOrig;
260 copy->back().setP4(recalibP4);
262 LogDebug(
"PFCandidateRecalibrator") <<
"====> stored en (tot,H,E): " <<
copy->back().energy() <<
" " 263 <<
copy->back().hcalEnergy() <<
" " <<
copy->back().ecalEnergy();
267 oldToNew[
i] = (
copy->size());
268 newToOld.push_back(
i);
272 oldToNew[
i] = (
copy->size());
273 newToOld.push_back(
i);
283 std::vector<reco::PFCandidateRef> refs;
284 refs.reserve(nPfCand);
287 for (
auto iOldToNew : oldToNew) {
297 for (
int i : newToOld) {
300 filler.insert(newpf, refs.begin(), refs.end());
303 for (
int i : badToOld) {
306 filler.insert(badpf, refs.begin(), refs.end());
316 desc.add<
double>(
"shortFibreThr", 1.4);
317 desc.add<
double>(
"longFibreThr", 1.4);
319 descriptions.
add(
"pfCandidateRecalibrator",
desc);
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &, const edm::EventSetup &) override
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenRun_
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
DetId getClosestCell(const GlobalPoint &r) const override
edm::ESWatcher< HcalRecNumberingRecord > hcalDbWatcher_
std::vector< l1t::PFCandidate > PFCandidateCollection
void endRun(const edm::Run &iRun, edm::EventSetup const &iSetup) override
std::vector< HEChannel > badChHE_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
PFCandidateRecalibrator(const edm::ParameterSet &)
const Item * getValues(DetId fId, bool throwOnFail=true) const
HEChannel(float eta, float phi, float ratio)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::ESGetToken< HcalRespCorrs, HcalRespCorrsRcd > buggedCondToken_
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
constexpr int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > calogeomTokenEvent_
~PFCandidateRecalibrator() override
edm::ESWatcher< HcalRespCorrsRcd > hcalRCWatcher_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::vector< HFChannel > badChHF_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HFChannel(int ieta, int iphi, int depth, float ratio)
bool check(const edm::EventSetup &iSetup)
edm::EDGetTokenT< reco::PFCandidateCollection > pfcandidates_
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > htopoToken_
void beginRun(const edm::Run &iRun, edm::EventSetup const &iSetup) override
Particle reconstructed by the particle flow algorithm.
GlobalPoint getPosition(const DetId &id) const
const edm::ESGetToken< HcalDbService, HcalDbRecord > gtCondToken_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
constexpr int iphi() const
get the cell iphi
void setTopo(const HcalTopology *topo)
constexpr int depth() const
get the tower depth