Skip to content

Commit

Permalink
Merge pull request #33270 from swagata87/egmCodeOptimization_113X
Browse files Browse the repository at this point in the history
Technical optimisation of e/gamma (local)covariances function (11_3_X)
  • Loading branch information
cmsbuild committed Mar 31, 2021
2 parents 770b5a2 + 9a90148 commit bf9409a
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 119 deletions.
4 changes: 2 additions & 2 deletions DQMOffline/Ecal/plugins/EcalPileUpDepMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void EcalPileUpDepMonitor::analyze(const edm::Event &e, const edm::EventSetup &)
const EcalRecHitCollection *eeRecHits = RecHitsEE.product();

reco::BasicCluster const &seedCluster(*itSC->seed());
std::vector<float> cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);
const auto &cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);
float sigmaIetaIeta = std::sqrt(cov[0]);
float sigmaIetaIphi = cov[1];

Expand Down Expand Up @@ -383,7 +383,7 @@ void EcalPileUpDepMonitor::analyze(const edm::Event &e, const edm::EventSetup &)
const EcalRecHitCollection *ebRecHits = RecHitsEB.product();

reco::BasicCluster const &seedCluster(*itSC->seed());
std::vector<float> cov = EcalClusterTools::localCovariances(seedCluster, ebRecHits, p_topology);
const auto &cov = EcalClusterTools::localCovariances(seedCluster, ebRecHits, p_topology);
float sigmaIetaIeta = std::sqrt(cov[0]);
float sigmaIetaIphi = cov[1];

Expand Down
20 changes: 8 additions & 12 deletions DQMOffline/Trigger/src/EgHLTOffHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ void OffHelper::fillClusShapeData(const reco::GsfElectron& ele, OffEle::ClusShap
seedClus.hitsAndFractions()[0]
.first; //note this may not actually be the seed hit but it doesnt matter because all hits will be in the barrel OR endcap
if (seedDetId.subdetId() == EcalBarrel) {
std::vector<float> stdCov =
const auto& stdCov =
EcalClusterTools::covariances(seedClus, ebRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
const auto& crysCov = EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
if (ele.superCluster()->rawEnergy() != 0.) {
Expand All @@ -338,10 +337,9 @@ void OffHelper::fillClusShapeData(const reco::GsfElectron& ele, OffEle::ClusShap
clusShapeData.r9 = -1.;

} else {
std::vector<float> stdCov =
const auto& stdCov =
EcalClusterTools::covariances(seedClus, eeRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());
const auto& crysCov = EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
if (ele.superCluster()->rawEnergy() != 0.) {
Expand Down Expand Up @@ -496,17 +494,15 @@ void OffHelper::fillClusShapeData(const reco::Photon& pho, OffPho::ClusShapeData
seedClus.hitsAndFractions()[0]
.first; //note this may not actually be the seed hit but it doesnt matter because all hits will be in the barrel OR endcap (it is also incredably inefficient as it getHitsByDetId passes the vector by value not reference
if (seedDetId.subdetId() == EcalBarrel) {
std::vector<float> stdCov =
const auto& stdCov =
EcalClusterTools::covariances(seedClus, ebRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
const auto& crysCov = EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
} else {
std::vector<float> stdCov =
const auto& stdCov =
EcalClusterTools::covariances(seedClus, eeRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());
const auto& crysCov = EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());

clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class SuperClusterHelper {
/// cached variables
/// covariance matrix
bool covComputed_;
std::vector<float> vCov_;
float spp_;
float sep_;
/// local coordinates
Expand Down
6 changes: 3 additions & 3 deletions EgammaAnalysis/ElectronTools/src/EGammaMvaEleEstimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ Double_t EGammaMvaEleEstimator::mvaValue(const reco::GsfElectron& ele,

// Pure ECAL -> shower shapes
fMVAVar_see = ele.sigmaIetaIeta(); //EleSigmaIEtaIEta
std::vector<float> vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
const auto& vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
if (edm::isFinite(vCov[2]))
fMVAVar_spp = sqrt(vCov[2]); //EleSigmaIPhiIPhi
else
Expand Down Expand Up @@ -1096,7 +1096,7 @@ Double_t EGammaMvaEleEstimator::mvaValue(const reco::GsfElectron& ele,

// Pure ECAL -> shower shapes
fMVAVar_see = ele.sigmaIetaIeta(); //EleSigmaIEtaIEta
std::vector<float> vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
const auto& vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
if (edm::isFinite(vCov[2]))
fMVAVar_spp = sqrt(vCov[2]); //EleSigmaIPhiIPhi
else
Expand Down Expand Up @@ -1654,7 +1654,7 @@ Double_t EGammaMvaEleEstimator::IDIsoCombinedMvaValue(const reco::GsfElectron& e

// Pure ECAL -> shower shapes
fMVAVar_see = ele.sigmaIetaIeta(); //EleSigmaIEtaIEta
std::vector<float> vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
const auto& vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
if (edm::isFinite(vCov[2]))
fMVAVar_spp = sqrt(vCov[2]); //EleSigmaIPhiIPhi
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Double_t EGammaMvaEleEstimatorCSA14::mvaValue(const reco::GsfElectron &ele,
fMVAVar_detacalo = ele.deltaEtaSeedClusterTrackAtCalo();

// Pure ECAL -> shower shapes
std::vector<float> vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
const auto &vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
if (edm::isFinite(vCov[0]))
fMVAVar_see = sqrt(vCov[0]); //EleSigmaIEtaIEta
else
Expand Down
2 changes: 1 addition & 1 deletion EgammaAnalysis/ElectronTools/src/SuperClusterHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SuperClusterHelper::SuperClusterHelper(const pat::Electron* electron,

void SuperClusterHelper::computeLocalCovariances() {
if (!covComputed_) {
vCov_ = EcalClusterTools::localCovariances(*seedCluster_, rechits_, topology_, 4.7);
const auto& vCov_ = EcalClusterTools::localCovariances(*seedCluster_, rechits_, topology_, 4.7);
covComputed_ = true;

spp_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion EgammaAnalysis/ElectronTools/test/ElectronTestAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void ElectronTestAnalyzer::myVar(const reco::GsfElectron& ele,
myMVAVar_dphicalo = ele.deltaPhiSeedClusterTrackAtCalo();

myMVAVar_see = ele.sigmaIetaIeta(); //EleSigmaIEtaIEta
std::vector<float> vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
const auto& vCov = myEcalCluster.localCovariances(*(ele.superCluster()->seed()));
if (edm::isFinite(vCov[2]))
myMVAVar_spp = sqrt(vCov[2]); //EleSigmaIPhiIPhi
else
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void PATElectronProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe

if (addMVAVariables_) {
// add missing mva variables
std::vector<float> vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
anElectron.setMvaVariables(vCov[1], ip3d);
}
// PFClusterIso
Expand Down Expand Up @@ -681,7 +681,7 @@ void PATElectronProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe

if (addMVAVariables_) {
// add mva variables
std::vector<float> vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
anElectron.setMvaVariables(vCov[1], ip3d);
}

Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/PatAlgos/plugins/PATElectronSlimmer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void pat::PATElectronSlimmer::produce(edm::Event& iEvent, const edm::EventSetup&
}
}
if (saveNonZSClusterShapes_(electron)) {
std::vector<float> vCov = lazyToolsNoZS.localCovariances(*(electron.superCluster()->seed()));
const auto& vCov = lazyToolsNoZS.localCovariances(*(electron.superCluster()->seed()));
electron.full5x5_setSigmaIetaIphi(vCov[1]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion PhysicsTools/PatAlgos/plugins/PATPhotonSlimmer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void pat::PATPhotonSlimmer::produce(edm::Event& iEvent, const edm::EventSetup& i
}
}
if (saveNonZSClusterShapes_(photon)) {
std::vector<float> vCov = lazyToolsNoZS.localCovariances(*(photon.superCluster()->seed()));
const auto& vCov = lazyToolsNoZS.localCovariances(*(photon.superCluster()->seed()));
float r9 = lazyToolsNoZS.e3x3(*(photon.superCluster()->seed())) / photon.superCluster()->rawEnergy();
float sigmaIetaIeta = (!edm::isNotFinite(vCov[0])) ? sqrt(vCov[0]) : 0;
float sigmaIetaIphi = vCov[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ std::vector<float> SCEnergyCorrectorSemiParm::getRegDataECALV1(const reco::Super
const double raw_energy = sc.rawEnergy();
const int numberOfClusters = sc.clusters().size();

std::vector<float> localCovariances = EcalClusterTools::localCovariances(seedCluster, recHits, caloTopo_);
const auto& localCovariances = EcalClusterTools::localCovariances(seedCluster, recHits, caloTopo_);

const float eLeft = EcalClusterTools::eLeft(seedCluster, recHits, caloTopo_);
const float eRight = EcalClusterTools::eRight(seedCluster, recHits, caloTopo_);
Expand Down
18 changes: 9 additions & 9 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
return ClusterTools::lat(cluster, getEcalRecHitCollection(cluster), geometry_, logW, w0);
}

// return a vector v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi
std::vector<float> covariances(const reco::BasicCluster &cluster, float w0 = 4.7) const {
// return an array v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi
std::array<float, 3> covariances(const reco::BasicCluster &cluster, float w0 = 4.7) const {
return ClusterTools::covariances(cluster, getEcalRecHitCollection(cluster), topology_, geometry_, w0);
}

// return a vector v with v[0] = covIEtaIEta, v[1] = covIEtaIPhi, v[2] = covIPhiIPhi
// return an array v with v[0] = covIEtaIEta, v[1] = covIEtaIPhi, v[2] = covIPhiIPhi
// this function calculates differences in eta/phi in units of crystals not
// global eta/phi this is gives better performance in the crack regions of
// the calorimeter but gives otherwise identical results to covariances
Expand All @@ -281,15 +281,15 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
// egamma, but so far covIPhiIPhi hasnt been studied extensively so there
// could be a bug in the covIPhiIEta or covIPhiIPhi calculations. I dont
// think there is but as it hasnt been heavily used, there might be one
std::vector<float> localCovariances(const reco::BasicCluster &cluster,
float w0 = EgammaLocalCovParamDefaults::kRelEnCut,
const EcalPFRecHitThresholds *rhthresholds = nullptr,
float multEB = 0.0,
float multEE = 0.0) const {
std::array<float, 3> localCovariances(const reco::BasicCluster &cluster,
float w0 = EgammaLocalCovParamDefaults::kRelEnCut,
const EcalPFRecHitThresholds *rhthresholds = nullptr,
float multEB = 0.0,
float multEE = 0.0) const {
return ClusterTools::localCovariances(
cluster, getEcalRecHitCollection(cluster), topology_, w0, rhthresholds, multEB, multEE);
}
std::vector<float> scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7) const {
std::array<float, 3> scLocalCovariances(const reco::SuperCluster &cluster, float w0 = 4.7) const {
return ClusterTools::scLocalCovariances(cluster, getEcalRecHitCollection(cluster), topology_, w0);
}
double zernike20(const reco::BasicCluster &cluster, double R0 = 6.6, bool logW = true, float w0 = 4.7) const {
Expand Down

0 comments on commit bf9409a

Please sign in to comment.