forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
Synchronize L1 MET code with CMSSW main branch, fix phi calculation for HLS testbench, and temporarily add JSON files #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JunwonTomOh
wants to merge
27
commits into
p2l1pfp:L1PF_15_1_X
Choose a base branch
from
JunwonTomOh:L1PF_15_1_X
base: L1PF_15_1_X
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
db7e90b
Update L1T MET and Add JUMP algorithm
070951d
Apply code checks and format
JunwonTomOh 104769c
Fix the code to read the factors from cms-data
JunwonTomOh 9a8ce18
Modified the JUMP emulator
JunwonTomOh 88d6bf5
Apply code format
JunwonTomOh af82bf2
Change emulators to define the json file directory
JunwonTomOh 935b8cd
Merge pull request #1 from JunwonTomOh/l1met_jump
JunwonTomOh b64fd73
Modified Scaler on L1 MET Phi calculation
JunwonTomOh e2f6964
Add json files for met temporary
JunwonTomOh 08fb352
Modified met json file path for hls emulator
JunwonTomOh cdd06bb
Delete L1 MET json files
JunwonTomOh 970fea8
Add L1 MET json files
JunwonTomOh b471b87
Apply code-checks and code-format
JunwonTomOh e199113
Delete L1 MET JSON files
JunwonTomOh 4fc43a7
Add L1 MET JSON files
JunwonTomOh 9376488
Update L1Trigger/Phase2L1ParticleFlow/plugins/L1JUMPProducer.cc
JunwonTomOh eae69d1
Update L1Trigger/Phase2L1ParticleFlow/data/met/l1met_ptphi2pxpy_poly2…
JunwonTomOh 345e2ae
Update L1Trigger/Phase2L1ParticleFlow/python/l1tJUMPProducer_cfi.py
JunwonTomOh 8100227
Update L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFMetEmulator.h
JunwonTomOh 53d4297
Update L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFJUMPEmulat…
JunwonTomOh 977384f
Update L1Trigger/Phase2L1ParticleFlow/plugins/L1JUMPProducer.cc
JunwonTomOh c48d5dd
Update L1Trigger/Phase2L1ParticleFlow/plugins/L1JUMPProducer.cc
JunwonTomOh 304856b
Update L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFJUMPEmulat…
JunwonTomOh f96846d
Update L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFMetEmulator.h
JunwonTomOh 818f479
Update L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFJUMPEmulat…
JunwonTomOh 6e7350a
Update L1Trigger/Phase2L1ParticleFlow/plugins/L1JUMPProducer.cc
JunwonTomOh ae37b5d
Update L1Trigger/Phase2L1ParticleFlow/plugins/L1JUMPProducer.cc
JunwonTomOh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
L1Trigger/Phase2L1ParticleFlow/data/met/l1jump_jer_v1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "version": 1, | ||
| "description": "JUMP L1 jet resolution: σ(pT)[GeV] = a(ηbin)·pT + b(ηbin); |η| bins at [1.3, 1.7, 2.5, 3.0]; used to build dPx,dPy for MET update.", | ||
| "eta_bins": 4, | ||
| "eta_edges": [ | ||
| 1.3, | ||
| 1.7, | ||
| 2.5, | ||
| 3.0 | ||
| ], | ||
| "eta": { | ||
| "par0": [ | ||
| 0, | ||
| 0.073, | ||
| 0.247, | ||
| 0.128, | ||
| 0.091 | ||
| ], | ||
| "par1": [ | ||
| 0, | ||
| 12.322, | ||
| 6.061, | ||
| 10.944, | ||
| 12.660 | ||
| ] | ||
| } | ||
| } |
136 changes: 136 additions & 0 deletions
136
L1Trigger/Phase2L1ParticleFlow/data/met/l1met_ptphi2pxpy_poly2_v1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| { | ||
| "version": 1, | ||
| "description": "L1METEmu 2nd-order polynomial coefficients for cos/sin; 16 phi bins over [-pi, pi]; phi_edges in radians.", | ||
| "phi_bins": 16, | ||
| "phi_edges": [ | ||
| -1.0, | ||
| -0.875, | ||
| -0.75, | ||
| -0.625, | ||
| -0.5, | ||
| -0.375, | ||
| -0.25, | ||
| -0.125, | ||
| 0.0, | ||
| 0.125, | ||
| 0.25, | ||
| 0.375, | ||
| 0.5, | ||
| 0.625, | ||
| 0.75, | ||
| 0.875, | ||
| 1.0 | ||
| ], | ||
| "cos": { | ||
| "par0": [ | ||
| -1.00007, | ||
| -0.924181, | ||
| -0.707596, | ||
| -0.382902, | ||
| -0.000618262, | ||
| 0.382137, | ||
| 0.707056, | ||
| 0.923708, | ||
| 1.00007, | ||
| 0.924181, | ||
| 0.707594, | ||
| 0.383285, | ||
| 0.000188727, | ||
| -0.382139, | ||
| -0.706719, | ||
| -0.923708 | ||
| ], | ||
| "par1": [ | ||
| 9.164680268990924e-06, | ||
| 0.0017064607695524156, | ||
| 0.0031441321076514446, | ||
| 0.004079929656016374, | ||
| 0.004437063290882583, | ||
| 0.004095969231842202, | ||
| 0.0031107221424451436, | ||
| 0.001689531075808071, | ||
| -9.161756842493832e-06, | ||
| -0.001706456406229286, | ||
| -0.003143961938049376, | ||
| -0.004103015998697129, | ||
| -0.004411145151490469, | ||
| -0.0040958165155326525, | ||
| -0.0031310072316764474, | ||
| -0.001689531075808071 | ||
| ], | ||
| "par2": [ | ||
| 9.319674765430664e-06, | ||
| 7.871694899063284e-06, | ||
| 5.222989318251642e-06, | ||
| 2.0256106486379287e-06, | ||
| -1.9299417402361656e-06, | ||
| -5.35167113952279e-06, | ||
| -7.740062096537953e-06, | ||
| -9.348822844786505e-06, | ||
| -9.319674765430664e-06, | ||
| -7.871694899063284e-06, | ||
| -5.225331064666252e-06, | ||
| -1.780776301343235e-06, | ||
| 1.6556927733433181e-06, | ||
| 5.3495197789955455e-06, | ||
| 7.954684107366423e-06, | ||
| 9.348822844786505e-06 | ||
| ] | ||
| }, | ||
| "sin": { | ||
| "par0": [ | ||
| 0.000524872, | ||
| -0.382229, | ||
| -0.706791, | ||
| -0.923959, | ||
| -1.00008, | ||
| -0.924156, | ||
| -0.707264, | ||
| -0.383199, | ||
| -0.000525527, | ||
| 0.382228, | ||
| 0.706792, | ||
| 0.923752, | ||
| 1.00013, | ||
| 0.924155, | ||
| 0.707535, | ||
| 0.3832 | ||
| ], | ||
| "par1": [ | ||
| -0.004431478237276202, | ||
| -0.00409041472149773, | ||
| -0.0031267268116859314, | ||
| -0.00167440343451641, | ||
| 9.741773386162849e-06, | ||
| 0.0017049641497188307, | ||
| 0.00312406082125351, | ||
| 0.0040978672774037465, | ||
| 0.004431478237276202, | ||
| 0.00409041472149773, | ||
| 0.0031266351819002015, | ||
| 0.0016868781753450394, | ||
| -1.249302315254411e-05, | ||
| -0.001704846339994321, | ||
| -0.003140405829698437, | ||
| -0.0040978672774037465 | ||
| ], | ||
| "par2": [ | ||
| 1.870674613498914e-06, | ||
| 5.292404012785538e-06, | ||
| 7.909829192302831e-06, | ||
| 9.188746390688592e-06, | ||
| 9.313525301268721e-06, | ||
| 7.887020962996302e-06, | ||
| 5.435897856093815e-06, | ||
| 1.8358587462761668e-06, | ||
| -1.870668901922293e-06, | ||
| -5.292404012785538e-06, | ||
| -7.908420336736317e-06, | ||
| -9.320836119343602e-06, | ||
| -9.284396260501616e-06, | ||
| -7.88869635880513e-06, | ||
| -5.262894200243701e-06, | ||
| -1.835864457852788e-06 | ||
| ] | ||
| } | ||
| } | ||
154 changes: 154 additions & 0 deletions
154
L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFJUMPEmulator.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| #ifndef L1Trigger_Phase2L1ParticleFlow_JUMPEmulator_h | ||
| #define L1Trigger_Phase2L1ParticleFlow_JUMPEmulator_h | ||
|
|
||
| #include "DataFormats/L1TParticleFlow/interface/jets.h" | ||
| #include "DataFormats/L1TParticleFlow/interface/sums.h" | ||
| #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h" | ||
|
|
||
| #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h" | ||
| #include "L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFMetEmulator.h" | ||
|
|
||
| #include "FWCore/Utilities/interface/FileInPath.h" | ||
| #include "FWCore/Utilities/interface/Exception.h" | ||
| #include "nlohmann/json.hpp" | ||
|
|
||
| #include <vector> | ||
| #include <numeric> | ||
| #include <array> | ||
| #include <fstream> | ||
| #include <algorithm> | ||
| #include <cmath> | ||
| #include "ap_int.h" | ||
| #include "ap_fixed.h" | ||
|
|
||
| namespace L1JUMPEmu { | ||
| /* | ||
| Emulator for the JUMP Algorithm | ||
| DPS Note publicly available on CDS: CMS DP-2025/023 | ||
| JUMP: Jet Uncertainty-aware MET Prediction | ||
| - Approximate L1 Jet energy resolution by pT, eta value | ||
| - Apply the estimated resolution to MET | ||
| */ | ||
| struct JER_param { | ||
| std::vector<ap_fixed<11, 1>> par0; // eta.par0 (slope) | ||
| std::vector<ap_fixed<8, 5>> par1; // eta.par1 (offset) | ||
| std::vector<L1METEmu::eta_t> edges; // |eta| boundaries in HW scale | ||
| unsigned int eta_bins = 0; | ||
| }; | ||
|
|
||
| struct JER_Path { | ||
| std::string path = "L1Trigger/Phase2L1ParticleFlow/data/met/l1jump_jer_v1.json"; | ||
| }; | ||
|
|
||
| inline JER_Path& jer_path_config() { | ||
| static JER_Path jump_p; | ||
| return jump_p; | ||
| } | ||
|
|
||
| inline void SetJERFile(std::string jump_p) { jer_path_config().path = std::move(jump_p); } | ||
|
|
||
| inline const JER_param& Get_jer_param() { | ||
| static JER_param P = []() { | ||
| JER_param t{}; | ||
| std::string path = jer_path_config().path; | ||
|
|
||
| #ifdef CMSSW_GIT_HASH | ||
| edm::FileInPath f(path); | ||
| std::ifstream in(f.fullPath()); | ||
| if (!in) { | ||
| throw cms::Exception("FileNotFound") << f.fullPath(); | ||
| } | ||
| #else | ||
| path = "l1jump_jer_v1.json"; // For HLS Emulator | ||
| std::ifstream in(path); | ||
| if (!in) { | ||
| throw std::runtime_error(std::string("File not found: ") + path); | ||
| } | ||
| #endif | ||
|
|
||
| nlohmann::json j; | ||
| in >> j; | ||
|
|
||
| unsigned int N = j["eta_bins"].get<unsigned int>(); | ||
| t.eta_bins = N; | ||
|
|
||
| t.par0.resize(N + 1); | ||
| t.par1.resize(N + 1); | ||
| t.edges.resize(N); | ||
|
|
||
| for (unsigned int i = 0; i < N + 1; ++i) { | ||
| t.par0[i] = ap_fixed<11, 1>(j["eta"]["par0"][i].get<double>()); | ||
| t.par1[i] = ap_fixed<8, 5>(j["eta"]["par1"][i].get<double>()); | ||
| } | ||
| for (unsigned int i = 0; i < N; ++i) { | ||
| t.edges[i] = l1ct::Scales::makeGlbEta(j["eta_edges"][i].get<double>()); | ||
| } | ||
| return t; | ||
| }(); | ||
| return P; | ||
| } | ||
|
|
||
| inline void Get_dPt(const l1ct::Jet jet, L1METEmu::proj2_t& dPx_2, L1METEmu::proj2_t& dPy_2) { | ||
JunwonTomOh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /* | ||
| L1 Jet Energy Resolution parameterization | ||
| - Fitted σ(pT)/pT as a function of jet pT in each η region (detector boundary at η≈1.3, 1.7, 2.5, 3.0) | ||
| - Derived from simulated QCD multijet samples to calculate detector‐dependent resolution | ||
| - σ(pT) ≈ eta_par0[i] * pT + eta_par1[i] | ||
| */ | ||
|
|
||
| const auto& J = Get_jer_param(); | ||
|
|
||
| L1METEmu::eta_t abseta = abs(jet.hwEta.to_float()); | ||
| unsigned int etabin = 0; | ||
| for (unsigned int i = 0; i < J.eta_bins; i++) { | ||
| if (abseta < J.edges[i]) { | ||
| etabin = i + 1; | ||
| break; | ||
| } | ||
| } | ||
JunwonTomOh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| dPx_2 = 0; | ||
| dPy_2 = 0; | ||
| l1ct::Sum jet_resolution; | ||
| jet_resolution.hwPt = J.par0[etabin] * jet.hwPt + J.par1[etabin]; | ||
| jet_resolution.hwPhi = jet.hwPhi; | ||
| L1METEmu::Particle_xy dpt_xy = L1METEmu::Get_xy(jet_resolution.hwPt, jet_resolution.hwPhi); | ||
|
|
||
| dPx_2 = dpt_xy.hwPx * dpt_xy.hwPx; | ||
| dPy_2 = dpt_xy.hwPy * dpt_xy.hwPy; | ||
| } | ||
|
|
||
| inline void Met_dPt(const std::vector<l1ct::Jet>& jets, L1METEmu::proj2_t& dPx_2, L1METEmu::proj2_t& dPy_2) { | ||
| L1METEmu::proj2_t each_dPx2 = 0; | ||
| L1METEmu::proj2_t each_dPy2 = 0; | ||
|
|
||
| L1METEmu::proj2_t sum_dPx2 = 0; | ||
| L1METEmu::proj2_t sum_dPy2 = 0; | ||
|
|
||
| for (unsigned int i = 0; i < jets.size(); i++) { | ||
| Get_dPt(jets[i], each_dPx2, each_dPy2); | ||
| sum_dPx2 += each_dPx2; | ||
| sum_dPy2 += each_dPy2; | ||
| } | ||
|
|
||
| dPx_2 = sum_dPx2; | ||
| dPy_2 = sum_dPy2; | ||
| } | ||
| } // namespace L1JUMPEmu | ||
|
|
||
| inline void JUMP_emu(const l1ct::Sum& inMet, const std::vector<l1ct::Jet>& jets, l1ct::Sum& outMet) { | ||
| L1METEmu::Particle_xy inMet_xy = L1METEmu::Get_xy(inMet.hwPt, inMet.hwPhi); | ||
|
|
||
| L1METEmu::proj2_t dPx_2; | ||
| L1METEmu::proj2_t dPy_2; | ||
| L1JUMPEmu::Met_dPt(jets, dPx_2, dPy_2); | ||
|
|
||
| L1METEmu::Particle_xy outMet_xy; | ||
| outMet_xy.hwPx = (inMet_xy.hwPx > 0) ? inMet_xy.hwPx + L1METEmu::proj2_t(sqrt(dPx_2.to_float())) | ||
| : inMet_xy.hwPx - L1METEmu::proj2_t(sqrt(dPx_2.to_float())); | ||
| outMet_xy.hwPy = (inMet_xy.hwPy > 0) ? inMet_xy.hwPy + L1METEmu::proj2_t(sqrt(dPy_2.to_float())) | ||
| : inMet_xy.hwPy - L1METEmu::proj2_t(sqrt(dPy_2.to_float())); | ||
JunwonTomOh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| L1METEmu::pxpy_to_ptphi(outMet_xy, outMet); | ||
| } | ||
|
|
||
| #endif | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.