CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GenToInputProducer.cc
Go to the documentation of this file.
1 
15 // system include files
16 #include <memory>
17 
18 // user include files
19 
30 
31 //#include <vector>
33 
40 
45 
46 #include "TMath.h"
47 #include "TRandom3.h"
48 #include <cstdlib>
49 
50 using namespace std;
51 using namespace edm;
52 
53 #ifndef M_PI
54 #define M_PI 3.14159265358979323846
55 #endif
56 
57 namespace l1t {
58 
59  //
60  // class declaration
61  //
62 
63  class GenToInputProducer : public EDProducer {
64  public:
65  explicit GenToInputProducer(const ParameterSet&);
66  ~GenToInputProducer() override;
67 
68  static void fillDescriptions(ConfigurationDescriptions& descriptions);
69 
70  private:
71  void produce(Event&, EventSetup const&) override;
72  void beginJob() override;
73  void endJob() override;
74  void beginRun(Run const& iR, EventSetup const& iE) override;
75  void endRun(Run const& iR, EventSetup const& iE) override;
76 
77  int convertPhiToHW(double iphi, int steps);
78  int convertEtaToHW(double ieta, double minEta, double maxEta, int steps);
79  int convertPtToHW(double ipt, int maxPt, double step);
80 
81  // ----------member data ---------------------------
82  unsigned long long m_paramsCacheId; // Cache-ID from current parameters, to check if needs to be updated.
83  //std::shared_ptr<const CaloParams> m_dbpars; // Database parameters for the trigger, to be updated as needed.
84  //std::shared_ptr<const FirmwareVersion> m_fwv;
85  //std::shared_ptr<FirmwareVersion> m_fwv; //not const during testing.
86 
87  TRandom3* gRandom;
88 
89  // BX parameters
90  int bxFirst_;
91  int bxLast_;
92 
97 
102 
103  // Control how to end the job
107 
108  // Tokens
112 
113  int counter_;
114 
115  std::vector<l1t::Muon> muonVec_bxm2;
116  std::vector<l1t::Muon> muonVec_bxm1;
117  std::vector<l1t::Muon> muonVec_bx0;
118  std::vector<l1t::Muon> muonVec_bxp1;
119 
120  std::vector<l1t::EGamma> egammaVec_bxm2;
121  std::vector<l1t::EGamma> egammaVec_bxm1;
122  std::vector<l1t::EGamma> egammaVec_bx0;
123  std::vector<l1t::EGamma> egammaVec_bxp1;
124 
125  std::vector<l1t::Tau> tauVec_bxm2;
126  std::vector<l1t::Tau> tauVec_bxm1;
127  std::vector<l1t::Tau> tauVec_bx0;
128  std::vector<l1t::Tau> tauVec_bxp1;
129 
130  std::vector<l1t::Jet> jetVec_bxm2;
131  std::vector<l1t::Jet> jetVec_bxm1;
132  std::vector<l1t::Jet> jetVec_bx0;
133  std::vector<l1t::Jet> jetVec_bxp1;
134 
135  std::vector<l1t::EtSum> etsumVec_bxm2;
136  std::vector<l1t::EtSum> etsumVec_bxm1;
137  std::vector<l1t::EtSum> etsumVec_bx0;
138  std::vector<l1t::EtSum> etsumVec_bxp1;
139 
144  };
145 
146  //
147  // constructors and destructor
148  //
149  GenToInputProducer::GenToInputProducer(const ParameterSet& iConfig) {
150  // register what you produce
151  produces<BXVector<l1t::EGamma>>();
152  produces<BXVector<l1t::Muon>>();
153  produces<BXVector<l1t::Tau>>();
154  produces<BXVector<l1t::Jet>>();
155  produces<BXVector<l1t::EtSum>>();
156  produces<GlobalExtBlkBxCollection>();
157 
158  // Setup parameters
159  bxFirst_ = iConfig.getParameter<int>("bxFirst");
160  bxLast_ = iConfig.getParameter<int>("bxLast");
161 
162  maxNumMuCands_ = iConfig.getParameter<int>("maxMuCand");
163  maxNumJetCands_ = iConfig.getParameter<int>("maxJetCand");
164  maxNumEGCands_ = iConfig.getParameter<int>("maxEGCand");
165  maxNumTauCands_ = iConfig.getParameter<int>("maxTauCand");
166 
167  jetEtThreshold_ = iConfig.getParameter<double>("jetEtThreshold");
168  tauEtThreshold_ = iConfig.getParameter<double>("tauEtThreshold");
169  egEtThreshold_ = iConfig.getParameter<double>("egEtThreshold");
170  muEtThreshold_ = iConfig.getParameter<double>("muEtThreshold");
171 
172  emptyBxTrailer_ = iConfig.getParameter<int>("emptyBxTrailer");
173  emptyBxEvt_ = iConfig.getParameter<int>("emptyBxEvt");
174 
175  genParticlesToken = consumes<reco::GenParticleCollection>(std::string("genParticles"));
176  genJetsToken = consumes<reco::GenJetCollection>(std::string("ak4GenJets"));
177  genMetToken = consumes<reco::GenMETCollection>(std::string("genMetCalo"));
178 
179  // set cache id to zero, will be set at first beginRun:
180  m_paramsCacheId = 0;
181  eventCnt_ = 0;
182  }
183 
184  GenToInputProducer::~GenToInputProducer() {}
185 
186  //
187  // member functions
188  //
189 
190  // ------------ method called to produce the data ------------
191  void GenToInputProducer::produce(Event& iEvent, const EventSetup& iSetup) {
192  eventCnt_++;
193 
194  LogDebug("GtGenToInputProducer") << "GenToInputProducer::produce function called...\n";
195 
196  // Setup vectors
197  std::vector<l1t::Muon> muonVec;
198  std::vector<l1t::EGamma> egammaVec;
199  std::vector<l1t::Tau> tauVec;
200  std::vector<l1t::Jet> jetVec;
201  std::vector<l1t::EtSum> etsumVec;
202  GlobalExtBlk extCond_bx;
203 
204  // Set the range of BX....TO DO...move to Params or determine from param set.
205  int bxFirst = bxFirst_;
206  int bxLast = bxLast_;
207 
208  // Default values objects
209  double MaxLepPt_ = 255;
210  double MaxJetPt_ = 1023;
211  double MaxEt_ = 2047;
212 
213  double MaxCaloEta_ = 5.0;
214  double MaxMuonEta_ = 2.45;
215 
216  double PhiStepCalo_ = 144;
217  double PhiStepMuon_ = 576;
218 
219  // eta scale
220  double EtaStepCalo_ = 230;
221  double EtaStepMuon_ = 450;
222 
223  // Et scale (in GeV)
224  double PtStep_ = 0.5;
225 
226  //outputs
227  std::unique_ptr<l1t::EGammaBxCollection> egammas(new l1t::EGammaBxCollection(0, bxFirst, bxLast));
228  std::unique_ptr<l1t::MuonBxCollection> muons(new l1t::MuonBxCollection(0, bxFirst, bxLast));
229  std::unique_ptr<l1t::TauBxCollection> taus(new l1t::TauBxCollection(0, bxFirst, bxLast));
230  std::unique_ptr<l1t::JetBxCollection> jets(new l1t::JetBxCollection(0, bxFirst, bxLast));
231  std::unique_ptr<l1t::EtSumBxCollection> etsums(new l1t::EtSumBxCollection(0, bxFirst, bxLast));
232  std::unique_ptr<GlobalExtBlkBxCollection> extCond(new GlobalExtBlkBxCollection(0, bxFirst, bxLast));
233 
234  std::vector<int> mu_cands_index;
235  std::vector<int> eg_cands_index;
236  std::vector<int> tau_cands_index;
238  // Make sure that you can get genParticles
239  if (iEvent.getByToken(genParticlesToken, genParticles)) {
240  for (size_t k = 0; k < genParticles->size(); k++) {
241  const reco::Candidate& mcParticle = (*genParticles)[k];
242 
243  int status = mcParticle.status();
244  int pdgId = mcParticle.pdgId();
245  double pt = mcParticle.pt();
246 
247  // Only use status 1 particles (Tau's need to be allowed through..take status 2 taus)
248  if (status != 1 && !(abs(pdgId) == 15 && status == 2))
249  continue;
250 
251  int absId = abs(pdgId);
252 
253  if (absId == 11 && pt >= egEtThreshold_)
254  eg_cands_index.push_back(k);
255  else if (absId == 13 && pt >= muEtThreshold_)
256  mu_cands_index.push_back(k);
257  else if (absId == 15 && pt >= tauEtThreshold_)
258  tau_cands_index.push_back(k);
259  }
260  } else {
261  LogTrace("GtGenToInputProducer") << ">>> GenParticles collection not found!" << std::endl;
262  }
263 
264  // Muon Collection
265  int numMuCands = int(mu_cands_index.size());
266  Int_t idxMu[numMuCands];
267  double muPtSorted[numMuCands];
268  for (int iMu = 0; iMu < numMuCands; iMu++)
269  muPtSorted[iMu] = genParticles->at(mu_cands_index[iMu]).pt();
270 
271  TMath::Sort(numMuCands, muPtSorted, idxMu);
272  for (int iMu = 0; iMu < numMuCands; iMu++) {
273  if (iMu >= maxNumMuCands_)
274  continue;
275 
276  const reco::Candidate& mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
277 
278  int pt = convertPtToHW(mcParticle.pt(), MaxLepPt_, PtStep_);
279  int eta = convertEtaToHW(mcParticle.eta(), -MaxMuonEta_, MaxMuonEta_, EtaStepMuon_);
280  int phi = convertPhiToHW(mcParticle.phi(), PhiStepMuon_);
281  int qual = gRandom->Integer(16); //4;
282  int iso = gRandom->Integer(4) % 2; //1;
283  int charge = (mcParticle.charge() < 0) ? 1 : 0;
284  int chargeValid = 1;
285  int tfMuIdx = 0;
286  int tag = 1;
287  bool debug = false;
288  int isoSum = 0;
289  int dPhi = 0;
290  int dEta = 0;
291  int rank = 0;
292  int hwEtaAtVtx = eta;
293  int hwPhiAtVtx = phi;
294  double etaAtVtx = 0.0;
295  double phiAtVtx = 0.0;
296  int hwPtUnconstrained =
297  convertPtToHW(mcParticle.pt(), MaxLepPt_, PtStep_) / 2; // word is 8 bits wide so divide 9 bit word by 2
298  double ptUnconstrained = 0.0;
299  int dXY = gRandom->Integer(4); // should be [0,3] = 2 bits
300 
301  // Eta outside of acceptance
302  if (eta >= 9999)
303  continue;
304 
305  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
306  new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
307 
308  l1t::Muon mu(*p4,
309  pt,
310  eta,
311  phi,
312  qual,
313  charge,
314  chargeValid,
315  iso,
316  tfMuIdx,
317  tag,
318  debug,
319  isoSum,
320  dPhi,
321  dEta,
322  rank,
323  hwEtaAtVtx,
324  hwPhiAtVtx,
325  etaAtVtx,
326  phiAtVtx,
327  hwPtUnconstrained,
328  ptUnconstrained,
329  dXY); // modified to conform to latest Muon.h interface
330  muonVec.push_back(mu);
331  }
332 
333  // EG Collection
334  int numEgCands = int(eg_cands_index.size());
335  Int_t idxEg[numEgCands];
336  double egPtSorted[numEgCands];
337  for (int iEg = 0; iEg < numEgCands; iEg++)
338  egPtSorted[iEg] = genParticles->at(eg_cands_index[iEg]).pt();
339 
340  TMath::Sort(numEgCands, egPtSorted, idxEg);
341  for (int iEg = 0; iEg < numEgCands; iEg++) {
342  if (iEg >= maxNumEGCands_)
343  continue;
344 
345  const reco::Candidate& mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
346 
347  int pt = convertPtToHW(mcParticle.pt(), MaxLepPt_, PtStep_);
348  int eta = convertEtaToHW(mcParticle.eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
349  int phi = convertPhiToHW(mcParticle.phi(), PhiStepCalo_);
350  int qual = gRandom->Integer(2); // modified for LLP Jets
351  int iso = gRandom->Integer(4) % 2;
352 
353  // Eta outside of acceptance
354  if (eta >= 9999)
355  continue;
356 
357  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
358  new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
359 
360  l1t::EGamma eg(*p4, pt, eta, phi, qual, iso);
361  egammaVec.push_back(eg);
362  }
363 
364  // Tau Collection
365  int numTauCands = int(tau_cands_index.size());
366  Int_t idxTau[numTauCands];
367  double tauPtSorted[numTauCands];
368  for (int iTau = 0; iTau < numTauCands; iTau++)
369  tauPtSorted[iTau] = genParticles->at(tau_cands_index[iTau]).pt();
370 
371  TMath::Sort(numTauCands, tauPtSorted, idxTau);
372  for (int iTau = 0; iTau < numTauCands; iTau++) {
373  if (iTau >= maxNumTauCands_)
374  continue;
375 
376  const reco::Candidate& mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
377 
378  int pt = convertPtToHW(mcParticle.pt(), MaxLepPt_, PtStep_);
379  int eta = convertEtaToHW(mcParticle.eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
380  int phi = convertPhiToHW(mcParticle.phi(), PhiStepCalo_);
381  int qual = gRandom->Integer(2); // modified for LLP Jets
382  int iso = gRandom->Integer(4) % 2;
383 
384  // Eta outside of acceptance
385  if (eta >= 9999)
386  continue;
387 
388  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
389  new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
390 
391  l1t::Tau tau(*p4, pt, eta, phi, qual, iso);
392  tauVec.push_back(tau);
393  }
394 
395  // Temporary hack to increase number of EGs and taus
396  int maxOtherEGs = 4;
397  int maxOtherTaus = 8;
398  int numCurrentEGs = int(egammaVec.size());
399  int numCurrentTaus = int(tauVec.size());
400 
401  int numExtraEGs = 0, numExtraTaus = 0;
402  // end hack
403 
404  // Use to sum the energy of the objects in the event for ETT and HTT
405  // sum all jets
406  double sumEt = 0;
407 
408  int nJet = 0;
410  // Make sure that you can get genJets
411  if (iEvent.getByToken(genJetsToken, genJets)) { // Jet Collection
412  for (reco::GenJetCollection::const_iterator genJet = genJets->begin(); genJet != genJets->end(); ++genJet) {
413  //Keep running sum of total Et
414  sumEt += genJet->et();
415 
416  // Apply pt and eta cut?
417  if (genJet->pt() < jetEtThreshold_)
418  continue;
419 
420  //
421  if (nJet >= maxNumJetCands_)
422  continue;
423  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
424  new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
425 
426  int pt = convertPtToHW(genJet->et(), MaxJetPt_, PtStep_);
427  int eta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
428  int phi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
429 
430  // Eta outside of acceptance
431  if (eta >= 9999)
432  continue;
433 
434  int qual = gRandom->Integer(2); // modified for LLP Jets
435 
436  l1t::Jet jet(*p4, pt, eta, phi, qual);
437  jetVec.push_back(jet);
438 
439  nJet++;
440 
441  // Temporary hack to increase number of EGs and taus
442  if ((numExtraEGs + numCurrentEGs) < maxNumEGCands_ && numExtraEGs < maxOtherEGs) {
443  numExtraEGs++;
444 
445  int EGpt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
446  int EGeta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
447  int EGphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
448 
449  int EGqual = gRandom->Integer(2); // modified for LLP Jets
450  int EGiso = gRandom->Integer(4) % 2;
451 
452  l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
453  egammaVec.push_back(eg);
454  }
455 
456  if ((numExtraTaus + numCurrentTaus) < maxNumTauCands_ && numExtraTaus < maxOtherTaus) {
457  numExtraTaus++;
458 
459  int Taupt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
460  int Taueta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
461  int Tauphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
462  int Tauqual = gRandom->Integer(2); // modified for LLP Jets
463  int Tauiso = gRandom->Integer(4) % 2;
464 
465  l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
466  tauVec.push_back(tau);
467  }
468  // end hack
469  }
470  } else {
471  LogTrace("GtGenToInputProducer") << ">>> GenJets collection not found!" << std::endl;
472  }
473 
474  // Put the total Et into EtSums (Make HTT slightly smaller to tell them apart....not supposed to be realistic)
475  int pt = convertPtToHW(sumEt, 2047, PtStep_);
476  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
477  new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
478  l1t::EtSum etTotal(*p4, l1t::EtSum::EtSumType::kTotalEt, pt, 0, 0, 0);
479 
480  // Scale down ETTem as an estimate
481  pt = convertPtToHW(sumEt * 0.6, 2047, PtStep_);
482  l1t::EtSum etEmTotal(*p4, l1t::EtSum::EtSumType::kTotalEtEm, pt, 0, 0, 0);
483 
484  //ccla Generate uniform distribution of tower counts
485  int nTowers = 4095 * gRandom->Rndm();
486  l1t::EtSum towerCounts(*p4, l1t::EtSum::EtSumType::kTowerCount, nTowers, 0, 0, 0);
487 
488  //ccla Generate uniform distributions of AsymEt, AsymHt, AsymEtHF, AsymHtF
489  int nAsymEt = 255 * gRandom->Rndm();
490  l1t::EtSum AsymEt(*p4, l1t::EtSum::EtSumType::kAsymEt, nAsymEt, 0, 0, 0);
491  int nAsymHt = 255 * gRandom->Rndm();
492  l1t::EtSum AsymHt(*p4, l1t::EtSum::EtSumType::kAsymHt, nAsymHt, 0, 0, 0);
493  int nAsymEtHF = 255 * gRandom->Rndm();
494  l1t::EtSum AsymEtHF(*p4, l1t::EtSum::EtSumType::kAsymEtHF, nAsymEtHF, 0, 0, 0);
495  int nAsymHtHF = 255 * gRandom->Rndm();
496  l1t::EtSum AsymHtHF(*p4, l1t::EtSum::EtSumType::kAsymHtHF, nAsymHtHF, 0, 0, 0);
497 
498  pt = convertPtToHW(sumEt * 0.9, 2047, PtStep_);
499  l1t::EtSum htTotal(*p4, l1t::EtSum::EtSumType::kTotalHt, pt, 0, 0, 0);
500 
501  // Add EtSums for testing the MinBias Trigger (use some random numbers)
502  int hfP0val = gRandom->Poisson(4.);
503  if (hfP0val > 15)
504  hfP0val = 15;
505  l1t::EtSum hfP0(*p4, l1t::EtSum::EtSumType::kMinBiasHFP0, hfP0val, 0, 0, 0);
506 
507  int hfM0val = gRandom->Poisson(4.);
508  if (hfM0val > 15)
509  hfM0val = 15;
510  l1t::EtSum hfM0(*p4, l1t::EtSum::EtSumType::kMinBiasHFM0, hfM0val, 0, 0, 0);
511 
512  int hfP1val = gRandom->Poisson(4.);
513  if (hfP1val > 15)
514  hfP1val = 15;
515  l1t::EtSum hfP1(*p4, l1t::EtSum::EtSumType::kMinBiasHFP1, hfP1val, 0, 0, 0);
516 
517  int hfM1val = gRandom->Poisson(4.);
518  if (hfM1val > 15)
519  hfM1val = 15;
520  l1t::EtSum hfM1(*p4, l1t::EtSum::EtSumType::kMinBiasHFM1, hfM1val, 0, 0, 0);
521 
522  // Do same for Centrality
523  int cent30val(0), cent74val(0);
524  int centa = gRandom->Poisson(2.);
525  int centb = gRandom->Poisson(2.);
526  if (centa >= centb) {
527  cent30val = centa;
528  cent74val = centb;
529  } else {
530  cent30val = centb;
531  cent74val = centa;
532  }
533 
534  if (cent30val > 15)
535  cent30val = 15;
536  if (cent74val > 15)
537  cent74val = 15;
538 
539  int shift = 4;
540  int centralval = 0;
541  centralval |= cent30val & 0xF;
542  centralval |= (cent74val & 0xF) << shift;
543 
544  l1t::EtSum centrality(*p4, l1t::EtSum::EtSumType::kCentrality, centralval, 0, 0, 0);
545 
546  int mpt = 0;
547  int mphi = 0;
548  int mptHf = 0;
549  int mphiHf = 0;
550  int mhpt = 0;
551  int mhphi = 0;
552  int mhptHf = 0;
553  int mhphiHf = 0;
554 
556  // Make sure that you can get genMET
557  if (iEvent.getByToken(genMetToken, genMet)) {
558  mpt = convertPtToHW(genMet->front().pt(), MaxEt_, PtStep_);
559  mphi = convertPhiToHW(genMet->front().phi(), PhiStepCalo_);
560 
561  // Make Missing Et with HF slightly largeer and rotated (These are all fake inputs anyway...not supposed to be realistic)
562  mptHf = convertPtToHW(genMet->front().pt() * 1.1, MaxEt_, PtStep_);
563  mphiHf = convertPhiToHW(genMet->front().phi() + 3.14 / 7., PhiStepCalo_);
564 
565  // Make Missing Ht slightly smaller and rotated (These are all fake inputs anyway...not supposed to be realistic)
566  mhpt = convertPtToHW(genMet->front().pt() * 0.9, MaxEt_, PtStep_);
567  mhphi = convertPhiToHW(genMet->front().phi() + 3.14 / 5., PhiStepCalo_);
568 
569  // Ditto with Hissing Ht with HF
570  mhptHf = convertPtToHW(genMet->front().pt() * 0.95, MaxEt_, PtStep_);
571  mhphiHf = convertPhiToHW(genMet->front().phi() + 3.14 / 6., PhiStepCalo_);
572  } else {
573  LogTrace("GtGenToInputProducer") << ">>> GenMet collection not found!" << std::endl;
574  }
575 
576  // Missing Et and missing htt
577  l1t::EtSum etmiss(*p4, l1t::EtSum::EtSumType::kMissingEt, mpt, 0, mphi, 0);
578  l1t::EtSum etmissHF(*p4, l1t::EtSum::EtSumType::kMissingEtHF, mptHf, 0, mphiHf, 0);
579  l1t::EtSum htmiss(*p4, l1t::EtSum::EtSumType::kMissingHt, mhpt, 0, mhphi, 0);
580  l1t::EtSum htmissHF(*p4, l1t::EtSum::EtSumType::kMissingHtHF, mhptHf, 0, mhphiHf, 0);
581 
582  // Fill the EtSums in the Correct order
583  etsumVec.push_back(etTotal);
584  etsumVec.push_back(etEmTotal);
585  etsumVec.push_back(hfP0); // Frame0
586 
587  etsumVec.push_back(htTotal);
588  etsumVec.push_back(towerCounts);
589  etsumVec.push_back(hfM0); //Frame1
590 
591  etsumVec.push_back(etmiss);
592  etsumVec.push_back(AsymEt);
593  etsumVec.push_back(hfP1); //Frame2
594 
595  etsumVec.push_back(htmiss);
596  etsumVec.push_back(AsymHt);
597  etsumVec.push_back(hfM1); //Frame3
598 
599  etsumVec.push_back(etmissHF);
600  etsumVec.push_back(AsymEtHF); // Frame4
601 
602  etsumVec.push_back(htmissHF);
603  etsumVec.push_back(AsymHtHF);
604  etsumVec.push_back(centrality); // Frame5
605 
606  // Fill in some external conditions for testing
607  if ((iEvent.id().event()) % 2 == 0) {
608  for (int i = 0; i < 255; i = i + 2)
609  extCond_bx.setExternalDecision(i, true);
610  } else {
611  for (int i = 1; i < 255; i = i + 2)
612  extCond_bx.setExternalDecision(i, true);
613  }
614 
615  // Insert all the bx into the L1 Collections
616  //printf("Event %i EmptyBxEvt %i emptyBxTrailer %i diff %i \n",eventCnt_,emptyBxEvt_,emptyBxTrailer_,(emptyBxEvt_ - eventCnt_));
617 
618  // Fill Muons
619  for (int iMu = 0; iMu < int(muonVec_bxm2.size()); iMu++) {
620  muons->push_back(-2, muonVec_bxm2[iMu]);
621  }
622  for (int iMu = 0; iMu < int(muonVec_bxm1.size()); iMu++) {
623  muons->push_back(-1, muonVec_bxm1[iMu]);
624  }
625  for (int iMu = 0; iMu < int(muonVec_bx0.size()); iMu++) {
626  muons->push_back(0, muonVec_bx0[iMu]);
627  }
628  for (int iMu = 0; iMu < int(muonVec_bxp1.size()); iMu++) {
629  muons->push_back(1, muonVec_bxp1[iMu]);
630  }
631  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
632  for (int iMu = 0; iMu < int(muonVec.size()); iMu++) {
633  muons->push_back(2, muonVec[iMu]);
634  }
635  } else {
636  // this event is part of empty trailer...clear out data
637  muonVec.clear();
638  }
639 
640  // Fill Egammas
641  for (int iEG = 0; iEG < int(egammaVec_bxm2.size()); iEG++) {
642  egammas->push_back(-2, egammaVec_bxm2[iEG]);
643  }
644  for (int iEG = 0; iEG < int(egammaVec_bxm1.size()); iEG++) {
645  egammas->push_back(-1, egammaVec_bxm1[iEG]);
646  }
647  for (int iEG = 0; iEG < int(egammaVec_bx0.size()); iEG++) {
648  egammas->push_back(0, egammaVec_bx0[iEG]);
649  }
650  for (int iEG = 0; iEG < int(egammaVec_bxp1.size()); iEG++) {
651  egammas->push_back(1, egammaVec_bxp1[iEG]);
652  }
653  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
654  for (int iEG = 0; iEG < int(egammaVec.size()); iEG++) {
655  egammas->push_back(2, egammaVec[iEG]);
656  }
657  } else {
658  // this event is part of empty trailer...clear out data
659  egammaVec.clear();
660  }
661 
662  // Fill Taus
663  for (int iTau = 0; iTau < int(tauVec_bxm2.size()); iTau++) {
664  taus->push_back(-2, tauVec_bxm2[iTau]);
665  }
666  for (int iTau = 0; iTau < int(tauVec_bxm1.size()); iTau++) {
667  taus->push_back(-1, tauVec_bxm1[iTau]);
668  }
669  for (int iTau = 0; iTau < int(tauVec_bx0.size()); iTau++) {
670  taus->push_back(0, tauVec_bx0[iTau]);
671  }
672  for (int iTau = 0; iTau < int(tauVec_bxp1.size()); iTau++) {
673  taus->push_back(1, tauVec_bxp1[iTau]);
674  }
675  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
676  for (int iTau = 0; iTau < int(tauVec.size()); iTau++) {
677  taus->push_back(2, tauVec[iTau]);
678  }
679  } else {
680  // this event is part of empty trailer...clear out data
681  tauVec.clear();
682  }
683 
684  // Fill Jets
685  for (int iJet = 0; iJet < int(jetVec_bxm2.size()); iJet++) {
686  jets->push_back(-2, jetVec_bxm2[iJet]);
687  }
688  for (int iJet = 0; iJet < int(jetVec_bxm1.size()); iJet++) {
689  jets->push_back(-1, jetVec_bxm1[iJet]);
690  }
691  for (int iJet = 0; iJet < int(jetVec_bx0.size()); iJet++) {
692  jets->push_back(0, jetVec_bx0[iJet]);
693  }
694  for (int iJet = 0; iJet < int(jetVec_bxp1.size()); iJet++) {
695  jets->push_back(1, jetVec_bxp1[iJet]);
696  }
697  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
698  for (int iJet = 0; iJet < int(jetVec.size()); iJet++) {
699  jets->push_back(2, jetVec[iJet]);
700  }
701  } else {
702  // this event is part of empty trailer...clear out data
703  jetVec.clear();
704  }
705 
706  // Fill Etsums
707  for (int iETsum = 0; iETsum < int(etsumVec_bxm2.size()); iETsum++) {
708  etsums->push_back(-2, etsumVec_bxm2[iETsum]);
709  }
710  for (int iETsum = 0; iETsum < int(etsumVec_bxm1.size()); iETsum++) {
711  etsums->push_back(-1, etsumVec_bxm1[iETsum]);
712  }
713  for (int iETsum = 0; iETsum < int(etsumVec_bx0.size()); iETsum++) {
714  etsums->push_back(0, etsumVec_bx0[iETsum]);
715  }
716  for (int iETsum = 0; iETsum < int(etsumVec_bxp1.size()); iETsum++) {
717  etsums->push_back(1, etsumVec_bxp1[iETsum]);
718  }
719  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
720  for (int iETsum = 0; iETsum < int(etsumVec.size()); iETsum++) {
721  etsums->push_back(2, etsumVec[iETsum]);
722  }
723  } else {
724  // this event is part of empty trailer...clear out data
725  etsumVec.clear();
726  }
727 
728  // Fill Externals
729  extCond->push_back(-2, extCond_bxm2);
730  extCond->push_back(-1, extCond_bxm1);
731  extCond->push_back(0, extCond_bx0);
732  extCond->push_back(1, extCond_bxp1);
733  if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
734  extCond->push_back(2, extCond_bx);
735  } else {
736  // this event is part of the empty trailer...clear out data
737  extCond_bx.reset();
738  }
739 
740  iEvent.put(std::move(egammas));
741  iEvent.put(std::move(muons));
742  iEvent.put(std::move(taus));
743  iEvent.put(std::move(jets));
744  iEvent.put(std::move(etsums));
745  iEvent.put(std::move(extCond));
746 
747  // Now shift the bx data by one to prepare for next event.
748  muonVec_bxm2 = muonVec_bxm1;
749  egammaVec_bxm2 = egammaVec_bxm1;
750  tauVec_bxm2 = tauVec_bxm1;
751  jetVec_bxm2 = jetVec_bxm1;
752  etsumVec_bxm2 = etsumVec_bxm1;
753  extCond_bxm2 = extCond_bxm1;
754 
755  muonVec_bxm1 = muonVec_bx0;
756  egammaVec_bxm1 = egammaVec_bx0;
757  tauVec_bxm1 = tauVec_bx0;
758  jetVec_bxm1 = jetVec_bx0;
759  etsumVec_bxm1 = etsumVec_bx0;
760  extCond_bxm1 = extCond_bx0;
761 
762  muonVec_bx0 = muonVec_bxp1;
763  egammaVec_bx0 = egammaVec_bxp1;
764  tauVec_bx0 = tauVec_bxp1;
765  jetVec_bx0 = jetVec_bxp1;
766  etsumVec_bx0 = etsumVec_bxp1;
767  extCond_bx0 = extCond_bxp1;
768 
769  muonVec_bxp1 = muonVec;
770  egammaVec_bxp1 = egammaVec;
771  tauVec_bxp1 = tauVec;
772  jetVec_bxp1 = jetVec;
773  etsumVec_bxp1 = etsumVec;
774  extCond_bxp1 = extCond_bx;
775  }
776 
777  // ------------ method called once each job just before starting event loop ------------
779 
780  // ------------ method called once each job just after ending the event loop ------------
781  void GenToInputProducer::endJob() {}
782 
783  // ------------ method called when starting to processes a run ------------
784 
785  void GenToInputProducer::beginRun(Run const& iR, EventSetup const& iE) {
786  LogDebug("GtGenToInputProducer") << "GenToInputProducer::beginRun function called...\n";
787 
788  counter_ = 0;
789  srand(0);
790 
791  gRandom = new TRandom3();
792  }
793 
794  // ------------ method called when ending the processing of a run ------------
795  void GenToInputProducer::endRun(Run const& iR, EventSetup const& iE) {}
796 
797  // ------------ methods to convert from physical to HW values ------------
798  int GenToInputProducer::convertPhiToHW(double iphi, int steps) {
799  double phiMax = 2 * M_PI;
800  if (iphi < 0)
801  iphi += 2 * M_PI;
802  if (iphi > phiMax)
803  iphi -= phiMax;
804 
805  int hwPhi = int((iphi / phiMax) * steps + 0.00001);
806  return hwPhi;
807  }
808 
809  int GenToInputProducer::convertEtaToHW(double ieta, double minEta, double maxEta, int steps) {
810  double binWidth = (maxEta - minEta) / steps;
811 
812  //if we are outside the limits, set error
813  if (ieta < minEta)
814  return 99999; //ieta = minEta+binWidth/2.;
815  if (ieta > maxEta)
816  return 99999; //ieta = maxEta-binWidth/2.;
817 
818  int binNum = (int)(ieta / binWidth);
819  if (ieta < 0.)
820  binNum--;
821 
822  // unsigned int hwEta = binNum & bitMask;
823  // Remove masking for BXVectors...only assume in raw data
824 
825  return binNum;
826  }
827 
828  int GenToInputProducer::convertPtToHW(double ipt, int maxPt, double step) {
829  int hwPt = int(ipt / step + 0.0001);
830  // if above max Pt, set to largest value
831  if (hwPt > maxPt)
832  hwPt = maxPt;
833 
834  return hwPt;
835  }
836 
837  // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
839  //The following says we do not know what parameters are allowed so do no validation
840  // Please change this to state exactly what you do use, even if it is no parameters
842  desc.setUnknown();
843  descriptions.addDefault(desc);
844  }
845 
846 } // namespace l1t
847 
848 //define this as a plug-in
EventNumber_t event() const
Definition: EventID.h:40
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
Definition: GlobalExtBlk.h:29
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< l1t::EtSum > etsumVec_bxm1
void reset()
reset the content of a GlobalExtBlk
Definition: GlobalExtBlk.cc:58
std::vector< l1t::Muon > muonVec_bxm1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< l1t::EtSum > etsumVec_bx0
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< l1t::Muon > muonVec_bxp1
virtual int status() const =0
status word
Definition: Tau.h:20
std::vector< l1t::Tau > tauVec_bx0
std::vector< l1t::Tau > tauVec_bxp1
std::vector< l1t::Tau > tauVec_bxm2
list status
Definition: mps_update.py:107
std::vector< l1t::Muon > muonVec_bxm2
std::vector< l1t::EtSum > etsumVec_bxp1
double maxEta
tuple isoSum
===&gt; require is not the leading lepton and opposite to the leading lepton
#define LogTrace(id)
void beginJob()
Definition: Breakpoints.cc:14
std::vector< l1t::EGamma > egammaVec_bxm1
Definition: Jet.h:20
int iEvent
Definition: GenABIO.cc:224
unsigned long long m_paramsCacheId
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< l1t::EGamma > egammaVec_bxm2
std::vector< l1t::EGamma > egammaVec_bxp1
edm::EDGetTokenT< reco::GenJetCollection > genJetsToken
std::vector< l1t::Muon > muonVec_bx0
vector< PseudoJet > jets
std::vector< l1t::Tau > tauVec_bxm1
std::vector< l1t::Jet > jetVec_bxm1
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual int charge() const =0
electric charge
const int mu
Definition: Constants.h:22
std::vector< l1t::Jet > jetVec_bxp1
std::vector< l1t::EGamma > egammaVec_bx0
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
Definition: GlobalExtBlk.cc:40
Definition: Muon.h:21
virtual int pdgId() const =0
PDG identifier.
#define M_PI
#define debug
Definition: HDRShower.cc:19
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
edm::EDGetTokenT< reco::GenMETCollection > genMetToken
edm::EventID id() const
Definition: EventBase.h:59
tuple muons
Definition: patZpeak.py:41
static unsigned int const shift
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken
step
Definition: StallMonitor.cc:98
std::vector< l1t::Jet > jetVec_bxm2
std::vector< l1t::EtSum > etsumVec_bxm2
std::vector< l1t::Jet > jetVec_bx0
Definition: Run.h:45
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
#define LogDebug(id)