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>>();
103 buggedRespCorrs.
setTopo(&theHBHETopology);
115 for (
auto id : cellsHE) {
118 if (buggedRespCorr == 0.)
121 float ratio = currentRespCorr / buggedRespCorr;
130 for (
auto id : cellsHF) {
133 if (buggedRespCorr == 0.)
136 float ratio = currentRespCorr / buggedRespCorr;
159 copy->reserve(nPfCand);
160 std::vector<int> oldToNew(nPfCand), newToOld, badToOld;
161 newToOld.reserve(nPfCand);
163 LogDebug(
"PFCandidateRecalibrator") <<
"NEW EV:";
172 if (
pf.particleId() == reco::PFCandidate::ParticleType::h0 &&
174 absEta > 1.4 && absEta < 3.) {
181 discarded->push_back(
pf);
182 oldToNew[
i] = (-discarded->size());
183 badToOld.push_back(
i);
187 oldToNew[
i] = (
copy->size());
188 newToOld.push_back(
i);
192 else if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF ||
193 pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF) &&
197 GlobalPoint ecalGPoint(ecalPoint.X(), ecalPoint.Y(), ecalPoint.Z());
201 HcalDetId hDetId(closestDetId.subdet(), closestDetId.ieta(), closestDetId.iphi(), 1);
204 float longE =
pf.rawEcalEnergy() +
pf.rawHcalEnergy() / 2.;
205 float shortE =
pf.rawHcalEnergy() / 2.;
207 float ecalEnergy =
pf.rawEcalEnergy();
208 float hcalEnergy =
pf.rawHcalEnergy();
209 float totEnergy = ecalEnergy + hcalEnergy;
210 float totEnergyOrig = totEnergy;
214 for (
auto const& badIt :
badChHF_) {
215 if (hDetId.ieta() == badIt.ieta && hDetId.iphi() == badIt.iphi) {
217 <<
"==> orig en (tot,H,E): " <<
pf.energy() <<
" " <<
pf.rawHcalEnergy() <<
" " <<
pf.rawEcalEnergy();
218 if (badIt.depth == 1)
220 longE *= badIt.ratio;
221 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
222 totEnergy = ecalEnergy + hcalEnergy;
225 shortE *= badIt.ratio;
226 hcalEnergy = 2 * shortE;
227 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
228 totEnergy = ecalEnergy + hcalEnergy;
231 if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF && shortE <
shortFibreThr_) ||
232 (
pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF && longE <
longFibreThr_))
235 LogDebug(
"PFCandidateRecalibrator") <<
"====> ieta,iphi,depth: " << badIt.ieta <<
" " << badIt.iphi <<
" " 236 << badIt.depth <<
" corr: " << badIt.ratio;
238 <<
"====> recal en (tot,H,E): " << totEnergy <<
" " << hcalEnergy <<
" " << ecalEnergy;
243 discarded->push_back(
pf);
244 oldToNew[
i] = (-discarded->size());
245 badToOld.push_back(
i);
247 LogDebug(
"PFCandidateRecalibrator") <<
"==> KILLED ";
250 oldToNew[
i] = (
copy->size());
251 newToOld.push_back(
i);
253 copy->back().setHcalEnergy(hcalEnergy, hcalEnergy);
254 copy->back().setEcalEnergy(ecalEnergy, ecalEnergy);
256 float scalingFactor = totEnergy / totEnergyOrig;
258 copy->back().setP4(recalibP4);
260 LogDebug(
"PFCandidateRecalibrator") <<
"====> stored en (tot,H,E): " <<
copy->back().energy() <<
" " 261 <<
copy->back().hcalEnergy() <<
" " <<
copy->back().ecalEnergy();
265 oldToNew[
i] = (
copy->size());
266 newToOld.push_back(
i);
270 oldToNew[
i] = (
copy->size());
271 newToOld.push_back(
i);
281 std::vector<reco::PFCandidateRef> refs;
282 refs.reserve(nPfCand);
285 for (
auto iOldToNew : oldToNew) {
295 for (
int i : newToOld) {
298 filler.insert(newpf, refs.begin(), refs.end());
301 for (
int i : badToOld) {
304 filler.insert(badpf, refs.begin(), refs.end());
314 desc.add<
double>(
"shortFibreThr", 1.4);
315 desc.add<
double>(
"longFibreThr", 1.4);
317 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)
DetId getClosestCell(const GlobalPoint &r) const override
#define DEFINE_FWK_MODULE(type)
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)
bool getData(T &iHolder) const
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