15#include "TObjString.h"
23#include "GaudiKernel/SystemOfUnits.h"
24using Gaudi::Units::GeV;
54 ATH_MSG_FATAL(
"Particle type not set: you have to set property ParticleType to a valid value");
55 return StatusCode::FAILURE;
65 return StatusCode::FAILURE;
73 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
81 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
89 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
97 std::unique_ptr<egammaMVAFunctions::funcMap_t> funcLibraryPtr =
106 return StatusCode::FAILURE;
111 TClass::GetClass (
"TH2Poly");
112 TClass::GetClass (
"TMultiGraph");
114 return StatusCode::SUCCESS;
118 const std::string& fileName)
122 std::unique_ptr<TFile> f(TFile::Open(fileName.c_str()));
123 if (!f || f->IsZombie()) {
125 return StatusCode::FAILURE;
129 TH2Poly *hPoly =
nullptr;
130 f->GetObject(
"hPoly", hPoly);
133 return StatusCode::FAILURE;
136 m_hPoly.reset(
static_cast<TH2Poly*
>(hPoly));
137 m_hPoly->SetDirectory(
nullptr);
140 TObjArray *variablesTmp =
nullptr;
141 f->GetObject(
"variables", variablesTmp);
144 return StatusCode::FAILURE;
146 auto variables = std::unique_ptr<TObjArray>(variablesTmp);
147 variables->SetOwner();
150 TObjArray *shiftsTmp =
nullptr;
151 f->GetObject(
"shifts", shiftsTmp);
154 return StatusCode::FAILURE;
156 auto shifts = std::unique_ptr<TObjArray>(shiftsTmp);
160 TObjArray *treesTmp =
nullptr;
161 std::unique_ptr<TObjArray> trees;
162 f->GetObject(
"trees", treesTmp);
164 trees = std::unique_ptr<TObjArray>(treesTmp);
169 trees = std::make_unique<TObjArray>();
171 for (
int i = 0; i < variables->GetEntries(); ++i)
173 TTree *
tree =
nullptr;
174 f->GetObject(Form(
"BDT%d", i),
tree);
176 trees->AddAtAndExpand(
tree, i);
181 if (!trees->GetEntries() || !(trees->GetEntries() == variables->GetEntries())) {
183 <<
" while variables has size " << variables->GetEntries());
184 return StatusCode::FAILURE;
192 TIter nextTree(trees.get());
193 TIter nextVariables(variables.get());
194 TIter nextShift(shifts.get());
195 for (
int i=0; (
tree = (TTree*) nextTree()) && ((TObjString*) nextVariables()); ++i)
201 char separator_var =
';';
202 if (
getString(variables->At(i)).Index(
";") < 1) separator_var =
',';
203 std::unique_ptr<TObjArray> tokens(
getString(variables->At(i)).Tokenize(separator_var));
204 TIter nextVar(tokens.get());
205 while ((str2 = (TObjString*) nextVar()))
207 const TString& varName =
getString(str2);
208 if (varName.Contains(
"npv") || varName.Contains(
"actualIntPerXing"))
210 if (!varName.Length()) {
212 return StatusCode::FAILURE;
215 funcs.push_back(funcLibrary.at(varName.Data()));
216 }
catch(
const std::out_of_range& e) {
217 ATH_MSG_FATAL(
"Could not find formula for variable " << varName <<
", error: " << e.what());
218 return StatusCode::FAILURE;
221 m_funcs->funcs.push_back(std::move(funcs));
224 shift = (TObjString*) nextShift();
225 const TString& shiftFormula =
getString(shift);
226 m_shifts.emplace_back(
"", shiftFormula);
229 return StatusCode::SUCCESS;
235 TObjString *objS =
dynamic_cast<TObjString*
>(obj);
237 throw std::runtime_error(
"egammaMVACalibTool::getString was passed something that was not a string object");
239 return objS->GetString();
250 const auto initEnergy =
256 const auto etVarGeV = (initEnergy / std::cosh(clus.
eta())) /
GeV;
257 const auto etaVar = std::abs(clus.
eta());
259 ATH_MSG_DEBUG(
"Looking at object with initEnergy = " << initEnergy
260 <<
", etVarGeV = " << etVarGeV
261 <<
", etaVar = " << etaVar
262 <<
", clus->e() = " << clus.
e());
269 const int bin = hPoly->FindBin(etaVar, etVarGeV) - 1;
274 ATH_MSG_DEBUG(
"The bin is under/overflow; just return the energy");
278 if (
bin >=
static_cast<int>(
m_BDTs.size())) {
279 ATH_MSG_WARNING(
"The bin is outside the range, so just return the energy");
286 const int bin_BDT =
m_BDTs.size() != 1 ?
bin : 0;
287 const auto& bdt =
m_BDTs[bin_BDT];
288 const auto& funcs =
m_funcs->funcs[bin_BDT];
290 const size_t sz = funcs.size();
293 std::vector<float> vars(
sz);
295 for (
size_t i = 0; i <
sz; ++i) {
296 vars[i] = funcs[i](eg, &clus);
297 ATH_MSG_DEBUG(
"Variable " << i <<
" = " << std::format(
"{:10.4f}", vars[i]));
303 vars.insert(vars.end(),{float(gei.nPV), gei.acmu});
307 const float mvaOutput = bdt.GetResponse(vars);
308 ATH_MSG_DEBUG(
"BDT response = " << std::format(
"{:10.6f}", mvaOutput));
311 if (mvaOutput == 0.) {
320 mvaOutput : (initEnergy * mvaOutput);
322 ATH_MSG_DEBUG(
"energy after MVA = " << std::format(
"{:.3f}", energy));
330 const auto etGeV = (energy / std::cosh(clus.
eta())) /
GeV;
336 ATH_MSG_DEBUG(
"energy after MVA and shift = " << std::format(
"{:.3f}", energy/shift));
337 return energy / shift;
339 ATH_MSG_WARNING(
"Shift value too small: " << shift <<
"; not applying shift");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
size_t index() const
Return the index of this element within its container.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
std::unique_ptr< funcMap_t > initializeUnconvertedPhotonFuncs(bool useLayerCorrected)
A function to build the map for uncoverted photons.
float compute_correctedcl_Eacc(const xAOD::CaloCluster &cl)
std::unique_ptr< funcMap_t > initializeElectronFuncs(bool useLayerCorrected)
A function to build the map for electrons.
float compute_rawcl_Eacc(const xAOD::CaloCluster &cl)
std::unique_ptr< funcMap_t > initializeForwardElectronFuncs(bool useLayerCorrected)
NEW: A function to build the map for forward electrons.
std::unique_ptr< funcMap_t > initializeConvertedPhotonFuncs(bool useLayerCorrected)
A function to build the map for converted photons.
std::unordered_map< std::string, std::function< float(const xAOD::Egamma *, const xAOD::CaloCluster *)> > funcMap_t
Define the map type since it's long.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
A structure holding some global event information.