CMS 3D CMS Logo

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