54 #define M_PI 3.14159265358979323846 73 void endJob()
override;
77 int convertPhiToHW(
double iphi,
int steps);
79 int convertPtToHW(
double ipt,
int maxPt,
double step);
149 produces<BXVector<l1t::EGamma>>();
150 produces<BXVector<l1t::Muon>>();
151 produces<BXVector<l1t::Tau>>();
152 produces<BXVector<l1t::Jet>>();
153 produces<BXVector<l1t::EtSum>>();
154 produces<GlobalExtBlkBxCollection>();
160 maxNumMuCands_ = iConfig.
getParameter<
int>(
"maxMuCand");
161 maxNumJetCands_ = iConfig.
getParameter<
int>(
"maxJetCand");
162 maxNumEGCands_ = iConfig.
getParameter<
int>(
"maxEGCand");
163 maxNumTauCands_ = iConfig.
getParameter<
int>(
"maxTauCand");
165 jetEtThreshold_ = iConfig.
getParameter<
double>(
"jetEtThreshold");
166 tauEtThreshold_ = iConfig.
getParameter<
double>(
"tauEtThreshold");
167 egEtThreshold_ = iConfig.
getParameter<
double>(
"egEtThreshold");
168 muEtThreshold_ = iConfig.
getParameter<
double>(
"muEtThreshold");
170 emptyBxTrailer_ = iConfig.
getParameter<
int>(
"emptyBxTrailer");
173 genParticlesToken = consumes<reco::GenParticleCollection>(
std::string(
"genParticles"));
174 genJetsToken = consumes<reco::GenJetCollection>(
std::string(
"ak4GenJets"));
175 genMetToken = consumes<reco::GenMETCollection>(
std::string(
"genMetCalo"));
182 GenToInputProducer::~GenToInputProducer() {}
192 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::produce function called...\n";
195 std::vector<l1t::Muon> muonVec;
196 std::vector<l1t::EGamma> egammaVec;
197 std::vector<l1t::Tau> tauVec;
198 std::vector<l1t::Jet> jetVec;
199 std::vector<l1t::EtSum> etsumVec;
207 double MaxLepPt_ = 255;
208 double MaxJetPt_ = 1023;
209 double MaxEt_ = 2047;
211 double MaxCaloEta_ = 5.0;
212 double MaxMuonEta_ = 2.45;
214 double PhiStepCalo_ = 144;
215 double PhiStepMuon_ = 576;
218 double EtaStepCalo_ = 230;
219 double EtaStepMuon_ = 450;
222 double PtStep_ = 0.5;
232 std::vector<int> mu_cands_index;
233 std::vector<int> eg_cands_index;
234 std::vector<int> tau_cands_index;
243 double pt = mcParticle.
pt();
251 if (absId == 11 &&
pt >= egEtThreshold_)
252 eg_cands_index.push_back(
k);
253 else if (absId == 13 &&
pt >= muEtThreshold_)
254 mu_cands_index.push_back(
k);
255 else if (absId == 15 &&
pt >= tauEtThreshold_)
256 tau_cands_index.push_back(
k);
259 LogTrace(
"GtGenToInputProducer") <<
">>> GenParticles collection not found!" << std::endl;
263 int numMuCands =
int(mu_cands_index.size());
264 Int_t idxMu[numMuCands];
265 double muPtSorted[numMuCands];
266 for (
int iMu = 0; iMu < numMuCands; iMu++)
267 muPtSorted[iMu] =
genParticles->at(mu_cands_index[iMu]).pt();
269 TMath::Sort(numMuCands, muPtSorted, idxMu);
270 for (
int iMu = 0; iMu < numMuCands; iMu++) {
271 if (iMu >= maxNumMuCands_)
274 const reco::Candidate& mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
276 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
277 int eta = convertEtaToHW(mcParticle.
eta(), -MaxMuonEta_, MaxMuonEta_, EtaStepMuon_);
278 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepMuon_);
279 int qual = gRandom->Integer(16);
280 int iso = gRandom->Integer(4) % 2;
290 int hwEtaAtVtx =
eta;
291 int hwPhiAtVtx = phi;
292 double etaAtVtx = 0.0;
293 double phiAtVtx = 0.0;
294 int hwPtUnconstrained =
295 convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_) / 2;
296 double ptUnconstrained = 0.0;
297 int dXY = gRandom->Integer(4);
303 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
304 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
328 muonVec.push_back(
mu);
332 int numEgCands =
int(eg_cands_index.size());
333 Int_t idxEg[numEgCands];
334 double egPtSorted[numEgCands];
335 for (
int iEg = 0; iEg < numEgCands; iEg++)
336 egPtSorted[iEg] =
genParticles->at(eg_cands_index[iEg]).pt();
338 TMath::Sort(numEgCands, egPtSorted, idxEg);
339 for (
int iEg = 0; iEg < numEgCands; iEg++) {
340 if (iEg >= maxNumEGCands_)
343 const reco::Candidate& mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
345 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
346 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
347 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
348 int qual = gRandom->Integer(2);
349 int iso = gRandom->Integer(4) % 2;
355 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
356 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
359 egammaVec.push_back(eg);
363 int numTauCands =
int(tau_cands_index.size());
364 Int_t idxTau[numTauCands];
365 double tauPtSorted[numTauCands];
366 for (
int iTau = 0; iTau < numTauCands; iTau++)
367 tauPtSorted[iTau] =
genParticles->at(tau_cands_index[iTau]).pt();
369 TMath::Sort(numTauCands, tauPtSorted, idxTau);
370 for (
int iTau = 0; iTau < numTauCands; iTau++) {
371 if (iTau >= maxNumTauCands_)
374 const reco::Candidate& mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
376 int pt = convertPtToHW(mcParticle.
pt(), MaxLepPt_, PtStep_);
377 int eta = convertEtaToHW(mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
378 int phi = convertPhiToHW(mcParticle.
phi(), PhiStepCalo_);
379 int qual = gRandom->Integer(2);
380 int iso = gRandom->Integer(4) % 2;
386 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
387 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
390 tauVec.push_back(
tau);
395 int maxOtherTaus = 8;
396 int numCurrentEGs =
int(egammaVec.size());
397 int numCurrentTaus =
int(tauVec.size());
399 int numExtraEGs = 0, numExtraTaus = 0;
410 for (reco::GenJetCollection::const_iterator genJet =
genJets->begin(); genJet !=
genJets->end(); ++genJet) {
412 sumEt += genJet->et();
415 if (genJet->pt() < jetEtThreshold_)
419 if (nJet >= maxNumJetCands_)
421 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
422 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
424 int pt = convertPtToHW(genJet->et(), MaxJetPt_, PtStep_);
425 int eta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
426 int phi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
432 int qual = gRandom->Integer(2);
435 jetVec.push_back(
jet);
440 if ((numExtraEGs + numCurrentEGs) < maxNumEGCands_ && numExtraEGs < maxOtherEGs) {
443 int EGpt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
444 int EGeta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
445 int EGphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
447 int EGqual = gRandom->Integer(2);
448 int EGiso = gRandom->Integer(4) % 2;
450 l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
451 egammaVec.push_back(eg);
454 if ((numExtraTaus + numCurrentTaus) < maxNumTauCands_ && numExtraTaus < maxOtherTaus) {
457 int Taupt = convertPtToHW(genJet->et(), MaxLepPt_, PtStep_);
458 int Taueta = convertEtaToHW(genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
459 int Tauphi = convertPhiToHW(genJet->phi(), PhiStepCalo_);
460 int Tauqual = gRandom->Integer(2);
461 int Tauiso = gRandom->Integer(4) % 2;
463 l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
464 tauVec.push_back(
tau);
469 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
473 int pt = convertPtToHW(
sumEt, 2047, PtStep_);
474 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>* p4 =
475 new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>();
479 pt = convertPtToHW(
sumEt * 0.6, 2047, PtStep_);
483 int nTowers = 4095 * gRandom->Rndm();
487 int nAsymEt = 255 * gRandom->Rndm();
489 int nAsymHt = 255 * gRandom->Rndm();
491 int nAsymEtHF = 255 * gRandom->Rndm();
493 int nAsymHtHF = 255 * gRandom->Rndm();
496 pt = convertPtToHW(
sumEt * 0.9, 2047, PtStep_);
500 int hfP0val = gRandom->Poisson(4.);
505 int hfM0val = gRandom->Poisson(4.);
510 int hfP1val = gRandom->Poisson(4.);
515 int hfM1val = gRandom->Poisson(4.);
521 int cent30val(0), cent74val(0);
522 int centa = gRandom->Poisson(2.);
523 int centb = gRandom->Poisson(2.);
524 if (centa >= centb) {
539 centralval |= cent30val & 0xF;
540 centralval |= (cent74val & 0xF) <<
shift;
556 mpt = convertPtToHW(
genMet->front().pt(), MaxEt_, PtStep_);
557 mphi = convertPhiToHW(
genMet->front().phi(), PhiStepCalo_);
560 mptHf = convertPtToHW(
genMet->front().pt() * 1.1, MaxEt_, PtStep_);
561 mphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 7., PhiStepCalo_);
564 mhpt = convertPtToHW(
genMet->front().pt() * 0.9, MaxEt_, PtStep_);
565 mhphi = convertPhiToHW(
genMet->front().phi() + 3.14 / 5., PhiStepCalo_);
568 mhptHf = convertPtToHW(
genMet->front().pt() * 0.95, MaxEt_, PtStep_);
569 mhphiHf = convertPhiToHW(
genMet->front().phi() + 3.14 / 6., PhiStepCalo_);
571 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
581 etsumVec.push_back(etTotal);
582 etsumVec.push_back(etEmTotal);
583 etsumVec.push_back(hfP0);
585 etsumVec.push_back(htTotal);
586 etsumVec.push_back(towerCounts);
587 etsumVec.push_back(hfM0);
589 etsumVec.push_back(
etmiss);
590 etsumVec.push_back(AsymEt);
591 etsumVec.push_back(hfP1);
593 etsumVec.push_back(
htmiss);
594 etsumVec.push_back(AsymHt);
595 etsumVec.push_back(hfM1);
597 etsumVec.push_back(etmissHF);
598 etsumVec.push_back(AsymEtHF);
600 etsumVec.push_back(htmissHF);
601 etsumVec.push_back(AsymHtHF);
602 etsumVec.push_back(centrality);
605 if ((
iEvent.id().event()) % 2 == 0) {
606 for (
int i = 0;
i < 255;
i =
i + 2)
609 for (
int i = 1;
i < 255;
i =
i + 2)
617 for (
int iMu = 0; iMu <
int(muonVec_bxm2.size()); iMu++) {
618 muons->push_back(-2, muonVec_bxm2[iMu]);
620 for (
int iMu = 0; iMu <
int(muonVec_bxm1.size()); iMu++) {
621 muons->push_back(-1, muonVec_bxm1[iMu]);
623 for (
int iMu = 0; iMu <
int(muonVec_bx0.size()); iMu++) {
624 muons->push_back(0, muonVec_bx0[iMu]);
626 for (
int iMu = 0; iMu <
int(muonVec_bxp1.size()); iMu++) {
627 muons->push_back(1, muonVec_bxp1[iMu]);
629 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
630 for (
int iMu = 0; iMu <
int(muonVec.size()); iMu++) {
631 muons->push_back(2, muonVec[iMu]);
639 for (
int iEG = 0; iEG <
int(egammaVec_bxm2.size()); iEG++) {
640 egammas->push_back(-2, egammaVec_bxm2[iEG]);
642 for (
int iEG = 0; iEG <
int(egammaVec_bxm1.size()); iEG++) {
643 egammas->push_back(-1, egammaVec_bxm1[iEG]);
645 for (
int iEG = 0; iEG <
int(egammaVec_bx0.size()); iEG++) {
646 egammas->push_back(0, egammaVec_bx0[iEG]);
648 for (
int iEG = 0; iEG <
int(egammaVec_bxp1.size()); iEG++) {
649 egammas->push_back(1, egammaVec_bxp1[iEG]);
651 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
652 for (
int iEG = 0; iEG <
int(egammaVec.size()); iEG++) {
653 egammas->push_back(2, egammaVec[iEG]);
661 for (
int iTau = 0; iTau <
int(tauVec_bxm2.size()); iTau++) {
662 taus->push_back(-2, tauVec_bxm2[iTau]);
664 for (
int iTau = 0; iTau <
int(tauVec_bxm1.size()); iTau++) {
665 taus->push_back(-1, tauVec_bxm1[iTau]);
667 for (
int iTau = 0; iTau <
int(tauVec_bx0.size()); iTau++) {
668 taus->push_back(0, tauVec_bx0[iTau]);
670 for (
int iTau = 0; iTau <
int(tauVec_bxp1.size()); iTau++) {
671 taus->push_back(1, tauVec_bxp1[iTau]);
673 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
674 for (
int iTau = 0; iTau <
int(tauVec.size()); iTau++) {
675 taus->push_back(2, tauVec[iTau]);
683 for (
int iJet = 0; iJet <
int(jetVec_bxm2.size()); iJet++) {
684 jets->push_back(-2, jetVec_bxm2[iJet]);
686 for (
int iJet = 0; iJet <
int(jetVec_bxm1.size()); iJet++) {
687 jets->push_back(-1, jetVec_bxm1[iJet]);
689 for (
int iJet = 0; iJet <
int(jetVec_bx0.size()); iJet++) {
690 jets->push_back(0, jetVec_bx0[iJet]);
692 for (
int iJet = 0; iJet <
int(jetVec_bxp1.size()); iJet++) {
693 jets->push_back(1, jetVec_bxp1[iJet]);
695 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
696 for (
int iJet = 0; iJet <
int(jetVec.size()); iJet++) {
697 jets->push_back(2, jetVec[iJet]);
705 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm2.size()); iETsum++) {
706 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
708 for (
int iETsum = 0; iETsum <
int(etsumVec_bxm1.size()); iETsum++) {
709 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
711 for (
int iETsum = 0; iETsum <
int(etsumVec_bx0.size()); iETsum++) {
712 etsums->push_back(0, etsumVec_bx0[iETsum]);
714 for (
int iETsum = 0; iETsum <
int(etsumVec_bxp1.size()); iETsum++) {
715 etsums->push_back(1, etsumVec_bxp1[iETsum]);
717 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
718 for (
int iETsum = 0; iETsum <
int(etsumVec.size()); iETsum++) {
719 etsums->push_back(2, etsumVec[iETsum]);
727 extCond->push_back(-2, extCond_bxm2);
728 extCond->push_back(-1, extCond_bxm1);
729 extCond->push_back(0, extCond_bx0);
730 extCond->push_back(1, extCond_bxp1);
731 if (emptyBxTrailer_ <= (emptyBxEvt_ - eventCnt_)) {
732 extCond->push_back(2, extCond_bx);
746 muonVec_bxm2 = muonVec_bxm1;
747 egammaVec_bxm2 = egammaVec_bxm1;
748 tauVec_bxm2 = tauVec_bxm1;
749 jetVec_bxm2 = jetVec_bxm1;
750 etsumVec_bxm2 = etsumVec_bxm1;
751 extCond_bxm2 = extCond_bxm1;
753 muonVec_bxm1 = muonVec_bx0;
754 egammaVec_bxm1 = egammaVec_bx0;
755 tauVec_bxm1 = tauVec_bx0;
756 jetVec_bxm1 = jetVec_bx0;
757 etsumVec_bxm1 = etsumVec_bx0;
758 extCond_bxm1 = extCond_bx0;
760 muonVec_bx0 = muonVec_bxp1;
761 egammaVec_bx0 = egammaVec_bxp1;
762 tauVec_bx0 = tauVec_bxp1;
763 jetVec_bx0 = jetVec_bxp1;
764 etsumVec_bx0 = etsumVec_bxp1;
765 extCond_bx0 = extCond_bxp1;
767 muonVec_bxp1 = muonVec;
768 egammaVec_bxp1 = egammaVec;
769 tauVec_bxp1 = tauVec;
770 jetVec_bxp1 = jetVec;
771 etsumVec_bxp1 = etsumVec;
772 extCond_bxp1 = extCond_bx;
779 void GenToInputProducer::endJob() {}
784 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
788 gRandom =
new TRandom3();
795 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps) {
815 int binNum = (
int)(
ieta / binWidth);
825 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step) {
826 int hwPt =
int(ipt /
step + 0.0001);
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
T getParameter(std::string const &) const
void reset()
reset the content of a GlobalExtBlk
virtual double pt() const =0
transverse momentum
virtual int status() const =0
status word
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 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
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity