Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical optimisation of e/gamma (local)covariances function (11_3_X) #33270

Merged
merged 4 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
std::array<float, 3> cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to capture the return it would be better to use auto everywhere

Suggested change
std::array<float, 3> cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);
const auto& cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);

or

Suggested change
std::array<float, 3> cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);
const auto cov = EcalClusterTools::localCovariances(seedCluster, eeRecHits, p_topology);

I'm not sure which is better honestly, @VinInn what do you think?

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);
std::array<float, 3> cov = EcalClusterTools::localCovariances(seedCluster, ebRecHits, p_topology);
float sigmaIetaIeta = std::sqrt(cov[0]);
float sigmaIetaIphi = cov[1];

Expand Down
16 changes: 8 additions & 8 deletions DQMOffline/Trigger/src/EgHLTOffHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +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 =
std::array<float, 3> stdCov =
EcalClusterTools::covariances(seedClus, ebRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
std::array<float, 3> crysCov =
EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
Expand All @@ -338,9 +338,9 @@ void OffHelper::fillClusShapeData(const reco::GsfElectron& ele, OffEle::ClusShap
clusShapeData.r9 = -1.;

} else {
std::vector<float> stdCov =
std::array<float, 3> stdCov =
EcalClusterTools::covariances(seedClus, eeRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
std::array<float, 3> crysCov =
EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
Expand Down Expand Up @@ -496,16 +496,16 @@ 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 =
std::array<float, 3> stdCov =
EcalClusterTools::covariances(seedClus, ebRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
std::array<float, 3> crysCov =
EcalClusterTools::localCovariances(seedClus, ebRecHits_.product(), caloTopology_.product());
clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
clusShapeData.sigmaIPhiIPhi = sqrt(crysCov[2]);
} else {
std::vector<float> stdCov =
std::array<float, 3> stdCov =
EcalClusterTools::covariances(seedClus, eeRecHits_.product(), caloTopology_.product(), caloGeom_.product());
std::vector<float> crysCov =
std::array<float, 3> crysCov =
EcalClusterTools::localCovariances(seedClus, eeRecHits_.product(), caloTopology_.product());

clusShapeData.sigmaPhiPhi = sqrt(stdCov[2]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SuperClusterHelper {
/// cached variables
/// covariance matrix
bool covComputed_;
std::vector<float> vCov_;
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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/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()));
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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()));
std::array<float, 3> 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_);
std::array<float, 3> localCovariances = EcalClusterTools::localCovariances(seedCluster, recHits, caloTopo_);

const float eLeft = EcalClusterTools::eLeft(seedCluster, recHits, caloTopo_);
const float eRight = EcalClusterTools::eRight(seedCluster, recHits, caloTopo_);
Expand Down
14 changes: 7 additions & 7 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class EcalClusterLazyToolsT : public EcalClusterLazyToolsBase {
}

// 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 {
std::array<float, 3> covariances(const reco::BasicCluster &cluster, float w0 = 4.7) const {
return ClusterTools::covariances(cluster, getEcalRecHitCollection(cluster), topology_, geometry_, w0);
}

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
86 changes: 43 additions & 43 deletions RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ class EcalClusterToolsT {

// return a vector v with v[0] = covEtaEta, v[1] = covEtaPhi, v[2] = covPhiPhi

static std::vector<float> covariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
const CaloGeometry *geometry,
float w0 = 4.7);
static std::array<float, 3> covariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
const CaloGeometry *geometry,
float w0 = 4.7);

// return a vector 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
Expand All @@ -199,18 +199,18 @@ class EcalClusterToolsT {
//
//Warning: covIEtaIEta has been studied by 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
static std::vector<float> localCovariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0 = EgammaLocalCovParamDefaults::kRelEnCut,
const EcalPFRecHitThresholds *thresholds = nullptr,
float multEB = 0.0,
float multEE = 0.0);

static std::vector<float> scLocalCovariances(const reco::SuperCluster &cluster,
static std::array<float, 3> localCovariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0 = 4.7);
float w0 = EgammaLocalCovParamDefaults::kRelEnCut,
const EcalPFRecHitThresholds *thresholds = nullptr,
float multEB = 0.0,
float multEE = 0.0);

static std::array<float, 3> scLocalCovariances(const reco::SuperCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0 = 4.7);

// cluster second moments with respect to principal axes:
static Cluster2ndMoments cluster2ndMoments(const reco::BasicCluster &basicCluster,
Expand Down Expand Up @@ -960,11 +960,11 @@ std::pair<float, float> EcalClusterToolsT<noZS>::mean5x5PositionInXY(const reco:
}

template <bool noZS>
std::vector<float> EcalClusterToolsT<noZS>::covariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
const CaloGeometry *geometry,
float w0) {
std::array<float, 3> EcalClusterToolsT<noZS>::covariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
const CaloGeometry *geometry,
float w0) {
float e_5x5 = e5x5(cluster, recHits, topology);
float covEtaEta, covEtaPhi, covPhiPhi;
if (e_5x5 >= 0.) {
Expand Down Expand Up @@ -1025,10 +1025,10 @@ std::vector<float> EcalClusterToolsT<noZS>::covariances(const reco::BasicCluster
covEtaPhi = 0;
covPhiPhi = 0;
}
std::vector<float> v;
v.push_back(covEtaEta);
v.push_back(covEtaPhi);
v.push_back(covPhiPhi);
std::array<float, 3> v;
v[0] = covEtaEta;
v[1] = covEtaPhi;
v[2] = covPhiPhi;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and everywhere else

Suggested change
std::array<float, 3> v;
v[0] = covEtaEta;
v[1] = covEtaPhi;
v[2] = covPhiPhi;
std::array<float, 3> v{{covEtaEta, covEtaPhi, covPhiPhi}};

return v;
}

Expand All @@ -1037,13 +1037,13 @@ std::vector<float> EcalClusterToolsT<noZS>::covariances(const reco::BasicCluster
//it also does not require any eta correction function in the endcap
//it is multipled by an approprate crystal size to ensure it gives similar values to covariances(...)
template <bool noZS>
std::vector<float> EcalClusterToolsT<noZS>::localCovariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0,
const EcalPFRecHitThresholds *thresholds,
float multEB,
float multEE) {
std::array<float, 3> EcalClusterToolsT<noZS>::localCovariances(const reco::BasicCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0,
const EcalPFRecHitThresholds *thresholds,
float multEB,
float multEE) {
float e_5x5 = e5x5(cluster, recHits, topology);
float covEtaEta, covEtaPhi, covPhiPhi;

Expand Down Expand Up @@ -1125,10 +1125,10 @@ std::vector<float> EcalClusterToolsT<noZS>::localCovariances(const reco::BasicCl
covEtaPhi = 0;
covPhiPhi = 0;
}
std::vector<float> v;
v.push_back(covEtaEta);
v.push_back(covEtaPhi);
v.push_back(covPhiPhi);
std::array<float, 3> v;
v[0] = covEtaEta;
v[1] = covEtaPhi;
v[2] = covPhiPhi;
return v;
}

Expand Down Expand Up @@ -1384,10 +1384,10 @@ float EcalClusterToolsT<noZS>::getDPhiEndcap(const DetId &crysId, float meanX, f
}

template <bool noZS>
std::vector<float> EcalClusterToolsT<noZS>::scLocalCovariances(const reco::SuperCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0) {
std::array<float, 3> EcalClusterToolsT<noZS>::scLocalCovariances(const reco::SuperCluster &cluster,
const EcalRecHitCollection *recHits,
const CaloTopology *topology,
float w0) {
const reco::BasicCluster bcluster = *(cluster.seed());

float e_5x5 = e5x5(bcluster, recHits, topology);
Expand Down Expand Up @@ -1453,10 +1453,10 @@ std::vector<float> EcalClusterToolsT<noZS>::scLocalCovariances(const reco::Super
covPhiPhi = 0;
}

std::vector<float> v;
v.push_back(covEtaEta);
v.push_back(covEtaPhi);
v.push_back(covPhiPhi);
std::array<float, 3> v;
v[0] = covEtaEta;
v[1] = covEtaPhi;
v[2] = covPhiPhi;

return v;
}
Expand Down