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