55 #define M_PI 3.14159265358979323846 74 void endJob()
override;
78 int convertPhiToHW(
double iphi,
int steps);
80 int convertPtToHW(
double ipt,
int maxPt,
double step);
157 produces<BXVector<l1t::EGamma>>();
158 produces<BXVector<l1t::Muon>>();
159 produces<BXVector<l1t::MuonShower>>();
160 produces<BXVector<l1t::Tau>>();
161 produces<BXVector<l1t::Jet>>();
162 produces<BXVector<l1t::EtSum>>();
163 produces<GlobalExtBlkBxCollection>();
169 maxNumMuCands_ = iConfig.
getParameter<
int>(
"maxMuCand");
170 maxNumMuShowerCands_ = iConfig.
getParameter<
int>(
"maxMuShowerCand");
171 maxNumJetCands_ = iConfig.
getParameter<
int>(
"maxJetCand");
172 maxNumEGCands_ = iConfig.
getParameter<
int>(
"maxEGCand");
173 maxNumTauCands_ = iConfig.
getParameter<
int>(
"maxTauCand");
175 jetEtThreshold_ = iConfig.
getParameter<
double>(
"jetEtThreshold");
176 tauEtThreshold_ = iConfig.
getParameter<
double>(
"tauEtThreshold");
177 egEtThreshold_ = iConfig.
getParameter<
double>(
"egEtThreshold");
178 muEtThreshold_ = iConfig.
getParameter<
double>(
"muEtThreshold");
180 emptyBxTrailer_ = iConfig.
getParameter<
int>(
"emptyBxTrailer");
183 genParticlesToken = consumes<reco::GenParticleCollection>(
std::string(
"genParticles"));
184 genJetsToken = consumes<reco::GenJetCollection>(
std::string(
"ak4GenJets"));
185 genMetToken = consumes<reco::GenMETCollection>(
std::string(
"genMetCalo"));
192 GenToInputProducer::~GenToInputProducer() {}
202 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::produce function called...\n";
205 std::vector<l1t::Muon> muonVec;
206 std::vector<l1t::MuonShower> muonShowerVec;
207 std::vector<l1t::EGamma> egammaVec;
208 std::vector<l1t::Tau> tauVec;
209 std::vector<l1t::Jet> jetVec;
210 std::vector<l1t::EtSum> etsumVec;
218 double MaxLepPt_ = 255;
219 double MaxJetPt_ = 1023;
220 double MaxEt_ = 2047;
222 double MaxCaloEta_ = 5.0;
223 double MaxMuonEta_ = 2.45;
225 double PhiStepCalo_ = 144;
226 double PhiStepMuon_ = 576;
229 double EtaStepCalo_ = 230;
230 double EtaStepMuon_ = 450;
233 double PtStep_ = 0.5;
244 std::vector<int> mu_cands_index;
245 std::vector<int> eg_cands_index;
246 std::vector<int> tau_cands_index;
255 double pt = mcParticle.
pt();
263 if (absId == 11 &&
pt >= egEtThreshold_)
264 eg_cands_index.push_back(
k);
265 else if (absId == 13 &&
pt >= muEtThreshold_)
266 mu_cands_index.push_back(
k);
267 else if (absId == 15 &&
pt >= tauEtThreshold_)
268 tau_cands_index.push_back(
k);
271 LogTrace(
"GtGenToInputProducer") <<
">>> GenParticles collection not found!" << std::endl;
276 bool mus0 = (
bool)mushowerRandom->Integer(2);
277 bool mus1 = (
bool)mushowerRandom->Integer(2);
278 bool mus2 = (
bool)mushowerRandom->Integer(2);
279 bool mus2Loose = (
bool)mushowerRandom->Integer(2);
280 bool musoot0 = (
bool)mushowerRandom->Integer(2);
281 bool musoot1 = (
bool)mushowerRandom->Integer(2);
282 bool musoot2Loose = (
bool)mushowerRandom->Integer(2);
284 cout <<
"GenToInputProducer MuonShower = (MUS0, MUS1, MUS2, MUSOOT0, MUSOOT1) = (" << mus0 <<
"," << mus1 <<
"," 285 << mus2 <<
"," << musoot0 <<
"," << musoot1 <<
")" << endl;
286 l1t::MuonShower muShower(mus0, musoot0, mus2Loose, musoot2Loose, mus1, musoot1, mus2);
289 muonShowerVec.push_back(muShower);
292 int numMuCands =
int(mu_cands_index.size());
293 Int_t idxMu[numMuCands];
294 double muPtSorted[numMuCands];
295 for (
int iMu = 0; iMu < numMuCands; iMu++)
296 muPtSorted[iMu] =
genParticles->at(mu_cands_index[iMu]).pt();
298 TMath::Sort(numMuCands, muPtSorted, idxMu);
299 for (
int iMu = 0; iMu < numMuCands; iMu++) {
300 if (iMu >= maxNumMuCands_)
303 const reco::Candidate& mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
305 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
306 int eta = convertEtaToHW(mcParticle.
eta(), -MaxMuonEta_, MaxMuonEta_, EtaStepMuon_);
307 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepMuon_);
308 int qual = gRandom->Integer(16);
309 int iso = gRandom->Integer(4) % 2;
324 convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_) / 2;
326 int dXY = gRandom->Integer(4);
332 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
333 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
357 muonVec.push_back(
mu);
361 int numEgCands =
int(eg_cands_index.size());
362 Int_t idxEg[numEgCands];
363 double egPtSorted[numEgCands];
364 for (
int iEg = 0; iEg < numEgCands; iEg++)
365 egPtSorted[iEg] =
genParticles->at(eg_cands_index[iEg]).pt();
367 TMath::Sort(numEgCands, egPtSorted, idxEg);
368 for (
int iEg = 0; iEg < numEgCands; iEg++) {
369 if (iEg >= maxNumEGCands_)
372 const reco::Candidate& mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
374 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
375 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
376 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
377 int qual = gRandom->Integer(2);
378 int iso = gRandom->Integer(4) % 2;
384 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
385 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
388 egammaVec.push_back(eg);
392 int numTauCands =
int(tau_cands_index.size());
393 Int_t idxTau[numTauCands];
394 double tauPtSorted[numTauCands];
395 for (
int iTau = 0; iTau < numTauCands; iTau++)
396 tauPtSorted[iTau] =
genParticles->at(tau_cands_index[iTau]).pt();
398 TMath::Sort(numTauCands, tauPtSorted, idxTau);
399 for (
int iTau = 0; iTau < numTauCands; iTau++) {
400 if (iTau >= maxNumTauCands_)
403 const reco::Candidate& mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
405 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
406 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
407 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
408 int qual = gRandom->Integer(2);
409 int iso = gRandom->Integer(4) % 2;
415 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
416 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
419 tauVec.push_back(
tau);
424 int maxOtherTaus = 8;
425 int numCurrentEGs =
int(egammaVec.size());
426 int numCurrentTaus =
int(tauVec.size());
428 int numExtraEGs = 0, numExtraTaus = 0;
439 for (reco::GenJetCollection::const_iterator genJet =
genJets->begin(); genJet !=
genJets->end(); ++genJet) {
441 sumEt += genJet->et();
444 if (genJet->pt() < jetEtThreshold_)
448 if (nJet >= maxNumJetCands_)
450 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
451 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
453 int pt = convertPtToHW(genJet->et(), MaxJetPt_, PtStep_);
454 int eta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
455 int phi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
461 int qual = gRandom->Integer(2);
464 jetVec.push_back(
jet);
469 if ((numExtraEGs + numCurrentEGs) < maxNumEGCands_ && numExtraEGs < maxOtherEGs) {
472 int EGpt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
473 int EGeta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
474 int EGphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
476 int EGqual = gRandom->Integer(2);
477 int EGiso = gRandom->Integer(4) % 2;
479 l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
480 egammaVec.push_back(eg);
483 if ((numExtraTaus + numCurrentTaus) < maxNumTauCands_ && numExtraTaus < maxOtherTaus) {
486 int Taupt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
487 int Taueta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
488 int Tauphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
489 int Tauqual = gRandom->Integer(2);
490 int Tauiso = gRandom->Integer(4) % 2;
492 l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
493 tauVec.push_back(
tau);
498 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
502 int pt = convertPtToHW(
sumEt, 2047, PtStep_);
503 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
504 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
508 pt = convertPtToHW(
sumEt * 0.6, 2047, PtStep_);
512 int nTowers = 4095 * gRandom->Rndm();
516 int nAsymEt = 255 * gRandom->Rndm();
518 int nAsymHt = 255 * gRandom->Rndm();
520 int nAsymEtHF = 255 * gRandom->Rndm();
522 int nAsymHtHF = 255 * gRandom->Rndm();
525 pt = convertPtToHW(
sumEt * 0.9, 2047, PtStep_);
529 int hfP0val = gRandom->Poisson(4.);
534 int hfM0val = gRandom->Poisson(4.);
539 int hfP1val = gRandom->Poisson(4.);
544 int hfM1val = gRandom->Poisson(4.);
550 int cent30val(0), cent74val(0);
551 int centa = gRandom->Poisson(2.);
552 int centb = gRandom->Poisson(2.);
553 if (centa >= centb) {
568 centralval |= cent30val & 0xF;
569 centralval |= (cent74val & 0xF) <<
shift;
585 mpt = convertPtToHW(
genMet->front().pt(), MaxEt_, PtStep_);
586 mphi = convertPhiToHW(
genMet->front().phi(), PhiStepCalo_);
589 mptHf = convertPtToHW(
genMet->front().pt() * 1.1, MaxEt_, PtStep_);
590 mphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 7., PhiStepCalo_);
593 mhpt = convertPtToHW(
genMet->front().pt() * 0.9, MaxEt_, PtStep_);
594 mhphi = convertPhiToHW(
genMet->front().phi() + 3.14 / 5., PhiStepCalo_);
597 mhptHf = convertPtToHW(
genMet->front().pt() * 0.95, MaxEt_, PtStep_);
598 mhphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 6., PhiStepCalo_);
600 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
610 etsumVec.push_back(etTotal);
611 etsumVec.push_back(etEmTotal);
612 etsumVec.push_back(hfP0);
614 etsumVec.push_back(htTotal);
615 etsumVec.push_back(towerCounts);
616 etsumVec.push_back(hfM0);
618 etsumVec.push_back(
etmiss);
619 etsumVec.push_back(AsymEt);
620 etsumVec.push_back(hfP1);
622 etsumVec.push_back(
htmiss);
623 etsumVec.push_back(AsymHt);
624 etsumVec.push_back(hfM1);
626 etsumVec.push_back(etmissHF);
627 etsumVec.push_back(AsymEtHF);
629 etsumVec.push_back(htmissHF);
630 etsumVec.push_back(AsymHtHF);
631 etsumVec.push_back(centrality);
634 if ((
iEvent.id().event()) % 2 == 0) {
635 for (
int i = 0;
i < 255;
i =
i + 2)
638 for (
int i = 1;
i < 255;
i =
i + 2)
646 for (
int iMu = 0; iMu <
int(muonVec_bxm2.size()); iMu++) {
647 muons->push_back(-2, muonVec_bxm2[iMu]);
649 for (
int iMu = 0; iMu <
int(muonVec_bxm1.size()); iMu++) {
650 muons->push_back(-1, muonVec_bxm1[iMu]);
652 for (
int iMu = 0; iMu <
int(muonVec_bx0.size()); iMu++) {
653 muons->push_back(0, muonVec_bx0[iMu]);
655 for (
int iMu = 0; iMu <
int(muonVec_bxp1.size()); iMu++) {
656 muons->push_back(1, muonVec_bxp1[iMu]);
658 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
659 for (
int iMu = 0; iMu <
int(muonVec.size()); iMu++) {
660 muons->push_back(2, muonVec[iMu]);
668 for (
int iMuShower = 0; iMuShower <
int(muonShowerVec_bxm2.size()); iMuShower++) {
669 muonShowers->push_back(-2, muonShowerVec_bxm2[iMuShower]);
671 for (
int iMuShower = 0; iMuShower <
int(muonShowerVec_bxm1.size()); iMuShower++) {
672 muonShowers->push_back(-1, muonShowerVec_bxm1[iMuShower]);
674 for (
int iMuShower = 0; iMuShower <
int(muonShowerVec_bx0.size()); iMuShower++) {
675 muonShowers->push_back(0, muonShowerVec_bx0[iMuShower]);
677 for (
int iMuShower = 0; iMuShower <
int(muonShowerVec_bxp1.size()); iMuShower++) {
678 muonShowers->push_back(1, muonShowerVec_bxp1[iMuShower]);
680 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
681 for (
int iMuShower = 0; iMuShower <
int(muonShowerVec.size()); iMuShower++) {
682 muonShowers->push_back(2, muonShowerVec[iMuShower]);
686 muonShowerVec.clear();
690 for (
int iEG = 0; iEG <
int(egammaVec_bxm2.size()); iEG++) {
691 egammas->push_back(-2, egammaVec_bxm2[iEG]);
693 for (
int iEG = 0; iEG <
int(egammaVec_bxm1.size()); iEG++) {
694 egammas->push_back(-1, egammaVec_bxm1[iEG]);
696 for (
int iEG = 0; iEG <
int(egammaVec_bx0.size()); iEG++) {
697 egammas->push_back(0, egammaVec_bx0[iEG]);
699 for (
int iEG = 0; iEG <
int(egammaVec_bxp1.size()); iEG++) {
700 egammas->push_back(1, egammaVec_bxp1[iEG]);
702 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
703 for (
int iEG = 0; iEG <
int(egammaVec.size()); iEG++) {
704 egammas->push_back(2, egammaVec[iEG]);
712 for (
int iTau = 0; iTau <
int(tauVec_bxm2.size()); iTau++) {
713 taus->push_back(-2, tauVec_bxm2[iTau]);
715 for (
int iTau = 0; iTau <
int(tauVec_bxm1.size()); iTau++) {
716 taus->push_back(-1, tauVec_bxm1[iTau]);
718 for (
int iTau = 0; iTau <
int(tauVec_bx0.size()); iTau++) {
719 taus->push_back(0, tauVec_bx0[iTau]);
721 for (
int iTau = 0; iTau <
int(tauVec_bxp1.size()); iTau++) {
722 taus->push_back(1, tauVec_bxp1[iTau]);
724 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
725 for (
int iTau = 0; iTau <
int(tauVec.size()); iTau++) {
726 taus->push_back(2, tauVec[iTau]);
734 for (
int iJet = 0; iJet <
int(jetVec_bxm2.size()); iJet++) {
735 jets->push_back(-2, jetVec_bxm2[iJet]);
737 for (
int iJet = 0; iJet <
int(jetVec_bxm1.size()); iJet++) {
738 jets->push_back(-1, jetVec_bxm1[iJet]);
740 for (
int iJet = 0; iJet <
int(jetVec_bx0.size()); iJet++) {
741 jets->push_back(0, jetVec_bx0[iJet]);
743 for (
int iJet = 0; iJet <
int(jetVec_bxp1.size()); iJet++) {
744 jets->push_back(1, jetVec_bxp1[iJet]);
746 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
747 for (
int iJet = 0; iJet <
int(jetVec.size()); iJet++) {
748 jets->push_back(2, jetVec[iJet]);
756 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm2.size()); iETsum++) {
757 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
759 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm1.size()); iETsum++) {
760 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
762 for (
int iETsum = 0; iETsum <
int(etsumVec_bx0.size()); iETsum++) {
763 etsums->push_back(0, etsumVec_bx0[iETsum]);
765 for (
int iETsum = 0; iETsum <
int(etsumVec_bxp1.size()); iETsum++) {
766 etsums->push_back(1, etsumVec_bxp1[iETsum]);
768 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
769 for (
int iETsum = 0; iETsum <
int(etsumVec.size()); iETsum++) {
770 etsums->push_back(2, etsumVec[iETsum]);
778 extCond->push_back(-2, extCond_bxm2);
779 extCond->push_back(-1, extCond_bxm1);
780 extCond->push_back(0, extCond_bx0);
781 extCond->push_back(1, extCond_bxp1);
782 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
783 extCond->push_back(2, extCond_bx);
798 muonVec_bxm2 = muonVec_bxm1;
799 muonShowerVec_bxm2 = muonShowerVec_bxm1;
800 egammaVec_bxm2 = egammaVec_bxm1;
801 tauVec_bxm2 = tauVec_bxm1;
802 jetVec_bxm2 = jetVec_bxm1;
803 etsumVec_bxm2 = etsumVec_bxm1;
804 extCond_bxm2 = extCond_bxm1;
806 muonVec_bxm1 = muonVec_bx0;
807 muonShowerVec_bxm1 = muonShowerVec_bx0;
808 egammaVec_bxm1 = egammaVec_bx0;
809 tauVec_bxm1 = tauVec_bx0;
810 jetVec_bxm1 = jetVec_bx0;
811 etsumVec_bxm1 = etsumVec_bx0;
812 extCond_bxm1 = extCond_bx0;
814 muonVec_bx0 = muonVec_bxp1;
815 muonShowerVec_bx0 = muonShowerVec_bxp1;
816 egammaVec_bx0 = egammaVec_bxp1;
817 tauVec_bx0 = tauVec_bxp1;
818 jetVec_bx0 = jetVec_bxp1;
819 etsumVec_bx0 = etsumVec_bxp1;
820 extCond_bx0 = extCond_bxp1;
822 muonVec_bxp1 = muonVec;
823 muonShowerVec_bxp1 = muonShowerVec;
824 egammaVec_bxp1 = egammaVec;
825 tauVec_bxp1 = tauVec;
826 jetVec_bxp1 = jetVec;
827 etsumVec_bxp1 = etsumVec;
828 extCond_bxp1 = extCond_bx;
835 void GenToInputProducer::endJob() {}
840 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
844 gRandom =
new TRandom3();
845 mushowerRandom =
new TRandom3();
852 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps) {
872 int binNum = (
int)(
ieta / binWidth);
882 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step) {
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
T getParameter(std::string const &) const
void reset()
reset the content of a GlobalExtBlk
static constexpr int nTowers
virtual double pt() const =0
transverse momentum
virtual int status() const =0
status word
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
virtual int charge() const =0
electric charge
void setMusOutOfTime1(const bool bit)
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
virtual int pdgId() const =0
PDG identifier.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
static unsigned int const shift
isoSum
===> compute the isolation and find the most isolated track
void setMusOutOfTime0(const bool bit)
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity