Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion L1Trigger/Phase2L1ParticleFlow/interface/JetId.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JetId {

void setNNVectorVar();
float EvaluateNN();
ap_fixed<16, 6> EvaluateNNFixed();
ap_fixed<14, 8, AP_TRN, AP_SAT, 0> EvaluateNNFixed();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should

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

also be changed to <14, 8, AP_TRN, AP_SAT, 0> or it is ok to keep that as <16, 6>?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch. I checked things and I found no difference in going from <16, 6> to <14, 8, AP_TRN, AP_SAT, 0>. However, I updated the precision accordingly to keep things consistent.

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

Expand Down
17 changes: 9 additions & 8 deletions L1Trigger/Phase2L1ParticleFlow/plugins/TOoLLiPProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class TOoLLiPProducer : public edm::stream::EDProducer<> {
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
std::unique_ptr<JetId> fJetId_;
void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;

edm::EDGetTokenT<edm::View<l1t::PFJet>> const jets_;
Expand All @@ -43,6 +42,7 @@ class TOoLLiPProducer : public edm::stream::EDProducer<> {

hls4mlEmulator::ModelLoader loader;
std::shared_ptr<hls4mlEmulator::Model> model;
std::unique_ptr<JetId> fJetId_;
};

TOoLLiPProducer::TOoLLiPProducer(const edm::ParameterSet& cfg)
Expand All @@ -53,10 +53,10 @@ 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"))) {
model = loader.load_model();
fJetId_ = std::make_unique<JetId>(
cfg.getParameter<std::string>("NNInput"), cfg.getParameter<std::string>("NNOutput"), model, fNParticles_);
loader(cfg.getParameter<std::string>("TOoLLiPVersion")),
model(loader.load_model()),
fJetId_(std::make_unique<JetId>(
cfg.getParameter<std::string>("NNInput"), cfg.getParameter<std::string>("NNOutput"), model, fNParticles_)) {
produces<edm::ValueMap<float>>("L1PFLLPJets");
}

Expand All @@ -78,10 +78,10 @@ void TOoLLiPProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
for (const auto& srcjet : *jets) {
if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta()) > fMaxEta_ ||
LLPScores.size() >= fMaxJets_) {
LLPScores.push_back(-1.);
LLPScores.push_back(-999.);
continue;
}
ap_fixed<16, 6> LLPScore = fJetId_->computeFixed(srcjet, vz, fUseRawPt_);
ap_fixed<14, 8, AP_TRN, AP_SAT, 0> LLPScore = fJetId_->computeFixed(srcjet, vz, fUseRawPt_);
LLPScores.push_back(LLPScore);
}

Expand All @@ -97,7 +97,8 @@ void TOoLLiPProducer::fillDescriptions(edm::ConfigurationDescriptions& descripti
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("jets", edm::InputTag("scPFL1Puppi"));
desc.add<bool>("useRawPt", true);
desc.add<std::string>("TOoLLiPVersion", std::string("TOoLLiP_v1"));
desc.add<std::string>("TOoLLiPVersion", std::string("TOoLLiP_v3"));

desc.add<std::string>("NNInput", "input:0");
desc.add<std::string>("NNOutput", "sequential/dense_2/Sigmoid");
desc.add<int>("maxJets", 10);
Expand Down
11 changes: 6 additions & 5 deletions L1Trigger/Phase2L1ParticleFlow/src/JetId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void JetId::setNNVectorVar() {
NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] < 0); // Pion
NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] > 0); // Anti-Pion
NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ
NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0
NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0]));
Comment thread
Brainz22 marked this conversation as resolved.
Outdated
NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT
NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis
NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis
Expand All @@ -73,17 +73,17 @@ 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<14, 8, AP_TRN, AP_SAT, 0> JetId::EvaluateNNFixed() {
ap_fixed<12, 6, AP_TRN, AP_SAT, 0> modelInput[130] = {};
for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
modelInput[i] = NNvectorVar_[i];
}
ap_fixed<16, 6> modelResult[1] = {-1};
ap_fixed<14, 8, AP_TRN, AP_SAT, 0> modelResult[1] = {-1};

modelRef_->prepare_input(modelInput);
modelRef_->predict();
modelRef_->read_result(modelResult);
ap_fixed<16, 6> modelResult_ = modelResult[0];
ap_fixed<14, 8, AP_TRN, AP_SAT, 0> modelResult_ = modelResult[0];
return modelResult_;
} //end EvaluateNNFixed

Expand Down Expand Up @@ -152,5 +152,6 @@ ap_fixed<16, 6> JetId::computeFixed(const l1t::PFJet &iJet, float vz, bool useRa
}
}
setNNVectorVar();

return EvaluateNNFixed();
}