From 165217c3f941e77f412895a727306ad61aa35686 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 12 Jun 2026 16:26:50 +0200 Subject: [PATCH 1/3] Add generic emulator wrapper for NGJet --- .../interface/L1TSC4NGJetID.h | 60 +++--- .../Phase2L1ParticleFlow/src/L1TSC4NGJet.cc | 201 ++++++++++++------ 2 files changed, 170 insertions(+), 91 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h b/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h index 32f7538c62e5c..07d3a9ec4b7ef 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h @@ -14,6 +14,8 @@ namespace L1TSC4NGJet { + typedef ap_fixed<64, 32,AP_RND,AP_SAT,0> inputtype; + template t candidate_mass(l1ct::PuppiObj puppicand) { // Define lookup table @@ -43,39 +45,49 @@ namespace L1TSC4NGJet { class L1TSC4NGJetID { public: L1TSC4NGJetID(const std::shared_ptr model, int iNParticles, bool debug); - - typedef ap_fixed<24, 12, AP_RND, AP_SAT, 0> inputtype; - typedef std::array, 8> classtype; - typedef std::array, 1> regressiontype; - typedef std::pair pairtype; + + static const int N_candidates = 16; + static const int N_candidate_features = 21; + static const int N_candidate_inputs = N_candidates * N_candidate_features; + static const int N_jet_inputs = 2; + static const int N_class_outputs = 8; + static const int N_regression_outputs = 1; // Intermediate output type to allow full precision multiplication of jet pt by the ratio typedef ap_ufixed<22, 12, AP_TRN, AP_SAT> output_regression_type; // Intermediate output type for classification score to be loaded into jet word - typedef std::array output_class_type; - typedef std::pair outputpairtype; - void setNNVectorVar(); + typedef std::array output_class_type; + typedef std::pair, output_class_type> outputpairtype; + + void setVectors(); outputpairtype EvaluateNNFixed(); outputpairtype computeFixed(const l1t::PFJet &iJet); private: - std::vector NNvectorVar_; + std::vector candidate_vector_; + std::vector jet_vector_; + int fNParticles_; - std::unique_ptr fPt_; - std::unique_ptr fPt_rel_; - std::unique_ptr fDEta_; - std::unique_ptr fDPhi_; - std::unique_ptr fPt_log_; - std::unique_ptr fMass_; - std::unique_ptr fZ0_; - std::unique_ptr fDxy_; - std::unique_ptr fIs_filled_; - std::unique_ptr fPuppi_weight_; - std::unique_ptr fEmID_; - std::unique_ptr fQuality_; - - std::unique_ptr fCharge_; - std::unique_ptr fId_; + std::unique_ptr fPt_; + std::unique_ptr fPt_rel_; + std::unique_ptr fDEta_; + std::unique_ptr fDPhi_; + std::unique_ptr fPt_log_; + std::unique_ptr fMass_; + std::unique_ptr fZ0_; + std::unique_ptr fDxy_; + std::unique_ptr fIs_filled_; + std::unique_ptr fPuppi_weight_; + std::unique_ptr fEmID_; + std::unique_ptr fQuality_; + std::unique_ptr fEta_; + + std::unique_ptr fCharge_; + std::unique_ptr fId_; + + L1TSC4NGJet::inputtype fJetPt_; + L1TSC4NGJet::inputtype fJetEta_; + std::shared_ptr modelRef_; bool isDebugEnabled_; diff --git a/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc b/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc index 9879f9c494011..7742c40230075 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc @@ -3,9 +3,23 @@ #include "L1Trigger/Phase2L1ParticleFlow/interface/common/log.h" #include +using namespace L1TSC4NGJet; + + struct ModelInputs { + inputtype* candidate_inputs; + inputtype* jet_inputs; + int total_candidate_inputs; + int total_jet_inputs; + }; + + struct ModelOutputs { + inputtype* jet_class_output; + inputtype* jet_regression_output; + }; + L1TSC4NGJetID::L1TSC4NGJetID(const std::shared_ptr model, int iNParticles, bool debug) : modelRef_(model) { - NNvectorVar_.clear(); + candidate_vector_.clear(); fNParticles_ = iNParticles; isDebugEnabled_ = debug; @@ -21,13 +35,18 @@ L1TSC4NGJetID::L1TSC4NGJetID(const std::shared_ptr model, fPuppi_weight_ = std::make_unique(fNParticles_); fEmID_ = std::make_unique(fNParticles_); fQuality_ = std::make_unique(fNParticles_); + fEta_ = std::make_unique(fNParticles_); fId_ = std::make_unique(fNParticles_); fCharge_ = std::make_unique(fNParticles_); + + fJetPt_ = 0; + fJetEta_ = 0; } -void L1TSC4NGJetID::setNNVectorVar() { - NNvectorVar_.clear(); +void L1TSC4NGJetID::setVectors() { + candidate_vector_.clear(); + jet_vector_.clear(); if (isDebugEnabled_) { LogDebug("L1TSC4NGJetID") << "\n ===== Input Vector =====" << std::endl; } @@ -36,131 +55,168 @@ void L1TSC4NGJetID::setNNVectorVar() { bool filled = fIs_filled_.get()[i0] == 1; inputtype null_value = 0; - NNvectorVar_.push_back(filled ? fPt_.get()[i0] : null_value); // pt - NNvectorVar_.push_back(filled ? fPt_rel_.get()[i0] : null_value); // pT as a fraction of jet pT - NNvectorVar_.push_back(filled ? fPt_log_.get()[i0] : null_value); // pt log - NNvectorVar_.push_back(filled ? fDEta_.get()[i0] : null_value); // dEta from jet axis - NNvectorVar_.push_back(filled ? fDPhi_.get()[i0] : null_value); // dPhi from jet axis - NNvectorVar_.push_back(filled ? fMass_.get()[i0] : null_value); // Mass - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::PHOTON) : null_value); // Photon - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEPLUS) : null_value); // Positron - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEMINUS) : null_value); // Electron - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUPLUS) : null_value); // Anti-muon - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUMINUS) : null_value); // Muon - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADZERO) : null_value); - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADPLUS) : null_value); // Anti-Pion - NNvectorVar_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADMINUS) : null_value); // Pion - NNvectorVar_.push_back(filled ? fZ0_.get()[i0] : null_value); // z0 - NNvectorVar_.push_back(filled ? fDxy_.get()[i0] : null_value); // dxy - NNvectorVar_.push_back(filled ? fIs_filled_.get()[i0] : null_value); // isfilled - NNvectorVar_.push_back(filled ? fPuppi_weight_.get()[i0] : null_value); // puppi weight - NNvectorVar_.push_back(filled ? fEmID_.get()[i0] : null_value); // emID - NNvectorVar_.push_back(filled ? fQuality_.get()[i0] : null_value); // quality + candidate_vector_.push_back(filled ? fPt_.get()[i0] : null_value); // pt + candidate_vector_.push_back(filled ? fPt_rel_.get()[i0] : null_value); // pT as a fraction of jet pT + candidate_vector_.push_back(filled ? fPt_log_.get()[i0] : null_value); // pt log + candidate_vector_.push_back(filled ? fDEta_.get()[i0] : null_value); // dEta from jet axis + candidate_vector_.push_back(filled ? fDPhi_.get()[i0] : null_value); // dPhi from jet axis + candidate_vector_.push_back(filled ? fMass_.get()[i0] : null_value); // Mass + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::PHOTON) : null_value); // Photon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEPLUS) : null_value); // Positron + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEMINUS) : null_value); // Electron + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUPLUS) : null_value); // Anti-muon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUMINUS) : null_value); // Muon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADZERO) : null_value); + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADPLUS) : null_value); // Anti-Pion + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADMINUS) : null_value); // Pion + candidate_vector_.push_back(filled ? fZ0_.get()[i0] : null_value); // z0 + candidate_vector_.push_back(filled ? fDxy_.get()[i0] : null_value); // dxy + candidate_vector_.push_back(filled ? fIs_filled_.get()[i0] : null_value); // isfilled + candidate_vector_.push_back(filled ? fPuppi_weight_.get()[i0] : null_value); // puppi weight + candidate_vector_.push_back(filled ? fEmID_.get()[i0] : null_value); // emID + candidate_vector_.push_back(filled ? fQuality_.get()[i0] : null_value); // quality + candidate_vector_.push_back(filled ? fEta_.get()[i0] : null_value); // eta if (isDebugEnabled_) { LogDebug("L1TSC4NGJetID") << "Particle: " << i0 << "\n" - << "pT: " << NNvectorVar_[i0 * 20] + << "pT: " << candidate_vector_[i0 * N_candidate_features] << " | " "pT rel: " - << NNvectorVar_[i0 * 20 + 1] + << candidate_vector_[i0 * N_candidate_features + 1] << " | " "pT log: " - << NNvectorVar_[i0 * 20 + 2] + << candidate_vector_[i0 * N_candidate_features + 2] << " | " "dEta: " - << NNvectorVar_[i0 * 20 + 3] + << candidate_vector_[i0 * N_candidate_features + 3] << " | " "dPhi: " - << NNvectorVar_[i0 * 20 + 4] + << candidate_vector_[i0 * N_candidate_features + 4] << " | " "mass: " - << NNvectorVar_[i0 * 20 + 5] + << candidate_vector_[i0 * N_candidate_features + 5] << " | " "photon ID: " - << NNvectorVar_[i0 * 20 + 6] + << candidate_vector_[i0 * N_candidate_features + 6] << " | " "electron + ID: " - << NNvectorVar_[i0 * 20 + 7] + << candidate_vector_[i0 * N_candidate_features + 7] << " | " "electron - ID: " - << NNvectorVar_[i0 * 20 + 8] + << candidate_vector_[i0 * N_candidate_features + 8] << " | " "muon + ID: " - << NNvectorVar_[i0 * 20 + 9] + << candidate_vector_[i0 * N_candidate_features + 9] << " | " "muon - ID: " - << NNvectorVar_[i0 * 20 + 10] + << candidate_vector_[i0 * N_candidate_features + 10] << " | " "neutral hadron ID: " - << NNvectorVar_[i0 * 20 + 11] + << candidate_vector_[i0 * N_candidate_features + 11] << " | " "hadron + ID: " - << NNvectorVar_[i0 * 20 + 12] + << candidate_vector_[i0 * N_candidate_features + 12] << " | " "hadron - ID: " - << NNvectorVar_[i0 * 20 + 13] + << candidate_vector_[i0 * N_candidate_features + 13] << " | " "z0: " - << NNvectorVar_[i0 * 20 + 14] + << candidate_vector_[i0 * N_candidate_features + 14] << " | " "sqrt Dxy: " - << NNvectorVar_[i0 * 20 + 15] + << candidate_vector_[i0 * N_candidate_features + 15] << " | " "is filled: " - << NNvectorVar_[i0 * 20 + 16] + << candidate_vector_[i0 * N_candidate_features + 16] << " | " "puppi weight: " - << NNvectorVar_[i0 * 20 + 17] + << candidate_vector_[i0 * N_candidate_features + 17] << " | " "ElectroMagnetic ID: " - << NNvectorVar_[i0 * 20 + 18] + << candidate_vector_[i0 * N_candidate_features + 18] << " | " "Track Quality: " - << NNvectorVar_[i0 * 20 + 19] << " | " - << "===========" << std::endl; + << candidate_vector_[i0 * N_candidate_features + 19] + << " | " + "Eta: " + << candidate_vector_[i0 * N_candidate_features + 20] << " | " + << "===========" << std::endl; } } + // After the particle loop + jet_vector_.push_back(fJetPt_); + jet_vector_.push_back(fJetEta_); } L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { - const int NInputs = 320; - classtype classresult; - regressiontype regressionresult; inputtype fillzero = 0.0; - inputtype modelInput[NInputs] = {}; // Do something - std::fill(modelInput, modelInput + NInputs, fillzero); + // Define Candidate inputs and fill fully with 0s. Allows for case when N_candidate_inputs > candidate_vector_.size(). + inputtype modelCandidateInput[N_candidate_inputs] = {}; + std::fill(modelCandidateInput, modelCandidateInput + N_candidate_inputs, fillzero); + + // Fill the candidate inputs from the pre calculated NNvectorVar + for (unsigned int i = 0; i < candidate_vector_.size(); i++) { + modelCandidateInput[i] = candidate_vector_[i]; + } - for (unsigned int i = 0; i < NNvectorVar_.size(); i++) { - modelInput[i] = NNvectorVar_[i]; + // Define Jet inputs and fill fully with 0s. + inputtype modelJetInput[N_jet_inputs] = {}; + std::fill(modelJetInput, modelJetInput + N_jet_inputs, fillzero); + for (unsigned int i = 0; i < jet_vector_.size(); i++) { + modelJetInput[i] = jet_vector_[i]; } - pairtype modelResult; + // Define input struct + ModelInputs modelInputStruct; + // Load candidate and jet inputs + modelInputStruct.candidate_inputs = modelCandidateInput; + modelInputStruct.jet_inputs = modelJetInput; + modelInputStruct.total_candidate_inputs = N_candidate_features; + modelInputStruct.total_jet_inputs = N_jet_inputs; - modelRef_->prepare_input(modelInput); + // Define output struct + ModelOutputs modelOutputStruct; + + // Define and load output with zeros ready for replacement from the model + inputtype modelClassOutput[N_class_outputs] = {}; + inputtype modelRegressionOutput[N_regression_outputs] = {}; + std::fill(modelClassOutput, modelClassOutput + N_class_outputs, fillzero); + std::fill(modelRegressionOutput, modelRegressionOutput + N_regression_outputs, fillzero); + + // Load class and regression outputs + modelOutputStruct.jet_class_output = modelClassOutput; + modelOutputStruct.jet_regression_output = modelRegressionOutput; + + // Run the inference + modelRef_->prepare_input(modelInputStruct); modelRef_->predict(); - modelRef_->read_result(&modelResult); + modelRef_->read_result(&modelOutputStruct); outputpairtype modelResult_forOutput; if (isDebugEnabled_) { LogDebug("L1TSC4NGJetID") << "\n ===== Jet ID Output Score =====" << std::endl; } - for (unsigned int i = 0; i < 8; i++) { + for (unsigned int i = 0; i < N_class_outputs; i++) { // Cast model output to jet tag score datatype - modelResult_forOutput.second[i] = l1ct::jet_tag_score_t(modelResult.second[i]); + modelResult_forOutput.second[i] = l1ct::jet_tag_score_t(modelOutputStruct.jet_class_output[i]); if (isDebugEnabled_) { - LogDebug("L1TSC4NGJetID") << l1ct::JetTagClassHandler::tagClassesDefault_[i] << " : " << modelResult.second[i] + LogDebug("L1TSC4NGJetID") << l1ct::JetTagClassHandler::tagClassesDefault_[i] << " : " << modelOutputStruct.jet_class_output[i] << " Cast to Jet Class type: " << modelResult_forOutput.second[i] << std::endl; } } - // Cast model output to transient regression score for jet pt multiplication - modelResult_forOutput.first[0] = output_regression_type(modelResult.first[0]); - if (isDebugEnabled_) { - LogDebug("L1TSC4NGJetID") << "\n ===== Jet pT Correction Output ===== \n" - << modelResult.first[0] << " Cast to Jet pT type: " << modelResult_forOutput.first[0] - << std::endl; - } + + for (unsigned int i = 0; i < N_regression_outputs; i++) { + // Cast model output to transient regression score for jet pt multiplication + modelResult_forOutput.first[i] = modelOutputStruct.jet_regression_output[i]; + if (isDebugEnabled_) { + LogDebug("L1TSC4NGJetID") << "\n ===== Jet pT Correction Output ===== \n" + << modelOutputStruct.jet_regression_output[i] << " Cast to Jet pT type: " << modelResult_forOutput.first[i] + << std::endl; + } + } + return modelResult_forOutput; } //end EvaluateNNFixed @@ -178,6 +234,7 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet fPuppi_weight_.get()[i0] = 0; fEmID_.get()[i0] = 0; fQuality_.get()[i0] = 0; + fEta_.get()[i0] = 0; fId_.get()[i0] = 0; fCharge_.get()[i0] = 0; @@ -192,6 +249,11 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet inputtype jet_pt_ = inputtype(ctJet.hwPt); inputtype jet_eta_ = inputtype(ctJet.hwEta); inputtype jet_phi_ = inputtype(ctJet.hwPhi); + + // Fill jet level features + fJetPt_ = jet_pt_; + fJetEta_ = jet_eta_; + for (unsigned int i0 = 0; i0 < iParts.size(); i0++) { if (i0 >= (unsigned int)fNParticles_) @@ -200,7 +262,7 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet fPt_.get()[i0] = inputtype(puppicand.hwPt); constexpr int INV_LUT_SIZE = 1024; - inputtype inv_jet_pt = l1ct::invert_with_shift(jet_pt_); + inputtype inv_jet_pt = l1ct::invert_with_shift(jet_pt_); fPt_rel_.get()[i0] = inputtype(puppicand.hwPt) * inv_jet_pt; @@ -218,12 +280,17 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet fDPhi_.get()[i0] = dphiw; constexpr int LOG_LUT_SIZE = 256; - inputtype log_pt = l1ct::log_with_shift(puppicand.hwPt); + inputtype log_pt = l1ct::log_with_shift(puppicand.hwPt); fPt_log_.get()[i0] = log_pt; inputtype massCand = L1TSC4NGJet::candidate_mass(puppicand); fMass_.get()[i0] = inputtype(massCand); + inputtype const_eta = inputtype(puppicand.hwEta); + fEta_.get()[i0] = (const_eta < 0) + ? inputtype(-const_eta) + : inputtype(const_eta); + fZ0_.get()[i0] = puppicand.hwId.charged() ? inputtype(puppicand.hwZ0()) : inputtype(0); fDxy_.get()[i0] = puppicand.hwId.charged() ? inputtype(puppicand.hwDxy()) : inputtype(0); fIs_filled_.get()[i0] = inputtype(1); @@ -234,6 +301,6 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet fCharge_.get()[i0] = inputtype(puppicand.hwId.charged()); fId_.get()[i0] = inputtype(puppicand.hwId.bits); } - setNNVectorVar(); + setVectors(); return EvaluateNNFixed(); } From cf73c9bb652f3966582d333ef7f5e28bdd66170b Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 19 Jun 2026 14:40:07 +0200 Subject: [PATCH 2/3] code checks --- .../interface/L1TSC4NGJetID.h | 14 +-- .../Phase2L1ParticleFlow/src/L1TSC4NGJet.cc | 95 ++++++++++--------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h b/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h index 07d3a9ec4b7ef..497b4115716e4 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/L1TSC4NGJetID.h @@ -14,7 +14,7 @@ namespace L1TSC4NGJet { - typedef ap_fixed<64, 32,AP_RND,AP_SAT,0> inputtype; + typedef ap_fixed<64, 32, AP_RND, AP_SAT, 0> inputtype; template t candidate_mass(l1ct::PuppiObj puppicand) { @@ -45,11 +45,11 @@ namespace L1TSC4NGJet { class L1TSC4NGJetID { public: L1TSC4NGJetID(const std::shared_ptr model, int iNParticles, bool debug); - - static const int N_candidates = 16; - static const int N_candidate_features = 21; + + static const int N_candidates = 16; + static const int N_candidate_features = 21; static const int N_candidate_inputs = N_candidates * N_candidate_features; - static const int N_jet_inputs = 2; + static const int N_jet_inputs = 2; static const int N_class_outputs = 8; static const int N_regression_outputs = 1; @@ -57,7 +57,7 @@ class L1TSC4NGJetID { typedef ap_ufixed<22, 12, AP_TRN, AP_SAT> output_regression_type; // Intermediate output type for classification score to be loaded into jet word typedef std::array output_class_type; - typedef std::pair, output_class_type> outputpairtype; + typedef std::pair, output_class_type> outputpairtype; void setVectors(); outputpairtype EvaluateNNFixed(); @@ -84,7 +84,7 @@ class L1TSC4NGJetID { std::unique_ptr fCharge_; std::unique_ptr fId_; - + L1TSC4NGJet::inputtype fJetPt_; L1TSC4NGJet::inputtype fJetEta_; diff --git a/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc b/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc index 7742c40230075..57fdb5d2010f8 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/L1TSC4NGJet.cc @@ -5,17 +5,17 @@ using namespace L1TSC4NGJet; - struct ModelInputs { - inputtype* candidate_inputs; - inputtype* jet_inputs; - int total_candidate_inputs; - int total_jet_inputs; - }; - - struct ModelOutputs { - inputtype* jet_class_output; - inputtype* jet_regression_output; - }; +struct ModelInputs { + inputtype* candidate_inputs; + inputtype* jet_inputs; + int total_candidate_inputs; + int total_jet_inputs; +}; + +struct ModelOutputs { + inputtype* jet_class_output; + inputtype* jet_regression_output; +}; L1TSC4NGJetID::L1TSC4NGJetID(const std::shared_ptr model, int iNParticles, bool debug) : modelRef_(model) { @@ -61,21 +61,25 @@ void L1TSC4NGJetID::setVectors() { candidate_vector_.push_back(filled ? fDEta_.get()[i0] : null_value); // dEta from jet axis candidate_vector_.push_back(filled ? fDPhi_.get()[i0] : null_value); // dPhi from jet axis candidate_vector_.push_back(filled ? fMass_.get()[i0] : null_value); // Mass - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::PHOTON) : null_value); // Photon - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEPLUS) : null_value); // Positron - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEMINUS) : null_value); // Electron - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUPLUS) : null_value); // Anti-muon - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUMINUS) : null_value); // Muon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::PHOTON) : null_value); // Photon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEPLUS) + : null_value); // Positron + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::ELEMINUS) + : null_value); // Electron + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUPLUS) + : null_value); // Anti-muon + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::MUMINUS) : null_value); // Muon candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADZERO) : null_value); - candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADPLUS) : null_value); // Anti-Pion + candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADPLUS) + : null_value); // Anti-Pion candidate_vector_.push_back(filled ? inputtype(fId_.get()[i0] == l1ct::ParticleID::HADMINUS) : null_value); // Pion candidate_vector_.push_back(filled ? fZ0_.get()[i0] : null_value); // z0 candidate_vector_.push_back(filled ? fDxy_.get()[i0] : null_value); // dxy - candidate_vector_.push_back(filled ? fIs_filled_.get()[i0] : null_value); // isfilled + candidate_vector_.push_back(filled ? fIs_filled_.get()[i0] : null_value); // isfilled candidate_vector_.push_back(filled ? fPuppi_weight_.get()[i0] : null_value); // puppi weight candidate_vector_.push_back(filled ? fEmID_.get()[i0] : null_value); // emID candidate_vector_.push_back(filled ? fQuality_.get()[i0] : null_value); // quality - candidate_vector_.push_back(filled ? fEta_.get()[i0] : null_value); // eta + candidate_vector_.push_back(filled ? fEta_.get()[i0] : null_value); // eta if (isDebugEnabled_) { LogDebug("L1TSC4NGJetID") << "Particle: " << i0 << "\n" @@ -138,9 +142,9 @@ void L1TSC4NGJetID::setVectors() { "Track Quality: " << candidate_vector_[i0 * N_candidate_features + 19] << " | " - "Eta: " - << candidate_vector_[i0 * N_candidate_features + 20] << " | " - << "===========" << std::endl; + "Eta: " + << candidate_vector_[i0 * N_candidate_features + 20] << " | " + << "===========" << std::endl; } } // After the particle loop @@ -149,11 +153,10 @@ void L1TSC4NGJetID::setVectors() { } L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { - inputtype fillzero = 0.0; - // Define Candidate inputs and fill fully with 0s. Allows for case when N_candidate_inputs > candidate_vector_.size(). - inputtype modelCandidateInput[N_candidate_inputs] = {}; + // Define Candidate inputs and fill fully with 0s. Allows for case when N_candidate_inputs > candidate_vector_.size(). + inputtype modelCandidateInput[N_candidate_inputs] = {}; std::fill(modelCandidateInput, modelCandidateInput + N_candidate_inputs, fillzero); // Fill the candidate inputs from the pre calculated NNvectorVar @@ -162,7 +165,7 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { } // Define Jet inputs and fill fully with 0s. - inputtype modelJetInput[N_jet_inputs] = {}; + inputtype modelJetInput[N_jet_inputs] = {}; std::fill(modelJetInput, modelJetInput + N_jet_inputs, fillzero); for (unsigned int i = 0; i < jet_vector_.size(); i++) { modelJetInput[i] = jet_vector_[i]; @@ -170,7 +173,7 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { // Define input struct ModelInputs modelInputStruct; - // Load candidate and jet inputs + // Load candidate and jet inputs modelInputStruct.candidate_inputs = modelCandidateInput; modelInputStruct.jet_inputs = modelJetInput; modelInputStruct.total_candidate_inputs = N_candidate_features; @@ -178,14 +181,14 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { // Define output struct ModelOutputs modelOutputStruct; - + // Define and load output with zeros ready for replacement from the model - inputtype modelClassOutput[N_class_outputs] = {}; - inputtype modelRegressionOutput[N_regression_outputs] = {}; + inputtype modelClassOutput[N_class_outputs] = {}; + inputtype modelRegressionOutput[N_regression_outputs] = {}; std::fill(modelClassOutput, modelClassOutput + N_class_outputs, fillzero); std::fill(modelRegressionOutput, modelRegressionOutput + N_regression_outputs, fillzero); - // Load class and regression outputs + // Load class and regression outputs modelOutputStruct.jet_class_output = modelClassOutput; modelOutputStruct.jet_regression_output = modelRegressionOutput; @@ -202,25 +205,26 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::EvaluateNNFixed() { // Cast model output to jet tag score datatype modelResult_forOutput.second[i] = l1ct::jet_tag_score_t(modelOutputStruct.jet_class_output[i]); if (isDebugEnabled_) { - LogDebug("L1TSC4NGJetID") << l1ct::JetTagClassHandler::tagClassesDefault_[i] << " : " << modelOutputStruct.jet_class_output[i] + LogDebug("L1TSC4NGJetID") << l1ct::JetTagClassHandler::tagClassesDefault_[i] << " : " + << modelOutputStruct.jet_class_output[i] << " Cast to Jet Class type: " << modelResult_forOutput.second[i] << std::endl; } } - + for (unsigned int i = 0; i < N_regression_outputs; i++) { - // Cast model output to transient regression score for jet pt multiplication - modelResult_forOutput.first[i] = modelOutputStruct.jet_regression_output[i]; - if (isDebugEnabled_) { - LogDebug("L1TSC4NGJetID") << "\n ===== Jet pT Correction Output ===== \n" - << modelOutputStruct.jet_regression_output[i] << " Cast to Jet pT type: " << modelResult_forOutput.first[i] - << std::endl; - } - } + // Cast model output to transient regression score for jet pt multiplication + modelResult_forOutput.first[i] = modelOutputStruct.jet_regression_output[i]; + if (isDebugEnabled_) { + LogDebug("L1TSC4NGJetID") << "\n ===== Jet pT Correction Output ===== \n" + << modelOutputStruct.jet_regression_output[i] + << " Cast to Jet pT type: " << modelResult_forOutput.first[i] << std::endl; + } + } return modelResult_forOutput; } //end EvaluateNNFixed -L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet) { +L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet& iJet) { for (int i0 = 0; i0 < fNParticles_; i0++) { fPt_rel_.get()[i0] = 0; fPt_.get()[i0] = 0; @@ -249,12 +253,11 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet inputtype jet_pt_ = inputtype(ctJet.hwPt); inputtype jet_eta_ = inputtype(ctJet.hwEta); inputtype jet_phi_ = inputtype(ctJet.hwPhi); - + // Fill jet level features fJetPt_ = jet_pt_; fJetEta_ = jet_eta_; - for (unsigned int i0 = 0; i0 < iParts.size(); i0++) { if (i0 >= (unsigned int)fNParticles_) break; @@ -287,9 +290,7 @@ L1TSC4NGJetID::outputpairtype L1TSC4NGJetID::computeFixed(const l1t::PFJet &iJet fMass_.get()[i0] = inputtype(massCand); inputtype const_eta = inputtype(puppicand.hwEta); - fEta_.get()[i0] = (const_eta < 0) - ? inputtype(-const_eta) - : inputtype(const_eta); + fEta_.get()[i0] = (const_eta < 0) ? inputtype(-const_eta) : inputtype(const_eta); fZ0_.get()[i0] = puppicand.hwId.charged() ? inputtype(puppicand.hwZ0()) : inputtype(0); fDxy_.get()[i0] = puppicand.hwId.charged() ? inputtype(puppicand.hwDxy()) : inputtype(0); From ae9cc6c8abb6400e176d0b0f17fbd78b747b15e2 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Tue, 23 Jun 2026 08:19:01 +0200 Subject: [PATCH 3/3] Update default model to v2_0_0 --- L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC4NGJetProducer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC4NGJetProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC4NGJetProducer.cc index bb021c49240e5..0bfdc22508d08 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC4NGJetProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TSC4NGJetProducer.cc @@ -152,7 +152,7 @@ void L1TSC4NGJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descr desc.add("returnRawPt", false); desc.add("correctorFile", ""); desc.add("correctorDir", ""); - desc.add("l1tSC4NGJetModelPath", std::string("L1TSC4NGJetModel_v1_0_1")); + desc.add("l1tSC4NGJetModelPath", std::string("L1TSC4NGJetModel_v2_0_0")); desc.add("maxJets", 16); desc.add("nParticles", 16); desc.add("minPt", 10);