54 #define M_PI 3.14159265358979323846
73 void endJob()
override;
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);
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>();
162 maxNumMuCands_ = iConfig.
getParameter<
int>(
"maxMuCand");
163 maxNumJetCands_ = iConfig.
getParameter<
int>(
"maxJetCand");
164 maxNumEGCands_ = iConfig.
getParameter<
int>(
"maxEGCand");
165 maxNumTauCands_ = iConfig.
getParameter<
int>(
"maxTauCand");
167 jetEtThreshold_ = iConfig.
getParameter<
double>(
"jetEtThreshold");
168 tauEtThreshold_ = iConfig.
getParameter<
double>(
"tauEtThreshold");
169 egEtThreshold_ = iConfig.
getParameter<
double>(
"egEtThreshold");
170 muEtThreshold_ = iConfig.
getParameter<
double>(
"muEtThreshold");
172 emptyBxTrailer_ = iConfig.
getParameter<
int>(
"emptyBxTrailer");
175 genParticlesToken = consumes<reco::GenParticleCollection>(
std::string(
"genParticles"));
176 genJetsToken = consumes<reco::GenJetCollection>(
std::string(
"ak4GenJets"));
177 genMetToken = consumes<reco::GenMETCollection>(
std::string(
"genMetCalo"));
184 GenToInputProducer::~GenToInputProducer() {}
194 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::produce function called...\n";
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;
205 int bxFirst = bxFirst_;
206 int bxLast = bxLast_;
209 double MaxLepPt_ = 255;
210 double MaxJetPt_ = 1023;
211 double MaxEt_ = 2047;
213 double MaxCaloEta_ = 5.0;
214 double MaxMuonEta_ = 2.45;
216 double PhiStepCalo_ = 144;
217 double PhiStepMuon_ = 576;
220 double EtaStepCalo_ = 230;
221 double EtaStepMuon_ = 450;
224 double PtStep_ = 0.5;
234 std::vector<int> mu_cands_index;
235 std::vector<int> eg_cands_index;
236 std::vector<int> tau_cands_index;
239 if (iEvent.
getByToken(genParticlesToken, genParticles)) {
240 for (
size_t k = 0;
k < genParticles->size();
k++) {
244 int pdgId = mcParticle.
pdgId();
245 double pt = mcParticle.
pt();
248 if (status != 1 && !(
abs(pdgId) == 15 && status == 2))
251 int absId =
abs(pdgId);
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);
261 LogTrace(
"GtGenToInputProducer") <<
">>> GenParticles collection not found!" << std::endl;
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();
271 TMath::Sort(numMuCands, muPtSorted, idxMu);
272 for (
int iMu = 0; iMu < numMuCands; iMu++) {
273 if (iMu >= maxNumMuCands_)
276 const reco::Candidate& mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
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);
282 int iso = gRandom->Integer(4) % 2;
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;
298 double ptUnconstrained = 0.0;
299 int dXY = gRandom->Integer(4);
305 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
306 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
330 muonVec.push_back(mu);
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();
340 TMath::Sort(numEgCands, egPtSorted, idxEg);
341 for (
int iEg = 0; iEg < numEgCands; iEg++) {
342 if (iEg >= maxNumEGCands_)
345 const reco::Candidate& mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
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);
351 int iso = gRandom->Integer(4) % 2;
357 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
358 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
361 egammaVec.push_back(eg);
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();
371 TMath::Sort(numTauCands, tauPtSorted, idxTau);
372 for (
int iTau = 0; iTau < numTauCands; iTau++) {
373 if (iTau >= maxNumTauCands_)
376 const reco::Candidate& mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
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);
382 int iso = gRandom->Integer(4) % 2;
388 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
389 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
392 tauVec.push_back(tau);
397 int maxOtherTaus = 8;
398 int numCurrentEGs = int(egammaVec.size());
399 int numCurrentTaus = int(tauVec.size());
401 int numExtraEGs = 0, numExtraTaus = 0;
411 if (iEvent.
getByToken(genJetsToken, genJets)) {
412 for (reco::GenJetCollection::const_iterator genJet = genJets->begin(); genJet != genJets->end(); ++genJet) {
414 sumEt += genJet->et();
417 if (genJet->pt() < jetEtThreshold_)
421 if (nJet >= maxNumJetCands_)
423 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
424 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
426 int pt = convertPtToHW(genJet->et(), MaxJetPt_, PtStep_);
427 int eta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
428 int phi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
434 int qual = gRandom->Integer(2);
437 jetVec.push_back(jet);
442 if ((numExtraEGs + numCurrentEGs) < maxNumEGCands_ && numExtraEGs < maxOtherEGs) {
445 int EGpt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
446 int EGeta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
447 int EGphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
449 int EGqual = gRandom->Integer(2);
450 int EGiso = gRandom->Integer(4) % 2;
452 l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
453 egammaVec.push_back(eg);
456 if ((numExtraTaus + numCurrentTaus) < maxNumTauCands_ && numExtraTaus < maxOtherTaus) {
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);
463 int Tauiso = gRandom->Integer(4) % 2;
465 l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
466 tauVec.push_back(tau);
471 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
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>>();
481 pt = convertPtToHW(sumEt * 0.6, 2047, PtStep_);
485 int nTowers = 4095 * gRandom->Rndm();
489 int nAsymEt = 255 * gRandom->Rndm();
491 int nAsymHt = 255 * gRandom->Rndm();
493 int nAsymEtHF = 255 * gRandom->Rndm();
495 int nAsymHtHF = 255 * gRandom->Rndm();
498 pt = convertPtToHW(sumEt * 0.9, 2047, PtStep_);
502 int hfP0val = gRandom->Poisson(4.);
507 int hfM0val = gRandom->Poisson(4.);
512 int hfP1val = gRandom->Poisson(4.);
517 int hfM1val = gRandom->Poisson(4.);
523 int cent30val(0), cent74val(0);
524 int centa = gRandom->Poisson(2.);
525 int centb = gRandom->Poisson(2.);
526 if (centa >= centb) {
541 centralval |= cent30val & 0xF;
542 centralval |= (cent74val & 0xF) << shift;
558 mpt = convertPtToHW(genMet->front().pt(), MaxEt_, PtStep_);
559 mphi = convertPhiToHW(genMet->front().phi(), PhiStepCalo_);
562 mptHf = convertPtToHW(genMet->front().pt() * 1.1, MaxEt_, PtStep_);
563 mphiHf = convertPhiToHW(genMet->front().phi() + 3.14 / 7., PhiStepCalo_);
566 mhpt = convertPtToHW(genMet->front().pt() * 0.9, MaxEt_, PtStep_);
567 mhphi = convertPhiToHW(genMet->front().phi() + 3.14 / 5., PhiStepCalo_);
570 mhptHf = convertPtToHW(genMet->front().pt() * 0.95, MaxEt_, PtStep_);
571 mhphiHf = convertPhiToHW(genMet->front().phi() + 3.14 / 6., PhiStepCalo_);
573 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
583 etsumVec.push_back(etTotal);
584 etsumVec.push_back(etEmTotal);
585 etsumVec.push_back(hfP0);
587 etsumVec.push_back(htTotal);
588 etsumVec.push_back(towerCounts);
589 etsumVec.push_back(hfM0);
591 etsumVec.push_back(etmiss);
592 etsumVec.push_back(AsymEt);
593 etsumVec.push_back(hfP1);
595 etsumVec.push_back(htmiss);
596 etsumVec.push_back(AsymHt);
597 etsumVec.push_back(hfM1);
599 etsumVec.push_back(etmissHF);
600 etsumVec.push_back(AsymEtHF);
602 etsumVec.push_back(htmissHF);
603 etsumVec.push_back(AsymHtHF);
604 etsumVec.push_back(centrality);
607 if ((iEvent.
id().
event()) % 2 == 0) {
608 for (
int i = 0;
i < 255;
i =
i + 2)
611 for (
int i = 1;
i < 255;
i =
i + 2)
619 for (
int iMu = 0; iMu < int(muonVec_bxm2.size()); iMu++) {
620 muons->push_back(-2, muonVec_bxm2[iMu]);
622 for (
int iMu = 0; iMu < int(muonVec_bxm1.size()); iMu++) {
623 muons->push_back(-1, muonVec_bxm1[iMu]);
625 for (
int iMu = 0; iMu < int(muonVec_bx0.size()); iMu++) {
626 muons->push_back(0, muonVec_bx0[iMu]);
628 for (
int iMu = 0; iMu < int(muonVec_bxp1.size()); iMu++) {
629 muons->push_back(1, muonVec_bxp1[iMu]);
631 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
632 for (
int iMu = 0; iMu < int(muonVec.size()); iMu++) {
633 muons->push_back(2, muonVec[iMu]);
641 for (
int iEG = 0; iEG < int(egammaVec_bxm2.size()); iEG++) {
642 egammas->push_back(-2, egammaVec_bxm2[iEG]);
644 for (
int iEG = 0; iEG < int(egammaVec_bxm1.size()); iEG++) {
645 egammas->push_back(-1, egammaVec_bxm1[iEG]);
647 for (
int iEG = 0; iEG < int(egammaVec_bx0.size()); iEG++) {
648 egammas->push_back(0, egammaVec_bx0[iEG]);
650 for (
int iEG = 0; iEG < int(egammaVec_bxp1.size()); iEG++) {
651 egammas->push_back(1, egammaVec_bxp1[iEG]);
653 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
654 for (
int iEG = 0; iEG < int(egammaVec.size()); iEG++) {
655 egammas->push_back(2, egammaVec[iEG]);
663 for (
int iTau = 0; iTau < int(tauVec_bxm2.size()); iTau++) {
664 taus->push_back(-2, tauVec_bxm2[iTau]);
666 for (
int iTau = 0; iTau < int(tauVec_bxm1.size()); iTau++) {
667 taus->push_back(-1, tauVec_bxm1[iTau]);
669 for (
int iTau = 0; iTau < int(tauVec_bx0.size()); iTau++) {
670 taus->push_back(0, tauVec_bx0[iTau]);
672 for (
int iTau = 0; iTau < int(tauVec_bxp1.size()); iTau++) {
673 taus->push_back(1, tauVec_bxp1[iTau]);
675 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
676 for (
int iTau = 0; iTau < int(tauVec.size()); iTau++) {
677 taus->push_back(2, tauVec[iTau]);
685 for (
int iJet = 0; iJet < int(jetVec_bxm2.size()); iJet++) {
686 jets->push_back(-2, jetVec_bxm2[iJet]);
688 for (
int iJet = 0; iJet < int(jetVec_bxm1.size()); iJet++) {
689 jets->push_back(-1, jetVec_bxm1[iJet]);
691 for (
int iJet = 0; iJet < int(jetVec_bx0.size()); iJet++) {
692 jets->push_back(0, jetVec_bx0[iJet]);
694 for (
int iJet = 0; iJet < int(jetVec_bxp1.size()); iJet++) {
695 jets->push_back(1, jetVec_bxp1[iJet]);
697 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
698 for (
int iJet = 0; iJet < int(jetVec.size()); iJet++) {
699 jets->push_back(2, jetVec[iJet]);
707 for (
int iETsum = 0; iETsum < int(etsumVec_bxm2.size()); iETsum++) {
708 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
710 for (
int iETsum = 0; iETsum < int(etsumVec_bxm1.size()); iETsum++) {
711 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
713 for (
int iETsum = 0; iETsum < int(etsumVec_bx0.size()); iETsum++) {
714 etsums->push_back(0, etsumVec_bx0[iETsum]);
716 for (
int iETsum = 0; iETsum < int(etsumVec_bxp1.size()); iETsum++) {
717 etsums->push_back(1, etsumVec_bxp1[iETsum]);
719 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
720 for (
int iETsum = 0; iETsum < int(etsumVec.size()); iETsum++) {
721 etsums->push_back(2, etsumVec[iETsum]);
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);
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;
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;
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;
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;
781 void GenToInputProducer::endJob() {}
786 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
791 gRandom =
new TRandom3();
798 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps) {
805 int hwPhi = int((iphi / phiMax) * steps + 0.00001);
809 int GenToInputProducer::convertEtaToHW(
double ieta,
double minEta,
double maxEta,
int steps) {
810 double binWidth = (maxEta - minEta) / steps;
818 int binNum = (int)(ieta / binWidth);
828 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step) {
829 int hwPt = int(ipt / step + 0.0001);
EventNumber_t event() const
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void reset()
reset the content of a GlobalExtBlk
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
virtual int status() const =0
status word
tuple isoSum
===> require is not the leading lepton and opposite to the leading lepton
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
virtual int charge() const =0
electric charge
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
virtual int pdgId() const =0
PDG identifier.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
static unsigned int const shift
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity