38 HEChannel(
float eta,
float phi,
float ratio) : eta(eta), phi(phi), ratio(ratio) {}
45 HFChannel(
int ieta,
int iphi,
int depth,
float ratio) : ieta(ieta), iphi(iphi), depth(depth), ratio(ratio) {}
74 shortFibreThr_(iConfig.getParameter<double>(
"shortFibreThr")),
75 longFibreThr_(iConfig.getParameter<double>(
"longFibreThr")) {
76 produces<reco::PFCandidateCollection>();
77 produces<reco::PFCandidateCollection>(
"discarded");
78 produces<edm::ValueMap<reco::PFCandidateRef>>();
95 buggedRespCorrs.
setTopo(theHBHETopology);
110 for (
auto id : cellsHE) {
112 float buggedRespCorr = buggedRespCorrs.getValues(
id)->getValue();
113 if (buggedRespCorr == 0.)
116 float ratio = currentRespCorr / buggedRespCorr;
125 for (
auto id : cellsHF) {
127 float buggedRespCorr = buggedRespCorrs.getValues(
id)->getValue();
128 if (buggedRespCorr == 0.)
131 float ratio = currentRespCorr / buggedRespCorr;
153 int nPfCand = pfcandidates->size();
156 copy->reserve(nPfCand);
157 std::vector<int> oldToNew(nPfCand), newToOld, badToOld;
158 newToOld.reserve(nPfCand);
160 LogDebug(
"PFCandidateRecalibrator") <<
"NEW EV:";
169 if (
pf.particleId() == reco::PFCandidate::ParticleType::h0 &&
171 absEta > 1.4 && absEta < 3.) {
178 discarded->push_back(
pf);
179 oldToNew[
i] = (-discarded->size());
180 badToOld.push_back(i);
184 oldToNew[
i] = (copy->size());
185 newToOld.push_back(i);
189 else if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF ||
190 pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF) &&
194 GlobalPoint ecalGPoint(ecalPoint.X(), ecalPoint.Y(), ecalPoint.Z());
198 HcalDetId hDetId(closestDetId.subdet(), closestDetId.ieta(), closestDetId.iphi(), 1);
201 float longE =
pf.rawEcalEnergy() +
pf.rawHcalEnergy() / 2.;
202 float shortE =
pf.rawHcalEnergy() / 2.;
204 float ecalEnergy =
pf.rawEcalEnergy();
205 float hcalEnergy =
pf.rawHcalEnergy();
206 float totEnergy = ecalEnergy + hcalEnergy;
207 float totEnergyOrig = totEnergy;
211 for (
auto const& badIt :
badChHF_) {
212 if (hDetId.ieta() == badIt.ieta && hDetId.iphi() == badIt.iphi) {
214 <<
"==> orig en (tot,H,E): " <<
pf.energy() <<
" " <<
pf.rawHcalEnergy() <<
" " <<
pf.rawEcalEnergy();
215 if (badIt.depth == 1)
217 longE *= badIt.ratio;
218 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
219 totEnergy = ecalEnergy + hcalEnergy;
222 shortE *= badIt.ratio;
223 hcalEnergy = 2 * shortE;
224 ecalEnergy = ((longE - shortE) > 0.) ? (longE - shortE) : 0.;
225 totEnergy = ecalEnergy + hcalEnergy;
228 if ((
pf.particleId() == reco::PFCandidate::ParticleType::h_HF && shortE <
shortFibreThr_) ||
229 (
pf.particleId() == reco::PFCandidate::ParticleType::egamma_HF && longE <
longFibreThr_))
232 LogDebug(
"PFCandidateRecalibrator") <<
"====> ieta,iphi,depth: " << badIt.ieta <<
" " << badIt.iphi <<
" " 233 << badIt.depth <<
" corr: " << badIt.ratio;
235 <<
"====> recal en (tot,H,E): " << totEnergy <<
" " << hcalEnergy <<
" " << ecalEnergy;
240 discarded->push_back(
pf);
241 oldToNew[
i] = (-discarded->size());
242 badToOld.push_back(i);
244 LogDebug(
"PFCandidateRecalibrator") <<
"==> KILLED ";
247 oldToNew[
i] = (copy->size());
248 newToOld.push_back(i);
250 copy->back().setHcalEnergy(hcalEnergy, hcalEnergy);
251 copy->back().setEcalEnergy(ecalEnergy, ecalEnergy);
253 float scalingFactor = totEnergy / totEnergyOrig;
255 copy->back().setP4(recalibP4);
257 LogDebug(
"PFCandidateRecalibrator") <<
"====> stored en (tot,H,E): " << copy->back().energy() <<
" " 258 << copy->back().hcalEnergy() <<
" " << copy->back().ecalEnergy();
262 oldToNew[
i] = (copy->size());
263 newToOld.push_back(i);
267 oldToNew[
i] = (copy->size());
268 newToOld.push_back(i);
278 std::vector<reco::PFCandidateRef> refs;
279 refs.reserve(nPfCand);
282 for (
auto iOldToNew : oldToNew) {
289 filler.
insert(pfcandidates, refs.begin(), refs.end());
292 for (
int i : newToOld) {
295 filler.
insert(newpf, refs.begin(), refs.end());
298 for (
int i : badToOld) {
301 filler.
insert(badpf, refs.begin(), refs.end());
311 desc.
add<
double>(
"shortFibreThr", 1.4);
312 desc.
add<
double>(
"longFibreThr", 1.4);
314 descriptions.
add(
"pfCandidateRecalibrator", desc);
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::ESWatcher< HcalRecNumberingRecord > hcalDbWatcher_
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)
Geom::Phi< T > phi() const
void insert(const H &h, I begin, I end)
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 &)
HEChannel(float eta, float phi, float ratio)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const HcalRespCorr * getHcalRespCorr(const HcalGenericDetId &fId) const
int depth() const
get the tower depth
#define DEFINE_FWK_MODULE(type)
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
GlobalPoint getPosition(const DetId &id) const
~PFCandidateRecalibrator() override
edm::ESWatcher< HcalRespCorrsRcd > hcalRCWatcher_
int iphi() const
get the cell iphi
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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_
void beginRun(const edm::Run &iRun, edm::EventSetup const &iSetup) override
Particle reconstructed by the particle flow algorithm.
T const * product() const
void setTopo(const HcalTopology *topo)
DetId getClosestCell(const GlobalPoint &r) const override