13 #include <boost/shared_ptr.hpp>
51 #define M_PI 3.14159265358979323846
70 virtual void endJob();
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;
300 if( eta>=9999 )
continue;
302 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
304 l1t::Muon mu(*p4, pt, eta, phi, qual, charge, chargeValid, iso, mip, tag);
305 muonVec.push_back(mu);
310 int numEgCands = int( eg_cands_index.size() );
311 Int_t idxEg[numEgCands];
312 double egPtSorted[numEgCands];
313 for(
int iEg=0; iEg<numEgCands; iEg++ ) egPtSorted[iEg] = genParticles->at(eg_cands_index[iEg]).pt();
315 TMath::Sort(numEgCands,egPtSorted,idxEg);
316 for(
int iEg=0; iEg<numEgCands; iEg++ ){
318 if( iEg>=maxNumEGCands_ )
continue;
320 const reco::Candidate & mcParticle = (*genParticles)[eg_cands_index[idxEg[iEg]]];
322 int pt = convertPtToHW( mcParticle.
pt(), MaxLepPt_, PtStep_ );
323 int eta = convertEtaToHW( mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
324 int phi = convertPhiToHW( mcParticle.
phi(), PhiStepCalo_ );
326 int iso = gRandom->Integer(4)%2;
329 if( eta>=9999 )
continue;
331 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
334 egammaVec.push_back(eg);
340 int numTauCands = int( tau_cands_index.size() );
341 Int_t idxTau[numTauCands];
342 double tauPtSorted[numTauCands];
343 for(
int iTau=0; iTau<numTauCands; iTau++ ) tauPtSorted[iTau] = genParticles->at(tau_cands_index[iTau]).pt();
345 TMath::Sort(numTauCands,tauPtSorted,idxTau);
346 for(
int iTau=0; iTau<numTauCands; iTau++ ){
348 if( iTau>=maxNumTauCands_ )
continue;
350 const reco::Candidate & mcParticle = (*genParticles)[tau_cands_index[idxTau[iTau]]];
352 int pt = convertPtToHW( mcParticle.
pt(), MaxLepPt_, PtStep_ );
353 int eta = convertEtaToHW( mcParticle.
eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_);
354 int phi = convertPhiToHW( mcParticle.
phi(), PhiStepCalo_ );
356 int iso = gRandom->Integer(4)%2;
359 if( eta>=9999 )
continue;
361 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
364 tauVec.push_back(tau);
370 int maxOtherTaus = 8;
371 int numCurrentEGs = int( egammaVec.size() );
372 int numCurrentTaus = int( tauVec.size() );
374 int numExtraEGs=0, numExtraTaus=0;
384 if( iEvent.
getByToken(genJetsToken, genJets) ){
385 for(reco::GenJetCollection::const_iterator genJet = genJets->begin(); genJet!=genJets->end(); ++genJet ){
388 sumEt += genJet->et();
391 if( genJet->pt()<jetEtThreshold_ )
continue;
394 if( nJet>=maxNumJetCands_ )
continue;
395 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
397 int pt = convertPtToHW( genJet->et(), MaxJetPt_, PtStep_ );
398 int eta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
399 int phi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
402 if( eta>=9999 )
continue;
407 jetVec.push_back(jet);
412 if( (numExtraEGs+numCurrentEGs)<maxNumEGCands_ && numExtraEGs<maxOtherEGs ){
415 int EGpt = convertPtToHW( genJet->et(), MaxLepPt_, PtStep_ );
416 int EGeta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
417 int EGphi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
420 int EGiso = gRandom->Integer(4)%2;
422 l1t::EGamma eg(*p4, EGpt, EGeta, EGphi, EGqual, EGiso);
423 egammaVec.push_back(eg);
426 if( (numExtraTaus+numCurrentTaus)<maxNumTauCands_ && numExtraTaus<maxOtherTaus ){
429 int Taupt = convertPtToHW( genJet->et(), MaxLepPt_, PtStep_ );
430 int Taueta = convertEtaToHW( genJet->eta(), -MaxCaloEta_, MaxCaloEta_, EtaStepCalo_ );
431 int Tauphi = convertPhiToHW( genJet->phi(), PhiStepCalo_ );
433 int Tauiso = gRandom->Integer(4)%2;
435 l1t::Tau tau(*p4, Taupt, Taueta, Tauphi, Tauqual, Tauiso);
436 tauVec.push_back(tau);
442 LogTrace(
"GtGenToInputProducer") <<
">>> GenJets collection not found!" << std::endl;
447 int pt = convertPtToHW( sumEt, 2047, PtStep_ );
448 ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > *
p4 =
new ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >();
452 pt = convertPtToHW( sumEt*0.6, 2047, PtStep_ );
453 l1t::EtSum etEmTotal(*p4, l1t::EtSum::EtSumType::kTotalEtEm,pt, 0, 0, 0);
456 int nTowers=4095*gRandom->Rndm();
457 l1t::EtSum towerCounts(*p4, l1t::EtSum::EtSumType::kTowerCount,nTowers, 0, 0, 0);
459 pt = convertPtToHW( sumEt*0.9, 2047, PtStep_ );
463 int hfP0val = gRandom->Poisson(4.);
464 if(hfP0val>15) hfP0val = 15;
465 l1t::EtSum hfP0(*p4, l1t::EtSum::EtSumType::kMinBiasHFP0,hfP0val, 0, 0, 0);
467 int hfM0val = gRandom->Poisson(4.);
468 if(hfM0val>15) hfM0val = 15;
469 l1t::EtSum hfM0(*p4, l1t::EtSum::EtSumType::kMinBiasHFM0,hfM0val, 0, 0, 0);
471 int hfP1val = gRandom->Poisson(4.);
472 if(hfP1val>15) hfP1val = 15;
473 l1t::EtSum hfP1(*p4, l1t::EtSum::EtSumType::kMinBiasHFP1,hfP1val, 0, 0, 0);
475 int hfM1val = gRandom->Poisson(4.);
476 if(hfM1val>15) hfM1val = 15;
477 l1t::EtSum hfM1(*p4, l1t::EtSum::EtSumType::kMinBiasHFM1,hfM1val, 0, 0, 0);
489 mpt = convertPtToHW( genMet->front().pt(), MaxEt_, PtStep_ );
490 mphi = convertPhiToHW( genMet->front().phi(), PhiStepCalo_ );
493 mptHf = convertPtToHW( genMet->front().pt()*1.1, MaxEt_, PtStep_ );
494 mphiHf = convertPhiToHW( genMet->front().phi()+ 3.14/7., PhiStepCalo_ );
497 mhpt = convertPtToHW( genMet->front().pt()*0.9, MaxEt_, PtStep_ );
498 mhphi = convertPhiToHW( genMet->front().phi()+ 3.14/5., PhiStepCalo_ );
501 LogTrace(
"GtGenToInputProducer") <<
">>> GenMet collection not found!" << std::endl;
506 l1t::EtSum etmissHF(*p4, l1t::EtSum::EtSumType::kMissingEtHF,mptHf, 0,mphiHf, 0);
510 etsumVec.push_back(etTotal);
511 etsumVec.push_back(etEmTotal);
512 etsumVec.push_back(hfP0);
513 etsumVec.push_back(htTotal);
514 etsumVec.push_back(hfM0);
515 etsumVec.push_back(etmiss);
516 etsumVec.push_back(hfP1);
517 etsumVec.push_back(htmiss);
518 etsumVec.push_back(hfM1);
519 etsumVec.push_back(etmissHF);
520 etsumVec.push_back(towerCounts);
523 if((iEvent.
id().
event())%2 == 0 ) {
533 for(
int iMu=0; iMu<int(muonVec_bxm2.size()); iMu++ ){
534 muons->push_back(-2, muonVec_bxm2[iMu]);
536 for(
int iMu=0; iMu<int(muonVec_bxm1.size()); iMu++ ){
537 muons->push_back(-1, muonVec_bxm1[iMu]);
539 for(
int iMu=0; iMu<int(muonVec_bx0.size()); iMu++ ){
540 muons->push_back(0, muonVec_bx0[iMu]);
542 for(
int iMu=0; iMu<int(muonVec_bxp1.size()); iMu++ ){
543 muons->push_back(1, muonVec_bxp1[iMu]);
545 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
546 for(
int iMu=0; iMu<int(muonVec.size()); iMu++ ){
547 muons->push_back(2, muonVec[iMu]);
555 for(
int iEG=0; iEG<int(egammaVec_bxm2.size()); iEG++ ){
556 egammas->push_back(-2, egammaVec_bxm2[iEG]);
558 for(
int iEG=0; iEG<int(egammaVec_bxm1.size()); iEG++ ){
559 egammas->push_back(-1, egammaVec_bxm1[iEG]);
561 for(
int iEG=0; iEG<int(egammaVec_bx0.size()); iEG++ ){
562 egammas->push_back(0, egammaVec_bx0[iEG]);
564 for(
int iEG=0; iEG<int(egammaVec_bxp1.size()); iEG++ ){
565 egammas->push_back(1, egammaVec_bxp1[iEG]);
567 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
568 for(
int iEG=0; iEG<int(egammaVec.size()); iEG++ ){
569 egammas->push_back(2, egammaVec[iEG]);
577 for(
int iTau=0; iTau<int(tauVec_bxm2.size()); iTau++ ){
578 taus->push_back(-2, tauVec_bxm2[iTau]);
580 for(
int iTau=0; iTau<int(tauVec_bxm1.size()); iTau++ ){
581 taus->push_back(-1, tauVec_bxm1[iTau]);
583 for(
int iTau=0; iTau<int(tauVec_bx0.size()); iTau++ ){
584 taus->push_back(0, tauVec_bx0[iTau]);
586 for(
int iTau=0; iTau<int(tauVec_bxp1.size()); iTau++ ){
587 taus->push_back(1, tauVec_bxp1[iTau]);
589 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
590 for(
int iTau=0; iTau<int(tauVec.size()); iTau++ ){
591 taus->push_back(2, tauVec[iTau]);
599 for(
int iJet=0; iJet<int(jetVec_bxm2.size()); iJet++ ){
600 jets->push_back(-2, jetVec_bxm2[iJet]);
602 for(
int iJet=0; iJet<int(jetVec_bxm1.size()); iJet++ ){
603 jets->push_back(-1, jetVec_bxm1[iJet]);
605 for(
int iJet=0; iJet<int(jetVec_bx0.size()); iJet++ ){
606 jets->push_back(0, jetVec_bx0[iJet]);
608 for(
int iJet=0; iJet<int(jetVec_bxp1.size()); iJet++ ){
609 jets->push_back(1, jetVec_bxp1[iJet]);
611 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
612 for(
int iJet=0; iJet<int(jetVec.size()); iJet++ ){
613 jets->push_back(2, jetVec[iJet]);
621 for(
int iETsum=0; iETsum<int(etsumVec_bxm2.size()); iETsum++ ){
622 etsums->push_back(-2, etsumVec_bxm2[iETsum]);
624 for(
int iETsum=0; iETsum<int(etsumVec_bxm1.size()); iETsum++ ){
625 etsums->push_back(-1, etsumVec_bxm1[iETsum]);
627 for(
int iETsum=0; iETsum<int(etsumVec_bx0.size()); iETsum++ ){
628 etsums->push_back(0, etsumVec_bx0[iETsum]);
630 for(
int iETsum=0; iETsum<int(etsumVec_bxp1.size()); iETsum++ ){
631 etsums->push_back(1, etsumVec_bxp1[iETsum]);
633 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
634 for(
int iETsum=0; iETsum<int(etsumVec.size()); iETsum++ ){
635 etsums->push_back(2, etsumVec[iETsum]);
643 extCond->push_back(-2, extCond_bxm2);
644 extCond->push_back(-1, extCond_bxm1);
645 extCond->push_back(0, extCond_bx0);
646 extCond->push_back(1, extCond_bxp1);
647 if(emptyBxTrailer_<=(emptyBxEvt_ - eventCnt_)) {
648 extCond->push_back(2, extCond_bx);
663 muonVec_bxm2 = muonVec_bxm1;
664 egammaVec_bxm2 = egammaVec_bxm1;
665 tauVec_bxm2 = tauVec_bxm1;
666 jetVec_bxm2 = jetVec_bxm1;
667 etsumVec_bxm2 = etsumVec_bxm1;
668 extCond_bxm2 = extCond_bxm1;
670 muonVec_bxm1 = muonVec_bx0;
671 egammaVec_bxm1 = egammaVec_bx0;
672 tauVec_bxm1 = tauVec_bx0;
673 jetVec_bxm1 = jetVec_bx0;
674 etsumVec_bxm1 = etsumVec_bx0;
675 extCond_bxm1 = extCond_bx0;
677 muonVec_bx0 = muonVec_bxp1;
678 egammaVec_bx0 = egammaVec_bxp1;
679 tauVec_bx0 = tauVec_bxp1;
680 jetVec_bx0 = jetVec_bxp1;
681 etsumVec_bx0 = etsumVec_bxp1;
682 extCond_bx0 = extCond_bxp1;
684 muonVec_bxp1 = muonVec;
685 egammaVec_bxp1 = egammaVec;
686 tauVec_bxp1 = tauVec;
687 jetVec_bxp1 = jetVec;
688 etsumVec_bxp1 = etsumVec;
689 extCond_bxp1 = extCond_bx;
700 GenToInputProducer::endJob() {
707 LogDebug(
"GtGenToInputProducer") <<
"GenToInputProducer::beginRun function called...\n";
712 gRandom =
new TRandom3();
722 int GenToInputProducer::convertPhiToHW(
double iphi,
int steps){
724 double phiMax = 2 *
M_PI;
725 if( iphi < 0 ) iphi += 2*
M_PI;
726 if( iphi > phiMax) iphi -= phiMax;
728 int hwPhi = int( (iphi/phiMax)*steps + 0.00001 );
734 double binWidth = (maxEta -
minEta)/steps;
737 if(ieta < minEta)
return 99999;
738 if(ieta > maxEta)
return 99999;
740 int binNum = (int)(ieta/binWidth);
741 if(ieta<0.) binNum--;
749 int GenToInputProducer::convertPtToHW(
double ipt,
int maxPt,
double step){
751 int hwPt = int( ipt/step + 0.0001 );
753 if( hwPt > maxPt ) hwPt = maxPt;
T getParameter(std::string const &) const
EventNumber_t event() const
BXVector< GlobalExtBlk > GlobalExtBlkBxCollection
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
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
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.
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
Geom::Phi< T > phi() const
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity