Skip to content

Commit 4d3b9f2

Browse files
authored
Merge pull request cms-sw#33606 from cecilecaillol/l1t-Emyr_120X
L1T phase-2: Update to histogram (Phase-1 like) jets
2 parents 97bcdcb + 607d546 commit 4d3b9f2

11 files changed

+1387
-24
lines changed

DataFormats/L1Trigger/src/classes_def.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</class>
5757
<class name="l1t::EtSumBxCollection"/>
5858
<class name="std::vector<l1t::EtSum>"/>
59+
<class name="edm::Wrapper<std::vector<l1t::EtSum>>"/>
5960
<class name="edm::Wrapper<l1t::EtSumBxCollection>"/>
6061
<class name="l1t::EtSumRef"/>
6162
<class name="edm::Wrapper<l1t::EtSumRef>"/>

L1Trigger/L1CaloTrigger/plugins/Phase1L1TJetProducer.cc

Lines changed: 286 additions & 19 deletions
Large diffs are not rendered by default.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// -*- C++ -*-
2+
//
3+
// Package: L1CaloTrigger
4+
// Class: Phase1L1TJetSumsProducer
5+
//
6+
/**\class Phase1L1TJetSumsProducer Phase1L1TJetSumsProducer.cc L1Trigger/L1CaloTrigger/plugin/Phase1L1TJetSumsProducer.cc
7+
8+
Description: Computes HT and MHT from phase-1-like jets
9+
10+
*** INPUT PARAMETERS ***
11+
* sin/cosPhi: Value of sin/cos phi in the middle of each bin of the grid.
12+
* etaBinning: vdouble with eta binning (allows non-homogeneous binning in eta)
13+
* nBinsPhi: uint32, number of bins in phi
14+
* phiLow: double, min phi (typically -pi)
15+
* phiUp: double, max phi (typically +pi)
16+
* {m}htPtThreshold: Minimum jet pt for HT/MHT calculation
17+
* {m}htAbsEtaCut:
18+
* pt/eta/philsb : lsb of quantities used in firmware implementation
19+
* outputCollectionName: string, tag for the output collection
20+
* inputCollectionTag: tag for input jet collection
21+
22+
*/
23+
//
24+
// Original Simone Bologna
25+
//
26+
27+
#include "FWCore/Framework/interface/Frameworkfwd.h"
28+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
29+
#include "FWCore/Framework/interface/one/EDProducer.h"
30+
#include "FWCore/Framework/interface/ESHandle.h"
31+
#include "DataFormats/JetReco/interface/CaloJet.h"
32+
#include "DataFormats/L1Trigger/interface/EtSum.h"
33+
#include "DataFormats/Common/interface/View.h"
34+
#include "DataFormats/Candidate/interface/Candidate.h"
35+
#include "FWCore/Framework/interface/MakerMacros.h"
36+
#include "FWCore/Framework/interface/Event.h"
37+
#include "DataFormats/Math/interface/LorentzVector.h"
38+
#include "FWCore/ServiceRegistry/interface/Service.h"
39+
#include "CommonTools/UtilAlgos/interface/TFileService.h"
40+
41+
#include <cmath>
42+
43+
class Phase1L1TJetSumsProducer : public edm::one::EDProducer<edm::one::SharedResources> {
44+
public:
45+
explicit Phase1L1TJetSumsProducer(const edm::ParameterSet&);
46+
~Phase1L1TJetSumsProducer() override;
47+
48+
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49+
50+
private:
51+
void produce(edm::Event&, const edm::EventSetup&) override;
52+
53+
// computes ht, adds jet pt to ht only if the pt of the jet is above the ht calculation threshold
54+
l1t::EtSum computeHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const;
55+
56+
// computes MHT
57+
// adds jet pt to mht only if the pt of the jet is above the mht calculation threshold
58+
// performs some calculations with digitised/integer quantities to ensure agreement with firmware
59+
l1t::EtSum computeMHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const;
60+
61+
edm::EDGetTokenT<std::vector<reco::CaloJet> > inputJetCollectionTag_;
62+
63+
// holds the sin and cos for HLs LUT emulation
64+
std::vector<double> sinPhi_;
65+
std::vector<double> cosPhi_;
66+
unsigned int nBinsPhi_;
67+
68+
// lower phi value
69+
double phiLow_;
70+
// higher phi value
71+
double phiUp_;
72+
// size of a phi bin
73+
double phiStep_;
74+
// threshold for ht calculation
75+
double htPtThreshold_;
76+
// threshold for ht calculation
77+
double mhtPtThreshold_;
78+
// jet eta cut for ht calculation
79+
double htAbsEtaCut_;
80+
// jet eta cut for mht calculation
81+
double mhtAbsEtaCut_;
82+
// LSB of pt quantity
83+
double ptlsb_;
84+
// label of sums
85+
std::string outputCollectionName_;
86+
};
87+
88+
// initialises plugin configuration and prepares ROOT file for saving the sums
89+
Phase1L1TJetSumsProducer::Phase1L1TJetSumsProducer(const edm::ParameterSet& iConfig)
90+
: inputJetCollectionTag_{consumes<std::vector<reco::CaloJet> >(
91+
iConfig.getParameter<edm::InputTag>("inputJetCollectionTag"))},
92+
sinPhi_(iConfig.getParameter<std::vector<double> >("sinPhi")),
93+
cosPhi_(iConfig.getParameter<std::vector<double> >("cosPhi")),
94+
nBinsPhi_(iConfig.getParameter<unsigned int>("nBinsPhi")),
95+
phiLow_(iConfig.getParameter<double>("phiLow")),
96+
phiUp_(iConfig.getParameter<double>("phiUp")),
97+
htPtThreshold_(iConfig.getParameter<double>("htPtThreshold")),
98+
mhtPtThreshold_(iConfig.getParameter<double>("mhtPtThreshold")),
99+
htAbsEtaCut_(iConfig.getParameter<double>("htAbsEtaCut")),
100+
mhtAbsEtaCut_(iConfig.getParameter<double>("mhtAbsEtaCut")),
101+
ptlsb_(iConfig.getParameter<double>("ptlsb")),
102+
outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName")) {
103+
phiStep_ = (phiUp_ - phiLow_) / nBinsPhi_;
104+
produces<std::vector<l1t::EtSum> >(outputCollectionName_).setBranchAlias(outputCollectionName_);
105+
}
106+
107+
Phase1L1TJetSumsProducer::~Phase1L1TJetSumsProducer() {}
108+
109+
void Phase1L1TJetSumsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
110+
edm::Handle<std::vector<reco::CaloJet> > jetCollectionHandle;
111+
iEvent.getByToken(inputJetCollectionTag_, jetCollectionHandle);
112+
113+
// computing sums and storing them in sum object
114+
l1t::EtSum lHT = computeHT(jetCollectionHandle);
115+
l1t::EtSum lMHT = computeMHT(jetCollectionHandle);
116+
117+
//packing sums in vector for event saving
118+
std::unique_ptr<std::vector<l1t::EtSum> > lSumVectorPtr(new std::vector<l1t::EtSum>(0));
119+
lSumVectorPtr->push_back(lHT);
120+
lSumVectorPtr->push_back(lMHT);
121+
iEvent.put(std::move(lSumVectorPtr), outputCollectionName_);
122+
123+
return;
124+
}
125+
126+
l1t::EtSum Phase1L1TJetSumsProducer::computeHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const {
127+
double lHT = 0;
128+
for (const auto& jet : *inputJets) {
129+
double lJetPt = jet.pt();
130+
double lJetPhi = jet.phi();
131+
double lJetEta = jet.eta();
132+
if ((lJetPhi < phiLow_) || (lJetPhi >= phiUp_))
133+
continue;
134+
135+
lHT += (lJetPt >= htPtThreshold_ && std::fabs(lJetEta) < htAbsEtaCut_) ? lJetPt : 0;
136+
}
137+
138+
reco::Candidate::PolarLorentzVector lHTVector;
139+
lHTVector.SetPt(lHT);
140+
lHTVector.SetEta(0);
141+
lHTVector.SetPhi(0);
142+
l1t::EtSum lHTSum(lHTVector, l1t::EtSum::EtSumType::kTotalHt, 0, 0, 0, 0);
143+
return lHTSum;
144+
}
145+
146+
l1t::EtSum Phase1L1TJetSumsProducer::computeMHT(const edm::Handle<std::vector<reco::CaloJet> > inputJets) const {
147+
int lTotalJetPx = 0;
148+
int lTotalJetPy = 0;
149+
150+
std::vector<unsigned int> jetPtInPhiBins(nBinsPhi_, 0);
151+
152+
for (const auto& jet : *inputJets) {
153+
double lJetPhi = jet.phi();
154+
155+
if ((lJetPhi < phiLow_) || (lJetPhi >= phiUp_))
156+
continue;
157+
158+
unsigned int iPhi = (lJetPhi - phiLow_) / phiStep_;
159+
160+
if (jet.pt() >= mhtPtThreshold_ && std::fabs(jet.eta()) < mhtAbsEtaCut_) {
161+
unsigned int digiJetPt = floor(jet.pt() / ptlsb_);
162+
jetPtInPhiBins[iPhi] += digiJetPt;
163+
}
164+
}
165+
166+
for (unsigned int iPhi = 0; iPhi < jetPtInPhiBins.size(); ++iPhi) {
167+
unsigned int digiJetPtSum = jetPtInPhiBins[iPhi];
168+
169+
// retrieving sin cos from LUT emulator
170+
double lSinPhi = sinPhi_[iPhi];
171+
double lCosPhi = cosPhi_[iPhi];
172+
173+
// checking if above threshold
174+
lTotalJetPx += trunc(digiJetPtSum * lCosPhi);
175+
lTotalJetPy += trunc(digiJetPtSum * lSinPhi);
176+
}
177+
178+
double lMHT = floor(sqrt(lTotalJetPx * lTotalJetPx + lTotalJetPy * lTotalJetPy)) * ptlsb_;
179+
math::PtEtaPhiMLorentzVector lMHTVector(lMHT, 0, acos(lTotalJetPx / (lMHT / ptlsb_)), 0);
180+
l1t::EtSum lMHTSum(lMHTVector, l1t::EtSum::EtSumType::kMissingHt, 0, 0, 0, 0);
181+
182+
return lMHTSum;
183+
}
184+
185+
void Phase1L1TJetSumsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
186+
edm::ParameterSetDescription desc;
187+
desc.add<edm::InputTag>("inputJetCollectionTag",
188+
edm::InputTag("Phase1L1TJetCalibrator", "Phase1L1TJetFromPfCandidates"));
189+
desc.add<std::vector<double> >("sinPhi");
190+
desc.add<std::vector<double> >("cosPhi");
191+
desc.add<unsigned int>("nBinsPhi", 72);
192+
desc.add<double>("phiLow", -M_PI);
193+
desc.add<double>("phiUp", M_PI);
194+
desc.add<double>("htPtThreshold", 30);
195+
desc.add<double>("mhtPtThreshold", 30);
196+
desc.add<double>("htAbsEtaCut", 3);
197+
desc.add<double>("mhtAbsEtaCut", 3);
198+
desc.add<double>("ptlsb", 0.25), desc.add<string>("outputCollectionName", "Sums");
199+
descriptions.add("Phase1L1TJetSumsProducer", desc);
200+
}
201+
202+
// creates the plugin for later use in python
203+
DEFINE_FWK_MODULE(Phase1L1TJetSumsProducer);

0 commit comments

Comments
 (0)