Skip to content

Commit

Permalink
code check updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiaz006 committed Dec 22, 2023
1 parent b415b1c commit 3c1d656
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
9 changes: 6 additions & 3 deletions L1Trigger/Phase2L1ParticleFlow/interface/JetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ struct BJetTFCache {

class JetId {
public:
JetId(const std::string &iInput, const std::string &iOutput, const std::shared_ptr<hls4mlEmulator::Model> model, int iNParticles);
JetId(const std::string &iInput,
const std::string &iOutput,
const std::shared_ptr<hls4mlEmulator::Model> model,
int iNParticles);
JetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles);
~JetId();

void setNNVectorVar();
float EvaluateNN();
ap_fixed<16,6> EvaluateNNFixed();
ap_fixed<16, 6> EvaluateNNFixed();
float compute(const l1t::PFJet &iJet, float vz, bool useRawPt);
ap_fixed<16,6> computeFixed(const l1t::PFJet &iJet, float vz, bool useRawPt);
ap_fixed<16, 6> computeFixed(const l1t::PFJet &iJet, float vz, bool useRawPt);

private:
std::vector<float> NNvectorVar_;
Expand Down
15 changes: 8 additions & 7 deletions L1Trigger/Phase2L1ParticleFlow/plugins/TOoLLiPProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ TOoLLiPProducer::TOoLLiPProducer(const edm::ParameterSet& cfg)
fMaxJets_(cfg.getParameter<int>("maxJets")),
fNParticles_(cfg.getParameter<int>("nParticles")),
fVtxEmu_(consumes<std::vector<l1t::VertexWord>>(cfg.getParameter<edm::InputTag>("vtx"))),
loader(hls4mlEmulator::ModelLoader(cfg.getParameter<string>("TOoLLiPVersion")))
{
loader(hls4mlEmulator::ModelLoader(cfg.getParameter<string>("TOoLLiPVersion"))) {
//load model and feed to JetID
model = loader.load_model();
fJetId_ = std::make_unique<JetId>(cfg.getParameter<std::string>("NNInput"), cfg.getParameter<std::string>("NNOutput"), model, fNParticles_);
fJetId_ = std::make_unique<JetId>(
cfg.getParameter<std::string>("NNInput"), cfg.getParameter<std::string>("NNOutput"), model, fNParticles_);
//produces<float>("L1LLPScores");
produces<edm::ValueMap<float>>("L1PFLLPJets");
}
Expand All @@ -78,14 +78,14 @@ void TOoLLiPProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
}
}

std::vector<float> LLPScores;
for (const auto& srcjet : *jets) {
std::vector<float> LLPScores;
for (const auto& srcjet : *jets) {
if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta()) > fMaxEta_ ||
LLPScores.size() >= fMaxJets_) {
LLPScores.push_back(-1.);
continue;
}
ap_fixed<16, 6> LLPScore = fJetId_->computeFixed(srcjet, vz, fUseRawPt_);
ap_fixed<16, 6> LLPScore = fJetId_->computeFixed(srcjet, vz, fUseRawPt_);
LLPScores.push_back(LLPScore);
}

Expand All @@ -102,7 +102,8 @@ void TOoLLiPProducer::fillDescriptions(edm::ConfigurationDescriptions& descripti
desc.add<edm::InputTag>("jets", edm::InputTag("scPFL1Puppi"));
desc.add<bool>("useRawPt", true);
//change for LLP
desc.add<std::string>("TOoLLiPVersion", std::string("/src/L1Trigger/Phase2L1ParticleFlow/test/TOoLLip_emulator_v1.so"));
desc.add<std::string>("TOoLLiPVersion",
std::string("/src/L1Trigger/Phase2L1ParticleFlow/test/TOoLLip_emulator_v1.so"));
desc.add<std::string>("NNInput", "input:0");
desc.add<std::string>("NNOutput", "sequential/dense_2/Sigmoid");
desc.add<int>("maxJets", 10);
Expand Down
15 changes: 9 additions & 6 deletions L1Trigger/Phase2L1ParticleFlow/src/JetId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#include "DataFormats/Math/interface/deltaPhi.h"
#include <cmath>

JetId::JetId(const std::string &iInput, const std::string &iOutput, const std::shared_ptr<hls4mlEmulator::Model> model, int iNParticles)
:modelRef_(model){
JetId::JetId(const std::string &iInput,
const std::string &iOutput,
const std::shared_ptr<hls4mlEmulator::Model> model,
int iNParticles)
: modelRef_(model) {
NNvectorVar_.clear();
fNParticles_ = iNParticles;

Expand Down Expand Up @@ -72,18 +75,18 @@ float JetId::EvaluateNN() {
return outputs[0].matrix<float>()(0, 0);
} //end EvaluateNN

ap_fixed<16,6> JetId::EvaluateNNFixed() {
ap_fixed<16,6> modelInput[140]={};
ap_fixed<16, 6> JetId::EvaluateNNFixed() {
ap_fixed<16, 6> modelInput[140] = {};
for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
modelInput[i] = NNvectorVar_[i];
}
ap_fixed<16,6> modelResult = -1;
ap_fixed<16, 6> modelResult = -1;
//for (int i = 0; i < 1; i++) {
// modelResult[i] = -1;
//}

modelRef_->prepare_input(modelInput);
modelRef_->predict();
modelRef_->predict();
modelRef_->read_result(modelResult);
return modelResult;
} //end EvaluateNN
Expand Down

0 comments on commit 3c1d656

Please sign in to comment.