CMS 3D CMS Logo

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