diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.cxx index 3f7868d1ef8e70aa4bdb8a3a4f0ad1ccd607a3bc..6cd7844b71d24db115701232fc2ae689c1586413 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.cxx @@ -41,7 +41,6 @@ Root::TElectronLikelihoodTool::TElectronLikelihoodTool(const char* name) , m_name(name) , m_variableBitMask(0x0) , m_ipBinning("") - , m_pdfFile(nullptr) , m_cutPosition_kinematic(-9) , m_cutPosition_NSilicon(-9) , m_cutPosition_NPixel(-9) @@ -275,16 +274,16 @@ Root::TElectronLikelihoodTool::initialize() TString tmpString(m_pdfFileName); gSystem->ExpandPathName(tmpString); std::string fname(tmpString.Data()); - m_pdfFile = TFile::Open(fname.c_str(), "READ"); + auto pdfFile = std::unique_ptr<TFile>(TFile::Open(fname.c_str(), "READ")); // Check that we could load the ROOT file - if (!m_pdfFile) { + if (!pdfFile) { ATH_MSG_ERROR(" No ROOT file found here: " << m_pdfFileName); return StatusCode::FAILURE; } // Load the histograms for (unsigned int varIndex = 0; varIndex < s_fnVariables; varIndex++) { - const std::string& vstr = fVariables[varIndex]; + const std::string& vstr = s_fVariables[varIndex]; // Skip the loading of PDFs for variables we don't care about for this // operating point. If the string is empty (which is true in the default // 2012 case), load all of them. @@ -292,13 +291,11 @@ Root::TElectronLikelihoodTool::initialize() !m_variableNames.empty()) { continue; } - loadVarHistograms(vstr, varIndex); + loadVarHistograms(vstr, pdfFile.get(), varIndex); } // TFile close does not free the memory - m_pdfFile->Close(); - // We need the destructor to be called - delete m_pdfFile; + pdfFile->Close(); //----------End File/Histo operation------------------------------------ ATH_MSG_DEBUG("Initialization complete for a LH tool with these specs:" @@ -350,6 +347,7 @@ Root::TElectronLikelihoodTool::initialize() int Root::TElectronLikelihoodTool::loadVarHistograms(const std::string& vstr, + TFile* pdfFile, unsigned int varIndex) { for (unsigned int s_or_b = 0; s_or_b < 2; s_or_b++) { @@ -369,13 +367,15 @@ Root::TElectronLikelihoodTool::loadVarHistograms(const std::string& vstr, getBinName(binname, et_tmp, eta_tmp, ip, m_ipBinning); if (((std::string(binname).find("2.37") != std::string::npos)) && - (vstr.find("el_f3") != std::string::npos)) + (vstr.find("el_f3") != std::string::npos)) { continue; + } if (((std::string(binname).find("2.01") != std::string::npos) || (std::string(binname).find("2.37") != std::string::npos)) && - (vstr.find("TRT") != std::string::npos)) + (vstr.find("TRT") != std::string::npos)) { continue; + } char pdfdir[500]; snprintf(pdfdir, 500, "%s/%s", vstr.c_str(), sig_bkg.c_str()); @@ -395,12 +395,12 @@ Root::TElectronLikelihoodTool::loadVarHistograms(const std::string& vstr, sig_bkg.c_str(), binname); - if (!m_pdfFile->GetListOfKeys()->Contains(vstr.c_str())) { + if (!pdfFile->GetListOfKeys()->Contains(vstr.c_str())) { ATH_MSG_INFO("Warning: skipping variable " << vstr << " because the folder does not exist."); return 1; } - if (!((TDirectory*)m_pdfFile->Get(vstr.c_str())) + if (!((TDirectory*)pdfFile->Get(vstr.c_str())) ->GetListOfKeys() ->Contains(sig_bkg.c_str())) { ATH_MSG_INFO("Warning: skipping variable " @@ -417,7 +417,7 @@ Root::TElectronLikelihoodTool::loadVarHistograms(const std::string& vstr, // If the 0th et bin (4-7 GeV) histogram does not exist in the root // file, then just use the 7-10 GeV bin histogram. This should // preserve backward compatibility - if (et == 0 && !((TDirectory*)m_pdfFile->Get(pdfdir)) + if (et == 0 && !((TDirectory*)pdfFile->Get(pdfdir)) ->GetListOfKeys() ->Contains(pdf)) { getBinName(binname, et_tmp + 1, eta_tmp, ip, m_ipBinning); @@ -435,11 +435,10 @@ Root::TElectronLikelihoodTool::loadVarHistograms(const std::string& vstr, sig_bkg.c_str(), binname); } - if (((TDirectory*)m_pdfFile->Get(pdfdir)) + if (((TDirectory*)pdfFile->Get(pdfdir)) ->GetListOfKeys() ->Contains(pdf)) { - TH1F* hist = - (TH1F*)(((TDirectory*)m_pdfFile->Get(pdfdir))->Get(pdf)); + TH1F* hist = (TH1F*)(((TDirectory*)pdfFile->Get(pdfdir))->Get(pdf)); fPDFbins[s_or_b][ip][et][eta][varIndex] = new EGSelectors::SafeTH1(hist); delete hist; @@ -812,7 +811,7 @@ Root::TElectronLikelihoodTool::evaluateLikelihood( for (unsigned int var = 0; var < s_fnVariables; var++) { - const std::string& varstr = fVariables[var]; + const std::string& varstr = s_fVariables[var]; // Skip variables that are masked off (not used) in the likelihood if (!(m_variableBitMask & (0x1 << var))) { @@ -1028,16 +1027,13 @@ Root::TElectronLikelihoodTool::TransformLikelihoodOutput(double ps, return disc; } -const double Root::TElectronLikelihoodTool::fIpBounds[IP_BINS + 1] = { 0., - 500. }; - //--------------------------------------------------------------------------------------- // Gets the IP bin unsigned int -Root::TElectronLikelihoodTool::getIpBin(double ip) const +Root::TElectronLikelihoodTool::getIpBin(double ip) { for (unsigned int ipBin = 0; ipBin < IP_BINS; ++ipBin) { - if (ip < fIpBounds[ipBin + 1]) + if (ip < s_fIpBounds[ipBin + 1]) return ipBin; } return 0; @@ -1046,7 +1042,7 @@ Root::TElectronLikelihoodTool::getIpBin(double ip) const //--------------------------------------------------------------------------------------- // Gets the Eta bin [0-9] given the eta unsigned int -Root::TElectronLikelihoodTool::getLikelihoodEtaBin(double eta) const +Root::TElectronLikelihoodTool::getLikelihoodEtaBin(double eta) { const unsigned int nEtaBins = s_fnEtaBins; const double etaBins[nEtaBins] = { 0.1, 0.6, 0.8, 1.15, 1.37, @@ -1062,7 +1058,7 @@ Root::TElectronLikelihoodTool::getLikelihoodEtaBin(double eta) const //--------------------------------------------------------------------------------------- // Gets the histogram Et bin given the et (MeV) -- corrresponds to fnEtBinsHist unsigned int -Root::TElectronLikelihoodTool::getLikelihoodEtHistBin(double eT) const +Root::TElectronLikelihoodTool::getLikelihoodEtHistBin(double eT) { const double GeV = 1000; @@ -1125,7 +1121,7 @@ Root::TElectronLikelihoodTool::getBinName(char* buffer, int etbin, int etabin, int ipbin, - const std::string& iptype) const + const std::string& iptype) { double eta_bounds[9] = { 0.0, 0.6, 0.8, 1.15, 1.37, 1.52, 1.81, 2.01, 2.37 }; int et_bounds[s_fnEtBinsHist] = { 4, 7, 10, 15, 20, 30, 40 }; @@ -1134,7 +1130,7 @@ Root::TElectronLikelihoodTool::getBinName(char* buffer, 200, "%s%det%02deta%0.2f", iptype.c_str(), - int(fIpBounds[ipbin]), + int(s_fIpBounds[ipbin]), et_bounds[etbin], eta_bounds[etabin]); } else { @@ -1149,8 +1145,8 @@ Root::TElectronLikelihoodTool::getLikelihoodBitmask( unsigned int mask = 0x0; ATH_MSG_DEBUG("Variables to be used: "); for (unsigned int var = 0; var < s_fnVariables; var++) { - if (vars.find(fVariables[var]) != std::string::npos) { - ATH_MSG_DEBUG(fVariables[var]); + if (vars.find(s_fVariables[var]) != std::string::npos) { + ATH_MSG_DEBUG(s_fVariables[var]); mask = mask | 0x1 << var; } } @@ -1312,7 +1308,7 @@ Root::TElectronLikelihoodTool::InterpolatePdfs(unsigned int s_or_b, //---------------------------------------------------------------------------------------- // These are the variables availalble in the likelihood. -const std::string Root::TElectronLikelihoodTool::fVariables[s_fnVariables] = { +const std::string Root::TElectronLikelihoodTool::s_fVariables[s_fnVariables] = { "el_d0significance", "el_eratio", "el_deltaeta1", diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.h index 321f9685e0039635275821827e1722d9773ec0fa..75236c51ddda58f88b06b80e812c19ef4a453c1c 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TElectronLikelihoodTool.h @@ -31,7 +31,7 @@ June 2011 class TFile; namespace { -const unsigned int IP_BINS = 1; +constexpr unsigned int IP_BINS = 1; } namespace LikeEnum { @@ -142,7 +142,9 @@ public: } /// Load the variable histograms from the pdf file. - int loadVarHistograms(const std::string& vstr, unsigned int varIndex); + int loadVarHistograms(const std::string& vstr, + TFile* pdfFile, + unsigned int varIndex); /// Define the binning inline void setBinning(const std::string& val) { m_ipBinning = val; } @@ -262,10 +264,10 @@ private: double eta) const; /// Eta binning for pdfs and discriminant cuts. - unsigned int getLikelihoodEtaBin(double eta) const; + static unsigned int getLikelihoodEtaBin(double eta) ; /// Coarse Et binning. Used for the likelihood pdfs. - unsigned int getLikelihoodEtHistBin(double eT) const; + static unsigned int getLikelihoodEtHistBin(double eT) ; /// Fine Et binning. Used for the likelihood discriminant cuts. unsigned int getLikelihoodEtDiscBin(double eT, const bool isLHbinning) const; @@ -285,9 +287,6 @@ private: /// Deprecated. std::string m_ipBinning; - /// Pointer to the opened TFile that holds the PDFs - TFile* m_pdfFile; - /// The position of the kinematic cut bit in the AcceptInfo return object int m_cutPosition_kinematic; @@ -323,29 +322,30 @@ private: /// object int m_cutPositionEoverPAtHighET; - static const double fIpBounds[IP_BINS + 1]; + static constexpr double s_fIpBounds[IP_BINS + 1] = { 0., 500. }; + // number of hists stored for original LH, including 4GeV bin (for backwards // compatibility) - static const unsigned int s_fnEtBinsHist = 7; + static constexpr unsigned int s_fnEtBinsHist = 7; // number of discs stored for original LH, excluding 4GeV bin (for // backwards compatibility) - static const unsigned int s_fnDiscEtBins = 9; + static constexpr unsigned int s_fnDiscEtBins = 9; // number of discs stored for original LH plus one for // HighETBinThreshold (useOneExtraHighETLHBin), excluding 4GeV bin - static const unsigned int s_fnDiscEtBinsOneExtra = 10; - static const unsigned int s_fnEtaBins = 10; - static const unsigned int s_fnVariables = 13; + static constexpr unsigned int s_fnDiscEtBinsOneExtra = 10; + static constexpr unsigned int s_fnEtaBins = 10; + static constexpr unsigned int s_fnVariables = 13; // 5D array of ptr to SafeTH1 // [sig(0)/bkg(1)][ip][et][eta][variable] EGSelectors::SafeTH1* fPDFbins[2][IP_BINS][s_fnEtBinsHist][s_fnEtaBins] [s_fnVariables]{}; - static const std::string fVariables[s_fnVariables]; + static const std::string s_fVariables[s_fnVariables]; - unsigned int getIpBin(double ip) const; - void getBinName(char* buffer, + static unsigned int getIpBin(double ip) ; + static void getBinName(char* buffer, int etbin, int etabin, int ipbin, - const std::string& iptype) const; + const std::string& iptype) ; }; } // End: namespace Root diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.cxx b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.cxx index d4745ff313fd8b85318c9c7b9ea4071c6363df72..247a4a3d52b3b4c7c51c1abd73a771a495c50328 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.cxx +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.cxx @@ -473,7 +473,7 @@ Root::TForwardElectronLikelihoodTool::TransformLikelihoodOutput(double ps, // Gets the IP bin unsigned int -Root::TForwardElectronLikelihoodTool::getIpBin(double ip) const +Root::TForwardElectronLikelihoodTool::getIpBin(double ip) { for (unsigned int ipBin = 0; ipBin < IP_FBINS; ++ipBin) { if (ip < fIpBounds[ipBin + 1]) @@ -484,7 +484,7 @@ Root::TForwardElectronLikelihoodTool::getIpBin(double ip) const // Gets the Eta bin given the eta . Binning uses uper bound unsigned int -Root::TForwardElectronLikelihoodTool::getLikelihoodEtaBin(double eta) const +Root::TForwardElectronLikelihoodTool::getLikelihoodEtaBin(double eta) { const unsigned int nEtaBins = s_fnEtaBins; const double etaBins[nEtaBins] = { 2.6, 2.7, 2.8, 2.9, 3.0, @@ -497,7 +497,7 @@ Root::TForwardElectronLikelihoodTool::getLikelihoodEtaBin(double eta) const } // Gets the histogram Et bin given the et (MeV). Binning uses upper bound unsigned int -Root::TForwardElectronLikelihoodTool::getLikelihoodEtHistBin(double eT) const +Root::TForwardElectronLikelihoodTool::getLikelihoodEtHistBin(double eT) { const double GeV = 1000; const unsigned int nEtBins = s_fnDiscEtBins; @@ -520,7 +520,7 @@ Root::TForwardElectronLikelihoodTool::getBinName( int etbin, int etabin, int ipbin, - const std::string& iptype) const + const std::string& iptype) { double eta_bounds[s_fnEtaBins] = { 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.16, 3.35, 3.6 }; diff --git a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.h b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.h index 72869ac81a4690af4e5052558f20317539bc0224..fad6ab3ea43b0d9a9295d5985a79c0136a5bef26 100644 --- a/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.h +++ b/PhysicsAnalysis/ElectronPhotonID/ElectronPhotonSelectorTools/Root/TForwardElectronLikelihoodTool.h @@ -207,10 +207,10 @@ private: double TransformLikelihoodOutput(double ps, double pb) const; /// Eta binning for pdfs and discriminant cuts. - unsigned int getLikelihoodEtaBin(double eta) const; + static unsigned int getLikelihoodEtaBin(double eta) ; /// Coarse Et binning. Used for the likelihood and discriminant pdfs. - unsigned int getLikelihoodEtHistBin(double eT) const; + static unsigned int getLikelihoodEtHistBin(double eT) ; // Private member variables private: @@ -246,12 +246,12 @@ private: EGSelectors::SafeTH1* fPDFbins[2][IP_FBINS][s_fnEtBinsHist][s_fnEtaBins] [s_fnVariables]{}; - unsigned int getIpBin(double ip) const; - void getBinName(char* buffer, + static unsigned int getIpBin(double ip) ; + static void getBinName(char* buffer, int etbin, int etabin, int ipbin, - const std::string& iptype) const; + const std::string& iptype) ; }; } // namespace Root