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"
59 class Pythia6ServiceWithCallback :
public Pythia6Service {
93 int n,
npad,
k[5][pyjets_maxn];
94 double p[5][pyjets_maxn],
v[5][pyjets_maxn];
103 fCOMEnergy(ps.getParameter<double>(
"comEnergy")),
104 fHepMCVerbosity(ps.getUntrackedParameter<bool>(
"pythiaHepMCVerbosity",
false)),
105 fMaxEventsToPrint(ps.getUntrackedParameter<int>(
"maxEventsToPrint", 0)),
106 fPythiaListVerbosity(ps.getUntrackedParameter<int>(
"pythiaPylistVerbosity", 0)),
107 fDisplayPythiaBanner(ps.getUntrackedParameter<bool>(
"displayPythiaBanner",
false)),
108 fDisplayPythiaCards(ps.getUntrackedParameter<bool>(
"displayPythiaCards",
false))
114 if ( ps.
exists(
"PPbarInitialState" ) )
120 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
121 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
122 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
123 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
130 else if ( ps.
exists(
"ElectronPositronInitialState" ) )
136 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
137 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
138 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
139 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
146 else if ( ps.
exists(
"ElectronProtonInitialState" ) )
154 <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE. "
155 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
156 std::cout <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE." << std::endl;
157 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
164 else if ( ps.
exists(
"PositronProtonInitialState" ) )
172 <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE. "
173 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
174 std::cout <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE." << std::endl;
175 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
181 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
192 if ( ps.
exists(
"stopHadrons" ) )
196 if ( ps.
exists(
"gluinoHadrons" ) )
200 if ( ps.
exists(
"imposeProperTime" ) )
206 if ( ps.
exists(
"doPDGConvert" ) )
209 if ( ps.
exists(
"jetMatching") )
225 <<
" Pythia did not accept MSTU(12)=12345";
236 <<
" Pythia did not accept MSTU(13)=0";
257 for (
int ip=0; ip<pyjets_maxn; ip++ )
259 for (
int i=0;
i<5;
i++ )
275 for (
int ip=0; ip<pyjets_maxn; ip++ )
277 for (
int i=0;
i<5;
i++ )
308 if (
event()->signal_process_id() <= 0)
event()->set_signal_process_id(
pypars.msti[0] );
309 if (
event()->event_scale() <=0 )
event()->set_event_scale(
pypars.pari[22] );
316 if ( pdf.id1() <= 0) pdf.set_id1(
pyint1.mint[14] == 21 ? 0 :
pyint1.mint[14] );
317 if ( pdf.id2() <= 0) pdf.set_id2(
pyint1.mint[15] == 21 ? 0 :
pyint1.mint[15] );
318 if ( pdf.x1() <= 0) pdf.set_x1(
pyint1.vint[40] );
319 if ( pdf.x2() <= 0) pdf.set_x2(
pyint1.vint[41] );
320 if ( pdf.pdf1() <= 0) pdf.set_pdf1(
pyint1.vint[38] /
pyint1.vint[40] );
321 if ( pdf.pdf2() <= 0) pdf.set_pdf2(
pyint1.vint[39] /
pyint1.vint[41] );
322 if ( pdf.scalePDF() <= 0) pdf.set_scalePDF(
pyint1.vint[50] );
351 event()->set_pdf_info( pdf ) ;
357 event()->weights().push_back(
pyint1.vint[96] * 1.0e9 );
363 event()->weights().push_back( 1./(
pyint1.vint[98]) );
375 eventInfo()->setBinningValues( std::vector<double>(1,
pypars.pari[16]) );
384 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
386 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
399 <<
"----------------------" << std::endl;
409 std::cout <<
"\n PYPARS \n" << std::endl;
410 std::cout << std::setw(5) << std::fixed <<
"I"
411 << std::setw(10) << std::fixed <<
"MSTP(I)"
412 << std::setw(16) << std::fixed <<
"PARP(I)"
413 << std::setw(10) << std::fixed <<
"MSTI(I)"
414 << std::setw(16) << std::fixed <<
"PARI(I)" << std::endl;
415 for (
unsigned int ind=0; ind < 200; ind++ ) {
416 std::cout << std::setw(5) << std::fixed << ind+1
417 << std::setw(10) << std::fixed <<
pypars.mstp[ind]
418 << std::setw(16) << std::fixed <<
pypars.parp[ind]
419 << std::setw(10) << std::fixed <<
pypars.msti[ind]
420 << std::setw(16) << std::fixed <<
pypars.pari[ind] << std::endl;
461 if (
pyint1.mint[50] != 0 )
532 if (
pyint1.mint[50] != 0 )
564 int NPartsAfterDecays =
event().get()->particles_size();
565 int barcode = NPartsAfterDecays;
575 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
578 int status = part->status();
579 if ( status != 1 )
continue;
581 int pdgid = part->pdg_id();
583 if ( pydat3.mdcy[0][py6ptr-1] != 1 )
continue;
584 int py6id = HepPID::translatePDTtoPythia( pdgid );
590 if ( part->momentum().t() <= part->generated_mass() )
597 for (
int i=0;
i<5;
i++ )
604 pyjets.k[1][0] = py6id;
605 pyjets.p[4][0] = part->generated_mass();
606 pyjets.p[3][0] = part->momentum().t();
607 pyjets.p[0][0] = part->momentum().x();
608 pyjets.p[1][0] = part->momentum().y();
609 pyjets.p[2][0] = part->momentum().z();
610 HepMC::GenVertex* prod_vtx = part->production_vertex();
611 if ( !prod_vtx )
continue;
612 pyjets.v[0][0] = prod_vtx->position().x();
613 pyjets.v[1][0] = prod_vtx->position().y();
614 pyjets.v[2][0] = prod_vtx->position().z();
615 pyjets.v[3][0] = prod_vtx->position().t();
628 for (
int iprt1=1; iprt1<pyjets.n; iprt1++ )
630 part->set_status( 2 );
632 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(pyjets.v[0][iprt1],
635 pyjets.v[3][iprt1]) );
636 DecVtx->add_particle_in( part );
639 HepMC::FourVector pmom(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
640 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
643 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
647 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
651 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
655 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
657 dstatus = pyjets.k[0][iprt1];
660 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
663 daughter->suggest_barcode( barcode );
664 DecVtx->add_particle_out( daughter );
667 for ( iprt2=iprt1+1; iprt2<pyjets.n; iprt2++ )
669 if ( pyjets.k[2][iprt2] != parent )
671 parent = pyjets.k[2][iprt2];
675 HepMC::FourVector pmomN(pyjets.p[0][iprt2],pyjets.p[1][iprt2],
676 pyjets.p[2][iprt2],pyjets.p[3][iprt2] );
679 if ( pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10 )
683 else if ( pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20 )
687 else if ( pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30 )
691 else if ( pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100 )
693 dstatus = pyjets.k[0][iprt2];
696 HepPID::translatePythiatoPDT( pyjets.k[1][iprt2] ),
699 daughterN->suggest_barcode( barcode );
700 DecVtx->add_particle_out( daughterN );
706 event().get()->add_vertex( DecVtx );
722 for (
int i=0;
i<5;
i++ )
778 call_pyinit(
"USER",
"",
"", 0.0);
785 <<
"Pythia6 hadronisation found an SLHA header, "
786 <<
"will be passed on to Pythia." << std::endl;
844 call_pyinit(
"3mom",
"e-",
"p", 0.0 );
856 call_pyinit(
"3mom",
"e+",
"p", 0.0 );
862 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
876 for (
unsigned int i=0;
i<pdg.size();
i++ )
878 int PyID = HepPID::translatePDTtoPythia( pdg[
i] );
883 std::ostringstream pyCard ;
884 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
898 for (
unsigned int iss=0; iss<settings.size(); iss++ )
900 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
901 size_t fnd1 = settings[iss].find(
":");
902 if ( fnd1 == std::string::npos )
continue;
906 if ( value ==
"all" )
912 int number = atoi(value.c_str());
913 int PyID = HepPID::translatePDTtoPythia( number );
924 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
925 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38] <<
" - user will not get expected behaviour \n";
927 std::ostringstream pyCard ;
928 pyCard <<
"MSTJ(39)=" << pyCode ;
945 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
946 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
947 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
948 for (; vitr !=
vend; ++vitr )
950 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(HepMC::children);
951 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(HepMC::children);
952 HepMC::GenVertex::particle_iterator pitr = pbegin;
953 for (; pitr != pend; ++pitr)
955 if ((*pitr)->end_vertex())
continue;
956 if ((*pitr)->status()!=1)
continue;
958 int pdgcode=
abs((*pitr)->pdg_id());
960 if ( pydat3.mdcy[0][
pycomp_(pdgcode)-1] !=1 )
continue;
962 double ctau = pydat2.pmas[3][
pycomp_(pdgcode)-1];
963 HepMC::FourVector mom = (*pitr)->momentum();
964 HepMC::FourVector vin = (*vitr)->position();
969 bool decayInRange =
false;
970 while (!decayInRange)
974 double proper_length = - ctau *
log(unif_rand);
975 double factor = proper_length/mom.m();
976 x = vin.x() + factor * mom.px();
977 y = vin.y() + factor * mom.py();
978 z = vin.z() + factor * mom.pz();
979 t = vin.t() + factor * mom.e();
985 else if (
pydat1.mstj[21]==3) {
994 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x,y,z,t));
995 event()->add_vertex(vdec);
996 vdec->add_particle_in((*pitr));
1007 if ( !
runInfo().internalXSec() )
1024 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
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
Abs< T >::type abs(const T &t)
void setPYUPDAParams(bool afterPyinit)
bool initializeForExternalPartons()
static struct gen::@322 pyjets_local
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()
return(e1-e2)*(e1-e2)+dp *dp
void resetIterationsPerEvent()
bool fGluinoHadronsEnabled
bool declareSpecialSettings(const std::vector< std::string > &)
std::vector< std::string > findHeader(const std::string &tag) const
volatile std::atomic< bool > shutdown_flag false
virtual void init(const lhef::LHERunInfo *runInfo)
static JetMatching * fJetMatching