50 #define M_PI 3.14159265358979323846
69 void endJob()
override;
73 int convertPhiToHW(
double iphi,
int steps);
75 int convertPtToHW(
double ipt,
int maxPt,
double step);
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>();
158 maxNumMuCands_ = iConfig.
getParameter<
int>(
"maxMuCand");
159 maxNumJetCands_ = iConfig.
getParameter<
int>(
"maxJetCand");
160 maxNumEGCands_ = iConfig.
getParameter<
int>(
"maxEGCand");
161 maxNumTauCands_ = iConfig.
getParameter<
int>(
"maxTauCand");
163 jetEtThreshold_ = iConfig.
getParameter<
double>(
"jetEtThreshold");
164 tauEtThreshold_ = iConfig.
getParameter<
double>(
"tauEtThreshold");
165 egEtThreshold_ = iConfig.
getParameter<
double>(
"egEtThreshold");
166 muEtThreshold_ = iConfig.
getParameter<
double>(
"muEtThreshold");
168 emptyBxTrailer_ = iConfig.
getParameter<
int>(
"emptyBxTrailer");
171 genParticlesToken = consumes<reco::GenParticleCollection>(
std::string(
"genParticles"));
172 genJetsToken = consumes<reco::GenJetCollection>(
std::string(
"ak4GenJets"));
173 genMetToken = consumes<reco::GenMETCollection>(
std::string(
"genMetCalo"));
180 GenToInputProducer::~GenToInputProducer() {}
190 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::produce function called...\n";
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;
205 double MaxLepPt_ = 255;
206 double MaxJetPt_ = 1023;
207 double MaxEt_ = 2047;
209 double MaxCaloEta_ = 5.0;
210 double MaxMuonEta_ = 2.45;
212 double PhiStepCalo_ = 144;
213 double PhiStepMuon_ = 576;
216 double EtaStepCalo_ = 230;
217 double EtaStepMuon_ = 450;
220 double PtStep_ = 0.5;
230 std::vector<int> mu_cands_index;
231 std::vector<int> eg_cands_index;
232 std::vector<int> tau_cands_index;
241 double pt = mcParticle.
pt();
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);
257 LogTrace(
"GtGenToInputProducer") <<
">>> GenParticles collection not found!" << std::endl;
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();
267 TMath::Sort(numMuCands, muPtSorted, idxMu);
268 for (
int iMu = 0; iMu < numMuCands; iMu++) {
269 if (iMu >= maxNumMuCands_)
272 const reco::Candidate& mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
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);
278 int iso = gRandom->Integer(4) % 2;
288 int hwEtaAtVtx =
eta;
289 int hwPhiAtVtx = phi;
295 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>*
p4 =
296 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
315 muonVec.push_back(
mu);
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();
325 TMath::Sort(numEgCands, egPtSorted, idxEg);
326 for (
int iEg = 0; iEg < numEgCands; iEg++) {
327 if (iEg >= maxNumEGCands_)
330 const reco::Candidate& mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
332 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
333 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
334 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
336 int iso = gRandom->Integer(4) % 2;
342 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>*
p4 =
343 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
346 egammaVec.push_back(eg);
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();
356 TMath::Sort(numTauCands, tauPtSorted, idxTau);
357 for (
int iTau = 0; iTau < numTauCands; iTau++) {
358 if (iTau >= maxNumTauCands_)
361 const reco::Candidate& mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
363 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
364 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
365 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
367 int iso = gRandom->Integer(4) % 2;
373 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>*
p4 =
374 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
377 tauVec.push_back(
tau);
382 int maxOtherTaus = 8;
383 int numCurrentEGs =
int(egammaVec.size());
384 int numCurrentTaus =
int(tauVec.size());
386 int numExtraEGs = 0, numExtraTaus = 0;
397 for (reco::GenJetCollection::const_iterator genJet =
genJets->begin(); genJet !=
genJets->end(); ++genJet) {
399 sumEt += genJet->et();
402 if (genJet->pt() < jetEtThreshold_)
406 if (nJet >= maxNumJetCands_)
408 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>*
p4 =
409 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
411 int pt = convertPtToHW(genJet->et(), MaxJetPt_, PtStep_);
412 int eta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
413 int phi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
422 jetVec.push_back(
jet);
427 if ((numExtraEGs + numCurrentEGs) < maxNumEGCands_ && numExtraEGs < maxOtherEGs) {
430 int EGpt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
431 int EGeta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
432 int EGphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
435 int EGiso = gRandom->Integer(4) % 2;
438 egammaVec.push_back(eg);
441 if ((numExtraTaus + numCurrentTaus) < maxNumTauCands_ && numExtraTaus < maxOtherTaus) {
444 int Taupt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
445 int Taueta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
446 int Tauphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
448 int Tauiso = gRandom->Integer(4) % 2;
451 tauVec.push_back(
tau);
456 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
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>>();
466 pt = convertPtToHW(
sumEt * 0.6, 2047, PtStep_);
470 int nTowers = 4095 * gRandom->Rndm();
474 int nAsymEt = 255 * gRandom->Rndm();
476 int nAsymHt = 255 * gRandom->Rndm();
478 int nAsymEtHF = 255 * gRandom->Rndm();
480 int nAsymHtHF = 255 * gRandom->Rndm();
483 pt = convertPtToHW(
sumEt * 0.9, 2047, PtStep_);
487 int hfP0val = gRandom->Poisson(4.);
492 int hfM0val = gRandom->Poisson(4.);
497 int hfP1val = gRandom->Poisson(4.);
502 int hfM1val = gRandom->Poisson(4.);
508 int cent30val(0), cent74val(0);
509 int centa = gRandom->Poisson(2.);
510 int centb = gRandom->Poisson(2.);
511 if (centa >= centb) {
526 centralval |= cent30val & 0xF;
527 centralval |= (cent74val & 0xF) <<
shift;
543 mpt = convertPtToHW(
genMet->front().pt(), MaxEt_, PtStep_);
544 mphi = convertPhiToHW(
genMet->front().phi(), PhiStepCalo_);
547 mptHf = convertPtToHW(
genMet->front().pt() * 1.1, MaxEt_, PtStep_);
548 mphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 7., PhiStepCalo_);
551 mhpt = convertPtToHW(
genMet->front().pt() * 0.9, MaxEt_, PtStep_);
552 mhphi = convertPhiToHW(
genMet->front().phi() + 3.14 / 5., PhiStepCalo_);
555 mhptHf = convertPtToHW(
genMet->front().pt() * 0.95, MaxEt_, PtStep_);
556 mhphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 6., PhiStepCalo_);
558 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
568 etsumVec.push_back(etTotal);
569 etsumVec.push_back(etEmTotal);
570 etsumVec.push_back(hfP0);
572 etsumVec.push_back(htTotal);
573 etsumVec.push_back(towerCounts);
574 etsumVec.push_back(hfM0);
576 etsumVec.push_back(etmiss);
577 etsumVec.push_back(AsymEt);
578 etsumVec.push_back(hfP1);
580 etsumVec.push_back(htmiss);
581 etsumVec.push_back(AsymHt);
582 etsumVec.push_back(hfM1);
584 etsumVec.push_back(etmissHF);
585 etsumVec.push_back(AsymEtHF);
587 etsumVec.push_back(htmissHF);
588 etsumVec.push_back(AsymHtHF);
589 etsumVec.push_back(centrality);
592 if ((
iEvent.id().event()) % 2 == 0) {
593 for (
int i = 0;
i < 255;
i =
i + 2)
596 for (
int i = 1;
i < 255;
i =
i + 2)
604 for (
int iMu = 0; iMu <
int(muonVec_bxm2.size()); iMu++) {
605 muons->push_back(-2, muonVec_bxm2[iMu]);
607 for (
int iMu = 0; iMu <
int(muonVec_bxm1.size()); iMu++) {
608 muons->push_back(-1, muonVec_bxm1[iMu]);
610 for (
int iMu = 0; iMu <
int(muonVec_bx0.size()); iMu++) {
611 muons->push_back(0, muonVec_bx0[iMu]);
613 for (
int iMu = 0; iMu <
int(muonVec_bxp1.size()); iMu++) {
614 muons->push_back(1, muonVec_bxp1[iMu]);
616 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
617 for (
int iMu = 0; iMu <
int(muonVec.size()); iMu++) {
618 muons->push_back(2, muonVec[iMu]);
626 for (
int iEG = 0; iEG <
int(egammaVec_bxm2.size()); iEG++) {
627 egammas->push_back(-2, egammaVec_bxm2[iEG]);
629 for (
int iEG = 0; iEG <
int(egammaVec_bxm1.size()); iEG++) {
630 egammas->push_back(-1, egammaVec_bxm1[iEG]);
632 for (
int iEG = 0; iEG <
int(egammaVec_bx0.size()); iEG++) {
633 egammas->push_back(0, egammaVec_bx0[iEG]);
635 for (
int iEG = 0; iEG <
int(egammaVec_bxp1.size()); iEG++) {
636 egammas->push_back(1, egammaVec_bxp1[iEG]);
638 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
639 for (
int iEG = 0; iEG <
int(egammaVec.size()); iEG++) {
640 egammas->push_back(2, egammaVec[iEG]);
648 for (
int iTau = 0; iTau <
int(tauVec_bxm2.size()); iTau++) {
649 taus->push_back(-2, tauVec_bxm2[iTau]);
651 for (
int iTau = 0; iTau <
int(tauVec_bxm1.size()); iTau++) {
652 taus->push_back(-1, tauVec_bxm1[iTau]);
654 for (
int iTau = 0; iTau <
int(tauVec_bx0.size()); iTau++) {
655 taus->push_back(0, tauVec_bx0[iTau]);
657 for (
int iTau = 0; iTau <
int(tauVec_bxp1.size()); iTau++) {
658 taus->push_back(1, tauVec_bxp1[iTau]);
660 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
661 for (
int iTau = 0; iTau <
int(tauVec.size()); iTau++) {
662 taus->push_back(2, tauVec[iTau]);
670 for (
int iJet = 0; iJet <
int(jetVec_bxm2.size()); iJet++) {
671 jets->push_back(-2, jetVec_bxm2[iJet]);
673 for (
int iJet = 0; iJet <
int(jetVec_bxm1.size()); iJet++) {
674 jets->push_back(-1, jetVec_bxm1[iJet]);
676 for (
int iJet = 0; iJet <
int(jetVec_bx0.size()); iJet++) {
677 jets->push_back(0, jetVec_bx0[iJet]);
679 for (
int iJet = 0; iJet <
int(jetVec_bxp1.size()); iJet++) {
680 jets->push_back(1, jetVec_bxp1[iJet]);
682 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
683 for (
int iJet = 0; iJet <
int(jetVec.size()); iJet++) {
684 jets->push_back(2, jetVec[iJet]);
692 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm2.size()); iETsum++) {
693 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
695 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm1.size()); iETsum++) {
696 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
698 for (
int iETsum = 0; iETsum <
int(etsumVec_bx0.size()); iETsum++) {
699 etsums->push_back(0, etsumVec_bx0[iETsum]);
701 for (
int iETsum = 0; iETsum <
int(etsumVec_bxp1.size()); iETsum++) {
702 etsums->push_back(1, etsumVec_bxp1[iETsum]);
704 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
705 for (
int iETsum = 0; iETsum <
int(etsumVec.size()); iETsum++) {
706 etsums->push_back(2, etsumVec[iETsum]);
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);
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;
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;
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;
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;
766 void GenToInputProducer::endJob() {}
771 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
776 gRandom =
new TRandom3();
783 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps) {
803 int binNum = (
int)(
ieta / binWidth);
813 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step) {
814 int hwPt =
int(ipt /
step + 0.0001);