37 float mu = eventInfoDecor(0);
44 std::vector<xAOD::Jet*> batchJets;
45 std::vector<xAOD::JetFourMom_t> batchStartP4;
46 std::vector<float> batchInputValues;
47 batchJets.reserve(jets.size());
48 batchStartP4.reserve(jets.size());
58 jet->setJetP4(jetStartP4);
61 if (jetStartP4.mass() <= 0 ||
jet->numConstituents() == 1) {
66 std::vector<float> inputTensorValues;
74 static const std::vector<std::string> logScaledVars = {
"log_e",
"log_m",
"log_m_cap40"};
76 bool eScaleAlreadyApplied = std::any_of(logScaledVars.begin(), logScaledVars.end(),
77 [&varName](
const std::string& n) { return varName.find(n) != std::string::npos; });
85 if (eScaleAlreadyApplied) {
86 normalisedVar = inputVar*normScale + normOffset;
88 normalisedVar = inputVar*eScale*normScale + normOffset;
92 <<
" normOffset=" << normOffset <<
" normScale=" << normScale <<
" normalised=" << normalisedVar);
94 inputTensorValues.push_back(normalisedVar);
97 int nNan = std::count_if(inputTensorValues.begin(), inputTensorValues.end(),
98 [](
float f){ return std::isnan(f) || std::isinf(f); });
100 ATH_MSG_WARNING(
"Encountered NaN or inf value in input features, will not apply calibration to this jet");
101 jet->setJetP4(jetStartP4);
106 batchJets.push_back(
jet);
107 batchStartP4.push_back(jetStartP4);
108 batchInputValues.insert(batchInputValues.end(), inputTensorValues.begin(), inputTensorValues.end());
111 if (batchJets.empty()) {
112 return StatusCode::SUCCESS;
115 const int64_t nBatch =
static_cast<int64_t
>(batchJets.size());
118 inputData[
"input_1"] = std::make_pair(
123 outputData[
"outputE"] = std::make_pair(std::vector<int64_t>{nBatch,
m_onnxOutputShape}, std::vector<float>{});
124 outputData[
"outputM"] = std::make_pair(std::vector<int64_t>{nBatch,
m_onnxOutputShape}, std::vector<float>{});
128 const std::vector<float>& outputE = std::get<std::vector<float>>(outputData[
"outputE"].second);
129 const std::vector<float>& outputM = std::get<std::vector<float>>(outputData[
"outputM"].second);
132 for (int64_t idx = 0; idx < nBatch; idx++) {
141 ATH_MSG_DEBUG(
"jetStartP4: pt=" << jetStartP4.pt() <<
" eta=" << jetStartP4.eta()
142 <<
" e=" << jetStartP4.e() <<
" m=" << jetStartP4.mass());
143 ATH_MSG_DEBUG(
"Predicted response: E=" << predRespE <<
" M=" << predRespM);
145 if (predRespE == 0 || predRespM == 0) {
146 ATH_MSG_WARNING(
"DNN predictions give 0 values, will not apply calibration to this jet");
147 jet->setJetP4(jetStartP4);
153 float calibE = jetStartP4.e() / predRespE;
157 float calibM = jetStartP4.mass() / predRespM;
160 float calibpT = std::sqrt(calibE*calibE - calibM*calibM) / std::cosh(jetStartP4.eta());
162 TLorentzVector TLVjet;
163 TLVjet.SetPtEtaPhiM(calibpT, jetStartP4.eta(), jetStartP4.phi(), calibM);
165 calibP4.SetPxPyPzE(TLVjet.Px(), TLVjet.Py(), TLVjet.Pz(), TLVjet.E());
167 jet->setJetP4(calibP4);
172 return StatusCode::SUCCESS;
Class JetContext Designed to read AOD information related to the event, N vertices,...
bool setValue(std::string_view name, const T value, bool allowOverwrite=false)