51 #define M_PI 3.14159265358979323846 70 void endJob()
override;
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);
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>();
161 maxNumMuCands_ = iConfig.
getParameter<
int>(
"maxMuCand");
162 maxNumJetCands_ = iConfig.
getParameter<
int>(
"maxJetCand");
163 maxNumEGCands_ = iConfig.
getParameter<
int>(
"maxEGCand");
164 maxNumTauCands_ = iConfig.
getParameter<
int>(
"maxTauCand");
166 jetEtThreshold_ = iConfig.
getParameter<
double>(
"jetEtThreshold");
167 tauEtThreshold_ = iConfig.
getParameter<
double>(
"tauEtThreshold");
168 egEtThreshold_ = iConfig.
getParameter<
double>(
"egEtThreshold");
169 muEtThreshold_ = iConfig.
getParameter<
double>(
"muEtThreshold");
172 emptyBxTrailer_ = iConfig.
getParameter<
int>(
"emptyBxTrailer");
176 genParticlesToken = consumes <reco::GenParticleCollection> (
std::string(
"genParticles"));
177 genJetsToken = consumes <reco::GenJetCollection> (
std::string(
"ak4GenJets"));
178 genMetToken = consumes <reco::GenMETCollection> (
std::string(
"genMetCalo"));
187 GenToInputProducer::~GenToInputProducer()
204 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::produce function called...\n";
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;
215 int bxFirst = bxFirst_;
216 int bxLast = bxLast_;
220 double MaxLepPt_ = 255;
221 double MaxJetPt_ = 1023;
222 double MaxEt_ = 2047;
224 double MaxCaloEta_ = 5.0;
225 double MaxMuonEta_ = 2.45;
227 double PhiStepCalo_ = 144;
228 double PhiStepMuon_ = 576;
231 double EtaStepCalo_ = 230;
232 double EtaStepMuon_ = 450;
235 double PtStep_ = 0.5;
246 std::vector<int> mu_cands_index;
247 std::vector<int> eg_cands_index;
248 std::vector<int> tau_cands_index;
251 if( iEvent.
getByToken(genParticlesToken, genParticles) ){
253 for(
size_t k = 0;
k < genParticles->size();
k++ ){
258 double pt = mcParticle.
pt();
261 if( status!=1 && !(
abs(pdgId)==15 && status==2) )
continue;
263 int absId =
abs(pdgId);
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);
271 LogTrace(
"GtGenToInputProducer") <<
">>> GenParticles collection not found!" << std::endl;
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();
282 TMath::Sort(numMuCands,muPtSorted,idxMu);
283 for(
int iMu=0; iMu<numMuCands; iMu++ ){
285 if( iMu>=maxNumMuCands_ )
continue;
287 const reco::Candidate & mcParticle = (*genParticles)[mu_cands_index[idxMu[iMu]]];
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);
293 int iso = gRandom->Integer(4)%2;
303 int hwEtaAtVtx =
eta;
304 int hwPhiAtVtx = phi;
307 if( eta>=9999 )
continue;
309 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
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);
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();
322 TMath::Sort(numEgCands,egPtSorted,idxEg);
323 for(
int iEg=0; iEg<numEgCands; iEg++ ){
325 if( iEg>=maxNumEGCands_ )
continue;
327 const reco::Candidate & mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
329 int pt = convertPtToHW( mcParticle.
pt(), MaxLepPt_, PtStep_ );
330 int eta = convertEtaToHW( mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
331 int phi = convertPhiToHW( mcParticle.
phi(), PhiStepCalo_ );
333 int iso = gRandom->Integer(4)%2;
336 if( eta>=9999 )
continue;
338 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
341 egammaVec.push_back(eg);
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();
352 TMath::Sort(numTauCands,tauPtSorted,idxTau);
353 for(
int iTau=0; iTau<numTauCands; iTau++ ){
355 if( iTau>=maxNumTauCands_ )
continue;
357 const reco::Candidate & mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
359 int pt = convertPtToHW( mcParticle.
pt(), MaxLepPt_, PtStep_ );
360 int eta = convertEtaToHW( mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
361 int phi = convertPhiToHW( mcParticle.
phi(), PhiStepCalo_ );
363 int iso = gRandom->Integer(4)%2;
366 if( eta>=9999 )
continue;
368 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
371 tauVec.push_back(tau);
377 int maxOtherTaus = 8;
378 int numCurrentEGs =
int( egammaVec.size() );
379 int numCurrentTaus =
int( tauVec.size() );
381 int numExtraEGs=0, numExtraTaus=0;
391 if( iEvent.
getByToken(genJetsToken, genJets) ){
392 for(reco::GenJetCollection::const_iterator genJet = genJets->begin(); genJet!=genJets->end(); ++genJet ){
395 sumEt += genJet->et();
398 if( genJet->pt()<jetEtThreshold_ )
continue;
401 if( nJet>=maxNumJetCands_ )
continue;
402 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
404 int pt = convertPtToHW( genJet->et(), MaxJetPt_, PtStep_ );
405 int eta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
406 int phi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
409 if( eta>=9999 )
continue;
414 jetVec.push_back(jet);
419 if( (numExtraEGs+numCurrentEGs)<maxNumEGCands_ && numExtraEGs<maxOtherEGs ){
422 int EGpt = convertPtToHW( genJet->et(), MaxLepPt_, PtStep_ );
423 int EGeta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
424 int EGphi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
427 int EGiso = gRandom->Integer(4)%2;
429 l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
430 egammaVec.push_back(eg);
433 if( (numExtraTaus+numCurrentTaus)<maxNumTauCands_ && numExtraTaus<maxOtherTaus ){
436 int Taupt = convertPtToHW( genJet->et(), MaxLepPt_, PtStep_ );
437 int Taueta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
438 int Tauphi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
440 int Tauiso = gRandom->Integer(4)%2;
442 l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
443 tauVec.push_back(tau);
449 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
454 int pt = convertPtToHW( sumEt, 2047, PtStep_ );
455 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
459 pt = convertPtToHW( sumEt*0.6, 2047, PtStep_ );
463 int nTowers=4095*gRandom->Rndm();
467 int nAsymEt=255*gRandom->Rndm();
469 int nAsymHt=255*gRandom->Rndm();
471 int nAsymEtHF=255*gRandom->Rndm();
473 int nAsymHtHF=255*gRandom->Rndm();
476 pt = convertPtToHW( sumEt*0.9, 2047, PtStep_ );
480 int hfP0val = gRandom->Poisson(4.);
481 if(hfP0val>15) hfP0val = 15;
484 int hfM0val = gRandom->Poisson(4.);
485 if(hfM0val>15) hfM0val = 15;
488 int hfP1val = gRandom->Poisson(4.);
489 if(hfP1val>15) hfP1val = 15;
492 int hfM1val = gRandom->Poisson(4.);
493 if(hfM1val>15) hfM1val = 15;
497 int cent30val(0), cent74val(0);
498 int centa = gRandom->Poisson(2.);
499 int centb = gRandom->Poisson(2.);
500 if (centa >= centb) {
508 if(cent30val>15) cent30val = 15;
509 if(cent74val>15) cent74val = 15;
513 centralval |= cent30val & 0xF;
514 centralval |= (cent74val & 0xF ) << shift;
530 mpt = convertPtToHW( genMet->front().pt(), MaxEt_, PtStep_ );
531 mphi = convertPhiToHW( genMet->front().phi(), PhiStepCalo_ );
534 mptHf = convertPtToHW( genMet->front().pt()*1.1, MaxEt_, PtStep_ );
535 mphiHf = convertPhiToHW( genMet->front().phi()+ 3.14/7., PhiStepCalo_ );
538 mhpt = convertPtToHW( genMet->front().pt()*0.9, MaxEt_, PtStep_ );
539 mhphi = convertPhiToHW( genMet->front().phi()+ 3.14/5., PhiStepCalo_ );
542 mhptHf = convertPtToHW( genMet->front().pt()*0.95, MaxEt_, PtStep_ );
543 mhphiHf = convertPhiToHW( genMet->front().phi()+ 3.14/6., PhiStepCalo_ );
546 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
556 etsumVec.push_back(etTotal);
557 etsumVec.push_back(etEmTotal);
558 etsumVec.push_back(hfP0);
560 etsumVec.push_back(htTotal);
561 etsumVec.push_back(towerCounts);
562 etsumVec.push_back(hfM0);
564 etsumVec.push_back(etmiss);
565 etsumVec.push_back(AsymEt);
566 etsumVec.push_back(hfP1);
568 etsumVec.push_back(htmiss);
569 etsumVec.push_back(AsymHt);
570 etsumVec.push_back(hfM1);
572 etsumVec.push_back(etmissHF);
573 etsumVec.push_back(AsymEtHF);
575 etsumVec.push_back(htmissHF);
576 etsumVec.push_back(AsymHtHF);
577 etsumVec.push_back(centrality);
580 if((iEvent.
id().
event())%2 == 0 ) {
590 for(
int iMu=0; iMu<
int(muonVec_bxm2.size()); iMu++ ){
591 muons->push_back(-2, muonVec_bxm2[iMu]);
593 for(
int iMu=0; iMu<
int(muonVec_bxm1.size()); iMu++ ){
594 muons->push_back(-1, muonVec_bxm1[iMu]);
596 for(
int iMu=0; iMu<
int(muonVec_bx0.size()); iMu++ ){
597 muons->push_back(0, muonVec_bx0[iMu]);
599 for(
int iMu=0; iMu<
int(muonVec_bxp1.size()); iMu++ ){
600 muons->push_back(1, muonVec_bxp1[iMu]);
602 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
603 for(
int iMu=0; iMu<
int(muonVec.size()); iMu++ ){
604 muons->push_back(2, muonVec[iMu]);
612 for(
int iEG=0; iEG<
int(egammaVec_bxm2.size()); iEG++ ){
613 egammas->push_back(-2, egammaVec_bxm2[iEG]);
615 for(
int iEG=0; iEG<
int(egammaVec_bxm1.size()); iEG++ ){
616 egammas->push_back(-1, egammaVec_bxm1[iEG]);
618 for(
int iEG=0; iEG<
int(egammaVec_bx0.size()); iEG++ ){
619 egammas->push_back(0, egammaVec_bx0[iEG]);
621 for(
int iEG=0; iEG<
int(egammaVec_bxp1.size()); iEG++ ){
622 egammas->push_back(1, egammaVec_bxp1[iEG]);
624 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
625 for(
int iEG=0; iEG<
int(egammaVec.size()); iEG++ ){
626 egammas->push_back(2, egammaVec[iEG]);
634 for(
int iTau=0; iTau<
int(tauVec_bxm2.size()); iTau++ ){
635 taus->push_back(-2, tauVec_bxm2[iTau]);
637 for(
int iTau=0; iTau<
int(tauVec_bxm1.size()); iTau++ ){
638 taus->push_back(-1, tauVec_bxm1[iTau]);
640 for(
int iTau=0; iTau<
int(tauVec_bx0.size()); iTau++ ){
641 taus->push_back(0, tauVec_bx0[iTau]);
643 for(
int iTau=0; iTau<
int(tauVec_bxp1.size()); iTau++ ){
644 taus->push_back(1, tauVec_bxp1[iTau]);
646 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
647 for(
int iTau=0; iTau<
int(tauVec.size()); iTau++ ){
648 taus->push_back(2, tauVec[iTau]);
656 for(
int iJet=0; iJet<
int(jetVec_bxm2.size()); iJet++ ){
657 jets->push_back(-2, jetVec_bxm2[iJet]);
659 for(
int iJet=0; iJet<
int(jetVec_bxm1.size()); iJet++ ){
660 jets->push_back(-1, jetVec_bxm1[iJet]);
662 for(
int iJet=0; iJet<
int(jetVec_bx0.size()); iJet++ ){
663 jets->push_back(0, jetVec_bx0[iJet]);
665 for(
int iJet=0; iJet<
int(jetVec_bxp1.size()); iJet++ ){
666 jets->push_back(1, jetVec_bxp1[iJet]);
668 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
669 for(
int iJet=0; iJet<
int(jetVec.size()); iJet++ ){
670 jets->push_back(2, jetVec[iJet]);
678 for(
int iETsum=0; iETsum<
int(etsumVec_bxm2.size()); iETsum++ ){
679 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
681 for(
int iETsum=0; iETsum<
int(etsumVec_bxm1.size()); iETsum++ ){
682 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
684 for(
int iETsum=0; iETsum<
int(etsumVec_bx0.size()); iETsum++ ){
685 etsums->push_back(0, etsumVec_bx0[iETsum]);
687 for(
int iETsum=0; iETsum<
int(etsumVec_bxp1.size()); iETsum++ ){
688 etsums->push_back(1, etsumVec_bxp1[iETsum]);
690 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
691 for(
int iETsum=0; iETsum<
int(etsumVec.size()); iETsum++ ){
692 etsums->push_back(2, etsumVec[iETsum]);
700 extCond->push_back(-2, extCond_bxm2);
701 extCond->push_back(-1, extCond_bxm1);
702 extCond->push_back(0, extCond_bx0);
703 extCond->push_back(1, extCond_bxp1);
704 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
705 extCond->push_back(2, extCond_bx);
720 muonVec_bxm2 = muonVec_bxm1;
721 egammaVec_bxm2 = egammaVec_bxm1;
722 tauVec_bxm2 = tauVec_bxm1;
723 jetVec_bxm2 = jetVec_bxm1;
724 etsumVec_bxm2 = etsumVec_bxm1;
725 extCond_bxm2 = extCond_bxm1;
727 muonVec_bxm1 = muonVec_bx0;
728 egammaVec_bxm1 = egammaVec_bx0;
729 tauVec_bxm1 = tauVec_bx0;
730 jetVec_bxm1 = jetVec_bx0;
731 etsumVec_bxm1 = etsumVec_bx0;
732 extCond_bxm1 = extCond_bx0;
734 muonVec_bx0 = muonVec_bxp1;
735 egammaVec_bx0 = egammaVec_bxp1;
736 tauVec_bx0 = tauVec_bxp1;
737 jetVec_bx0 = jetVec_bxp1;
738 etsumVec_bx0 = etsumVec_bxp1;
739 extCond_bx0 = extCond_bxp1;
741 muonVec_bxp1 = muonVec;
742 egammaVec_bxp1 = egammaVec;
743 tauVec_bxp1 = tauVec;
744 jetVec_bxp1 = jetVec;
745 etsumVec_bxp1 = etsumVec;
746 extCond_bxp1 = extCond_bx;
757 GenToInputProducer::endJob() {
764 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
769 gRandom =
new TRandom3();
779 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps){
782 if( iphi < 0 ) iphi += 2*
M_PI;
783 if( iphi > phiMax) iphi -=
phiMax;
785 int hwPhi =
int( (iphi/phiMax)*steps + 0.00001 );
791 double binWidth = (maxEta -
minEta)/steps;
794 if(ieta < minEta)
return 99999;
795 if(ieta > maxEta)
return 99999;
797 int binNum = (
int)(ieta/binWidth);
798 if(ieta<0.) binNum--;
806 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step){
808 int hwPt =
int( ipt/step + 0.0001 );
810 if( hwPt > maxPt ) hwPt =
maxPt;
T getParameter(std::string const &) const
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 int status() const =0
status word
#define DEFINE_FWK_MODULE(type)
void addDefault(ParameterSetDescription const &psetDescription)
virtual int pdgId() const =0
PDG identifier.
Abs< T >::type abs(const T &t)
void setExternalDecision(unsigned int bit, bool val)
Set decision bits.
virtual double eta() const =0
momentum pseudorapidity
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual double pt() const =0
transverse momentum
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
virtual int charge() const =0
electric charge
static unsigned int const shift
isoSum
===> compute the isolation and find the most isolated track
virtual double phi() const =0
momentum azimuthal angle