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 
10 // system include files
11 #include <memory>
12 #include <numeric>
13 
14 // user include files
27 
29 
30 using namespace l1t;
31 
33 public:
35  ~L1TkHTMissEmulatorProducer() override = default;
36 
37 private:
38  virtual void beginJob();
39  void produce(edm::Event&, const edm::EventSetup&) override;
40  virtual void endJob();
41 
42  // ----------member data ---------------------------
43 
44  bool debug_ = false;
45  bool displaced_;
46 
48  int aSteps = 8;
49 
54 
55  std::vector<l1tmhtemu::phi_t> cosLUT_;
56  std::vector<l1tmhtemu::MHTphi_t> atanLUT_;
57  std::vector<l1tmhtemu::Et_t> magNormalisationLUT_;
58 
60 
62 };
63 
65  : jetToken_(consumes<TkJetWordCollection>(iConfig.getParameter<edm::InputTag>("L1TkJetEmulationInputTag"))) {
66  debug_ = iConfig.getParameter<bool>("debug");
67  displaced_ = iConfig.getParameter<bool>("displaced");
68 
69  jetMinPt_ = l1tmhtemu::digitizeSignedValue<l1tmhtemu::pt_t>(
70  (float)iConfig.getParameter<double>("jet_minPt"), l1tmhtemu::kInternalPtWidth, l1tmhtemu::kStepPt);
71  jetMaxEta_ = l1tmhtemu::digitizeSignedValue<l1tmhtemu::eta_t>(
72  (float)iConfig.getParameter<double>("jet_maxEta"), l1tmhtemu::kInternalEtaWidth, l1tmhtemu::kStepEta);
73  minNtracksHighPt_ = (l1tmhtemu::ntracks_t)iConfig.getParameter<int>("jet_minNtracksHighPt");
74  minNtracksLowPt_ = (l1tmhtemu::ntracks_t)iConfig.getParameter<int>("jet_minNtracksLowPt");
75 
78 
81 
82  // Name of output ED Product
83  L1MHTCollectionName_ = (std::string)iConfig.getParameter<std::string>("L1MHTCollectionName");
84 
85  produces<std::vector<EtSum>>(L1MHTCollectionName_);
86 
87  if (debug_) {
88  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
89  << "-------------------------------------------------------------------------\n"
90  << "====BITWIDTHS====\n"
91  << "pt: " << l1t::TkJetWord::TkJetBitWidths::kPtSize << " eta: " << l1t::TkJetWord::TkJetBitWidths::kGlbEtaSize
92  << " phi:" << l1t::TkJetWord::TkJetBitWidths::kGlbPhiSize << "\n"
93  << "====CUT AP_INTS====\n"
94  << "minpt: " << jetMinPt_ << " maxeta: " << jetMaxEta_ << " minNtracksHighPt: " << minNtracksHighPt_
95  << " minNtracksLowPt: " << minNtracksLowPt_ << "\n"
96  << "====CUT AP_INTS TO FLOATS====\n"
97  << "minpt: " << (float)jetMinPt_ * l1tmhtemu::kStepPt << " maxeta: " << (float)jetMaxEta_ * l1tmhtemu::kStepEta
98  << " minNtracksHighPt: " << (int)minNtracksHighPt_ << " minNtracksLowPt: " << (int)minNtracksLowPt_ << "\n"
99  << "-------------------------------------------------------------------------\n";
100  }
101 }
102 
104  using namespace edm;
105  std::unique_ptr<std::vector<l1t::EtSum>> MHTCollection(new std::vector<l1t::EtSum>(0));
106 
107  // L1 track-trigger jets
108  edm::Handle<TkJetWordCollection> L1TkJetsHandle;
109  iEvent.getByToken(jetToken_, L1TkJetsHandle);
110  std::vector<TkJetWord>::const_iterator jetIter;
111 
112  if (!L1TkJetsHandle.isValid() && !displaced_) {
113  LogError("TkHTMissEmulatorProducer") << "\nWarning: TkJetCollection not found in the event. Exit\n";
114  return;
115  }
116 
117  if (!L1TkJetsHandle.isValid() && displaced_) {
118  LogError("TkHTMissEmulatorProducer") << "\nWarning: TkJetExtendedCollection not found in the event. Exit\n";
119  return;
120  }
121 
122  // floats used for debugging
123  float sumPx_ = 0;
124  float sumPy_ = 0;
125  float HT_ = 0;
126 
127  l1tmhtemu::Et_t sumPx = 0;
128  l1tmhtemu::Et_t sumPy = 0;
129  l1tmhtemu::MHT_t HT = 0;
130 
131  // loop over jets
132  int jetn = 0;
133  int jetnpasscuts = 0;
134 
135  for (jetIter = L1TkJetsHandle->begin(); jetIter != L1TkJetsHandle->end(); ++jetIter) {
136  // floats used for debugging
137  float tmp_jet_px_ = jetIter->pt() * cos(jetIter->glbphi());
138  float tmp_jet_py_ = jetIter->pt() * sin(jetIter->glbphi());
139  //float tmp_jet_et_ = jetIter->pt(); // FIXME Get Et from the emulated jets
140  float tmp_jet_pt_ = jetIter->pt();
141 
142  l1tmhtemu::pt_t tmp_jet_pt =
143  l1tmhtemu::digitizeSignedValue<l1tmhtemu::pt_t>(jetIter->pt(), l1tmhtemu::kInternalPtWidth, l1tmhtemu::kStepPt);
144  l1tmhtemu::eta_t tmp_jet_eta = l1tmhtemu::digitizeSignedValue<l1tmhtemu::eta_t>(
146  l1tmhtemu::phi_t tmp_jet_phi = l1tmhtemu::digitizeSignedValue<l1tmhtemu::phi_t>(
148  l1tmhtemu::ntracks_t tmp_jet_nt = l1tmhtemu::ntracks_t(jetIter->nt());
149 
150  l1tmhtemu::phi_t tmp_jet_cos_phi = l1tmhtemu::phi_t(-999);
151  l1tmhtemu::phi_t tmp_jet_sin_phi = l1tmhtemu::phi_t(-999);
152 
153  if (tmp_jet_phi >= 0) {
154  tmp_jet_cos_phi = cosLUT_[tmp_jet_phi];
155 
156  if (cosLUTbins / 2 + 1 - tmp_jet_phi >= 0)
157  tmp_jet_sin_phi = cosLUT_[cosLUTbins / 2 + 1 - tmp_jet_phi];
158  else
159  tmp_jet_sin_phi = cosLUT_[-1 * (cosLUTbins / 2 + 1 - tmp_jet_phi)];
160 
161  } else {
162  tmp_jet_cos_phi = cosLUT_[-1 * tmp_jet_phi];
163 
164  if (cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi) >= 0)
165  tmp_jet_sin_phi = -1 * cosLUT_[cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi)];
166  else
167  tmp_jet_sin_phi = -1 * cosLUT_[-1 * (cosLUTbins / 2 + 1 - (-1 * tmp_jet_phi))];
168  }
169 
170  l1tmhtemu::Et_t tmp_jet_px = tmp_jet_pt * tmp_jet_cos_phi;
171  l1tmhtemu::Et_t tmp_jet_py = tmp_jet_pt * tmp_jet_sin_phi;
172 
173  jetn++;
174 
175  if (debug_) {
176  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
177  << "****JET EMULATION" << jetn << "****\n"
178  << "FLOATS ORIGINAL\n"
179  << "PT: " << jetIter->pt() << "| ETA: " << jetIter->glbeta() << "| PHI: " << jetIter->glbphi()
180  << "| NTRACKS: " << jetIter->nt() << "| COS(PHI): " << cos(jetIter->glbphi())
181  << "| SIN(PHI): " << sin(jetIter->glbphi()) << "| Px: " << jetIter->pt() * cos(jetIter->glbphi())
182  << "| Py: " << jetIter->pt() * sin(jetIter->glbphi()) << "\n"
183  << "AP_INTS RAW\n"
184  << "PT: " << jetIter->ptWord() << "| ETA: " << jetIter->glbEtaWord() << "| PHI: " << jetIter->glbPhiWord()
185  << "| NTRACKS: " << jetIter->ntWord() << "\n"
186  << "AP_INTS NEW\n"
187  << "PT: " << tmp_jet_pt << "| ETA: " << tmp_jet_eta << "| PHI: " << tmp_jet_phi << "| NTRACKS: " << tmp_jet_nt
188  << "| COS(PHI): " << tmp_jet_cos_phi << "| SIN(PHI): " << tmp_jet_sin_phi << "| Px: " << tmp_jet_px
189  << "| Py: " << tmp_jet_py << "\n"
190  << "AP_INTS NEW TO FLOATS\n"
191  << "PT: " << (float)tmp_jet_pt * l1tmhtemu::kStepPt << "| ETA: " << (float)tmp_jet_eta * l1tmhtemu::kStepEta
192  << "| PHI: " << (float)tmp_jet_phi * l1tmhtemu::kStepPhi << "| NTRACKS: " << (int)tmp_jet_nt
193  << "| COS(PHI): " << (float)tmp_jet_cos_phi * l1tmhtemu::kStepPhi
194  << "| SIN(PHI): " << (float)tmp_jet_sin_phi * l1tmhtemu::kStepPhi
195  << "| Px: " << (float)tmp_jet_px * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi
196  << "| Py: " << (float)tmp_jet_py * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi << "\n"
197  << "-------------------------------------------------------------------------\n";
198  }
199 
200  if (tmp_jet_pt < jetMinPt_)
201  continue;
202  if (tmp_jet_eta > jetMaxEta_ or tmp_jet_eta < -1 * jetMaxEta_)
203  continue;
204  if (tmp_jet_nt < minNtracksLowPt_ && tmp_jet_pt > 200)
205  continue;
206  if (tmp_jet_nt < minNtracksHighPt_ && tmp_jet_pt > 400)
207  continue;
208 
209  jetnpasscuts++;
210 
211  if (debug_) {
212  sumPx_ += tmp_jet_px_;
213  sumPy_ += tmp_jet_py_;
214  HT_ += tmp_jet_pt_;
215  }
216 
217  sumPx += tmp_jet_pt * tmp_jet_cos_phi;
218  sumPy += tmp_jet_pt * tmp_jet_sin_phi;
219  HT += tmp_jet_pt;
220 
221  } // end jet loop
222 
223  // define missing HT
224 
225  // Perform cordic sqrt, take x,y and converts to polar coordinate r,phi where
226  // r=sqrt(x**2+y**2) and phi = atan(y/x)
228  math::XYZTLorentzVector missingEt(-sumPx, -sumPy, 0, EtMiss.Et);
229 
231 
232  if ((sumPx < 0) && (sumPy < 0))
233  phi = EtMiss.Phi - l1tmhtemu::kMHTPhiBins / 2;
234  else if ((sumPx >= 0) && (sumPy >= 0))
235  phi = (EtMiss.Phi) + l1tmhtemu::kMHTPhiBins / 2;
236  else if ((sumPx >= 0) && (sumPy < 0))
237  phi = EtMiss.Phi - l1tmhtemu::kMHTPhiBins / 2;
238  else if ((sumPx < 0) && (sumPy >= 0))
239  phi = EtMiss.Phi - 3 * l1tmhtemu::kMHTPhiBins / 2;
240 
241  if (debug_) {
242  edm::LogVerbatim("L1TrackerHTMissEmulatorProducer")
243  << "-------------------------------------------------------------------------\n"
244  << "====MHT FLOATS====\n"
245  << "sumPx: " << sumPx_ << "| sumPy: " << sumPy_ << "| ET: " << sqrt(sumPx_ * sumPx_ + sumPy_ * sumPy_)
246  << "| HT: " << HT_ << "| PHI: " << atan2(sumPy_, sumPx_) << "\n"
247  << "====MHT AP_INTS====\n"
248  << "sumPx: " << sumPx << "| sumPy: " << sumPy << "| ET: " << EtMiss.Et << "| HT: " << HT << "| PHI: " << phi
249  << "\n"
250  << "====MHT AP_INTS TO FLOATS====\n"
251  << "sumPx: " << (float)sumPx * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi
252  << "| sumPy: " << (float)sumPy * l1tmhtemu::kStepPt * l1tmhtemu::kStepPhi << "| ET: " << EtMiss.Et.to_double()
253  << "| HT: " << (float)HT * l1tmhtemu::kStepPt << "| PHI: " << (float)phi * l1tmhtemu::kStepMHTPhi - M_PI << "\n"
254  << "-------------------------------------------------------------------------\n";
255  }
256  //rescale HT to correct output range
257  HT = HT / (int)(1 / l1tmhtemu::kStepPt);
258 
259  EtSum L1HTSum(missingEt, EtSum::EtSumType::kMissingHt, (int)HT.range(), 0, (int)phi, (int)jetn);
260 
261  MHTCollection->push_back(L1HTSum);
263 
264 } //end producer
265 
267 
269 
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:156
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:19
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