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

Use std:: functions instead of TMath:: functions in RecoEgamma #34325

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions RecoEgamma/EgammaElectronAlgos/src/ElectronEnergyCorrector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterFunctionBaseClass.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "TMath.h"

/****************************************************************************
*
Expand Down Expand Up @@ -73,18 +72,18 @@ namespace {
float rightEta[nBinsEta] = {0.25, 0.42, 0.77, 0.91, 1.01, 1.13, etaCrackMin, 1.653, 1.8, 2.0, 2.2, 2.3, 2.4, 2.5};

// eta = 0
if (TMath::Abs(eta) < leftEta[0]) {
if (std::abs(eta) < leftEta[0]) {
eta = 0.02;
}

// outside acceptance
if (TMath::Abs(eta) >= rightEta[nBinsEta - 1]) {
if (std::abs(eta) >= rightEta[nBinsEta - 1]) {
eta = 2.49;
} //if (DBG) std::cout << " WARNING [applyScCorrections]: TMath::Abs(eta) >= rightEta[nBinsEta-1] " << std::endl;}
} //if (DBG) std::cout << " WARNING [applyScCorrections]: std::abs(eta) >= rightEta[nBinsEta-1] " << std::endl;}

int tmpEta = -1;
for (int iEta = 0; iEta < nBinsEta; ++iEta) {
if (leftEta[iEta] <= TMath::Abs(eta) && TMath::Abs(eta) < rightEta[iEta]) {
if (leftEta[iEta] <= std::abs(eta) && std::abs(eta) < rightEta[iEta]) {
tmpEta = iEta;
}
}
Expand Down Expand Up @@ -168,7 +167,7 @@ namespace {
{
float tmpInter = 1;
for (int iEta = 0; iEta < nBinsEta - 1; ++iEta) {
if (rightEta[iEta] <= TMath::Abs(eta) && TMath::Abs(eta) < leftEta[iEta + 1]) {
if (rightEta[iEta] <= std::abs(eta) && std::abs(eta) < leftEta[iEta + 1]) {
if (sigmaPhiSigmaEta >= sigmaPhiSigmaEtaFit[cl]) {
tmpInter =
(par0[iEta][cl] + sigmaPhiSigmaEta * par1[iEta][cl] +
Expand Down Expand Up @@ -323,7 +322,7 @@ float egamma::classBasedElectronEnergy(reco::GsfElectron const& electron,
0,
elClass);

float et = energy * TMath::Sin(2 * TMath::ATan(TMath::Exp(-electron.superCluster()->eta()))) / corr;
float et = energy * std::sin(2 * std::atan(std::exp(-electron.superCluster()->eta()))) / corr;

if (electron.isEB()) {
corr2 = corr * fEt(et, 0, elClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace {
double et = energy / cosh(eta);

constexpr int nBinsEta = 5;
constexpr Double_t EtaBins[nBinsEta + 1] = {0.0, 0.4, 0.8, 1.5, 2.0, 2.5};
constexpr double EtaBins[nBinsEta + 1] = {0.0, 0.4, 0.8, 1.5, 2.0, 2.5};

constexpr int nBinsBrem = 6;
constexpr Double_t BremBins[nBinsBrem + 1] = {0.8, 1.0, 1.1, 1.2, 1.3, 1.5, 8.0};
constexpr double BremBins[nBinsBrem + 1] = {0.8, 1.0, 1.1, 1.2, 1.3, 1.5, 8.0};

constexpr float par0[nBinsEta][nBinsBrem] = {
{0.00567891, 0.0065673, 0.00574742, 0.00542964, 0.00523293, 0.00547518},
Expand Down Expand Up @@ -93,10 +93,10 @@ namespace {
const double et = energy / cosh(eta);

constexpr int nBinsEta = 4;
constexpr Double_t EtaBins[nBinsEta + 1] = {0.0, 0.8, 1.5, 2.0, 2.5};
constexpr double EtaBins[nBinsEta + 1] = {0.0, 0.8, 1.5, 2.0, 2.5};

constexpr int nBinsBrem = 1;
constexpr Double_t BremBins[nBinsBrem + 1] = {0.8, 8.0};
constexpr double BremBins[nBinsBrem + 1] = {0.8, 8.0};

constexpr float par0[nBinsEta][nBinsBrem] = {{0.00593389}, {0.00266954}, {0.00500623}, {0.00841038}};

Expand Down Expand Up @@ -155,10 +155,10 @@ namespace {
const double et = energy / cosh(eta);

constexpr int nBinsEta = 4;
constexpr Double_t EtaBins[nBinsEta + 1] = {0.0, 0.7, 1.3, 1.8, 2.5};
constexpr double EtaBins[nBinsEta + 1] = {0.0, 0.7, 1.3, 1.8, 2.5};

constexpr int nBinsBrem = 1;
constexpr Double_t BremBins[nBinsBrem + 1] = {0.8, 8.0};
constexpr double BremBins[nBinsBrem + 1] = {0.8, 8.0};

constexpr float par0[nBinsEta][nBinsBrem] = {{0.00601311}, {0.0059814}, {0.00953032}, {0.00728618}};

Expand Down Expand Up @@ -218,10 +218,10 @@ namespace {
const double et = energy / cosh(eta);

constexpr int nBinsEta = 4;
constexpr Double_t EtaBins[nBinsEta + 1] = {0.0, 0.8, 1.2, 1.7, 2.5};
constexpr double EtaBins[nBinsEta + 1] = {0.0, 0.8, 1.2, 1.7, 2.5};

constexpr int nBinsBrem = 5;
constexpr Double_t BremBins[nBinsBrem + 1] = {0.8, 1.8, 2.2, 3.0, 4.0, 8.0};
constexpr double BremBins[nBinsBrem + 1] = {0.8, 1.8, 2.2, 3.0, 4.0, 8.0};

constexpr float par0[nBinsEta][nBinsBrem] = {{0.0049351, 0.00566155, 0.0051397, 0.00468481, 0.00444475},

Expand Down Expand Up @@ -305,10 +305,10 @@ namespace {
const double et = energy / cosh(eta);

constexpr int nBinsEta = 5;
constexpr Double_t EtaBins[nBinsEta + 1] = {0.0, 0.42, 0.78, 1.2, 1.52, 1.65};
constexpr double EtaBins[nBinsEta + 1] = {0.0, 0.42, 0.78, 1.2, 1.52, 1.65};

constexpr int nBinsBrem = 6;
constexpr Double_t BremBins[nBinsBrem + 1] = {0.8, 1.2, 1.5, 2.1, 3., 4, 8.0};
constexpr double BremBins[nBinsBrem + 1] = {0.8, 1.2, 1.5, 2.1, 3., 4, 8.0};

constexpr float par0[nBinsEta][nBinsBrem] = {
{0.0139815, 0.00550839, 0.0108292, 0.00596201, -0.00498136, 0.000621696},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "RecoEgamma/EgammaPhotonAlgos/interface/EnergyUncertaintyPhotonSpecific.h"
#include "TMath.h"

#include <iostream>

Expand Down Expand Up @@ -205,7 +204,7 @@ double EnergyUncertaintyPhotonSpecific::computePhotonEnergyUncertainty_lowR9(dou

int iEtaSl = -1;
for (int iEta = 0; iEta < nBinsEta; ++iEta) {
if (EtaBins[iEta] <= TMath::Abs(eta) && TMath::Abs(eta) < EtaBins[iEta + 1]) {
if (EtaBins[iEta] <= std::abs(eta) && std::abs(eta) < EtaBins[iEta + 1]) {
iEtaSl = iEta;
}
}
Expand All @@ -217,7 +216,7 @@ double EnergyUncertaintyPhotonSpecific::computePhotonEnergyUncertainty_lowR9(dou
}
}

if (TMath::Abs(eta) > 2.5)
if (std::abs(eta) > 2.5)
iEtaSl = nBinsEta - 1;
if (brem < BremBins[0])
iBremSl = 0;
Expand Down Expand Up @@ -435,7 +434,7 @@ double EnergyUncertaintyPhotonSpecific::computePhotonEnergyUncertainty_highR9(do

int iEtaSl = -1;
for (int iEta = 0; iEta < nBinsEta; ++iEta) {
if (EtaBins[iEta] <= TMath::Abs(eta) && TMath::Abs(eta) < EtaBins[iEta + 1]) {
if (EtaBins[iEta] <= std::abs(eta) && std::abs(eta) < EtaBins[iEta + 1]) {
iEtaSl = iEta;
}
}
Expand All @@ -447,7 +446,7 @@ double EnergyUncertaintyPhotonSpecific::computePhotonEnergyUncertainty_highR9(do
}
}

if (TMath::Abs(eta) > 2.5)
if (std::abs(eta) > 2.5)
iEtaSl = nBinsEta - 1;
if (brem < BremBins[0])
iBremSl = 0;
Expand Down
60 changes: 30 additions & 30 deletions RecoEgamma/EgammaTools/src/EGEnergyCorrector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot

//highest energy basic cluster excluding seed basic cluster
CaloClusterPtr b2;
Double_t ebcmax = -99.;
double ebcmax = -99.;
for (reco::CaloCluster_iterator bit = s->clustersBegin(); bit != s->clustersEnd(); ++bit) {
const CaloClusterPtr bc = *bit;
if (bc->energy() > ebcmax && bc != b) {
Expand All @@ -94,7 +94,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot

//lowest energy basic cluster excluding seed (for pileup mitigation)
CaloClusterPtr bclast;
Double_t ebcmin = 1e6;
double ebcmin = 1e6;
for (reco::CaloCluster_iterator bit = s->clustersBegin(); bit != s->clustersEnd(); ++bit) {
const CaloClusterPtr bc = *bit;
if (bc->energy() < ebcmin && bc != b) {
Expand All @@ -114,10 +114,10 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot
}
}

Bool_t isbarrel = b->hitsAndFractions().at(0).first.subdetId() == EcalBarrel;
Bool_t hasbc2 = b2.isNonnull() && b2->energy() > 0.;
Bool_t hasbclast = bclast.isNonnull() && bclast->energy() > 0.;
Bool_t hasbclast2 = bclast2.isNonnull() && bclast2->energy() > 0.;
bool isbarrel = b->hitsAndFractions().at(0).first.subdetId() == EcalBarrel;
bool hasbc2 = b2.isNonnull() && b2->energy() > 0.;
bool hasbclast = bclast.isNonnull() && bclast->energy() > 0.;
bool hasbclast2 = bclast2.isNonnull() && bclast2->energy() > 0.;

if (isbarrel) {
//basic supercluster variables
Expand Down Expand Up @@ -208,10 +208,10 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot
fVals[57] = biphi; //crystal iphi
fVals[58] = bieta % 5; //submodule boundary eta symmetry
fVals[59] = biphi % 2; //submodule boundary phi symmetry
fVals[60] = (TMath::Abs(bieta) <= 25) * (bieta % 25) +
(TMath::Abs(bieta) > 25) *
((bieta - 25 * TMath::Abs(bieta) / bieta) % 20); //module boundary eta approximate symmetry
fVals[61] = biphi % 20; //module boundary phi symmetry
fVals[60] = (std::abs(bieta) <= 25) * (bieta % 25) +
(std::abs(bieta) > 25) *
((bieta - 25 * std::abs(bieta) / bieta) % 20); //module boundary eta approximate symmetry
fVals[61] = biphi % 20; //module boundary phi symmetry
fVals[62] = betacry; //local coordinates with respect to closest crystal center at nominal shower depth
fVals[63] = bphicry;

Expand All @@ -226,8 +226,8 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot
fVals[65] = hasbc2 ? bc2iphi : 0.;
fVals[66] = hasbc2 ? bc2ieta % 5 : 0.;
fVals[67] = hasbc2 ? bc2iphi % 2 : 0.;
fVals[68] = hasbc2 ? (TMath::Abs(bc2ieta) <= 25) * (bc2ieta % 25) +
(TMath::Abs(bc2ieta) > 25) * ((bc2ieta - 25 * TMath::Abs(bc2ieta) / bc2ieta) % 20)
fVals[68] = hasbc2 ? (std::abs(bc2ieta) <= 25) * (bc2ieta % 25) +
(std::abs(bc2ieta) > 25) * ((bc2ieta - 25 * std::abs(bc2ieta) / bc2ieta) % 20)
: 0.;
fVals[69] = hasbc2 ? bc2iphi % 20 : 0.;
fVals[70] = hasbc2 ? bc2etacry : 0.;
Expand All @@ -246,8 +246,8 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot
fVals[7] = vtxcol.size();
}

const Double_t varscale = 1.253;
Double_t den;
const double varscale = 1.253;
double den;
const GBRForest *reader;
const GBRForest *readervar;
if (isbarrel) {
Expand All @@ -260,8 +260,8 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithError(const Phot
readervar = fReadereevariance;
}

Double_t ecor = reader->GetResponse(fVals.data()) * den;
Double_t ecorerr = readervar->GetResponse(fVals.data()) * den * varscale;
double ecor = reader->GetResponse(fVals.data()) * den;
double ecorerr = readervar->GetResponse(fVals.data()) * den * varscale;

//printf("ecor = %5f, ecorerr = %5f\n",ecor,ecorerr);

Expand All @@ -278,7 +278,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
const SuperClusterRef s = p.superCluster();
const CaloClusterPtr b = s->seed(); //seed basic cluster

Bool_t isbarrel = b->hitsAndFractions().at(0).first.subdetId() == EcalBarrel;
bool isbarrel = b->hitsAndFractions().at(0).first.subdetId() == EcalBarrel;

//basic supercluster variables
fVals[0] = s->rawEnergy();
Expand Down Expand Up @@ -339,10 +339,10 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
fVals[31] = biphi; //crystal iphi
fVals[32] = bieta % 5; //submodule boundary eta symmetry
fVals[33] = biphi % 2; //submodule boundary phi symmetry
fVals[34] = (TMath::Abs(bieta) <= 25) * (bieta % 25) +
(TMath::Abs(bieta) > 25) *
((bieta - 25 * TMath::Abs(bieta) / bieta) % 20); //module boundary eta approximate symmetry
fVals[35] = biphi % 20; //module boundary phi symmetry
fVals[34] = (std::abs(bieta) <= 25) * (bieta % 25) +
(std::abs(bieta) > 25) *
((bieta - 25 * std::abs(bieta) / bieta) % 20); //module boundary eta approximate symmetry
fVals[35] = biphi % 20; //module boundary phi symmetry
fVals[36] = betacry; //local coordinates with respect to closest crystal center at nominal shower depth
fVals[37] = bphicry;

Expand All @@ -356,7 +356,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
// }
// else for (int i=0; i<31; ++i) printf("%i: %5f\n",i,fVals[i]);

Double_t den;
double den;
const GBRForest *reader;
const GBRForest *readervar;
if (isbarrel) {
Expand All @@ -369,7 +369,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
readervar = fReadereevariance;
}

Double_t ecor = reader->GetResponse(fVals.data()) * den;
double ecor = reader->GetResponse(fVals.data()) * den;

//apply shower shape rescaling - for Monte Carlo only, and only for calculation of energy uncertainty
if (applyRescale) {
Expand All @@ -379,7 +379,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
fVals[6] = 1.00002 * s->phiWidth() - 0.000371; //phiwidth
fVals[14] = fVals[3] * s->rawEnergy() / b->energy(); //compute consistent e3x3/eseed after r9 rescaling
if (fVals[15] <= 1.0) // rescale e5x5/eseed only if value is <=1.0, don't allow scaled values to exceed 1.0
fVals[15] = TMath::Min(1.0, 1.0022 * p.e5x5() / b->energy());
fVals[15] = std::min(1.0, 1.0022 * p.e5x5() / b->energy());

fVals[4] =
fVals[15] * b->energy() / s->rawEnergy(); // compute consistent e5x5()/rawEnergy() after e5x5/eseed resacling
Expand All @@ -400,12 +400,12 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
fVals[29] = 1.09 * be2x5right / b->energy();

} else {
fVals[3] = 1.0086 * p.r9() - 0.0007; //r9
fVals[4] = TMath::Min(1.0, 1.0022 * p.e5x5() / s->rawEnergy()); //e5x5/rawenergy
fVals[5] = 0.903254 * s->etaWidth() + 0.001346; //etawidth
fVals[6] = 0.99992 * s->phiWidth() + 4.8e-07; //phiwidth
fVals[3] = 1.0086 * p.r9() - 0.0007; //r9
fVals[4] = std::min(1.0, 1.0022 * p.e5x5() / s->rawEnergy()); //e5x5/rawenergy
fVals[5] = 0.903254 * s->etaWidth() + 0.001346; //etawidth
fVals[6] = 0.99992 * s->phiWidth() + 4.8e-07; //phiwidth
fVals[13] =
TMath::Min(1.0, 1.0022 * b->energy() / s->rawEnergy()); //eseed/rawenergy (practically equivalent to e5x5)
std::min(1.0, 1.0022 * b->energy() / s->rawEnergy()); //eseed/rawenergy (practically equivalent to e5x5)

fVals[14] = fVals[3] * s->rawEnergy() / b->energy(); //compute consistent e3x3/eseed after r9 rescaling

Expand All @@ -425,7 +425,7 @@ std::pair<double, double> EGEnergyCorrector::CorrectedEnergyWithErrorV3(const Ph
}
}

Double_t ecorerr = readervar->GetResponse(fVals.data()) * den;
double ecorerr = readervar->GetResponse(fVals.data()) * den;

//printf("ecor = %5f, ecorerr = %5f\n",ecor,ecorerr);

Expand Down
13 changes: 6 additions & 7 deletions RecoEgamma/EgammaTools/src/EcalClusterLocal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/CaloRecHit/interface/CaloCluster.h"
#include "TMath.h"
#include "TVector2.h"

namespace egammaTools {
Expand All @@ -25,7 +24,7 @@ namespace egammaTools {
caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel); //EcalBarrel = 1

const math::XYZPoint &position_ = bclus.position();
double Theta = -position_.theta() + 0.5 * TMath::Pi();
double Theta = -position_.theta() + 0.5 * M_PI;
double Eta = position_.eta();
double Phi = TVector2::Phi_mpi_pi(position_.phi());

Expand Down Expand Up @@ -69,14 +68,14 @@ namespace egammaTools {
GlobalPoint center_pos = cpyr->getPosition(depth);

double PhiCentr = TVector2::Phi_mpi_pi(center_pos.phi());
double PhiWidth = (TMath::Pi() / 180.);
double PhiWidth = (M_PI / 180.);
phicry = (TVector2::Phi_mpi_pi(Phi - PhiCentr)) / PhiWidth;
//Some flips to take into account ECAL barrel symmetries:
if (ieta < 0)
phicry *= -1.;

double ThetaCentr = -center_pos.theta() + 0.5 * TMath::Pi();
double ThetaWidth = (TMath::Pi() / 180.) * TMath::Cos(ThetaCentr);
double ThetaCentr = -center_pos.theta() + 0.5 * M_PI;
double ThetaWidth = (M_PI / 180.) * std::cos(ThetaCentr);
etacry = (Theta - ThetaCentr) / ThetaWidth;
//flip to take into account ECAL barrel symmetries:
if (ieta < 0)
Expand All @@ -99,7 +98,7 @@ namespace egammaTools {
caloGeometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap); //EcalBarrel = 1

const math::XYZPoint &position_ = bclus.position();
//double Theta = -position_.theta()+0.5*TMath::Pi();
//double Theta = -position_.theta()+0.5*M_PI;
double Eta = position_.eta();
double Phi = TVector2::Phi_mpi_pi(position_.phi());
double X = position_.x();
Expand All @@ -110,7 +109,7 @@ namespace egammaTools {
const float X0 = 0.89;
float T0 = 1.2;
//different T0 value if outside of preshower coverage
if (TMath::Abs(bclus.eta()) < 1.653)
if (std::abs(bclus.eta()) < 1.653)
T0 = 3.1;

double depth = X0 * (T0 + log(bclus.energy()));
Expand Down
5 changes: 2 additions & 3 deletions RecoEgamma/Examples/plugins/GsfElectronDataAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include "CLHEP/Units/GlobalPhysicalConstants.h"

#include "TMath.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH1I.h"
Expand Down Expand Up @@ -1993,8 +1992,8 @@ void GsfElectronDataAnalyzer::analyze(const edm::Event &iEvent, const edm::Event
if (!gsfIter->ecalDrivenSeed() && gsfIter->trackerDrivenSeed())
sclRef = gsfIter->parentSuperCluster();
histSclEn_->Fill(sclRef->energy());
double R = TMath::Sqrt(sclRef->x() * sclRef->x() + sclRef->y() * sclRef->y() + sclRef->z() * sclRef->z());
double Rt = TMath::Sqrt(sclRef->x() * sclRef->x() + sclRef->y() * sclRef->y());
double R = std::sqrt(sclRef->x() * sclRef->x() + sclRef->y() * sclRef->y() + sclRef->z() * sclRef->z());
double Rt = std::sqrt(sclRef->x() * sclRef->x() + sclRef->y() * sclRef->y());
histSclEt_->Fill(sclRef->energy() * (Rt / R));
histSclEtVsEta_->Fill(sclRef->eta(), sclRef->energy() * (Rt / R));
histSclEtVsPhi_->Fill(sclRef->phi(), sclRef->energy() * (Rt / R));
Expand Down
Loading