CMS 3D CMS Logo

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