CMS 3D CMS Logo

L1TkHTMissEmulatorProducer.cc
Go to the documentation of this file.
1 
7 // Original Author: Hardik Routray
8 // Created: Mon, 11 Oct 2021
9 // Update: George Karathanasis, CU Boulder
10 // 2/4/2024
11 
12 // system include files
13 #include <memory>
14 #include <numeric>
15 
16 // user include files
29 
31 
32 using namespace l1t;
33 
35 public:
37  ~L1TkHTMissEmulatorProducer() override = default;
38 
39 private:
40  virtual void beginJob();
41  void produce(edm::Event&, const edm::EventSetup&) override;
42  virtual void endJob();
43 
44  // ----------member data ---------------------------
45 
46  bool debug_ = false;
47  bool displaced_;
48 
50  int aSteps = 8;
51 
56 
57  std::vector<l1tmhtemu::phi_t> cosLUT_;
58  std::vector<l1tmhtemu::MHTphi_t> atanLUT_;
59  std::vector<l1tmhtemu::Et_t> magNormalisationLUT_;
60 
62 
64 };
65 
67  : jetToken_(consumes<TkJetWordCollection>(iConfig.getParameter<edm::InputTag>("L1TkJetEmulationInputTag"))) {
68  debug_ = iConfig.getParameter<bool>("debug");
69  displaced_ = iConfig.getParameter<bool>("displaced");
70 
71  jetMinPt_ = l1tmhtemu::digitizeSignedValue<l1tmhtemu::pt_t>(
72  (float)iConfig.getParameter<double>("jet_minPt"), l1tmhtemu::kInternalPtWidth, l1tmhtemu::kStepPt);
73  jetMaxEta_ = l1tmhtemu::digitizeSignedValue<l1tmhtemu::eta_t>(
74  (float)iConfig.getParameter<double>("jet_maxEta"), l1tmhtemu::kInternalEtaWidth, l1tmhtemu::kStepEta);
75  minNtracksHighPt_ = (l1tmhtemu::ntracks_t)iConfig.getParameter<int>("jet_minNtracksHighPt");
76  minNtracksLowPt_ = (l1tmhtemu::ntracks_t)iConfig.getParameter<int>("jet_minNtracksLowPt");
77 
80 
83 
84  // Name of output ED Product
85  L1MHTCollectionName_ = (std::string)iConfig.getParameter<std::string>("L1MHTCollectionName");
86 
87  produces<std::vector<EtSum>>(L1MHTCollectionName_);
88 
89  if (debug_) {
90  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
91  << "-------------------------------------------------------------------------\n"
92  << "====BITWIDTHS====\n"
93  << "pt: " << l1t::TkJetWord::TkJetBitWidths::kPtSize << " eta: " << l1t::TkJetWord::TkJetBitWidths::kGlbEtaSize
94  << " phi:" << l1t::TkJetWord::TkJetBitWidths::kGlbPhiSize << "\n"
95  << "====CUT AP_INTS====\n"
96  << "minpt: " << jetMinPt_ << " maxeta: " << jetMaxEta_ << " minNtracksHighPt: " << minNtracksHighPt_
97  << " minNtracksLowPt: " << minNtracksLowPt_ << "\n"
98  << "====CUT AP_INTS TO FLOATS====\n"
99  << "minpt: " << (float)jetMinPt_ * l1tmhtemu::kStepPt << " maxeta: " << (float)jetMaxEta_ * l1tmhtemu::kStepEta
100  << " minNtracksHighPt: " << (int)minNtracksHighPt_ << " minNtracksLowPt: " << (int)minNtracksLowPt_ << "\n"
101  << "-------------------------------------------------------------------------\n";
102  }
103 }
104 
106  using namespace edm;
107  std::unique_ptr<std::vector<l1t::EtSum>> MHTCollection(new std::vector<l1t::EtSum>(0));
108 
109  // L1 track-trigger jets
110  edm::Handle<TkJetWordCollection> L1TkJetsHandle;
111  iEvent.getByToken(jetToken_, L1TkJetsHandle);
112  std::vector<TkJetWord>::const_iterator jetIter;
113 
114  if (!L1TkJetsHandle.isValid() && !displaced_) {
115  LogError("TkHTMissEmulatorProducer") << "\nWarning: TkJetCollection not found in the event. Exit\n";
116  return;
117  }
118 
119  if (!L1TkJetsHandle.isValid() && displaced_) {
120  LogError("TkHTMissEmulatorProducer") << "\nWarning: TkJetExtendedCollection not found in the event. Exit\n";
121  return;
122  }
123 
124  // floats used for debugging
125  float sumPx_ = 0;
126  float sumPy_ = 0;
127  float HT_ = 0;
128 
129  l1tmhtemu::Et_t sumPx = 0;
130  l1tmhtemu::Et_t sumPy = 0;
131  l1tmhtemu::MHT_t HT = 0;
132 
133  // loop over jets
134  int jetn = 0;
135 
136  for (jetIter = L1TkJetsHandle->begin(); jetIter != L1TkJetsHandle->end(); ++jetIter) {
137  // floats used for debugging
138  float tmp_jet_px_ = jetIter->pt() * cos(jetIter->glbphi());
139  float tmp_jet_py_ = jetIter->pt() * sin(jetIter->glbphi());
140  //float tmp_jet_et_ = jetIter->pt(); // FIXME Get Et from the emulated jets
141  float tmp_jet_pt_ = jetIter->pt();
142 
143  bool tmp_jet_isDisplaced_ = jetIter->dispflag();
144 
145  l1tmhtemu::pt_t tmp_jet_pt =
146  l1tmhtemu::digitizeSignedValue<l1tmhtemu::pt_t>(jetIter->pt(), l1tmhtemu::kInternalPtWidth, l1tmhtemu::kStepPt);
147  l1tmhtemu::eta_t tmp_jet_eta = l1tmhtemu::digitizeSignedValue<l1tmhtemu::eta_t>(
149  l1tmhtemu::phi_t tmp_jet_phi = l1tmhtemu::digitizeSignedValue<l1tmhtemu::phi_t>(
151  l1tmhtemu::ntracks_t tmp_jet_nt = l1tmhtemu::ntracks_t(jetIter->nt());
152 
153  l1tmhtemu::phi_t tmp_jet_cos_phi = l1tmhtemu::phi_t(-999);
154  l1tmhtemu::phi_t tmp_jet_sin_phi = l1tmhtemu::phi_t(-999);
155 
156  if (tmp_jet_phi >= 0) {
157  tmp_jet_cos_phi = cosLUT_[tmp_jet_phi];
158 
159  if (cosLUTbins / 2 + 1 - tmp_jet_phi >= 0)
160  tmp_jet_sin_phi = cosLUT_[cosLUTbins / 2 + 1 - tmp_jet_phi];
161  else
162  tmp_jet_sin_phi = cosLUT_[-1 * (cosLUTbins / 2 + 1 - tmp_jet_phi)];
163 
164  } else {
165  tmp_jet_cos_phi = cosLUT_[-1 * tmp_jet_phi];
166 
167  if (cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi) >= 0)
168  tmp_jet_sin_phi = -1 * cosLUT_[cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi)];
169  else
170  tmp_jet_sin_phi = -1 * cosLUT_[-1 * (cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi))];
171  }
172 
173  l1tmhtemu::Et_t tmp_jet_px = tmp_jet_pt * tmp_jet_cos_phi;
174  l1tmhtemu::Et_t tmp_jet_py = tmp_jet_pt * tmp_jet_sin_phi;
175 
176  jetn++;
177 
178  if (debug_) {
179  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
180  << "****JET EMULATION" << jetn << "****\n"
181  << "FLOATS ORIGINAL\n"
182  << "PT: " << jetIter->pt() << "| ETA: " << jetIter->glbeta() << "| PHI: " << jetIter->glbphi()
183  << "| NTRACKS: " << jetIter->nt() << "| COS(PHI): " << cos(jetIter->glbphi())
184  << "| SIN(PHI): " << sin(jetIter->glbphi()) << "| Px: " << jetIter->pt() * cos(jetIter->glbphi())
185  << "| Py: " << jetIter->pt() * sin(jetIter->glbphi()) << "\n"
186  << "AP_INTS RAW\n"
187  << "PT: " << jetIter->ptWord() << "| ETA: " << jetIter->glbEtaWord() << "| PHI: " << jetIter->glbPhiWord()
188  << "| NTRACKS: " << jetIter->ntWord() << "\n"
189  << "AP_INTS NEW\n"
190  << "PT: " << tmp_jet_pt << "| ETA: " << tmp_jet_eta << "| PHI: " << tmp_jet_phi << "| NTRACKS: " << tmp_jet_nt
191  << "| COS(PHI): " << tmp_jet_cos_phi << "| SIN(PHI): " << tmp_jet_sin_phi << "| Px: " << tmp_jet_px
192  << "| Py: " << tmp_jet_py << "\n"
193  << "AP_INTS NEW TO FLOATS\n"
194  << "PT: " << (float)tmp_jet_pt * l1tmhtemu::kStepPt << "| ETA: " << (float)tmp_jet_eta * l1tmhtemu::kStepEta
195  << "| PHI: " << (float)tmp_jet_phi * l1tmhtemu::kStepPhi << "| NTRACKS: " << (int)tmp_jet_nt
196  << "| COS(PHI): " << (float)tmp_jet_cos_phi * l1tmhtemu::kStepPhi
197  << "| SIN(PHI): " << (float)tmp_jet_sin_phi * l1tmhtemu::kStepPhi
198  << "| Px: " << (float)tmp_jet_px * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi
199  << "| Py: " << (float)tmp_jet_py * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi << "\n"
200  << "-------------------------------------------------------------------------\n";
201  }
202 
203  if (tmp_jet_pt < jetMinPt_)
204  continue;
205  if (tmp_jet_eta > jetMaxEta_ or tmp_jet_eta < -1 * jetMaxEta_)
206  continue;
207  if (tmp_jet_nt < minNtracksLowPt_ && tmp_jet_pt > 200)
208  continue;
209  if (tmp_jet_nt < minNtracksHighPt_ && tmp_jet_pt > 400)
210  continue;
211  if (displaced_ && !tmp_jet_isDisplaced_)
212  continue;
213 
214  if (debug_) {
215  sumPx_ += tmp_jet_px_;
216  sumPy_ += tmp_jet_py_;
217  HT_ += tmp_jet_pt_;
218  }
219 
220  sumPx += tmp_jet_pt * tmp_jet_cos_phi;
221  sumPy += tmp_jet_pt * tmp_jet_sin_phi;
222  HT += tmp_jet_pt;
223 
224  } // end jet loop
225 
226  // define missing HT
227 
228  // Perform cordic sqrt, take x,y and converts to polar coordinate r,phi where
229  // r=sqrt(x**2+y**2) and phi = atan(y/x)
231  math::XYZTLorentzVector missingEt(-sumPx, -sumPy, 0, EtMiss.Et);
232 
234 
235  if ((sumPx < 0) && (sumPy < 0))
236  phi = EtMiss.Phi - l1tmhtemu::kMHTPhiBins / 2;
237  else if ((sumPx >= 0) && (sumPy >= 0))
238  phi = (EtMiss.Phi) + l1tmhtemu::kMHTPhiBins / 2;
239  else if ((sumPx >= 0) && (sumPy < 0))
240  phi = EtMiss.Phi - l1tmhtemu::kMHTPhiBins / 2;
241  else if ((sumPx < 0) && (sumPy >= 0))
242  phi = EtMiss.Phi - 3 * l1tmhtemu::kMHTPhiBins / 2;
243 
244  if (debug_) {
245  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
246  << "-------------------------------------------------------------------------\n"
247  << "====MHT FLOATS====\n"
248  << "sumPx: " << sumPx_ << "| sumPy: " << sumPy_ << "| ET: " << sqrt(sumPx_ * sumPx_ + sumPy_ * sumPy_)
249  << "| HT: " << HT_ << "| PHI: " << atan2(sumPy_, sumPx_) << "\n"
250  << "====MHT AP_INTS====\n"
251  << "sumPx: " << sumPx << "| sumPy: " << sumPy << "| ET: " << EtMiss.Et << "| HT: " << HT << "| PHI: " << phi
252  << "\n"
253  << "====MHT AP_INTS TO FLOATS====\n"
254  << "sumPx: " << (float)sumPx * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi
255  << "| sumPy: " << (float)sumPy * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi << "| ET: " << EtMiss.Et.to_double()
256  << "| HT: " << (float)HT * l1tmhtemu::kStepPt << "| PHI: " << (float)phi * l1tmhtemu::kStepMHTPhi - M_PI << "\n"
257  << "-------------------------------------------------------------------------\n";
258  }
259  //rescale HT to correct output range
260  HT = HT / (int)(1 / l1tmhtemu::kStepPt);
261 
262  EtSum L1HTSum(missingEt, EtSum::EtSumType::kMissingHt, (int)HT.range(), 0, (int)phi, (int)jetn);
263 
264  MHTCollection->push_back(L1HTSum);
266 
267 } //end producer
268 
270 
272 
std::vector< l1tmhtemu::MHTphi_t > atanLUT_
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< l1t::TkJetWord > TkJetWordCollection
Definition: TkJetWord.h:191
const edm::EDGetTokenT< TkJetWordCollection > jetToken_
L1TkHTMissEmulatorProducer(const edm::ParameterSet &)
ap_uint< 5 > ntracks_t
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ap_uint< kMHTPhiSize > MHTphi_t
delete x;
Definition: CaloConfig.h:22
EtMiss cordicSqrt(Et_t x, Et_t y, int cordicSteps, std::vector< l1tmhtemu::MHTphi_t > atanLUT, std::vector< Et_t > magNormalisationLUT)
std::vector< MHTphi_t > generateaTanLUT(int cordicSteps)
Log< level::Error, false > LogError
const unsigned int kInternalPhiWidth
void beginJob()
Definition: Breakpoints.cc:14
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const float kMaxCosLUTPhi
ap_uint< kInternalPtWidth > pt_t
int iEvent
Definition: GenABIO.cc:224
const double kStepMHTPhi
std::vector< l1tmhtemu::Et_t > magNormalisationLUT_
ap_ufixed< kMHTSize, kMHTIntSize > MHT_t
T sqrt(T t)
Definition: SSEVec.h:23
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< pat::MHT > MHTCollection
Definition: MHT.h:39
#define M_PI
const unsigned int kInternalPtWidth
void produce(edm::Event &, const edm::EventSetup &) override
ap_int< kInternalEtaWidth > eta_t
const unsigned int kInternalEtaWidth
bool isValid() const
Definition: HandleBase.h:70
std::vector< l1tmhtemu::phi_t > cosLUT_
HLT enums.
const unsigned int kMHTPhiBins
std::vector< phi_t > generateCosLUT(unsigned int size)
std::vector< Et_t > generatemagNormalisationLUT(int cordicSteps)
Definition: HT.h:21
ap_int< kInternalPhiWidth > phi_t
ap_int< kHTSize > Et_t
def move(src, dest)
Definition: eostools.py:511