CMS 3D CMS Logo

BXVectorInputProducer.cc
Go to the documentation of this file.
1 
14 // system include files
15 #include <memory>
16 
17 // user include files
18 
28 
29 //#include <vector>
31 
38 
43 
44 #include "TMath.h"
45 
46 using namespace std;
47 using namespace edm;
48 
49 #ifndef M_PI
50 #define M_PI 3.14159265358979323846
51 #endif
52 
53 namespace l1t {
54 
55  //
56  // class declaration
57  //
58 
59  class BXVectorInputProducer : public one::EDProducer<> {
60  public:
61  explicit BXVectorInputProducer(const ParameterSet&);
62  ~BXVectorInputProducer() override;
63 
64  static void fillDescriptions(ConfigurationDescriptions& descriptions);
65 
66  private:
67  void produce(Event&, EventSetup const&) override;
68 
69  int convertPhiToHW(double iphi, int steps) const;
70  int convertEtaToHW(double ieta, double minEta, double maxEta, int steps) const;
71  int convertPtToHW(double ipt, int maxPt, double step) const;
72 
73  // ----------member data ---------------------------
74  //std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
75  //std::shared_ptr<const FirmwareVersion> m_fwv;
76  //std::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
77 
78  // BX parameters
79  int bxFirst_;
80  int bxLast_;
81 
82  unsigned int maxNumMuCands_;
83  unsigned int maxNumMuShowerCands_;
84  unsigned int maxNumJetCands_;
85  unsigned int maxNumEGCands_;
86  unsigned int maxNumTauCands_;
87 
92 
93  // Control how to end the job
96  int eventCnt_;
97 
98  // Tokens for inputs from other parts of the L1 system
105 
106  std::vector<l1t::Muon> muonVec_bxm2;
107  std::vector<l1t::Muon> muonVec_bxm1;
108  std::vector<l1t::Muon> muonVec_bx0;
109  std::vector<l1t::Muon> muonVec_bxp1;
110 
111  std::vector<l1t::MuonShower> muonShowerVec_bxm2;
112  std::vector<l1t::MuonShower> muonShowerVec_bxm1;
113  std::vector<l1t::MuonShower> muonShowerVec_bx0;
114  std::vector<l1t::MuonShower> muonShowerVec_bxp1;
115 
116  std::vector<l1t::EGamma> egammaVec_bxm2;
117  std::vector<l1t::EGamma> egammaVec_bxm1;
118  std::vector<l1t::EGamma> egammaVec_bx0;
119  std::vector<l1t::EGamma> egammaVec_bxp1;
120 
121  std::vector<l1t::Tau> tauVec_bxm2;
122  std::vector<l1t::Tau> tauVec_bxm1;
123  std::vector<l1t::Tau> tauVec_bx0;
124  std::vector<l1t::Tau> tauVec_bxp1;
125 
126  std::vector<l1t::Jet> jetVec_bxm2;
127  std::vector<l1t::Jet> jetVec_bxm1;
128  std::vector<l1t::Jet> jetVec_bx0;
129  std::vector<l1t::Jet> jetVec_bxp1;
130 
131  std::vector<l1t::EtSum> etsumVec_bxm2;
132  std::vector<l1t::EtSum> etsumVec_bxm1;
133  std::vector<l1t::EtSum> etsumVec_bx0;
134  std::vector<l1t::EtSum> etsumVec_bxp1;
135  };
136 
137  //
138  // constructors and destructor
139  //
140  BXVectorInputProducer::BXVectorInputProducer(const ParameterSet& iConfig) {
141  egToken = consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<InputTag>("egInputTag"));
142  muToken = consumes<BXVector<l1t::Muon>>(iConfig.getParameter<InputTag>("muInputTag"));
143  muShowerToken = consumes<BXVector<l1t::MuonShower>>(iConfig.getParameter<InputTag>("muShowerInputTag"));
144  tauToken = consumes<BXVector<l1t::Tau>>(iConfig.getParameter<InputTag>("tauInputTag"));
145  jetToken = consumes<BXVector<l1t::Jet>>(iConfig.getParameter<InputTag>("jetInputTag"));
146  etsumToken = consumes<BXVector<l1t::EtSum>>(iConfig.getParameter<InputTag>("etsumInputTag"));
147 
148  // register what you produce
149  produces<BXVector<l1t::EGamma>>();
150  produces<BXVector<l1t::Muon>>();
151  produces<BXVector<l1t::MuonShower>>();
152  produces<BXVector<l1t::Tau>>();
153  produces<BXVector<l1t::Jet>>();
154  produces<BXVector<l1t::EtSum>>();
155 
156  // Setup parameters
157  bxFirst_ = iConfig.getParameter<int>("bxFirst");
158  bxLast_ = iConfig.getParameter<int>("bxLast");
159 
160  maxNumMuCands_ = iConfig.getParameter<unsigned int>("maxMuCand");
161  maxNumMuShowerCands_ = iConfig.getParameter<unsigned int>("maxMuShowerCand");
162  maxNumJetCands_ = iConfig.getParameter<unsigned int>("maxJetCand");
163  maxNumEGCands_ = iConfig.getParameter<unsigned int>("maxEGCand");
164  maxNumTauCands_ = iConfig.getParameter<unsigned int>("maxTauCand");
165 
166  jetEtThreshold_ = iConfig.getParameter<double>("jetEtThreshold");
167  tauEtThreshold_ = iConfig.getParameter<double>("tauEtThreshold");
168  egEtThreshold_ = iConfig.getParameter<double>("egEtThreshold");
169  muEtThreshold_ = iConfig.getParameter<double>("muEtThreshold");
170 
171  emptyBxTrailer_ = iConfig.getParameter<int>("emptyBxTrailer");
172  emptyBxEvt_ = iConfig.getParameter<int>("emptyBxEvt");
173 
174  // set cache id to zero, will be set at first beginRun:
175  eventCnt_ = 0;
176  }
177 
178  BXVectorInputProducer::~BXVectorInputProducer() {}
179 
180  //
181  // member functions
182  //
183 
184  // ------------ method called to produce the data ------------
185  void BXVectorInputProducer::produce(Event& iEvent, const EventSetup& iSetup) {
186  eventCnt_++;
187 
188  LogDebug("l1t|Global") << "BXVectorInputProducer::produce function called...\n";
189 
190  // Setup vectors
191  std::vector<l1t::Muon> muonVec;
192  std::vector<l1t::MuonShower> muonShowerVec;
193  std::vector<l1t::EGamma> egammaVec;
194  std::vector<l1t::Tau> tauVec;
195  std::vector<l1t::Jet> jetVec;
196  std::vector<l1t::EtSum> etsumVec;
197 
198  // Set the range of BX....TO DO...move to Params or determine from param set.
199  int bxFirst = bxFirst_;
200  int bxLast = bxLast_;
201 
202  //outputs
203  std::unique_ptr<l1t::EGammaBxCollection> egammas(new l1t::EGammaBxCollection(0, bxFirst, bxLast));
204  std::unique_ptr<l1t::MuonBxCollection> muons(new l1t::MuonBxCollection(0, bxFirst, bxLast));
205  std::unique_ptr<l1t::MuonShowerBxCollection> muonShowers(new l1t::MuonShowerBxCollection(0, bxFirst, bxLast));
206  std::unique_ptr<l1t::TauBxCollection> taus(new l1t::TauBxCollection(0, bxFirst, bxLast));
207  std::unique_ptr<l1t::JetBxCollection> jets(new l1t::JetBxCollection(0, bxFirst, bxLast));
208  std::unique_ptr<l1t::EtSumBxCollection> etsums(new l1t::EtSumBxCollection(0, bxFirst, bxLast));
209 
210  std::vector<int> mu_cands_index;
211  std::vector<int> eg_cands_index;
212  std::vector<int> tau_cands_index;
213 
214  // Bx to use...grab only bx=0 for now
215  int bx = 0;
216 
217  // Make sure that you can get input EG
218  Handle<BXVector<l1t::EGamma>> inputEgammas;
219  if (iEvent.getByToken(egToken, inputEgammas)) {
220  for (std::vector<l1t::EGamma>::const_iterator eg = inputEgammas->begin(bx); eg != inputEgammas->end(bx); ++eg) {
221  if (eg->hwPt() > egEtThreshold_ && egammaVec.size() < maxNumEGCands_) {
222  egammaVec.push_back((*eg));
223  }
224  }
225  } else {
226  LogTrace("l1t|Global") << ">>> input EG collection not found!" << std::endl;
227  }
228 
229  // Make sure that you can get input Muons
231  if (iEvent.getByToken(muToken, inputMuons)) {
232  for (std::vector<l1t::Muon>::const_iterator mu = inputMuons->begin(bx); mu != inputMuons->end(bx); ++mu) {
233  if (mu->hwPt() > muEtThreshold_ && muonVec.size() < maxNumMuCands_) {
234  muonVec.push_back((*mu));
235  }
236  }
237  } else {
238  LogTrace("l1t|Global") << ">>> input Mu collection not found!" << std::endl;
239  }
240 
241  // Make sure that you can get input Muon Showers
242  Handle<BXVector<l1t::MuonShower>> inputMuonShowers;
243  if (iEvent.getByToken(muToken, inputMuonShowers)) {
244  for (std::vector<l1t::MuonShower>::const_iterator mu = inputMuonShowers->begin(bx);
245  mu != inputMuonShowers->end(bx);
246  ++mu) {
247  if (mu->isValid() && muonShowerVec.size() < maxNumMuCands_) {
248  muonShowerVec.push_back((*mu));
249  }
250  }
251  } else {
252  LogTrace("l1t|Global") << ">>> input Mu collection not found!" << std::endl;
253  }
254 
255  // Make sure that you can get input Tau
256  Handle<BXVector<l1t::Tau>> inputTaus;
257  if (iEvent.getByToken(tauToken, inputTaus)) {
258  for (std::vector<l1t::Tau>::const_iterator tau = inputTaus->begin(bx); tau != inputTaus->end(bx); ++tau) {
259  if (tau->hwPt() > tauEtThreshold_ && tauVec.size() < maxNumTauCands_) {
260  tauVec.push_back((*tau));
261  }
262  }
263  } else {
264  LogTrace("l1t|Global") << ">>> input tau collection not found!" << std::endl;
265  }
266 
267  // Make sure that you can get input jet
269  if (iEvent.getByToken(jetToken, inputJets)) {
270  for (std::vector<l1t::Jet>::const_iterator jet = inputJets->begin(bx); jet != inputJets->end(bx); ++jet) {
271  if (jet->hwPt() > jetEtThreshold_ && jetVec.size() < maxNumJetCands_) {
272  jetVec.push_back((*jet));
273  }
274  }
275  } else {
276  LogTrace("l1t|Global") << ">>> input jet collection not found!" << std::endl;
277  }
278 
279  // Make sure that you can get input etsum
280  Handle<BXVector<l1t::EtSum>> inputEtsums;
281  if (iEvent.getByToken(etsumToken, inputEtsums)) {
282  for (std::vector<l1t::EtSum>::const_iterator etsum = inputEtsums->begin(bx); etsum != inputEtsums->end(bx);
283  ++etsum) {
284  etsumVec.push_back((*etsum));
285  }
286  } else {
287  LogTrace("l1t|Global") << ">>> input etsum collection not found!" << std::endl;
288  }
289 
290  // Insert all the bx into the L1 Collections
291  LogTrace("l1t|Global") << "Event " << eventCnt_ << " EmptyBxEvt " << emptyBxEvt_ << " emptyBxTrailer "
292  << emptyBxTrailer_ << " diff " << (emptyBxEvt_ - eventCnt_) << std::endl;
293 
294  // Fill Muons
295  for (int iMu = 0; iMu < int(muonVec_bxm2.size()); iMu++) {
296  muons->push_back(-2, muonVec_bxm2[iMu]);
297  }
298  for (int iMu = 0; iMu < int(muonVec_bxm1.size()); iMu++) {
299  muons->push_back(-1, muonVec_bxm1[iMu]);
300  }
301  for (int iMu = 0; iMu < int(muonVec_bx0.size()); iMu++) {
302  muons->push_back(0, muonVec_bx0[iMu]);
303  }
304  for (int iMu = 0; iMu < int(muonVec_bxp1.size()); iMu++) {
305  muons->push_back(1, muonVec_bxp1[iMu]);
306  }
307  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
308  for (int iMu = 0; iMu < int(muonVec.size()); iMu++) {
309  muons->push_back(2, muonVec[iMu]);
310  }
311  } else {
312  // this event is part of empty trailer...clear out data
313  muonVec.clear();
314  }
315 
316  // Fill MuonShowers
317  for (int iMuShower = 0; iMuShower < int(muonShowerVec_bxm2.size()); iMuShower++) {
318  muonShowers->push_back(-2, muonShowerVec_bxm2[iMuShower]);
319  }
320  for (int iMuShower = 0; iMuShower < int(muonShowerVec_bxm1.size()); iMuShower++) {
321  muonShowers->push_back(-1, muonShowerVec_bxm1[iMuShower]);
322  }
323  for (int iMuShower = 0; iMuShower < int(muonShowerVec_bx0.size()); iMuShower++) {
324  muonShowers->push_back(0, muonShowerVec_bx0[iMuShower]);
325  }
326  for (int iMuShower = 0; iMuShower < int(muonShowerVec_bxp1.size()); iMuShower++) {
327  muonShowers->push_back(1, muonShowerVec_bxp1[iMuShower]);
328  }
329  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
330  for (int iMuShower = 0; iMuShower < int(muonShowerVec.size()); iMuShower++) {
331  muonShowers->push_back(2, muonShowerVec[iMuShower]);
332  }
333  } else {
334  // this event is part of empty trailer...clear out data
335  muonShowerVec.clear();
336  }
337 
338  // Fill Egammas
339  for (int iEG = 0; iEG < int(egammaVec_bxm2.size()); iEG++) {
340  egammas->push_back(-2, egammaVec_bxm2[iEG]);
341  }
342  for (int iEG = 0; iEG < int(egammaVec_bxm1.size()); iEG++) {
343  egammas->push_back(-1, egammaVec_bxm1[iEG]);
344  }
345  for (int iEG = 0; iEG < int(egammaVec_bx0.size()); iEG++) {
346  egammas->push_back(0, egammaVec_bx0[iEG]);
347  }
348  for (int iEG = 0; iEG < int(egammaVec_bxp1.size()); iEG++) {
349  egammas->push_back(1, egammaVec_bxp1[iEG]);
350  }
351  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
352  for (int iEG = 0; iEG < int(egammaVec.size()); iEG++) {
353  egammas->push_back(2, egammaVec[iEG]);
354  }
355  } else {
356  // this event is part of empty trailer...clear out data
357  egammaVec.clear();
358  }
359 
360  // Fill Taus
361  for (int iTau = 0; iTau < int(tauVec_bxm2.size()); iTau++) {
362  taus->push_back(-2, tauVec_bxm2[iTau]);
363  }
364  for (int iTau = 0; iTau < int(tauVec_bxm1.size()); iTau++) {
365  taus->push_back(-1, tauVec_bxm1[iTau]);
366  }
367  for (int iTau = 0; iTau < int(tauVec_bx0.size()); iTau++) {
368  taus->push_back(0, tauVec_bx0[iTau]);
369  }
370  for (int iTau = 0; iTau < int(tauVec_bxp1.size()); iTau++) {
371  taus->push_back(1, tauVec_bxp1[iTau]);
372  }
373  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
374  for (int iTau = 0; iTau < int(tauVec.size()); iTau++) {
375  taus->push_back(2, tauVec[iTau]);
376  }
377  } else {
378  // this event is part of empty trailer...clear out data
379  tauVec.clear();
380  }
381 
382  // Fill Jets
383  for (int iJet = 0; iJet < int(jetVec_bxm2.size()); iJet++) {
384  jets->push_back(-2, jetVec_bxm2[iJet]);
385  }
386  for (int iJet = 0; iJet < int(jetVec_bxm1.size()); iJet++) {
387  jets->push_back(-1, jetVec_bxm1[iJet]);
388  }
389  for (int iJet = 0; iJet < int(jetVec_bx0.size()); iJet++) {
390  jets->push_back(0, jetVec_bx0[iJet]);
391  }
392  for (int iJet = 0; iJet < int(jetVec_bxp1.size()); iJet++) {
393  jets->push_back(1, jetVec_bxp1[iJet]);
394  }
395  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
396  for (int iJet = 0; iJet < int(jetVec.size()); iJet++) {
397  jets->push_back(2, jetVec[iJet]);
398  }
399  } else {
400  // this event is part of empty trailer...clear out data
401  jetVec.clear();
402  }
403 
404  // Fill Etsums
405  for (int iETsum = 0; iETsum < int(etsumVec_bxm2.size()); iETsum++) {
406  etsums->push_back(-2, etsumVec_bxm2[iETsum]);
407  }
408  for (int iETsum = 0; iETsum < int(etsumVec_bxm1.size()); iETsum++) {
409  etsums->push_back(-1, etsumVec_bxm1[iETsum]);
410  }
411  for (int iETsum = 0; iETsum < int(etsumVec_bx0.size()); iETsum++) {
412  etsums->push_back(0, etsumVec_bx0[iETsum]);
413  }
414  for (int iETsum = 0; iETsum < int(etsumVec_bxp1.size()); iETsum++) {
415  etsums->push_back(1, etsumVec_bxp1[iETsum]);
416  }
417  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
418  for (int iETsum = 0; iETsum < int(etsumVec.size()); iETsum++) {
419  etsums->push_back(2, etsumVec[iETsum]);
420  }
421  } else {
422  // this event is part of empty trailer...clear out data
423  etsumVec.clear();
424  }
425 
426  iEvent.put(std::move(egammas));
427  iEvent.put(std::move(muons));
428  iEvent.put(std::move(muonShowers));
429  iEvent.put(std::move(taus));
430  iEvent.put(std::move(jets));
431  iEvent.put(std::move(etsums));
432 
433  // Now shift the bx data by one to prepare for next event.
434  muonVec_bxm2 = muonVec_bxm1;
435  muonShowerVec_bxm2 = muonShowerVec_bxm1;
436  egammaVec_bxm2 = egammaVec_bxm1;
437  tauVec_bxm2 = tauVec_bxm1;
438  jetVec_bxm2 = jetVec_bxm1;
439  etsumVec_bxm2 = etsumVec_bxm1;
440 
441  muonVec_bxm1 = muonVec_bx0;
442  muonShowerVec_bxm1 = muonShowerVec_bx0;
443  egammaVec_bxm1 = egammaVec_bx0;
444  tauVec_bxm1 = tauVec_bx0;
445  jetVec_bxm1 = jetVec_bx0;
446  etsumVec_bxm1 = etsumVec_bx0;
447 
448  muonVec_bx0 = muonVec_bxp1;
449  muonShowerVec_bx0 = muonShowerVec_bxp1;
450  egammaVec_bx0 = egammaVec_bxp1;
451  tauVec_bx0 = tauVec_bxp1;
452  jetVec_bx0 = jetVec_bxp1;
453  etsumVec_bx0 = etsumVec_bxp1;
454 
455  muonVec_bxp1 = muonVec;
456  muonShowerVec_bxp1 = muonShowerVec;
457  egammaVec_bxp1 = egammaVec;
458  tauVec_bxp1 = tauVec;
459  jetVec_bxp1 = jetVec;
460  etsumVec_bxp1 = etsumVec;
461  }
462 
463  // ------------ methods to convert from physical to HW values ------------
464  int BXVectorInputProducer::convertPhiToHW(double iphi, int steps) const {
465  double phiMax = 2 * M_PI;
466  if (iphi < 0)
467  iphi += 2 * M_PI;
468  if (iphi > phiMax)
469  iphi -= phiMax;
470 
471  int hwPhi = int((iphi / phiMax) * steps + 0.00001);
472  return hwPhi;
473  }
474 
475  int BXVectorInputProducer::convertEtaToHW(double ieta, double minEta, double maxEta, int steps) const {
476  double binWidth = (maxEta - minEta) / steps;
477 
478  //if we are outside the limits, set error
479  if (ieta < minEta)
480  return 99999; //ieta = minEta+binWidth/2.;
481  if (ieta > maxEta)
482  return 99999; //ieta = maxEta-binWidth/2.;
483 
484  int binNum = (int)(ieta / binWidth);
485  if (ieta < 0.)
486  binNum--;
487 
488  // unsigned int hwEta = binNum & bitMask;
489  // Remove masking for BXVectors...only assume in raw data
490 
491  return binNum;
492  }
493 
494  int BXVectorInputProducer::convertPtToHW(double ipt, int maxPt, double step) const {
495  int hwPt = int(ipt / step + 0.0001);
496  // if above max Pt, set to largest value
497  if (hwPt > maxPt)
498  hwPt = maxPt;
499 
500  return hwPt;
501  }
502 
503  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
505  //The following says we do not know what parameters are allowed so do no validation
506  // Please change this to state exactly what you do use, even if it is no parameters
508  desc.setUnknown();
509  descriptions.addDefault(desc);
510  }
511 
512 } // namespace l1t
513 
514 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< l1t::Jet > jetVec_bxp1
std::vector< l1t::Muon > muonVec_bx0
std::vector< l1t::EGamma > egammaVec_bxm1
std::vector< l1t::EtSum > etsumVec_bxm2
std::vector< l1t::EGamma > egammaVec_bxp1
std::vector< l1t::Jet > jetVec_bx0
std::vector< l1t::EGamma > egammaVec_bxm2
std::vector< l1t::Jet > jetVec_bxm2
delete x;
Definition: CaloConfig.h:22
std::vector< l1t::Tau > tauVec_bxm2
std::vector< l1t::EtSum > etsumVec_bx0
#define LogTrace(id)
std::vector< l1t::MuonShower > muonShowerVec_bxm2
std::vector< l1t::Jet > jetVec_bxm1
int iEvent
Definition: GenABIO.cc:224
std::vector< l1t::Tau > tauVec_bxm1
std::vector< l1t::EtSum > etsumVec_bxm1
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< l1t::Muon > muonVec_bxp1
std::vector< l1t::Tau > tauVec_bx0
std::vector< l1t::EGamma > egammaVec_bx0
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
#define M_PI
std::vector< l1t::MuonShower > muonShowerVec_bxm1
std::vector< l1t::EtSum > etsumVec_bxp1
std::vector< l1t::Muon > muonVec_bxm1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< l1t::MuonShower > muonShowerVec_bxp1
HLT enums.
std::vector< l1t::Muon > muonVec_bxm2
std::vector< l1t::Tau > tauVec_bxp1
step
Definition: StallMonitor.cc:98
def move(src, dest)
Definition: eostools.py:511
std::vector< l1t::MuonShower > muonShowerVec_bx0
#define LogDebug(id)