From ca9df6cc0089975eea7b4b652a40c45231bd409b Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Wed, 2 Aug 2023 19:32:19 +0200 Subject: [PATCH 1/3] Fix errors and warnings with C++20 in `FastTemplate.h` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The destructor and assignment operators are not allowed to include template specializations in C++20. They were not needed anyway, because the class itself is templated. Also, generalize the assignment operators to take `TH1` and check for the dimension at runtime. This is necessary to avoid other compiler warnings, such as: ``` interface/FastTemplate.h:123:34: warning: ‘FastTemplate_t& FastTemplate_t::operator=(const TH1&) [with T = double]’ was hidden [-Woverloaded-virtual=] 123 | virtual FastTemplate_t & operator=(const TH1 &other) { | ^~~~~~~~ interface/FastTemplate.h:284:24: note: by ‘FastHisto2D_t::operator=’ 284 | FastHisto2D_t& operator=(const TH2 &other) { ``` That is a very valid warning! `FastHisto2D_t` inherits from `FastTemplate_t`, and it's not good if their assignment operators take different types. --- interface/FastTemplate.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/interface/FastTemplate.h b/interface/FastTemplate.h index 08e7279aa0d..b61be41a120 100644 --- a/interface/FastTemplate.h +++ b/interface/FastTemplate.h @@ -120,7 +120,10 @@ template class FastTemplate_t { } return *this; } - virtual FastTemplate_t & operator=(const TH1 &other) { + virtual FastTemplate_t & operator=(const TH1 &other) { + if(other.GetDimension() != 1) { + throw std::invalid_argument("FastTemplate_t assignment error: right hand histogram must be 1-dimensional"); + } if ((int)size() != other.GetNbinsX()) { size_ = (unsigned int)other.GetNbinsX(); values_.resize(size_); @@ -200,7 +203,7 @@ template class FastHisto_t : public FastTempla else this->CopyValues(other); return *this; } - ~FastHisto_t(){} + ~FastHisto_t(){} }; template class FastHisto2D_t : public FastTemplate_t { private: @@ -278,9 +281,12 @@ template class FastHisto2D_t : public FastTemp else this->CopyValues(other); return *this; } - FastHisto2D_t& operator=(const TH2 &other) { - if (GetNbinsX() != other.GetNbinsX() || GetNbinsY() != other.GetNbinsY()) { - FastHisto2D_t fh(other); + FastHisto2D_t& operator=(const TH1 &other) { + if(other.GetDimension() != 2) { + throw std::invalid_argument("FastHisto2D_t assignment error: right hand histogram must be 2-dimensional"); + } + if (int(GetNbinsX()) != other.GetNbinsX() || int(GetNbinsY()) != other.GetNbinsY()) { + FastHisto2D_t fh(static_cast(other)); swap(fh); } else this->CopyValues(other); @@ -374,9 +380,12 @@ template class FastHisto3D_t : public FastTemp else this->CopyValues(other); return *this; } - FastHisto3D_t& operator=(const TH3 &other) { - if (GetNbinsX() != other.GetNbinsX() || GetNbinsY() != other.GetNbinsY() || GetNbinsZ() != other.GetNbinsZ()) { - FastHisto3D_t fh(other); + FastHisto3D_t& operator=(const TH1 &other) { + if(other.GetDimension() != 3) { + throw std::invalid_argument("FastHisto3D_t assignment error: right hand histogram must be 3-dimensional"); + } + if (int(GetNbinsX()) != other.GetNbinsX() || int(GetNbinsY()) != other.GetNbinsY() || int(GetNbinsZ()) != other.GetNbinsZ()) { + FastHisto3D_t fh(static_cast(other)); swap(fh); } else this->CopyValues(other); From e397b9fe5cf134f054f94ce8860df1e4daad9c49 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 28 Nov 2023 11:19:09 +0100 Subject: [PATCH 2/3] Add missing include to compile with ROOT `master` --- src/ProfiledLikelihoodRatioTestStat.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ProfiledLikelihoodRatioTestStat.cc b/src/ProfiledLikelihoodRatioTestStat.cc index 7bbea842df5..3a29700de56 100644 --- a/src/ProfiledLikelihoodRatioTestStat.cc +++ b/src/ProfiledLikelihoodRatioTestStat.cc @@ -1,6 +1,7 @@ #include "../interface/ProfiledLikelihoodRatioTestStat.h" #include "../interface/CloseCoutSentry.h" #include +#include #include Double_t ProfiledLikelihoodRatioTestStat::Evaluate(RooAbsData& data, RooArgSet& nullPOI) From 622b5b5f8935e84f574e5b8657a9bbd7c42700c1 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 28 Nov 2023 11:19:33 +0100 Subject: [PATCH 3/3] Avoid `operator-` on TComplex and RooRealProxy This will not work anymore in ROOT 6.30. The `double` value needs to be retrieved from the proxy first. --- src/HZZ4LRooPdfs.cc | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/HZZ4LRooPdfs.cc b/src/HZZ4LRooPdfs.cc index 9e221d4c141..613031da83b 100644 --- a/src/HZZ4LRooPdfs.cc +++ b/src/HZZ4LRooPdfs.cc @@ -4009,11 +4009,14 @@ ClassImp(RooCPSHighMassGGH) beta = getBeta(mH,effKPrime); } + // Cast the "x" proxy to double only once to avoid overhead and ambiguous + // overloads the TComplex operators. + const double xVal = x; - Double_t bwHM = x / ( TMath::Power( TMath::Power(x,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(x,2)*TMath::Power(effKPrime*width,2) ); + Double_t bwHM = xVal / ( TMath::Power( TMath::Power(xVal,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(xVal,2)*TMath::Power(effKPrime*width,2) ); Double_t splineFactor; - if (x<1850) splineFactor = Spline(x); + if (xVal<1850) splineFactor = Spline(xVal); else splineFactor = Spline(1850); Double_t signal = bwHM*splineFactor; @@ -4024,9 +4027,9 @@ ClassImp(RooCPSHighMassGGH) TComplex M = MSquared.Sqrt(MSquared); TComplex Exp1 = MSquared.Exp((TComplex)alpha); TComplex Exp2 = MSquared.Exp(-(TComplex)alpha); - TComplex Exp3 = MSquared.Exp(-x*(TComplex)alpha/M); + TComplex Exp3 = MSquared.Exp(-xVal*(TComplex)alpha/M); - double interference = -r*(1-TMath::Exp(-beta*(x-150.)/mH_eff))*((Exp1/(x-M)-Exp2/(x+M))*Exp3).Re(); + double interference = -r*(1-TMath::Exp(-beta*(xVal-150.)/mH_eff))*((Exp1/(xVal-M)-Exp2/(xVal+M))*Exp3).Re(); Double_t fValue = signal + IntStr*interference/( TMath::Sqrt(1-BRnew) ); if (fValue > 0) return fValue; @@ -4655,7 +4658,11 @@ ClassImp(RooBWHighMassGGH) Double_t r = getR(mH,effKPrime); Double_t beta = getBeta(mH,effKPrime); - Double_t bwHM = x / ( TMath::Power( TMath::Power(x,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(x,2)*TMath::Power(effKPrime*width,2) ); + // Cast the "x" proxy to double only once to avoid overhead and ambiguous + // overloads the TComplex operators. + const double xVal = x; + + Double_t bwHM = xVal / ( TMath::Power( TMath::Power(xVal,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(xVal,2)*TMath::Power(effKPrime*width,2) ); Double_t signal = bwHM; Double_t k=0.25; @@ -4666,7 +4673,7 @@ ClassImp(RooBWHighMassGGH) TComplex Exp2 = MSquared.Exp(-(TComplex)alpha); TComplex Exp3 = MSquared.Exp(-x*(TComplex)alpha/M); - double interference = -r*(1-TMath::Exp(-beta*(x-150.)/mH_eff))*((Exp1/(x-M)-Exp2/(x+M))*Exp3).Re(); + double interference = -r*(1-TMath::Exp(-beta*(xVal-150.)/mH_eff))*((Exp1/(xVal-M)-Exp2/(xVal+M))*Exp3).Re(); Double_t fValue = signal + IntStr*interference/( TMath::Sqrt(1-BRnew) ); if (fValue > 0) return fValue; @@ -6552,11 +6559,14 @@ ClassImp(RooCPSHighMassVBF) beta = getBeta(mH,effKPrime); } + // Cast the "x" proxy to double only once to avoid overhead and ambiguous + // overloads the TComplex operators. + const double xVal = x; - Double_t bwHM = x / ( TMath::Power( TMath::Power(x,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(x,2)*TMath::Power(effKPrime*width,2) ); + Double_t bwHM = xVal / ( TMath::Power( TMath::Power(xVal,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(xVal,2)*TMath::Power(effKPrime*width,2) ); Double_t splineFactor; - if (x<1850) splineFactor = Spline(x); + if (xVal<1850) splineFactor = Spline(xVal); else splineFactor = Spline(1850); Double_t signal = bwHM*splineFactor; @@ -6567,9 +6577,9 @@ ClassImp(RooCPSHighMassVBF) TComplex M = MSquared.Sqrt(MSquared); TComplex Exp1 = MSquared.Exp((TComplex)alpha); TComplex Exp2 = MSquared.Exp(-(TComplex)alpha); - TComplex Exp3 = MSquared.Exp(-x*(TComplex)alpha/M); + TComplex Exp3 = MSquared.Exp(-xVal*(TComplex)alpha/M); - double interference = -r*(1-TMath::Exp(-beta*(x-150.)/mH_eff))*((Exp1/(x-M)-Exp2/(x+M))*Exp3).Re(); + double interference = -r*(1-TMath::Exp(-beta*(xVal-150.)/mH_eff))*((Exp1/(xVal-M)-Exp2/(xVal+M))*Exp3).Re(); Double_t fValue = signal*(1+IntStr*interference/(bwHM*( TMath::Sqrt(1-BRnew) ))); if (fValue > 0) return fValue; @@ -7645,13 +7655,16 @@ ClassImp(RooSigPlusInt) Double_t RooSigPlusInt::evaluate() const { + // Cast the "x" proxy to double only once to avoid overhead and ambiguous + // overloads the TComplex operators. + const double xVal = x; Double_t totWidthSF = CSquared/(1-BRnew); Double_t mH_eff = mH*TMath::Sqrt(1-k*(totWidthSF*width/mH)*(totWidthSF*width/mH)); - + Double_t splineFactor = Spline(x); - Double_t bwHM = x / ( TMath::Power( TMath::Power(x,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(x,2)*TMath::Power(totWidthSF*width,2) ); + Double_t bwHM = xVal / ( TMath::Power( TMath::Power(xVal,2) - TMath::Power(mH+delta,2) , 2 ) + TMath::Power(xVal,2)*TMath::Power(totWidthSF*width,2) ); Double_t signal = splineFactor*bwHM; @@ -7659,9 +7672,9 @@ ClassImp(RooSigPlusInt) TComplex M = MSquared.Sqrt(MSquared); TComplex Exp1 = MSquared.Exp((TComplex)alpha); TComplex Exp2 = MSquared.Exp(-(TComplex)alpha); - TComplex Exp3 = MSquared.Exp(-x*(TComplex)alpha/M); + TComplex Exp3 = MSquared.Exp(-xVal*(TComplex)alpha/M); - double interference = -r*sqrt(1/1-BRnew)*(1-TMath::Exp(-beta*(x-150.)/mH_eff))*((Exp1/(x-M)-Exp2/(x+M))*Exp3).Re(); + double interference = -r*sqrt(1/1-BRnew)*(1-TMath::Exp(-beta*(xVal-150.)/mH_eff))*((Exp1/(xVal-M)-Exp2/(xVal+M))*Exp3).Re(); return signal + interference;