From f04135f9960f0bbbf67eff1632f9d81b66138764 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Wed, 12 Feb 2020 15:35:33 +0100 Subject: [PATCH 1/4] don't store vectors just to accumulate them --- .../src/PFECALSuperClusterAlgo.cc | 31 +++++++------- .../interface/PFEnergyCalibration.h | 10 ----- .../PFClusterTools/src/PFEnergyCalibration.cc | 19 --------- .../PFProducer/src/PFEGammaAlgo.cc | 41 ++++++++----------- .../PFTracking/src/ConvBremPFTrackFinder.cc | 4 +- 5 files changed, 32 insertions(+), 73 deletions(-) diff --git a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc index cf2e01546a220..cfed7601cc99a 100644 --- a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc +++ b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc @@ -316,20 +316,21 @@ void PFECALSuperClusterAlgo::buildSuperCluster(CalibClusterPtr& seed, CalibClust // need the vector of raw pointers for a PF width class std::vector bare_ptrs; // calculate necessary parameters and build the SC - double posX(0), posY(0), posZ(0), corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0), ePS1(0), ePS2(0), - energyweight(0), energyweighttot(0); - std::vector ps1_energies, ps2_energies; - int condP1(1), condP2(1); + double posX(0), posY(0), posZ(0), corrSCEnergy(0), corrPS1Energy(0), corrPS2Energy(0), energyweight(0), + energyweighttot(0); for (auto& clus : clustered) { - ePS1 = ePS2 = 0; + double ePS1 = 0.0; + double ePS2 = 0; energyweight = clus->energy_nocalib(); bare_ptrs.push_back(clus->the_ptr().get()); // update EE calibrated super cluster energies if (isEE) { - ePS1 = ePS2 = 0; - condP1 = condP2 = 1; - ps1_energies.clear(); - ps2_energies.clear(); + double ps1_energy_sum = 0.; + double ps2_energy_sum = 0.; + ePS1 = 0.; + ePS2 = 0.; + int condP1 = 1; + int condP2 = 1; auto ee_key_val = std::make_pair(clus->the_ptr().key(), edm::Ptr()); const auto clustops = std::equal_range(EEtoPS_->begin(), EEtoPS_->end(), ee_key_val, sortByKey); for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) { @@ -339,25 +340,23 @@ void PFECALSuperClusterAlgo::buildSuperCluster(CalibClusterPtr& seed, CalibClust switch (psclus->layer()) { case PFLayer::PS1: - ps1_energies.push_back(psclus->energy()); + ps1_energy_sum += psclus->energy(); for (auto const& recH : recH_Frac) { ESDetId strip1 = recH.recHitRef()->detId(); if (strip1 != ESDetId(0)) { - ESChannelStatusMap::const_iterator status_p1 = channelStatus_->getMap().find(strip1); // getStatusCode() == 1 => dead channel //apply correction if all recHits in dead region - if (status_p1->getStatusCode() == 0) + if (channelStatus_->getMap().find(strip1)->getStatusCode() == 0) condP1 = 0; //active } } break; case PFLayer::PS2: - ps2_energies.push_back(psclus->energy()); + ps2_energy_sum += psclus->energy(); for (auto const& recH : recH_Frac) { ESDetId strip2 = recH.recHitRef()->detId(); if (strip2 != ESDetId(0)) { - ESChannelStatusMap::const_iterator status_p2 = channelStatus_->getMap().find(strip2); - if (status_p2->getStatusCode() == 0) + if (channelStatus_->getMap().find(strip2)->getStatusCode() == 0) condP2 = 0; } } @@ -371,7 +370,7 @@ void PFECALSuperClusterAlgo::buildSuperCluster(CalibClusterPtr& seed, CalibClust if (condP2 == 1) ePS2 = -1.; _pfEnergyCalibration->energyEm( - *(clus->the_ptr()), ps1_energies, ps2_energies, ePS1, ePS2, applyCrackCorrections_); + *(clus->the_ptr()), ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, applyCrackCorrections_); } if (ePS1 == -1.) diff --git a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h index 981702f7febc8..ff15d4390bc75 100644 --- a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h +++ b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h @@ -45,18 +45,8 @@ class PFEnergyCalibration { ~PFEnergyCalibration(); // ecal calibration for photons - double energyEm(const reco::PFCluster& clusterEcal, - std::vector& EclustersPS1, - std::vector& EclustersPS2, - bool crackCorrection = true) const; double energyEm(const reco::PFCluster& clusterEcal, double ePS1, double ePS2, bool crackCorrection = true) const; - double energyEm(const reco::PFCluster& clusterEcal, - std::vector& EclustersPS1, - std::vector& EclustersPS2, - double& ps1, - double& ps2, - bool crackCorrection = true) const; double energyEm(const reco::PFCluster& clusterEcal, double ePS1, double ePS2, diff --git a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc index 2800f42034fe0..0da74a3e5308c 100644 --- a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc +++ b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc @@ -485,15 +485,6 @@ double PFEnergyCalibration::dEtaEndcapEH(double x) const { return fdEtaEndcapEH->Eval(x); } } -// -double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, - std::vector& EclustersPS1, - std::vector& EclustersPS2, - bool crackCorrection) const { - double ePS1(std::accumulate(EclustersPS1.begin(), EclustersPS1.end(), 0.0)); - double ePS2(std::accumulate(EclustersPS2.begin(), EclustersPS2.end(), 0.0)); - return energyEm(clusterEcal, ePS1, ePS2, crackCorrection); -} double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, double ePS1, @@ -511,16 +502,6 @@ double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, return calibrated; } -double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, - std::vector& EclustersPS1, - std::vector& EclustersPS2, - double& ps1, - double& ps2, - bool crackCorrection) const { - double ePS1(std::accumulate(EclustersPS1.begin(), EclustersPS1.end(), 0.0)); - double ePS2(std::accumulate(EclustersPS2.begin(), EclustersPS2.end(), 0.0)); - return energyEm(clusterEcal, ePS1, ePS2, ps1, ps2, crackCorrection); -} double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, double ePS1, double ePS2, diff --git a/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc b/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc index 4189c7b2a52b1..2668960a0490c 100644 --- a/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc +++ b/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc @@ -1780,18 +1780,15 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr } bool isEE = false; - edm::Ptr clusptr; // need the vector of raw pointers for a PF width class std::vector bare_ptrs; // calculate necessary parameters and build the SC - double posX(0), posY(0), posZ(0), rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0), PS1_clus_sum(0), PS2_clus_sum(0), - ePS1(0), ePS2(0), ps1_energy(0.0), ps2_energy(0.0); - int condP1(1), condP2(1); + double posX(0), posY(0), posZ(0), rawSCEnergy(0), corrSCEnergy(0), corrPSEnergy(0), ps1_energy(0.0), ps2_energy(0.0); for (auto& clus : RO.ecalclusters) { - ePS1 = 0; - ePS2 = 0; + double ePS1 = 0; + double ePS2 = 0; isEE = PFLayer::ECAL_ENDCAP == clus->clusterRef()->layer(); - clusptr = edm::refToPtr(clus->clusterRef()); + auto clusptr = edm::refToPtr(clus->clusterRef()); bare_ptrs.push_back(clusptr.get()); const double cluseraw = clusptr->energy(); @@ -1802,9 +1799,12 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr posZ += cluseraw * cluspos.Z(); // update EE calibrated super cluster energies if (isEE && RO.ecal2ps.count(clus.get())) { - ePS1 = 0; - ePS2 = 0; - condP1 = condP2 = 1; + double ps1_energy_sum = 0.; + double ps2_energy_sum = 0.; + ePS1 = 0.; + ePS2 = 0.; + int condP1 = 1; + int condP2 = 1; const auto& psclusters = RO.ecal2ps.at(clus.get()); @@ -1815,23 +1815,23 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr switch (psclus->layer()) { case PFLayer::PS1: + ps1_energy_sum += psclus->energy(); for (auto const& recH : recH_Frac) { ESDetId strip1 = recH.recHitRef()->detId(); if (strip1 != ESDetId(0)) { - ESChannelStatusMap::const_iterator status_p1 = channelStatus_->getMap().find(strip1); //getStatusCode() == 0 => active channel // apply correction if all recHits are dead - if (status_p1->getStatusCode() == 0) + if (channelStatus_->getMap().find(strip1)->getStatusCode() == 0) condP1 = 0; } } break; case PFLayer::PS2: + ps2_energy_sum += psclus->energy(); for (auto const& recH : recH_Frac) { ESDetId strip2 = recH.recHitRef()->detId(); if (strip2 != ESDetId(0)) { - ESChannelStatusMap::const_iterator status_p2 = channelStatus_->getMap().find(strip2); - if (status_p2->getStatusCode() == 0) + if (channelStatus_->getMap().find(strip2)->getStatusCode() == 0) condP2 = 0; } } @@ -1841,22 +1841,13 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr } } - auto sumPSEnergy = [](double a, const ClusterElement* b, PFLayer::Layer layer) { - return a + (layer == b->clusterRef()->layer()) * b->clusterRef()->energy(); - }; - - PS1_clus_sum = - std::accumulate(psclusters.begin(), psclusters.end(), 0.0, std::bind(sumPSEnergy, _1, _2, PFLayer::PS1)); - PS2_clus_sum = - std::accumulate(psclusters.begin(), psclusters.end(), 0.0, std::bind(sumPSEnergy, _1, _2, PFLayer::PS2)); - if (condP1 == 1) ePS1 = -1.; if (condP2 == 1) ePS2 = -1.; cluscalibe = thePFEnergyCalibration_.energyEm( - *clusptr, PS1_clus_sum, PS2_clus_sum, ePS1, ePS2, cfg_.applyCrackCorrections); + *clusptr, ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, cfg_.applyCrackCorrections); } if (ePS1 == -1.) ePS1 = 0; @@ -1876,7 +1867,7 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr // now build the supercluster reco::SuperCluster new_sc(corrSCEnergy, math::XYZPoint(posX, posY, posZ)); - clusptr = edm::refToPtr(RO.ecalclusters.front()->clusterRef()); + auto clusptr = edm::refToPtr(RO.ecalclusters.front()->clusterRef()); new_sc.setCorrectedEnergy(corrSCEnergy); new_sc.setSeed(clusptr); new_sc.setPreshowerEnergyPlane1(ps1_energy); diff --git a/RecoParticleFlow/PFTracking/src/ConvBremPFTrackFinder.cc b/RecoParticleFlow/PFTracking/src/ConvBremPFTrackFinder.cc index f0f12654b6100..99fc7ac613d5f 100644 --- a/RecoParticleFlow/PFTracking/src/ConvBremPFTrackFinder.cc +++ b/RecoParticleFlow/PFTracking/src/ConvBremPFTrackFinder.cc @@ -278,13 +278,11 @@ void ConvBremPFTrackFinder::runConvBremFinder(const Handle if (dist > 0.) { bool applyCrackCorrections = false; - vector ps1Ene(0); - vector ps2Ene(0); double ps1, ps2; ps1 = ps2 = 0.; if (dist < MinDist) { MinDist = dist; - EE_calib = cache->pfcalib_->energyEm(*clus, ps1Ene, ps2Ene, ps1, ps2, applyCrackCorrections); + EE_calib = cache->pfcalib_->energyEm(*clus, 0.0, 0.0, ps1, ps2, applyCrackCorrections); } } } From 9fb176be45fb52b52f5b1e9a547a6e5432cc0d08 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 13 Feb 2020 16:10:18 +0100 Subject: [PATCH 2/4] factored out calibrateEndcapClusterEnergies function --- .../src/PFECALSuperClusterAlgo.cc | 48 +++-------------- .../interface/PFEnergyCalibration.h | 13 +++++ .../PFClusterTools/src/PFEnergyCalibration.cc | 53 ++++++++++++++++++ .../PFProducer/src/PFEGammaAlgo.cc | 54 +++---------------- 4 files changed, 80 insertions(+), 88 deletions(-) diff --git a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc index cfed7601cc99a..f56603f328475 100644 --- a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc +++ b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc @@ -325,52 +325,16 @@ void PFECALSuperClusterAlgo::buildSuperCluster(CalibClusterPtr& seed, CalibClust bare_ptrs.push_back(clus->the_ptr().get()); // update EE calibrated super cluster energies if (isEE) { - double ps1_energy_sum = 0.; - double ps2_energy_sum = 0.; - ePS1 = 0.; - ePS2 = 0.; - int condP1 = 1; - int condP2 = 1; auto ee_key_val = std::make_pair(clus->the_ptr().key(), edm::Ptr()); const auto clustops = std::equal_range(EEtoPS_->begin(), EEtoPS_->end(), ee_key_val, sortByKey); + std::vector psClusterPointers; for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) { - edm::Ptr psclus(i_ps->second); - - auto const& recH_Frac = psclus->recHitFractions(); - - switch (psclus->layer()) { - case PFLayer::PS1: - ps1_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip1 = recH.recHitRef()->detId(); - if (strip1 != ESDetId(0)) { - // getStatusCode() == 1 => dead channel - //apply correction if all recHits in dead region - if (channelStatus_->getMap().find(strip1)->getStatusCode() == 0) - condP1 = 0; //active - } - } - break; - case PFLayer::PS2: - ps2_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip2 = recH.recHitRef()->detId(); - if (strip2 != ESDetId(0)) { - if (channelStatus_->getMap().find(strip2)->getStatusCode() == 0) - condP2 = 0; - } - } - break; - default: - break; - } + psClusterPointers.push_back(i_ps->second.get()); } - if (condP1 == 1) - ePS1 = -1.; - if (condP2 == 1) - ePS2 = -1.; - _pfEnergyCalibration->energyEm( - *(clus->the_ptr()), ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, applyCrackCorrections_); + auto calibratedEnergies = _pfEnergyCalibration->calibrateEndcapClusterEnergies( + *(clus->the_ptr()), psClusterPointers, *channelStatus_, applyCrackCorrections_); + ePS1 = calibratedEnergies.ps1Energy; + ePS2 = calibratedEnergies.ps2Energy; } if (ePS1 == -1.) diff --git a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h index ff15d4390bc75..9face4ef39353 100644 --- a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h +++ b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h @@ -5,6 +5,7 @@ #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTFormula.h" #include "CondFormats/ESObjects/interface/ESEEIntercalibConstants.h" +#include "CondFormats/ESObjects/interface/ESChannelStatus.h" class TF1; @@ -54,6 +55,18 @@ class PFEnergyCalibration { double& ps2, bool crackCorrection = true) const; + struct CalibratedEndcapPFClusterEnergies { + double clusterEnergy = 0.; + double ps1Energy = 0.; + double ps2Energy = 0.; + }; + + CalibratedEndcapPFClusterEnergies calibrateEndcapClusterEnergies( + reco::PFCluster const& eeCluster, + std::vector const& psClusterPointers, + ESChannelStatus const& channelStatus, + bool applyCrackCorrections) const; + // ECAL+HCAL (abc) calibration, with E and eta dependent coefficients, for hadrons void energyEmHad(double t, double& e, double& h, double eta, double phi) const; diff --git a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc index 0da74a3e5308c..25428c6b8b478 100644 --- a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc +++ b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc @@ -161,6 +161,59 @@ void PFEnergyCalibration::initializeCalibrationFunctions() { fdEtaEndcapEH->SetParameter(3, 1.0); } +PFEnergyCalibration::CalibratedEndcapPFClusterEnergies PFEnergyCalibration::calibrateEndcapClusterEnergies( + reco::PFCluster const& eeCluster, + std::vector const& psClusterPointers, + ESChannelStatus const& channelStatus, + bool applyCrackCorrections) const { + double ps1_energy_sum = 0.; + double ps2_energy_sum = 0.; + double ePS1 = 0.; + double ePS2 = 0.; + int condP1 = 1; + int condP2 = 1; + + for (auto const& psclus : psClusterPointers) { + auto const& recH_Frac = psclus->recHitFractions(); + + switch (psclus->layer()) { + case PFLayer::PS1: + ps1_energy_sum += psclus->energy(); + for (auto const& recH : recH_Frac) { + ESDetId strip1 = recH.recHitRef()->detId(); + if (strip1 != ESDetId(0)) { + //getStatusCode() == 0 => active channel + // apply correction if all recHits are dead + if (channelStatus.getMap().find(strip1)->getStatusCode() == 0) + condP1 = 0; + } + } + break; + case PFLayer::PS2: + ps2_energy_sum += psclus->energy(); + for (auto const& recH : recH_Frac) { + ESDetId strip2 = recH.recHitRef()->detId(); + if (strip2 != ESDetId(0)) { + if (channelStatus.getMap().find(strip2)->getStatusCode() == 0) + condP2 = 0; + } + } + break; + default: + break; + } + } + + if (condP1 == 1) + ePS1 = -1.; + if (condP2 == 1) + ePS2 = -1.; + + double cluscalibe = energyEm(eeCluster, ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, applyCrackCorrections); + + return {cluscalibe, ePS1, ePS2}; +} + void PFEnergyCalibration::energyEmHad(double t, double& e, double& h, double eta, double phi) const { // Use calorimetric energy as true energy for neutral particles double tt = t; diff --git a/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc b/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc index 2668960a0490c..54068efeb2de1 100644 --- a/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc +++ b/RecoParticleFlow/PFProducer/src/PFEGammaAlgo.cc @@ -1799,55 +1799,17 @@ reco::SuperCluster PFEGammaAlgo::buildRefinedSuperCluster(const PFEGammaAlgo::Pr posZ += cluseraw * cluspos.Z(); // update EE calibrated super cluster energies if (isEE && RO.ecal2ps.count(clus.get())) { - double ps1_energy_sum = 0.; - double ps2_energy_sum = 0.; - ePS1 = 0.; - ePS2 = 0.; - int condP1 = 1; - int condP2 = 1; - const auto& psclusters = RO.ecal2ps.at(clus.get()); - for (auto i_ps = psclusters.begin(); i_ps != psclusters.end(); ++i_ps) { - const PFClusterRef& psclus = (*i_ps)->clusterRef(); - - auto const& recH_Frac = psclus->recHitFractions(); - - switch (psclus->layer()) { - case PFLayer::PS1: - ps1_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip1 = recH.recHitRef()->detId(); - if (strip1 != ESDetId(0)) { - //getStatusCode() == 0 => active channel - // apply correction if all recHits are dead - if (channelStatus_->getMap().find(strip1)->getStatusCode() == 0) - condP1 = 0; - } - } - break; - case PFLayer::PS2: - ps2_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip2 = recH.recHitRef()->detId(); - if (strip2 != ESDetId(0)) { - if (channelStatus_->getMap().find(strip2)->getStatusCode() == 0) - condP2 = 0; - } - } - break; - default: - break; - } + std::vector psClusterPointers; + for (auto const& psc : psclusters) { + psClusterPointers.push_back(psc->clusterRef().get()); } - - if (condP1 == 1) - ePS1 = -1.; - if (condP2 == 1) - ePS2 = -1.; - - cluscalibe = thePFEnergyCalibration_.energyEm( - *clusptr, ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, cfg_.applyCrackCorrections); + auto calibratedEnergies = thePFEnergyCalibration_.calibrateEndcapClusterEnergies( + *clusptr, psClusterPointers, *channelStatus_, cfg_.applyCrackCorrections); + cluscalibe = calibratedEnergies.clusterEnergy; + ePS1 = calibratedEnergies.ps1Energy; + ePS2 = calibratedEnergies.ps2Energy; } if (ePS1 == -1.) ePS1 = 0; From a932054154b76b79627bbec6714a36743a04bc14 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 3 Mar 2020 18:09:41 +0100 Subject: [PATCH 3/4] address review comments --- .../src/PFECALSuperClusterAlgo.cc | 2 +- .../interface/PFEnergyCalibration.h | 14 +-- .../PFClusterTools/src/PFEnergyCalibration.cc | 110 ++++++------------ 3 files changed, 40 insertions(+), 86 deletions(-) diff --git a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc index f56603f328475..f9519556cc1c5 100644 --- a/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc +++ b/RecoEcal/EgammaClusterAlgos/src/PFECALSuperClusterAlgo.cc @@ -320,7 +320,7 @@ void PFECALSuperClusterAlgo::buildSuperCluster(CalibClusterPtr& seed, CalibClust energyweighttot(0); for (auto& clus : clustered) { double ePS1 = 0.0; - double ePS2 = 0; + double ePS2 = 0.0; energyweight = clus->energy_nocalib(); bare_ptrs.push_back(clus->the_ptr().get()); // update EE calibrated super cluster energies diff --git a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h index 9face4ef39353..83d94dca2c300 100644 --- a/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h +++ b/RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h @@ -7,7 +7,7 @@ #include "CondFormats/ESObjects/interface/ESEEIntercalibConstants.h" #include "CondFormats/ESObjects/interface/ESChannelStatus.h" -class TF1; +#include // -*- C++ -*- // @@ -43,8 +43,6 @@ class PFEnergyCalibration { public: PFEnergyCalibration(); - ~PFEnergyCalibration(); - // ecal calibration for photons double energyEm(const reco::PFCluster& clusterEcal, double ePS1, double ePS2, bool crackCorrection = true) const; @@ -70,9 +68,6 @@ class PFEnergyCalibration { // ECAL+HCAL (abc) calibration, with E and eta dependent coefficients, for hadrons void energyEmHad(double t, double& e, double& h, double eta, double phi) const; - // Initialize default E- and eta-dependent coefficient functional form - void initializeCalibrationFunctions(); - // Set the run-dependent calibration functions from the global tag void setCalibrationFunctions(const PerformancePayloadFromTFormula* thePFCal) { pfCalibrations = thePFCal; } @@ -84,8 +79,8 @@ class PFEnergyCalibration { protected: // Calibration functions from global tag - const PerformancePayloadFromTFormula* pfCalibrations; - const ESEEIntercalibConstants* esEEInterCalib_; + const PerformancePayloadFromTFormula* pfCalibrations = nullptr; + const ESEEIntercalibConstants* esEEInterCalib_ = nullptr; // Barrel calibration (eta 0.00 -> 1.48) std::unique_ptr faBarrel; @@ -162,7 +157,8 @@ class PFEnergyCalibration { double dEtaEndcapH(double x) const; // Threshold correction (offset) - double threshE, threshH; + const double threshE = 3.5; + const double threshH = 2.5; }; #endif diff --git a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc index 25428c6b8b478..ecaa40740dfb9 100644 --- a/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc +++ b/RecoParticleFlow/PFClusterTools/src/PFEnergyCalibration.cc @@ -7,23 +7,13 @@ #include #include #include -#include #include #include #include using namespace std; -PFEnergyCalibration::PFEnergyCalibration() : pfCalibrations(nullptr), esEEInterCalib_(nullptr) { - initializeCalibrationFunctions(); -} - -PFEnergyCalibration::~PFEnergyCalibration() {} - -void PFEnergyCalibration::initializeCalibrationFunctions() { - threshE = 3.5; - threshH = 2.5; - +PFEnergyCalibration::PFEnergyCalibration() { //calibChrisClean.C calibration parameters bhumika Nov, 2018 faBarrel = std::make_unique( "faBarrel", "[0]+((([1]+([2]/sqrt(x)))*exp(-(x^[6]/[3])))-([4]*exp(-(x^[7]/[5]))))", 0., 1000.); @@ -168,46 +158,34 @@ PFEnergyCalibration::CalibratedEndcapPFClusterEnergies PFEnergyCalibration::cali bool applyCrackCorrections) const { double ps1_energy_sum = 0.; double ps2_energy_sum = 0.; - double ePS1 = 0.; - double ePS2 = 0.; - int condP1 = 1; - int condP2 = 1; + bool condP1 = true; + bool condP2 = true; for (auto const& psclus : psClusterPointers) { - auto const& recH_Frac = psclus->recHitFractions(); - - switch (psclus->layer()) { - case PFLayer::PS1: - ps1_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip1 = recH.recHitRef()->detId(); - if (strip1 != ESDetId(0)) { - //getStatusCode() == 0 => active channel - // apply correction if all recHits are dead - if (channelStatus.getMap().find(strip1)->getStatusCode() == 0) - condP1 = 0; - } + bool cond = true; + for (auto const& recH : psclus->recHitFractions()) { + auto strip = recH.recHitRef()->detId(); + if (strip != ESDetId(0)) { + //getStatusCode() == 0 => active channel + // apply correction if all recHits are dead + if (channelStatus.getMap().find(strip)->getStatusCode() == 0) { + cond = false; + break; } - break; - case PFLayer::PS2: - ps2_energy_sum += psclus->energy(); - for (auto const& recH : recH_Frac) { - ESDetId strip2 = recH.recHitRef()->detId(); - if (strip2 != ESDetId(0)) { - if (channelStatus.getMap().find(strip2)->getStatusCode() == 0) - condP2 = 0; - } - } - break; - default: - break; + } + } + + if (psclus->layer() == PFLayer::PS1) { + ps1_energy_sum += psclus->energy(); + condP1 &= cond; + } else if (psclus->layer() == PFLayer::PS2) { + ps2_energy_sum += psclus->energy(); + condP2 &= cond; } } - if (condP1 == 1) - ePS1 = -1.; - if (condP2 == 1) - ePS2 = -1.; + double ePS1 = condP1 ? -1. : 0.; + double ePS2 = condP2 ? -1. : 0.; double cluscalibe = energyEm(eeCluster, ps1_energy_sum, ps2_energy_sum, ePS1, ePS2, applyCrackCorrections); @@ -216,11 +194,9 @@ PFEnergyCalibration::CalibratedEndcapPFClusterEnergies PFEnergyCalibration::cali void PFEnergyCalibration::energyEmHad(double t, double& e, double& h, double eta, double phi) const { // Use calorimetric energy as true energy for neutral particles - double tt = t; - double ee = e; - double hh = h; - double a = 1.; - double b = 1.; + const double tt = t; + const double ee = e; + const double hh = h; double etaCorrE = 1.; double etaCorrH = 1.; auto absEta = std::abs(eta); @@ -231,8 +207,8 @@ void PFEnergyCalibration::energyEmHad(double t, double& e, double& h, double eta // Barrel calibration if (absEta < 1.48) { // The energy correction - a = e > 0. ? aBarrel(t) : 1.; - b = e > 0. ? bBarrel(t) : cBarrel(t); + double a = e > 0. ? aBarrel(t) : 1.; + double b = e > 0. ? bBarrel(t) : cBarrel(t); double thresh = e > 0. ? threshE : threshH; // Protection against negative calibration @@ -262,8 +238,8 @@ void PFEnergyCalibration::energyEmHad(double t, double& e, double& h, double eta // Endcap calibration } else { // The energy correction - a = e > 0. ? aEndcap(t) : 1.; - b = e > 0. ? bEndcap(t) : cEndcap(t); + double a = e > 0. ? aEndcap(t) : 1.; + double b = e > 0. ? bEndcap(t) : cEndcap(t); double thresh = e > 0. ? threshE : threshH; // Protection against negative calibration @@ -277,8 +253,8 @@ void PFEnergyCalibration::energyEmHad(double t, double& e, double& h, double eta t = min(999.9, max(tt, thresh + a * e + b * h)); // The angular correction - double dEta = std::abs(absEta - 1.5); - double etaPow = dEta * dEta * dEta * dEta; + const double dEta = std::abs(absEta - 1.5); + const double etaPow = dEta * dEta * dEta * dEta; if (e > 0. && thresh > 0.) { if (absEta < 2.5) { @@ -543,16 +519,7 @@ double PFEnergyCalibration::energyEm(const reco::PFCluster& clusterEcal, double ePS1, double ePS2, bool crackCorrection) const { - double eEcal = clusterEcal.energy(); - //temporaty ugly fix - reco::PFCluster myPFCluster = clusterEcal; - myPFCluster.calculatePositionREP(); - double eta = myPFCluster.positionREP().eta(); - double phi = myPFCluster.positionREP().phi(); - - double calibrated = Ecorr(eEcal, ePS1, ePS2, eta, phi, crackCorrection); - // if(eEcal!=0 && calibrated==0) std::cout<<"Eecal = "<