6 #include "HepMC/GenEvent.h"
7 #include "HepMC/PdfInfo.h"
8 #include "HepMC/PythiaWrapper6_4.h"
9 #include "HepMC/HEPEVT_Wrapper.h"
10 #include "HepMC/IO_HEPEVT.h"
25 #include "HepPID/ParticleIDTranslations.hh"
57 class Pythia6ServiceWithCallback :
public Pythia6Service {
91 int n,
npad,
k[5][pyjets_maxn];
92 double p[5][pyjets_maxn],
v[5][pyjets_maxn];
101 fCOMEnergy(ps.getParameter<double>(
"comEnergy")),
102 fHepMCVerbosity(ps.getUntrackedParameter<bool>(
"pythiaHepMCVerbosity",
false)),
103 fMaxEventsToPrint(ps.getUntrackedParameter<int>(
"maxEventsToPrint", 0)),
104 fPythiaListVerbosity(ps.getUntrackedParameter<int>(
"pythiaPylistVerbosity", 0)),
105 fDisplayPythiaBanner(ps.getUntrackedParameter<bool>(
"displayPythiaBanner",
false)),
106 fDisplayPythiaCards(ps.getUntrackedParameter<bool>(
"displayPythiaCards",
false))
112 if ( ps.
exists(
"PPbarInitialState" ) )
118 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
119 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
120 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
121 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
128 else if ( ps.
exists(
"ElectronPositronInitialState" ) )
134 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
135 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
136 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
137 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
144 else if ( ps.
exists(
"ElectronProtonInitialState" ) )
152 <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE. "
153 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
154 std::cout <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE." << std::endl;
155 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
162 else if ( ps.
exists(
"PositronProtonInitialState" ) )
170 <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE. "
171 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
172 std::cout <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE." << std::endl;
173 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
179 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
190 if ( ps.
exists(
"stopHadrons" ) )
194 if ( ps.
exists(
"gluinoHadrons" ) )
198 if ( ps.
exists(
"imposeProperTime" ) )
204 if ( ps.
exists(
"doPDGConvert" ) )
207 if ( ps.
exists(
"jetMatching") )
223 <<
" Pythia did not accept MSTU(12)=12345";
234 <<
" Pythia did not accept MSTU(13)=0";
255 for (
int ip=0; ip<pyjets_maxn; ip++ )
257 for (
int i=0;
i<5;
i++ )
273 for (
int ip=0; ip<pyjets_maxn; ip++ )
275 for (
int i=0;
i<5;
i++ )
306 if (
event()->signal_process_id() <= 0)
event()->set_signal_process_id(
pypars.msti[0] );
307 if (
event()->event_scale() <=0 )
event()->set_event_scale(
pypars.pari[22] );
314 if ( pdf.id1() <= 0) pdf.set_id1(
pyint1.mint[14] == 21 ? 0 :
pyint1.mint[14] );
315 if ( pdf.id2() <= 0) pdf.set_id2(
pyint1.mint[15] == 21 ? 0 :
pyint1.mint[15] );
316 if ( pdf.x1() <= 0) pdf.set_x1(
pyint1.vint[40] );
317 if ( pdf.x2() <= 0) pdf.set_x2(
pyint1.vint[41] );
318 if ( pdf.pdf1() <= 0) pdf.set_pdf1(
pyint1.vint[38] /
pyint1.vint[40] );
319 if ( pdf.pdf2() <= 0) pdf.set_pdf2(
pyint1.vint[39] /
pyint1.vint[41] );
320 if ( pdf.scalePDF() <= 0) pdf.set_scalePDF(
pyint1.vint[50] );
349 event()->set_pdf_info( pdf ) ;
355 event()->weights().push_back(
pyint1.vint[96] * 1.0e9 );
361 event()->weights().push_back( 1./(
pyint1.vint[98]) );
373 eventInfo()->setBinningValues( std::vector<double>(1,
pypars.pari[16]) );
382 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
384 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
397 <<
"----------------------" << std::endl;
407 std::cout <<
"\n PYPARS \n" << std::endl;
408 std::cout << std::setw(5) << std::fixed <<
"I"
409 << std::setw(10) << std::fixed <<
"MSTP(I)"
410 << std::setw(16) << std::fixed <<
"PARP(I)"
411 << std::setw(10) << std::fixed <<
"MSTI(I)"
412 << std::setw(16) << std::fixed <<
"PARI(I)" << std::endl;
413 for (
unsigned int ind=0; ind < 200; ind++ ) {
414 std::cout << std::setw(5) << std::fixed << ind+1
415 << std::setw(10) << std::fixed <<
pypars.mstp[ind]
416 << std::setw(16) << std::fixed <<
pypars.parp[ind]
417 << std::setw(10) << std::fixed <<
pypars.msti[ind]
418 << std::setw(16) << std::fixed <<
pypars.pari[ind] << std::endl;
459 if (
pyint1.mint[50] != 0 )
530 if (
pyint1.mint[50] != 0 )
562 int NPartsAfterDecays =
event().get()->particles_size();
563 int barcode = NPartsAfterDecays;
573 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
576 int status = part->status();
577 if ( status != 1 )
continue;
579 int pdgid = part->pdg_id();
581 if ( pydat3.mdcy[0][py6ptr-1] != 1 )
continue;
582 int py6id = HepPID::translatePDTtoPythia( pdgid );
588 if ( part->momentum().t() <= part->generated_mass() )
595 for (
int i=0;
i<5;
i++ )
602 pyjets.k[1][0] = py6id;
603 pyjets.p[4][0] = part->generated_mass();
604 pyjets.p[3][0] = part->momentum().t();
605 pyjets.p[0][0] = part->momentum().x();
606 pyjets.p[1][0] = part->momentum().y();
607 pyjets.p[2][0] = part->momentum().z();
608 HepMC::GenVertex* prod_vtx = part->production_vertex();
609 if ( !prod_vtx )
continue;
610 pyjets.v[0][0] = prod_vtx->position().x();
611 pyjets.v[1][0] = prod_vtx->position().y();
612 pyjets.v[2][0] = prod_vtx->position().z();
613 pyjets.v[3][0] = prod_vtx->position().t();
626 for (
int iprt1=1; iprt1<pyjets.n; iprt1++ )
628 part->set_status( 2 );
630 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(pyjets.v[0][iprt1],
633 pyjets.v[3][iprt1]) );
634 DecVtx->add_particle_in( part );
637 HepMC::FourVector pmom(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
638 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
641 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
645 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
649 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
653 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
655 dstatus = pyjets.k[0][iprt1];
658 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
661 daughter->suggest_barcode( barcode );
662 DecVtx->add_particle_out( daughter );
665 for ( iprt2=iprt1+1; iprt2<pyjets.n; iprt2++ )
667 if ( pyjets.k[2][iprt2] != parent )
669 parent = pyjets.k[2][iprt2];
673 HepMC::FourVector pmomN(pyjets.p[0][iprt2],pyjets.p[1][iprt2],
674 pyjets.p[2][iprt2],pyjets.p[3][iprt2] );
677 if ( pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10 )
681 else if ( pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20 )
685 else if ( pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30 )
689 else if ( pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100 )
691 dstatus = pyjets.k[0][iprt2];
694 HepPID::translatePythiatoPDT( pyjets.k[1][iprt2] ),
697 daughterN->suggest_barcode( barcode );
698 DecVtx->add_particle_out( daughterN );
704 event().get()->add_vertex( DecVtx );
720 for (
int i=0;
i<5;
i++ )
776 call_pyinit(
"USER",
"",
"", 0.0);
783 <<
"Pythia6 hadronisation found an SLHA header, "
784 <<
"will be passed on to Pythia." << std::endl;
842 call_pyinit(
"3mom",
"e-",
"p", 0.0 );
854 call_pyinit(
"3mom",
"e+",
"p", 0.0 );
860 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
874 for (
unsigned int i=0;
i<pdg.size();
i++ )
876 int PyID = HepPID::translatePDTtoPythia( pdg[
i] );
881 std::ostringstream pyCard ;
882 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
896 for (
unsigned int iss=0; iss<settings.size(); iss++ )
898 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
899 size_t fnd1 = settings[iss].find(
":");
900 if ( fnd1 == std::string::npos )
continue;
904 if ( value ==
"all" )
910 int number = atoi(value.c_str());
911 int PyID = HepPID::translatePDTtoPythia( number );
922 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
923 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38] <<
" - user will not get expected behaviour \n";
925 std::ostringstream pyCard ;
926 pyCard <<
"MSTJ(39)=" << pyCode ;
943 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
944 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
945 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
946 for (; vitr !=
vend; ++vitr )
948 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(HepMC::children);
949 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(HepMC::children);
950 HepMC::GenVertex::particle_iterator pitr = pbegin;
951 for (; pitr != pend; ++pitr)
953 if ((*pitr)->end_vertex())
continue;
954 if ((*pitr)->status()!=1)
continue;
956 int pdgcode=
abs((*pitr)->pdg_id());
958 if ( pydat3.mdcy[0][
pycomp_(pdgcode)-1] !=1 )
continue;
960 double ctau = pydat2.pmas[3][
pycomp_(pdgcode)-1];
961 HepMC::FourVector mom = (*pitr)->momentum();
962 HepMC::FourVector vin = (*vitr)->position();
967 bool decayInRange =
false;
968 while (!decayInRange)
972 double proper_length = - ctau *
log(unif_rand);
973 double factor = proper_length/mom.m();
974 x = vin.x() + factor * mom.px();
975 y = vin.y() + factor * mom.py();
976 z = vin.z() + factor * mom.pz();
977 t = vin.t() + factor * mom.e();
983 else if (
pydat1.mstj[21]==3) {
992 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x,y,z,t));
993 event()->add_vertex(vdec);
994 vdec->add_particle_in((*pitr));
1005 if ( !
runInfo().internalXSec() )
1022 return "gen::Pythia6Hadronizer";
T getParameter(std::string const &) const
static std::auto_ptr< JetMatching > create(const edm::ParameterSet ¶ms)
T getUntrackedParameter(std::string const &, T const &) const
auto_ptr< ClusterSequence > cs
static struct gen::@316 pyjets_local
unsigned int fPythiaListVerbosity
bool fDisplayPythiaBanner
Pythia6ServiceWithCallback(const edm::ParameterSet &ps)
unsigned int fMaxEventsToPrint
static HepMC::IO_HEPEVT conv
void fillEventInfo(HepMC::GenEvent *hepmc) const
static JetMatching * getJetMatching()
bool call_pygive(const std::string &line)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const char * classname() const
void setLHERunInfo(lhef::LHERunInfo *lheri)
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
virtual void beforeHadronisation(const lhef::LHEEvent *event)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
bool initializeForInternalPartons()
virtual int match(const lhef::LHEEvent *partonLevel, const std::vector< fastjet::PseudoJet > *jetInput)=0
GenRunInfoProduct & runInfo()
bool declareStableParticles(const std::vector< int > &)
void call_pylist(int mode)
void resetMatchingStatus()
lhef::LHEEvent * lheEvent()
void setSLHAFromHeader(const std::vector< std::string > &lines)
void fillPdfInfo(HepMC::PdfInfo *info) const
void setPYUPDAParams(bool afterPyinit)
bool initializeForExternalPartons()
Pythia6Hadronizer(edm::ParameterSet const &ps)
std::auto_ptr< GenEventInfoProduct > & eventInfo()
lhef::LHERunInfo * lheRunInfo()
static FortranCallback * getInstance()
Pythia6Service * fPy6Service
void setLHEEvent(lhef::LHEEvent *lhee)
bool generatePartonsAndHadronize()
virtual void beforeHadronisationExec()
void resetIterationsPerEvent()
bool fGluinoHadronsEnabled
bool declareSpecialSettings(const std::vector< std::string > &)
std::vector< std::string > findHeader(const std::string &tag) const
virtual void init(const lhef::LHERunInfo *runInfo)
static JetMatching * fJetMatching