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 {
86 int n,
npad,
k[5][pyjets_maxn];
87 double p[5][pyjets_maxn],
v[5][pyjets_maxn];
96 fCOMEnergy(ps.getParameter<double>(
"comEnergy")),
97 fHepMCVerbosity(ps.getUntrackedParameter<bool>(
"pythiaHepMCVerbosity",
false)),
98 fMaxEventsToPrint(ps.getUntrackedParameter<int>(
"maxEventsToPrint", 0)),
99 fPythiaListVerbosity(ps.getUntrackedParameter<int>(
"pythiaPylistVerbosity", 0)),
100 fDisplayPythiaBanner(ps.getUntrackedParameter<bool>(
"displayPythiaBanner",
false)),
101 fDisplayPythiaCards(ps.getUntrackedParameter<bool>(
"displayPythiaCards",
false))
107 if ( ps.
exists(
"PPbarInitialState" ) )
113 <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE. "
114 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
115 std::cout <<
"Pythia6 will be initialized for PROTON-ANTIPROTON INITIAL STATE." << std::endl;
116 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
123 else if ( ps.
exists(
"ElectronPositronInitialState" ) )
129 <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE. "
130 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
131 std::cout <<
"Pythia6 will be initialized for ELECTRON-POSITRON INITIAL STATE." << std::endl;
132 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
139 else if ( ps.
exists(
"ElectronProtonInitialState" ) )
147 <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE. "
148 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
149 std::cout <<
"Pythia6 will be initialized for ELECTRON-PROTON INITIAL STATE." << std::endl;
150 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
157 else if ( ps.
exists(
"PositronProtonInitialState" ) )
165 <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE. "
166 <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
167 std::cout <<
"Pythia6 will be initialized for POSITRON-PROTON INITIAL STATE." << std::endl;
168 std::cout <<
"This is a user-request change from the DEFAULT PROTON-PROTON initial state." << std::endl;
174 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
185 if ( ps.
exists(
"stopHadrons" ) )
189 if ( ps.
exists(
"gluinoHadrons" ) )
193 if ( ps.
exists(
"imposeProperTime" ) )
199 if ( ps.
exists(
"doPDGConvert" ) )
202 if ( ps.
exists(
"jetMatching") )
218 <<
" Pythia did not accept MSTU(12)=12345";
229 <<
" Pythia did not accept MSTU(13)=0";
250 for (
int ip=0; ip<pyjets_maxn; ip++ )
252 for (
int i=0;
i<5;
i++ )
268 for (
int ip=0; ip<pyjets_maxn; ip++ )
270 for (
int i=0;
i<5;
i++ )
301 if (
event()->signal_process_id() <= 0)
event()->set_signal_process_id(
pypars.msti[0] );
302 if (
event()->event_scale() <=0 )
event()->set_event_scale(
pypars.pari[22] );
309 if ( pdf.id1() <= 0) pdf.set_id1(
pyint1.mint[14] == 21 ? 0 :
pyint1.mint[14] );
310 if ( pdf.id2() <= 0) pdf.set_id2(
pyint1.mint[15] == 21 ? 0 :
pyint1.mint[15] );
311 if ( pdf.x1() <= 0) pdf.set_x1(
pyint1.vint[40] );
312 if ( pdf.x2() <= 0) pdf.set_x2(
pyint1.vint[41] );
313 if ( pdf.pdf1() <= 0) pdf.set_pdf1(
pyint1.vint[38] /
pyint1.vint[40] );
314 if ( pdf.pdf2() <= 0) pdf.set_pdf2(
pyint1.vint[39] /
pyint1.vint[41] );
315 if ( pdf.scalePDF() <= 0) pdf.set_scalePDF(
pyint1.vint[50] );
344 event()->set_pdf_info( pdf ) ;
350 event()->weights().push_back(
pyint1.vint[96] * 1.0e9 );
356 event()->weights().push_back( 1./(
pyint1.vint[98]) );
368 eventInfo()->setBinningValues( std::vector<double>(1,
pypars.pari[16]) );
377 for ( HepMC::GenEvent::particle_iterator
part =
event()->particles_begin();
379 (*part)->set_pdg_id(HepPID::translatePythiatoPDT((*part)->pdg_id()));
392 <<
"----------------------" << std::endl;
402 std::cout <<
"\n PYPARS \n" << std::endl;
403 std::cout << std::setw(5) << std::fixed <<
"I"
404 << std::setw(10) << std::fixed <<
"MSTP(I)"
405 << std::setw(16) << std::fixed <<
"PARP(I)"
406 << std::setw(10) << std::fixed <<
"MSTI(I)"
407 << std::setw(16) << std::fixed <<
"PARI(I)" << std::endl;
408 for (
unsigned int ind=0; ind < 200; ind++ ) {
409 std::cout << std::setw(5) << std::fixed << ind+1
410 << std::setw(10) << std::fixed <<
pypars.mstp[ind]
411 << std::setw(16) << std::fixed <<
pypars.parp[ind]
412 << std::setw(10) << std::fixed <<
pypars.msti[ind]
413 << std::setw(16) << std::fixed <<
pypars.pari[ind] << std::endl;
454 if (
pyint1.mint[50] != 0 )
525 if (
pyint1.mint[50] != 0 )
557 int NPartsAfterDecays =
event().get()->particles_size();
558 int barcode = NPartsAfterDecays;
568 for (
int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
571 int status = part->status();
572 if ( status != 1 )
continue;
574 int pdgid = part->pdg_id();
576 if ( pydat3.mdcy[0][py6ptr-1] != 1 )
continue;
577 int py6id = HepPID::translatePDTtoPythia( pdgid );
583 if ( part->momentum().t() <= part->generated_mass() )
590 for (
int i=0;
i<5;
i++ )
597 pyjets.k[1][0] = py6id;
598 pyjets.p[4][0] = part->generated_mass();
599 pyjets.p[3][0] = part->momentum().t();
600 pyjets.p[0][0] = part->momentum().x();
601 pyjets.p[1][0] = part->momentum().y();
602 pyjets.p[2][0] = part->momentum().z();
603 HepMC::GenVertex* prod_vtx = part->production_vertex();
604 if ( !prod_vtx )
continue;
605 pyjets.v[0][0] = prod_vtx->position().x();
606 pyjets.v[1][0] = prod_vtx->position().y();
607 pyjets.v[2][0] = prod_vtx->position().z();
608 pyjets.v[3][0] = prod_vtx->position().t();
621 for (
int iprt1=1; iprt1<pyjets.n; iprt1++ )
623 part->set_status( 2 );
625 HepMC::GenVertex* DecVtx =
new HepMC::GenVertex( HepMC::FourVector(pyjets.v[0][iprt1],
628 pyjets.v[3][iprt1]) );
629 DecVtx->add_particle_in( part );
632 HepMC::FourVector pmom(pyjets.p[0][iprt1],pyjets.p[1][iprt1],
633 pyjets.p[2][iprt1],pyjets.p[3][iprt1] );
636 if ( pyjets.k[0][iprt1] >= 1 && pyjets.k[0][iprt1] <= 10 )
640 else if ( pyjets.k[0][iprt1] >= 11 && pyjets.k[0][iprt1] <= 20 )
644 else if ( pyjets.k[0][iprt1] >= 21 && pyjets.k[0][iprt1] <= 30 )
648 else if ( pyjets.k[0][iprt1] >= 31 && pyjets.k[0][iprt1] <= 100 )
650 dstatus = pyjets.k[0][iprt1];
653 HepPID::translatePythiatoPDT( pyjets.k[1][iprt1] ),
656 daughter->suggest_barcode( barcode );
657 DecVtx->add_particle_out( daughter );
660 for ( iprt2=iprt1+1; iprt2<pyjets.n; iprt2++ )
662 if ( pyjets.k[2][iprt2] != parent )
664 parent = pyjets.k[2][iprt2];
668 HepMC::FourVector pmomN(pyjets.p[0][iprt2],pyjets.p[1][iprt2],
669 pyjets.p[2][iprt2],pyjets.p[3][iprt2] );
672 if ( pyjets.k[0][iprt2] >= 1 && pyjets.k[0][iprt2] <= 10 )
676 else if ( pyjets.k[0][iprt2] >= 11 && pyjets.k[0][iprt2] <= 20 )
680 else if ( pyjets.k[0][iprt2] >= 21 && pyjets.k[0][iprt2] <= 30 )
684 else if ( pyjets.k[0][iprt2] >= 31 && pyjets.k[0][iprt2] <= 100 )
686 dstatus = pyjets.k[0][iprt2];
689 HepPID::translatePythiatoPDT( pyjets.k[1][iprt2] ),
692 daughterN->suggest_barcode( barcode );
693 DecVtx->add_particle_out( daughterN );
699 event().get()->add_vertex( DecVtx );
715 for (
int i=0;
i<5;
i++ )
771 call_pyinit(
"USER",
"",
"", 0.0);
778 <<
"Pythia6 hadronisation found an SLHA header, "
779 <<
"will be passed on to Pythia." << std::endl;
837 call_pyinit(
"3mom",
"e-",
"p", 0.0 );
849 call_pyinit(
"3mom",
"e+",
"p", 0.0 );
855 <<
" UNKNOWN INITIAL STATE. \n The allowed initial states are: PP, PPbar, ElectronPositron, ElectronProton, and PositronProton \n";
869 for (
unsigned int i=0;
i<pdg.size();
i++ )
871 int PyID = HepPID::translatePDTtoPythia( pdg[
i] );
876 std::ostringstream pyCard ;
877 pyCard <<
"MDCY(" << pyCode <<
",1)=0";
891 for (
unsigned int iss=0; iss<settings.size(); iss++ )
893 if ( settings[iss].
find(
"QED-brem-off") == std::string::npos )
continue;
894 size_t fnd1 = settings[iss].find(
":");
895 if ( fnd1 == std::string::npos )
continue;
897 std::string
value = settings[iss].substr (fnd1+1);
899 if ( value ==
"all" )
905 int number = atoi(value.c_str());
906 int PyID = HepPID::translatePDTtoPythia( number );
917 <<
" Fatal conflict: \n mandatory internal directive to set MSTJ(39)=" << pyCode
918 <<
" overrides user setting MSTJ(39)=" <<
pydat1_.mstj[38] <<
" - user will not get expected behaviour \n";
920 std::ostringstream pyCard ;
921 pyCard <<
"MSTJ(39)=" << pyCode ;
938 HepMC::GenEvent::vertex_const_iterator
vbegin =
event()->vertices_begin();
939 HepMC::GenEvent::vertex_const_iterator
vend =
event()->vertices_end();
940 HepMC::GenEvent::vertex_const_iterator vitr =
vbegin;
941 for (; vitr !=
vend; ++vitr )
943 HepMC::GenVertex::particle_iterator pbegin = (*vitr)->particles_begin(HepMC::children);
944 HepMC::GenVertex::particle_iterator pend = (*vitr)->particles_end(HepMC::children);
945 HepMC::GenVertex::particle_iterator pitr = pbegin;
946 for (; pitr != pend; ++pitr)
948 if ((*pitr)->end_vertex())
continue;
949 if ((*pitr)->status()!=1)
continue;
951 int pdgcode=
abs((*pitr)->pdg_id());
953 if ( pydat3.mdcy[0][
pycomp_(pdgcode)-1] !=1 )
continue;
955 double ctau = pydat2.pmas[3][
pycomp_(pdgcode)-1];
956 HepMC::FourVector mom = (*pitr)->momentum();
957 HepMC::FourVector vin = (*vitr)->position();
962 bool decayInRange =
false;
963 while (!decayInRange)
967 double proper_length = - ctau *
log(unif_rand);
968 double factor = proper_length/mom.m();
969 x = vin.x() + factor * mom.px();
970 y = vin.y() + factor * mom.py();
971 z = vin.z() + factor * mom.pz();
972 t = vin.t() + factor * mom.e();
978 else if (
pydat1.mstj[21]==3) {
987 HepMC::GenVertex* vdec =
new HepMC::GenVertex(HepMC::FourVector(x,y,z,t));
988 event()->add_vertex(vdec);
989 vdec->add_particle_in((*pitr));
1000 if ( !
runInfo().internalXSec() )
1017 return "gen::Pythia6Hadronizer";
static struct gen::@232 pyjets_local
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)
bool declareSpecialSettings(const std::vector< std::string >)
void setInternalXSec(const XSec &xsec)
std::auto_ptr< HepMC::GenEvent > & event()
bool initializeForInternalPartons()
GenRunInfoProduct & runInfo()
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
virtual int match(const HepMC::GenEvent *partonLevel, const HepMC::GenEvent *finalState, bool showeredFinalState=false)=0
std::vector< std::string > findHeader(const std::string &tag) const
virtual void init(const lhef::LHERunInfo *runInfo)
bool declareStableParticles(const std::vector< int >)
static JetMatching * fJetMatching